runcitests.cmd 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. if "%_HadFailures%" == "1" (
  86. echo -- runcitests.cmd ^>^> Tests failed! 1>&2
  87. ) else (
  88. echo -- runcitests.cmd ^>^> Tests passed!
  89. )
  90. echo -- runcitests.cmd ^>^> Logs at %_DropRootDir%\testlogs
  91. popd
  92. exit /b %_HadFailures%
  93. :noTests
  94. echo -- runcitests.cmd ^>^> The tests are not supported on this build configuration.
  95. echo -- runcitests.cmd ^>^> No tests were run. This is expected.
  96. echo -- runcitests.cmd ^>^> Configuration: %_BuildArch% %_BuildType%
  97. exit /b 0
  98. :: ============================================================================
  99. :: Run one test suite against one build config and record if there were errors
  100. :: ============================================================================
  101. :runTests
  102. call :do %_TestDir%\runtests.cmd -%1%2 %3 -quiet -cleanupall -binDir %_StagingDir%\bin
  103. if ERRORLEVEL 1 set _HadFailures=1
  104. goto :eof
  105. :: ============================================================================
  106. :: Run jsrt test suite against one build config and record if there were errors
  107. :: ============================================================================
  108. :runNativeTests
  109. call :do %_TestDir%\runnativetests.cmd -%1%2 > %_TestDir%\logs\%1_%2\nativetests.log 2>&1
  110. if ERRORLEVEL 1 set _HadFailures=1
  111. goto :eof
  112. :: ============================================================================
  113. :: Copy all result logs to the drop share
  114. :: ============================================================================
  115. :copyLogsToDrop
  116. :: /S Copy all non-empty dirs
  117. :: /Y Do not prompt for overwriting destination files
  118. :: /C Continue copying if there are errors
  119. :: /I Assume destination is a directory if it does not exist
  120. call :do xcopy %_TestDir%\logs %_StagingDir%\testlogs /S /Y /C /I
  121. goto :eof
  122. :: ============================================================================
  123. :: Summarize the logs into a listing of only the failures
  124. :: ============================================================================
  125. :summarizeLogs
  126. pushd %_TestDir%\logs
  127. findstr /sp failed rl.results.log > %1
  128. findstr /sip failed nativetests.log >> %1
  129. rem Echo to stderr so that VSO includes the output in the build summary
  130. type %1 1>&2
  131. popd
  132. goto :eof
  133. :: ============================================================================
  134. :: Print usage
  135. :: ============================================================================
  136. :printUsage
  137. echo runcitests.cmd -x86^|-x64^|-arm -debug^|-test^|-release
  138. echo.
  139. echo Runs tests post-build for automated VSO TFS Builds.
  140. echo Depends on TFS Build environment.
  141. echo.
  142. echo Required switches:
  143. echo.
  144. echo Specify architecture of build to test:
  145. echo.
  146. echo -x86 Build arch of binaries is x86
  147. echo -x64 Build arch of binaries is x64
  148. echo -arm Build arch of binaries is ARM
  149. echo.
  150. echo Specify type of of build to test:
  151. echo.
  152. echo -debug Build type of binaries is debug
  153. echo -test Build type of binaries is test
  154. echo -release Build type of binaries is release
  155. echo.
  156. echo Shorthand combinations can be used, e.g. -x64debug
  157. echo.
  158. echo Note: No tests are run for ARM or release as they are
  159. echo not supported. The switches are provided for tooling
  160. echo convenience.
  161. goto :eof
  162. :: ============================================================================
  163. :: Print how to get help
  164. :: ============================================================================
  165. :printGetHelp
  166. echo For help use runcitests.cmd -?
  167. goto :eof
  168. :: ============================================================================
  169. :: Parse the user arguments into environment variables
  170. :: ============================================================================
  171. :parseArgs
  172. :NextArgument
  173. if "%1" == "-?" set fShowUsage=1& goto :ArgOk
  174. if "%1" == "/?" set fShowUsage=1& goto :ArgOk
  175. if /i "%1" == "-x86" set _BuildArch=x86& goto :ArgOk
  176. if /i "%1" == "-x64" set _BuildArch=x64& goto :ArgOk
  177. if /i "%1" == "-arm" set _BuildArch=arm& goto :ArgOk
  178. if /i "%1" == "-debug" set _BuildType=debug& goto :ArgOk
  179. if /i "%1" == "-test" set _BuildType=test& goto :ArgOk
  180. if /i "%1" == "-release" set _BuildType=release& goto :ArgOk
  181. if /i "%1" == "-x86debug" set _BuildArch=x86&set _BuildType=debug& goto :ArgOk
  182. if /i "%1" == "-x64debug" set _BuildArch=x64&set _BuildType=debug& goto :ArgOk
  183. if /i "%1" == "-armdebug" set _BuildArch=arm&set _BuildType=debug& goto :ArgOk
  184. if /i "%1" == "-x86test" set _BuildArch=x86&set _BuildType=test& goto :ArgOk
  185. if /i "%1" == "-x64test" set _BuildArch=x64&set _BuildType=test& goto :ArgOk
  186. if /i "%1" == "-armtest" set _BuildArch=arm&set _BuildType=test& goto :ArgOk
  187. if /i "%1" == "-x86release" set _BuildArch=x86&set _BuildType=release& goto :ArgOk
  188. if /i "%1" == "-x64release" set _BuildArch=x64&set _BuildType=release& goto :ArgOk
  189. if /i "%1" == "-armrelease" set _BuildArch=arm&set _BuildType=release& goto :ArgOk
  190. if /i "%1" == "-all" set _RunAll=1& goto :ArgOk
  191. if not "%1" == "" set _ExtraArgs=%_ExtraArgs% %1& goto :ArgOk
  192. goto :eof
  193. :ArgOk
  194. shift
  195. goto :NextArgument
  196. :: ============================================================================
  197. :: Validate arguments; if non specified default to -all
  198. :: ============================================================================
  199. :validateArgs
  200. if "%_BuildArch%" == "" (
  201. set _RunAll=1
  202. )
  203. if "%_BuildType%" == "" (
  204. set _RunAll=1
  205. )
  206. goto :eof
  207. :: ============================================================================
  208. :: Echo a command line before executing it
  209. :: ============================================================================
  210. :do
  211. echo -- runcitests.cmd ^>^> %*
  212. cmd /s /c "%*"
  213. goto :eof
  214. :: ============================================================================
  215. :: Echo a command line before executing it and redirect the command's output
  216. :: to nul
  217. :: ============================================================================
  218. :doSilent
  219. echo -- runcitests.cmd ^>^> %* ^> nul 2^>^&1
  220. cmd /s /c "%* > nul 2>&1"
  221. goto :eof