blob: 065f7ef2b8552710f2bc66ef5fd6369b1dfb6c19 [file] [log] [blame]
Colin Crossb098d212019-10-10 22:58:36 +00001/*
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
Colin Cross552c7a62019-10-10 22:58:41 +000017#ifndef ANDROID_HARDWARE_NEURALNETWORKS_V1_3_GENERATED_TEST_HARNESS_H
18#define ANDROID_HARDWARE_NEURALNETWORKS_V1_3_GENERATED_TEST_HARNESS_H
Colin Crossb098d212019-10-10 22:58:36 +000019
Colin Cross552c7a62019-10-10 22:58:41 +000020#include <android/hardware/neuralnetworks/1.3/IDevice.h>
Xusong Wang62a760c2019-10-25 12:07:17 -070021#include <android/hardware/neuralnetworks/1.3/IPreparedModel.h>
Colin Cross552c7a62019-10-10 22:58:41 +000022#include <android/hardware/neuralnetworks/1.3/types.h>
Colin Crossb098d212019-10-10 22:58:36 +000023#include <functional>
24#include <vector>
25#include "1.0/Utils.h"
26#include "TestHarness.h"
27#include "VtsHalNeuralnetworks.h"
28
Colin Cross552c7a62019-10-10 22:58:41 +000029namespace android::hardware::neuralnetworks::V1_3::vts::functional {
Colin Crossb098d212019-10-10 22:58:36 +000030
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()));
39};
40
41using FilterFn = std::function<bool(const test_helper::TestModel&)>;
42std::vector<NamedModel> getNamedModels(const FilterFn& filter);
43
Michael Butler678a1062020-03-19 17:10:34 -070044using FilterNameFn = std::function<bool(const std::string&)>;
45std::vector<NamedModel> getNamedModels(const FilterNameFn& filter);
46
Colin Crossb098d212019-10-10 22:58:36 +000047std::string printGeneratedTest(const testing::TestParamInfo<GeneratedTestParam>& info);
48
49#define INSTANTIATE_GENERATED_TEST(TestSuite, filter) \
50 INSTANTIATE_TEST_SUITE_P(TestGenerated, TestSuite, \
51 testing::Combine(testing::ValuesIn(getNamedDevices()), \
52 testing::ValuesIn(getNamedModels(filter))), \
53 printGeneratedTest)
54
55// Tag for the validation tests, instantiated in VtsHalNeuralnetworks.cpp.
56// TODO: Clean up the hierarchy for ValidationTest.
57class ValidationTest : public GeneratedTestBase {};
58
59Model createModel(const test_helper::TestModel& testModel);
60
Xusong Wang62a760c2019-10-25 12:07:17 -070061void PrepareModel(const sp<IDevice>& device, const Model& model, sp<IPreparedModel>* preparedModel);
Colin Crossb098d212019-10-10 22:58:36 +000062
Lev Proleevc88f4c62019-10-03 14:43:18 +010063enum class TestKind {
64 // Runs a test model and compares the results to a golden data
65 GENERAL,
66 // Same as GENERAL but sets dimensions for the output tensors to zeros
67 DYNAMIC_SHAPE,
Xusong Wang1f50e542020-01-13 11:44:45 -080068 // Same as GENERAL but use device memories for inputs and outputs
69 MEMORY_DOMAIN,
Miao Wang33173a32020-01-23 13:53:21 -080070 // Same as GENERAL but use executeFenced for exeuction
71 FENCED_COMPUTE,
Lev Proleevc88f4c62019-10-03 14:43:18 +010072 // Tests if quantized model with TENSOR_QUANT8_ASYMM produces the same result
73 // (OK/SKIPPED/FAILED) as the model with all such tensors converted to
74 // TENSOR_QUANT8_ASYMM_SIGNED.
Slava Shklyaevcc873ae2020-02-18 16:11:32 +000075 QUANTIZATION_COUPLING,
76 // Runs a test model and verifies that MISSED_DEADLINE_* is returned.
77 INTINITE_LOOP_TIMEOUT
Lev Proleevc88f4c62019-10-03 14:43:18 +010078};
79
Xusong Wang1f50e542020-01-13 11:44:45 -080080void EvaluatePreparedModel(const sp<IDevice>& device, const sp<IPreparedModel>& preparedModel,
Lev Proleevc88f4c62019-10-03 14:43:18 +010081 const test_helper::TestModel& testModel, TestKind testKind);
Colin Crossb098d212019-10-10 22:58:36 +000082
Colin Cross552c7a62019-10-10 22:58:41 +000083} // namespace android::hardware::neuralnetworks::V1_3::vts::functional
Colin Crossb098d212019-10-10 22:58:36 +000084
Colin Cross552c7a62019-10-10 22:58:41 +000085#endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_3_GENERATED_TEST_HARNESS_H