Update CoreClr, CoreFx, CoreSetup to preview-27213-02, preview.18613.4, preview-27213...
[platform/upstream/coreclr.git] / tests / runtest.cmd
1 @if not defined _echo @echo off
2 setlocal EnableDelayedExpansion EnableExtensions
3
4 :: Define a prefix for most output progress messages that come from this script. That makes
5 :: it easier to see where these are coming from. Note that there is a trailing space here.
6 set "__MsgPrefix=RUNTEST: "
7
8 set __ThisScriptDir="%~dp0"
9
10 if /I not "%PROCESSOR_ARCHITECTURE%"=="arm64" (
11     if /I not "%PROCESSOR_ARCHITECTURE%"=="arm" (
12         call "%__ThisScriptDir%"\..\setup_vs_tools.cmd
13         if NOT '%ERRORLEVEL%' == '0' exit /b 1
14
15         if defined VS150COMNTOOLS (
16             set __VSVersion=vs2017
17         ) else (
18             set __VSVersion=vs2015
19         )
20     )
21 )   
22
23 :: Set the default arguments
24 set __BuildArch=x64
25 set __BuildType=Debug
26 set __BuildOS=Windows_NT
27
28 set "__ProjectDir=%~dp0"
29 :: remove trailing slash
30 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
31 set "__ProjectFilesDir=%__ProjectDir%"
32 set "__RootBinDir=%__ProjectDir%\..\bin"
33 set "__LogsDir=%__RootBinDir%\Logs"
34
35 set __Sequential=
36 set __msbuildExtraArgs=
37 set __LongGCTests=
38 set __GCSimulatorTests=
39 set __AgainstPackages=
40 set __JitDisasm=
41 set __IlasmRoundTrip=
42 set __CollectDumps=
43 set __DoCrossgen=
44 set __CrossgenAltJit=
45 set __PerfTests=
46 set __CoreFXTests=
47 set __CoreFXTestsRunAllAvailable=
48 set __SkipGenerateLayout=
49 set __BuildXUnitWrappers=
50 set __PrintLastResultsOnly=
51
52 :Arg_Loop
53 if "%1" == "" goto ArgsDone
54
55 if /i "%1" == "/?"    goto Usage
56 if /i "%1" == "-?"    goto Usage
57 if /i "%1" == "/h"    goto Usage
58 if /i "%1" == "-h"    goto Usage
59 if /i "%1" == "/help" goto Usage
60 if /i "%1" == "-help" goto Usage
61
62 if /i "%1" == "x64"                   (set __BuildArch=x64&shift&goto Arg_Loop)
63 if /i "%1" == "x86"                   (set __BuildArch=x86&shift&goto Arg_Loop)
64 if /i "%1" == "arm"                   (set __BuildArch=arm&shift&goto Arg_Loop)
65 if /i "%1" == "arm64"                 (set __BuildArch=arm64&shift&goto Arg_Loop)
66
67 if /i "%1" == "debug"                 (set __BuildType=Debug&shift&goto Arg_Loop)
68 if /i "%1" == "release"               (set __BuildType=Release&shift&goto Arg_Loop)
69 if /i "%1" == "checked"               (set __BuildType=Checked&shift&goto Arg_Loop)
70
71 if /i "%1" == "vs2015"                (set __VSVersion=%1&shift&goto Arg_Loop)
72 if /i "%1" == "vs2017"                (set __VSVersion=%1&shift&goto Arg_Loop)
73
74 if /i "%1" == "TestEnv"               (set __TestEnv=%2&shift&shift&goto Arg_Loop)
75 if /i "%1" == "AgainstPackages"       (set __AgainstPackages=1&shift&goto Arg_Loop)
76 if /i "%1" == "sequential"            (set __Sequential=1&shift&goto Arg_Loop)
77 if /i "%1" == "crossgen"              (set __DoCrossgen=1&shift&goto Arg_Loop)
78 if /i "%1" == "crossgenaltjit"        (set __DoCrossgen=1&set __CrossgenAltJit=%2&shift&shift&goto Arg_Loop)
79 if /i "%1" == "longgc"                (set __LongGCTests=1&shift&goto Arg_Loop)
80 if /i "%1" == "gcsimulator"           (set __GCSimulatorTests=1&shift&goto Arg_Loop)
81 if /i "%1" == "jitstress"             (set COMPlus_JitStress=%2&shift&shift&goto Arg_Loop)
82 if /i "%1" == "jitstressregs"         (set COMPlus_JitStressRegs=%2&shift&shift&goto Arg_Loop)
83 if /i "%1" == "jitminopts"            (set COMPlus_JITMinOpts=1&shift&goto Arg_Loop)
84 if /i "%1" == "jitforcerelocs"        (set COMPlus_ForceRelocs=1&shift&goto Arg_Loop)
85 if /i "%1" == "jitdisasm"             (set __JitDisasm=1&shift&goto Arg_Loop)
86 if /i "%1" == "ilasmroundtrip"        (set __IlasmRoundTrip=1&shift&goto Arg_Loop)
87 if /i "%1" == "GenerateLayoutOnly"    (set __GenerateLayoutOnly=1&shift&goto Arg_Loop)
88 if /i "%1" == "skipgeneratelayout"    (set __SkipGenerateLayout=1&shift&goto Arg_Loop)
89 if /i "%1" == "buildxunitwrappers"    (set __BuildXunitWrappers=1&shift&goto Arg_Loop)
90 if /i "%1" == "printlastresultsonly"  (set __PrintLastResultsOnly=1&shift&goto Arg_Loop)
91 if /i "%1" == "PerfTests"             (set __PerfTests=true&shift&goto Arg_Loop)
92 if /i "%1" == "CoreFXTests"           (set __CoreFXTests=true&shift&goto Arg_Loop)
93 if /i "%1" == "CoreFXTestsAll"        (set __CoreFXTests=true&set __CoreFXTestsRunAllAvailable=true&shift&goto Arg_Loop)
94 if /i "%1" == "CoreFXTestList"        (set __CoreFXTests=true&set __CoreFXTestList=%2&shift&shift&goto Arg_Loop)
95 if /i "%1" == "runcrossgentests"      (set RunCrossGen=true&shift&goto Arg_Loop)
96 if /i "%1" == "link"                  (set DoLink=true&set ILLINK=%2&shift&shift&goto Arg_Loop)
97 REM tieredcompilation is on by default now, but setting this environment variable is harmless and I didn't want to break any automation that might be using it just yet
98 if /i "%1" == "tieredcompilation"     (set COMPLUS_TieredCompilation=1&shift&goto Arg_Loop)
99 if /i "%1" == "gcname"                (set COMPlus_GCName=%2&shift&shift&goto Arg_Loop)
100 if /i "%1" == "timeout"               (set __TestTimeout=%2&shift&shift&goto Arg_Loop)
101 if /i "%1" == "altjitarch"            (set __AltJitArch=%2&shift&shift&goto Arg_Loop)
102
103 REM change it to COMPlus_GCStress when we stop using xunit harness
104 if /i "%1" == "gcstresslevel"         (set COMPlus_GCStress=%2&set __TestTimeout=1800000&shift&shift&goto Arg_Loop)
105 if /i "%1" == "collectdumps"          (set __CollectDumps=true&shift&goto Arg_Loop)
106
107 if /i not "%1" == "msbuildargs" goto SkipMsbuildArgs
108 :: All the rest of the args will be collected and passed directly to msbuild.
109 :CollectMsbuildArgs
110 shift
111 if "%1"=="" goto ArgsDone
112 set __msbuildExtraArgs=%__msbuildExtraArgs% %1
113 goto CollectMsbuildArgs
114 :SkipMsbuildArgs
115
116 set CORE_ROOT=%1
117 echo %__MsgPrefix%CORE_ROOT is initially set to: "%CORE_ROOT%"
118 shift 
119 :ArgsDone
120
121 :: Done with argument processing. Check argument values for validity.
122
123 if defined __TestEnv (if not exist %__TestEnv% echo %__MsgPrefix%Error: Test Environment script %__TestEnv% not found && exit /b 1)
124 if "%__PerfTests%"=="true" (if defined __GenerateLayoutOnly  echo %__MsgPrefix%Error: Don't specify both "PerfTests" and "GenerateLayoutOnly" && exit /b 1)
125 if "%__CoreFXTests%"=="true" (if defined __GenerateLayoutOnly  echo %__MsgPrefix%Error: Don't specify both "CoreFXTests" and "GenerateLayoutOnly" && exit /b 1)
126
127 if defined __CoreFXTestList (
128     if not exist "%__CoreFXTestList%" (
129         echo %__MsgPrefix%Error: Couldn't find CoreFX Test List "%__CoreFXTestList%".
130         exit /b 1
131     )
132 )
133
134 :: Set the remaining variables based upon the determined configuration
135 set __MSBuildBuildArch=%__BuildArch%
136
137 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
138 set "__TestWorkingDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%"
139
140 :: Default global test environment variables
141 :: REVIEW: are these ever expected to be defined on entry to this script? Why? By whom?
142 :: REVIEW: XunitTestReportDirBase is not used in this script. Who needs to have it set?
143 if not defined XunitTestBinBase       set  XunitTestBinBase=%__TestWorkingDir%
144 if not defined XunitTestReportDirBase set  XunitTestReportDirBase=%XunitTestBinBase%\Reports\
145
146 REM At this point in the script there will be a divergence in how the tests are run.
147 REM For official builds we will continue to run tests using the un-unified scripting
148 REM which relies on msbuild and calls runtest.proj directly. For all other scenarios
149 REM runtest.py will handle setup and will then call runtest.proj
150
151 if defined __AgainstPackages goto SetupMSBuildAndCallRuntestProj
152 if "%__CoreFXTests%"=="true" goto SetupMSBuildAndCallRuntestProj
153 if "%__PerfTests%"=="true" goto SetupMSBuildAndCallRuntestProj
154 if defined __GenerateLayoutOnly goto SetupMSBuildAndCallRuntestProj
155
156 REM We are not running in the official build scenario, call runtest.py
157
158 set __RuntestPyArgs=-arch %__BuildArch% -build_type %__BuildType%
159
160 if defined DoLink (
161     set __RuntestPyArgs=%__RuntestPyArgs% --il_link
162 )
163
164 if defined __LongGCTests (
165     set __RuntestPyArgs=%__RuntestPyArgs% --long_gc
166 )
167
168 if defined __GCSimulatorTests (
169     set __RuntestPyArgs=%__RuntestPyArgs% --gcsimulator
170 )
171
172 if defined __JitDisasm (
173     set __RuntestPyArgs=%__RuntestPyArgs% --jitdisasm
174 )
175
176 if defined __IlasmRoundTrip (
177     set __RuntestPyArgs=%__RuntestPyArgs% --ilasmroundtrip
178 )
179
180 if defined __TestEnv (
181     set __RuntestPyArgs=%__RuntestPyArgs% -test_env %__TestEnv%
182 )
183
184 if defined __Sequential (
185     set __RuntestPyArgs=%__RuntestPyArgs% --sequential
186 )
187
188 if not defined __SkipGenerateLayout (
189     set __RuntestPyArgs=%__RuntestPyArgs% --generate_layout
190 )
191
192 if defined __GenerateLayoutOnly (
193     set __RuntestPyArgs=%__RuntestPyArgs% --generate_layout_only
194 )
195
196 if defined __BuildXUnitWrappers (
197     set __RuntestPyArgs=%__RuntestPyArgs% --build_xunit_test_wrappers
198 )
199
200 if defined RunCrossGen (
201     set __RuntestPyArgs=%__RuntestPyArgs% --run_crossgen_tests
202 )
203
204 if defined __DoCrossgen (
205     set __RuntestPyArgs=%__RuntestPyArgs% --precompile_core_root
206 )
207
208 if defined __PrintLastResultsOnly (
209     set __RuntestPyArgs=%__RuntestPyArgs% --analyze_results_only
210 )
211
212 if defined __AltJitArch (
213     set __RuntestPyArgs=%__RuntestPyArgs% -altjit_arch %__AltJitArch%
214 )
215
216 REM __ProjectDir is poorly named, it is actually <projectDir>/tests
217 set NEXTCMD=python "%__ProjectDir%\runtest.py" %__RuntestPyArgs%
218 echo !NEXTCMD!
219 !NEXTCMD!
220
221 exit /b %ERRORLEVEL%
222
223 :SetupMSBuildAndCallRuntestProj
224
225 :: Set up msbuild and tools environment. Check if msbuild and VS exist.
226
227 set _msbuildexe=
228 if /i "%__VSVersion%" == "vs2017" (
229     set "__VSToolsRoot=%VS150COMNTOOLS%"
230     set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build"
231
232     set _msbuildexe="%VS150COMNTOOLS%\..\..\MSBuild\15.0\Bin\MSBuild.exe"
233 ) else if /i "%__VSVersion%" == "vs2015" (
234     set "__VSToolsRoot=%VS140COMNTOOLS%"
235     set "__VCToolsRoot=%VS140COMNTOOLS%\..\..\VC"
236
237     set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
238     if not exist !_msbuildexe! set _msbuildexe="%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe"
239 )
240
241 :: Does VS really exist?
242 if not exist "%__VSToolsRoot%\..\IDE\devenv.exe"      goto NoVS
243 if not exist "%__VCToolsRoot%\vcvarsall.bat"          goto NoVS
244 if not exist "%__VSToolsRoot%\VsDevCmd.bat"           goto NoVS
245
246 :: Does MSBuild really exist?
247 if not exist %_msbuildexe% (
248     echo %__MsgPrefix%Error: Could not find MSBuild.exe.  Please see https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md for build instructions.
249     exit /b 1
250 )
251
252 if not defined VSINSTALLDIR (
253     echo %__MsgPrefix%Error: runtest.cmd should be run from a Visual Studio Command Prompt.  Please see https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md for build instructions.
254     exit /b 1
255 )
256
257 :: Note: We've disabled node reuse because it causes file locking issues.
258 ::       The issue is that we extend the build with our own targets which
259 ::       means that that rebuilding cannot successfully delete the task
260 ::       assembly. 
261 set __msbuildCommonArgs=/nologo /nodeReuse:false %__msbuildExtraArgs% /p:Platform=%__MSBuildBuildArch%
262
263 if not defined __Sequential (
264     set __msbuildCommonArgs=%__msbuildCommonArgs% /maxcpucount
265 ) else (
266     set __msbuildCommonArgs=%__msbuildCommonArgs% /p:ParallelRun=false
267 )
268
269 if defined __AgainstPackages (
270     set __msbuildCommonArgs=%__msbuildCommonArgs% /p:BuildTestsAgainstPackages=true
271 )
272
273 if defined DoLink (
274     set __msbuildCommonArgs=%__msbuildCommonArgs% /p:RunTestsViaIllink=true
275 )
276
277 if not exist %__LogsDir% md %__LogsDir%
278
279 REM These log files are created automatically by the test run process. Q: what do they depend on being set?
280 set __TestRunHtmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.html
281 set __TestRunXmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.xml
282
283 REM Prepare the Test Drop
284
285 if not defined __GenerateLayoutOnly (
286     echo %__MsgPrefix%Removing 'ni' files and 'lock' folders from %__TestWorkingDir%
287     REM Cleans any NI from the last run
288     powershell -NoProfile "Get-ChildItem -path %__TestWorkingDir% -Include '*.ni.*' -Recurse -Force | Remove-Item -force"
289     REM Cleans up any lock folder used for synchronization from last run
290     powershell -NoProfile "Get-ChildItem -path %__TestWorkingDir% -Include 'lock' -Recurse -Force |  where {$_.Attributes -eq 'Directory'}| Remove-Item -force -Recurse"
291 )
292
293 if defined CORE_ROOT goto SkipCoreRootSetup
294
295 set "CORE_ROOT=%XunitTestBinBase%\Tests\Core_Root"
296 echo %__MsgPrefix%Using Default CORE_ROOT as %CORE_ROOT%
297 echo %__MsgPrefix%Copying Built binaries from %__BinDir% to %CORE_ROOT%
298 if exist "%CORE_ROOT%" rd /s /q "%CORE_ROOT%"
299 md "%CORE_ROOT%"
300 xcopy "%__BinDir%" "%CORE_ROOT%"
301
302 :SkipCoreRootSetup
303
304 if not exist %CORE_ROOT%\coreclr.dll (
305     echo %__MsgPrefix%Error: Ensure you have done a successful build of the Product and %CORE_ROOT% contains runtime binaries.
306     exit /b 1
307 )
308
309 if "%__CoreFXTests%"=="true" goto RunCoreFXTests
310
311 if "%__PerfTests%"=="true" goto RunPerfTests
312
313 REM =========================================================================================
314 REM ===
315 REM === Run normal (non-perf) tests
316 REM ===
317 REM =========================================================================================
318
319 call :SetTestEnvironment
320
321 call :ResolveDependencies
322 if errorlevel 1 exit /b 1
323
324 if defined __DoCrossgen (
325     echo %__MsgPrefix%Running crossgen on framework assemblies
326     call :PrecompileFX
327 )
328
329 REM Delete the unecessary mscorlib.ni file.
330 if exist %CORE_ROOT%\mscorlib.ni.dll del %CORE_ROOT%\mscorlib.ni.dll
331
332 if defined __GenerateLayoutOnly (
333     echo %__MsgPrefix%Done generating layout.
334     exit /b 0
335 )
336
337 ::Check if the test Binaries are built
338 if not exist %XunitTestBinBase% (
339     echo %__MsgPrefix%Error: Ensure the Test Binaries are built and are present at %XunitTestBinBase%.
340     echo %__MsgPrefix%Run "buildtest.cmd %__BuildArch% %__BuildType%" to build the tests first.
341     exit /b 1
342 )
343
344 if "%__CollectDumps%"=="true" (
345     :: Install dumpling
346     set "__DumplingHelperPath=%__ProjectDir%\..\Tools\DumplingHelper.py"
347     python "!__DumplingHelperPath!" install_dumpling
348
349     :: Create the crash dump folder if necessary
350     set "__CrashDumpFolder=%tmp%\CoreCLRTestCrashDumps"
351     if not exist "!__CrashDumpFolder!" (
352         mkdir "!__CrashDumpFolder!"
353     )
354
355     :: Grab the current time before execution begins. This will be used to determine which crash dumps
356     :: will be uploaded.
357     for /f "delims=" %%a in ('python !__DumplingHelperPath! get_timestamp') do @set __StartTime=%%a
358 )
359
360 echo %__MsgPrefix%CORE_ROOT that will be used is: %CORE_ROOT%
361 echo %__MsgPrefix%Starting test run at %TIME%
362
363 set __BuildLogRootName=TestRunResults
364 call :msbuild "%__ProjectFilesDir%\runtest.proj" /p:Runtests=true /clp:showcommandline
365 set __errorlevel=%errorlevel%
366
367 if "%__CollectDumps%"=="true" (
368     python "%__DumplingHelperPath%" collect_dump %errorlevel% "%__CrashDumpFolder%" %__StartTime% "CoreCLR_Tests"
369 )
370
371 if %__errorlevel% GEQ 1 (
372     echo %__MsgPrefix%Test Run failed. Refer to the following:
373     echo     Html report: %__TestRunHtmlLog%
374     exit /b 1
375 )
376
377 goto TestsDone
378
379 REM =========================================================================================
380 REM ===
381 REM === Run perf tests
382 REM ===
383 REM =========================================================================================
384
385 :RunPerfTests 
386 echo %__MsgPrefix%CORE_ROOT that will be used is: %CORE_ROOT%  
387 echo %__MsgPrefix%Starting test run at %TIME%
388
389 set __BuildLogRootName=PerfTestRunResults  
390 echo %__MsgPrefix%Running perf tests  
391 call :msbuild "%__ProjectFilesDir%\runtest.proj" /t:RunPerfTests /clp:showcommandline  
392
393 if errorlevel 1 (  
394     echo %__MsgPrefix%Test Run failed. Refer to the following:  
395     echo     Html report: %__TestRunHtmlLog%  
396 )
397
398 goto TestsDone
399
400 REM =========================================================================================
401 REM ===
402 REM === Run CoreFX tests
403 REM ===
404 REM =========================================================================================
405
406 :RunCoreFXTests
407
408 set _CoreFXTestHost=%XunitTestBinBase%\testhost
409 set __ToolsDir=%__ProjectDir%\..\Tools
410 set "DotNetCli=%__ToolsDir%\dotnetcli\dotnet.exe"
411
412 set _RootCoreFXTestPath=%__TestWorkingDir%\CoreFX
413 set _CoreFXTestUtilitiesOutputPath=%_RootCoreFXTestPath%\CoreFXTestUtilities
414 set _CoreFXTestBinariesPath=%_RootCoreFXTestPath%\tests_downloaded
415 set _CoreFXLogsDir=%__LogsDir%\CoreFX\%__BuildOS%.%__BuildArch%.%__BuildType%
416 if not exist "%_CoreFXLogsDir%"  (mkdir "%_CoreFXLogsDir%")
417
418 set _CoreFXTestSetupUtilityName=CoreFX.TestUtils.TestFileSetup
419 set _CoreFXTestSetupUtility=%__ProjectFilesDir%\src\Common\CoreFX\TestFileSetup\%_CoreFXTestSetupUtilityName%.csproj
420
421 call :ResolveDependencies
422 if errorlevel 1 exit /b 1
423
424 if defined __GenerateTestHostOnly (
425     exit /b 0
426 )
427
428 if not exist %_CoreFXTestHost%\dotnet.exe (
429     echo %__MsgPrefix%CoreFX test host not found, please run runtest.cmd again
430     exit /b 1
431 )
432
433 set /p _CoreFXTestRemoteURL=< "%__ProjectFilesDir%\CoreFX\CoreFXTestListURL.txt"
434 if not defined __CoreFXTestList ( set __CoreFXTestList=%__ProjectFilesDir%\CoreFX\CoreFX.issues.json )
435
436 set _CoreFXTestExecutable=xunit.console.netcore.exe
437 set _CoreFXTestExecutableArgs= --notrait category=nonnetcoreapptests --notrait category=nonwindowstests  --notrait category=failing --notrait category=IgnoreForCI --notrait category=OuterLoop --notrait Benchmark=true
438
439 REM Set the log file name to something Jenkins can understand
440 set _CoreFX_TestLogFileName=testResults.xml
441 set _CoreFX_TestRunScriptName=CoreCLR_RunTest.cmd
442 if "%__CoreFXTestsRunAllAvailable%" == "true" ( 
443     set _CoreFX_RunCommand=--runAllTests
444 ) else ( 
445     set _CoreFX_RunCommand=--runSpecifiedTests
446 )
447
448 echo %__MsgPrefix%Downloading and Running CoreFX Test Binaries
449 set NEXTCMD=call "%DotNetCli%" "%_CoreFXTestUtilitiesOutputPath%\%_CoreFXTestSetupUtilityName%.dll" --clean --outputDirectory "%_CoreFXTestBinariesPath%" --testListJsonPath "%__CoreFXTestList%" --testUrl "!_CoreFXTestRemoteURL!" %_CoreFX_RunCommand% --dotnetPath "%_CoreFXTestHost%\dotnet.exe" --executable %_CoreFXTestExecutable% --log %_CoreFXLogsDir% %_CoreFXTestExecutableArgs%
450 echo !NEXTCMD!
451 !NEXTCMD!
452 if errorlevel 1 (
453     echo %__MsgPrefix%CoreFX tests finished with failures. Refer to the following:  
454     echo     %_CoreFXLogsDir%
455     exit /b 1
456 )
457
458 goto TestsDone
459
460 REM =========================================================================================
461 REM ===
462 REM === All tests complete!
463 REM ===
464 REM =========================================================================================
465
466 :TestsDone
467
468 echo %__MsgPrefix%Test run successful. Finished at %TIME%. Refer to the log files for details:
469 echo     %__TestRunHtmlLog%
470 echo     %__TestRunXmlLog%
471 exit /b 0
472
473 REM =========================================================================================
474 REM ===
475 REM === Compile the managed assemblies in Core_ROOT before running the tests
476 REM ===
477 REM =========================================================================================
478
479 :PrecompileAssembly
480
481 if defined __JitDisasm goto :jitdisasm
482
483 REM Skip mscorlib since it is already precompiled.
484 if /I "%3" == "mscorlib.dll" exit /b 0
485 if /I "%3" == "mscorlib.ni.dll" exit /b 0
486
487 "%1\crossgen.exe" /Platform_Assemblies_Paths "%CORE_ROOT%" "%2" >nul 2>nul
488 set /a __exitCode = %errorlevel%
489 if "%__exitCode%" == "-2146230517" (
490     echo %2 is not a managed assembly.
491     exit /b 0
492 )
493
494 if %__exitCode% neq 0 (
495     echo Unable to precompile %2
496     exit /b 0
497 )
498     
499 echo %__MsgPrefix%Successfully precompiled %2
500 exit /b 0
501
502 :jitdisasm
503
504 if /I "%3" == "mscorlib.ni.dll" exit /b 0
505
506 echo "%1\corerun" "%1\jit-dasm.dll" --crossgen %1\crossgen.exe --platform %CORE_ROOT% --output %__TestWorkingDir%\dasm "%2"
507 "%1\corerun" "%1\jit-dasm.dll" --crossgen %1\crossgen.exe --platform %CORE_ROOT% --output %__TestWorkingDir%\dasm "%2"
508 set /a __exitCode = %errorlevel%
509
510 if "%__exitCode%" == "-2146230517" (
511     echo %2 is not a managed assembly.
512     exit /b 0
513 )
514
515 if %__exitCode% neq 0 (
516     echo Unable to precompile %2
517     exit /b 0
518 )
519
520 echo %__MsgPrefix%Successfully precompiled and generated dasm for %2
521 exit /b 0
522
523 :PrecompileFX
524 setlocal
525
526 if defined __CrossgenAltJit (
527     REM Set altjit flags for the crossgen run. Note that this entire crossgen section is within a setlocal/endlocal scope,
528     REM so we don't need to save or unset these afterwards.
529     echo %__MsgPrefix%Setting altjit environment variables for %__CrossgenAltJit%.
530     set COMPlus_AltJit=*
531     set COMPlus_AltJitNgen=*
532     set COMPlus_AltJitName=%__CrossgenAltJit%
533     set COMPlus_AltJitAssertOnNYI=1
534     set COMPlus_NoGuiOnAssert=1
535     set COMPlus_ContinueOnAssert=0
536 )
537
538 for %%F in (%CORE_ROOT%\*.dll) do call :PrecompileAssembly "%CORE_ROOT%" "%%F" %%~nF%%~xF
539 endlocal
540 exit /b 0
541
542 REM =========================================================================================
543 REM ===
544 REM === Subroutine to invoke msbuild.
545 REM ===
546 REM === All arguments are passed to msbuild. The first argument should be the .proj file to invoke.
547 REM ===
548 REM === On entry, environment variable __BuildLogRootName must be set to a file name prefix for the generated log files.
549 REM === All the "standard" environment variables that aren't expected to change per invocation must also be set,
550 REM === like __msbuildCommonArgs.
551 REM ===
552 REM === The build log files will be overwritten, not appended to.
553 REM ===
554 REM =========================================================================================
555
556 :msbuild
557
558 echo %__MsgPrefix%Invoking msbuild
559
560 set "__BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
561 set "__BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
562 set "__BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
563
564 set __msbuildLogArgs=^
565 /fileloggerparameters:Verbosity=normal;LogFile="%__BuildLog%";Append ^
566 /fileloggerparameters1:WarningsOnly;LogFile="%__BuildWrn%" ^
567 /fileloggerparameters2:ErrorsOnly;LogFile="%__BuildErr%" ^
568 /consoleloggerparameters:Summary ^
569 /verbosity:minimal
570
571 set __msbuildArgs=%* %__msbuildCommonArgs% %__msbuildLogArgs%
572
573 @REM The next line will overwrite the existing log file, if any.
574 echo %__MsgPrefix%%_msbuildexe% %__msbuildArgs%
575 echo Invoking: %_msbuildexe% %__msbuildArgs% > "%__BuildLog%"
576
577 %_msbuildexe% %__msbuildArgs%
578 if errorlevel 1 (
579     echo %__MsgPrefix%Error: msbuild failed. Refer to the log files for details:
580     echo     %__BuildLog%
581     echo     %__BuildWrn%
582     echo     %__BuildErr%
583     exit /b 1
584 )
585
586 exit /b 0
587
588 REM =========================================================================================
589 REM ===
590 REM === Set various environment variables, based on arguments to this script, before invoking the tests.
591 REM ===
592 REM =========================================================================================
593
594 :SetTestEnvironment
595
596 :: Long GC tests take about 10 minutes per test on average, so
597 :: they often bump up against the default 10 minute timeout.
598 :: 20 minutes is more than enough time for a test to complete successfully.
599 if defined __LongGCTests (
600     echo %__MsgPrefix%Running Long GC tests, extending timeout to 20 minutes
601     set __TestTimeout=1200000
602     set RunningLongGCTests=1
603 )
604
605 :: GCSimulator tests can take up to an hour to complete. They are run twice a week in the
606 :: CI, so it's fine if they take a long time.
607 if defined __GCSimulatorTests (
608     echo %__MsgPrefix%Running GCSimulator tests, extending timeout to one hour
609     set __TestTimeout=3600000
610     set RunningGCSimulatorTests=1
611 )
612
613 if defined __JitDisasm (
614     if defined __DoCrossgen (
615         echo %__MsgPrefix%Running jit disasm on framework and test assemblies
616     )
617     if not defined __DoCrossgen (
618        echo %__MsgPrefix%Running jit disasm on test assemblies only
619     )
620     set RunningJitDisasm=1
621 )
622
623 if defined __IlasmRoundTrip (
624     echo %__MsgPrefix%Running Ilasm round trip
625     set RunningIlasmRoundTrip=1
626 )
627
628 exit /b 0
629
630 REM =========================================================================================
631 REM ===
632 REM === Generate the "layout" directory in CORE_ROOT; download dependencies.
633 REM ===
634 REM =========================================================================================
635
636 :ResolveDependencies
637
638 set __BuildLogRootName=Tests_GenerateRuntimeLayout
639 call :msbuild "%__ProjectFilesDir%\runtest.proj" /p:GenerateRuntimeLayout=true 
640 if errorlevel 1 (
641     echo %__MsgPrefix%Test Dependency Resolution Failed
642     exit /b 1
643 )
644 echo %__MsgPrefix%Created the runtime layout with all dependencies in %CORE_ROOT%
645
646 if "%__CoreFXTests%"=="true" goto ResolveCoreFXDependencies
647
648 exit /b 0
649
650 REM =========================================================================================
651 REM ===
652 REM === Generate the "testhost" directory for running CoreFX tests; download dependencies.
653 REM ===
654 REM =========================================================================================
655
656 :ResolveCoreFXDependencies
657
658 echo %__MsgPrefix%Building CoreFX Test Host
659
660 set __BuildLogRootName=Tests_GenerateTestHost
661 call :msbuild "%__ProjectFilesDir%\runtest.proj" /p:GenerateTestHost=true 
662 if errorlevel 1 (
663     echo %__MsgPrefix%Test Host Dependency Resolution Failed
664     exit /b 1
665 )
666 echo %__MsgPrefix%Created the Test Host layout with all dependencies in %_CoreFXTestHost%
667
668 REM Publish and call the CoreFX test helper projects - should this be integrated into runtest.proj?
669 REM Build Helper project
670 set NEXTCMD="%DotNetCli%" msbuild /t:Restore "%_CoreFXTestSetupUtility%"
671 echo !NEXTCMD!
672 !NEXTCMD!
673 if errorlevel 1 (
674     exit /b 1
675 )
676
677 set NEXTCMD=call "%DotNetCli%" msbuild "/p:Configuration=%CoreRT_BuildType%" "/p:OSGroup=%CoreRT_BuildOS%" "/p:Platform=%CoreRT_BuildArch%" "/p:OutputPath=%_CoreFXTestUtilitiesOutputPath%" "%_CoreFXTestSetupUtility%"
678 echo !NEXTCMD!
679 !NEXTCMD!
680 if errorlevel 1 (
681     exit /b 1
682 )
683
684 exit /b 0
685
686 REM =========================================================================================
687 REM ===
688 REM === Display a help message describing how to use this script.
689 REM ===
690 REM =========================================================================================
691
692 :Usage
693 @REM NOTE: The caret character is used to escape meta-characters known to the CMD shell. This character does
694 @REM NOTE: not appear in output. Thus, while it might look like in lines below that the "-" are not aligned,
695 @REM NOTE: they are in the output (and please keep them aligned).
696 echo.
697 echo Usage:
698 echo   %0 [options] [^<CORE_ROOT^>]
699 echo.
700 echo where:
701 echo.
702 echo./? -? /h -h /help -help   - View this message.
703 echo ^<build_architecture^>      - Specifies build architecture: x64, x86, arm, or arm64 ^(default: x64^).
704 echo ^<build_type^>              - Specifies build type: Debug, Release, or Checked ^(default: Debug^).
705 echo VSVersion ^<vs_version^>    - VS2015 or VS2017 ^(default: VS2017^).
706 echo TestEnv ^<test_env_script^> - Run a custom script before every test to set custom test environment settings.
707 echo AgainstPackages           - This indicates that we are running tests that were built against packages.
708 echo GenerateLayoutOnly        - If specified will not run the tests and will only create the Runtime Dependency Layout
709 echo skipgeneratelayout        - Do not generate the core root. Used for cross target testing.
710 echo sequential                - Run tests sequentially (no parallelism).
711 echo crossgen                  - Precompile ^(crossgen^) the managed assemblies in CORE_ROOT before running the tests.
712 echo crossgenaltjit ^<altjit^>   - Precompile ^(crossgen^) the managed assemblies in CORE_ROOT before running the tests, using the given altjit.
713 echo link ^<ILlink^>             - Runs the tests after linking via the IL linker ^<ILlink^>.
714 echo CoreFXTests               - Runs CoreFX tests
715 echo CoreFXTestsAll            - Runs all CoreFX tests ^(no exclusions^)
716 echo CoreFXTestList ^<file^>     - Specify a file containing a list of CoreFX tests to run, and runs them.
717 echo PerfTests                 - Runs perf tests
718 echo RunCrossgenTests          - Runs ReadytoRun tests
719 echo jitstress ^<n^>             - Runs the tests with COMPlus_JitStress=n
720 echo jitstressregs ^<n^>         - Runs the tests with COMPlus_JitStressRegs=n
721 echo jitminopts                - Runs the tests with COMPlus_JITMinOpts=1
722 echo jitforcerelocs            - Runs the tests with COMPlus_ForceRelocs=1
723 echo jitdisasm                 - Runs jit-dasm on the tests
724 echo ilasmroundtrip            - Runs ilasm round trip on the tests
725 echo longgc                    - Run the long-running GC tests
726 echo gcsimulator               - Run the GC Simulator tests
727 echo gcstresslevel ^<n^>         - Runs the tests with COMPlus_GCStress=n. n=0 means no GC Stress. Otherwise, n is a bitmask of the following:
728 echo                               1: GC on all allocations and 'easy' places
729 echo                               2: GC on transitions to preemptive GC
730 echo                               4: GC on every allowable JITed instruction
731 echo                               8: GC on every allowable NGEN instruction
732 echo                              16: GC only on a unique stack trace
733 echo tieredcompilation         - Run the tests with COMPlus_TieredCompilation=1
734 echo gcname ^<name^>             - Runs the tests with COMPlus_GCName=name
735 echo timeout ^<n^>               - Sets the per-test timeout in milliseconds ^(default is 10 minutes = 10 * 60 * 1000 = 600000^).
736 echo                             Note: some options override this ^(gcstresslevel, longgc, gcsimulator^).
737 echo printlastresultsonly      - Print the last test results without running tests.
738 echo msbuildargs ^<args...^>     - Pass all subsequent args directly to msbuild invocations.
739 echo ^<CORE_ROOT^>               - Path to the runtime to test ^(if specified^).
740 echo.
741 echo Note that arguments are not case-sensitive.
742 echo.
743 echo Examples:
744 echo   %0 x86 checked
745 echo   %0 x64 checked GenerateLayoutOnly
746 echo   %0 x64 release
747 exit /b 1
748
749 :NoVS
750 echo Visual Studio 2015 or 2017 ^(Community is free^) is a prerequisite to build this repository.
751 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
752 exit /b 1