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 :: Define a prefix for most output progress messages that come from this script. That makes
11 :: it easier to see where these are coming from. Note that there is a trailing space here.
12 set "__MsgPrefix=RUNTEST: "
14 :: Default to highest Visual Studio version available
16 :: For VS2015 (and prior), only a single instance is allowed to be installed on a box
17 :: and VS140COMNTOOLS is set as a global environment variable by the installer. This
18 :: allows users to locate where the instance of VS2015 is installed.
20 :: For VS2017, multiple instances can be installed on the same box SxS and VS150COMNTOOLS
21 :: is no longer set as a global environment variable and is instead only set if the user
22 :: has launched the VS2017 Developer Command Prompt.
24 :: Following this logic, we will default to the VS2017 toolset if VS150COMNTOOLS tools is
25 :: set, as this indicates the user is running from the VS2017 Developer Command Prompt and
26 :: is already configured to use that toolset. Otherwise, we will fallback to using the VS2015
27 :: toolset if it is installed. Finally, we will fail the script if no supported VS instance
29 if defined VisualStudioVersion (
30 if not defined __VSVersion echo %__MsgPrefix%Detected Visual Studio %VisualStudioVersion% developer command ^prompt environment
34 set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
36 for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools
38 if not exist "%_VSCOMNTOOLS%" set _VSCOMNTOOLS=%VS140COMNTOOLS%
39 if not exist "%_VSCOMNTOOLS%" (
40 echo %__MsgPrefix%Error: Visual Studio 2015 or 2017 required.
41 echo Please see https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/developer-guide.md for build instructions.
45 call "%_VSCOMNTOOLS%\VsDevCmd.bat"
49 set __VSVersion=vs2017
51 if defined VS140COMNTOOLS set __VSVersion=vs2015
52 if defined VS150COMNTOOLS set __VSVersion=vs2017
54 set __ProjectDir=%~dp0
55 :: remove trailing slash
56 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
57 set "__ProjectFilesDir=%__ProjectDir%"
58 set "__RootBinDir=%__ProjectDir%\..\bin"
59 set "__LogsDir=%__RootBinDir%\Logs"
62 set __msbuildExtraArgs=
64 set __GCSimulatorTests=
65 set __AgainstPackages=
73 if "%1" == "" goto ArgsDone
75 if /i "%1" == "/?" goto Usage
76 if /i "%1" == "-?" goto Usage
77 if /i "%1" == "/h" goto Usage
78 if /i "%1" == "-h" goto Usage
79 if /i "%1" == "/help" goto Usage
80 if /i "%1" == "-help" goto Usage
82 if /i "%1" == "x64" (set __BuildArch=x64&set __MSBuildBuildArch=x64&shift&goto Arg_Loop)
83 if /i "%1" == "x86" (set __BuildArch=x86&set __MSBuildBuildArch=x86&shift&goto Arg_Loop)
84 if /i "%1" == "arm" (set __BuildArch=arm&set __MSBuildBuildArch=arm&shift&goto Arg_Loop)
85 if /i "%1" == "arm64" (set __BuildArch=arm64&set __MSBuildBuildArch=arm64&shift&goto Arg_Loop)
87 if /i "%1" == "debug" (set __BuildType=Debug&shift&goto Arg_Loop)
88 if /i "%1" == "release" (set __BuildType=Release&shift&goto Arg_Loop)
89 if /i "%1" == "checked" (set __BuildType=Checked&shift&goto Arg_Loop)
91 if /i "%1" == "vs2015" (set __VSVersion=%1&shift&goto Arg_Loop)
92 if /i "%1" == "vs2017" (set __VSVersion=%1&shift&goto Arg_Loop)
94 if /i "%1" == "TestEnv" (set __TestEnv=%2&shift&shift&goto Arg_Loop)
95 if /i "%1" == "AgainstPackages" (set __AgainstPackages=1&shift&goto Arg_Loop)
96 if /i "%1" == "sequential" (set __Sequential=1&shift&goto Arg_Loop)
97 if /i "%1" == "crossgen" (set __DoCrossgen=1&shift&goto Arg_Loop)
98 if /i "%1" == "crossgenaltjit" (set __DoCrossgen=1&set __CrossgenAltJit=%2&shift&shift&goto Arg_Loop)
99 if /i "%1" == "longgc" (set __LongGCTests=1&shift&goto Arg_Loop)
100 if /i "%1" == "gcsimulator" (set __GCSimulatorTests=1&shift&goto Arg_Loop)
101 if /i "%1" == "jitstress" (set COMPlus_JitStress=%2&shift&shift&goto Arg_Loop)
102 if /i "%1" == "jitstressregs" (set COMPlus_JitStressRegs=%2&shift&shift&goto Arg_Loop)
103 if /i "%1" == "jitminopts" (set COMPlus_JITMinOpts=1&shift&goto Arg_Loop)
104 if /i "%1" == "jitforcerelocs" (set COMPlus_ForceRelocs=1&shift&goto Arg_Loop)
105 if /i "%1" == "jitdisasm" (set __JitDisasm=1&shift&goto Arg_Loop)
106 if /i "%1" == "ilasmroundtrip" (set __IlasmRoundTrip=1&shift&goto Arg_Loop)
107 if /i "%1" == "GenerateLayoutOnly" (set __GenerateLayoutOnly=1&shift&goto Arg_Loop)
108 if /i "%1" == "PerfTests" (set __PerfTests=true&shift&goto Arg_Loop)
109 if /i "%1" == "runcrossgentests" (set RunCrossGen=true&shift&goto Arg_Loop)
110 if /i "%1" == "link" (set DoLink=true&set ILLINK=%2&shift&shift&goto Arg_Loop)
111 if /i "%1" == "tieredcompilation" (set COMPLUS_EXPERIMENTAL_TieredCompilation=1&shift&goto Arg_Loop)
112 if /i "%1" == "gcname" (set COMPlus_GCName=%2&shift&shift&goto Arg_Loop)
113 if /i "%1" == "timeout" (set __TestTimeout=%2&shift&shift&goto Arg_Loop)
115 REM change it to COMPlus_GCStress when we stop using xunit harness
116 if /i "%1" == "gcstresslevel" (set __GCSTRESSLEVEL=%2&set __TestTimeout=1800000&shift&shift&goto Arg_Loop)
117 if /i "%1" == "collectdumps" (set __CollectDumps=true&shift&goto Arg_Loop)
119 if /i not "%1" == "msbuildargs" goto SkipMsbuildArgs
120 :: All the rest of the args will be collected and passed directly to msbuild.
123 if "%1"=="" goto ArgsDone
124 set __msbuildExtraArgs=%__msbuildExtraArgs% %1
125 goto CollectMsbuildArgs
129 echo %__MsgPrefix%CORE_ROOT is initially set to: "%CORE_ROOT%"
133 :: Set the remaining variables based upon the determined configuration
134 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
135 set "__TestWorkingDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%"
137 :: Default global test environment variables
138 :: REVIEW: are these ever expected to be defined on entry to this script? Why? By whom?
139 :: REVIEW: XunitTestReportDirBase is not used in this script. Who needs to have it set?
140 if not defined XunitTestBinBase set XunitTestBinBase=%__TestWorkingDir%
141 if not defined XunitTestReportDirBase set XunitTestReportDirBase=%XunitTestBinBase%\Reports\
143 if not exist %__LogsDir% md %__LogsDir%
146 if /i "%__VSVersion%" == "vs2017" (
147 set "__VSToolsRoot=%VS150COMNTOOLS%"
148 set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build"
150 set _msbuildexe="%VS150COMNTOOLS%\..\..\MSBuild\15.0\Bin\MSBuild.exe"
151 ) else if /i "%__VSVersion%" == "vs2015" (
152 set "__VSToolsRoot=%VS140COMNTOOLS%"
153 set "__VCToolsRoot=%VS140COMNTOOLS%\..\..\VC"
155 set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
156 if not exist !_msbuildexe! set _msbuildexe="%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe"
159 :: Does VS really exist?
160 if not exist "%__VSToolsRoot%\..\IDE\devenv.exe" goto NoVS
161 if not exist "%__VCToolsRoot%\vcvarsall.bat" goto NoVS
162 if not exist "%__VSToolsRoot%\VsDevCmd.bat" goto NoVS
164 :: Does MSBuild really exist?
165 if not exist %_msbuildexe% 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. && exit /b 1
167 if not defined VSINSTALLDIR (
168 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.
172 :: Note: We've disabled node reuse because it causes file locking issues.
173 :: The issue is that we extend the build with our own targets which
174 :: means that that rebuilding cannot successfully delete the task
176 set __msbuildCommonArgs=/nologo /nodeReuse:false %__msbuildExtraArgs% /p:Platform=%__MSBuildBuildArch%
178 if not defined __Sequential (
179 set __msbuildCommonArgs=%__msbuildCommonArgs% /maxcpucount
181 set __msbuildCommonArgs=%__msbuildCommonArgs% /p:ParallelRun=false
184 if defined __AgainstPackages (
185 set __msbuildCommonArgs=%__msbuildCommonArgs% /p:BuildTestsAgainstPackages=true
189 set __msbuildCommonArgs=%__msbuildCommonArgs% /p:RunTestsViaIllink=true
192 REM Prepare the Test Drop
193 echo %__MsgPrefix%Removing 'ni' files and 'lock' folders from %__TestWorkingDir%
194 REM Cleans any NI from the last run
195 powershell -NoProfile "Get-ChildItem -path %__TestWorkingDir% -Include '*.ni.*' -Recurse -Force | Remove-Item -force"
196 REM Cleans up any lock folder used for synchronization from last run
197 powershell -NoProfile "Get-ChildItem -path %__TestWorkingDir% -Include 'lock' -Recurse -Force | where {$_.Attributes -eq 'Directory'}| Remove-Item -force -Recurse"
199 if defined CORE_ROOT goto SkipCoreRootSetup
201 set "CORE_ROOT=%XunitTestBinBase%\Tests\Core_Root"
202 echo %__MsgPrefix%Using Default CORE_ROOT as %CORE_ROOT%
203 echo %__MsgPrefix%Copying Built binaries from %__BinDir% to %CORE_ROOT%
204 if exist "%CORE_ROOT%" rd /s /q "%CORE_ROOT%"
206 xcopy "%__BinDir%" "%CORE_ROOT%"
211 if defined __TestEnv (if not exist %__TestEnv% echo %__MsgPrefix%Error: Test Environment script %__TestEnv% not found && exit /b 1)
213 REM These log files are created automatically by the test run process. Q: what do they depend on being set?
214 set __TestRunHtmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.html
215 set __TestRunXmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.xml
218 if "%__PerfTests%"=="true" goto RunPerfTests
220 call :ResolveDependecies
222 if defined __DoCrossgen call :PrecompileFX
224 if defined __GenerateLayoutOnly (
225 REM Delete the unecessary mscorlib.ni file.
226 if exist %CORE_ROOT%\mscorlib.ni.dll del %CORE_ROOT%\mscorlib.ni.dll
230 if not exist %CORE_ROOT%\coreclr.dll (
231 echo %__MsgPrefix%Error: Ensure you have done a successful build of the Product and %CORE_ROOT% contains runtime binaries.
235 ::Check if the test Binaries are built
236 if not exist %XunitTestBinBase% (
237 echo %__MsgPrefix%Error: Ensure the Test Binaries are built and are present at %XunitTestBinBase%.
238 echo %__MsgPrefix%Run "buildtest.cmd %__BuildArch% %__BuildType%" to build the tests first.
242 if "%__CollectDumps%"=="true" (
244 set "__DumplingHelperPath=%__ProjectDir%\..\Tools\DumplingHelper.py"
245 python "!__DumplingHelperPath!" install_dumpling
247 :: Create the crash dump folder if necessary
248 set "__CrashDumpFolder=%tmp%\CoreCLRTestCrashDumps"
249 if not exist "!__CrashDumpFolder!" (
250 mkdir "!__CrashDumpFolder!"
253 :: Grab the current time before execution begins. This will be used to determine which crash dumps
255 for /f "delims=" %%a in ('python !__DumplingHelperPath! get_timestamp') do @set __StartTime=%%a
258 echo %__MsgPrefix%CORE_ROOT that will be used is: %CORE_ROOT%
259 echo %__MsgPrefix%Starting the test run ...
261 REM Delete the unecessary mscorlib.ni file.
262 if exist %CORE_ROOT%\mscorlib.ni.dll del %CORE_ROOT%\mscorlib.ni.dll
264 set __BuildLogRootName=TestRunResults
265 call :msbuild "%__ProjectFilesDir%\runtest.proj" /p:Runtests=true /clp:showcommandline
266 set __errorlevel=%errorlevel%
268 if "%__CollectDumps%"=="true" (
269 python "%__DumplingHelperPath%" collect_dump %errorlevel% "%__CrashDumpFolder%" %__StartTime% "CoreCLR_Tests"
272 if %__errorlevel% GEQ 1 (
273 echo Test Run failed. Refer to the following:
274 echo Html report: %__TestRunHtmlLog%
278 if not defined __PerfTests goto :SkipRunPerfTests
281 echo %__MsgPrefix%CORE_ROOT that will be used is: %CORE_ROOT%
282 echo %__MsgPrefix%Starting the test run ...
284 set __BuildLogRootName=PerfTestRunResults
285 echo %__MsgPrefix%Running perf tests
286 call :msbuild "%__ProjectFilesDir%\runtest.proj" /t:RunPerfTests /clp:showcommandline
289 echo %__MsgPrefix%Test Run failed. Refer to the following:
290 echo Html report: %__TestRunHtmlLog%
295 REM =========================================================================================
297 REM === All tests complete!
299 REM =========================================================================================
301 echo %__MsgPrefix%Test run successful. Refer to the log files for details:
302 echo %__TestRunHtmlLog%
303 echo %__TestRunXmlLog%
306 REM =========================================================================================
308 REM === Helper routines
310 REM =========================================================================================
312 REM Compile the managed assemblies in Core_ROOT before running the tests
315 if defined __JitDisasm goto :jitdisasm
317 REM Skip mscorlib since it is already precompiled.
318 if /I "%3" == "mscorlib.dll" exit /b 0
319 if /I "%3" == "mscorlib.ni.dll" exit /b 0
321 "%1\crossgen.exe" /Platform_Assemblies_Paths "%CORE_ROOT%" "%2" >nul 2>nul
322 set /a __exitCode = %errorlevel%
323 if "%__exitCode%" == "-2146230517" (
324 echo %2 is not a managed assembly.
328 if %__exitCode% neq 0 (
329 echo Unable to precompile %2
333 echo %__MsgPrefix%Successfully precompiled %2
338 if /I "%3" == "mscorlib.ni.dll" exit /b 0
340 echo "%1\corerun" "%1\jit-dasm.dll" --crossgen %1\crossgen.exe --platform %CORE_ROOT% --output %__TestWorkingDir%\dasm "%2"
341 "%1\corerun" "%1\jit-dasm.dll" --crossgen %1\crossgen.exe --platform %CORE_ROOT% --output %__TestWorkingDir%\dasm "%2"
342 set /a __exitCode = %errorlevel%
344 if "%__exitCode%" == "-2146230517" (
345 echo %2 is not a managed assembly.
349 if %__exitCode% neq 0 (
350 echo Unable to precompile %2
354 echo %__MsgPrefix%Successfully precompiled and generated dasm for %2
360 if defined __CrossgenAltJit (
361 REM Set altjit flags for the crossgen run. Note that this entire crossgen section is within a setlocal/endlocal scope,
362 REM so we don't need to save or unset these afterwards.
363 echo %__MsgPrefix%Setting altjit environment variables for %__CrossgenAltJit%.
365 set COMPlus_AltJitNgen=*
366 set COMPlus_AltJitName=%__CrossgenAltJit%
367 set COMPlus_AltJitAssertOnNYI=1
368 set COMPlus_NoGuiOnAssert=1
369 set COMPlus_ContinueOnAssert=0
372 for %%F in (%CORE_ROOT%\*.dll) do call :PrecompileAssembly "%CORE_ROOT%" "%%F" %%~nF%%~xF
377 @REM Subroutine to invoke msbuild. All arguments are passed to msbuild. The first argument should be the
378 @REM .proj file to invoke.
380 @REM On entry, __BuildLogRootName must be set to a file name prefix for the generated log file.
381 @REM All the "standard" environment variables that aren't expected to change per invocation must also be set,
382 @REM like __msbuildCommonArgs.
384 @REM The build log files will be overwritten, not appended to.
386 echo %__MsgPrefix%Invoking msbuild
388 set "__BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
389 set "__BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
390 set "__BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
392 set __msbuildLogArgs=^
393 /fileloggerparameters:Verbosity=normal;LogFile="%__BuildLog%";Append ^
394 /fileloggerparameters1:WarningsOnly;LogFile="%__BuildWrn%" ^
395 /fileloggerparameters2:ErrorsOnly;LogFile="%__BuildErr%" ^
396 /consoleloggerparameters:Summary ^
399 set __msbuildArgs=%* %__msbuildCommonArgs% %__msbuildLogArgs%
401 @REM The next line will overwrite the existing log file, if any.
402 echo %__MsgPrefix%%_msbuildexe% %__msbuildArgs%
403 echo Invoking: %_msbuildexe% %__msbuildArgs% > "%__BuildLog%"
405 %_msbuildexe% %__msbuildArgs%
407 echo %__MsgPrefix%Error: msbuild failed. Refer to the log files for details:
418 if "%CORE_ROOT%" == "" (
419 echo %__MsgPrefix%Error: Ensure you have done a successful build of the Product and Run - runtest BuildArch BuildType {path to product binaries}.
423 :: Long GC tests take about 10 minutes per test on average, so
424 :: they often bump up against the default 10 minute timeout.
425 :: 20 minutes is more than enough time for a test to complete successfully.
426 if defined __LongGCTests (
427 echo %__MsgPrefix%Running Long GC tests, extending timeout to 20 minutes
428 set __TestTimeout=1200000
429 set RunningLongGCTests=1
432 :: GCSimulator tests can take up to an hour to complete. They are run twice a week in the
433 :: CI, so it's fine if they take a long time.
434 if defined __GCSimulatorTests (
435 echo %__MsgPrefix%Running GCSimulator tests, extending timeout to one hour
436 set __TestTimeout=3600000
437 set RunningGCSimulatorTests=1
440 if defined __JitDisasm (
441 if defined __DoCrossgen (
442 echo %__MsgPrefix%Running jit disasm on framework and test assemblies
444 if not defined __DoCrossgen (
445 echo %__MsgPrefix%Running jit disasm on test assemblies only
447 set RunningJitDisasm=1
450 if defined __IlasmRoundTrip (
451 echo %__MsgPrefix%Running Ilasm round trip
452 set RunningIlasmRoundTrip=1
455 set __BuildLogRootName=Tests_GenerateRuntimeLayout
456 call :msbuild "%__ProjectFilesDir%\runtest.proj" /p:GenerateRuntimeLayout=true
458 echo %__MsgPrefix%Test Dependency Resolution Failed
461 echo %__MsgPrefix%Created the runtime layout with all dependencies in %CORE_ROOT%
468 @REM NOTE: The caret character is used to escape meta-characters known to the CMD shell. This character does
469 @REM NOTE: not appear in output. Thus, while it might look like in lines below that the "-" are not aligned,
470 @REM NOTE: they are in the output (and please keep them aligned).
473 echo %0 [options] [^<CORE_ROOT^>]
477 echo./? -? /h -h /help -help - View this message.
478 echo ^<build_architecture^> - Specifies build architecture: x64, x86, arm, or arm64 ^(default: x64^).
479 echo ^<build_type^> - Specifies build type: Debug, Release, or Checked ^(default: Debug^).
480 echo VSVersion ^<vs_version^> - VS2015 or VS2017 ^(default: VS2017^).
481 echo TestEnv ^<test_env_script^> - Run a custom script before every test to set custom test environment settings.
482 echo AgainstPackages - This indicates that we are running tests that were built against packages.
483 echo GenerateLayoutOnly - If specified will not run the tests and will only create the Runtime Dependency Layout
484 echo sequential - Run tests sequentially (no parallelism).
485 echo crossgen - Precompile ^(crossgen^) the managed assemblies in CORE_ROOT before running the tests.
486 echo crossgenaltjit ^<altjit^> - Precompile ^(crossgen^) the managed assemblies in CORE_ROOT before running the tests, using the given altjit.
487 echo link ^<ILlink^> - Runs the tests after linking via the IL linker ^<ILlink^>.
488 echo RunCrossgenTests - Runs ReadytoRun tests
489 echo jitstress ^<n^> - Runs the tests with COMPlus_JitStress=n
490 echo jitstressregs ^<n^> - Runs the tests with COMPlus_JitStressRegs=n
491 echo jitminopts - Runs the tests with COMPlus_JITMinOpts=1
492 echo jitforcerelocs - Runs the tests with COMPlus_ForceRelocs=1
493 echo jitdisasm - Runs jit-dasm on the tests
494 echo ilasmroundtrip - Runs ilasm round trip on the tests
495 echo longgc - Run the long-running GC tests
496 echo gcsimulator - Run the GC Simulator tests
497 echo gcstresslevel ^<n^> - Runs the tests with COMPlus_GCStress=n. n=0 means no GC Stress. Otherwise, n is a bitmask of the following:
498 echo 1: GC on all allocations and 'easy' places
499 echo 2: GC on transitions to preemptive GC
500 echo 4: GC on every allowable JITed instruction
501 echo 8: GC on every allowable NGEN instruction
502 echo 16: GC only on a unique stack trace
503 echo tieredcompilation - Run the tests with COMPlus_EXPERIMENTAL_TieredCompilation=1
504 echo gcname ^<name^> - Runs the tests with COMPlus_GCName=name
505 echo timeout ^<n^> - Sets the per-test timeout in milliseconds ^(default is 10 minutes = 10 * 60 * 1000 = 600000^).
506 echo Note: some options override this ^(gcstresslevel, longgc, gcsimulator^).
507 echo msbuildargs ^<args...^> - Pass all subsequent args directly to msbuild invocations.
508 echo ^<CORE_ROOT^> - Path to the runtime to test (if specified).
510 echo Note that arguments are not case-sensitive.
514 echo %0 x64 release GenerateLayoutOnly
518 echo Visual Studio 2015 or 2017 (Community is free) is a prerequisite to build this repository.
519 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites