blob: dfc980c16940639eb54e45262827d1788a7c6297 [file] [log] [blame]
Slava Shklyaev1d6b4652019-05-14 14:15:14 +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
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 Butler7076f622019-08-29 11:08:25 -070025#include "1.0/Utils.h"
Slava Shklyaev1d6b4652019-05-14 14:15:14 +010026#include "TestHarness.h"
Xusong Wang9e2b97b2019-08-23 16:10:54 -070027#include "VtsHalNeuralnetworks.h"
Slava Shklyaev1d6b4652019-05-14 14:15:14 +010028
Michael Butlerbbe5dad2019-08-26 23:55:47 -070029namespace android::hardware::neuralnetworks::V1_2::vts::functional {
Xusong Wang9e2b97b2019-08-23 16:10:54 -070030
Michael Butler7076f622019-08-29 11:08:25 -070031using NamedModel = Named<const test_helper::TestModel*>;
32using GeneratedTestParam = std::tuple<NamedDevice, NamedModel>;
33
34class GeneratedTestBase : public testing::TestWithParam<GeneratedTestParam> {
Xusong Wang9e2b97b2019-08-23 16:10:54 -070035 protected:
Michael Butler7076f622019-08-29 11:08:25 -070036 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 Wang9e2b97b2019-08-23 16:10:54 -070039};
40
Michael Butler7076f622019-08-29 11:08:25 -070041using FilterFn = std::function<bool(const test_helper::TestModel&)>;
42std::vector<NamedModel> getNamedModels(const FilterFn& filter);
43
44std::string printGeneratedTest(const testing::TestParamInfo<GeneratedTestParam>& info);
45
46#define INSTANTIATE_GENERATED_TEST(TestSuite, filter) \
47 INSTANTIATE_TEST_SUITE_P(TestGenerated, TestSuite, \
48 testing::Combine(testing::ValuesIn(getNamedDevices()), \
49 testing::ValuesIn(getNamedModels(filter))), \
50 printGeneratedTest)
Xusong Wang9e2b97b2019-08-23 16:10:54 -070051
52// Tag for the validation tests, instantiated in VtsHalNeuralnetworks.cpp.
53// TODO: Clean up the hierarchy for ValidationTest.
Michael Butlere16af0a2019-08-29 22:17:24 -070054class ValidationTest : public GeneratedTestBase {};
Slava Shklyaev1d6b4652019-05-14 14:15:14 +010055
Michael Butler7076f622019-08-29 11:08:25 -070056Model createModel(const test_helper::TestModel& testModel);
Slava Shklyaev1d6b4652019-05-14 14:15:14 +010057
Michael Butlerbbe5dad2019-08-26 23:55:47 -070058void PrepareModel(const sp<IDevice>& device, const Model& model, sp<IPreparedModel>* preparedModel);
Slava Shklyaev1d6b4652019-05-14 14:15:14 +010059
Michael Butlerbbe5dad2019-08-26 23:55:47 -070060void EvaluatePreparedModel(const sp<IPreparedModel>& preparedModel,
Michael Butler7076f622019-08-29 11:08:25 -070061 const test_helper::TestModel& testModel, bool testDynamicOutputShape);
Slava Shklyaev1d6b4652019-05-14 14:15:14 +010062
Michael Butlerbbe5dad2019-08-26 23:55:47 -070063} // namespace android::hardware::neuralnetworks::V1_2::vts::functional
Slava Shklyaev1d6b4652019-05-14 14:15:14 +010064
65#endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_2_GENERATED_TEST_HARNESS_H