hcttest.cmd 14 KB

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