runcitests.cmd 10 KB

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