blob: 61aa5716fe5e1732e62a778743214534220c27c5 [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
21namespace android {
22namespace hardware {
23namespace neuralnetworks {
24namespace V1_2 {
25namespace vts {
26namespace functional {
27
David Gross2d47c802019-03-15 17:26:32 -070028using V1_0::PerformanceInfo;
Slava Shklyaevfeb87a92018-09-12 14:52:02 +010029
30// create device test
31TEST_F(NeuralnetworksHidlTest, CreateDevice) {}
32
33// status test
34TEST_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 Gross2d47c802019-03-15 17:26:32 -070040// initialization
41TEST_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 Wang618028b2018-09-20 11:35:42 -070065// device version test
66TEST_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 Wang7176fe72018-09-20 13:30:31 -070073
74// device type test
75TEST_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 Shklyaevc9ff0992018-11-20 15:29:01 +000083
84// device supported extensions test
85TEST_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 Shklyaev1d2cd432019-02-25 18:23:03 +000092 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 Shklyaevc9ff0992018-11-20 15:29:01 +000098 << "Extension name must start with the reverse domain name of the "
99 "vendor";
100 }
101 });
102 EXPECT_TRUE(ret.isOk());
103}
104
Xusong Wang96e68dc2019-01-18 17:28:26 -0800105// isCachingSupported test
106TEST_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 Shklyaevfeb87a92018-09-12 14:52:02 +0100111} // namespace functional
112} // namespace vts
113} // namespace V1_2
114} // namespace neuralnetworks
115} // namespace hardware
116} // namespace android