hcttest.cmd 11 KB

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