blob: 8e82c5376e82dfa14f86c10ea5d0de60605a074b [file] [log] [blame]
Colin Crossb098d212019-10-10 22:58:36 +00001/*
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
21namespace android::hardware::neuralnetworks::V1_2::vts::functional {
22
23using V1_0::DeviceStatus;
24using V1_0::ErrorStatus;
25using V1_0::PerformanceInfo;
26
27// create device test
28TEST_P(NeuralnetworksHidlTest, CreateDevice) {}
29
30// status test
31TEST_P(NeuralnetworksHidlTest, StatusTest) {
32 Return<DeviceStatus> status = kDevice->getStatus();
33 ASSERT_TRUE(status.isOk());
34 EXPECT_EQ(DeviceStatus::AVAILABLE, static_cast<DeviceStatus>(status));
35}
36
37// initialization
38TEST_P(NeuralnetworksHidlTest, GetCapabilitiesTest) {
39 using OperandPerformance = Capabilities::OperandPerformance;
40 Return<void> ret = kDevice->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
62// device version test
63TEST_P(NeuralnetworksHidlTest, GetDeviceVersionStringTest) {
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 });
69 EXPECT_TRUE(ret.isOk());
70}
71
72// device type test
73TEST_P(NeuralnetworksHidlTest, GetDeviceTypeTest) {
74 Return<void> ret = kDevice->getType([](ErrorStatus status, DeviceType type) {
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}
81
82// device supported extensions test
83TEST_P(NeuralnetworksHidlTest, GetDeviceSupportedExtensionsTest) {
84 Return<void> ret = kDevice->getSupportedExtensions(
85 [](ErrorStatus status, const hidl_vec<Extension>& extensions) {
86 EXPECT_EQ(ErrorStatus::NONE, status);
87 for (auto& extension : extensions) {
88 std::string extensionName = extension.name;
89 EXPECT_FALSE(extensionName.empty());
90 for (char c : extensionName) {
91 EXPECT_TRUE(('a' <= c && c <= 'z') || ('0' <= c && c <= '9') || c == '_' ||
92 c == '.')
93 << "Extension name contains an illegal character: " << c;
94 }
95 EXPECT_NE(extensionName.find('.'), std::string::npos)
96 << "Extension name must start with the reverse domain name of the "
97 "vendor";
98 }
99 });
100 EXPECT_TRUE(ret.isOk());
101}
102
103// getNumberOfCacheFilesNeeded test
104TEST_P(NeuralnetworksHidlTest, getNumberOfCacheFilesNeeded) {
105 Return<void> ret = kDevice->getNumberOfCacheFilesNeeded(
106 [](ErrorStatus status, uint32_t numModelCache, uint32_t numDataCache) {
107 EXPECT_EQ(ErrorStatus::NONE, status);
108 EXPECT_LE(numModelCache,
109 static_cast<uint32_t>(Constant::MAX_NUMBER_OF_CACHE_FILES));
110 EXPECT_LE(numDataCache, static_cast<uint32_t>(Constant::MAX_NUMBER_OF_CACHE_FILES));
111 });
112 EXPECT_TRUE(ret.isOk());
113}
114} // namespace android::hardware::neuralnetworks::V1_2::vts::functional