Spawn child process to run DeviceLostRecovery scenario test (#2530)

* Spawn child process to run DeviceLostRecovery scenario test
This commit is contained in:
Ryan Lai 2019-12-03 15:38:04 -08:00 committed by GitHub
parent c615002f5d
commit 3afb7a89fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<ID3D12Device5> d3d12Device;
D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, __uuidof(ID3D12Device5), d3d12Device.put_void());
d3d12Device->RemoveDevice();
}
// force device lost here
{
winrt::com_ptr<ID3D12Device5> 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)