2
0

runnativetests.cmd 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. :: runnativetests.cmd
  8. ::
  9. :: ============================================================================
  10. @echo off
  11. setlocal
  12. goto :main
  13. :: ============================================================================
  14. :: Print usage
  15. :: ============================================================================
  16. :printUsage
  17. echo runnativetests.cmd -x86^|-x64 -debug^|-test [--help]
  18. echo.
  19. echo Required switches:
  20. echo.
  21. echo Specify architecture of jsrt binaries (required):
  22. echo.
  23. echo -x86 Build arch of binaries is x86
  24. echo -x64 Build arch of binaries is x64
  25. echo.
  26. echo Specify type of jsrt binaries (required):
  27. echo.
  28. echo -debug Build type of binaries is debug
  29. echo -test Build type of binaries is test
  30. echo.
  31. echo --help Print help from nativetests (note, arch/type still required)
  32. echo.
  33. echo Shorthand combinations can be used, e.g. -x64debug
  34. echo.
  35. goto :eof
  36. :: ============================================================================
  37. :: Print how to get help
  38. :: ============================================================================
  39. :printGetHelp
  40. echo For help use runnativetests.cmd -?
  41. goto :eof
  42. :: ============================================================================
  43. :: Main script
  44. :: ============================================================================
  45. :main
  46. call :initVars
  47. call :parseArgs %*
  48. if not "%fShowUsage%" == "" (
  49. call :printUsage
  50. goto :eof
  51. )
  52. call :validateArgs
  53. if not "%fShowGetHelp%" == "" (
  54. call :printGetHelp
  55. goto :eof
  56. )
  57. call :configureVars
  58. call :copyScriptsAndBinaries
  59. call :runtest
  60. call :cleanup
  61. echo -- runnativetests.cmd ^>^> Exiting with exit code %_HadFailures%
  62. exit /b %_HadFailures%
  63. :: ============================================================================
  64. :: Parse the user arguments into environment variables
  65. :: ============================================================================
  66. :parseArgs
  67. :NextArgument
  68. if "%1" == "-?" set fShowUsage=1& goto :ArgOk
  69. if "%1" == "/?" set fShowUsage=1& goto :ArgOk
  70. if /i "%1" == "-x86" set _BuildArch=x86& goto :ArgOk
  71. if /i "%1" == "-x64" set _BuildArch=x64& goto :ArgOk
  72. if /i "%1" == "-debug" set _BuildType=debug& goto :ArgOk
  73. if /i "%1" == "-test" set _BuildType=test& goto :ArgOk
  74. if /i "%1" == "-x86debug" set _BuildArch=x86&set _BuildType=debug& goto :ArgOk
  75. if /i "%1" == "-x64debug" set _BuildArch=x64&set _BuildType=debug& goto :ArgOk
  76. if /i "%1" == "-x86test" set _BuildArch=x86&set _BuildType=test& goto :ArgOk
  77. if /i "%1" == "-x64test" set _BuildArch=x64&set _BuildType=test& goto :ArgOk
  78. if /i "%1" == "-binDir" set _BinDirBase=%~f2& goto :ArgOkShift2
  79. rem Store unrecognized args in this var for when we later call the executable
  80. if not "%1" == "" set _NativeTestArgs=%_NativeTestArgs%%1 & goto :ArgOk
  81. goto :eof
  82. :ArgOkShift2
  83. shift
  84. :ArgOk
  85. shift
  86. goto :NextArgument
  87. :: ============================================================================
  88. :: Initialize batch script variables to defaults
  89. :: ============================================================================
  90. :initVars
  91. set _HadFailures=0
  92. set _RootDir=%~dp0..
  93. set _BinDirBase=%_RootDir%\Build\VcBuild\Bin
  94. set _BinDir=
  95. set _TestTempDir=
  96. set _BuildArch=
  97. set _BuildType=
  98. set _NativeTestArgs=
  99. goto :eof
  100. :: ============================================================================
  101. :: Validate that required arguments were specified
  102. :: ============================================================================
  103. :validateArgs
  104. if "%_BuildArch%" == "" (
  105. echo Error missing required build architecture or build type switch
  106. set fShowGetHelp=1
  107. goto :eof
  108. )
  109. if "%_BuildType%" == "" (
  110. echo Error missing required build architecture or build type switch
  111. set fShowGetHelp=1
  112. )
  113. goto :eof
  114. :: ============================================================================
  115. :: Configure the script variables and environment based on parsed arguments
  116. :: ============================================================================
  117. :configureVars
  118. set _BinDir=%_BinDirBase%\%_BuildArch%_%_BuildType%\
  119. rem Use %_BinDir% as the root for %_TestTempDir% to ensure that running jsrt
  120. rem native tests from multiple repos simultaneously do not clobber each other.
  121. rem This means we need to delete the temp directory afterwards to clean up.
  122. set _TestTempDir=%_BinDir%\jsrttest\
  123. if not exist %_TestTempDir% mkdir %_TestTempDir%
  124. echo -- runnativetests.cmd ^>^> #### BinDir: %_BinDir%
  125. echo -- runnativetests.cmd ^>^> #### TestTempDir: %_TestTempDir%
  126. goto :eof
  127. :: ============================================================================
  128. :: Copying javascript files from source location to temp test location and test
  129. :: binaries from binary location to test temp location.
  130. :: ============================================================================
  131. :copyScriptsAndBinaries
  132. echo -- runnativetests.cmd ^>^> copying scripts from '%_RootDir%\bin\nativetests\Scripts' to '%_TestTempDir%'
  133. copy /y %_RootDir%\bin\nativetests\Scripts\*.js %_TestTempDir%
  134. copy /y %_BinDir%ChakraCore.dll %_TestTempDir%
  135. copy /y %_BinDir%nativetests.exe %_TestTempDir%
  136. goto :eof
  137. :: ============================================================================
  138. :: Running tests using nativetests.exe
  139. :: ============================================================================
  140. :runtest
  141. pushd %_TestTempDir%
  142. echo -- runnativetests.cmd ^>^> Calling %cd%\nativetests.exe with additional args: %_NativeTestArgs%
  143. call :do nativetests.exe %_NativeTestArgs%
  144. if "%_error%" NEQ "0" (
  145. set _HadFailures=1
  146. echo -- runnativetests.cmd ^>^> nativetests.exe exited with non-zero exit code %_error%
  147. )
  148. popd
  149. goto :eof
  150. :: ============================================================================
  151. :: Clean up left over files
  152. :: ============================================================================
  153. :cleanUp
  154. call :do rd /s/q %_TestTempDir%
  155. goto :eof
  156. :: ============================================================================
  157. :: Echo a command line before executing it
  158. :: ============================================================================
  159. :do
  160. echo ^>^> %*
  161. cmd /s /c "%*"
  162. set _error=%ERRORLEVEL%
  163. goto :eof
  164. :: ============================================================================
  165. :: Echo a command line before executing it and redirect the command's output
  166. :: to nul
  167. :: ============================================================================
  168. :doSilent
  169. echo ^>^> %* ^> nul 2^>^&1
  170. cmd /s /c "%* > nul 2>&1"
  171. goto :eof