2
0

hcttest.cmd 12 KB

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