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
28 using V1_0::PerformanceInfo;
29
30 // create device test
TEST_F(NeuralnetworksHidlTest,CreateDevice)31 TEST_F(NeuralnetworksHidlTest, CreateDevice) {}
32
33 // status test
TEST_F(NeuralnetworksHidlTest,StatusTest)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
40 // initialization
TEST_F(NeuralnetworksHidlTest,GetCapabilitiesTest)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
65 // device version test
TEST_F(NeuralnetworksHidlTest,GetDeviceVersionStringTest)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 }
73
74 // device type test
TEST_F(NeuralnetworksHidlTest,GetDeviceTypeTest)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 }
83
84 // device supported extensions test
TEST_F(NeuralnetworksHidlTest,GetDeviceSupportedExtensionsTest)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());
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)
98 << "Extension name must start with the reverse domain name of the "
99 "vendor";
100 }
101 });
102 EXPECT_TRUE(ret.isOk());
103 }
104
105 // getNumberOfCacheFilesNeeded test
TEST_F(NeuralnetworksHidlTest,getNumberOfCacheFilesNeeded)106 TEST_F(NeuralnetworksHidlTest, getNumberOfCacheFilesNeeded) {
107 Return<void> ret = device->getNumberOfCacheFilesNeeded(
108 [](ErrorStatus status, uint32_t numModelCache, uint32_t numDataCache) {
109 EXPECT_EQ(ErrorStatus::NONE, status);
110 EXPECT_LE(numModelCache,
111 static_cast<uint32_t>(Constant::MAX_NUMBER_OF_CACHE_FILES));
112 EXPECT_LE(numDataCache, static_cast<uint32_t>(Constant::MAX_NUMBER_OF_CACHE_FILES));
113 });
114 EXPECT_TRUE(ret.isOk());
115 }
116 } // namespace functional
117 } // namespace vts
118 } // namespace V1_2
119 } // namespace neuralnetworks
120 } // namespace hardware
121 } // namespace android
122