From 7b0b54697cf9d9f9afbf4d4c97bd5292057c732e Mon Sep 17 00:00:00 2001 From: Lev Proleev Date: Mon, 8 Mar 2021 10:46:33 +0000 Subject: [PATCH] Add missing NNAPI HIDL interface mock tests prepareModelFromCache* was tested for handling of errors happening during the preparation launch but not during the actual preparation. Bug: 163801800 Test: mma Test: atest neuralnetworks_utils_hal_common_test Test: atest neuralnetworks_utils_hal_1_[0-3]_test Change-Id: I2c4b235fd4877238d7a18be8b0ea051434c1df6b Merged-In: I2c4b235fd4877238d7a18be8b0ea051434c1df6b (cherry picked from commit c6cf50ad425d60796da6a326f5d5515fb3b28fc0) --- neuralnetworks/1.2/utils/test/DeviceTest.cpp | 19 ++++++++++++++++++- neuralnetworks/1.3/utils/test/DeviceTest.cpp | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/neuralnetworks/1.2/utils/test/DeviceTest.cpp b/neuralnetworks/1.2/utils/test/DeviceTest.cpp index 9c8addef1f..215d44c83f 100644 --- a/neuralnetworks/1.2/utils/test/DeviceTest.cpp +++ b/neuralnetworks/1.2/utils/test/DeviceTest.cpp @@ -772,7 +772,7 @@ TEST(DeviceTest, prepareModelFromCache) { EXPECT_NE(result.value(), nullptr); } -TEST(DeviceTest, prepareModelFromCacheError) { +TEST(DeviceTest, prepareModelFromCacheLaunchError) { // setup call const auto mockDevice = createMockDevice(); const auto device = Device::create(kName, mockDevice).value(); @@ -790,6 +790,23 @@ TEST(DeviceTest, prepareModelFromCacheError) { EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE); } +TEST(DeviceTest, prepareModelFromCacheReturnError) { + // setup call + const auto mockDevice = createMockDevice(); + const auto device = Device::create(kName, mockDevice).value(); + EXPECT_CALL(*mockDevice, prepareModelFromCache(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(makePreparedModelFromCacheReturn( + V1_0::ErrorStatus::NONE, V1_0::ErrorStatus::GENERAL_FAILURE, nullptr))); + + // run test + const auto result = device->prepareModelFromCache({}, {}, {}, {}); + + // verify result + ASSERT_FALSE(result.has_value()); + EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE); +} + TEST(DeviceTest, prepareModelFromCacheNullptrError) { // setup call const auto mockDevice = createMockDevice(); diff --git a/neuralnetworks/1.3/utils/test/DeviceTest.cpp b/neuralnetworks/1.3/utils/test/DeviceTest.cpp index f260990471..2d1b2f295a 100644 --- a/neuralnetworks/1.3/utils/test/DeviceTest.cpp +++ b/neuralnetworks/1.3/utils/test/DeviceTest.cpp @@ -794,7 +794,7 @@ TEST(DeviceTest, prepareModelFromCache) { EXPECT_NE(result.value(), nullptr); } -TEST(DeviceTest, prepareModelFromCacheError) { +TEST(DeviceTest, prepareModelFromCacheLaunchError) { // setup call const auto mockDevice = createMockDevice(); const auto device = Device::create(kName, mockDevice).value(); @@ -812,6 +812,23 @@ TEST(DeviceTest, prepareModelFromCacheError) { EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE); } +TEST(DeviceTest, prepareModelFromCacheReturnError) { + // setup call + const auto mockDevice = createMockDevice(); + const auto device = Device::create(kName, mockDevice).value(); + EXPECT_CALL(*mockDevice, prepareModelFromCache_1_3(_, _, _, _, _)) + .Times(1) + .WillOnce(Invoke(makePreparedModelFromCacheReturn( + V1_3::ErrorStatus::NONE, V1_3::ErrorStatus::GENERAL_FAILURE, nullptr))); + + // run test + const auto result = device->prepareModelFromCache({}, {}, {}, {}); + + // verify result + ASSERT_FALSE(result.has_value()); + EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE); +} + TEST(DeviceTest, prepareModelFromCacheNullptrError) { // setup call const auto mockDevice = createMockDevice();