blob: 27208ce4b6b97c0aaa56562793eee56940a1f3d3 [file] [log] [blame]
Slava Shklyaev73ee79d2019-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>
25#include "TestHarness.h"
Xusong Wangbcaa7822019-08-23 16:10:54 -070026#include "VtsHalNeuralnetworks.h"
Slava Shklyaev73ee79d2019-05-14 14:15:14 +010027
28namespace android {
29namespace hardware {
30namespace neuralnetworks {
Slava Shklyaeve8b24462019-07-17 15:50:57 +010031namespace V1_2 {
Xusong Wangbcaa7822019-08-23 16:10:54 -070032namespace vts {
33namespace functional {
34
35class GeneratedTestBase
36 : public NeuralnetworksHidlTest,
37 public ::testing::WithParamInterface<test_helper::TestModelManager::TestParam> {
38 protected:
39 void SetUp() override {
40 NeuralnetworksHidlTest::SetUp();
41 ASSERT_NE(mTestModel, nullptr);
42 }
43
44 const test_helper::TestModel* mTestModel = GetParam().second;
45};
46
47#define INSTANTIATE_GENERATED_TEST(TestSuite, filter) \
48 INSTANTIATE_TEST_SUITE_P( \
49 TestGenerated, TestSuite, \
50 ::testing::ValuesIn(::test_helper::TestModelManager::get().getTestModels(filter)), \
51 [](const auto& info) { return info.param.first; })
52
53// Tag for the validation tests, instantiated in VtsHalNeuralnetworks.cpp.
54// TODO: Clean up the hierarchy for ValidationTest.
55class ValidationTest : public GeneratedTestBase {
56 protected:
57 void validateEverything(const Model& model, const Request& request);
58 void validateFailure(const Model& model, const Request& request);
59
60 private:
61 void validateModel(const Model& model);
62 void validateRequest(const sp<IPreparedModel>& preparedModel, const Request& request);
63 void validateRequestFailure(const sp<IPreparedModel>& preparedModel, const Request& request);
64 void validateBurst(const sp<IPreparedModel>& preparedModel, const Request& request);
65};
Slava Shklyaev73ee79d2019-05-14 14:15:14 +010066
Xusong Wangead950d2019-08-09 16:45:24 -070067Model createModel(const ::test_helper::TestModel& testModel);
Slava Shklyaev73ee79d2019-05-14 14:15:14 +010068
69void PrepareModel(const sp<V1_2::IDevice>& device, const V1_2::Model& model,
70 sp<V1_2::IPreparedModel>* preparedModel);
71
Xusong Wangead950d2019-08-09 16:45:24 -070072void EvaluatePreparedModel(const sp<V1_2::IPreparedModel>& preparedModel,
73 const ::test_helper::TestModel& testModel, bool testDynamicOutputShape);
Slava Shklyaev73ee79d2019-05-14 14:15:14 +010074
Xusong Wangbcaa7822019-08-23 16:10:54 -070075} // namespace functional
76} // namespace vts
Slava Shklyaeve8b24462019-07-17 15:50:57 +010077} // namespace V1_2
Slava Shklyaev73ee79d2019-05-14 14:15:14 +010078} // namespace neuralnetworks
79} // namespace hardware
80} // namespace android
81
82#endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_2_GENERATED_TEST_HARNESS_H