280bb46380f4b08b4d3cc5a1acd138e8eb1e8fcc
[platform/upstream/coreclr.git] / tests / runtest.cmd
1 @echo off
2 setlocal EnableDelayedExpansion
3 set __ProjectFilesDir=%~dp0
4
5 :: Default to VS2013
6 set __VSVersion=VS2013
7 set __VSProductVersion=120
8
9 :: Default __Exclude to issues.targets
10 set __Exclude=%~dp0\issues.targets
11
12 :Arg_Loop
13 if "%1" == "" goto ArgsDone
14 if /i "%1" == "x64"    (set __BuildArch=x64&set __MSBuildBuildArch=x64&shift&goto Arg_Loop)
15
16 if /i "%1" == "debug"    (set __BuildType=debug&shift&goto Arg_Loop)
17 if /i "%1" == "release"   (set __BuildType=release&shift&goto Arg_Loop)
18 if /i "%1" == "SkipWrapperGeneration" (set __SkipWrapperGeneration=true&shift&goto Arg_Loop)
19 if /i "%1" == "Exclude" (set __Exclude=%2&shift&shift&goto Arg_Loop)
20 if /i "%1" == "TestEnv" (set __TestEnv=%2&shift&shift&goto Arg_Loop)
21
22 if /i "%1" == "vs2013"   (set __VSVersion=%1&set __VSProductVersion=120&shift&goto Arg_Loop)
23 if /i "%1" == "vs2015"   (set __VSVersion=%1&set __VSProductVersion=140&shift&goto Arg_Loop)
24
25 if /i "%1" == "/?"      (goto Usage)
26
27 set Core_Root=%1
28 shift 
29 :ArgsDone
30 :: Check prerequisites
31
32 :: Check presence of VS
33 if defined VS%__VSProductVersion%COMNTOOLS goto CheckMSbuild
34 echo InVisual Studio 2013+ (Community is free) is a pre-requisite to build this repository.
35 exit /b 1
36
37 :CheckMSBuild
38 if /i "%__VSVersion%" =="vs2015" goto MSBuild14
39 set _msbuildexe="%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe"
40 if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles%\MSBuild\12.0\Bin\MSBuild.exe"
41 if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
42 goto :CheckMSBuild14
43 :MSBuild14
44 set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
45 set UseRoslynCompiler=true
46 :CheckMSBuild14
47 if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe"
48 if not exist %_msbuildexe% echo Error: Could not find MSBuild.exe.  Please see https://github.com/dotnet/corefx/blob/master/Documentation/developer-guide.md for build instructions. && exit /b 1
49
50 :: Set the environment for the  build- Vs cmd prompt
51 call "!VS%__VSProductVersion%COMNTOOLS!\VsDevCmd.bat"
52
53 if not defined VSINSTALLDIR echo Error: runtest.cmd should be run from a Visual Studio Command Prompt.  Please see https://github.com/dotnet/coreclr/blob/master/Documentation/developer-guide.md for build instructions. && exit /b 1
54
55
56 if not defined __BuildArch set __BuildArch=x64
57 if not defined __BuildType set __BuildType=debug
58 if not defined __BuildOS set __BuildOS=Windows_NT
59 if not defined __BinDir    set  __BinDir=%__ProjectFilesDir%..\bin\Product\%__BuildOS%.%__BuildArch%.%__BuildType%
60 if not defined __TestWorkingDir set __TestWorkingDir=%__ProjectFilesDir%..\bin\tests\%__BuildOS%.%__BuildArch%.%__BuildType%
61 if not defined __LogsDir        set  __LogsDir=%__ProjectFilesDir%..\bin\Logs
62
63 :: Default global test environmet variables
64 if not defined XunitTestBinBase       set  XunitTestBinBase=%__TestWorkingDir%\
65 if not defined XunitTestReportDirBase set  XunitTestReportDirBase=%XunitTestBinBase%\Reports\
66 if defined Core_Root goto  :CheckTestEnv 
67
68 set noCore_RootSet=true
69 set Core_Root=%__BinDir%
70
71 :CheckTestEnv 
72 ::Check if the test Binaries are built
73 if not exist %XunitTestBinBase% echo Error: Ensure the Test Binaries are built and are present at %XunitTestBinBase%, Run - buildtest.cmd %__BuildArch% %__BuildType% to build the tests first. && exit /b 1
74 if "%Core_Root%" == ""             echo Error: Ensure you have done a successful build of the Product and Run - runtest BuildArch BuildType {path to product binaries}. && exit /b 1
75 if not exist %Core_Root%\coreclr.dll echo Error: Ensure you have done a successful build of the Product and %Core_Root% contains runtime binaries. && exit /b 1
76 if not "%__Exclude%"==""           (if not exist %__Exclude% echo Error: Exclusion .targets file not found && exit /b 1) 
77 if not "%__TestEnv%"==""           (if not exist %__TestEnv% echo Error: Test Environment script not found && exit /b 1) 
78 if not exist %__LogsDir%           md  %__LogsDir%
79
80 :SkipDefaultCoreRootSetup
81 set __XunitWrapperBuildLog=%__LogsDir%\Tests_XunitWrapper_%__BuildOS%__%__BuildArch%__%__BuildType%.log
82 set __TestRunBuildLog=%__LogsDir%\TestRunResults_%__BuildOS%__%__BuildArch%__%__BuildType%.log
83 set __TestRunHtmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.html
84 set __TestRunXmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.xml
85
86 echo "Core_Root that will be used is : %Core_Root%"
87 echo "Starting The Test Run .. "
88 if  "%__SkipWrapperGeneration%"=="true" goto :preptests
89
90 :: Log build command line
91 set _buildprefix=echo
92 set _buildpostfix=^> "%__TestRunBuildLog%"
93 set _buildappend=^>
94 call :PerformXunitWrapperBuild 
95
96 :: Build
97 set _buildprefix=
98 set _buildpostfix=
99 set _buildappend=
100 call :PerformXunitWrapperBuild 
101 IF ERRORLEVEL 1 (
102     echo XunitWrapperBuild build failed. Refer %__XunitWrapperBuildLog% for details.
103     exit /b 1
104 )
105
106 :: Log build command line
107 set _buildprefix=echo
108 set _buildpostfix=^> "%__TestRunBuildLog%"
109 set _buildappend=^>
110 call :runtests
111
112 :: Build
113 set _buildprefix=
114 set _buildpostfix=
115 set _buildappend=
116 if not "%noCore_RootSet%"=="true" goto :runtests 
117 set Core_Root=%XunitTestBinBase%\Tests\Core_Root
118 echo "Using Default Core_Root as %Core_Root% " 
119 echo "Copying Built binaries from  %__BinDir% to %Core_Root%"
120 if exist %Core_Root% rd /s /q %Core_Root%
121 md %Core_Root%
122 xcopy /s %__BinDir% %Core_Root%
123 call :runtests 
124 if ERRORLEVEL 1 (
125     echo Test Run failed. Refer to the following"
126     echo Msbuild log: %__TestRunBuildLog%
127     echo Html report: %__TestRunHtmlLog%
128     exit /b 1
129 )
130
131 :runtests
132 %_buildprefix% %_msbuildexe% "%__ProjectFilesDir%runtest.proj" /p:NoBuild=true /nologo /maxcpucount /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=normal;LogFile="%__TestRunBuildLog%";Append %1 %_buildpostfix% /clp:showcommandline
133 exit /b %ERRORLEVEL%
134
135 :PerformXunitWrapperBuild
136
137 %_buildprefix% %_msbuildexe% "%__ProjectFilesDir%runtest.proj" /p:NoRun=true /nologo /maxcpucount /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=normal;LogFile="%__XunitWrapperBuildLog%";Append %1  %_buildappend%%_buildpostfix%
138 exit /b %ERRORLEVEL%
139
140 :Usage
141 echo.
142 echo Usage:
143 echo %0 BuildArch BuildType [SkipWrapperGeneration] [Exclude EXCLUSION_TARGETS] [TestEnv TEST_ENV_SCRIPT] [vsversion] CORE_ROOT   where:
144 echo.
145 echo BuildArch is x64
146 echo BuildType can be: Debug, Release
147 echo SkipWrapperGeneration- Optional parameter - this will run the same set of tests as the last time it was run
148 echo Exclude- Optional parameter - this will exclude individual tests from running, specified by ExcludeList ItemGroup in an .targets file.
149 echo TestEnv- Optional parameter - this will run a custom script to set custom test envirommnent settings.
150 echo VSVersion- optional argument to use VS2013 or VS2015  (default VS2013)
151 echo CORE_ROOT The path to the runtime  
152 exit /b 1
153