runnativetests.cmd 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. exit /b %_HadFailures%
  62. :: ============================================================================
  63. :: Parse the user arguments into environment variables
  64. :: ============================================================================
  65. :parseArgs
  66. :NextArgument
  67. if "%1" == "-?" set fShowUsage=1& goto :ArgOk
  68. if "%1" == "/?" set fShowUsage=1& goto :ArgOk
  69. if /i "%1" == "-x86" set _BuildArch=x86& goto :ArgOk
  70. if /i "%1" == "-x64" set _BuildArch=x64& goto :ArgOk
  71. if /i "%1" == "-debug" set _BuildType=debug& goto :ArgOk
  72. if /i "%1" == "-test" set _BuildType=test& goto :ArgOk
  73. if /i "%1" == "-x86debug" set _BuildArch=x86&set _BuildType=debug& goto :ArgOk
  74. if /i "%1" == "-x64debug" set _BuildArch=x64&set _BuildType=debug& goto :ArgOk
  75. if /i "%1" == "-x86test" set _BuildArch=x86&set _BuildType=test& goto :ArgOk
  76. if /i "%1" == "-x64test" set _BuildArch=x64&set _BuildType=test& goto :ArgOk
  77. if /i "%1" == "-binDir" set _BinDirBase=%~f2& goto :ArgOkShift2
  78. rem Store unrecognized args in this var for when we later call the executable
  79. if not "%1" == "" set _NativeTestArgs=%_NativeTestArgs%%1 & goto :ArgOk
  80. goto :eof
  81. :ArgOkShift2
  82. shift
  83. :ArgOk
  84. shift
  85. goto :NextArgument
  86. :: ============================================================================
  87. :: Initialize batch script variables to defaults
  88. :: ============================================================================
  89. :initVars
  90. set _HadFailures=0
  91. set _RootDir=%~dp0..
  92. set _BinDirBase=%_RootDir%\Build\VcBuild\Bin
  93. set _BinDir=
  94. set _TestTempDir=
  95. set _BuildArch=
  96. set _BuildType=
  97. set _NativeTestArgs=
  98. goto :eof
  99. :: ============================================================================
  100. :: Validate that required arguments were specified
  101. :: ============================================================================
  102. :validateArgs
  103. if "%_BuildArch%" == "" (
  104. echo Error missing required build architecture or build type switch
  105. set fShowGetHelp=1
  106. goto :eof
  107. )
  108. if "%_BuildType%" == "" (
  109. echo Error missing required build architecture or build type switch
  110. set fShowGetHelp=1
  111. )
  112. goto :eof
  113. :: ============================================================================
  114. :: Configure the script variables and environment based on parsed arguments
  115. :: ============================================================================
  116. :configureVars
  117. set _BinDir=%_BinDirBase%\%_BuildArch%_%_BuildType%\
  118. rem Use %_BinDir% as the root for %_TestTempDir% to ensure that running jsrt
  119. rem native tests from multiple repos simultaneously do not clobber each other.
  120. rem This means we need to delete the temp directory afterwards to clean up.
  121. set _TestTempDir=%_BinDir%\jsrttest\
  122. if not exist %_TestTempDir% mkdir %_TestTempDir%
  123. echo -- runnativetests.cmd ^>^> #### BinDir: %_BinDir%
  124. echo -- runnativetests.cmd ^>^> #### TestTempDir: %_TestTempDir%
  125. goto :eof
  126. :: ============================================================================
  127. :: Copying javascript files from source location to temp test location and test
  128. :: binaries from binary location to test temp location.
  129. :: ============================================================================
  130. :copyScriptsAndBinaries
  131. echo -- runnativetests.cmd ^>^> copying scripts from '%_RootDir%\bin\nativetests\Scripts' to '%_TestTempDir%'
  132. copy /y %_RootDir%\bin\nativetests\Scripts\*.js %_TestTempDir%
  133. copy /y %_BinDir%ChakraCore.dll %_TestTempDir%
  134. copy /y %_BinDir%nativetests.exe %_TestTempDir%
  135. goto :eof
  136. :: ============================================================================
  137. :: Running tests using nativetests.exe
  138. :: ============================================================================
  139. :runtest
  140. pushd %_TestTempDir%
  141. echo Calling %cd%\nativetests.exe with additional args: %_NativeTestArgs%
  142. call :do nativetests.exe %_NativeTestArgs%
  143. if ERRORLEVEL 1 set _HadFailures=1
  144. popd
  145. goto :eof
  146. :: ============================================================================
  147. :: Clean up left over files
  148. :: ============================================================================
  149. :cleanUp
  150. call :do rd /s/q %_TestTempDir%
  151. goto :eof
  152. :: ============================================================================
  153. :: Echo a command line before executing it
  154. :: ============================================================================
  155. :do
  156. echo ^>^> %*
  157. cmd /s /c "%*"
  158. goto :eof
  159. :: ============================================================================
  160. :: Echo a command line before executing it and redirect the command's output
  161. :: to nul
  162. :: ============================================================================
  163. :doSilent
  164. echo ^>^> %* ^> nul 2^>^&1
  165. cmd /s /c "%* > nul 2>&1"
  166. goto :eof