hcttest.cmd 13 KB

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