Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ def NeedRegenerate():
def InitializeFiles(model_fd, example_fd, test_fd):
fileHeader = "// clang-format off\n// Generated file (from: {spec_file}). Do not edit"
testFileHeader = """\
#include "../../TestGenerated.h"\n
namespace {spec_name} {{
#include "../../TestGenerated.h"
namespace cts_gen_{spec_name} {{
// Generated {spec_name} test
#include "{example_file}"
// Generated model constructor
#include "{model_file}"
}} // namespace {spec_name}\n"""
}} // namespace cts_gen_{spec_name}
"""
# This regex is to remove prefix and get relative path for #include
# Fix for onert: update path
pathRegex = r".*(runtime/tests/nnapi/src/)"
Expand Down Expand Up @@ -272,13 +273,13 @@ def DumpCtsExample(example, example_fd):
def DumpCtsTest(example, test_fd):
testTemplate = """\
TEST_F({test_case_name}, {test_name}) {{
execute({namespace}::{create_model_name},
{namespace}::{is_ignored_name},
{namespace}::get_{examples_name}(){log_file});\n}}\n"""
# Fix for onert: Remove version check
#if example.model.version is not None:
#testTemplate += """\
#TEST_AVAILABLE_SINCE({version}, {test_name}, {namespace}::{create_model_name})\n"""
execute(cts_gen_{namespace}::{create_model_name},
cts_gen_{namespace}::{is_ignored_name},
cts_gen_{namespace}::get_{examples_name}(){log_file});\n}}\n"""
# Fix for onert: Remove version check
# if example.model.version is not None:
# testTemplate += """\
# TEST_AVAILABLE_SINCE({version}, {test_name}, {namespace}::{create_model_name})\n"""
print(testTemplate.format(
test_case_name="DynamicOutputShapeTest" if example.model.hasDynamicOutputShape \
else "GeneratedTests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
#
# Copyright 2017, The Android Open Source Project
# Copyright 2026, Samsung Electronics Co., Ltd. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -271,15 +272,17 @@ def generate_vts_test(example, test_file):
testTemplate = """\
TEST_F({test_case_name}, {test_name}) {{
generated_tests::Execute(device,
{namespace}::{create_model_name},
{namespace}::{is_ignored_name},
{namespace}::get_{examples_name}(){test_dynamic_output_shape});\n}}
vts_gen_{namespace}::{create_model_name},
vts_gen_{namespace}::{is_ignored_name},
vts_gen_{namespace}::get_{examples_name}(){test_dynamic_output_shape});
}}

TEST_F(ValidationTest, {test_name}) {{
const Model model = {namespace}::{create_model_name}();
const std::vector<Request> requests = createRequests({namespace}::get_{examples_name}());
const Model model = vts_gen_{namespace}::{create_model_name}();
const std::vector<Request> requests = createRequests(vts_gen_{namespace}::get_{examples_name}());
validateEverything(model, requests);
}}\n
}}

"""
if example.model.hasDynamicOutputShape:
print("#ifdef NN_TEST_DYNAMIC_OUTPUT_SHAPE", file=test_fd)
Expand All @@ -300,12 +303,12 @@ def InitializeFiles(model_fd, example_fd, test_fd):
fileHeader = "// clang-format off\n// Generated file (from: {spec_file}). Do not edit"
testFileHeader = """\
// Generated from: {spec_file}.
namespace {spec_name} {{
namespace vts_gen_{spec_name} {{
// Generated {spec_name} test
#include "{example_file}"
// Generated model constructor
#include "{model_file}"
}} // namespace {spec_name}\n"""
}} // namespace vts_gen_{spec_name}\n"""
# This regex is to remove prefix and get relative path for #include
pathRegex = r".*frameworks/ml/nn/(runtime/test/generated/)?"
specFileBase = os.path.basename(tg.FileNames.specFile)
Expand Down
29 changes: 15 additions & 14 deletions runtime/tests/nnapi/specs/generate_vts_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#
# Copyright (C) 2017 The Android Open Source Project
# Copyright (C) 2026 Samsung Electronics Co., Ltd. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,20 +32,20 @@ function generate_one_testcase {
-e $VTS_PATH/generated/examples/$BASENAME.example.cpp
# Paste these lines into TestGenerated.cpp
echo
echo namespace $BASENAME {
echo std::vector\<MixedTypedExample\> examples \= {
echo // Generated $BASENAME test
echo \#include \"examples/$BASENAME.example.cpp\"
echo }\;
echo // Generated model constructor
echo \#include \"vts_models/$BASENAME.model.cpp\"
echo } // namespace $BASENAME
echo TEST_F\(NeuralnetworksHidlTest\, $BASENAME\) {
echo ' generated_tests::Execute'\(device,
echo ' '$BASENAME\:\:createTestModel\,
echo ' '$BASENAME\:\:is_ignored\,
echo ' '$BASENAME\:\:examples\)\;
echo }
echo "namespace vts_gen_$BASENAME {"
echo "std::vector<MixedTypedExample> examples = {"
echo "// Generated $BASENAME test"
echo "#include \"examples/$BASENAME.example.cpp\""
echo "};"
echo "// Generated model constructor"
echo "#include \"vts_models/$BASENAME.model.cpp\""
echo "} // namespace vts_gen_$BASENAME"
echo "TEST_F(NeuralnetworksHidlTest, $BASENAME) {"
echo " generated_tests::Execute(device,"
echo " vts_gen_$BASENAME::createTestModel,"
echo " vts_gen_$BASENAME::is_ignored,"
echo " vts_gen_$BASENAME::examples);"
echo "}"
}

for ver in $NNAPI_VERSION;
Expand Down