runcitests.cmd 9.3 KB

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