Colin Cross | b098d21 | 2019-10-10 22:58:36 +0000 | [diff] [blame] | 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 | |
Colin Cross | 552c7a6 | 2019-10-10 22:58:41 +0000 | [diff] [blame] | 21 | namespace android::hardware::neuralnetworks::V1_3::vts::functional { |
Colin Cross | b098d21 | 2019-10-10 22:58:36 +0000 | [diff] [blame] | 22 | |
| 23 | using V1_0::DeviceStatus; |
Colin Cross | b098d21 | 2019-10-10 22:58:36 +0000 | [diff] [blame] | 24 | using V1_0::PerformanceInfo; |
Colin Cross | 552c7a6 | 2019-10-10 22:58:41 +0000 | [diff] [blame] | 25 | using V1_2::Constant; |
| 26 | using V1_2::DeviceType; |
| 27 | using V1_2::Extension; |
Colin Cross | b098d21 | 2019-10-10 22:58:36 +0000 | [diff] [blame] | 28 | |
| 29 | // create device test |
| 30 | TEST_P(NeuralnetworksHidlTest, CreateDevice) {} |
| 31 | |
| 32 | // status test |
| 33 | TEST_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 |
| 40 | TEST_P(NeuralnetworksHidlTest, GetCapabilitiesTest) { |
| 41 | using OperandPerformance = Capabilities::OperandPerformance; |
Colin Cross | 552c7a6 | 2019-10-10 22:58:41 +0000 | [diff] [blame] | 42 | Return<void> ret = kDevice->getCapabilities_1_3([](ErrorStatus status, |
Colin Cross | b098d21 | 2019-10-10 22:58:36 +0000 | [diff] [blame] | 43 | 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 Shklyaev | 8a9b306 | 2020-01-21 11:38:47 +0000 | [diff] [blame] | 60 | 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 Cross | b098d21 | 2019-10-10 22:58:36 +0000 | [diff] [blame] | 65 | }); |
| 66 | EXPECT_TRUE(ret.isOk()); |
| 67 | } |
Colin Cross | 552c7a6 | 2019-10-10 22:58:41 +0000 | [diff] [blame] | 68 | } // namespace android::hardware::neuralnetworks::V1_3::vts::functional |