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 #ifndef VTS_HAL_NEURALNETWORKS_V1_2_H 18 #define VTS_HAL_NEURALNETWORKS_V1_2_H 19 20 #include "Callbacks.h" 21 22 #include <android/hardware/neuralnetworks/1.0/types.h> 23 #include <android/hardware/neuralnetworks/1.1/types.h> 24 #include <android/hardware/neuralnetworks/1.2/IDevice.h> 25 #include <android/hardware/neuralnetworks/1.2/types.h> 26 27 #include <VtsHalHidlTargetTestBase.h> 28 #include <VtsHalHidlTargetTestEnvBase.h> 29 30 #include <android-base/macros.h> 31 #include <gtest/gtest.h> 32 #include <iostream> 33 #include <vector> 34 35 namespace android { 36 namespace hardware { 37 namespace neuralnetworks { 38 namespace V1_2 { 39 40 using V1_0::DeviceStatus; 41 using V1_0::ErrorStatus; 42 using V1_0::Request; 43 44 namespace vts { 45 namespace functional { 46 47 // A class for test environment setup 48 class NeuralnetworksHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { 49 DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlEnvironment); 50 NeuralnetworksHidlEnvironment(); 51 ~NeuralnetworksHidlEnvironment() override; 52 53 public: 54 static NeuralnetworksHidlEnvironment* getInstance(); 55 void registerTestServices() override; 56 }; 57 58 // The main test class for NEURALNETWORKS HIDL HAL. 59 class NeuralnetworksHidlTest : public ::testing::VtsHalHidlTargetTestBase { 60 DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlTest); 61 62 public: 63 NeuralnetworksHidlTest(); 64 ~NeuralnetworksHidlTest() override; 65 void SetUp() override; 66 void TearDown() override; 67 68 protected: 69 sp<IDevice> device; 70 }; 71 72 // Tag for the validation tests 73 class ValidationTest : public NeuralnetworksHidlTest { 74 protected: 75 void validateEverything(const Model& model, const std::vector<Request>& requests); 76 77 private: 78 void validateModel(const Model& model); 79 void validateRequests(const sp<IPreparedModel>& preparedModel, 80 const std::vector<Request>& requests); 81 void validateBurst(const sp<IPreparedModel>& preparedModel, 82 const std::vector<Request>& requests); 83 }; 84 85 // Tag for the generated tests 86 class GeneratedTest : public NeuralnetworksHidlTest {}; 87 88 // Tag for the dynamic output shape tests 89 class DynamicOutputShapeTest : public NeuralnetworksHidlTest {}; 90 91 // Utility function to get PreparedModel from callback and downcast to V1_2. 92 sp<IPreparedModel> getPreparedModel_1_2( 93 const sp<V1_2::implementation::PreparedModelCallback>& callback); 94 95 } // namespace functional 96 } // namespace vts 97 } // namespace V1_2 98 } // namespace neuralnetworks 99 } // namespace hardware 100 } // namespace android 101 102 namespace android::hardware::neuralnetworks::V1_0 { 103 104 // pretty-print values for error messages 105 ::std::ostream& operator<<(::std::ostream& os, ErrorStatus errorStatus); 106 ::std::ostream& operator<<(::std::ostream& os, DeviceStatus deviceStatus); 107 108 } // namespace android::hardware::neuralnetworks::V1_0 109 110 #endif // VTS_HAL_NEURALNETWORKS_V1_2_H 111