From 6d148753870d6ea7aa8c601873fc7500a7c8437f Mon Sep 17 00:00:00 2001 From: Sofya Balandina Date: Wed, 19 Jan 2022 12:21:42 +0300 Subject: [PATCH] [IE TEST] Fix missing falls of HoldersTest in case of crash (#9277) --- .../include/behavior/plugin/life_time.hpp | 5 -- .../shared/src/behavior/plugin/life_time.cpp | 60 ++++++++++++------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/tests/functional/plugin/shared/include/behavior/plugin/life_time.hpp b/src/tests/functional/plugin/shared/include/behavior/plugin/life_time.hpp index 692c6f69b14..39cb28f6cbd 100644 --- a/src/tests/functional/plugin/shared/include/behavior/plugin/life_time.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/plugin/life_time.hpp @@ -33,9 +33,6 @@ public: void SetUp() override; - void TearDown() override; - - std::string deathTestStyle; std::vector order; std::shared_ptr function; std::string targetDevice; @@ -49,11 +46,9 @@ public: static std::string getTestCaseName(testing::TestParamInfo obj); void SetUp() override; - void TearDown() override; std::shared_ptr function; std::string targetDevice; - std::string deathTestStyle; }; } // namespace BehaviorTestsDefinitions \ No newline at end of file diff --git a/src/tests/functional/plugin/shared/src/behavior/plugin/life_time.cpp b/src/tests/functional/plugin/shared/src/behavior/plugin/life_time.cpp index 09dec2a65f3..df57618e916 100644 --- a/src/tests/functional/plugin/shared/src/behavior/plugin/life_time.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/plugin/life_time.cpp @@ -8,7 +8,17 @@ #include #include "behavior/plugin/life_time.hpp" +#ifndef _WIN32 + #include + #include +#endif + namespace BehaviorTestsDefinitions { + +#ifndef _WIN32 + static jmp_buf env; +#endif + std::string HoldersTest::getTestCaseName(testing::TestParamInfo obj) { std::string targetDevice; std::vector order; @@ -27,20 +37,22 @@ namespace BehaviorTestsDefinitions { void HoldersTest::SetUp() { SKIP_IF_CURRENT_TEST_IS_DISABLED(); std::tie(targetDevice, order) = this->GetParam(); - deathTestStyle = ::testing::GTEST_FLAG(death_test_style); - if (deathTestStyle == "fast") { - ::testing::GTEST_FLAG(death_test_style) = "threadsafe"; - } function = ngraph::builder::subgraph::makeConvPoolRelu(); - } - void HoldersTest::TearDown() { - ::testing::GTEST_FLAG(death_test_style) = deathTestStyle; +#ifndef _WIN32 + // configure handling of crash + auto crashHandler = [](int errCode) { + std::cerr << "Unexpected application crash with code: " << errCode << std::endl; + siglongjmp(env, 1); + }; + struct sigaction act; + act.sa_handler = crashHandler; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + sigaction(SIGSEGV, &act, 0); +#endif } -#define EXPECT_NO_CRASH(_statement) \ - EXPECT_EXIT(_statement; exit(0), testing::ExitedWithCode(0), "") - void release_order_test(std::vector order, const std::string &deviceName, std::shared_ptr function) { InferenceEngine::CNNNetwork cnnNet(function); @@ -79,12 +91,28 @@ namespace BehaviorTestsDefinitions { TEST_P(HoldersTest, Orders) { // Test failed if crash happens - EXPECT_NO_CRASH(release_order_test(order, targetDevice, function)); +#ifdef _WIN32 + EXPECT_NO_THROW(release_order_test(order, targetDevice, function)); +#else + if (sigsetjmp(env, 1) == 0) { + release_order_test(order, targetDevice, function); + } else { + IE_THROW() << "Crash happens"; + } +#endif } TEST_P(HoldersTestImportNetwork, Orders) { // Test failed if crash happens - EXPECT_NO_CRASH(release_order_test(order, targetDevice, function)); +#ifdef _WIN32 + EXPECT_NO_THROW(release_order_test(order, targetDevice, function)); +#else + if (sigsetjmp(env, 1) == 0) { + release_order_test(order, targetDevice, function); + } else { + IE_THROW() << "Crash happens"; + } +#endif } std::string HoldersTestOnImportedNetwork::getTestCaseName(testing::TestParamInfo obj) { @@ -94,17 +122,9 @@ namespace BehaviorTestsDefinitions { void HoldersTestOnImportedNetwork::SetUp() { SKIP_IF_CURRENT_TEST_IS_DISABLED(); targetDevice = this->GetParam(); - deathTestStyle = ::testing::GTEST_FLAG(death_test_style); - if (deathTestStyle == "fast") { - ::testing::GTEST_FLAG(death_test_style) = "threadsafe"; - } function = ngraph::builder::subgraph::makeConvPoolRelu(); } - void HoldersTestOnImportedNetwork::TearDown() { - ::testing::GTEST_FLAG(death_test_style) = deathTestStyle; - } - TEST_P(HoldersTestOnImportedNetwork, CreateRequestWithCoreRemoved) { InferenceEngine::CNNNetwork cnnNet(function); InferenceEngine::Core core = BehaviorTestsUtils::createIECoreWithTemplate();