runcitests.cmd 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. ::-------------------------------------------------------------------------------------------------------
  2. :: Copyright (C) Microsoft. All rights reserved.
  3. :: Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. ::-------------------------------------------------------------------------------------------------------
  5. :: ============================================================================
  6. ::
  7. :: runcitests.cmd
  8. ::
  9. :: Runs tests for continuous integration. This script is called from the VSO
  10. :: build and it runs all tests for x86 and x64, debug and test build configs.
  11. :: Logs are copied to build drop.
  12. ::
  13. :: Do not use this script to run all tests on your dev box.
  14. :: - It will delete all your existing test logs
  15. :: - It does not run the various flavors of the tests in parallel (though
  16. :: this is not currently possible anyway because rl stages logs in a
  17. :: common directory)
  18. :: - It does nothing to provide useful output when there are failures, e.g.
  19. :: they can be buried under thousands of lines of output from further
  20. :: tests run.
  21. :: - It cannot be cancelled without risk of polluting your command prompt
  22. :: environment with environment variables that will make further calls to
  23. :: runtests.cmd behave unexpectedly.
  24. :: - It will copy the logs to a folder named \testlogs in the directory you
  25. :: started this script from.
  26. ::
  27. :: ============================================================================
  28. @echo off
  29. setlocal
  30. if "%TF_BUILD_BINARIESDIRECTORY%" == "" (
  31. echo TF_BUILD_BINARIESDIRECTORY is required for this script to work correctly.
  32. exit /b 1
  33. )
  34. set _RootDir=%~dp0..
  35. set _StagingDir=%TF_BUILD_BINARIESDIRECTORY%
  36. REM %TF_BUILD_DROPLOCATION% is not required -- used only for an informational message
  37. set _DropRootDir=%TF_BUILD_DROPLOCATION%
  38. set _HadFailures=0
  39. :: ============================================================================
  40. :: Main script
  41. :: ============================================================================
  42. :main
  43. call :parseArgs %*
  44. if not "%fShowUsage%" == "" (
  45. call :printUsage
  46. goto :eof
  47. )
  48. call :validateArgs
  49. if not "%fShowGetHelp%" == "" (
  50. call :printGetHelp
  51. goto :eof
  52. )
  53. if not "%TF_BUILD%" == "True" (
  54. echo Error: TF_BUILD environment variable is not set to "True".
  55. echo This script must be run under a TF Build Agent environment.
  56. exit /b 2
  57. )
  58. :: Cannot run tests for arm on build machine and release builds
  59. :: do not work with ch.exe so no-op those configurations.
  60. :: Include _RunAll in the check because if it is specified it
  61. :: should trump this early out.
  62. if "%_RunAll%%_BuildArch%" == "arm" goto :noTests
  63. if "%_RunAll%%_BuildArch%" == "arm64" goto :noTests
  64. if "%_RunAll%%_BuildType%" == "release" goto :noTests
  65. pushd %_RootDir%\test
  66. set _TestDir=%CD%
  67. call :doSilent rd /s/q %_TestDir%\logs
  68. if not "%_RunAll%" == "" (
  69. call :runTests x86 debug
  70. call :runTests x86 test
  71. call :runTests x64 debug
  72. call :runTests x64 test
  73. call :runNativeTests x86 debug
  74. call :runNativeTests x86 test
  75. call :runNativeTests x64 debug
  76. call :runNativeTests x64 test
  77. call :summarizeLogs summary.log
  78. ) else (
  79. call :runTests %_BuildArch% %_BuildType% %_ExtraArgs%
  80. call :runNativeTests %_BuildArch% %_BuildType%
  81. call :summarizeLogs summary.%_BuildArch%%_BuildType%.log
  82. )
  83. call :copyLogsToDrop
  84. echo.
  85. echo -- runcitests.cmd ^>^> Failure code: %_HadFailures%
  86. if "%_HadFailures%" NEQ "0" (
  87. if "%_HadFailures%" == "3" (
  88. echo -- runcitests.cmd ^>^> Unit tests failed! 1>&2
  89. ) else if "%_HadFailures%" == "4" (
  90. echo -- runcitests.cmd ^>^> Native tests failed! 1>&2
  91. ) else (
  92. echo -- runcitests.cmd ^>^> Unknown failure! 1>&2
  93. )
  94. ) else (
  95. echo -- runcitests.cmd ^>^> Tests passed!
  96. )
  97. echo -- runcitests.cmd ^>^> Logs at %_DropRootDir%\testlogs
  98. popd
  99. exit /b %_HadFailures%
  100. :noTests
  101. echo -- runcitests.cmd ^>^> The tests are not supported on this build configuration.
  102. echo -- runcitests.cmd ^>^> No tests were run. This is expected.
  103. echo -- runcitests.cmd ^>^> Configuration: %_BuildArch% %_BuildType%
  104. exit /b 0
  105. :: ============================================================================
  106. :: Run one test suite against one build config and record if there were errors
  107. :: ============================================================================
  108. :runTests
  109. :: save the architecture and build values, then obtain the rest of the arguments
  110. set arch=%1
  111. set build=%2
  112. shift
  113. shift
  114. set rest=
  115. :rest_loop
  116. if "%1"=="" goto after_rest_loop
  117. set rest=%rest% %1
  118. shift
  119. goto rest_loop
  120. :after_rest_loop
  121. call :do %_TestDir%\runtests.cmd -%arch%%build% %rest% -quiet -cleanupall -binDir %_StagingDir%\bin
  122. if "%_error%" NEQ "0" (
  123. echo -- runcitests.cmd ^>^> runtests.cmd failed
  124. set _HadFailures=3
  125. )
  126. goto :eof
  127. :: ============================================================================
  128. :: Run jsrt test suite against one build config and record if there were errors
  129. :: ============================================================================
  130. :runNativeTests
  131. echo -- runcitests.cmd ^>^> Running native tests... this can take some time
  132. if not exist %_LogDir%\ mkdir %_LogDir%
  133. set _LogFile=%_TestDir%\logs\%1_%2\nativetests.log
  134. call :do %_TestDir%\runnativetests.cmd -%1%2 -d yes > %_LogFile% 2>&1
  135. echo -- runcitests.cmd ^>^> Running native tests... DONE!
  136. if "%_error%" NEQ "0" (
  137. echo -- runcitests.cmd ^>^> runnativetests.cmd failed; printing %_LogFile%
  138. powershell "if (Test-Path %_LogFile%) { Get-Content %_LogFile% }"
  139. set _HadFailures=4
  140. )
  141. goto :eof
  142. :: ============================================================================
  143. :: Copy all result logs to the drop share
  144. :: ============================================================================
  145. :copyLogsToDrop
  146. :: /S Copy all non-empty dirs
  147. :: /Y Do not prompt for overwriting destination files
  148. :: /C Continue copying if there are errors
  149. :: /I Assume destination is a directory if it does not exist
  150. call :do xcopy %_TestDir%\logs %_StagingDir%\testlogs /S /Y /C /I
  151. goto :eof
  152. :: ============================================================================
  153. :: Summarize the logs into a listing of only the failures
  154. :: ============================================================================
  155. :summarizeLogs
  156. pushd %_TestDir%\logs
  157. findstr /sp failed rl.results.log > %1
  158. findstr /sip failed nativetests.log >> %1
  159. rem Echo to stderr so that VSO includes the output in the build summary
  160. type %1 1>&2
  161. popd
  162. goto :eof
  163. :: ============================================================================
  164. :: Print usage
  165. :: ============================================================================
  166. :printUsage
  167. echo runcitests.cmd -x86^|-x64^|-arm -debug^|-test^|-release
  168. echo.
  169. echo Runs tests post-build for automated VSO TFS Builds.
  170. echo Depends on TFS Build environment.
  171. echo.
  172. echo Required switches:
  173. echo.
  174. echo Specify architecture of build to test:
  175. echo.
  176. echo -x86 Build arch of binaries is x86
  177. echo -x64 Build arch of binaries is x64
  178. echo -arm Build arch of binaries is ARM
  179. echo.
  180. echo Specify type of of build to test:
  181. echo.
  182. echo -debug Build type of binaries is debug
  183. echo -test Build type of binaries is test
  184. echo -release Build type of binaries is release
  185. echo.
  186. echo Shorthand combinations can be used, e.g. -x64debug
  187. echo.
  188. echo Note: No tests are run for ARM or release as they are
  189. echo not supported. The switches are provided for tooling
  190. echo convenience.
  191. goto :eof
  192. :: ============================================================================
  193. :: Print how to get help
  194. :: ============================================================================
  195. :printGetHelp
  196. echo For help use runcitests.cmd -?
  197. goto :eof
  198. :: ============================================================================
  199. :: Parse the user arguments into environment variables
  200. :: ============================================================================
  201. :parseArgs
  202. :NextArgument
  203. if "%1" == "-?" set fShowUsage=1& goto :ArgOk
  204. if "%1" == "/?" set fShowUsage=1& goto :ArgOk
  205. if /i "%1" == "-x86" set _BuildArch=x86& goto :ArgOk
  206. if /i "%1" == "-x64" set _BuildArch=x64& goto :ArgOk
  207. if /i "%1" == "-arm" set _BuildArch=arm& goto :ArgOk
  208. if /i "%1" == "-debug" set _BuildType=debug& goto :ArgOk
  209. if /i "%1" == "-test" set _BuildType=test& goto :ArgOk
  210. if /i "%1" == "-release" set _BuildType=release& goto :ArgOk
  211. if /i "%1" == "-x86debug" set _BuildArch=x86&set _BuildType=debug& goto :ArgOk
  212. if /i "%1" == "-x64debug" set _BuildArch=x64&set _BuildType=debug& goto :ArgOk
  213. if /i "%1" == "-armdebug" set _BuildArch=arm&set _BuildType=debug& goto :ArgOk
  214. if /i "%1" == "-x86test" set _BuildArch=x86&set _BuildType=test& goto :ArgOk
  215. if /i "%1" == "-x64test" set _BuildArch=x64&set _BuildType=test& goto :ArgOk
  216. if /i "%1" == "-armtest" set _BuildArch=arm&set _BuildType=test& goto :ArgOk
  217. if /i "%1" == "-x86release" set _BuildArch=x86&set _BuildType=release& goto :ArgOk
  218. if /i "%1" == "-x64release" set _BuildArch=x64&set _BuildType=release& goto :ArgOk
  219. if /i "%1" == "-armrelease" set _BuildArch=arm&set _BuildType=release& goto :ArgOk
  220. if /i "%1" == "-all" set _RunAll=1& goto :ArgOk
  221. if not "%1" == "" set _ExtraArgs=%_ExtraArgs% %1& goto :ArgOk
  222. goto :eof
  223. :ArgOk
  224. shift
  225. goto :NextArgument
  226. :: ============================================================================
  227. :: Validate arguments; if non specified default to -all
  228. :: ============================================================================
  229. :validateArgs
  230. if "%_BuildArch%" == "" (
  231. set _RunAll=1
  232. )
  233. if "%_BuildType%" == "" (
  234. set _RunAll=1
  235. )
  236. goto :eof
  237. :: ============================================================================
  238. :: Echo a command line before executing it
  239. :: ============================================================================
  240. :do
  241. echo -- runcitests.cmd ^>^> %*
  242. cmd /s /c "%*"
  243. set _error=%ERRORLEVEL%
  244. goto :eof
  245. :: ============================================================================
  246. :: Echo a command line before executing it and redirect the command's output
  247. :: to nul
  248. :: ============================================================================
  249. :doSilent
  250. echo -- runcitests.cmd ^>^> %* ^> nul 2^>^&1
  251. cmd /s /c "%* > nul 2>&1"
  252. set _error=%ERRORLEVEL%
  253. goto :eof