Skip to content

Commit b93f6a4

Browse files
Moved HANDLE management to Test Class Constructor and Destructor (microsoft#7357)
Test class `ShaderOpTest` had a `HANDLE` not closed after `RunShaderOp` test ran. Created a constructor and destructor for the Test Class to manage the `HANDLE`.
1 parent 0beaa76 commit b93f6a4

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

tools/clang/unittests/HLSLExec/ShaderOpTest.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ void CommandListRefs::CreateForDevice(ID3D12Device *pDevice, bool compute) {
258258
IID_PPV_ARGS(&List)));
259259
}
260260

261+
ShaderOpTest::ShaderOpTest() {
262+
m_hFence = CreateEvent(nullptr, FALSE, FALSE, nullptr);
263+
if (m_hFence == nullptr) {
264+
AtlThrow(HRESULT_FROM_WIN32(GetLastError()));
265+
}
266+
}
267+
268+
ShaderOpTest::~ShaderOpTest() { CloseHandle(m_hFence); }
269+
261270
void ShaderOpTest::CopyBackResources() {
262271
CommandListRefs ResCommandList;
263272
ResCommandList.CreateForDevice(m_pDevice, m_pShaderOp->IsCompute());
@@ -423,10 +432,6 @@ void ShaderOpTest::CreateDevice() {
423432
CHECK_HR(m_pDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE,
424433
__uuidof(ID3D12Fence), (void **)&m_pFence));
425434
m_pFence->SetName(L"ShaderOpTest Fence");
426-
m_hFence = CreateEvent(nullptr, FALSE, FALSE, nullptr);
427-
if (m_hFence == nullptr) {
428-
AtlThrow(HRESULT_FROM_WIN32(GetLastError()));
429-
}
430435
}
431436

432437
static void InitByteCode(D3D12_SHADER_BYTECODE *pBytecode, ID3D10Blob *pBlob) {

tools/clang/unittests/HLSLExec/ShaderOpTest.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ class ShaderOpTest {
275275
typedef std::function<void(LPCSTR Name, LPCSTR pText, IDxcBlob **ppShaderBlob,
276276
ShaderOp *pShaderOp)>
277277
TShaderCallbackFn;
278+
279+
ShaderOpTest();
280+
~ShaderOpTest();
278281
void GetPipelineStats(D3D12_QUERY_DATA_PIPELINE_STATISTICS *pStats);
279282
void GetReadBackData(LPCSTR pResourceName, MappedData *pData);
280283
void RunShaderOp(ShaderOp *pShaderOp);

0 commit comments

Comments
 (0)