Snap for 10784727 from cbafa526d1dce7754d83377d73fc50c4d20e3a88 to udc-d2-release

Change-Id: Iace8b3e78237393c5346bf0352f90bc78620ada6
diff --git a/runtime/test/TestTrivialModel.cpp b/runtime/test/TestTrivialModel.cpp
index 999a27d..9c168df 100644
--- a/runtime/test/TestTrivialModel.cpp
+++ b/runtime/test/TestTrivialModel.cpp
@@ -37,7 +37,8 @@
     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 @@
 // 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 @@
             .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 @@
 }
 
 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