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
163 REM Prepare the Test Drop
164 REM Cleans any NI from the last run
165 powershell "Get-ChildItem -path %__TestWorkingDir% -Include '*.ni.*' -Recurse -Force | Remove-Item -force"
166 REM Cleans up any lock folder used for synchronization from last run
167 powershell "Get-ChildItem -path %__TestWorkingDir% -Include 'lock' -Recurse -Force | where {$_.Attributes -eq 'Directory'}| Remove-Item -force -Recurse"
169 if defined CORE_ROOT goto SkipCoreRootSetup
171 set "CORE_ROOT=%XunitTestBinBase%\Tests\Core_Root"
172 echo %__MsgPrefix%Using Default CORE_ROOT as %CORE_ROOT%
173 echo %__MsgPrefix%Copying Built binaries from %__BinDir% to %CORE_ROOT%
174 if exist "%CORE_ROOT%" rd /s /q "%CORE_ROOT%"
176 xcopy /s "%__BinDir%" "%CORE_ROOT%"
181 if defined __TestEnv (if not exist %__TestEnv% echo %__MsgPrefix%Error: Test Environment script %__TestEnv% not found && exit /b 1)
183 REM These log files are created automatically by the test run process. Q: what do they depend on being set?
184 set __TestRunHtmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.html
185 set __TestRunXmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.xml
188 if "%__PerfTests%"=="true" goto RunPerfTests
190 call :ResolveDependecies
192 if not defined __DoCrossgen goto :SkipPrecompileFX
197 if defined __GenerateLayoutOnly (
201 if not exist %CORE_ROOT%\coreclr.dll (
202 echo %__MsgPrefix%Error: Ensure you have done a successful build of the Product and %CORE_ROOT% contains runtime binaries.
206 ::Check if the test Binaries are built
207 if not exist %XunitTestBinBase% (
208 echo %__MsgPrefix%Error: Ensure the Test Binaries are built and are present at %XunitTestBinBase%.
209 echo %__MsgPrefix%Run "buildtest.cmd %__BuildArch% %__BuildType%" to build the tests first.
213 if "%__CollectDumps%"=="true" (
215 set "__DumplingHelperPath=%__ProjectDir%\..\Tools\DumplingHelper.py"
216 python "!__DumplingHelperPath!" install_dumpling
218 :: Create the crash dump folder if necessary
219 set "__CrashDumpFolder=%tmp%\CoreCLRTestCrashDumps"
220 if not exist "!__CrashDumpFolder!" (
221 mkdir "!__CrashDumpFolder!"
224 :: Grab the current time before execution begins. This will be used to determine which crash dumps
226 for /f "delims=" %%a in ('python !__DumplingHelperPath! get_timestamp') do @set __StartTime=%%a
229 echo %__MsgPrefix%CORE_ROOT that will be used is: %CORE_ROOT%
230 echo %__MsgPrefix%Starting the test run ...
232 del %CORE_ROOT%\mscorlib.ni.dll
234 set __BuildLogRootName=TestRunResults
235 call :msbuild "%__ProjectFilesDir%\runtest.proj" /p:Runtests=true /clp:showcommandline
236 set __errorlevel=%errorlevel%
238 if "%__CollectDumps%"=="true" (
239 python "%__DumplingHelperPath%" collect_dump %errorlevel% "%__CrashDumpFolder%" %__StartTime% "CoreCLR_Tests"
242 if %__errorlevel% GEQ 1 (
243 echo Test Run failed. Refer to the following:
244 echo Html report: %__TestRunHtmlLog%
248 if not defined __PerfTests goto :SkipRunPerfTests
251 echo %__MsgPrefix%CORE_ROOT that will be used is: %CORE_ROOT%
252 echo %__MsgPrefix%Starting the test run ...
254 set __BuildLogRootName=PerfTestRunResults
255 echo Running perf tests
256 call :msbuild "%__ProjectFilesDir%\runtest.proj" /t:RunPerfTests /clp:showcommandline
259 echo Test Run failed. Refer to the following:
260 echo Html report: %__TestRunHtmlLog%
265 REM =========================================================================================
267 REM === All tests complete!
269 REM =========================================================================================
271 echo %__MsgPrefix%Test run successful. Refer to the log files for details:
272 echo %__TestRunHtmlLog%
273 echo %__TestRunXmlLog%
276 REM =========================================================================================
278 REM === Helper routines
280 REM =========================================================================================
282 REM Compile the managed assemblies in Core_ROOT before running the tests
285 if defined __JitDisasm goto :jitdisasm
287 REM Skip mscorlib since it is already precompiled.
288 if /I "%3" == "mscorlib.dll" exit /b 0
289 if /I "%3" == "mscorlib.ni.dll" exit /b 0
291 "%1\crossgen.exe" /Platform_Assemblies_Paths "%CORE_ROOT%" "%2" >nul 2>nul
292 set /a __exitCode = %errorlevel%
293 if "%__exitCode%" == "-2146230517" (
294 echo %2 is not a managed assembly.
298 if %__exitCode% neq 0 (
299 echo Unable to precompile %2
303 echo Successfully precompiled %2
308 if /I "%3" == "mscorlib.ni.dll" exit /b 0
310 echo "%1\corerun" "%1\jit-dasm.dll" --crossgen %1\crossgen.exe --platform %CORE_ROOT% --output %__TestWorkingDir%\dasm "%2"
311 "%1\corerun" "%1\jit-dasm.dll" --crossgen %1\crossgen.exe --platform %CORE_ROOT% --output %__TestWorkingDir%\dasm "%2"
312 set /a __exitCode = %errorlevel%
314 if "%__exitCode%" == "-2146230517" (
315 echo %2 is not a managed assembly.
319 if %__exitCode% neq 0 (
320 echo Unable to precompile %2
324 echo Successfully precompiled and generated dasm for %2
328 for %%F in (%CORE_ROOT%\*.dll) do call :PrecompileAssembly "%CORE_ROOT%" "%%F" %%~nF%%~xF
332 @REM Subroutine to invoke msbuild. All arguments are passed to msbuild. The first argument should be the
333 @REM .proj file to invoke.
335 @REM On entry, __BuildLogRootName must be set to a file name prefix for the generated log file.
336 @REM All the "standard" environment variables that aren't expected to change per invocation must also be set,
337 @REM like __msbuildCommonArgs.
339 @REM The build log files will be overwritten, not appended to.
341 echo %__MsgPrefix%Invoking msbuild
343 set "__BuildLog=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
344 set "__BuildWrn=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
345 set "__BuildErr=%__LogsDir%\%__BuildLogRootName%_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
347 set __msbuildLogArgs=^
348 /fileloggerparameters:Verbosity=normal;LogFile="%__BuildLog%";Append ^
349 /fileloggerparameters1:WarningsOnly;LogFile="%__BuildWrn%" ^
350 /fileloggerparameters2:ErrorsOnly;LogFile="%__BuildErr%" ^
351 /consoleloggerparameters:Summary ^
354 set __msbuildArgs=%* %__msbuildCommonArgs% %__msbuildLogArgs%
356 @REM The next line will overwrite the existing log file, if any.
357 echo %_msbuildexe% %__msbuildArgs%
358 echo Invoking: %_msbuildexe% %__msbuildArgs% > "%__BuildLog%"
360 %_msbuildexe% %__msbuildArgs%
362 echo %__MsgPrefix%Error: msbuild failed. Refer to the log files for details:
373 if "%CORE_ROOT%" == "" (
374 echo %__MsgPrefix%Error: Ensure you have done a successful build of the Product and Run - runtest BuildArch BuildType {path to product binaries}.
378 :: Long GC tests take about 10 minutes per test on average, so
379 :: they often bump up against the default 10 minute timeout.
380 :: 20 minutes is more than enough time for a test to complete successfully.
381 if defined __LongGCTests (
382 echo Running Long GC tests, extending timeout to 20 minutes
383 set __TestTimeout=1200000
384 set RunningLongGCTests=1
387 :: GCSimulator tests can take up to an hour to complete. They are run twice a week in the
388 :: CI, so it's fine if they take a long time.
389 if defined __GCSimulatorTests (
390 echo Running GCSimulator tests, extending timeout to one hour
391 set __TestTimeout=3600000
392 set RunningGCSimulatorTests=1
395 if defined __JitDisasm (
396 if defined __DoCrossgen (
397 echo Running jit disasm on framework and test assemblies
399 if not defined __DoCrossgen (
400 echo Running jit disasm on test assemblies only
402 set RunningJitDisasm=1
405 set __BuildLogRootName=Tests_GenerateRuntimeLayout
406 call :msbuild "%__ProjectFilesDir%\runtest.proj" /p:GenerateRuntimeLayout=true
408 echo Test Dependency Resolution Failed
411 echo %__MsgPrefix%Created the runtime layout with all dependencies in %CORE_ROOT%
420 echo %0 BuildArch BuildType [TestEnv TEST_ENV_SCRIPT] [VSVersion] CORE_ROOT
423 echo./? -? /h -h /help -help: view this message.
424 echo BuildArch- Optional parameter - x64 or x86 ^(default: x64^).
425 echo BuildType- Optional parameter - Debug, Release, or Checked ^(default: Debug^).
426 echo TestEnv- Optional parameter - this will run a custom script to set custom test environment settings.
427 echo VSVersion- Optional parameter - VS2015 or VS2017 ^(default: VS2017^)
428 echo AgainstPackages - Optional parameter - this indicates that we are running tests that were built against packages
429 echo GenerateLayoutOnly - If specified will not run the tests and will only create the Runtime Dependency Layout
430 echo link "ILlink" - Runs the tests after linking via ILlink
431 echo RunCrossgenTests - Runs ReadytoRun tests
432 echo jitstress n - Runs the tests with COMPlus_JitStress=n
433 echo jitstressregs n - Runs the tests with COMPlus_JitStressRegs=n
434 echo jitminopts - Runs the tests with COMPlus_JITMinOpts=1
435 echo jitforcerelocs - Runs the tests with COMPlus_ForceRelocs=1
436 echo jitdisasm - Runs jit-dasm on the tests
437 echo gcstresslevel n - Runs the tests with COMPlus_GCStress=n
438 echo 0: None 1: GC on all allocs and 'easy' places
439 echo 2: GC on transitions to preemptive GC 4: GC on every allowable JITed instr
440 echo 8: GC on every allowable NGEN instr 16: GC only on a unique stack trace
441 echo CORE_ROOT The path to the runtime
445 echo Visual Studio 2015 or 2017 (Community is free) is a prerequisite to build this repository.
446 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites