Skip to content

Commit 917de5d

Browse files
authored
LongVectors tests: Fix device leak and improve logging (#7951)
Previously, if a device is removed then the code that recreates it wouldn't release the old device pointer, resulting in the device leaking. This actually prevents removed device recovery entirely, since all references to a removed device need to be released before a new one can be created. This change fixes that. Also: * improve logging in situations where requirements aren't met (eg trying to create a SM 6.9 device on a system that doesn't support SM 6.9) * return false from class setup if we couldn't create a device - this will cause all the tests in the class to be skipped or failed (depending on the FailIfRequirementsNotMet setting) - reducing log noise, and saving the time that would be taken to run tests that we know are going to fail * improve logging when recreating a device so we can tell the difference between "device was removed" and "there wasn't a device set" * add a warning log if createDevice is called with something that looks like it already has a value set Fixes #7949
1 parent 3f85295 commit 917de5d

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ static UINT getD3D12SDKVersion(std::wstring SDKPath) {
6969

7070
bool createDevice(ID3D12Device **D3DDevice, D3D_SHADER_MODEL TestModel,
7171
bool SkipUnsupported) {
72+
73+
if (*D3DDevice)
74+
hlsl_test::LogWarningFmt(L"createDevice called with non-null *D3DDevice - "
75+
L"this will likely leak the previous device");
76+
7277
if (TestModel > D3D_HIGHEST_SHADER_MODEL) {
7378
const UINT Minor = (UINT)TestModel & 0x0f;
7479
hlsl_test::LogCommentFmt(L"Installed SDK does not support "

tools/clang/unittests/HLSLExec/LongVectors.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,17 @@ class DxilConf_SM69_Vectorized {
18191819
L"FailIfRequirementsNotMet", FailIfRequirementsNotMet);
18201820

18211821
const bool SkipUnsupported = !FailIfRequirementsNotMet;
1822-
createDevice(&D3DDevice, D3D_SHADER_MODEL_6_9, SkipUnsupported);
1822+
if (!createDevice(&D3DDevice, D3D_SHADER_MODEL_6_9, SkipUnsupported)) {
1823+
if (FailIfRequirementsNotMet)
1824+
hlsl_test::LogErrorFmt(
1825+
L"Device Creation failed, resulting in test failure, since "
1826+
L"FailIfRequirementsNotMet is set. The expectation is that this "
1827+
L"test will only be executed if something has previously "
1828+
L"determined that the system meets the requirements of this "
1829+
L"test.");
1830+
1831+
return false;
1832+
}
18231833
}
18241834

18251835
return true;
@@ -1828,10 +1838,21 @@ class DxilConf_SM69_Vectorized {
18281838
TEST_METHOD_SETUP(methodSetup) {
18291839
// It's possible a previous test case caused a device removal. If it did we
18301840
// need to try and create a new device.
1831-
if (!D3DDevice || D3DDevice->GetDeviceRemovedReason() != S_OK) {
1832-
hlsl_test::LogCommentFmt(
1833-
L"Device was lost: Attempting to create a new D3D12 device.");
1834-
VERIFY_IS_TRUE(createDevice(&D3DDevice, D3D_SHADER_MODEL_6_9, false));
1841+
if (D3DDevice && D3DDevice->GetDeviceRemovedReason() != S_OK) {
1842+
hlsl_test::LogCommentFmt(L"Device was lost!");
1843+
D3DDevice.Release();
1844+
}
1845+
1846+
if (!D3DDevice) {
1847+
hlsl_test::LogCommentFmt(L"Creating device");
1848+
1849+
// We expect this to succeed, and fail if it doesn't, because classSetup()
1850+
// has already ensured that the system configuration meets the
1851+
// requirements of all the tests in this class.
1852+
const bool SkipUnsupported = false;
1853+
1854+
VERIFY_IS_TRUE(
1855+
createDevice(&D3DDevice, D3D_SHADER_MODEL_6_9, SkipUnsupported));
18351856
}
18361857

18371858
return true;

0 commit comments

Comments
 (0)