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 :: Default to highest Visual Studio version available
12 :: For VS2015 (and prior), only a single instance is allowed to be installed on a box
13 :: and VS140COMNTOOLS is set as a global environment variable by the installer. This
14 :: allows users to locate where the instance of VS2015 is installed.
16 :: For VS2017, multiple instances can be installed on the same box SxS and VS150COMNTOOLS
17 :: is no longer set as a global environment variable and is instead only set if the user
18 :: has launched the VS2017 Developer Command Prompt.
20 :: Following this logic, we will default to the VS2017 toolset if VS150COMNTOOLS tools is
21 :: set, as this indicates the user is running from the VS2017 Developer Command Prompt and
22 :: is already configured to use that toolset. Otherwise, we will fallback to using the VS2015
23 :: toolset if it is installed. Finally, we will fail the script if no supported VS instance
25 set __VSVersion=vs2017
27 if defined VS140COMNTOOLS set __VSVersion=vs2015
28 if defined VS150COMNTOOLS set __VSVersion=vs2017
30 :: Define a prefix for most output progress messages that come from this script. That makes
31 :: it easier to see where these are coming from. Note that there is a trailing space here.
32 set __MsgPrefix=RUNTEST:
34 set __ProjectDir=%~dp0
35 :: remove trailing slash
36 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
37 set "__ProjectFilesDir=%__ProjectDir%"
38 set "__RootBinDir=%__ProjectDir%\..\bin"
39 set "__LogsDir=%__RootBinDir%\Logs"
42 set __msbuildExtraArgs=
44 set __GCSimulatorTests=
45 set __AgainstPackages=
50 if "%1" == "" goto ArgsDone
52 if /i "%1" == "/?" goto Usage
53 if /i "%1" == "-?" goto Usage
54 if /i "%1" == "/h" goto Usage
55 if /i "%1" == "-h" goto Usage
56 if /i "%1" == "/help" goto Usage
57 if /i "%1" == "-help" goto Usage
59 if /i "%1" == "x64" (set __BuildArch=x64&set __MSBuildBuildArch=x64&shift&goto Arg_Loop)
60 if /i "%1" == "x86" (set __BuildArch=x86&set __MSBuildBuildArch=x86&shift&goto Arg_Loop)
61 if /i "%1" == "arm" (set __BuildArch=arm&set __MSBuildBuildArch=arm&shift&goto Arg_Loop)
63 if /i "%1" == "debug" (set __BuildType=Debug&shift&goto Arg_Loop)
64 if /i "%1" == "release" (set __BuildType=Release&shift&goto Arg_Loop)
65 if /i "%1" == "checked" (set __BuildType=Checked&shift&goto Arg_Loop)
67 if /i "%1" == "vs2015" (set __VSVersion=%1&shift&goto Arg_Loop)
68 if /i "%1" == "vs2017" (set __VSVersion=%1&shift&goto Arg_Loop)
70 if /i "%1" == "TestEnv" (set __TestEnv=%2&shift&shift&goto Arg_Loop)
71 if /i "%1" == "AgainstPackages" (set __AgainstPackages=1&shift&goto Arg_Loop)
72 if /i "%1" == "sequential" (set __Sequential=1&shift&goto Arg_Loop)
73 if /i "%1" == "crossgen" (set __DoCrossgen=1&shift&goto Arg_Loop)
74 if /i "%1" == "longgc" (set __LongGCTests=1&shift&goto Arg_Loop)
75 if /i "%1" == "gcsimulator" (set __GCSimulatorTests=1&shift&goto Arg_Loop)
76 if /i "%1" == "jitstress" (set COMPlus_JitStress=%2&shift&shift&goto Arg_Loop)
77 if /i "%1" == "jitstressregs" (set COMPlus_JitStressRegs=%2&shift&shift&goto Arg_Loop)
78 if /i "%1" == "jitminopts" (set COMPlus_JITMinOpts=1&shift&shift&goto Arg_Loop)
79 if /i "%1" == "jitforcerelocs" (set COMPlus_ForceRelocs=1&shift&shift&goto Arg_Loop)
80 if /i "%1" == "jitdisasm" (set __JitDisasm=1&shift&goto Arg_Loop)
81 if /i "%1" == "GenerateLayoutOnly" (set __GenerateLayoutOnly=1&shift&goto Arg_Loop)
82 if /i "%1" == "PerfTests" (set __PerfTests=true&shift&goto Arg_Loop)
83 if /i "%1" == "runcrossgentests" (set RunCrossGen=true&shift&goto Arg_Loop)
84 if /i "%1" == "link" (set DoLink=true&set ILLINK=%2&shift&shift&goto Arg_Loop)
86 REM change it to COMPlus_GCStress when we stop using xunit harness
87 if /i "%1" == "gcstresslevel" (set __GCSTRESSLEVEL=%2&set __TestTimeout=1800000&shift&shift&goto Arg_Loop)
88 if /i "%1" == "collectdumps" (set __CollectDumps=true&shift&goto Arg_Loop)
90 if /i not "%1" == "msbuildargs" goto SkipMsbuildArgs
91 :: All the rest of the args will be collected and passed directly to msbuild.
94 if "%1"=="" goto ArgsDone
95 set __msbuildExtraArgs=%__msbuildExtraArgs% %1
96 goto CollectMsbuildArgs
100 echo %__MsgPrefix%CORE_ROOT is initially set to: "%CORE_ROOT%"
104 :: Set the remaining variables based upon the determined configuration
105 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
106 set "__TestWorkingDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%"
108 :: Default global test environment variables
109 :: REVIEW: are these ever expected to be defined on entry to this script? Why? By whom?
110 :: REVIEW: XunitTestReportDirBase is not used in this script. Who needs to have it set?
111 if not defined XunitTestBinBase set XunitTestBinBase=%__TestWorkingDir%
112 if not defined XunitTestReportDirBase set XunitTestReportDirBase=%XunitTestBinBase%\Reports\
114 if not exist %__LogsDir% md %__LogsDir%
117 if /i "%__VSVersion%" == "vs2017" (
118 set "__VSToolsRoot=%VS150COMNTOOLS%"
119 set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build"
121 set _msbuildexe="%VS150COMNTOOLS%\..\..\MSBuild\15.0\Bin\MSBuild.exe"
122 ) else if /i "%__VSVersion%" == "vs2015" (
123 set "__VSToolsRoot=%VS140COMNTOOLS%"
124 set "__VCToolsRoot=%VS140COMNTOOLS%\..\..\VC"
126 set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
127 if not exist !_msbuildexe! set _msbuildexe="%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe"
130 :: Does VS really exist?
131 if not exist "%__VSToolsRoot%\..\IDE\devenv.exe" goto NoVS
132 if not exist "%__VCToolsRoot%\vcvarsall.bat" goto NoVS
133 if not exist "%__VSToolsRoot%\VsDevCmd.bat" goto NoVS
135 :: Does MSBuild really exist?
136 if not exist %_msbuildexe% echo 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
138 :: Set the environment for the build- VS cmd prompt
139 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\VsDevCmd.bat"
140 call "%__VSToolsRoot%\VsDevCmd.bat"
142 if not defined VSINSTALLDIR (
143 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.
147 :: Note: We've disabled node reuse because it causes file locking issues.
148 :: The issue is that we extend the build with our own targets which
149 :: means that that rebuilding cannot successfully delete the task
151 set __msbuildCommonArgs=/nologo /nodeReuse:false %__msbuildExtraArgs% /p:Platform=%__MSBuildBuildArch%
153 if not defined __Sequential (
154 set __msbuildCommonArgs=%__msbuildCommonArgs% /maxcpucount
156 set __msbuildCommonArgs=%__msbuildCommonArgs% /p:ParallelRun=false
159 if defined __AgainstPackages (
160 set __msbuildCommonArgs=%__msbuildCommonArgs% /p:BuildTestsAgainstPackages=true
164 set __msbuildCommonArgs=%__msbuildCommonArgs% /p:RunTestsViaIllink=true
167 REM Prepare the Test Drop
168 REM Cleans any NI from the last run
169 powershell "Get-ChildItem -path %__TestWorkingDir% -Include '*.ni.*' -Recurse -Force | Remove-Item -force"
170 REM Cleans up any lock folder used for synchronization from last run
171 powershell "Get-ChildItem -path %__TestWorkingDir% -Include 'lock' -Recurse -Force | where {$_.Attributes -eq 'Directory'}| Remove-Item -force -Recurse"
173 if defined CORE_ROOT goto SkipCoreRootSetup
175 set "CORE_ROOT=%XunitTestBinBase%\Tests\Core_Root"
176 echo %__MsgPrefix%Using Default CORE_ROOT as %CORE_ROOT%
177 echo %__MsgPrefix%Copying Built binaries from %__BinDir% to %CORE_ROOT%
178 if exist "%CORE_ROOT%" rd /s /q "%CORE_ROOT%"
180 xcopy /s "%__BinDir%" "%CORE_ROOT%"
185 if defined __TestEnv (if not exist %__TestEnv% echo %__MsgPrefix%Error: Test Environment script %__TestEnv% not found && exit /b 1)
187 REM These log files are created automatically by the test run process. Q: what do they depend on being set?
188 set __TestRunHtmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.html
189 set __TestRunXmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.xml
192 if "%__PerfTests%"=="true" goto RunPerfTests
194 call :ResolveDependecies
196 if not defined __DoCrossgen goto :SkipPrecompileFX
201 if defined __GenerateLayoutOnly (
205 if not exist %CORE_ROOT%\coreclr.dll (
206 echo %__MsgPrefix%Error: Ensure you have done a successful build of the Product and %CORE_ROOT% contains runtime binaries.
210 ::Check if the test Binaries are built
211 if not exist %XunitTestBinBase% (
212 echo %__MsgPrefix%Error: Ensure the Test Binaries are built and are present at %XunitTestBinBase%.
213 echo %__MsgPrefix%Run "buildtest.cmd %__BuildArch% %__BuildType%" to build the tests first.
217 if "%__CollectDumps%"=="true" (
219 set "__DumplingHelperPath=%__ProjectDir%\..\Tools\DumplingHelper.py"
220 python "!__DumplingHelperPath!" install_dumpling
222 :: Create the crash dump folder if necessary
223 set "__CrashDumpFolder=%tmp%\CoreCLRTestCrashDumps"
224 if not exist "!__CrashDumpFolder!" (
225 mkdir "!__CrashDumpFolder!"
228 :: Grab the current time before execution begins. This will be used to determine which crash dumps
230 for /f "delims=" %%a in ('python !__DumplingHelperPath! get_timestamp') do @set __StartTime=%%a
233 echo %__MsgPrefix%CORE_ROOT that will be used is: %CORE_ROOT%
234 echo %__MsgPrefix%Starting the test run ...
236 del %CORE_ROOT%\mscorlib.ni.dll
238 set __BuildLogRootName=TestRunResults
239 call :msbuild "%__ProjectFilesDir%\runtest.proj" /p:Runtests=true /clp:showcommandline
240 set __errorlevel=%errorlevel%
242 if "%__CollectDumps%"=="true" (
243 python "%__DumplingHelperPath%" collect_dump %errorlevel% "%__CrashDumpFolder%" %__StartTime% "CoreCLR_Tests"
246 if %__errorlevel% GEQ 1 (
247 echo Test Run failed. Refer to the following:
248 echo Html report: %__TestRunHtmlLog%
252 if not defined __PerfTests goto :SkipRunPerfTests
255 echo %__MsgPrefix%CORE_ROOT that will be used is: %CORE_ROOT%
256 echo %__MsgPrefix%Starting the test run ...
258 set __BuildLogRootName=PerfTestRunResults
259 echo Running perf tests
260 call :msbuild "%__ProjectFilesDir%\runtest.proj" /t:RunPerfTests /clp:showcommandline
263 echo Test Run failed. Refer to the following:
264 echo Html report: %__TestRunHtmlLog%
269 REM =========================================================================================
271 REM === All tests complete!
273 REM =========================================================================================
275 echo %__MsgPrefix%Test run successful. Refer to the log files for details:
276 echo %__TestRunHtmlLog%
277 echo %__TestRunXmlLog%
280 REM =========================================================================================
282 REM === Helper routines
284 REM =========================================================================================
286 REM Compile the managed assemblies in Core_ROOT before running the tests
289 if defined __JitDisasm goto :jitdisasm
291 REM Skip mscorlib since it is already precompiled.
292 if /I "%3" == "mscorlib.dll" exit /b 0
293 if /I "%3" == "mscorlib.ni.dll" exit /b 0
295 "%1\crossgen.exe" /Platform_Assemblies_Paths "%CORE_ROOT%" "%2" >nul 2>nul
296 set /a __exitCode = %errorlevel%
297 if "%__exitCode%" == "-2146230517" (
298 echo %2 is not a managed assembly.
302 if %__exitCode% neq 0 (
303 echo Unable to precompile %2
307 echo Successfully precompiled %2
312 if /I "%3" == "mscorlib.ni.dll" exit /b 0
314 echo "%1\corerun" "%1\jit-dasm.dll" --crossgen %1\crossgen.exe --platform %CORE_ROOT% --output %__TestWorkingDir%\dasm "%2"
315 "%1\corerun" "%1\jit-dasm.dll" --crossgen %1\crossgen.exe --platform %CORE_ROOT% --output %__TestWorkingDir%\dasm "%2"
316 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 Successfully precompiled and generated dasm for %2
332 for %%F in (%CORE_ROOT%\*.dll) do call :PrecompileAssembly "%CORE_ROOT%" "%%F" %%~nF%%~xF
336 @REM Subroutine to invoke msbuild. All arguments are passed to msbuild. The first argument should be the
337 @REM .proj file to invoke.
339 @REM On entry, __BuildLogRootName must be set to a file name prefix for the generated log file.
340 @REM All the "standard" environment variables that aren't expected to change per invocation must also be set,
341 @REM like __msbuildCommonArgs.
343 @REM The build log files will be overwritten, not appended to.
345 echo %__MsgPrefix%Invoking msbuild
347 set "__BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
348 set "__BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
349 set "__BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
351 set __msbuildLogArgs=^
352 /fileloggerparameters:Verbosity=normal;LogFile="%__BuildLog%";Append ^
353 /fileloggerparameters1:WarningsOnly;LogFile="%__BuildWrn%" ^
354 /fileloggerparameters2:ErrorsOnly;LogFile="%__BuildErr%" ^
355 /consoleloggerparameters:Summary ^
358 set __msbuildArgs=%* %__msbuildCommonArgs% %__msbuildLogArgs%
360 @REM The next line will overwrite the existing log file, if any.
361 echo %_msbuildexe% %__msbuildArgs%
362 echo Invoking: %_msbuildexe% %__msbuildArgs% > "%__BuildLog%"
364 %_msbuildexe% %__msbuildArgs%
366 echo %__MsgPrefix%Error: msbuild failed. Refer to the log files for details:
377 if "%CORE_ROOT%" == "" (
378 echo %__MsgPrefix%Error: Ensure you have done a successful build of the Product and Run - runtest BuildArch BuildType {path to product binaries}.
382 :: Long GC tests take about 10 minutes per test on average, so
383 :: they often bump up against the default 10 minute timeout.
384 :: 20 minutes is more than enough time for a test to complete successfully.
385 if defined __LongGCTests (
386 echo Running Long GC tests, extending timeout to 20 minutes
387 set __TestTimeout=1200000
388 set RunningLongGCTests=1
391 :: GCSimulator tests can take up to an hour to complete. They are run twice a week in the
392 :: CI, so it's fine if they take a long time.
393 if defined __GCSimulatorTests (
394 echo Running GCSimulator tests, extending timeout to one hour
395 set __TestTimeout=3600000
396 set RunningGCSimulatorTests=1
399 if defined __JitDisasm (
400 if defined __DoCrossgen (
401 echo Running jit disasm on framework and test assemblies
403 if not defined __DoCrossgen (
404 echo Running jit disasm on test assemblies only
406 set RunningJitDisasm=1
409 set __BuildLogRootName=Tests_GenerateRuntimeLayout
410 call :msbuild "%__ProjectFilesDir%\runtest.proj" /p:GenerateRuntimeLayout=true
412 echo Test Dependency Resolution Failed
415 echo %__MsgPrefix%Created the runtime layout with all dependencies in %CORE_ROOT%
424 echo %0 BuildArch BuildType [TestEnv TEST_ENV_SCRIPT] [VSVersion] CORE_ROOT
427 echo./? -? /h -h /help -help: view this message.
428 echo BuildArch- Optional parameter - x64 or x86 ^(default: x64^).
429 echo BuildType- Optional parameter - Debug, Release, or Checked ^(default: Debug^).
430 echo TestEnv- Optional parameter - this will run a custom script to set custom test environment settings.
431 echo VSVersion- Optional parameter - VS2015 or VS2017 ^(default: VS2017^)
432 echo AgainstPackages - Optional parameter - this indicates that we are running tests that were built against packages
433 echo GenerateLayoutOnly - If specified will not run the tests and will only create the Runtime Dependency Layout
434 echo link "ILlink" - Runs the tests after linking via ILlink
435 echo RunCrossgenTests - Runs ReadytoRun tests
436 echo jitstress n - Runs the tests with COMPlus_JitStress=n
437 echo jitstressregs n - Runs the tests with COMPlus_JitStressRegs=n
438 echo jitminopts - Runs the tests with COMPlus_JITMinOpts=1
439 echo jitforcerelocs - Runs the tests with COMPlus_ForceRelocs=1
440 echo jitdisasm - Runs jit-dasm on the tests
441 echo gcstresslevel n - Runs the tests with COMPlus_GCStress=n
442 echo 0: None 1: GC on all allocs and 'easy' places
443 echo 2: GC on transitions to preemptive GC 4: GC on every allowable JITed instr
444 echo 8: GC on every allowable NGEN instr 16: GC only on a unique stack trace
445 echo CORE_ROOT The path to the runtime
449 echo Visual Studio 2015 or 2017 (Community is free) is a prerequisite to build this repository.
450 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites