From 1b539d8907af3cc77e52e8cf4edf029964e0423a Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Fri, 2 May 2025 20:08:49 +0000 Subject: Fix intermittent failure of slang-unit-test-tool/ReplayRecord (#6981) * Fix intermittent failure of slang-unit-test-tool/ReplayRecord Three problems are addressed: 1. the graphics driver sometimes returns nullptr from GetShaderIdentifier 2. `findRecordFileName()` may not find any records at all. 3. the return value from cleanupRecordFiles() overwrote the error value in `res` and it returned SLANG_OK even when there were errors. * Fix compiler warnings on Windows --- examples/example-winmain/main.cpp | 1 + examples/stacktrace-windows/common.cpp | 2 +- tools/gfx/d3d12/d3d12-shader-table.cpp | 2 ++ tools/slang-unit-test/unit-test-record-replay.cpp | 7 ++++++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/example-winmain/main.cpp b/examples/example-winmain/main.cpp index 8094e7fc4..a64328105 100644 --- a/examples/example-winmain/main.cpp +++ b/examples/example-winmain/main.cpp @@ -1,3 +1,4 @@ +#define _CRT_SECURE_NO_WARNINGS #include "../stacktrace-windows/common.h" #include diff --git a/examples/stacktrace-windows/common.cpp b/examples/stacktrace-windows/common.cpp index 98fa8ad78..54cf6622e 100644 --- a/examples/stacktrace-windows/common.cpp +++ b/examples/stacktrace-windows/common.cpp @@ -163,7 +163,7 @@ int exceptionFilter(FILE* logFile, _EXCEPTION_POINTERS* exception) FILE* file = logFile ? logFile : stdout; fprintf( file, - "error: Exception 0x%x occurred. Stack trace:\n", + "error: Exception 0x%lx occurred. Stack trace:\n", exception->ExceptionRecord->ExceptionCode); HANDLE process = GetCurrentProcess(); diff --git a/tools/gfx/d3d12/d3d12-shader-table.cpp b/tools/gfx/d3d12/d3d12-shader-table.cpp index be537c737..66d63bed1 100644 --- a/tools/gfx/d3d12/d3d12-shader-table.cpp +++ b/tools/gfx/d3d12/d3d12-shader-table.cpp @@ -61,6 +61,8 @@ RefPtr ShaderTableImpl::createDeviceBuffer( if (name.getLength()) { void* shaderId = stateObjectProperties->GetShaderIdentifier(name.toWString().begin()); + if (nullptr == shaderId) + throw Exception(String("Failed to get shader identifier for '") + name + "'"); memcpy(dest, shaderId, D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES); } if (overwrite.size) diff --git a/tools/slang-unit-test/unit-test-record-replay.cpp b/tools/slang-unit-test/unit-test-record-replay.cpp index b6ed99aa5..efa01a67c 100644 --- a/tools/slang-unit-test/unit-test-record-replay.cpp +++ b/tools/slang-unit-test/unit-test-record-replay.cpp @@ -268,6 +268,11 @@ static SlangResult replayExample(UnitTestContext* context, List& { List fileNames; findRecordFileName(&fileNames); + if (fileNames.getCount() == 0) + { + getTestReporter()->message(TestMessageType::TestFailure, "No record files found\n"); + return SLANG_FAIL; + } List optArgs; String recordFileName = Path::combine("slang-record", fileNames[0]); @@ -406,7 +411,7 @@ static SlangResult runTest(UnitTestContext* context, const char* testName) } error: - res = cleanupRecordFiles(); + cleanupRecordFiles(); return res; } -- cgit v1.2.3