Slava Shklyaev | feb87a9 | 2018-09-12 14:52:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "neuralnetworks_hidl_hal_test" |
| 18 | |
| 19 | #include "VtsHalNeuralnetworks.h" |
| 20 | |
Michael Butler | bbe5dad | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 21 | namespace android::hardware::neuralnetworks::V1_2::vts::functional { |
Slava Shklyaev | feb87a9 | 2018-09-12 14:52:02 +0100 | [diff] [blame] | 22 | |
Michael Butler | bbe5dad | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 23 | using V1_0::DeviceStatus; |
| 24 | using V1_0::ErrorStatus; |
David Gross | 632b4bd | 2019-03-15 17:26:32 -0700 | [diff] [blame] | 25 | using V1_0::PerformanceInfo; |
Slava Shklyaev | feb87a9 | 2018-09-12 14:52:02 +0100 | [diff] [blame] | 26 | |
| 27 | // create device test |
Michael Butler | 7076f62 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 28 | TEST_P(NeuralnetworksHidlTest, CreateDevice) {} |
Slava Shklyaev | feb87a9 | 2018-09-12 14:52:02 +0100 | [diff] [blame] | 29 | |
| 30 | // status test |
Michael Butler | 7076f62 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 31 | TEST_P(NeuralnetworksHidlTest, StatusTest) { |
Michael Butler | e16af0a | 2019-08-29 22:17:24 -0700 | [diff] [blame] | 32 | Return<DeviceStatus> status = kDevice->getStatus(); |
Slava Shklyaev | feb87a9 | 2018-09-12 14:52:02 +0100 | [diff] [blame] | 33 | ASSERT_TRUE(status.isOk()); |
| 34 | EXPECT_EQ(DeviceStatus::AVAILABLE, static_cast<DeviceStatus>(status)); |
| 35 | } |
| 36 | |
David Gross | 632b4bd | 2019-03-15 17:26:32 -0700 | [diff] [blame] | 37 | // initialization |
Michael Butler | 7076f62 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 38 | TEST_P(NeuralnetworksHidlTest, GetCapabilitiesTest) { |
David Gross | 632b4bd | 2019-03-15 17:26:32 -0700 | [diff] [blame] | 39 | using OperandPerformance = Capabilities::OperandPerformance; |
Michael Butler | e16af0a | 2019-08-29 22:17:24 -0700 | [diff] [blame] | 40 | Return<void> ret = kDevice->getCapabilities_1_2([](ErrorStatus status, |
| 41 | const Capabilities& capabilities) { |
David Gross | 632b4bd | 2019-03-15 17:26:32 -0700 | [diff] [blame] | 42 | EXPECT_EQ(ErrorStatus::NONE, status); |
| 43 | |
| 44 | auto isPositive = [](const PerformanceInfo& perf) { |
| 45 | return perf.execTime > 0.0f && perf.powerUsage > 0.0f; |
| 46 | }; |
| 47 | |
| 48 | EXPECT_TRUE(isPositive(capabilities.relaxedFloat32toFloat16PerformanceScalar)); |
| 49 | EXPECT_TRUE(isPositive(capabilities.relaxedFloat32toFloat16PerformanceTensor)); |
| 50 | const auto& opPerf = capabilities.operandPerformance; |
| 51 | EXPECT_TRUE(std::all_of( |
| 52 | opPerf.begin(), opPerf.end(), |
| 53 | [isPositive](const OperandPerformance& a) { return isPositive(a.info); })); |
| 54 | EXPECT_TRUE(std::is_sorted(opPerf.begin(), opPerf.end(), |
| 55 | [](const OperandPerformance& a, const OperandPerformance& b) { |
| 56 | return a.type < b.type; |
| 57 | })); |
| 58 | }); |
| 59 | EXPECT_TRUE(ret.isOk()); |
| 60 | } |
| 61 | |
Miao Wang | 618028b | 2018-09-20 11:35:42 -0700 | [diff] [blame] | 62 | // device version test |
Michael Butler | 7076f62 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 63 | TEST_P(NeuralnetworksHidlTest, GetDeviceVersionStringTest) { |
Michael Butler | e16af0a | 2019-08-29 22:17:24 -0700 | [diff] [blame] | 64 | Return<void> ret = |
| 65 | kDevice->getVersionString([](ErrorStatus status, const hidl_string& version) { |
| 66 | EXPECT_EQ(ErrorStatus::NONE, status); |
| 67 | EXPECT_LT(0, version.size()); |
| 68 | }); |
Miao Wang | 618028b | 2018-09-20 11:35:42 -0700 | [diff] [blame] | 69 | EXPECT_TRUE(ret.isOk()); |
| 70 | } |
Miao Wang | 7176fe7 | 2018-09-20 13:30:31 -0700 | [diff] [blame] | 71 | |
| 72 | // device type test |
Michael Butler | 7076f62 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 73 | TEST_P(NeuralnetworksHidlTest, GetDeviceTypeTest) { |
Michael Butler | e16af0a | 2019-08-29 22:17:24 -0700 | [diff] [blame] | 74 | Return<void> ret = kDevice->getType([](ErrorStatus status, DeviceType type) { |
Miao Wang | 7176fe7 | 2018-09-20 13:30:31 -0700 | [diff] [blame] | 75 | EXPECT_EQ(ErrorStatus::NONE, status); |
| 76 | EXPECT_TRUE(type == DeviceType::OTHER || type == DeviceType::CPU || |
| 77 | type == DeviceType::GPU || type == DeviceType::ACCELERATOR); |
| 78 | }); |
| 79 | EXPECT_TRUE(ret.isOk()); |
| 80 | } |
Slava Shklyaev | c9ff099 | 2018-11-20 15:29:01 +0000 | [diff] [blame] | 81 | |
Miao Wang | 2729d82 | 2020-02-05 16:26:37 -0800 | [diff] [blame] | 82 | // device name test |
| 83 | TEST_P(NeuralnetworksHidlTest, GetDeviceNameTest) { |
| 84 | const std::string deviceName = getName(GetParam()); |
| 85 | auto pos = deviceName.find('-'); |
| 86 | EXPECT_NE(pos, std::string::npos); |
| 87 | // The separator should not be the first or last character. |
| 88 | EXPECT_NE(pos, 0); |
| 89 | EXPECT_NE(pos, deviceName.length() - 1); |
| 90 | // There should only be 1 separator. |
| 91 | EXPECT_EQ(std::string::npos, deviceName.find('-', pos + 1)); |
| 92 | } |
| 93 | |
Slava Shklyaev | c9ff099 | 2018-11-20 15:29:01 +0000 | [diff] [blame] | 94 | // device supported extensions test |
Michael Butler | 7076f62 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 95 | TEST_P(NeuralnetworksHidlTest, GetDeviceSupportedExtensionsTest) { |
Michael Butler | e16af0a | 2019-08-29 22:17:24 -0700 | [diff] [blame] | 96 | Return<void> ret = kDevice->getSupportedExtensions( |
Slava Shklyaev | c9ff099 | 2018-11-20 15:29:01 +0000 | [diff] [blame] | 97 | [](ErrorStatus status, const hidl_vec<Extension>& extensions) { |
| 98 | EXPECT_EQ(ErrorStatus::NONE, status); |
| 99 | for (auto& extension : extensions) { |
| 100 | std::string extensionName = extension.name; |
| 101 | EXPECT_FALSE(extensionName.empty()); |
Slava Shklyaev | 1d2cd43 | 2019-02-25 18:23:03 +0000 | [diff] [blame] | 102 | for (char c : extensionName) { |
| 103 | EXPECT_TRUE(('a' <= c && c <= 'z') || ('0' <= c && c <= '9') || c == '_' || |
| 104 | c == '.') |
| 105 | << "Extension name contains an illegal character: " << c; |
| 106 | } |
| 107 | EXPECT_NE(extensionName.find('.'), std::string::npos) |
Slava Shklyaev | c9ff099 | 2018-11-20 15:29:01 +0000 | [diff] [blame] | 108 | << "Extension name must start with the reverse domain name of the " |
| 109 | "vendor"; |
| 110 | } |
| 111 | }); |
| 112 | EXPECT_TRUE(ret.isOk()); |
| 113 | } |
| 114 | |
Xusong Wang | b61ba1e | 2019-02-25 16:58:58 -0800 | [diff] [blame] | 115 | // getNumberOfCacheFilesNeeded test |
Michael Butler | 7076f62 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 116 | TEST_P(NeuralnetworksHidlTest, getNumberOfCacheFilesNeeded) { |
Michael Butler | e16af0a | 2019-08-29 22:17:24 -0700 | [diff] [blame] | 117 | Return<void> ret = kDevice->getNumberOfCacheFilesNeeded( |
Xusong Wang | b61ba1e | 2019-02-25 16:58:58 -0800 | [diff] [blame] | 118 | [](ErrorStatus status, uint32_t numModelCache, uint32_t numDataCache) { |
| 119 | EXPECT_EQ(ErrorStatus::NONE, status); |
| 120 | EXPECT_LE(numModelCache, |
| 121 | static_cast<uint32_t>(Constant::MAX_NUMBER_OF_CACHE_FILES)); |
| 122 | EXPECT_LE(numDataCache, static_cast<uint32_t>(Constant::MAX_NUMBER_OF_CACHE_FILES)); |
| 123 | }); |
Xusong Wang | 96e68dc | 2019-01-18 17:28:26 -0800 | [diff] [blame] | 124 | EXPECT_TRUE(ret.isOk()); |
| 125 | } |
Michael Butler | bbe5dad | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 126 | } // namespace android::hardware::neuralnetworks::V1_2::vts::functional |