From 389d2db1ce8e080382cdd1411921bfd9e6a0221b Mon Sep 17 00:00:00 2001 From: Chi Lo <54722500+chilo-ms@users.noreply.github.com> Date: Wed, 26 Jan 2022 15:08:27 -0800 Subject: [PATCH] Make model tests name clear (#10220) * add clear test name for model tests * handle remove character * modify for test * Modify for correct test name * Remove test code * add comments * make it only on Linux * change function name * Convert from wchar_t to char --- onnxruntime/test/providers/cpu/model_tests.cc | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/onnxruntime/test/providers/cpu/model_tests.cc b/onnxruntime/test/providers/cpu/model_tests.cc index fbdb421e5f..ee45ba423e 100644 --- a/onnxruntime/test/providers/cpu/model_tests.cc +++ b/onnxruntime/test/providers/cpu/model_tests.cc @@ -11,6 +11,9 @@ #include "asserts.h" #include #include "default_providers.h" +#include +#include +#include // test infrastructure #include "test/onnx/TestCase.h" @@ -990,7 +993,43 @@ TEST_P(ModelTest, Run) { return v; } -INSTANTIATE_TEST_SUITE_P(ModelTests, ModelTest, testing::ValuesIn(GetParameterStrings())); +auto ExpandModelName = [](const ::testing::TestParamInfo& info) { + // use info.param here to generate the test suffix + std::basic_string name = info.param; + + // the original name here is the combination of provider name and model path name + // remove the trailing 'xxxxxxx/model.onnx' of name + if (name.size() > 11 && name.substr(name.size() - 11) == ORT_TSTR("/model.onnx")) { + name = name.substr(0, info.param.size() - 11); + } + // remove the trailing 'xxxxxx.onnx' of name + else if (name.size() > 5 && name.substr(name.size() - 5) == ORT_TSTR(".onnx")) { + name = name.substr(0, info.param.size() - 5); + } + + // Note: test name only accepts '_' and alphanumeric + // replace '/' or '\' with '_' + std::replace(name.begin(), name.end(), '/', '_'); + std::replace(name.begin(), name.end(), '\\', '_'); + + // Note: test name only accepts '_' and alphanumeric + // remove '.' and '-' + char chars[] = ".-"; + for (unsigned int i = 0; i < strlen(chars); ++i) { + name.erase(std::remove(name.begin(), name.end(), chars[i]), name.end()); + } +#ifdef _WIN32 + // Note: The return value of INSTANTIATE_TEST_SUITE_P accpets std::basic_string. + // Need conversion of wchar_t to char. + return std::wstring_convert>().to_bytes(name); +#else + return name; +#endif +}; + +// The optional last argument is a function or functor that generates custom test name suffixes based on the test parameters. +// Specify the last argument to make test name more meaningful and clear instead of just the sequential number. +INSTANTIATE_TEST_SUITE_P(ModelTests, ModelTest, testing::ValuesIn(GetParameterStrings()), ExpandModelName); } // namespace test } // namespace onnxruntime