runcitests.cmd 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. call :do %_TestDir%\runtests.cmd -%1%2 %3 -quiet -cleanupall -binDir %_StagingDir%\bin
  110. if "%_error%" NEQ "0" (
  111. echo -- runcitests.cmd ^>^> runtests.cmd failed
  112. set _HadFailures=3
  113. )
  114. goto :eof
  115. :: ============================================================================
  116. :: Run jsrt test suite against one build config and record if there were errors
  117. :: ============================================================================
  118. :runNativeTests
  119. echo -- runcitests.cmd ^>^> Running native tests... this can take some time
  120. if not exist %_LogDir%\ mkdir %_LogDir%
  121. set _LogFile=%_TestDir%\logs\%1_%2\nativetests.log
  122. call :do %_TestDir%\runnativetests.cmd -%1%2 -d yes > %_LogFile% 2>&1
  123. echo -- runcitests.cmd ^>^> Running native tests... DONE!
  124. if "%_error%" NEQ "0" (
  125. echo -- runcitests.cmd ^>^> runnativetests.cmd failed; printing %_LogFile%
  126. powershell "if (Test-Path %_LogFile%) { Get-Content %_LogFile% }"
  127. set _HadFailures=4
  128. )
  129. goto :eof
  130. :: ============================================================================
  131. :: Copy all result logs to the drop share
  132. :: ============================================================================
  133. :copyLogsToDrop
  134. :: /S Copy all non-empty dirs
  135. :: /Y Do not prompt for overwriting destination files
  136. :: /C Continue copying if there are errors
  137. :: /I Assume destination is a directory if it does not exist
  138. call :do xcopy %_TestDir%\logs %_StagingDir%\testlogs /S /Y /C /I
  139. goto :eof
  140. :: ============================================================================
  141. :: Summarize the logs into a listing of only the failures
  142. :: ============================================================================
  143. :summarizeLogs
  144. pushd %_TestDir%\logs
  145. findstr /sp failed rl.results.log > %1
  146. findstr /sip failed nativetests.log >> %1
  147. rem Echo to stderr so that VSO includes the output in the build summary
  148. type %1 1>&2
  149. popd
  150. goto :eof
  151. :: ============================================================================
  152. :: Print usage
  153. :: ============================================================================
  154. :printUsage
  155. echo runcitests.cmd -x86^|-x64^|-arm -debug^|-test^|-release
  156. echo.
  157. echo Runs tests post-build for automated VSO TFS Builds.
  158. echo Depends on TFS Build environment.
  159. echo.
  160. echo Required switches:
  161. echo.
  162. echo Specify architecture of build to test:
  163. echo.
  164. echo -x86 Build arch of binaries is x86
  165. echo -x64 Build arch of binaries is x64
  166. echo -arm Build arch of binaries is ARM
  167. echo.
  168. echo Specify type of of build to test:
  169. echo.
  170. echo -debug Build type of binaries is debug
  171. echo -test Build type of binaries is test
  172. echo -release Build type of binaries is release
  173. echo.
  174. echo Shorthand combinations can be used, e.g. -x64debug
  175. echo.
  176. echo Note: No tests are run for ARM or release as they are
  177. echo not supported. The switches are provided for tooling
  178. echo convenience.
  179. goto :eof
  180. :: ============================================================================
  181. :: Print how to get help
  182. :: ============================================================================
  183. :printGetHelp
  184. echo For help use runcitests.cmd -?
  185. goto :eof
  186. :: ============================================================================
  187. :: Parse the user arguments into environment variables
  188. :: ============================================================================
  189. :parseArgs
  190. :NextArgument
  191. if "%1" == "-?" set fShowUsage=1& goto :ArgOk
  192. if "%1" == "/?" set fShowUsage=1& goto :ArgOk
  193. if /i "%1" == "-x86" set _BuildArch=x86& goto :ArgOk
  194. if /i "%1" == "-x64" set _BuildArch=x64& goto :ArgOk
  195. if /i "%1" == "-arm" set _BuildArch=arm& goto :ArgOk
  196. if /i "%1" == "-debug" set _BuildType=debug& goto :ArgOk
  197. if /i "%1" == "-test" set _BuildType=test& goto :ArgOk
  198. if /i "%1" == "-release" set _BuildType=release& goto :ArgOk
  199. if /i "%1" == "-x86debug" set _BuildArch=x86&set _BuildType=debug& goto :ArgOk
  200. if /i "%1" == "-x64debug" set _BuildArch=x64&set _BuildType=debug& goto :ArgOk
  201. if /i "%1" == "-armdebug" set _BuildArch=arm&set _BuildType=debug& goto :ArgOk
  202. if /i "%1" == "-x86test" set _BuildArch=x86&set _BuildType=test& goto :ArgOk
  203. if /i "%1" == "-x64test" set _BuildArch=x64&set _BuildType=test& goto :ArgOk
  204. if /i "%1" == "-armtest" set _BuildArch=arm&set _BuildType=test& goto :ArgOk
  205. if /i "%1" == "-x86release" set _BuildArch=x86&set _BuildType=release& goto :ArgOk
  206. if /i "%1" == "-x64release" set _BuildArch=x64&set _BuildType=release& goto :ArgOk
  207. if /i "%1" == "-armrelease" set _BuildArch=arm&set _BuildType=release& goto :ArgOk
  208. if /i "%1" == "-all" set _RunAll=1& goto :ArgOk
  209. if not "%1" == "" set _ExtraArgs=%_ExtraArgs% %1& goto :ArgOk
  210. goto :eof
  211. :ArgOk
  212. shift
  213. goto :NextArgument
  214. :: ============================================================================
  215. :: Validate arguments; if non specified default to -all
  216. :: ============================================================================
  217. :validateArgs
  218. if "%_BuildArch%" == "" (
  219. set _RunAll=1
  220. )
  221. if "%_BuildType%" == "" (
  222. set _RunAll=1
  223. )
  224. goto :eof
  225. :: ============================================================================
  226. :: Echo a command line before executing it
  227. :: ============================================================================
  228. :do
  229. echo -- runcitests.cmd ^>^> %*
  230. cmd /s /c "%*"
  231. set _error=%ERRORLEVEL%
  232. goto :eof
  233. :: ============================================================================
  234. :: Echo a command line before executing it and redirect the command's output
  235. :: to nul
  236. :: ============================================================================
  237. :doSilent
  238. echo -- runcitests.cmd ^>^> %* ^> nul 2^>^&1
  239. cmd /s /c "%* > nul 2>&1"
  240. set _error=%ERRORLEVEL%
  241. goto :eof