blob: 1c2536983e46c4283e5025c39bb8db76cda23ba2 [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
Colin Cross552c7a62019-10-10 22:58:41 +000021namespace android::hardware::neuralnetworks::V1_3::vts::functional {
Colin Crossb098d212019-10-10 22:58:36 +000022
23using V1_0::DeviceStatus;
Colin Crossb098d212019-10-10 22:58:36 +000024using V1_0::PerformanceInfo;
Colin Cross552c7a62019-10-10 22:58:41 +000025using V1_2::Constant;
26using V1_2::DeviceType;
27using V1_2::Extension;
Colin Crossb098d212019-10-10 22:58:36 +000028
29// create device test
30TEST_P(NeuralnetworksHidlTest, CreateDevice) {}
31
32// status test
33TEST_P(NeuralnetworksHidlTest, StatusTest) {
34 Return<DeviceStatus> status = kDevice->getStatus();
35 ASSERT_TRUE(status.isOk());
36 EXPECT_EQ(DeviceStatus::AVAILABLE, static_cast<DeviceStatus>(status));
37}
38
39// initialization
40TEST_P(NeuralnetworksHidlTest, GetCapabilitiesTest) {
41 using OperandPerformance = Capabilities::OperandPerformance;
Colin Cross552c7a62019-10-10 22:58:41 +000042 Return<void> ret = kDevice->getCapabilities_1_3([](ErrorStatus status,
Colin Crossb098d212019-10-10 22:58:36 +000043 const Capabilities& capabilities) {
44 EXPECT_EQ(ErrorStatus::NONE, status);
45
46 auto isPositive = [](const PerformanceInfo& perf) {
47 return perf.execTime > 0.0f && perf.powerUsage > 0.0f;
48 };
49
50 EXPECT_TRUE(isPositive(capabilities.relaxedFloat32toFloat16PerformanceScalar));
51 EXPECT_TRUE(isPositive(capabilities.relaxedFloat32toFloat16PerformanceTensor));
52 const auto& opPerf = capabilities.operandPerformance;
53 EXPECT_TRUE(std::all_of(
54 opPerf.begin(), opPerf.end(),
55 [isPositive](const OperandPerformance& a) { return isPositive(a.info); }));
56 EXPECT_TRUE(std::is_sorted(opPerf.begin(), opPerf.end(),
57 [](const OperandPerformance& a, const OperandPerformance& b) {
58 return a.type < b.type;
59 }));
Slava Shklyaev8a9b3062020-01-21 11:38:47 +000060 EXPECT_TRUE(std::all_of(opPerf.begin(), opPerf.end(), [](const OperandPerformance& a) {
61 return a.type != OperandType::SUBGRAPH;
62 }));
63 EXPECT_TRUE(isPositive(capabilities.ifPerformance));
64 EXPECT_TRUE(isPositive(capabilities.whilePerformance));
Colin Crossb098d212019-10-10 22:58:36 +000065 });
66 EXPECT_TRUE(ret.isOk());
67}
Colin Cross552c7a62019-10-10 22:58:41 +000068} // namespace android::hardware::neuralnetworks::V1_3::vts::functional