blob: da74db962e9c09dd1191616b8db19738a68c1e95 [file] [log] [blame]
Lev Proleevc185e882020-12-15 19:25:32 +00001/*
2 * Copyright (C) 2021 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_AIDL_GENERATED_TEST_HARNESS_H
18#define ANDROID_HARDWARE_NEURALNETWORKS_AIDL_GENERATED_TEST_HARNESS_H
19
20#include <functional>
21#include <vector>
22
23#include <TestHarness.h>
24#include "Utils.h"
25#include "VtsHalNeuralnetworks.h"
26
27namespace aidl::android::hardware::neuralnetworks::vts::functional {
28
29using NamedModel = Named<const test_helper::TestModel*>;
30using GeneratedTestParam = std::tuple<NamedDevice, NamedModel>;
31
32class GeneratedTestBase : public testing::TestWithParam<GeneratedTestParam> {
33 protected:
34 void SetUp() override;
35 const std::shared_ptr<IDevice> kDevice = getData(std::get<NamedDevice>(GetParam()));
36 const test_helper::TestModel& kTestModel = *getData(std::get<NamedModel>(GetParam()));
Ian Huaca46f972021-10-15 11:06:31 +010037
38 private:
39 void SkipIfDriverOlderThanTestModel();
Lev Proleevc185e882020-12-15 19:25:32 +000040};
41
42using FilterFn = std::function<bool(const test_helper::TestModel&)>;
43std::vector<NamedModel> getNamedModels(const FilterFn& filter);
44
45using FilterNameFn = std::function<bool(const std::string&)>;
46std::vector<NamedModel> getNamedModels(const FilterNameFn& filter);
47
48std::string printGeneratedTest(const testing::TestParamInfo<GeneratedTestParam>& info);
49
50#define INSTANTIATE_GENERATED_TEST(TestSuite, filter) \
51 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TestSuite); \
52 INSTANTIATE_TEST_SUITE_P(TestGenerated, TestSuite, \
53 testing::Combine(testing::ValuesIn(getNamedDevices()), \
54 testing::ValuesIn(getNamedModels(filter))), \
55 printGeneratedTest)
56
57// Tag for the validation tests, instantiated in VtsHalNeuralnetworks.cpp.
58// TODO: Clean up the hierarchy for ValidationTest.
59class ValidationTest : public GeneratedTestBase {};
60
61Model createModel(const test_helper::TestModel& testModel);
62
63void PrepareModel(const std::shared_ptr<IDevice>& device, const Model& model,
64 std::shared_ptr<IPreparedModel>* preparedModel);
65
66enum class TestKind {
67 // Runs a test model and compares the results to a golden data
68 GENERAL,
69 // Same as GENERAL but sets dimensions for the output tensors to zeros
70 DYNAMIC_SHAPE,
71 // Same as GENERAL but use device memories for inputs and outputs
72 MEMORY_DOMAIN,
73 // Same as GENERAL but use executeFenced for exeuction
74 FENCED_COMPUTE,
75 // Tests if quantized model with TENSOR_QUANT8_ASYMM produces the same result
76 // (OK/SKIPPED/FAILED) as the model with all such tensors converted to
77 // TENSOR_QUANT8_ASYMM_SIGNED.
78 QUANTIZATION_COUPLING,
79 // Runs a test model and verifies that MISSED_DEADLINE_* is returned.
80 INTINITE_LOOP_TIMEOUT
81};
82
83void EvaluatePreparedModel(const std::shared_ptr<IDevice>& device,
84 const std::shared_ptr<IPreparedModel>& preparedModel,
85 const test_helper::TestModel& testModel, TestKind testKind);
86
87void waitForSyncFence(int syncFd);
88
89} // namespace aidl::android::hardware::neuralnetworks::vts::functional
90
91#endif // ANDROID_HARDWARE_NEURALNETWORKS_AIDL_GENERATED_TEST_HARNESS_H