Merge pull request #10238 from pgavlin/SeekUnrollLimit
[platform/upstream/coreclr.git] / tests / runtest.cmd
1 @if not defined _echo @echo off
2 setlocal EnableDelayedExpansion
3
4 :: Set the default arguments
5 set __BuildArch=x64
6 set __BuildType=Debug
7 set __BuildOS=Windows_NT
8 set __MSBuildBuildArch=x64
9
10 :: Default to highest Visual Studio version available
11 ::
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.
15 ::
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.
19 ::
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
24 :: can be found.
25 set __VSVersion=vs2017
26
27 if defined VS140COMNTOOLS set __VSVersion=vs2015
28 if defined VS150COMNTOOLS set __VSVersion=vs2017
29
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: 
33
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"
40
41 set __Sequential=
42 set __msbuildExtraArgs=
43 set __LongGCTests=
44 set __GCSimulatorTests=
45 set __AgainstPackages=
46 set __JitDisasm=
47 set __CollectDumps=
48
49 :Arg_Loop
50 if "%1" == "" goto ArgsDone
51
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
58
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)
62
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)
66
67 if /i "%1" == "vs2015"                (set __VSVersion=%1&shift&goto Arg_Loop)
68 if /i "%1" == "vs2017"                (set __VSVersion=%1&shift&goto Arg_Loop)
69
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)
85
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)
89
90 if /i not "%1" == "msbuildargs" goto SkipMsbuildArgs
91 :: All the rest of the args will be collected and passed directly to msbuild.
92 :CollectMsbuildArgs
93 shift
94 if "%1"=="" goto ArgsDone
95 set __msbuildExtraArgs=%__msbuildExtraArgs% %1
96 goto CollectMsbuildArgs
97 :SkipMsbuildArgs
98
99 set CORE_ROOT=%1
100 echo %__MsgPrefix%CORE_ROOT is initially set to: "%CORE_ROOT%"
101 shift 
102 :ArgsDone
103
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%"
107
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\
113
114 if not exist %__LogsDir% md %__LogsDir%
115
116 set _msbuildexe=
117 if /i "%__VSVersion%" == "vs2017" (
118   set "__VSToolsRoot=%VS150COMNTOOLS%"
119   set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build"
120
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"
125
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"
128 )
129
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
134
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
137
138 :: Set the environment for the  build- VS cmd prompt
139 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\VsDevCmd.bat"
140 call                                 "%__VSToolsRoot%\VsDevCmd.bat"
141
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.
144     exit /b 1
145 )
146
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
150 ::       assembly. 
151 set __msbuildCommonArgs=/nologo /nodeReuse:false %__msbuildExtraArgs% /p:Platform=%__MSBuildBuildArch%
152
153 if not defined __Sequential (
154     set __msbuildCommonArgs=%__msbuildCommonArgs% /maxcpucount
155 ) else (
156     set __msbuildCommonArgs=%__msbuildCommonArgs% /p:ParallelRun=false
157 )
158
159 if defined __AgainstPackages (
160     set __msbuildCommonArgs=%__msbuildCommonArgs% /p:BuildTestsAgainstPackages=true
161 )
162
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"
168
169 if defined CORE_ROOT goto SkipCoreRootSetup
170
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%"
175 md "%CORE_ROOT%"
176 xcopy /s "%__BinDir%" "%CORE_ROOT%"
177
178 :SkipCoreRootSetup
179
180
181 if defined __TestEnv (if not exist %__TestEnv% echo %__MsgPrefix%Error: Test Environment script %__TestEnv% not found && exit /b 1)
182
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
186
187
188 if "%__PerfTests%"=="true" goto RunPerfTests
189
190 call :ResolveDependecies
191
192 if not defined __DoCrossgen goto :SkipPrecompileFX
193 call :PrecompileFX
194
195 :SkipPrecompileFX
196
197 if  defined __GenerateLayoutOnly (
198     exit /b 0
199 )
200
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.
203     exit /b 1
204 )
205
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.
210     exit /b 1
211 )
212
213 if "%__CollectDumps%"=="true" (
214     :: Install dumpling
215     set "__DumplingHelperPath=%__ProjectDir%\..\Tools\DumplingHelper.py"
216     python "!__DumplingHelperPath!" install_dumpling
217
218     :: Create the crash dump folder if necessary
219     set "__CrashDumpFolder=%tmp%\CoreCLRTestCrashDumps"
220     if not exist "!__CrashDumpFolder!" (
221         mkdir "!__CrashDumpFolder!"
222     )
223
224     :: Grab the current time before execution begins. This will be used to determine which crash dumps
225     :: will be uploaded.
226     for /f "delims=" %%a in ('python !__DumplingHelperPath! get_timestamp') do @set __StartTime=%%a
227 )
228
229 echo %__MsgPrefix%CORE_ROOT that will be used is: %CORE_ROOT%
230 echo %__MsgPrefix%Starting the test run ...
231
232 del %CORE_ROOT%\mscorlib.ni.dll
233
234 set __BuildLogRootName=TestRunResults
235 call :msbuild "%__ProjectFilesDir%\runtest.proj" /p:Runtests=true /clp:showcommandline
236 set __errorlevel=%errorlevel%
237
238 if "%__CollectDumps%"=="true" (
239     python "%__DumplingHelperPath%" collect_dump %errorlevel% "%__CrashDumpFolder%" %__StartTime% "CoreCLR_Tests"
240 )
241
242 if %__errorlevel% GEQ 1 (
243     echo Test Run failed. Refer to the following:
244     echo     Html report: %__TestRunHtmlLog%
245     exit /b 1
246 )
247
248 if not defined __PerfTests goto :SkipRunPerfTests
249
250 :RunPerfTests 
251 echo %__MsgPrefix%CORE_ROOT that will be used is: %CORE_ROOT%  
252 echo %__MsgPrefix%Starting the test run ...  
253
254 set __BuildLogRootName=PerfTestRunResults  
255 echo Running perf tests  
256 call :msbuild "%__ProjectFilesDir%\runtest.proj" /t:RunPerfTests /clp:showcommandline  
257
258 if errorlevel 1 (  
259    echo Test Run failed. Refer to the following:  
260    echo     Html report: %__TestRunHtmlLog%  
261 )  
262
263 :SkipRunPerfTests
264
265 REM =========================================================================================
266 REM ===
267 REM === All tests complete!
268 REM ===
269 REM =========================================================================================
270
271 echo %__MsgPrefix%Test run successful. Refer to the log files for details:
272 echo     %__TestRunHtmlLog%
273 echo     %__TestRunXmlLog%
274 exit /b 0
275
276 REM =========================================================================================
277 REM ===
278 REM === Helper routines
279 REM ===
280 REM =========================================================================================
281
282 REM Compile the managed assemblies in Core_ROOT before running the tests
283 :PrecompileAssembly
284
285 if defined __JitDisasm goto :jitdisasm
286
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
290
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.
295     exit /b 0
296 )
297
298 if %__exitCode% neq 0 (
299     echo Unable to precompile %2
300     exit /b 0
301 )
302     
303 echo Successfully precompiled %2
304 exit /b 0
305
306 :jitdisasm
307
308 if /I "%3" == "mscorlib.ni.dll" exit /b 0
309
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%
313
314 if "%__exitCode%" == "-2146230517" (
315     echo %2 is not a managed assembly.
316     exit /b 0
317 )
318
319 if %__exitCode% neq 0 (
320     echo Unable to precompile %2
321     exit /b 0
322 )
323
324 echo Successfully precompiled and generated dasm for %2
325 exit /b 0
326
327 :PrecompileFX
328 for %%F in (%CORE_ROOT%\*.dll) do call :PrecompileAssembly "%CORE_ROOT%" "%%F" %%~nF%%~xF
329 exit /b 0
330
331 :msbuild
332 @REM Subroutine to invoke msbuild. All arguments are passed to msbuild. The first argument should be the
333 @REM .proj file to invoke.
334 @REM
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.
338 @REM
339 @REM The build log files will be overwritten, not appended to.
340
341 echo %__MsgPrefix%Invoking msbuild
342
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"
346
347 set __msbuildLogArgs=^
348 /fileloggerparameters:Verbosity=normal;LogFile="%__BuildLog%";Append ^
349 /fileloggerparameters1:WarningsOnly;LogFile="%__BuildWrn%" ^
350 /fileloggerparameters2:ErrorsOnly;LogFile="%__BuildErr%" ^
351 /consoleloggerparameters:Summary ^
352 /verbosity:minimal
353
354 set __msbuildArgs=%* %__msbuildCommonArgs% %__msbuildLogArgs%
355
356 @REM The next line will overwrite the existing log file, if any.
357 echo %_msbuildexe% %__msbuildArgs%
358 echo Invoking: %_msbuildexe% %__msbuildArgs% > "%__BuildLog%"
359
360 %_msbuildexe% %__msbuildArgs%
361 if errorlevel 1 (
362     echo %__MsgPrefix%Error: msbuild failed. Refer to the log files for details:
363     echo     %__BuildLog%
364     echo     %__BuildWrn%
365     echo     %__BuildErr%
366     exit /b 1
367 )
368
369 exit /b 0
370
371 :ResolveDependecies:
372
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}.
375     exit /b 1
376 )
377
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
385 )
386
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
393 )
394
395 if defined __JitDisasm (
396     if defined __DoCrossgen (
397         echo Running jit disasm on framework and test assemblies
398     )
399     if not defined __DoCrossgen (
400        echo Running jit disasm on test assemblies only
401     )
402     set RunningJitDisasm=1
403 )
404
405 set __BuildLogRootName=Tests_GenerateRuntimeLayout
406 call :msbuild "%__ProjectFilesDir%\runtest.proj" /p:GenerateRuntimeLayout=true 
407 if errorlevel 1 (
408     echo Test Dependency Resolution Failed
409     exit /b 1
410 )
411 echo %__MsgPrefix%Created the runtime layout with all dependencies in %CORE_ROOT%
412
413 exit /b 0
414
415
416
417 :Usage
418 echo.
419 echo Usage:
420 echo   %0 BuildArch BuildType [TestEnv TEST_ENV_SCRIPT] [VSVersion] CORE_ROOT
421 echo where:
422 echo.
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  
442 exit /b 1
443
444 :NoVS
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
447 exit /b 1