From a09033841e475cdd2a7d3ffd9e9bcb25a188f378 Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Thu, 8 Feb 2024 14:03:35 +0100 Subject: [PATCH] [Core] Protect ov::Exception constructor (#22680) ### Details: - Changes `ov::Exception(const std::string&)` constructor access from public to protected. ### Tickets: - CVS-131717 --------- Co-authored-by: Ilya Lavrenov --- src/core/include/openvino/core/except.hpp | 15 +----- src/core/src/except.cpp | 10 ---- .../unit/compile_model_property_test.cpp | 50 +++++++++++-------- src/plugins/auto/tests/unit/ctput_test.cpp | 2 +- .../tests/unit/include/auto_unit_test.hpp | 4 ++ .../tests/unit/parse_meta_device_test.cpp | 5 +- .../auto/tests/unit/release_helper_test.cpp | 4 +- .../auto/tests/unit/runtime_fallback_test.cpp | 10 ++-- .../tests/unit/select_device_failed_test.cpp | 6 +-- 9 files changed, 47 insertions(+), 59 deletions(-) diff --git a/src/core/include/openvino/core/except.hpp b/src/core/include/openvino/core/except.hpp index a10e6c76f4238a..829bb24bd007c5 100644 --- a/src/core/include/openvino/core/except.hpp +++ b/src/core/include/openvino/core/except.hpp @@ -16,15 +16,14 @@ namespace ov { /// Base error for ov runtime errors. class OPENVINO_API Exception : public std::runtime_error { public: - OPENVINO_DEPRECATED("This constructor is deprecated and will be removed, please use OPENVINO_THROW instead") - explicit Exception(const std::string& what_arg); - [[noreturn]] static void create(const char* file, int line, const std::string& explanation); virtual ~Exception(); static const std::string default_msg; protected: + explicit Exception(const std::string& what_arg); + static std::string make_what(const char* file, int line, const char* check_string, @@ -65,9 +64,7 @@ class OPENVINO_API AssertFailure : public Exception { const std::string& explanation); protected: - OPENVINO_SUPPRESS_DEPRECATED_START explicit AssertFailure(const std::string& what_arg) : ov::Exception(what_arg) {} - OPENVINO_SUPPRESS_DEPRECATED_END }; /// Exception class to be thrown on not implemented code @@ -75,14 +72,6 @@ class OPENVINO_API NotImplemented : public AssertFailure { public: [[noreturn]] static void create(const char* file, int line, const std::string& explanation); - [[noreturn]] OPENVINO_DEPRECATED( - "This function is deprecated and will be removed, please use " - "OPENVINO_THROW_NOT_IMPLEMENTED instead") static void create(const char* file, - int line, - const char*, - const std::string&, - const std::string& explanation); - static const std::string default_msg; protected: diff --git a/src/core/src/except.cpp b/src/core/src/except.cpp index dcdc08e7661425..66d67c779b0254 100644 --- a/src/core/src/except.cpp +++ b/src/core/src/except.cpp @@ -9,9 +9,7 @@ ov::Exception::Exception(const std::string& what_arg) : std::runtime_error(what_arg) {} void ov::Exception::create(const char* file, int line, const std::string& explanation) { - OPENVINO_SUPPRESS_DEPRECATED_START throw ov::Exception(make_what(file, line, nullptr, default_msg, explanation)); - OPENVINO_SUPPRESS_DEPRECATED_END } std::string ov::Exception::make_what(const char* file, @@ -51,12 +49,4 @@ void ov::NotImplemented::create(const char* file, int line, const std::string& e throw ov::NotImplemented(make_what(file, line, nullptr, default_msg, explanation)); } -void ov::NotImplemented::create(const char* file, - int line, - const char*, - const std::string&, - const std::string& explanation) { - create(file, line, explanation); -} - const std::string ov::NotImplemented::default_msg{"Not Implemented"}; diff --git a/src/plugins/auto/tests/unit/compile_model_property_test.cpp b/src/plugins/auto/tests/unit/compile_model_property_test.cpp index d1ef9adcbdd573..1329bd94f03df5 100644 --- a/src/plugins/auto/tests/unit/compile_model_property_test.cpp +++ b/src/plugins/auto/tests/unit/compile_model_property_test.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "common_test_utils/test_assertions.hpp" #include "include/auto_unit_test.hpp" #include "openvino/runtime/properties.hpp" @@ -165,40 +166,45 @@ TEST_P(AutoLoadExeNetworkFailedTest, checkLoadFailMassage) { if (device.find("MULTI") != std::string::npos) plugin->set_device_name("MULTI"); + const auto cpu_failed = std::string{"Mock CPU Load Failed"}; + const auto gpu_failed = std::string{"Mock GPU Load Failed"}; ON_CALL(*core, compile_model(::testing::Matcher&>(_), ::testing::Matcher(StrEq(ov::test::utils::DEVICE_GPU)), ::testing::Matcher(_))) - .WillByDefault(Throw(ov::Exception{"Mock GPU Load Failed"})); + .WillByDefault(ov::Throw(gpu_failed)); ON_CALL(*core, compile_model(::testing::Matcher&>(_), ::testing::Matcher(StrEq(ov::test::utils::DEVICE_CPU)), ::testing::Matcher(_))) - .WillByDefault(Throw(ov::Exception{"Mock CPU Load Failed"})); + .WillByDefault(ov::Throw(cpu_failed)); + + const auto auto_failed = std::string{"[AUTO] compile model failed"}; + const auto multi_failed = std::string{"[MULTI] compile model failed"}; if (device == "AUTO") { - EXPECT_THROW_WITH_MESSAGE(plugin->compile_model(model, config), - ov::Exception, - "[AUTO] compile model failed, GPU:Mock GPU Load Failed; CPU:Mock CPU Load Failed"); + OV_EXPECT_THROW(plugin->compile_model(model, config), + ov::Exception, + AllOf(HasSubstr(auto_failed), HasSubstr(cpu_failed), HasSubstr(gpu_failed))); } else if (device == "AUTO:CPU") { - EXPECT_THROW_WITH_MESSAGE(plugin->compile_model(model, config), - ov::Exception, - "[AUTO] compile model failed, CPU:Mock CPU Load Failed"); + OV_EXPECT_THROW(plugin->compile_model(model, config), + ov::Exception, + AllOf(HasSubstr(auto_failed), HasSubstr(cpu_failed))); } else if (device == "AUTO:GPU") { - EXPECT_THROW_WITH_MESSAGE(plugin->compile_model(model, config), - ov::Exception, - "[AUTO] compile model failed, GPU:Mock GPU Load Failed"); + OV_EXPECT_THROW(plugin->compile_model(model, config), + ov::Exception, + AllOf(HasSubstr(auto_failed), HasSubstr(gpu_failed))); } else if (device == "MULTI") { - EXPECT_THROW_WITH_MESSAGE(plugin->compile_model(model, config), - ov::Exception, - "[MULTI] compile model failed, GPU:Mock GPU Load Failed; CPU:Mock CPU Load Failed"); + OV_EXPECT_THROW(plugin->compile_model(model, config), + ov::Exception, + AllOf(HasSubstr(multi_failed), HasSubstr(cpu_failed), HasSubstr(gpu_failed))); } else if (device == "MULTI:CPU") { - EXPECT_THROW_WITH_MESSAGE(plugin->compile_model(model, config), - ov::Exception, - "[MULTI] compile model failed, CPU:Mock CPU Load Failed"); + OV_EXPECT_THROW(plugin->compile_model(model, config), + ov::Exception, + AllOf(HasSubstr(multi_failed), HasSubstr(cpu_failed))); } else if (device == "MULTI:GPU") { - EXPECT_THROW_WITH_MESSAGE(plugin->compile_model(model, config), - ov::Exception, - "[MULTI] compile model failed, GPU:Mock GPU Load Failed"); + OV_EXPECT_THROW(plugin->compile_model(model, config), + ov::Exception, + AllOf(HasSubstr(multi_failed), HasSubstr(gpu_failed))); } } @@ -278,9 +284,9 @@ class CompiledModelPropertyMockTest : public tests::AutoTest, public ::testing:: .WillByDefault(RETURN_MOCK_VALUE(value)); } else { ON_CALL(*mockIExeNet.get(), get_property(StrEq(property.first))) - .WillByDefault(Throw(ov::Exception{"unsupported property"})); + .WillByDefault(ov::Throw("unsupported property")); ON_CALL(*mockIExeNetActual.get(), get_property(StrEq(property.first))) - .WillByDefault(Throw(ov::Exception{"unsupported property"})); + .WillByDefault(ov::Throw("unsupported property")); } } ON_CALL(*mockIExeNet.get(), get_property(StrEq(ov::supported_properties.name()))) diff --git a/src/plugins/auto/tests/unit/ctput_test.cpp b/src/plugins/auto/tests/unit/ctput_test.cpp index 14bfd1d0806ef9..32c338ecd75d40 100644 --- a/src/plugins/auto/tests/unit/ctput_test.cpp +++ b/src/plugins/auto/tests/unit/ctput_test.cpp @@ -180,7 +180,7 @@ TEST_P(AutoCTPUTCallMulti, CTPUTDeviceLoadFailedNoExceptionThrowTest) { compile_model(::testing::Matcher&>(_), ::testing::Matcher(StrEq(loadFailedDevice)), ::testing::Matcher(_))) - .WillByDefault(Throw(ov::Exception{"GeneralError"})); + .WillByDefault(ov::Throw("GeneralError")); if (loadFailedDevice != ov::test::utils::DEVICE_CPU) { EXPECT_CALL(*core, compile_model(::testing::Matcher&>(_), diff --git a/src/plugins/auto/tests/unit/include/auto_unit_test.hpp b/src/plugins/auto/tests/unit/include/auto_unit_test.hpp index 46e4532cff19da..de8d19527ecd75 100644 --- a/src/plugins/auto/tests/unit/include/auto_unit_test.hpp +++ b/src/plugins/auto/tests/unit/include/auto_unit_test.hpp @@ -98,4 +98,8 @@ class AutoTest : public BaseTest { }; } // namespace tests } // namespace mock_auto_plugin + +ACTION_P(Throw, what) { + OPENVINO_THROW(what); +} } // namespace ov diff --git a/src/plugins/auto/tests/unit/parse_meta_device_test.cpp b/src/plugins/auto/tests/unit/parse_meta_device_test.cpp index 3c023623b4c97a..e34791cf70f7a0 100644 --- a/src/plugins/auto/tests/unit/parse_meta_device_test.cpp +++ b/src/plugins/auto/tests/unit/parse_meta_device_test.cpp @@ -36,9 +36,8 @@ class ParseMetaDeviceTest : public tests::AutoTest, public ::testing::TestWithPa } void SetUp() override { - ON_CALL(*core, get_supported_property(StrEq("INVALID_DEVICE"), _, _)).WillByDefault(Throw(ov::Exception(""))); - ON_CALL(*core, get_property(StrEq("GPU.2"), ov::supported_properties.name(), _)) - .WillByDefault(Throw(ov::Exception(""))); + ON_CALL(*core, get_supported_property(StrEq("INVALID_DEVICE"), _, _)).WillByDefault(ov::Throw("")); + ON_CALL(*core, get_property(StrEq("GPU.2"), ov::supported_properties.name(), _)).WillByDefault(ov::Throw("")); ON_CALL(*plugin, parse_meta_devices) .WillByDefault([this](const std::string& priorityDevices, const ov::AnyMap& config) { return plugin->Plugin::parse_meta_devices(priorityDevices, config); diff --git a/src/plugins/auto/tests/unit/release_helper_test.cpp b/src/plugins/auto/tests/unit/release_helper_test.cpp index d576e22299ff31..b9b88b848b227f 100644 --- a/src/plugins/auto/tests/unit/release_helper_test.cpp +++ b/src/plugins/auto/tests/unit/release_helper_test.cpp @@ -195,7 +195,7 @@ TEST_P(AutoReleaseHelperTest, releaseResource) { compile_model(::testing::Matcher&>(_), ::testing::Matcher(StrEq(ov::test::utils::DEVICE_CPU)), _)) - .WillByDefault(Throw(ov::Exception{"GeneralError"})); + .WillByDefault(ov::Throw("GeneralError")); } metaDevices = {{ov::test::utils::DEVICE_CPU, {}, -1}, {ov::test::utils::DEVICE_GPU, {}, -1}}; DeviceInformation devInfo; @@ -254,4 +254,4 @@ const std::vector testReleaseConfigs = {ConfigParams{false, true}, INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, AutoCompiledModelGetPropertyWithReleaseHelper, ::testing::ValuesIn(testReleaseConfigs), - AutoCompiledModelGetPropertyWithReleaseHelper::getTestCaseName); \ No newline at end of file + AutoCompiledModelGetPropertyWithReleaseHelper::getTestCaseName); diff --git a/src/plugins/auto/tests/unit/runtime_fallback_test.cpp b/src/plugins/auto/tests/unit/runtime_fallback_test.cpp index bf837b7aaf4dcf..907ddf442c93d5 100644 --- a/src/plugins/auto/tests/unit/runtime_fallback_test.cpp +++ b/src/plugins/auto/tests/unit/runtime_fallback_test.cpp @@ -162,7 +162,7 @@ TEST_P(AutoRuntimeFallback, releaseResource) { compile_model(::testing::Matcher&>(_), ::testing::Matcher(StrEq("GPU.1")), _)) - .WillByDefault(Throw(ov::Exception{"compile model error"})); + .WillByDefault(ov::Throw("compile model error")); } for (auto& deviceInfo : targetDevices) { std::string deviceName; @@ -193,7 +193,7 @@ TEST_P(AutoRuntimeFallback, releaseResource) { mockExecutorGPU_1, nullptr, ifThrow); - ON_CALL(*mockIExeNetGPU_1.get(), create_infer_request()).WillByDefault(Throw(ov::Exception{"error"})); + ON_CALL(*mockIExeNetGPU_1.get(), create_infer_request()).WillByDefault(ov::Throw("error")); } else { mockInferrequestGPU_1 = std::make_shared(inferReqInternalGPU_1, @@ -315,7 +315,7 @@ TEST_P(AutoCTPUTRuntimeFallback, ctputDeviceInferFailTest) { compile_model(::testing::Matcher&>(_), ::testing::Matcher(StrEq("GPU.1")), _)) - .WillByDefault(Throw(ov::Exception{"compile model error"})); + .WillByDefault(ov::Throw("compile model error")); } for (auto& deviceInfo : targetDevices) { std::string deviceName; @@ -346,7 +346,7 @@ TEST_P(AutoCTPUTRuntimeFallback, ctputDeviceInferFailTest) { mockExecutorGPU_1, nullptr, ifThrow); - ON_CALL(*mockIExeNetGPU_1.get(), create_infer_request()).WillByDefault(Throw(ov::Exception{"error"})); + ON_CALL(*mockIExeNetGPU_1.get(), create_infer_request()).WillByDefault(ov::Throw("error")); } else { mockInferrequestGPU_1 = std::make_shared(inferReqInternalGPU_1, @@ -399,4 +399,4 @@ const std::vector testCtputConfigs = { INSTANTIATE_TEST_SUITE_P(smoke_AutoCTPUTRuntimeFallback, AutoCTPUTRuntimeFallback, ::testing::ValuesIn(testCtputConfigs), - AutoCTPUTRuntimeFallback::getTestCaseName); \ No newline at end of file + AutoCTPUTRuntimeFallback::getTestCaseName); diff --git a/src/plugins/auto/tests/unit/select_device_failed_test.cpp b/src/plugins/auto/tests/unit/select_device_failed_test.cpp index b1a74a7113e61a..d0acd5a220101c 100644 --- a/src/plugins/auto/tests/unit/select_device_failed_test.cpp +++ b/src/plugins/auto/tests/unit/select_device_failed_test.cpp @@ -106,7 +106,7 @@ TEST_P(AutoLoadFailedTest, LoadCNNetWork) { compile_model(::testing::Matcher&>(_), ::testing::Matcher(StrEq(deviceName)), (_))) - .WillByDefault(Throw(ov::Exception{"compile error"})); + .WillByDefault(ov::Throw("compile error")); } DeviceInformation devInfo; switch (configModel) { @@ -151,10 +151,10 @@ TEST_P(AutoLoadFailedTest, LoadCNNetWork) { selDevsSize = deviceConfigs.size(); if (selDevsSize > 1) { ON_CALL(*plugin, select_device(Property(&std::vector::size, Eq(selDevsSize - 1)), _, _)) - .WillByDefault(Throw(ov::Exception{""})); + .WillByDefault(ov::Throw("")); } else { ON_CALL(*plugin, select_device(Property(&std::vector::size, Eq(1)), _, _)) - .WillByDefault(Throw(ov::Exception{""})); + .WillByDefault(ov::Throw("")); } }