hcttest.cmd 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. if "%BUILD_CONFIG%"=="" (
  4. set BUILD_CONFIG=Debug
  5. )
  6. rem Whether we built the project using ninja as the generator.
  7. set GENERATOR_NINJA=0
  8. set TEST_ALL=1
  9. set TEST_CLANG=0
  10. set TEST_CMD=0
  11. set TEST_EXEC=0
  12. set TEST_EXTRAS=0
  13. set TEST_EXEC_REQUIRED=0
  14. set TEST_CLANG_FILTER= /select: "@Priority<1"
  15. set TEST_EXEC_FILTER=ExecutionTest::*
  16. set LOG_FILTER=/logOutput:LowWithConsoleBuffering
  17. set TEST_COMPAT_SUITE=0
  18. set COMPAT_SUIT_PATH=
  19. set TEST_SINGLE_FILE_CHECK=0
  20. set SINGLE_FILE_CHECK_NAME=0
  21. rem Begin SPIRV change
  22. set TEST_SPIRV=0
  23. set TEST_SPIRV_ONLY=0
  24. rem End SPIRV change
  25. set HCT_DIR=%~dp0
  26. if "%NUMBER_OF_PROCESSORS%"=="" (
  27. set PARALLEL_OPTION=
  28. ) else if %NUMBER_OF_PROCESSORS% LEQ 1 (
  29. set PARALLEL_OPTION=
  30. ) else if %NUMBER_OF_PROCESSORS% LEQ 4 (
  31. set PARALLEL_OPTION=/parallel:%NUMBER_OF_PROCESSORS%
  32. ) else (
  33. rem Sweet spot for /parallel seems to be NUMBER_OF_PROCESSORS - 1
  34. set /a PARALLEL_COUNT=%NUMBER_OF_PROCESSORS%-1
  35. set PARALLEL_OPTION=/parallel:!PARALLEL_COUNT!
  36. )
  37. :opt_loop
  38. if "%1"=="" (goto :done_opt)
  39. if "%1"=="/?" goto :showhelp
  40. if "%1"=="-?" goto :showhelp
  41. if "%1"=="-help" goto :showhelp
  42. if "%1"=="--help" goto :showhelp
  43. rem Begin SPIRV change
  44. if "%1"=="spirv" (
  45. set TEST_SPIRV=1
  46. shift /1
  47. )
  48. if "%1"=="spirv_only" (
  49. set TEST_SPIRV=1
  50. set TEST_SPIRV_ONLY=1
  51. shift /1
  52. )
  53. rem End SPIRV change
  54. if "%1"=="-clean" (
  55. set TEST_CLEAN=1
  56. ) else if "%1"=="clean" (
  57. set TEST_CLEAN=1
  58. set TEST_CLEAN_ONLY=1
  59. ) else if "%1"=="none" (
  60. set TEST_ALL=0
  61. ) else if "%1"=="clang" (
  62. set TEST_ALL=0
  63. set TEST_CLANG=1
  64. ) else if "%1"=="clang-filter" (
  65. set TEST_ALL=0
  66. set TEST_CLANG=1
  67. set TEST_CLANG_FILTER= /name:%2
  68. shift /1
  69. ) else if "%1"=="compat-suite" (
  70. set TEST_ALL=0
  71. set TEST_COMPAT_SUITE=1
  72. set COMPAT_SUIT_PATH= /p:"SuitePath=%~2"
  73. shift /1
  74. ) else if "%1"=="file-check" (
  75. set TEST_ALL=0
  76. set TEST_SINGLE_FILE_CHECK=1
  77. set COMPAT_SUIT_PATH= /p:"InputFile=%~2"
  78. shift /1
  79. ) else if "%1"=="v" (
  80. set TEST_ALL=0
  81. set TEST_CLANG=1
  82. set TEST_CLANG_FILTER= /name:VerifierTest::*
  83. ) else if "%1"=="cmd" (
  84. set TEST_ALL=0
  85. set TEST_CMD=1
  86. ) else if "%1"=="noexec" (
  87. set TEST_ALL=0
  88. set TEST_CLANG=1
  89. set TEST_CMD=1
  90. ) else if "%1"=="exec" (
  91. rem If exec is explicitly supplied, hcttest will fail if machine is not configured
  92. rem to run execution tests, otherwise, execution tests would be skipped.
  93. set TEST_ALL=0
  94. set TEST_EXEC=1
  95. set TEST_EXEC_REQUIRED=1
  96. ) else if "%1"=="exec-filter" (
  97. set TEST_ALL=0
  98. set TEST_EXEC=1
  99. set TEST_EXEC_FILTER=ExecutionTest::%2
  100. set TEST_EXEC_REQUIRED=1
  101. shift /1
  102. ) else if "%1"=="extras" (
  103. set TEST_ALL=0
  104. set TEST_EXTRAS=1
  105. ) else if "%1"=="-ninja" (
  106. set GENERATOR_NINJA=1
  107. ) else if "%1"=="-rel" (
  108. set BUILD_CONFIG=Release
  109. ) else if "%1"=="-x86" (
  110. rem Allow BUILD_ARCH override. This may be used by HCT_EXTRAS scripts.
  111. set BUILD_ARCH=Win32
  112. ) else if "%1"=="-x64" (
  113. set BUILD_ARCH=x64
  114. ) else if "%1"=="-arm" (
  115. set BUILD_ARCH=ARM
  116. ) else if "%1"=="-adapter" (
  117. set TEST_ADAPTER= /p:"Adapter=%~2"
  118. shift /1
  119. ) else if "%1"=="-verbose" (
  120. set LOG_FILTER=
  121. set PARALLEL_OPTION=
  122. ) else if "%1"=="--" (
  123. shift /1
  124. goto :done_opt
  125. ) else (
  126. goto :done_opt
  127. )
  128. shift /1
  129. goto :opt_loop
  130. :done_opt
  131. rem Collect additional arguments for tests
  132. :collect_args
  133. if "%1"=="" goto :done_args
  134. set ADDITIONAL_OPTS=%ADDITIONAL_OPTS% %1
  135. shift /1
  136. goto :collect_args
  137. :done_args
  138. rem By default, run clang tests and execution tests.
  139. if "%TEST_ALL%"=="1" (
  140. set TEST_CLANG=1
  141. set TEST_CMD=1
  142. set TEST_EXEC=1
  143. set TEST_EXTRAS=1
  144. )
  145. where te.exe 1>nul 2>nul
  146. if errorlevel 1 (
  147. echo Unable to find te.exe on path.
  148. exit /b 1
  149. )
  150. Rem For the Ninja generator, artifacts are not generated into a directory
  151. Rem matching the current build configuration; instead, they are generated
  152. Rem directly into bin/ under the build root directory.
  153. if "%GENERATOR_NINJA%"=="1" (
  154. set BIN_DIR=%HLSL_BLD_DIR%\bin
  155. set TEST_DIR=%HLSL_BLD_DIR%\test
  156. ) else (
  157. set BIN_DIR=%HLSL_BLD_DIR%\%BUILD_CONFIG%\bin
  158. set TEST_DIR=%HLSL_BLD_DIR%\%BUILD_CONFIG%\test
  159. )
  160. if "%TEST_CLEAN%"=="1" (
  161. echo Cleaning %TEST_DIR% ...
  162. if exist %TEST_DIR%\. (
  163. rmdir /q /s %TEST_DIR%
  164. )
  165. if "%TEST_CLEAN_ONLY%"=="1" (
  166. echo exiting after deleting test directory. if clean and test is desired, use -clean option.
  167. exit /b 0
  168. )
  169. )
  170. if not exist %TEST_DIR%\. (mkdir %TEST_DIR%)
  171. echo Copying binaries to test to %TEST_DIR%:
  172. call %HCT_DIR%\hctcopy.cmd %BIN_DIR% %TEST_DIR% dxa.exe dxc.exe dxexp.exe dxopt.exe dxr.exe dxv.exe clang-hlsl-tests.dll dxcompiler.dll d3dcompiler_dxc_bridge.dll dxl.exe dxc_batch.exe dxlib_sample.dll
  173. if errorlevel 1 exit /b 1
  174. rem Begin SPIRV change
  175. if "%TEST_SPIRV%"=="1" (
  176. if not exist %BIN_DIR%\clang-spirv-tests.exe (
  177. echo clang-spirv-tests.exe has not been built. Make sure you run "hctbuild -spirvtest" first.
  178. exit /b 1
  179. )
  180. echo Running SPIRV tests ...
  181. %BIN_DIR%\clang-spirv-tests.exe --spirv-test-root %HLSL_SRC_DIR%\tools\clang\test\CodeGenSPIRV
  182. if errorlevel 1 (
  183. echo Failure occured in SPIRV unit tests
  184. exit /b 1
  185. )
  186. if "%TEST_SPIRV_ONLY%"=="1" (
  187. exit /b 0
  188. )
  189. )
  190. rem End SPIRV change
  191. echo Running HLSL tests ...
  192. if exist "%HCT_EXTRAS%\hcttest-before.cmd" (
  193. call "%HCT_EXTRAS%\hcttest-before.cmd" %TEST_DIR%
  194. if errorlevel 1 (
  195. echo Fatal error, Failed command: "%HCT_EXTRAS%\hcttest-before.cmd" %TEST_DIR%
  196. exit /b 1
  197. )
  198. )
  199. if "%TEST_CLANG%"=="1" (
  200. echo Running Clang unit tests ...
  201. call :runte clang-hlsl-tests.dll /p:"HlslDataDir=%HLSL_SRC_DIR%\tools\clang\test\HLSL"%TEST_CLANG_FILTER%%ADDITIONAL_OPTS%
  202. set RES_CLANG=!ERRORLEVEL!
  203. )
  204. if "%TEST_CMD%"=="1" (
  205. copy /y %HLSL_SRC_DIR%\utils\hct\smoke.hlsl %TEST_DIR%\smoke.hlsl
  206. call %HLSL_SRC_DIR%\utils\hct\hcttestcmds.cmd %TEST_DIR% %HLSL_SRC_DIR%\tools\clang\test\HLSL
  207. set RES_CMD=!ERRORLEVEL!
  208. )
  209. if "%TEST_EXEC%"=="1" (
  210. echo Sniffing for D3D12 configuration ...
  211. call :runte clang-hlsl-tests.dll /p:"HlslDataDir=%HLSL_SRC_DIR%\tools\clang\test\HLSL" /name:ExecutionTest::BasicTriangleTest /runIgnoredTests /p:"ExperimentalShaders=*" %TEST_ADAPTER%
  212. rem /p:"ExperimentalShaders=*"
  213. set RES_EXEC=!ERRORLEVEL!
  214. if errorlevel 1 (
  215. if not "%TEST_EXEC_REQUIRED%"=="1" (
  216. echo Basic triangle test failed.
  217. echo Assuming this is an environmental limitation not a regression
  218. set TEST_EXEC=0
  219. ) else (
  220. echo Basic triangle test succeeded. Proceeding with execution tests.
  221. )
  222. )
  223. )
  224. if "%TEST_EXEC%"=="1" (
  225. call :runte clang-hlsl-tests.dll /p:"HlslDataDir=%HLSL_SRC_DIR%\tools\clang\test\HLSL" /select:"@Name='%TEST_EXEC_FILTER%' AND @Priority<2" /runIgnoredTests /p:"ExperimentalShaders=*" %TEST_ADAPTER% %ADDITIONAL_OPTS%
  226. set RES_EXEC=!ERRORLEVEL!
  227. )
  228. if exist "%HCT_EXTRAS%\hcttest-extras.cmd" (
  229. if "%TEST_EXTRAS%"=="1" (
  230. echo Running extra tests ...
  231. call "%HCT_EXTRAS%\hcttest-extras.cmd" %TEST_DIR%
  232. set RES_EXTRAS=!ERRORLEVEL!
  233. )
  234. )
  235. if exist "%HCT_EXTRAS%\hcttest-after.cmd" (
  236. call "%HCT_EXTRAS%\hcttest-after.cmd" %TEST_DIR%
  237. set RES_HCTTEST_AFTER=!ERRORLEVEL!
  238. )
  239. if "%TEST_SINGLE_FILE_CHECK%"=="1" (
  240. call :runte clang-hlsl-tests.dll /p:"HlslDataDir=%HLSL_SRC_DIR%\tools\clang\test\HLSL" /name:CompilerTest::SingleFileCheckTest /runIgnoredTests %COMPAT_SUIT_PATH%
  241. set RES_EXEC=!ERRORLEVEL!
  242. )
  243. if "%TEST_COMPAT_SUITE%"=="1" (
  244. call :runte clang-hlsl-tests.dll /p:"HlslDataDir=%HLSL_SRC_DIR%\tools\clang\test\HLSL" /name:CompilerTest::ShaderCompatSuite %COMPAT_SUIT_PATH%
  245. set RES_EXEC=!ERRORLEVEL!
  246. )
  247. echo.
  248. echo ==================================
  249. echo Unit test results:
  250. set TESTS_PASSED=0
  251. set TESTS_FAILED=0
  252. call :check_result "clang tests" %RES_CLANG%
  253. call :check_result "command line tests" %RES_CMD%
  254. if "%TEST_EXEC%"=="1" (
  255. call :check_result "execution tests" %RES_EXEC%
  256. )
  257. call :check_result "hcttest-extras tests" %RES_EXTRAS%
  258. call :check_result "hcttest-after script" %RES_HCTTEST_AFTER%
  259. if not "%TESTS_PASSED%"=="0" (
  260. echo %TESTS_PASSED% succeeded.
  261. ) else if "%TESTS_FAILED%"=="0" (
  262. echo No Unit tests run.
  263. )
  264. if not "%TESTS_FAILED%"=="0" (
  265. echo %TESTS_FAILED% failed.
  266. )
  267. echo ==================================
  268. exit /b %TESTS_FAILED%
  269. :showhelp
  270. echo Usage:
  271. echo hcttest [options] [target(s)] [-- additonal test arguments]
  272. echo.
  273. echo target can be empty or a specific subset.
  274. echo.
  275. echo If target if not specified, all tests will be run, but clang tests
  276. echo will be limited by /select: "@Priority<1" by default.
  277. echo You may specify 'clang-filter *' to run all clang tests.
  278. echo Multiple targets may be specified to choose which stages to run.
  279. echo.
  280. echo options:
  281. echo -clean - deletes test directory before copying binaries and testing
  282. echo -ninja - artifacts were built using the Ninja generator
  283. echo -rel - tests release rather than debug
  284. echo -adapter "adapter name" - overrides Adapter for execution tests
  285. echo -verbose - for TAEF: turns off /parallel and removes logging filter
  286. echo.
  287. echo current BUILD_ARCH=%BUILD_ARCH%. Override with:
  288. echo -x86 targets an x86 build (aka. Win32)
  289. echo -x64 targets an x64 build (aka. Win64)
  290. echo -arm targets an ARM build
  291. echo.
  292. echo target(s):
  293. echo clang - run clang tests.
  294. echo file-check - run file-check test on single file.
  295. echo - hcttest file-check "..\CodeGenHLSL\shader-compat-suite\lib_arg_flatten\lib_arg_flatten.hlsl"
  296. echo compat-suite - run compat-suite test.
  297. echo - hcttest compat-suite "..\CodeGenHLSL\shader-compat-suite\lib_arg_flatten"
  298. echo cmd - run command line tool tests.
  299. echo v - run the subset of clang tests that are verified-based.
  300. echo exec - run execution tests.
  301. echo extras - run hcttest-extras tests.
  302. echo noexec - all except exec and extras tests.
  303. echo.
  304. echo Select clang or exec targets with filter by test name:
  305. echo clang-filter Name
  306. echo exec-filter Name
  307. echo.
  308. echo Use the HCT_EXTRAS environment variable to add hcttest-before and hcttest-after hooks.
  309. echo.
  310. echo Delete test directory and do not copy binaries or run tests:
  311. echo hcttest clean
  312. echo.
  313. call :showtesample clang-hlsl-tests.dll /p:"HlslDataDir=%HLSL_SRC_DIR%\tools\clang\test\HLSL"
  314. goto :eof
  315. :runte
  316. rem Runs a unit test.
  317. rem %1 - the name of the binary to run
  318. rem %2 - first argument to te
  319. rem %3 - second argument to te
  320. rem %4 - third argument to te
  321. echo te /labMode /miniDumpOnCrash %LOG_FILTER% %PARALLEL_OPTION% %TEST_DIR%\%*
  322. call te /labMode /miniDumpOnCrash %LOG_FILTER% %PARALLEL_OPTION% %TEST_DIR%\%*
  323. if errorlevel 1 (
  324. call :showtesample %*
  325. exit /b 1
  326. )
  327. goto :eof
  328. :showtesample
  329. rem %1 - name of binary to demo
  330. rem %2 - first argument to te
  331. if "%TEST_DIR%"=="" (
  332. set TEST_DIR=%HLSL_BLD_DIR%\%BUILD_CONFIG%\test
  333. )
  334. echo You can debug the test with the following command line.
  335. echo start devenv /debugexe TE.exe /inproc %TEST_DIR%\%*
  336. echo.
  337. echo Use this te.exe for out-of-proc, or pick the correct one for the target arch, currently %BUILD_ARCH%.
  338. where te.exe
  339. echo.
  340. echo Use /name:TestClass* or /name:TestClass::MethodName to filter and /breakOnError to catch the failure.
  341. goto :eof
  342. :check_result
  343. if not "%2"=="" (
  344. if "%2"=="0" (
  345. echo [PASSED] %~1
  346. set /a TESTS_PASSED=%TESTS_PASSED%+1
  347. ) else (
  348. echo [FAILED] %~1
  349. set /a TESTS_FAILED=%TESTS_FAILED%+1
  350. )
  351. )
  352. goto :eof