hcttest.cmd 9.0 KB

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