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 | |
| 21 | namespace android { |
| 22 | namespace hardware { |
| 23 | namespace neuralnetworks { |
| 24 | namespace V1_2 { |
| 25 | namespace vts { |
| 26 | namespace functional { |
| 27 | |
David Gross | 2d47c80 | 2019-03-15 17:26:32 -0700 | [diff] [blame^] | 28 | using V1_0::PerformanceInfo; |
Slava Shklyaev | feb87a9 | 2018-09-12 14:52:02 +0100 | [diff] [blame] | 29 | |
| 30 | // create device test |
| 31 | TEST_F(NeuralnetworksHidlTest, CreateDevice) {} |
| 32 | |
| 33 | // status test |
| 34 | TEST_F(NeuralnetworksHidlTest, StatusTest) { |
| 35 | Return<DeviceStatus> status = device->getStatus(); |
| 36 | ASSERT_TRUE(status.isOk()); |
| 37 | EXPECT_EQ(DeviceStatus::AVAILABLE, static_cast<DeviceStatus>(status)); |
| 38 | } |
| 39 | |
David Gross | 2d47c80 | 2019-03-15 17:26:32 -0700 | [diff] [blame^] | 40 | // initialization |
| 41 | TEST_F(NeuralnetworksHidlTest, GetCapabilitiesTest) { |
| 42 | using OperandPerformance = Capabilities::OperandPerformance; |
| 43 | Return<void> ret = device->getCapabilities_1_2([](ErrorStatus status, |
| 44 | const Capabilities& capabilities) { |
| 45 | EXPECT_EQ(ErrorStatus::NONE, status); |
| 46 | |
| 47 | auto isPositive = [](const PerformanceInfo& perf) { |
| 48 | return perf.execTime > 0.0f && perf.powerUsage > 0.0f; |
| 49 | }; |
| 50 | |
| 51 | EXPECT_TRUE(isPositive(capabilities.relaxedFloat32toFloat16PerformanceScalar)); |
| 52 | EXPECT_TRUE(isPositive(capabilities.relaxedFloat32toFloat16PerformanceTensor)); |
| 53 | const auto& opPerf = capabilities.operandPerformance; |
| 54 | EXPECT_TRUE(std::all_of( |
| 55 | opPerf.begin(), opPerf.end(), |
| 56 | [isPositive](const OperandPerformance& a) { return isPositive(a.info); })); |
| 57 | EXPECT_TRUE(std::is_sorted(opPerf.begin(), opPerf.end(), |
| 58 | [](const OperandPerformance& a, const OperandPerformance& b) { |
| 59 | return a.type < b.type; |
| 60 | })); |
| 61 | }); |
| 62 | EXPECT_TRUE(ret.isOk()); |
| 63 | } |
| 64 | |
Miao Wang | 618028b | 2018-09-20 11:35:42 -0700 | [diff] [blame] | 65 | // device version test |
| 66 | TEST_F(NeuralnetworksHidlTest, GetDeviceVersionStringTest) { |
| 67 | Return<void> ret = device->getVersionString([](ErrorStatus status, const hidl_string& version) { |
| 68 | EXPECT_EQ(ErrorStatus::NONE, status); |
| 69 | EXPECT_LT(0, version.size()); |
| 70 | }); |
| 71 | EXPECT_TRUE(ret.isOk()); |
| 72 | } |
Miao Wang | 7176fe7 | 2018-09-20 13:30:31 -0700 | [diff] [blame] | 73 | |
| 74 | // device type test |
| 75 | TEST_F(NeuralnetworksHidlTest, GetDeviceTypeTest) { |
| 76 | Return<void> ret = device->getType([](ErrorStatus status, DeviceType type) { |
| 77 | EXPECT_EQ(ErrorStatus::NONE, status); |
| 78 | EXPECT_TRUE(type == DeviceType::OTHER || type == DeviceType::CPU || |
| 79 | type == DeviceType::GPU || type == DeviceType::ACCELERATOR); |
| 80 | }); |
| 81 | EXPECT_TRUE(ret.isOk()); |
| 82 | } |
Slava Shklyaev | c9ff099 | 2018-11-20 15:29:01 +0000 | [diff] [blame] | 83 | |
| 84 | // device supported extensions test |
| 85 | TEST_F(NeuralnetworksHidlTest, GetDeviceSupportedExtensionsTest) { |
| 86 | Return<void> ret = device->getSupportedExtensions( |
| 87 | [](ErrorStatus status, const hidl_vec<Extension>& extensions) { |
| 88 | EXPECT_EQ(ErrorStatus::NONE, status); |
| 89 | for (auto& extension : extensions) { |
| 90 | std::string extensionName = extension.name; |
| 91 | EXPECT_FALSE(extensionName.empty()); |
Slava Shklyaev | 1d2cd43 | 2019-02-25 18:23:03 +0000 | [diff] [blame] | 92 | for (char c : extensionName) { |
| 93 | EXPECT_TRUE(('a' <= c && c <= 'z') || ('0' <= c && c <= '9') || c == '_' || |
| 94 | c == '.') |
| 95 | << "Extension name contains an illegal character: " << c; |
| 96 | } |
| 97 | EXPECT_NE(extensionName.find('.'), std::string::npos) |
Slava Shklyaev | c9ff099 | 2018-11-20 15:29:01 +0000 | [diff] [blame] | 98 | << "Extension name must start with the reverse domain name of the " |
| 99 | "vendor"; |
| 100 | } |
| 101 | }); |
| 102 | EXPECT_TRUE(ret.isOk()); |
| 103 | } |
| 104 | |
Xusong Wang | 96e68dc | 2019-01-18 17:28:26 -0800 | [diff] [blame] | 105 | // isCachingSupported test |
| 106 | TEST_F(NeuralnetworksHidlTest, IsCachingSupported) { |
| 107 | Return<void> ret = device->isCachingSupported( |
| 108 | [](ErrorStatus status, bool) { EXPECT_EQ(ErrorStatus::NONE, status); }); |
| 109 | EXPECT_TRUE(ret.isOk()); |
| 110 | } |
Slava Shklyaev | feb87a9 | 2018-09-12 14:52:02 +0100 | [diff] [blame] | 111 | } // namespace functional |
| 112 | } // namespace vts |
| 113 | } // namespace V1_2 |
| 114 | } // namespace neuralnetworks |
| 115 | } // namespace hardware |
| 116 | } // namespace android |