blob: e597fac7cfbce66259e2f604dd12c5adc92d3922 [file] [log] [blame]
Lev Proleev13fdfcd2019-08-30 11:35:34 +01001/*
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 Proleev26d1bc82019-08-30 11:57:18 +010017#ifndef ANDROID_HARDWARE_NEURALNETWORKS_V1_3_GENERATED_TEST_HARNESS_H
18#define ANDROID_HARDWARE_NEURALNETWORKS_V1_3_GENERATED_TEST_HARNESS_H
Lev Proleev13fdfcd2019-08-30 11:35:34 +010019
Lev Proleev26d1bc82019-08-30 11:57:18 +010020#include <android/hardware/neuralnetworks/1.3/IDevice.h>
Xusong Wang1b3f4262019-10-25 12:07:17 -070021#include <android/hardware/neuralnetworks/1.3/IPreparedModel.h>
Lev Proleev26d1bc82019-08-30 11:57:18 +010022#include <android/hardware/neuralnetworks/1.3/types.h>
Lev Proleev13fdfcd2019-08-30 11:35:34 +010023#include <functional>
24#include <vector>
25#include "1.0/Utils.h"
26#include "TestHarness.h"
27#include "VtsHalNeuralnetworks.h"
28
Lev Proleev26d1bc82019-08-30 11:57:18 +010029namespace android::hardware::neuralnetworks::V1_3::vts::functional {
Lev Proleev13fdfcd2019-08-30 11:35:34 +010030
31using NamedModel = Named<const test_helper::TestModel*>;
32using GeneratedTestParam = std::tuple<NamedDevice, NamedModel>;
33
34class 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()));
Michael Butler95899b32020-01-07 14:52:44 -080039 std::pair<bool, bool> mSupportsDeadlines;
Lev Proleev13fdfcd2019-08-30 11:35:34 +010040};
41
42using FilterFn = std::function<bool(const test_helper::TestModel&)>;
43std::vector<NamedModel> getNamedModels(const FilterFn& filter);
44
45std::string printGeneratedTest(const testing::TestParamInfo<GeneratedTestParam>& info);
46
47#define INSTANTIATE_GENERATED_TEST(TestSuite, filter) \
48 INSTANTIATE_TEST_SUITE_P(TestGenerated, TestSuite, \
49 testing::Combine(testing::ValuesIn(getNamedDevices()), \
50 testing::ValuesIn(getNamedModels(filter))), \
51 printGeneratedTest)
52
53// Tag for the validation tests, instantiated in VtsHalNeuralnetworks.cpp.
54// TODO: Clean up the hierarchy for ValidationTest.
55class ValidationTest : public GeneratedTestBase {};
56
57Model createModel(const test_helper::TestModel& testModel);
58
Xusong Wang1b3f4262019-10-25 12:07:17 -070059void PrepareModel(const sp<IDevice>& device, const Model& model, sp<IPreparedModel>* preparedModel);
Lev Proleev13fdfcd2019-08-30 11:35:34 +010060
Lev Proleev9226c1e2019-10-03 14:43:18 +010061enum class TestKind {
62 // Runs a test model and compares the results to a golden data
63 GENERAL,
64 // Same as GENERAL but sets dimensions for the output tensors to zeros
65 DYNAMIC_SHAPE,
Xusong Wange9da9852020-01-13 11:44:45 -080066 // Same as GENERAL but use device memories for inputs and outputs
67 MEMORY_DOMAIN,
Miao Wange51e4a92020-01-23 13:53:21 -080068 // Same as GENERAL but use executeFenced for exeuction
69 FENCED_COMPUTE,
Lev Proleev9226c1e2019-10-03 14:43:18 +010070 // Tests if quantized model with TENSOR_QUANT8_ASYMM produces the same result
71 // (OK/SKIPPED/FAILED) as the model with all such tensors converted to
72 // TENSOR_QUANT8_ASYMM_SIGNED.
73 QUANTIZATION_COUPLING
74};
75
Xusong Wange9da9852020-01-13 11:44:45 -080076void EvaluatePreparedModel(const sp<IDevice>& device, const sp<IPreparedModel>& preparedModel,
Lev Proleev9226c1e2019-10-03 14:43:18 +010077 const test_helper::TestModel& testModel, TestKind testKind);
Lev Proleev13fdfcd2019-08-30 11:35:34 +010078
Lev Proleev26d1bc82019-08-30 11:57:18 +010079} // namespace android::hardware::neuralnetworks::V1_3::vts::functional
Lev Proleev13fdfcd2019-08-30 11:35:34 +010080
Lev Proleev26d1bc82019-08-30 11:57:18 +010081#endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_3_GENERATED_TEST_HARNESS_H