Slava Shklyaev | 73ee79d | 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> |
Michael Butler | 0763328 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 25 | #include "1.0/Utils.h" |
Slava Shklyaev | 73ee79d | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 26 | #include "TestHarness.h" |
Xusong Wang | bcaa782 | 2019-08-23 16:10:54 -0700 | [diff] [blame] | 27 | #include "VtsHalNeuralnetworks.h" |
Slava Shklyaev | 73ee79d | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 28 | |
Michael Butler | 62749b9 | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 29 | namespace android::hardware::neuralnetworks::V1_2::vts::functional { |
Xusong Wang | bcaa782 | 2019-08-23 16:10:54 -0700 | [diff] [blame] | 30 | |
Michael Butler | 0763328 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 31 | using NamedModel = Named<const test_helper::TestModel*>; |
| 32 | using GeneratedTestParam = std::tuple<NamedDevice, NamedModel>; |
| 33 | |
| 34 | class GeneratedTestBase : public testing::TestWithParam<GeneratedTestParam> { |
Xusong Wang | bcaa782 | 2019-08-23 16:10:54 -0700 | [diff] [blame] | 35 | protected: |
Michael Butler | 0763328 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 36 | void SetUp() override; |
| 37 | const sp<IDevice> kDevice = getData(std::get<NamedDevice>(GetParam())); |
| 38 | const test_helper::TestModel& kTestModel = *getData(std::get<NamedModel>(GetParam())); |
Xusong Wang | bcaa782 | 2019-08-23 16:10:54 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
Michael Butler | 0763328 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 41 | using FilterFn = std::function<bool(const test_helper::TestModel&)>; |
| 42 | std::vector<NamedModel> getNamedModels(const FilterFn& filter); |
| 43 | |
Michael Butler | b1865b6 | 2020-03-19 17:10:34 -0700 | [diff] [blame] | 44 | using FilterNameFn = std::function<bool(const std::string&)>; |
| 45 | std::vector<NamedModel> getNamedModels(const FilterNameFn& filter); |
| 46 | |
Michael Butler | 0763328 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 47 | std::string printGeneratedTest(const testing::TestParamInfo<GeneratedTestParam>& info); |
| 48 | |
| 49 | #define INSTANTIATE_GENERATED_TEST(TestSuite, filter) \ |
Dan Shi | ba4d532 | 2020-07-28 13:09:30 -0700 | [diff] [blame] | 50 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TestSuite); \ |
Michael Butler | 0763328 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 51 | INSTANTIATE_TEST_SUITE_P(TestGenerated, TestSuite, \ |
| 52 | testing::Combine(testing::ValuesIn(getNamedDevices()), \ |
| 53 | testing::ValuesIn(getNamedModels(filter))), \ |
| 54 | printGeneratedTest) |
Xusong Wang | bcaa782 | 2019-08-23 16:10:54 -0700 | [diff] [blame] | 55 | |
| 56 | // Tag for the validation tests, instantiated in VtsHalNeuralnetworks.cpp. |
| 57 | // TODO: Clean up the hierarchy for ValidationTest. |
Michael Butler | 13b0516 | 2019-08-29 22:17:24 -0700 | [diff] [blame] | 58 | class ValidationTest : public GeneratedTestBase {}; |
Slava Shklyaev | 73ee79d | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 59 | |
Michael Butler | 0763328 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 60 | Model createModel(const test_helper::TestModel& testModel); |
Slava Shklyaev | 73ee79d | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 61 | |
Michael Butler | 62749b9 | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 62 | void PrepareModel(const sp<IDevice>& device, const Model& model, sp<IPreparedModel>* preparedModel); |
Slava Shklyaev | 73ee79d | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 63 | |
Michael Butler | 62749b9 | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 64 | void EvaluatePreparedModel(const sp<IPreparedModel>& preparedModel, |
Michael Butler | 0763328 | 2019-08-29 11:08:25 -0700 | [diff] [blame] | 65 | const test_helper::TestModel& testModel, bool testDynamicOutputShape); |
Slava Shklyaev | 73ee79d | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 66 | |
Michael Butler | 62749b9 | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 67 | } // namespace android::hardware::neuralnetworks::V1_2::vts::functional |
Slava Shklyaev | 73ee79d | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 68 | |
| 69 | #endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_2_GENERATED_TEST_HARNESS_H |