Skip to content

Commit

Permalink
[Core] Protect ov::Exception constructor (#22680)
Browse files Browse the repository at this point in the history
### Details:
- Changes `ov::Exception(const std::string&)` constructor access from
public to protected.

### Tickets:
 - CVS-131717

---------

Co-authored-by: Ilya Lavrenov <ilya.lavrenov@intel.com>
  • Loading branch information
t-jankowski and ilya-lavrenov authored Feb 8, 2024
1 parent 676043c commit a090338
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 59 deletions.
15 changes: 2 additions & 13 deletions src/core/include/openvino/core/except.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -65,24 +64,14 @@ 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
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:
Expand Down
10 changes: 0 additions & 10 deletions src/core/src/except.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"};
50 changes: 28 additions & 22 deletions src/plugins/auto/tests/unit/compile_model_property_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<const std::shared_ptr<const ov::Model>&>(_),
::testing::Matcher<const std::string&>(StrEq(ov::test::utils::DEVICE_GPU)),
::testing::Matcher<const ov::AnyMap&>(_)))
.WillByDefault(Throw(ov::Exception{"Mock GPU Load Failed"}));
.WillByDefault(ov::Throw(gpu_failed));
ON_CALL(*core,
compile_model(::testing::Matcher<const std::shared_ptr<const ov::Model>&>(_),
::testing::Matcher<const std::string&>(StrEq(ov::test::utils::DEVICE_CPU)),
::testing::Matcher<const ov::AnyMap&>(_)))
.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)));
}
}

Expand Down Expand Up @@ -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())))
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/auto/tests/unit/ctput_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ TEST_P(AutoCTPUTCallMulti, CTPUTDeviceLoadFailedNoExceptionThrowTest) {
compile_model(::testing::Matcher<const std::shared_ptr<const ov::Model>&>(_),
::testing::Matcher<const std::string&>(StrEq(loadFailedDevice)),
::testing::Matcher<const ov::AnyMap&>(_)))
.WillByDefault(Throw(ov::Exception{"GeneralError"}));
.WillByDefault(ov::Throw("GeneralError"));
if (loadFailedDevice != ov::test::utils::DEVICE_CPU) {
EXPECT_CALL(*core,
compile_model(::testing::Matcher<const std::shared_ptr<const ov::Model>&>(_),
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/auto/tests/unit/include/auto_unit_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ class AutoTest : public BaseTest {
};
} // namespace tests
} // namespace mock_auto_plugin

ACTION_P(Throw, what) {
OPENVINO_THROW(what);
}
} // namespace ov
5 changes: 2 additions & 3 deletions src/plugins/auto/tests/unit/parse_meta_device_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/auto/tests/unit/release_helper_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ TEST_P(AutoReleaseHelperTest, releaseResource) {
compile_model(::testing::Matcher<const std::shared_ptr<const ov::Model>&>(_),
::testing::Matcher<const std::string&>(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;
Expand Down Expand Up @@ -254,4 +254,4 @@ const std::vector<ConfigParams> testReleaseConfigs = {ConfigParams{false, true},
INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests,
AutoCompiledModelGetPropertyWithReleaseHelper,
::testing::ValuesIn(testReleaseConfigs),
AutoCompiledModelGetPropertyWithReleaseHelper::getTestCaseName);
AutoCompiledModelGetPropertyWithReleaseHelper::getTestCaseName);
10 changes: 5 additions & 5 deletions src/plugins/auto/tests/unit/runtime_fallback_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ TEST_P(AutoRuntimeFallback, releaseResource) {
compile_model(::testing::Matcher<const std::shared_ptr<const ov::Model>&>(_),
::testing::Matcher<const std::string&>(StrEq("GPU.1")),
_))
.WillByDefault(Throw(ov::Exception{"compile model error"}));
.WillByDefault(ov::Throw("compile model error"));
}
for (auto& deviceInfo : targetDevices) {
std::string deviceName;
Expand Down Expand Up @@ -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<ov::mock_auto_plugin::MockAsyncInferRequest>(inferReqInternalGPU_1,
Expand Down Expand Up @@ -315,7 +315,7 @@ TEST_P(AutoCTPUTRuntimeFallback, ctputDeviceInferFailTest) {
compile_model(::testing::Matcher<const std::shared_ptr<const ov::Model>&>(_),
::testing::Matcher<const std::string&>(StrEq("GPU.1")),
_))
.WillByDefault(Throw(ov::Exception{"compile model error"}));
.WillByDefault(ov::Throw("compile model error"));
}
for (auto& deviceInfo : targetDevices) {
std::string deviceName;
Expand Down Expand Up @@ -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<ov::mock_auto_plugin::MockAsyncInferRequest>(inferReqInternalGPU_1,
Expand Down Expand Up @@ -399,4 +399,4 @@ const std::vector<ConfigParams> testCtputConfigs = {
INSTANTIATE_TEST_SUITE_P(smoke_AutoCTPUTRuntimeFallback,
AutoCTPUTRuntimeFallback,
::testing::ValuesIn(testCtputConfigs),
AutoCTPUTRuntimeFallback::getTestCaseName);
AutoCTPUTRuntimeFallback::getTestCaseName);
6 changes: 3 additions & 3 deletions src/plugins/auto/tests/unit/select_device_failed_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ TEST_P(AutoLoadFailedTest, LoadCNNetWork) {
compile_model(::testing::Matcher<const std::shared_ptr<const ov::Model>&>(_),
::testing::Matcher<const std::string&>(StrEq(deviceName)),
(_)))
.WillByDefault(Throw(ov::Exception{"compile error"}));
.WillByDefault(ov::Throw("compile error"));
}
DeviceInformation devInfo;
switch (configModel) {
Expand Down Expand Up @@ -151,10 +151,10 @@ TEST_P(AutoLoadFailedTest, LoadCNNetWork) {
selDevsSize = deviceConfigs.size();
if (selDevsSize > 1) {
ON_CALL(*plugin, select_device(Property(&std::vector<DeviceInformation>::size, Eq(selDevsSize - 1)), _, _))
.WillByDefault(Throw(ov::Exception{""}));
.WillByDefault(ov::Throw(""));
} else {
ON_CALL(*plugin, select_device(Property(&std::vector<DeviceInformation>::size, Eq(1)), _, _))
.WillByDefault(Throw(ov::Exception{""}));
.WillByDefault(ov::Throw(""));
}
}

Expand Down

0 comments on commit a090338

Please sign in to comment.