Move ONNX reader tests from ieFuncTests to ov_onnx_frontend_tests (#14132)

* Move ONNX reader tests from ieFuncTests to ov_onnx_frontend_tests

* Fix code style

Co-authored-by: Ilya Churaev <ilya.churaev@intel.com>
This commit is contained in:
Oleg Pipikin 2022-12-12 19:43:30 +01:00 committed by GitHub
parent 4705f54c68
commit 2ff0b24d92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 197 additions and 44 deletions

View File

@ -16,6 +16,7 @@ message(STATUS "ONNX frontend test enabled")
add_compile_definitions( add_compile_definitions(
TEST_MODEL_ZOO="${TEST_MODEL_ZOO}" TEST_MODEL_ZOO="${TEST_MODEL_ZOO}"
ONNX_MODELS_DIR="${TEST_MODEL_ZOO}/onnx" ONNX_MODELS_DIR="${TEST_MODEL_ZOO}/onnx"
ONNX_TEST_MODELS="${TEST_MODEL_ZOO}/onnx/"
TEST_ONNX_MODELS_DIRNAME="${TEST_MODEL_ZOO}/onnx/" TEST_ONNX_MODELS_DIRNAME="${TEST_MODEL_ZOO}/onnx/"
MANIFEST="${CMAKE_CURRENT_SOURCE_DIR}/unit_test.manifest" MANIFEST="${CMAKE_CURRENT_SOURCE_DIR}/unit_test.manifest"
SERIALIZED_ZOO="${TEST_MODEL_ZOO}") SERIALIZED_ZOO="${TEST_MODEL_ZOO}")
@ -90,7 +91,11 @@ set(SRC
onnx_test_util.cpp onnx_test_util.cpp
onnx_transformations.cpp onnx_transformations.cpp
op_extension.cpp op_extension.cpp
telemetry.cpp) telemetry.cpp
lib_close.cpp
model_support_tests.cpp
onnx_reader_external_data.cpp
skip_tests_config.cpp)
foreach(src IN LISTS SRC MULTI_TEST_SRC) foreach(src IN LISTS SRC MULTI_TEST_SRC)
if(IS_ABSOLUTE "${src}") if(IS_ABSOLUTE "${src}")
@ -134,7 +139,7 @@ if(ONNX_TESTS_DEPENDENCIES)
endif() endif()
target_link_libraries(ov_onnx_frontend_tests PRIVATE engines_test_util gtest_main_manifest openvino::runtime::dev target_link_libraries(ov_onnx_frontend_tests PRIVATE engines_test_util gtest_main_manifest openvino::runtime::dev
openvino_onnx_frontend onnx_common) openvino_onnx_frontend onnx_common funcTestUtils)
# It's needed by onnx_import_library.cpp and onnx_import_exceptions.cpp tests to include onnx_pb.h. # It's needed by onnx_import_library.cpp and onnx_import_exceptions.cpp tests to include onnx_pb.h.
# Not linking statically to libprotobuf (linked into libonnx) avoids false-failing onnx_editor tests. # Not linking statically to libprotobuf (linked into libonnx) avoids false-failing onnx_editor tests.

View File

@ -1,7 +1,7 @@
// Copyright (C) 2018-2022 Intel Corporation // Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
#include "lib_close.hpp" #include "functional_test_utils/lib_close.hpp"
#include <gtest/gtest.h> #include <gtest/gtest.h>

View File

@ -2,21 +2,22 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
#include "common_test_utils/file_utils.hpp"
#include "ie_common.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <fstream>
#include <fstream>
#include <ie_core.hpp> #include <ie_core.hpp>
#include "common_test_utils/file_utils.hpp"
#include "ie_common.h"
namespace { namespace {
std::string model_path(const char* model) { std::string model_path(const char* model) {
std::string path = ONNX_TEST_MODELS; std::string path = ONNX_TEST_MODELS;
path += "support_test/"; path += "support_test/";
path += model; path += model;
return CommonTestUtils::getModelFromTestModelZoo(path); return CommonTestUtils::getModelFromTestModelZoo(path);
}
} }
} // namespace
TEST(ONNXReader_ModelSupported, basic_model) { TEST(ONNXReader_ModelSupported, basic_model) {
// this model is a basic ONNX model taken from ngraph's unit test (add_abc.onnx) // this model is a basic ONNX model taken from ngraph's unit test (add_abc.onnx)

View File

@ -2,24 +2,26 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
#include <gtest/gtest.h>
#include <set>
#include <string>
#include <fstream>
#include <algorithm>
#include <ie_blob.h>
#include <ie_core.hpp>
#include <file_utils.h> #include <file_utils.h>
#include <gtest/gtest.h>
#include <ie_blob.h>
#include <algorithm>
#include <fstream>
#include <ie_core.hpp>
#include <ngraph/ngraph.hpp>
#include <set>
#include <streambuf> #include <streambuf>
#include <string>
#include "common_test_utils/file_utils.hpp" #include "common_test_utils/file_utils.hpp"
#include "common_test_utils/unicode_utils.hpp" #include "common_test_utils/unicode_utils.hpp"
#include <ngraph/ngraph.hpp>
TEST(ONNX_Reader_Tests, ImportModelWithExternalDataFromFile) { TEST(ONNX_Reader_Tests, ImportModelWithExternalDataFromFile) {
InferenceEngine::Core ie; InferenceEngine::Core ie;
auto cnnNetwork = ie.ReadNetwork(CommonTestUtils::getModelFromTestModelZoo( auto cnnNetwork = ie.ReadNetwork(
std::string(ONNX_TEST_MODELS) + "onnx_external_data.onnx"), ""); CommonTestUtils::getModelFromTestModelZoo(std::string(ONNX_TEST_MODELS) + "onnx_external_data.onnx"),
"");
auto function = cnnNetwork.getFunction(); auto function = cnnNetwork.getFunction();
int count_additions = 0; int count_additions = 0;
@ -51,27 +53,21 @@ TEST(ONNX_Reader_Tests, ImportModelWithExternalDataFromFile) {
TEST(ONNX_Reader_Tests, ImportModelWithExternalDataFromStringException) { TEST(ONNX_Reader_Tests, ImportModelWithExternalDataFromStringException) {
InferenceEngine::Core ie; InferenceEngine::Core ie;
const auto path = CommonTestUtils::getModelFromTestModelZoo( const auto path =
std::string(ONNX_TEST_MODELS) + "onnx_external_data.onnx"); CommonTestUtils::getModelFromTestModelZoo(std::string(ONNX_TEST_MODELS) + "onnx_external_data.onnx");
InferenceEngine::Blob::CPtr weights; // not used InferenceEngine::Blob::CPtr weights; // not used
std::ifstream stream(path, std::ios::binary); std::ifstream stream(path, std::ios::binary);
std::string modelAsString((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>()); std::string modelAsString((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>());
stream.close(); stream.close();
try { try {
auto cnnNetwork = ie.ReadNetwork(modelAsString, weights); auto cnnNetwork = ie.ReadNetwork(modelAsString, weights);
} } catch (const ngraph::ngraph_error& e) {
catch(const ngraph::ngraph_error& e) { EXPECT_PRED_FORMAT2(testing::IsSubstring, std::string("invalid external data:"), e.what());
EXPECT_PRED_FORMAT2(
testing::IsSubstring,
std::string("invalid external data:"),
e.what());
EXPECT_PRED_FORMAT2( EXPECT_PRED_FORMAT2(testing::IsSubstring,
testing::IsSubstring, std::string("data/tensor.data, offset: 0, data_length: 0)"),
std::string("data/tensor.data, offset: 0, data_length: 0)"), e.what());
e.what()); } catch (...) {
}
catch(...) {
FAIL() << "Reading network failed for unexpected reason"; FAIL() << "Reading network failed for unexpected reason";
} }
} }
@ -79,14 +75,12 @@ TEST(ONNX_Reader_Tests, ImportModelWithExternalDataFromStringException) {
#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
TEST(ONNX_Reader_Tests, ImportModelWithExternalDataFromWstringNamedFile) { TEST(ONNX_Reader_Tests, ImportModelWithExternalDataFromWstringNamedFile) {
InferenceEngine::Core ie; InferenceEngine::Core ie;
std::string win_dir_path = CommonTestUtils::getModelFromTestModelZoo( std::string win_dir_path = CommonTestUtils::getModelFromTestModelZoo(ONNX_TEST_MODELS "onnx_external_data.onnx");
ONNX_TEST_MODELS "onnx_external_data.onnx"); std::wstring wmodel =
std::wstring wmodel = CommonTestUtils::addUnicodePostfixToPath(win_dir_path, CommonTestUtils::addUnicodePostfixToPath(win_dir_path, CommonTestUtils::test_unicode_postfix_vector[0]);
CommonTestUtils::test_unicode_postfix_vector[0]);
bool is_copy_successfully = CommonTestUtils::copyFile(win_dir_path, wmodel); bool is_copy_successfully = CommonTestUtils::copyFile(win_dir_path, wmodel);
if (!is_copy_successfully) { if (!is_copy_successfully) {
FAIL() << "Unable to copy from '" << win_dir_path << "' to '" FAIL() << "Unable to copy from '" << win_dir_path << "' to '" << ov::util::wstring_to_string(wmodel) << "'";
<< ov::util::wstring_to_string(wmodel) << "'";
} }
auto cnnNetwork = ie.ReadNetwork(wmodel, L""); auto cnnNetwork = ie.ReadNetwork(wmodel, L"");

View File

@ -0,0 +1,17 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "functional_test_utils/skip_tests_config.hpp"
#include <string>
#include <vector>
std::vector<std::string> disabledTestPatterns() {
return {
#ifndef BUILD_SHARED_LIBS
// Disable tests for static libraries
".*FrontendLibCloseTest.*"
#endif
};
}

View File

@ -0,0 +1,34 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <gtest/gtest.h>
#include <tuple>
/**
* \brief Front end library close test parameters.
*
* \param frontend Frontend name.
* \param model_path Model file path.
* \param exp_name Tensor name in model used to get place.
*/
using FrontendLibCloseParams = std::tuple<std::string, // frontend name
std::string, // model file path
std::string // tensor name to get place
>;
/** \brief Frontend library close test fixture with parameters \ref FrontendLibCloseParams. */
class FrontendLibCloseTest : public testing::TestWithParam<FrontendLibCloseParams> {
public:
static std::string get_test_case_name(const testing::TestParamInfo<FrontendLibCloseParams>& obj);
protected:
std::string frontend;
std::string model_path;
std::string exp_name;
void SetUp() override;
};

View File

@ -0,0 +1,102 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "functional_test_utils/lib_close.hpp"
#include "common_test_utils/file_utils.hpp"
#include "functional_test_utils/skip_tests_config.hpp"
#include "gtest/gtest.h"
#include "openvino/frontend/manager.hpp"
#include "openvino/runtime/core.hpp"
#include "openvino/util/file_util.hpp"
using namespace testing;
using namespace ov::util;
using namespace ov::frontend;
std::string FrontendLibCloseTest::get_test_case_name(const testing::TestParamInfo<FrontendLibCloseParams>& obj) {
return std::get<0>(obj.param);
}
void FrontendLibCloseTest::SetUp() {
SKIP_IF_CURRENT_TEST_IS_DISABLED()
std::tie(frontend, model_path, exp_name) = GetParam();
model_path = CommonTestUtils::getModelFromTestModelZoo(model_path);
}
/**
* \brief Delete InputModel object as last.
*
* Frontend library must close after object deletion, otherwise segfault can occur.
*/
TEST_P(FrontendLibCloseTest, testModelIsLasDeletedObject) {
InputModel::Ptr model;
{
auto fem = std::make_shared<ov::frontend::FrontEndManager>();
auto fe = fem->load_by_framework(frontend);
model = fe->load(model_path);
}
ASSERT_NE(model, nullptr);
}
/** \brief Frontend library must close after object deletion, otherwise segfault can occur. */
TEST_P(FrontendLibCloseTest, testPlaceIsLastDeletedObject) {
Place::Ptr place;
{
auto fem = std::make_shared<ov::frontend::FrontEndManager>();
auto fe = fem->load_by_framework(frontend);
auto model = fe->load(model_path);
place = model->get_place_by_tensor_name(exp_name);
}
ASSERT_NE(place, nullptr);
EXPECT_EQ(place->get_names().at(0), exp_name);
}
/** \brief Frontend library unload before object deletion, expecting segfault. */
TEST_P(FrontendLibCloseTest, testUnloadLibBeforeDeletingDependentObject) {
EXPECT_DEATH(
{
Place::Ptr place;
{
auto fem = std::make_shared<ov::frontend::FrontEndManager>();
auto fe = fem->load_by_framework(frontend);
auto model = fe->load(model_path);
place = model->get_place_by_tensor_name(exp_name);
}
ov::shutdown();
ASSERT_NE(place, nullptr);
},
".*");
}
/** \brief Delete place which is created from other place instance. */
TEST_P(FrontendLibCloseTest, testPlaceFromPlaceIsLastDeletedObject) {
Place::Ptr port_place;
{
auto fem = std::make_shared<ov::frontend::FrontEndManager>();
auto fe = fem->load_by_framework(frontend);
auto model = fe->load(model_path);
auto tensor_place = model->get_place_by_tensor_name(exp_name);
port_place = tensor_place->get_producing_port();
}
ASSERT_NE(port_place, nullptr);
ASSERT_EQ(port_place->get_producing_port(), nullptr);
}
/** \brief Delete vector of places object as last one. */
TEST_P(FrontendLibCloseTest, testGetVectorOfPlaces) {
std::vector<Place::Ptr> inputs;
{
auto fem = std::make_shared<ov::frontend::FrontEndManager>();
auto fe = fem->load_by_framework(frontend);
auto model = fe->load(model_path);
inputs = model->get_inputs();
}
ASSERT_FALSE(inputs.empty());
}