1 @if not defined _echo @echo off
2 setlocal EnableDelayedExpansion
4 :: Set the default arguments
7 set __BuildOS=Windows_NT
8 set __MSBuildBuildArch=x64
10 set "__ProjectDir=%~dp0"
12 :: Define a prefix for most output progress messages that come from this script. That makes
13 :: it easier to see where these are coming from. Note that there is a trailing space here.
14 set "__MsgPrefix=RUNTEST: "
16 call "%__ProjectDir%"\..\setup_vs_tools.cmd
18 REM setup_vs_tools.cmd will correctly echo error message.
19 if NOT '%ERRORLEVEL%' == '0' exit /b 1
21 set __VSVersion=vs2017
23 if defined VS140COMNTOOLS set __VSVersion=vs2015
24 if defined VS150COMNTOOLS set __VSVersion=vs2017
26 :: remove trailing slash
27 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
28 set "__ProjectFilesDir=%__ProjectDir%"
29 set "__RootBinDir=%__ProjectDir%\..\bin"
30 set "__LogsDir=%__RootBinDir%\Logs"
33 set __msbuildExtraArgs=
35 set __GCSimulatorTests=
36 set __AgainstPackages=
45 if "%1" == "" goto ArgsDone
47 if /i "%1" == "/?" goto Usage
48 if /i "%1" == "-?" goto Usage
49 if /i "%1" == "/h" goto Usage
50 if /i "%1" == "-h" goto Usage
51 if /i "%1" == "/help" goto Usage
52 if /i "%1" == "-help" goto Usage
54 if /i "%1" == "x64" (set __BuildArch=x64&set __MSBuildBuildArch=x64&shift&goto Arg_Loop)
55 if /i "%1" == "x86" (set __BuildArch=x86&set __MSBuildBuildArch=x86&shift&goto Arg_Loop)
56 if /i "%1" == "arm" (set __BuildArch=arm&set __MSBuildBuildArch=arm&shift&goto Arg_Loop)
57 if /i "%1" == "arm64" (set __BuildArch=arm64&set __MSBuildBuildArch=arm64&shift&goto Arg_Loop)
59 if /i "%1" == "debug" (set __BuildType=Debug&shift&goto Arg_Loop)
60 if /i "%1" == "release" (set __BuildType=Release&shift&goto Arg_Loop)
61 if /i "%1" == "checked" (set __BuildType=Checked&shift&goto Arg_Loop)
63 if /i "%1" == "vs2015" (set __VSVersion=%1&shift&goto Arg_Loop)
64 if /i "%1" == "vs2017" (set __VSVersion=%1&shift&goto Arg_Loop)
66 if /i "%1" == "TestEnv" (set __TestEnv=%2&shift&shift&goto Arg_Loop)
67 if /i "%1" == "AgainstPackages" (set __AgainstPackages=1&shift&goto Arg_Loop)
68 if /i "%1" == "sequential" (set __Sequential=1&shift&goto Arg_Loop)
69 if /i "%1" == "crossgen" (set __DoCrossgen=1&shift&goto Arg_Loop)
70 if /i "%1" == "crossgenaltjit" (set __DoCrossgen=1&set __CrossgenAltJit=%2&shift&shift&goto Arg_Loop)
71 if /i "%1" == "longgc" (set __LongGCTests=1&shift&goto Arg_Loop)
72 if /i "%1" == "gcsimulator" (set __GCSimulatorTests=1&shift&goto Arg_Loop)
73 if /i "%1" == "jitstress" (set COMPlus_JitStress=%2&shift&shift&goto Arg_Loop)
74 if /i "%1" == "jitstressregs" (set COMPlus_JitStressRegs=%2&shift&shift&goto Arg_Loop)
75 if /i "%1" == "jitminopts" (set COMPlus_JITMinOpts=1&shift&goto Arg_Loop)
76 if /i "%1" == "jitforcerelocs" (set COMPlus_ForceRelocs=1&shift&goto Arg_Loop)
77 if /i "%1" == "jitdisasm" (set __JitDisasm=1&shift&goto Arg_Loop)
78 if /i "%1" == "ilasmroundtrip" (set __IlasmRoundTrip=1&shift&goto Arg_Loop)
79 if /i "%1" == "GenerateLayoutOnly" (set __GenerateLayoutOnly=1&shift&goto Arg_Loop)
80 if /i "%1" == "PerfTests" (set __PerfTests=true&shift&goto Arg_Loop)
81 if /i "%1" == "runcrossgentests" (set RunCrossGen=true&shift&goto Arg_Loop)
82 if /i "%1" == "link" (set DoLink=true&set ILLINK=%2&shift&shift&goto Arg_Loop)
83 if /i "%1" == "tieredcompilation" (set COMPLUS_TieredCompilation=1&shift&goto Arg_Loop)
84 if /i "%1" == "gcname" (set COMPlus_GCName=%2&shift&shift&goto Arg_Loop)
85 if /i "%1" == "timeout" (set __TestTimeout=%2&shift&shift&goto Arg_Loop)
87 REM change it to COMPlus_GCStress when we stop using xunit harness
88 if /i "%1" == "gcstresslevel" (set __GCSTRESSLEVEL=%2&set __TestTimeout=1800000&shift&shift&goto Arg_Loop)
89 if /i "%1" == "collectdumps" (set __CollectDumps=true&shift&goto Arg_Loop)
91 if /i not "%1" == "msbuildargs" goto SkipMsbuildArgs
92 :: All the rest of the args will be collected and passed directly to msbuild.
95 if "%1"=="" goto ArgsDone
96 set __msbuildExtraArgs=%__msbuildExtraArgs% %1
97 goto CollectMsbuildArgs
101 echo %__MsgPrefix%CORE_ROOT is initially set to: "%CORE_ROOT%"
105 :: Done with argument processing. Check argument values for validity.
107 if defined __TestEnv (if not exist %__TestEnv% echo %__MsgPrefix%Error: Test Environment script %__TestEnv% not found && exit /b 1)
108 if "%__PerfTests%"=="true" (if defined __GenerateLayoutOnly echo %__MsgPrefix%Error: Don't specify both "PerfTests" and "GenerateLayoutOnly" && exit /b 1)
110 :: Set the remaining variables based upon the determined configuration
111 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
112 set "__TestWorkingDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%"
114 :: Default global test environment variables
115 :: REVIEW: are these ever expected to be defined on entry to this script? Why? By whom?
116 :: REVIEW: XunitTestReportDirBase is not used in this script. Who needs to have it set?
117 if not defined XunitTestBinBase set XunitTestBinBase=%__TestWorkingDir%
118 if not defined XunitTestReportDirBase set XunitTestReportDirBase=%XunitTestBinBase%\Reports\
120 :: Set up msbuild and tools environment. Check if msbuild and VS exist.
123 if /i "%__VSVersion%" == "vs2017" (
124 set "__VSToolsRoot=%VS150COMNTOOLS%"
125 set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build"
127 set _msbuildexe="%VS150COMNTOOLS%\..\..\MSBuild\15.0\Bin\MSBuild.exe"
128 ) else if /i "%__VSVersion%" == "vs2015" (
129 set "__VSToolsRoot=%VS140COMNTOOLS%"
130 set "__VCToolsRoot=%VS140COMNTOOLS%\..\..\VC"
132 set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
133 if not exist !_msbuildexe! set _msbuildexe="%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe"
136 :: Does VS really exist?
137 if not exist "%__VSToolsRoot%\..\IDE\devenv.exe" goto NoVS
138 if not exist "%__VCToolsRoot%\vcvarsall.bat" goto NoVS
139 if not exist "%__VSToolsRoot%\VsDevCmd.bat" goto NoVS
141 :: Does MSBuild really exist?
142 if not exist %_msbuildexe% (
143 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.
147 if not defined VSINSTALLDIR (
148 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.
152 :: Note: We've disabled node reuse because it causes file locking issues.
153 :: The issue is that we extend the build with our own targets which
154 :: means that that rebuilding cannot successfully delete the task
156 set __msbuildCommonArgs=/nologo /nodeReuse:false %__msbuildExtraArgs% /p:Platform=%__MSBuildBuildArch%
158 if not defined __Sequential (
159 set __msbuildCommonArgs=%__msbuildCommonArgs% /maxcpucount
161 set __msbuildCommonArgs=%__msbuildCommonArgs% /p:ParallelRun=false
164 if defined __AgainstPackages (
165 set __msbuildCommonArgs=%__msbuildCommonArgs% /p:BuildTestsAgainstPackages=true
169 set __msbuildCommonArgs=%__msbuildCommonArgs% /p:RunTestsViaIllink=true
172 if not exist %__LogsDir% md %__LogsDir%
174 REM These log files are created automatically by the test run process. Q: what do they depend on being set?
175 set __TestRunHtmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.html
176 set __TestRunXmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.xml
178 REM Prepare the Test Drop
180 if not defined __GenerateLayoutOnly (
181 echo %__MsgPrefix%Removing 'ni' files and 'lock' folders from %__TestWorkingDir%
182 REM Cleans any NI from the last run
183 powershell -NoProfile "Get-ChildItem -path %__TestWorkingDir% -Include '*.ni.*' -Recurse -Force | Remove-Item -force"
184 REM Cleans up any lock folder used for synchronization from last run
185 powershell -NoProfile "Get-ChildItem -path %__TestWorkingDir% -Include 'lock' -Recurse -Force | where {$_.Attributes -eq 'Directory'}| Remove-Item -force -Recurse"
188 if defined CORE_ROOT goto SkipCoreRootSetup
190 set "CORE_ROOT=%XunitTestBinBase%\Tests\Core_Root"
191 echo %__MsgPrefix%Using Default CORE_ROOT as %CORE_ROOT%
192 echo %__MsgPrefix%Copying Built binaries from %__BinDir% to %CORE_ROOT%
193 if exist "%CORE_ROOT%" rd /s /q "%CORE_ROOT%"
195 xcopy "%__BinDir%" "%CORE_ROOT%"
199 if not exist %CORE_ROOT%\coreclr.dll (
200 echo %__MsgPrefix%Error: Ensure you have done a successful build of the Product and %CORE_ROOT% contains runtime binaries.
204 if "%__PerfTests%"=="true" goto RunPerfTests
206 REM =========================================================================================
208 REM === Run normal (non-perf) tests
210 REM =========================================================================================
212 call :SetTestEnvironment
214 call :ResolveDependencies
215 if errorlevel 1 exit /b 1
217 if defined __DoCrossgen call :PrecompileFX
219 REM Delete the unecessary mscorlib.ni file.
220 if exist %CORE_ROOT%\mscorlib.ni.dll del %CORE_ROOT%\mscorlib.ni.dll
222 if defined __GenerateLayoutOnly (
226 ::Check if the test Binaries are built
227 if not exist %XunitTestBinBase% (
228 echo %__MsgPrefix%Error: Ensure the Test Binaries are built and are present at %XunitTestBinBase%.
229 echo %__MsgPrefix%Run "buildtest.cmd %__BuildArch% %__BuildType%" to build the tests first.
233 if "%__CollectDumps%"=="true" (
235 set "__DumplingHelperPath=%__ProjectDir%\..\Tools\DumplingHelper.py"
236 python "!__DumplingHelperPath!" install_dumpling
238 :: Create the crash dump folder if necessary
239 set "__CrashDumpFolder=%tmp%\CoreCLRTestCrashDumps"
240 if not exist "!__CrashDumpFolder!" (
241 mkdir "!__CrashDumpFolder!"
244 :: Grab the current time before execution begins. This will be used to determine which crash dumps
246 for /f "delims=" %%a in ('python !__DumplingHelperPath! get_timestamp') do @set __StartTime=%%a
249 echo %__MsgPrefix%CORE_ROOT that will be used is: %CORE_ROOT%
250 echo %__MsgPrefix%Starting the test run ...
252 set __BuildLogRootName=TestRunResults
253 call :msbuild "%__ProjectFilesDir%\runtest.proj" /p:Runtests=true /clp:showcommandline
254 set __errorlevel=%errorlevel%
256 if "%__CollectDumps%"=="true" (
257 python "%__DumplingHelperPath%" collect_dump %errorlevel% "%__CrashDumpFolder%" %__StartTime% "CoreCLR_Tests"
260 if %__errorlevel% GEQ 1 (
261 echo Test Run failed. Refer to the following:
262 echo Html report: %__TestRunHtmlLog%
268 REM =========================================================================================
270 REM === Run perf tests
272 REM =========================================================================================
275 echo %__MsgPrefix%CORE_ROOT that will be used is: %CORE_ROOT%
276 echo %__MsgPrefix%Starting the test run ...
278 set __BuildLogRootName=PerfTestRunResults
279 echo %__MsgPrefix%Running perf tests
280 call :msbuild "%__ProjectFilesDir%\runtest.proj" /t:RunPerfTests /clp:showcommandline
283 echo %__MsgPrefix%Test Run failed. Refer to the following:
284 echo Html report: %__TestRunHtmlLog%
289 REM =========================================================================================
291 REM === All tests complete!
293 REM =========================================================================================
297 echo %__MsgPrefix%Test run successful. Refer to the log files for details:
298 echo %__TestRunHtmlLog%
299 echo %__TestRunXmlLog%
302 REM =========================================================================================
304 REM === Compile the managed assemblies in Core_ROOT before running the tests
306 REM =========================================================================================
310 if defined __JitDisasm goto :jitdisasm
312 REM Skip mscorlib since it is already precompiled.
313 if /I "%3" == "mscorlib.dll" exit /b 0
314 if /I "%3" == "mscorlib.ni.dll" exit /b 0
316 "%1\crossgen.exe" /Platform_Assemblies_Paths "%CORE_ROOT%" "%2" >nul 2>nul
317 set /a __exitCode = %errorlevel%
318 if "%__exitCode%" == "-2146230517" (
319 echo %2 is not a managed assembly.
323 if %__exitCode% neq 0 (
324 echo Unable to precompile %2
328 echo %__MsgPrefix%Successfully precompiled %2
333 if /I "%3" == "mscorlib.ni.dll" exit /b 0
335 echo "%1\corerun" "%1\jit-dasm.dll" --crossgen %1\crossgen.exe --platform %CORE_ROOT% --output %__TestWorkingDir%\dasm "%2"
336 "%1\corerun" "%1\jit-dasm.dll" --crossgen %1\crossgen.exe --platform %CORE_ROOT% --output %__TestWorkingDir%\dasm "%2"
337 set /a __exitCode = %errorlevel%
339 if "%__exitCode%" == "-2146230517" (
340 echo %2 is not a managed assembly.
344 if %__exitCode% neq 0 (
345 echo Unable to precompile %2
349 echo %__MsgPrefix%Successfully precompiled and generated dasm for %2
355 if defined __CrossgenAltJit (
356 REM Set altjit flags for the crossgen run. Note that this entire crossgen section is within a setlocal/endlocal scope,
357 REM so we don't need to save or unset these afterwards.
358 echo %__MsgPrefix%Setting altjit environment variables for %__CrossgenAltJit%.
360 set COMPlus_AltJitNgen=*
361 set COMPlus_AltJitName=%__CrossgenAltJit%
362 set COMPlus_AltJitAssertOnNYI=1
363 set COMPlus_NoGuiOnAssert=1
364 set COMPlus_ContinueOnAssert=0
367 for %%F in (%CORE_ROOT%\*.dll) do call :PrecompileAssembly "%CORE_ROOT%" "%%F" %%~nF%%~xF
371 REM =========================================================================================
373 REM === Subroutine to invoke msbuild.
375 REM === All arguments are passed to msbuild. The first argument should be the .proj file to invoke.
377 REM === On entry, environment variable __BuildLogRootName must be set to a file name prefix for the generated log files.
378 REM === All the "standard" environment variables that aren't expected to change per invocation must also be set,
379 REM === like __msbuildCommonArgs.
381 REM === The build log files will be overwritten, not appended to.
383 REM =========================================================================================
387 echo %__MsgPrefix%Invoking msbuild
389 set "__BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
390 set "__BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
391 set "__BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
393 set __msbuildLogArgs=^
394 /fileloggerparameters:Verbosity=normal;LogFile="%__BuildLog%";Append ^
395 /fileloggerparameters1:WarningsOnly;LogFile="%__BuildWrn%" ^
396 /fileloggerparameters2:ErrorsOnly;LogFile="%__BuildErr%" ^
397 /consoleloggerparameters:Summary ^
400 set __msbuildArgs=%* %__msbuildCommonArgs% %__msbuildLogArgs%
402 @REM The next line will overwrite the existing log file, if any.
403 echo %__MsgPrefix%%_msbuildexe% %__msbuildArgs%
404 echo Invoking: %_msbuildexe% %__msbuildArgs% > "%__BuildLog%"
406 %_msbuildexe% %__msbuildArgs%
408 echo %__MsgPrefix%Error: msbuild failed. Refer to the log files for details:
417 REM =========================================================================================
419 REM === Set various environment variables, based on arguments to this script, before invoking the tests.
421 REM =========================================================================================
425 :: Long GC tests take about 10 minutes per test on average, so
426 :: they often bump up against the default 10 minute timeout.
427 :: 20 minutes is more than enough time for a test to complete successfully.
428 if defined __LongGCTests (
429 echo %__MsgPrefix%Running Long GC tests, extending timeout to 20 minutes
430 set __TestTimeout=1200000
431 set RunningLongGCTests=1
434 :: GCSimulator tests can take up to an hour to complete. They are run twice a week in the
435 :: CI, so it's fine if they take a long time.
436 if defined __GCSimulatorTests (
437 echo %__MsgPrefix%Running GCSimulator tests, extending timeout to one hour
438 set __TestTimeout=3600000
439 set RunningGCSimulatorTests=1
442 if defined __JitDisasm (
443 if defined __DoCrossgen (
444 echo %__MsgPrefix%Running jit disasm on framework and test assemblies
446 if not defined __DoCrossgen (
447 echo %__MsgPrefix%Running jit disasm on test assemblies only
449 set RunningJitDisasm=1
452 if defined __IlasmRoundTrip (
453 echo %__MsgPrefix%Running Ilasm round trip
454 set RunningIlasmRoundTrip=1
459 REM =========================================================================================
461 REM === Generate the "layout" directory in CORE_ROOT; download dependencies.
463 REM =========================================================================================
466 set __BuildLogRootName=Tests_GenerateRuntimeLayout
467 call :msbuild "%__ProjectFilesDir%\runtest.proj" /p:GenerateRuntimeLayout=true
469 echo %__MsgPrefix%Test Dependency Resolution Failed
472 echo %__MsgPrefix%Created the runtime layout with all dependencies in %CORE_ROOT%
476 REM =========================================================================================
478 REM === Display a help message describing how to use this script.
480 REM =========================================================================================
483 @REM NOTE: The caret character is used to escape meta-characters known to the CMD shell. This character does
484 @REM NOTE: not appear in output. Thus, while it might look like in lines below that the "-" are not aligned,
485 @REM NOTE: they are in the output (and please keep them aligned).
488 echo %0 [options] [^<CORE_ROOT^>]
492 echo./? -? /h -h /help -help - View this message.
493 echo ^<build_architecture^> - Specifies build architecture: x64, x86, arm, or arm64 ^(default: x64^).
494 echo ^<build_type^> - Specifies build type: Debug, Release, or Checked ^(default: Debug^).
495 echo VSVersion ^<vs_version^> - VS2015 or VS2017 ^(default: VS2017^).
496 echo TestEnv ^<test_env_script^> - Run a custom script before every test to set custom test environment settings.
497 echo AgainstPackages - This indicates that we are running tests that were built against packages.
498 echo GenerateLayoutOnly - If specified will not run the tests and will only create the Runtime Dependency Layout
499 echo sequential - Run tests sequentially (no parallelism).
500 echo crossgen - Precompile ^(crossgen^) the managed assemblies in CORE_ROOT before running the tests.
501 echo crossgenaltjit ^<altjit^> - Precompile ^(crossgen^) the managed assemblies in CORE_ROOT before running the tests, using the given altjit.
502 echo link ^<ILlink^> - Runs the tests after linking via the IL linker ^<ILlink^>.
503 echo RunCrossgenTests - Runs ReadytoRun tests
504 echo jitstress ^<n^> - Runs the tests with COMPlus_JitStress=n
505 echo jitstressregs ^<n^> - Runs the tests with COMPlus_JitStressRegs=n
506 echo jitminopts - Runs the tests with COMPlus_JITMinOpts=1
507 echo jitforcerelocs - Runs the tests with COMPlus_ForceRelocs=1
508 echo jitdisasm - Runs jit-dasm on the tests
509 echo ilasmroundtrip - Runs ilasm round trip on the tests
510 echo longgc - Run the long-running GC tests
511 echo gcsimulator - Run the GC Simulator tests
512 echo gcstresslevel ^<n^> - Runs the tests with COMPlus_GCStress=n. n=0 means no GC Stress. Otherwise, n is a bitmask of the following:
513 echo 1: GC on all allocations and 'easy' places
514 echo 2: GC on transitions to preemptive GC
515 echo 4: GC on every allowable JITed instruction
516 echo 8: GC on every allowable NGEN instruction
517 echo 16: GC only on a unique stack trace
518 echo tieredcompilation - Run the tests with COMPlus_TieredCompilation=1
519 echo gcname ^<name^> - Runs the tests with COMPlus_GCName=name
520 echo timeout ^<n^> - Sets the per-test timeout in milliseconds ^(default is 10 minutes = 10 * 60 * 1000 = 600000^).
521 echo Note: some options override this ^(gcstresslevel, longgc, gcsimulator^).
522 echo msbuildargs ^<args...^> - Pass all subsequent args directly to msbuild invocations.
523 echo ^<CORE_ROOT^> - Path to the runtime to test ^(if specified^).
525 echo Note that arguments are not case-sensitive.
529 echo %0 x64 checked GenerateLayoutOnly
534 echo Visual Studio 2015 or 2017 ^(Community is free^) is a prerequisite to build this repository.
535 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites