blob: 86849d566a3d66c5385728c70cd833d0a497b096 [file] [log] [blame]
Slava Shklyaevfeb87a92018-09-12 14:52:02 +01001/*
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 Butler62749b92019-08-26 23:55:47 -070021namespace android::hardware::neuralnetworks::V1_2::vts::functional {
Slava Shklyaevfeb87a92018-09-12 14:52:02 +010022
Michael Butler62749b92019-08-26 23:55:47 -070023using V1_0::DeviceStatus;
24using V1_0::ErrorStatus;
David Gross2d47c802019-03-15 17:26:32 -070025using V1_0::PerformanceInfo;
Slava Shklyaevfeb87a92018-09-12 14:52:02 +010026
27// create device test
28TEST_F(NeuralnetworksHidlTest, CreateDevice) {}
29
30// status test
31TEST_F(NeuralnetworksHidlTest, StatusTest) {
32 Return<DeviceStatus> status = device->getStatus();
33 ASSERT_TRUE(status.isOk());
34 EXPECT_EQ(DeviceStatus::AVAILABLE, static_cast<DeviceStatus>(status));
35}
36
David Gross2d47c802019-03-15 17:26:32 -070037// initialization
38TEST_F(NeuralnetworksHidlTest, GetCapabilitiesTest) {
39 using OperandPerformance = Capabilities::OperandPerformance;
40 Return<void> ret = device->getCapabilities_1_2([](ErrorStatus status,
41 const Capabilities& capabilities) {
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 Wang618028b2018-09-20 11:35:42 -070062// device version test
63TEST_F(NeuralnetworksHidlTest, GetDeviceVersionStringTest) {
64 Return<void> ret = device->getVersionString([](ErrorStatus status, const hidl_string& version) {
65 EXPECT_EQ(ErrorStatus::NONE, status);
66 EXPECT_LT(0, version.size());
67 });
68 EXPECT_TRUE(ret.isOk());
69}
Miao Wang7176fe72018-09-20 13:30:31 -070070
71// device type test
72TEST_F(NeuralnetworksHidlTest, GetDeviceTypeTest) {
73 Return<void> ret = device->getType([](ErrorStatus status, DeviceType type) {
74 EXPECT_EQ(ErrorStatus::NONE, status);
75 EXPECT_TRUE(type == DeviceType::OTHER || type == DeviceType::CPU ||
76 type == DeviceType::GPU || type == DeviceType::ACCELERATOR);
77 });
78 EXPECT_TRUE(ret.isOk());
79}
Slava Shklyaevc9ff0992018-11-20 15:29:01 +000080
81// device supported extensions test
82TEST_F(NeuralnetworksHidlTest, GetDeviceSupportedExtensionsTest) {
83 Return<void> ret = device->getSupportedExtensions(
84 [](ErrorStatus status, const hidl_vec<Extension>& extensions) {
85 EXPECT_EQ(ErrorStatus::NONE, status);
86 for (auto& extension : extensions) {
87 std::string extensionName = extension.name;
88 EXPECT_FALSE(extensionName.empty());
Slava Shklyaev1d2cd432019-02-25 18:23:03 +000089 for (char c : extensionName) {
90 EXPECT_TRUE(('a' <= c && c <= 'z') || ('0' <= c && c <= '9') || c == '_' ||
91 c == '.')
92 << "Extension name contains an illegal character: " << c;
93 }
94 EXPECT_NE(extensionName.find('.'), std::string::npos)
Slava Shklyaevc9ff0992018-11-20 15:29:01 +000095 << "Extension name must start with the reverse domain name of the "
96 "vendor";
97 }
98 });
99 EXPECT_TRUE(ret.isOk());
100}
101
Xusong Wanged0822b2019-02-25 16:58:58 -0800102// getNumberOfCacheFilesNeeded test
103TEST_F(NeuralnetworksHidlTest, getNumberOfCacheFilesNeeded) {
104 Return<void> ret = device->getNumberOfCacheFilesNeeded(
105 [](ErrorStatus status, uint32_t numModelCache, uint32_t numDataCache) {
106 EXPECT_EQ(ErrorStatus::NONE, status);
107 EXPECT_LE(numModelCache,
108 static_cast<uint32_t>(Constant::MAX_NUMBER_OF_CACHE_FILES));
109 EXPECT_LE(numDataCache, static_cast<uint32_t>(Constant::MAX_NUMBER_OF_CACHE_FILES));
110 });
Xusong Wang96e68dc2019-01-18 17:28:26 -0800111 EXPECT_TRUE(ret.isOk());
112}
Michael Butler62749b92019-08-26 23:55:47 -0700113} // namespace android::hardware::neuralnetworks::V1_2::vts::functional