diff --git a/src/frontends/onnx/CMakeLists.txt b/src/frontends/onnx/CMakeLists.txt index c3f02f98cedcf4..8585c8b80c5641 100644 --- a/src/frontends/onnx/CMakeLists.txt +++ b/src/frontends/onnx/CMakeLists.txt @@ -2,7 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 # - add_subdirectory(onnx_common) add_subdirectory(frontend) diff --git a/src/frontends/onnx/tests/CMakeLists.txt b/src/frontends/onnx/tests/CMakeLists.txt index e94432041ba8b7..eea80d57ecbf1a 100644 --- a/src/frontends/onnx/tests/CMakeLists.txt +++ b/src/frontends/onnx/tests/CMakeLists.txt @@ -74,10 +74,8 @@ set(SRC onnx_editor.cpp onnx_editor_topological_sort.cpp onnx_import_exceptions.cpp - onnx_import_library.cpp onnx_importer_test.cpp onnx_tensor_names.cpp - onnx_test_util.cpp onnx_utils.cpp onnx_transformations.cpp op_extension.cpp @@ -118,6 +116,8 @@ foreach(BACKEND_NAME IN LISTS ACTIVE_BACKEND_LIST) message(STATUS "Adding unit test for backend ${BACKEND_NAME}") endforeach() +# Create target + add_executable(ov_onnx_frontend_tests ${SRC}) add_test(NAME ov_onnx_frontend_tests COMMAND ov_onnx_frontend_tests --gtest_filter=-*IE_GPU*) set_property(TEST ov_onnx_frontend_tests PROPERTY LABELS OV UNIT ONNX_FE) @@ -141,27 +141,14 @@ endif() target_link_libraries(ov_onnx_frontend_tests PRIVATE gtest_main_manifest frontend_shared_test_classes - openvino::runtime::dev - openvino_onnx_frontend - openvino_onnx_common + openvino::frontend::onnx func_test_utils) -# 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. -target_include_directories(ov_onnx_frontend_tests - SYSTEM PRIVATE - $ - $ - $) -target_compile_definitions(ov_onnx_frontend_tests PRIVATE $) -target_compile_definitions(ov_onnx_frontend_tests PRIVATE ENABLE_OV_ONNX_FRONTEND) - if(OV_COMPILER_IS_CLANG) target_compile_options(ov_onnx_frontend_tests PRIVATE -Wno-undef -Wno-reserved-id-macro) endif() -target_include_directories(ov_onnx_frontend_tests PRIVATE - $) +# Install rules install(TARGETS ov_onnx_frontend_tests RUNTIME DESTINATION tests COMPONENT tests EXCLUDE_FROM_ALL) diff --git a/src/frontends/onnx/tests/onnx_editor.cpp b/src/frontends/onnx/tests/onnx_editor.cpp index d8dc11bac5e0fe..56aa60642ec667 100644 --- a/src/frontends/onnx/tests/onnx_editor.cpp +++ b/src/frontends/onnx/tests/onnx_editor.cpp @@ -9,9 +9,7 @@ #include "common_test_utils/graph_comparator.hpp" #include "common_test_utils/test_case.hpp" #include "common_test_utils/test_control.hpp" -#include "editor.hpp" #include "gtest/gtest.h" -#include "onnx_test_util.hpp" #include "onnx_utils.hpp" #include "openvino/op/constant.hpp" diff --git a/src/frontends/onnx/tests/onnx_editor_topological_sort.cpp b/src/frontends/onnx/tests/onnx_editor_topological_sort.cpp index e9ea726415622a..7caea8199c64e3 100644 --- a/src/frontends/onnx/tests/onnx_editor_topological_sort.cpp +++ b/src/frontends/onnx/tests/onnx_editor_topological_sort.cpp @@ -7,9 +7,7 @@ #include "common_test_utils/file_utils.hpp" #include "common_test_utils/test_case.hpp" #include "common_test_utils/test_control.hpp" -#include "editor.hpp" #include "gtest/gtest.h" -#include "onnx_test_util.hpp" #include "onnx_utils.hpp" using namespace ov; diff --git a/src/frontends/onnx/tests/onnx_import_exceptions.cpp b/src/frontends/onnx/tests/onnx_import_exceptions.cpp index 09446f39738db7..62a4b332f148a7 100644 --- a/src/frontends/onnx/tests/onnx_import_exceptions.cpp +++ b/src/frontends/onnx/tests/onnx_import_exceptions.cpp @@ -6,7 +6,6 @@ #include "common_test_utils/file_utils.hpp" #include "common_test_utils/type_prop.hpp" -#include "exceptions.hpp" #include "gtest/gtest.h" #include "onnx_utils.hpp" @@ -34,10 +33,10 @@ TEST(onnx_importer, exception_msg_onnx_node_validation_failure) { convert_model("instance_norm_bad_scale_type.onnx"); // Should have thrown, so fail if it didn't FAIL() << "ONNX Importer did not detected incorrect model!"; - } catch (const ::ov::frontend::onnx_error::OnnxNodeValidationFailure& e) { + } catch (const ::ov::Exception& e) { EXPECT_HAS_SUBSTRING(e.what(), std::string("While validating ONNX node ' - -#include "common_test_utils/file_utils.hpp" -#include "common_test_utils/test_control.hpp" -#include "gtest/gtest.h" -#include "onnx_utils.hpp" - -using namespace ov::frontend::onnx::tests; - -static std::string s_manifest = onnx_backend_manifest(MANIFEST); - -OPENVINO_TEST(onnx, check_ir_version_support) { - // It appears you've changed the ONNX library version used by OpenVINO. Please update the value - // tested below to make sure it equals the current IR_VERSION enum value defined in ONNX headers - // - // You should also check the onnx_common/src/onnx_model_validator.cpp file and make sure that - // the details::onnx::is_correct_onnx_field() handles any new fields added in the new release - // of the ONNX library. Make sure to update the "Field" enum and the function mentioned above. - // - // The last step is to also update the details::onnx::contains_onnx_model_keys() function - // in the same file to make sure that prototxt format validation also covers the changes in ONNX - EXPECT_EQ(ONNX_NAMESPACE::Version::IR_VERSION, 9) - << "The IR_VERSION defined in ONNX does not match the version that OpenVINO supports. " - "Please check the source code of this test for details and explanation how to proceed."; -} diff --git a/src/frontends/onnx/tests/onnx_import_org_openvino.in.cpp b/src/frontends/onnx/tests/onnx_import_org_openvino.in.cpp index eb7edeccbb8198..28814dd17b3efa 100644 --- a/src/frontends/onnx/tests/onnx_import_org_openvino.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_org_openvino.in.cpp @@ -117,7 +117,7 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_priorbox_clustered_first_input_bad_shape) { } catch (const ov::Exception& e) { EXPECT_HAS_SUBSTRING(e.what(), std::string("Only 4D inputs are supported. First input rank: 5 (should be 4)")); } catch (...) { - FAIL() << "Expected OnnxNodeValidationFailure exception was not thrown"; + FAIL() << "Expected ov::Exception exception was not thrown"; } } @@ -128,7 +128,7 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_priorbox_clustered_second_input_bad_shape) { } catch (const ov::Exception& e) { EXPECT_HAS_SUBSTRING(e.what(), std::string("Only 4D inputs are supported. Second input rank: 5 (should be 4)")); } catch (...) { - FAIL() << "Expected OnnxNodeValidationFailure exception was not thrown"; + FAIL() << "Expected ov::Exception exception was not thrown"; } } diff --git a/src/frontends/onnx/tests/onnx_import_with_editor.in.cpp b/src/frontends/onnx/tests/onnx_import_with_editor.in.cpp index a7e204414253d2..b365c64f253e6c 100644 --- a/src/frontends/onnx/tests/onnx_import_with_editor.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_with_editor.in.cpp @@ -14,7 +14,6 @@ #include "common_test_utils/file_utils.hpp" #include "common_test_utils/test_case.hpp" #include "common_test_utils/test_control.hpp" -#include "editor.hpp" #include "gtest/gtest.h" #include "onnx_utils.hpp" #include "openvino/op/constant.hpp" diff --git a/src/frontends/onnx/tests/onnx_ops_registration.cpp b/src/frontends/onnx/tests/onnx_ops_registration.cpp index d4bca0639ecb73..2ac414abb6d5b2 100644 --- a/src/frontends/onnx/tests/onnx_ops_registration.cpp +++ b/src/frontends/onnx/tests/onnx_ops_registration.cpp @@ -10,13 +10,10 @@ #include "common_test_utils/file_utils.hpp" #include "common_test_utils/test_case.hpp" #include "common_test_utils/test_control.hpp" -#include "editor.hpp" #include "gtest/gtest.h" -#include "onnx_test_util.hpp" #include "onnx_utils.hpp" using namespace ov; -using namespace ov::onnx_editor; using namespace ov::frontend::onnx::tests; static std::string s_manifest = onnx_backend_manifest("${MANIFEST}"); diff --git a/src/frontends/onnx/tests/onnx_test_util.cpp b/src/frontends/onnx/tests/onnx_test_util.cpp deleted file mode 100644 index 4a1025cc9103ef..00000000000000 --- a/src/frontends/onnx/tests/onnx_test_util.cpp +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "onnx_test_util.hpp" - -#include - -#include -#include -#include - -#include "onnx_common/parser.hpp" - -using namespace ov::frontend::onnx::tests; -using namespace ov::frontend::onnx::common; - -namespace { -ComparisonResult compare_nodes(const ONNX_NAMESPACE::GraphProto& graph, - const ONNX_NAMESPACE::GraphProto& ref_graph, - CompType comp) { - if (graph.node_size() != ref_graph.node_size()) { - return ComparisonResult::fail("The number of nodes in compared models doesn't match"); - } else { - for (int i = 0; i < graph.node_size(); ++i) { - const auto& lhs = graph.node(i); - const auto& rhs = ref_graph.node(i); - - if (lhs.op_type() != rhs.op_type()) { - return ComparisonResult::fail("Operation types are different at index " + std::to_string(i) + ": " + - lhs.op_type() + " vs " + rhs.op_type()); - } - - for (int j = 0; j < lhs.input_size(); ++j) { - if (!comp(lhs.input(j), rhs.input(j))) { - return ComparisonResult::fail("Input names don't match for nodes at index " + std::to_string(i) + - ": " + lhs.input(j) + " vs " + rhs.input(j)); - } - } - - for (int j = 0; j < lhs.output_size(); ++j) { - if (!comp(lhs.output(j), rhs.output(j))) { - return ComparisonResult::fail("Output names don't match for nodes at index " + std::to_string(i) + - ": " + lhs.output(j) + " vs " + rhs.output(j)); - } - } - } - } - - return ComparisonResult::pass(); -} - -ComparisonResult compare_value_info(const ONNX_NAMESPACE::ValueInfoProto& lhs, - const ONNX_NAMESPACE::ValueInfoProto& rhs, - const std::string& item_type) { - if (lhs.name() != rhs.name()) { - return ComparisonResult::fail(item_type + " names in the graph don't match: " + lhs.name() + " vs " + - rhs.name()); - } - - const auto& lhs_tensor = lhs.type().tensor_type(); - const auto& rhs_tensor = rhs.type().tensor_type(); - if (lhs_tensor.elem_type() != rhs_tensor.elem_type()) { - return ComparisonResult::fail("Element types don't match for " + item_type + " " + lhs.name() + ": " + - std::to_string(lhs_tensor.elem_type()) + " vs " + - std::to_string(rhs_tensor.elem_type())); - } - - const auto& lhs_shape = lhs_tensor.shape(); - const auto& rhs_shape = rhs_tensor.shape(); - if (lhs_shape.dim_size() != rhs_shape.dim_size()) { - return ComparisonResult::fail("Tensor ranks don't match for " + item_type + " " + lhs.name() + ": " + - std::to_string(lhs_shape.dim_size()) + " vs " + - std::to_string(rhs_shape.dim_size())); - } else { - for (int j = 0; j < lhs_shape.dim_size(); ++j) { - const auto& lhs_dim = lhs_shape.dim(j); - const auto& rhs_dim = rhs_shape.dim(j); - if ((lhs_dim.has_dim_value() && rhs_dim.has_dim_param()) || - (rhs_dim.has_dim_value() && lhs_dim.has_dim_param())) { - return ComparisonResult::fail("Dynamic vs static dimension mismatch for " + item_type + " " + - lhs.name() + " at index: " + std::to_string(j)); - } else if (lhs_dim.has_dim_value() && lhs_dim.dim_value() != rhs_dim.dim_value()) { - return ComparisonResult::fail("Shape dimensions don't match for " + item_type + " " + lhs.name() + - " at index: " + std::to_string(j) + ". " + - std::to_string(lhs_dim.dim_value()) + " vs " + - std::to_string(rhs_dim.dim_value())); - } - } - } - - return ComparisonResult::pass(); -} - -ComparisonResult compare_inputs(const ONNX_NAMESPACE::GraphProto& graph, const ONNX_NAMESPACE::GraphProto& ref_graph) { - if (graph.input_size() != ref_graph.input_size()) { - return ComparisonResult::fail( - "The number of inputs in compared models doesn't match: " + std::to_string(graph.input_size()) + " vs " + - std::to_string(ref_graph.input_size())); - } else { - for (int i = 0; i < graph.input_size(); ++i) { - const auto& lhs = graph.input(i); - const auto& rhs = ref_graph.input(i); - - const auto res = compare_value_info(lhs, rhs, "input"); - if (!res.is_ok) { - return res; - } - } - - return ComparisonResult::pass(); - } -} - -ComparisonResult compare_outputs(const ONNX_NAMESPACE::GraphProto& graph, const ONNX_NAMESPACE::GraphProto& ref_graph) { - if (graph.output_size() != ref_graph.output_size()) { - return ComparisonResult::fail("The number of outputs in compared models doesn't match" + - std::to_string(graph.output_size()) + " vs " + - std::to_string(ref_graph.output_size())); - } else { - for (int i = 0; i < graph.output_size(); ++i) { - const auto& lhs = graph.output(i); - const auto& rhs = ref_graph.output(i); - - const auto res = compare_value_info(lhs, rhs, "output"); - if (!res.is_ok) { - return res; - } - } - - return ComparisonResult::pass(); - } -} - -ComparisonResult compare_initializers(const ONNX_NAMESPACE::GraphProto& graph, - const ONNX_NAMESPACE::GraphProto& ref_graph) { - if (graph.initializer_size() != ref_graph.initializer_size()) { - return ComparisonResult::fail("The number of initializers in compared models doesn't match" + - std::to_string(graph.initializer_size()) + " vs " + - std::to_string(ref_graph.initializer_size())); - } else { - for (int i = 0; i < graph.initializer_size(); ++i) { - const auto& lhs = graph.initializer(i); - const auto& rhs = ref_graph.initializer(i); - - if (lhs.name() != rhs.name()) { - return ComparisonResult::fail("Initializer names in the graph don't match: " + lhs.name() + " vs " + - rhs.name()); - } else if (lhs.data_type() != rhs.data_type()) { - return ComparisonResult::fail( - "Initializer data types in the graph don't match: " + std::to_string(lhs.data_type()) + " vs " + - std::to_string(rhs.data_type())); - } else if (lhs.dims_size() != rhs.dims_size()) { - return ComparisonResult::fail( - "Initializer ranks in the graph don't match: " + std::to_string(lhs.dims_size()) + " vs " + - std::to_string(rhs.dims_size())); - } else { - for (int j = 0; j < lhs.dims_size(); ++j) { - if (lhs.dims(j) != rhs.dims(j)) { - return ComparisonResult::fail("Shape dimensions don't match for initializer " + lhs.name() + - " at index: " + std::to_string(j) + ". " + - std::to_string(lhs.dims(j)) + " vs " + - std::to_string(rhs.dims(j))); - } - } - } - } - - return ComparisonResult::pass(); - } -} - -ComparisonResult compare_onnx_graphs(const ONNX_NAMESPACE::GraphProto& graph, - const ONNX_NAMESPACE::GraphProto& ref_graph, - CompType comp = default_name_comparator) { - ComparisonResult comparison = compare_inputs(graph, ref_graph); - if (!comparison.is_ok) { - return comparison; - } - - comparison = compare_outputs(graph, ref_graph); - if (!comparison.is_ok) { - return comparison; - } - - comparison = compare_initializers(graph, ref_graph); - if (!comparison.is_ok) { - return comparison; - } - - return compare_nodes(graph, ref_graph, comp); -} -} // namespace -namespace ov { -namespace frontend { -namespace onnx { -namespace tests { - -bool default_name_comparator(std::string lhs, std::string rhs) { - return lhs == rhs; -} - -ComparisonResult compare_onnx_models(const std::string& model, const std::string& reference_model_path, CompType comp) { - std::stringstream model_stream{model}; - const auto model_proto = parse_from_istream(model_stream); - const auto ref_model = parse_from_file(reference_model_path); - return compare_onnx_graphs(model_proto.graph(), ref_model.graph(), comp); -} - -std::string change_opset_version(const std::string& model, - const std::vector& new_opset_version, - const std::string& domain) { - std::stringstream model_stream{model}; - auto model_proto = parse_from_istream(model_stream); - model_proto.clear_opset_import(); - for (const auto& opset_version : new_opset_version) { - auto* opset_import = model_proto.add_opset_import(); - opset_import->set_version(opset_version); - opset_import->set_domain(domain); - } - - return model_proto.SerializeAsString(); -} - -} // namespace tests -} // namespace onnx -} // namespace frontend -} // namespace ov \ No newline at end of file diff --git a/src/frontends/onnx/tests/onnx_test_util.hpp b/src/frontends/onnx/tests/onnx_test_util.hpp deleted file mode 100644 index a2aa222905e0c5..00000000000000 --- a/src/frontends/onnx/tests/onnx_test_util.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include - -namespace ov { -namespace frontend { -namespace onnx { -namespace tests { -struct ComparisonResult { - ComparisonResult() = default; - ComparisonResult(std::string error) : is_ok{false}, error_message{std::move(error)} {} - ComparisonResult(ComparisonResult&&) = default; - ComparisonResult(const ComparisonResult&) = default; - ComparisonResult& operator=(ComparisonResult&&) = default; - ComparisonResult& operator=(const ComparisonResult&) = default; - - bool is_ok = true; - std::string error_message; - - static ComparisonResult pass() { - return {}; - } - static ComparisonResult fail(std::string error) { - return ComparisonResult{std::move(error)}; - } -}; - -bool default_name_comparator(std::string lhs, std::string rhs); - -// comp is a function to compare inputs and outputs names (as default it is a usual std::string comparison) -using CompType = std::function; -ComparisonResult compare_onnx_models(const std::string& model, - const std::string& reference_model_path, - CompType comp = default_name_comparator); - -std::string change_opset_version(const std::string& model, - const std::vector& new_opset_version, - const std::string& domain = "ai.onnx"); -} // namespace tests -} // namespace onnx -} // namespace frontend -} // namespace ov diff --git a/src/frontends/onnx/tests/onnx_transformations.cpp b/src/frontends/onnx/tests/onnx_transformations.cpp index c3edd053d5d836..389032c9bbde34 100644 --- a/src/frontends/onnx/tests/onnx_transformations.cpp +++ b/src/frontends/onnx/tests/onnx_transformations.cpp @@ -5,13 +5,10 @@ #include "common_test_utils/file_utils.hpp" #include "common_test_utils/graph_comparator.hpp" #include "common_test_utils/test_control.hpp" -#include "editor.hpp" #include "gtest/gtest.h" -#include "onnx_test_util.hpp" #include "onnx_utils.hpp" using namespace ov; -using namespace ov::onnx_editor; using namespace ov::frontend::onnx::tests; static std::string s_manifest = onnx_backend_manifest("${MANIFEST}");