Skip to content

Commit 5c4d3b6

Browse files
authored
hcttestcmds: Fix error handling and support skip cleanup on failure (microsoft#4879)
Fix problem with expression under :failed subroutine, and preserve Failed variable on endlocal in :cleanup subroutine. Use environment variable HLSL_TESTCMD_CLEANUP_ON_FAILURE to drive whether hcttestcmd cleans up temporary files on failure. Defaults to 1 (true) unless it's already set. You can set it to 0 to disable cleanup when the test fails. Fix originally intended behavior for -Vi test and check files for cleanup.
1 parent aac8727 commit 5c4d3b6

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

utils/hct/hcttestcmds.cmd

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ set FailingCmdWritten=0
1616
set OutputLog=%1\testcmd.log
1717
set LogOutput=1
1818

19+
if "%HLSL_TESTCMD_CLEANUP_ON_FAILURE%" == "" set HLSL_TESTCMD_CLEANUP_ON_FAILURE=1
20+
1921
pushd %1
2022

2123
set testname=Basic Rewriter Smoke Test
@@ -447,19 +449,19 @@ set testname=Test file with relative path and include
447449
mkdir subfolder 2>nul
448450
mkdir inc 2>nul
449451
copy "%testfiles%\include-main.hlsl" subfolder >nul
452+
call :check_file subfolder\include-main.hlsl
450453
copy "%testfiles%\include-declarations.h" inc >nul
454+
call :check_file inc\include-declarations.h
451455
call :run dxc.exe -Tps_6_0 -I inc subfolder\include-main.hlsl
452456
if %Failed% neq 0 goto :failed
453457
call :run dxc.exe -P include-main.hlsl.pp -I inc subfolder\include-main.hlsl
454458
if %Failed% neq 0 goto :failed
455459

456460
set testname=Test display include process with /Vi
457-
mkdir inc 2>nul
458-
copy "%testfiles%\include-declarations.h" inc >nul
459-
call :run dxc.exe -Tps_6_0 -Vi -I inc "%testfiles%\include-main.hlsl"
461+
call :run dxc.exe -Tps_6_0 -Vi -I inc subfolder\include-main.hlsl
460462
if %Failed% neq 0 goto :failed
461463
call :check_file log find "; Opening file ["
462-
call :check_file log find "include-declarations.h], stack top [0]"
464+
call :check_file log find "inc\include-declarations.h], stack top [0]"
463465
if %Failed% neq 0 goto :failed
464466

465467
set testname=Test Version macro
@@ -507,7 +509,9 @@ findstr /c:"SPIR-V CodeGen not available" %CD%\smoke.spirv.log >nul
507509
if %errorlevel% equ 0 set spirv_smoke_success=1
508510
if %spirv_smoke_success% neq 1 (
509511
echo dxc failed SPIR-V smoke test
510-
call :cleanup 2>nul
512+
if %HLSL_TESTCMD_CLEANUP_ON_FAILURE% equ 1 (
513+
call :cleanup 2>nul
514+
)
511515
exit /b 1
512516
)
513517
rem SPIR-V Change Ends
@@ -520,7 +524,7 @@ for %%f in (%cleanup_files%) do (
520524
del %%f 1>nul 2>nul
521525
)
522526
popd
523-
endlocal
527+
endlocal & set Failed=%Failed%
524528
exit /b 0
525529

526530
rem ============================================
@@ -678,6 +682,8 @@ exit /b 0
678682
rem ============================================
679683
rem Cleanup and return failure
680684
:failed
681-
call :cleanup 2>nul
682-
if %Failed% eq 0 set Failed=1
685+
if %HLSL_TESTCMD_CLEANUP_ON_FAILURE% neq 0 (
686+
call :cleanup 2>nul
687+
)
688+
if %Failed% equ 0 set Failed=1
683689
exit /b %Failed%

0 commit comments

Comments
 (0)