Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +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 | |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 17 | #ifndef ANDROID_HARDWARE_NEURALNETWORKS_V1_3_GENERATED_TEST_HARNESS_H |
| 18 | #define ANDROID_HARDWARE_NEURALNETWORKS_V1_3_GENERATED_TEST_HARNESS_H |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 19 | |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 20 | #include <android/hardware/neuralnetworks/1.3/IDevice.h> |
Xusong Wang | 1b3f426 | 2019-10-25 12:07:17 -0700 | [diff] [blame] | 21 | #include <android/hardware/neuralnetworks/1.3/IPreparedModel.h> |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 22 | #include <android/hardware/neuralnetworks/1.3/types.h> |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 23 | #include <functional> |
| 24 | #include <vector> |
| 25 | #include "1.0/Utils.h" |
| 26 | #include "TestHarness.h" |
| 27 | #include "VtsHalNeuralnetworks.h" |
| 28 | |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 29 | namespace android::hardware::neuralnetworks::V1_3::vts::functional { |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 30 | |
| 31 | using NamedModel = Named<const test_helper::TestModel*>; |
| 32 | using GeneratedTestParam = std::tuple<NamedDevice, NamedModel>; |
| 33 | |
| 34 | class GeneratedTestBase : public testing::TestWithParam<GeneratedTestParam> { |
| 35 | protected: |
| 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())); |
| 39 | }; |
| 40 | |
| 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 | |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [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); \ |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 51 | INSTANTIATE_TEST_SUITE_P(TestGenerated, TestSuite, \ |
| 52 | testing::Combine(testing::ValuesIn(getNamedDevices()), \ |
| 53 | testing::ValuesIn(getNamedModels(filter))), \ |
| 54 | printGeneratedTest) |
| 55 | |
| 56 | // Tag for the validation tests, instantiated in VtsHalNeuralnetworks.cpp. |
| 57 | // TODO: Clean up the hierarchy for ValidationTest. |
| 58 | class ValidationTest : public GeneratedTestBase {}; |
| 59 | |
| 60 | Model createModel(const test_helper::TestModel& testModel); |
| 61 | |
Xusong Wang | 1b3f426 | 2019-10-25 12:07:17 -0700 | [diff] [blame] | 62 | void PrepareModel(const sp<IDevice>& device, const Model& model, sp<IPreparedModel>* preparedModel); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 63 | |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 64 | enum class TestKind { |
| 65 | // Runs a test model and compares the results to a golden data |
| 66 | GENERAL, |
| 67 | // Same as GENERAL but sets dimensions for the output tensors to zeros |
| 68 | DYNAMIC_SHAPE, |
Xusong Wang | e9da985 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 69 | // Same as GENERAL but use device memories for inputs and outputs |
| 70 | MEMORY_DOMAIN, |
Miao Wang | e51e4a9 | 2020-01-23 13:53:21 -0800 | [diff] [blame] | 71 | // Same as GENERAL but use executeFenced for exeuction |
| 72 | FENCED_COMPUTE, |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 73 | // Tests if quantized model with TENSOR_QUANT8_ASYMM produces the same result |
| 74 | // (OK/SKIPPED/FAILED) as the model with all such tensors converted to |
| 75 | // TENSOR_QUANT8_ASYMM_SIGNED. |
Slava Shklyaev | a37c2c8 | 2020-02-18 16:11:32 +0000 | [diff] [blame] | 76 | QUANTIZATION_COUPLING, |
| 77 | // Runs a test model and verifies that MISSED_DEADLINE_* is returned. |
| 78 | INTINITE_LOOP_TIMEOUT |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 79 | }; |
| 80 | |
Xusong Wang | e9da985 | 2020-01-13 11:44:45 -0800 | [diff] [blame] | 81 | void EvaluatePreparedModel(const sp<IDevice>& device, const sp<IPreparedModel>& preparedModel, |
Lev Proleev | 9226c1e | 2019-10-03 14:43:18 +0100 | [diff] [blame] | 82 | const test_helper::TestModel& testModel, TestKind testKind); |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 83 | |
Xusong Wang | 2844165 | 2020-03-20 14:49:54 -0700 | [diff] [blame] | 84 | void waitForSyncFence(int syncFd); |
| 85 | |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 86 | } // namespace android::hardware::neuralnetworks::V1_3::vts::functional |
Lev Proleev | 13fdfcd | 2019-08-30 11:35:34 +0100 | [diff] [blame] | 87 | |
Lev Proleev | 26d1bc8 | 2019-08-30 11:57:18 +0100 | [diff] [blame] | 88 | #endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_3_GENERATED_TEST_HARNESS_H |