aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-02 22:35:51 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-02 22:35:51 +0000
commit1c63d4f46e60113cae9e3d64b351923b6a42e25c (patch)
tree4f38cdbacb54a515da07941c0aae50d8aa398172
parentd17943d08e169e922b9a8569bb1a11f380f97283 (diff)
parenta68fb57f2037e5925eb0fad49ede637ab04e20e6 (diff)
downloadNeuralNetworks-aml_net_341510050.tar.gz
Change-Id: I65042d53c50561808f844c2a17f93e7ecae7e196
-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