From 3afb7a89fe1941a108c0a7d89db70884b3c1a792 Mon Sep 17 00:00:00 2001 From: Ryan Lai Date: Tue, 3 Dec 2019 15:38:04 -0800 Subject: [PATCH] Spawn child process to run DeviceLostRecovery scenario test (#2530) * Spawn child process to run DeviceLostRecovery scenario test --- .../cppwinrt/scenariotestscppwinrt.cpp | 78 +++++++++++-------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/winml/test/scenario/cppwinrt/scenariotestscppwinrt.cpp b/winml/test/scenario/cppwinrt/scenariotestscppwinrt.cpp index c4dab13598..c037685217 100644 --- a/winml/test/scenario/cppwinrt/scenariotestscppwinrt.cpp +++ b/winml/test/scenario/cppwinrt/scenariotestscppwinrt.cpp @@ -66,6 +66,7 @@ protected: GPUTEST } }; +using ScenarioCppWinrtGpuTestDeathTest = ScenarioCppWinrtGpuTest; class ScenarioCppWinrtGpuSkipEdgeCoreTest : public ScenarioCppWinrtTest { @@ -1442,44 +1443,55 @@ TEST_F(ScenarioCppWinrtTest, EncryptedStream) EXPECT_NO_THROW(session = LearningModelSession(model)); } -TEST_F(ScenarioCppWinrtGpuTest, DeviceLostRecovery) +void DeviceLostRecoveryHelper() { - // load a model - std::wstring filePath = FileHelpers::GetModulePath() + L"model.onnx"; - LearningModel model = LearningModel::LoadFromFilePath(filePath); - // create a session on the DirectX device - LearningModelSession session(model, LearningModelDevice(LearningModelDeviceKind::DirectX)); - // create a binding set - LearningModelBinding binding(session); - // bind the inputs - BindFeatures(binding, model.InputFeatures()); + // load a model + std::wstring filePath = FileHelpers::GetModulePath() + L"model.onnx"; + LearningModel model = LearningModel::LoadFromFilePath(filePath); + // create a session on the DirectX device + LearningModelSession session(model, LearningModelDevice(LearningModelDeviceKind::DirectX)); + // create a binding set + LearningModelBinding binding(session); + // bind the inputs + BindFeatures(binding, model.InputFeatures()); - // force device lost here - { - winrt::com_ptr d3d12Device; - D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, __uuidof(ID3D12Device5), d3d12Device.put_void()); - d3d12Device->RemoveDevice(); - } + // force device lost here + { + winrt::com_ptr d3d12Device; + D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, __uuidof(ID3D12Device5), d3d12Device.put_void()); + d3d12Device->RemoveDevice(); + } - // evaluate should fail - try - { - session.Evaluate(binding, L""); - FAIL() << "Evaluate should fail after removing the device"; - } - catch(...) - { - } + // evaluate should fail + try + { + session.Evaluate(binding, L""); + FAIL() << "Evaluate should fail after removing the device"; + } + catch (...) + { + } - // remove all references to the device by reseting the session and binding. - session = nullptr; - binding = nullptr; + // remove all references to the device by reseting the session and binding. + session = nullptr; + binding = nullptr; - // create new session and binding and try again! - EXPECT_NO_THROW(session = LearningModelSession(model, LearningModelDevice(LearningModelDeviceKind::DirectX))); - EXPECT_NO_THROW(binding = LearningModelBinding(session)); - BindFeatures(binding, model.InputFeatures()); - EXPECT_NO_THROW(session.Evaluate(binding, L"")); + // create new session and binding and try again! + session = LearningModelSession(model, LearningModelDevice(LearningModelDeviceKind::DirectX)); + binding = LearningModelBinding(session); + BindFeatures(binding, model.InputFeatures()); + session.Evaluate(binding, L""); + exit(0); +} + +TEST_F(ScenarioCppWinrtGpuTestDeathTest, DeviceLostRecovery) { + + ::testing::FLAGS_gtest_death_test_style = "threadsafe"; + EXPECT_EXIT( + DeviceLostRecoveryHelper(), + ::testing::ExitedWithCode(0), + "" + ); } TEST_F(ScenarioCppWinrtGpuSkipEdgeCoreTest, D2DInterop)