runcitests.cmd 9.9 KB

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