aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-10-10 19:16:08 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-10-10 19:16:08 +0000
commite9b5fe323b735f46a966c8f7f0d714f3ed82de27 (patch)
tree4f38cdbacb54a515da07941c0aae50d8aa398172
parent3ecb388a9545e45e4d768bf1a879a51e0658c9c2 (diff)
parenta68fb57f2037e5925eb0fad49ede637ab04e20e6 (diff)
downloadNeuralNetworks-android14-mainline-adservices-release.tar.gz
Snap for 10927977 from a68fb57f2037e5925eb0fad49ede637ab04e20e6 to mainline-adservices-releaseaml_ads_341615050aml_ads_341517040aml_ads_341413000aml_ads_341316030android14-mainline-adservices-release
Change-Id: If1b6792f34f6479840a9d8bb308c0154f97ed738
-rw-r--r--runtime/test/TestTrivialModel.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/runtime/test/TestTrivialModel.cpp b/runtime/test/TestTrivialModel.cpp
index 999a27dfb..9c168dfa8 100644
--- a/runtime/test/TestTrivialModel.cpp
+++ b/runtime/test/TestTrivialModel.cpp
@@ -37,7 +37,8 @@ class TrivialTest : public ::testing::Test {
virtual void SetUp() {}
#if defined(__ANDROID__)
- void testAddTwoWithHardwareBufferInput(uint64_t additionalAhwbUsage);
+ void testAddTwoWithHardwareBufferInput(uint64_t additionalAhwbUsage,
+ bool allowAllocationFailure);
#endif
const Matrix3x4 matrix1 = {{1.f, 2.f, 3.f, 4.f}, {5.f, 6.f, 7.f, 8.f}, {9.f, 10.f, 11.f, 12.f}};
@@ -133,7 +134,8 @@ TEST_F(TrivialTest, AddTwo) {
// Hardware buffers are an Android concept, which aren't necessarily
// available on other platforms such as ChromeOS, which also build NNAPI.
#if defined(__ANDROID__)
-void TrivialTest::testAddTwoWithHardwareBufferInput(uint64_t additionalAhwbUsage) {
+void TrivialTest::testAddTwoWithHardwareBufferInput(uint64_t additionalAhwbUsage,
+ bool allowAllocationFailure) {
Model modelAdd2;
CreateAddTwoTensorModel(&modelAdd2);
@@ -147,7 +149,11 @@ void TrivialTest::testAddTwoWithHardwareBufferInput(uint64_t additionalAhwbUsage
.usage = cpuUsage | additionalAhwbUsage,
};
AHardwareBuffer* matrix1Buffer = nullptr;
- ASSERT_EQ(AHardwareBuffer_allocate(&desc, &matrix1Buffer), 0);
+ int err = AHardwareBuffer_allocate(&desc, &matrix1Buffer);
+ if (allowAllocationFailure && err != 0) {
+ GTEST_SKIP() << "Test skipped: AHardwareBuffer_allocate failed";
+ }
+ ASSERT_EQ(err, 0);
auto allocateGuard = android::base::make_scope_guard(
[matrix1Buffer]() { AHardwareBuffer_release(matrix1Buffer); });
@@ -194,11 +200,13 @@ void TrivialTest::testAddTwoWithHardwareBufferInput(uint64_t additionalAhwbUsage
}
TEST_F(TrivialTest, AddTwoWithHardwareBufferInput) {
- testAddTwoWithHardwareBufferInput(/* no additional usage */ 0u);
+ testAddTwoWithHardwareBufferInput(/* no additional usage */ 0u,
+ /*allowAllocationFailure=*/false);
}
TEST_F(TrivialTest, AddTwoWithHardwareBufferInputWithGPUUsage) {
- testAddTwoWithHardwareBufferInput(AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER);
+ testAddTwoWithHardwareBufferInput(AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER,
+ /*allowAllocationFailure=*/true);
}
#endif