summaryrefslogtreecommitdiff
path: root/nn/runtime/test/GeneratedTestUtils.h
diff options
context:
space:
mode:
authorXusong Wang <xusongw@google.com>2020-03-04 14:08:59 -0800
committerXusong Wang <xusongw@google.com>2020-03-09 16:09:21 -0700
commite968bb1055e582571a0a9bdccc12b6ba7bdaefce (patch)
tree524ac770e46177e02e153b4007f35bdce1fed635 /nn/runtime/test/GeneratedTestUtils.h
parent6e4afba20cd62dade0dd178b638e406cc3bc13dc (diff)
downloadml-e968bb1055e582571a0a9bdccc12b6ba7bdaefce.tar.gz
Separate generated test utilities and the tests.
The enables a test target to use the generated test utilities without including all the generated tests. Bug: 150805665 Test: NNT_static Change-Id: I58fbf949a03f8f0199b0893da41fc90b5b5c004e
Diffstat (limited to 'nn/runtime/test/GeneratedTestUtils.h')
-rw-r--r--nn/runtime/test/GeneratedTestUtils.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/nn/runtime/test/GeneratedTestUtils.h b/nn/runtime/test/GeneratedTestUtils.h
new file mode 100644
index 000000000..de0ce3f82
--- /dev/null
+++ b/nn/runtime/test/GeneratedTestUtils.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TEST_GENERATED_TEST_UTILS_H
+#define ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TEST_GENERATED_TEST_UTILS_H
+
+#include <gtest/gtest.h>
+
+#include <utility>
+#include <vector>
+
+#include "TestHarness.h"
+#include "TestNeuralNetworksWrapper.h"
+
+namespace android::nn::generated_tests {
+
+class GeneratedTestBase
+ : public ::testing::TestWithParam<test_helper::TestModelManager::TestParam> {
+ protected:
+ const test_helper::TestModel& testModel = *GetParam().second;
+};
+
+#define INSTANTIATE_GENERATED_TEST(TestSuite, filter) \
+ INSTANTIATE_TEST_SUITE_P( \
+ TestGenerated, TestSuite, \
+ ::testing::ValuesIn(::test_helper::TestModelManager::get().getTestModels(filter)), \
+ [](const auto& info) { return info.param.first; })
+
+// A generated NDK model.
+class GeneratedModel : public test_wrapper::Model {
+ public:
+ // A helper method to simplify referenced model lifetime management.
+ //
+ // Usage:
+ // GeneratedModel model;
+ // std::vector<Model> refModels;
+ // createModel(&model, &refModels);
+ // model.setRefModels(std::move(refModels));
+ //
+ // This makes sure referenced models live as long as the main model.
+ //
+ void setRefModels(std::vector<test_wrapper::Model> refModels) {
+ mRefModels = std::move(refModels);
+ }
+
+ private:
+ std::vector<test_wrapper::Model> mRefModels;
+};
+
+// Convert TestModel to NDK model.
+void createModel(const test_helper::TestModel& testModel, bool testDynamicOutputShape,
+ GeneratedModel* model);
+inline void createModel(const test_helper::TestModel& testModel, GeneratedModel* model) {
+ createModel(testModel, /*testDynamicOutputShape=*/false, model);
+}
+
+void createRequest(const test_helper::TestModel& testModel, test_wrapper::Execution* execution,
+ std::vector<test_helper::TestBuffer>* outputs);
+
+} // namespace android::nn::generated_tests
+
+#endif // ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TEST_GENERATED_TEST_UTILS_H