Slava Shklyaev | 1d6b465 | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 ANDROID_HARDWARE_NEURALNETWORKS_V1_2_GENERATED_TEST_HARNESS_H |
| 18 | #define ANDROID_HARDWARE_NEURALNETWORKS_V1_2_GENERATED_TEST_HARNESS_H |
| 19 | |
| 20 | #include <android/hardware/neuralnetworks/1.2/IDevice.h> |
| 21 | #include <android/hardware/neuralnetworks/1.2/IPreparedModel.h> |
| 22 | #include <android/hardware/neuralnetworks/1.2/types.h> |
| 23 | #include <functional> |
| 24 | #include <vector> |
| 25 | #include "TestHarness.h" |
Xusong Wang | 9e2b97b | 2019-08-23 16:10:54 -0700 | [diff] [blame] | 26 | #include "VtsHalNeuralnetworks.h" |
Slava Shklyaev | 1d6b465 | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 27 | |
Michael Butler | bbe5dad | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 28 | namespace android::hardware::neuralnetworks::V1_2::vts::functional { |
Xusong Wang | 9e2b97b | 2019-08-23 16:10:54 -0700 | [diff] [blame] | 29 | |
| 30 | class GeneratedTestBase |
| 31 | : public NeuralnetworksHidlTest, |
| 32 | public ::testing::WithParamInterface<test_helper::TestModelManager::TestParam> { |
| 33 | protected: |
| 34 | void SetUp() override { |
| 35 | NeuralnetworksHidlTest::SetUp(); |
| 36 | ASSERT_NE(mTestModel, nullptr); |
| 37 | } |
| 38 | |
| 39 | const test_helper::TestModel* mTestModel = GetParam().second; |
| 40 | }; |
| 41 | |
| 42 | #define INSTANTIATE_GENERATED_TEST(TestSuite, filter) \ |
| 43 | INSTANTIATE_TEST_SUITE_P( \ |
| 44 | TestGenerated, TestSuite, \ |
| 45 | ::testing::ValuesIn(::test_helper::TestModelManager::get().getTestModels(filter)), \ |
| 46 | [](const auto& info) { return info.param.first; }) |
| 47 | |
| 48 | // Tag for the validation tests, instantiated in VtsHalNeuralnetworks.cpp. |
| 49 | // TODO: Clean up the hierarchy for ValidationTest. |
| 50 | class ValidationTest : public GeneratedTestBase { |
| 51 | protected: |
Michael Butler | bbe5dad | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 52 | void validateEverything(const Model& model, const V1_0::Request& request); |
| 53 | void validateFailure(const Model& model, const V1_0::Request& request); |
Xusong Wang | 9e2b97b | 2019-08-23 16:10:54 -0700 | [diff] [blame] | 54 | |
| 55 | private: |
| 56 | void validateModel(const Model& model); |
Michael Butler | bbe5dad | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 57 | void validateRequest(const sp<IPreparedModel>& preparedModel, const V1_0::Request& request); |
| 58 | void validateRequestFailure(const sp<IPreparedModel>& preparedModel, |
| 59 | const V1_0::Request& request); |
| 60 | void validateBurst(const sp<IPreparedModel>& preparedModel, const V1_0::Request& request); |
Xusong Wang | 9e2b97b | 2019-08-23 16:10:54 -0700 | [diff] [blame] | 61 | }; |
Slava Shklyaev | 1d6b465 | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 62 | |
Xusong Wang | 491b0a8 | 2019-08-09 16:45:24 -0700 | [diff] [blame] | 63 | Model createModel(const ::test_helper::TestModel& testModel); |
Slava Shklyaev | 1d6b465 | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 64 | |
Michael Butler | bbe5dad | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 65 | void PrepareModel(const sp<IDevice>& device, const Model& model, sp<IPreparedModel>* preparedModel); |
Slava Shklyaev | 1d6b465 | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 66 | |
Michael Butler | bbe5dad | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 67 | void EvaluatePreparedModel(const sp<IPreparedModel>& preparedModel, |
Xusong Wang | 491b0a8 | 2019-08-09 16:45:24 -0700 | [diff] [blame] | 68 | const ::test_helper::TestModel& testModel, bool testDynamicOutputShape); |
Slava Shklyaev | 1d6b465 | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 69 | |
Michael Butler | bbe5dad | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 70 | } // namespace android::hardware::neuralnetworks::V1_2::vts::functional |
Slava Shklyaev | 1d6b465 | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 71 | |
| 72 | #endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_2_GENERATED_TEST_HARNESS_H |