Guard Crossgen Test Runtime logic with RunCrossGen Env
authorRama Krishnan Raghupathy <ramarag@microsoft.com>
Sat, 14 May 2016 02:41:46 +0000 (19:41 -0700)
committerRama Krishnan Raghupathy <ramarag@microsoft.com>
Wed, 18 May 2016 01:43:15 +0000 (18:43 -0700)
Adds Semaphores to prevent race conditions

netci.groovy
tests/runtest.cmd
tests/runtest.sh
tests/src/CLRTest.CrossGen.targets [new file with mode: 0644]
tests/src/CLRTest.Execute.Bash.targets
tests/src/CLRTest.Execute.Batch.targets
tests/src/CLRTest.Execute.targets

index 4f17aa0..0f6fba8 100755 (executable)
@@ -70,7 +70,6 @@ class Constants {
                ]
     // This is the basic set of scenarios
     def static basicScenarios = ['default', 'pri1', 'ilrt', 'r2r', 'pri1r2r', 'gcstress15_pri1r2r', 'longgc', 'coverage', 'gcsimulator']
-    // This is the set of configurations
     def static configurationList = ['Debug', 'Checked', 'Release']
     // This is the set of architectures
     def static architectureList = ['arm', 'arm64', 'x64', 'x86ryujit', 'x86lb']
@@ -1123,7 +1122,7 @@ combinedScenarios.each { scenario ->
                                         arch = 'x86'
                                     }
                                     
-                                    if (Constants.jitStressModeScenarios.containsKey(scenario) || scenario == 'default') {
+                                    if (Constants.jitStressModeScenarios.containsKey(scenario) || scenario == 'default' || scenario == 'r2r') {
                                         buildOpts = enableCorefxTesting ? 'skiptests' : ''
                                         buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${arch} ${buildOpts}"
                                     }
@@ -1134,7 +1133,7 @@ combinedScenarios.each { scenario ->
                                     // binaries are sent to a default directory whose name is about
                                     // 35 characters long.
 
-                                    else if (scenario == 'pri1') {
+                                    else if (scenario == 'pri1' || scenario == 'pri1r2r' || scenario == 'coverage') {
                                         buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${arch} Priority 1"
                                     }
                                     else if (scenario == 'ilrt') {
@@ -1142,18 +1141,10 @@ combinedScenarios.each { scenario ->
                                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} skiptests"
                                         buildCommands += "set __TestIntermediateDir=int&&tests\\buildtest.cmd ${lowerConfiguration} ${arch} ilasmroundtrip"
                                     }
-                                    else if (scenario == 'r2r') {
-                                        buildCommands += "build.cmd ${lowerConfiguration} ${arch} skiptests"
-                                        buildCommands += "set __TestIntermediateDir=int&&tests\\buildtest.cmd ${lowerConfiguration} ${arch} crossgen"
-                                    }
-                                    else if (scenario == 'pri1r2r') {
-                                        buildCommands += "build.cmd ${lowerConfiguration} ${arch} skiptests"
-                                        buildCommands += "set __TestIntermediateDir=int&&tests\\buildtest.cmd ${lowerConfiguration} ${arch} crossgen Priority 1"
-                                    }
                                     else if (scenario == 'gcstress15_pri1r2r') {
                                         //Build pri1 R2R tests with GC stress level 15
                                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} skiptests"
-                                        buildCommands += "set __TestIntermediateDir=int&&tests\\buildtest.cmd ${lowerConfiguration} ${arch} crossgen Priority 1 gcstresslevel 15"
+                                        buildCommands += "set __TestIntermediateDir=int&&tests\\buildtest.cmd ${lowerConfiguration} ${arch}  Priority 1 gcstresslevel 0xf"
                                     }
                                     else if (scenario == 'longgc') {
                                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} skiptests"
@@ -1163,10 +1154,6 @@ combinedScenarios.each { scenario ->
                                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} skiptests"
                                         buildCommands += "set __TestIntermediateDir=int&&tests\\buildtest.cmd ${lowerConfiguration} ${arch} gcsimulator"
                                     }
-                                    else if (scenario == 'coverage') {
-                                        buildCommands += "build.cmd ${lowerConfiguration} ${arch} skiptests"
-                                        buildCommands += "set __TestIntermediateDir=int&&tests\\buildtest.cmd ${lowerConfiguration} ${arch} crossgen Priority 1"
-                                    }
                                     else {
                                         println("Unknown scenario: ${scenario}")
                                         assert false
@@ -1178,8 +1165,10 @@ combinedScenarios.each { scenario ->
                                     if (!isBuildOnly) {
                                         //If this is a crossgen build, pass 'crossgen' to runtest.cmd
                                         def crossgenStr = ''
+                                        def runcrossgentestsStr = ''
                                         if (scenario == 'r2r' || scenario == 'pri1r2r' || scenario == 'gcstress15_pri1r2r'){
                                             crossgenStr = 'crossgen'
+                                            runcrossgentestsStr = 'runcrossgentests'
                                         }
                                         if (Constants.jitStressModeScenarios.containsKey(scenario)) {
                                             if (enableCorefxTesting) {
@@ -1201,7 +1190,7 @@ combinedScenarios.each { scenario ->
                                                 
                                                 // Run tests with the 
                                                 
-                                                buildCommands += "tests\\runtest.cmd ${lowerConfiguration} ${arch} TestEnv ${stepScriptLocation}"
+                                                buildCommands += "tests\\runtest.cmd ${lowerConfiguration} ${arch} ${crossgenStr} ${runcrossgentestsStr} TestEnv ${stepScriptLocation}"
                                             }                                            
                                         }
                                         else if (architecture == 'x64') {
@@ -1558,14 +1547,21 @@ combinedScenarios.each { scenario ->
                     // If this is a stress scenario, there isn't any difference in the build job
                     // so we didn't create a build only job for windows_nt specific to that stress mode.  Just copy
                     // from the default scenario
+                    def testBuildScenario = scenario
+                    if (testBuildScenario == 'coverage' || testBuildScenario == 'pri1r2r') {
+                        testBuildScenario = 'pri1'
+                    }
+                    else if ( testBuildScenario == 'r2r'){
+                        testBuildScenario = 'default'
+                    }
                     def inputWindowTestsBuildName = ''
-                    if (Constants.jitStressModeScenarios.containsKey(scenario)) {
+                    if (Constants.jitStressModeScenarios.containsKey(testBuildScenario)) {
                         inputWindowTestsBuildName = projectFolder + '/' + 
                             Utilities.getFullJobName(project, getJobName(configuration, architecture, 'windows_nt', 'default', true), isPR)
                     }
                     else {
                         inputWindowTestsBuildName = projectFolder + '/' + 
-                            Utilities.getFullJobName(project, getJobName(configuration, architecture, 'windows_nt', scenario, true), isPR)
+                            Utilities.getFullJobName(project, getJobName(configuration, architecture, 'windows_nt', testBuildScenario, true), isPR)
                     }
                     // Enable Server GC for Ubuntu PR builds
                     def serverGCString = ''
@@ -1584,8 +1580,10 @@ combinedScenarios.each { scenario ->
 
                     // pass --crossgen to runtest.sh for crossgen builds
                     def crossgenStr = ''
+                    def runcrossgentestsStr = ''
                     if (scenario == 'r2r' || scenario == 'pri1r2r' || scenario == 'gcstress15_pri1r2r'){
                         crossgenStr = '--crossgen'
+                        runcrossgentestsStr = '--runcrossgentests'
                     }
 
                     if (isLongGc(scenario)) {
@@ -1745,7 +1743,7 @@ combinedScenarios.each { scenario ->
                 --mscorlibDir=\"\${WORKSPACE}/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
                 --coreFxBinDir=\"\${WORKSPACE}/bin/${osGroup}.AnyCPU.Release;\${WORKSPACE}/bin/Unix.AnyCPU.Release;\${WORKSPACE}/bin/AnyOS.AnyCPU.Release\" \\
                 --coreFxNativeBinDir=\"\${WORKSPACE}/bin/${osGroup}.${architecture}.Release\" \\
-                ${testEnvOpt} ${serverGCString} ${crossgenStr} ${sequentialString} ${playlistString}""")
+                ${testEnvOpt} ${serverGCString} ${crossgenStr} ${runcrossgentestsStr} ${sequentialString} ${playlistString}""")
                             }
                         }
                     }
index e5f6262..e72a322 100644 (file)
@@ -59,6 +59,7 @@ if /i "%1" == "crossgen"            (set __DoCrossgen=1&shift&goto Arg_Loop)
 if /i "%1" == "longgctests"         (set __LongGCTests=1&shift&goto Arg_Loop)
 if /i "%1" == "GenerateLayoutOnly"  (set __GenerateLayoutOnly=1&set __SkipWrapperGeneration=true&shift&goto Arg_Loop)
 if /i "%1" == "PerfTests"           (set __PerfTests=true&set __SkipWrapperGeneration=true&shift&goto Arg_Loop)
+if /i "%1" == "runcrossgentests"    (set __RunCrossgenTests=1&shift&goto Arg_Loop)
 
 if /i not "%1" == "msbuildargs" goto SkipMsbuildArgs
 :: All the rest of the args will be collected and passed directly to msbuild.
@@ -133,6 +134,12 @@ if not defined __Sequential (
     set __msbuildCommonArgs=%__msbuildCommonArgs% /p:ParallelRun=false
 )
 
+REM Prepare the Test Drop
+REM Cleans any NI from the last run
+powershell "Get-ChildItem -path %__TestWorkingDir% -Include '*.ni.*' -Recurse -Force | Remove-Item -force"
+REM Cleans up any lock folder used for synchronization from last run
+powershell "Get-ChildItem -path E:\git\coreclr\bin\tests\Windows_NT.x64.Debug\baseservices\threading  -Include 'lock' -Recurse -Force |  where {$_.Attributes -eq 'Directory'}| Remove-Item -force -Recurse"
+
 if defined CORE_ROOT goto SkipCoreRootSetup
 
 set "CORE_ROOT=%XunitTestBinBase%\Tests\Core_Root"
@@ -152,6 +159,8 @@ REM These log files are created automatically by the test run process. Q: what d
 set __TestRunHtmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.html
 set __TestRunXmlLog=%__LogsDir%\TestRun_%__BuildOS%__%__BuildArch%__%__BuildType%.xml
 
+REM set ENV variables here:
+if defined __RunCrossgenTests ( set RunCrossGen=true)
 if "%__PerfTests%"=="true" goto RunPerfTests
 if "%__SkipWrapperGeneration%"=="true" goto SkipWrapperGeneration
 
@@ -336,6 +345,7 @@ echo Exclude-  Optional parameter - this will exclude individual tests from runn
 echo TestEnv- Optional parameter - this will run a custom script to set custom test environment settings.
 echo VSVersion- Optional parameter - VS2013 or VS2015 ^(default: VS2015^)
 echo GenerateLayoutOnly - If specified will not run the tests and will only create the Runtime Dependency Layout
+echo RunCrossgenTests   - Runs ReadytoRun tests
 echo CORE_ROOT The path to the runtime  
 exit /b 1
 
index f448530..a79aa7a 100755 (executable)
@@ -44,7 +44,8 @@ function print_usage {
     echo '  -v, --verbose                    : Show output from each test.'
     echo '  -h|--help                        : Show usage information.'
     echo '  --useServerGC                    : Enable server GC for this test run'
-    echo '  --test-en                        : Script to set environment variables for tests'
+    echo '  --test-env                       : Script to set environment variables for tests'
+    echo '  --runcrossgentests               : Runs the ready to run tests' 
     echo ''
     echo 'Runtime Code Coverage options:'
     echo '  --coreclr-coverage               : Optional argument to get coreclr code coverage reports'
@@ -523,12 +524,6 @@ function run_test {
     local scriptFileName=$(basename "$scriptFilePath")
     local outputFileName=$(basename "$outputFilePath")
 
-    # Convert DOS line endings to Unix if needed
-    perl -pi -e 's/\r\n|\n|\r/\n/g' "$scriptFileName"
-    
-    # Add executable file mode bit if needed
-    chmod +x "$scriptFileName"
-
     "./$scriptFileName" >"$outputFileName" 2>&1
     return $?
 }
@@ -612,6 +607,9 @@ function prep_test {
     # Add executable file mode bit if needed
     chmod +x "$scriptFilePath"
 
+    #remove any NI and Locks
+    rm -f *.ni.*
+    rm -rf lock
 }
 
 function start_test {
@@ -667,6 +665,8 @@ function run_tests_in_directory {
     local testDir=$1
 
     # Recursively search through directories for .sh files to prepare them.
+    # Note: This needs to occur before any test runs as some of the .sh files
+    # depend on other .sh files
     for scriptFilePath in $(find "$testDir" -type f -iname '*.sh' | sort)
     do
         prep_test "${scriptFilePath:2}"
@@ -783,6 +783,9 @@ do
         --disableEventLogging)
             ((disableEventLogging = 1))
             ;;
+        --runcrossgentests)
+            ((RunCrossGenTests = 1))
+            ;;
         --sequential)
             ((maxProcesses = 1))
             ;;
@@ -819,6 +822,9 @@ if ((disableEventLogging == 0)); then
     export COMPlus_EnableEventLog=1
 fi
 
+if ((RunCrossGenTests == 1)); then
+    export RunCrossGen=1
+fi
 export CORECLR_SERVER_GC="$serverGC"
 
 if [ -z "$testRootDir" ]; then
diff --git a/tests/src/CLRTest.CrossGen.targets b/tests/src/CLRTest.CrossGen.targets
new file mode 100644 (file)
index 0000000..c71df33
--- /dev/null
@@ -0,0 +1,101 @@
+<!--
+***********************************************************************************************
+CLRTest.Execute.targets
+
+WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
+          created a backup copy.  Incorrect changes to this file will make it
+          impossible to load or build your projects from the command-line or the IDE.
+
+This file contains the logic for providing Execution Script generation.
+
+WARNING:   When setting properties based on their current state (for example:
+           <Foo Condition="'$(Foo)'==''>Bar</Foo>).  Be very careful.  Another script generation
+           target might be trying to do the same thing.  It's better to avoid this by instead setting a new property.
+           
+           Additionally, be careful with itemgroups.  Include will propagate outside of the target too!
+
+***********************************************************************************************
+-->
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+
+  <PropertyGroup>
+    <BashScriptSnippetGen>$(BashScriptSnippetGen);GetCrossgenBashScript</BashScriptSnippetGen>
+    <BatchScriptSnippetGen>$(BatchScriptSnippetGen);GetCrossgenBatchScript</BatchScriptSnippetGen>
+  </PropertyGroup>
+  <ItemGroup>
+    <CLRTestBashEnvironmentVariable  Condition="'$(CrossGenTest)' == 'true'" Include = "export RunCrossGen=1"/>
+    <CLRTestBatchEnvironmentVariable Condition="'$(CrossGenTest)' == 'true'" Include = "set RunCrossGen=1"/>
+  </ItemGroup>
+
+  <!--
+    Target: GetCrossgenBatctchcript
+    This returns the portion of the execution script that generates the required lines to crossgen the test executable.
+  -->
+  <Target Name="GetCrossgenBashScript">
+    
+    <PropertyGroup>
+      <CrossgenBashScript Condition="'$(CLRTestKind)' == 'BuildAndRun'">
+        <![CDATA[
+# CrossGen Script
+if [ ! -z ${RunCrossGen+x} ]%3B then
+    export complus_zaprequire=2
+    export complus_zaprequireexcludelist=corerun
+    export complus_zaprequirelist=$(MSBuildProjectName)
+    if [ ! -f $(MSBuildProjectName).ni.exe ]%3B then
+        TakeLock
+        if [ ! -f $(MSBuildProjectName).ni.exe ]%3B then
+          echo $_DebuggerFullPath "$CORE_ROOT/crossgen" /Platform_Assemblies_Paths $CORE_ROOT%3A$PWD $(MSBuildProjectName).exe
+          $_DebuggerFullPath "$CORE_ROOT/crossgen" /Platform_Assemblies_Paths $CORE_ROOT%3A$PWD $(MSBuildProjectName).exe
+          __cgExitCode=$?
+          if [ $__cgExitCode -ne 0 ]
+          then
+            echo Crossgen failed with exitcode: $__cgExitCode
+            ReleaseLock
+            exit 1
+          fi
+        fi 
+        ReleaseLock       
+    fi        
+fi        
+        ]]>        
+      </CrossgenBashScript>
+
+      <BashCLRTestPreCommands>$(BashCLRTestPreCommands);$(CrossgenBashScript)</BashCLRTestPreCommands>
+    </PropertyGroup>
+  </Target>
+
+  <Target Name="GetCrossgenBatchScript">
+    
+    <PropertyGroup>
+      <CrossgenBatchScript Condition="'$(CLRTestKind)' == 'BuildAndRun'">
+        <![CDATA[
+
+REM CrossGen Script
+if defined RunCrossGen ( 
+    set complus_zaprequire=2
+    set complus_zaprequireexcludelist=corerun
+    set complus_zaprequirelist=$(MSBuildProjectName)
+    if not exist "$(MSBuildProjectName).ni.exe" (
+        call :TakeLock
+        if not exist "$(MSBuildProjectName).ni.exe" (
+            echo "%_DebuggerFullPath% %CORE_ROOT%\crossgen.exe" /Platform_Assemblies_Paths %CORE_ROOT%%3B%~dp0 $(MSBuildProjectName).exe
+            %_DebuggerFullPath% "%CORE_ROOT%\crossgen.exe" /Platform_Assemblies_Paths %CORE_ROOT%%3B%~dp0 $(MSBuildProjectName).exe
+            IF NOT !ERRORLEVEL!==0 (
+            ECHO Crossgen failed with exitcode - !ERRORLEVEL!
+            call :ReleaseLock
+            Exit /b 1
+            )
+          )
+          call :ReleaseLock
+    )
+) 
+        ]]>
+      </CrossgenBatchScript>
+
+      <CLRTestBatchPreCommands>$(CLRTestBatchPreCommands);$(CrossgenBatchScript)</CLRTestBatchPreCommands>
+    </PropertyGroup>
+  </Target>
+
+
+  
+</Project>
index 0779102..99becdd 100644 (file)
@@ -19,39 +19,9 @@ WARNING:   When setting properties based on their current state (for example:
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
   <ItemGroup>
-    <CLRTestBashEnvironmentVariable Condition="'$(CrossGen)' == 'true'" Include="export complus_zaprequire=2" />
-    <CLRTestBashEnvironmentVariable Condition="'$(CrossGen)' == 'true'" Include="export complus_zaprequireexcludelist=corerun" />
     <CLRTestBashEnvironmentVariable Condition="'$(GCStressLevel)' != '' and '$(GCStressLevel)' != '0'" Include="export complus_gcstress=$(GCStressLevel)" />
   </ItemGroup>
 
-    <!--
-    Target: GetBatchCrossgenScript
-    This returns the portion of the execution script that generates the required lines to crossgen the test executable.
-  -->
-  <Target
-    Condition="'$(CrossGen)'=='true'"
-    Name="GetCrossgenBashScript"
-    Returns="$(CrossgenBashScript)">  
-    
-    <PropertyGroup>
-      <!-- CrossGen will create output if it needs to crossgen. Otherwise there will be silence. -->
-      <CrossgenBashScript Condition="'$(CLRTestKind)' == 'BuildAndRun'">
-        <![CDATA[
-if [ ! -f $(MSBuildProjectName).ni.exe ]; then
-  echo "$CORE_ROOT/crossgen" /Platform_Assemblies_Paths $CORE_ROOT%3A$PWD $(MSBuildProjectName).exe
-  "$CORE_ROOT/crossgen" /Platform_Assemblies_Paths $CORE_ROOT%3A$PWD $(MSBuildProjectName).exe
-  __cgExitCode=$?
-  if [ $__cgExitCode -ne 0 ]
-  then
-    echo Crossgen failed with exitcode: $__cgExitCode
-    exit 1
-  fi
-fi        
-        ]]>        
-      </CrossgenBashScript>
-    </PropertyGroup>
-  </Target>
-
   <Target
     Name="GetIlasmRoundTripBashScript"
     Returns="$(IlasmRoundTripBashScript)">
@@ -133,7 +103,7 @@ fi
   <Target Name="GenerateBashExecutionScript"
     Inputs="$(MSBuildProjectFullPath)"
     Outputs="$(OutputPath)\$(MSBuildProjectName).sh"
-    DependsOnTargets="FetchExternalPropertiesForXpalt;GetCrossgenBashScript;GetIlasmRoundTripBashScript">
+    DependsOnTargets="FetchExternalPropertiesForXpalt;$(BashScriptSnippetGen);GetIlasmRoundTripBashScript">
 
     <Message Text="Project depends on $(_CLRTestToRunFileFullPath)." Condition="'$(_CLRTestNeedsProjectToRun)' == 'True'" />
 
@@ -212,11 +182,6 @@ fi
       </BashCLRTestExecutionScriptArgument>
     </ItemGroup>
 
-
-    <ItemGroup>
-      <CLRTestBashEnvironmentVariable Condition="'$(CrossGen)' == 'true' AND '$(_CLRTestNeedsProjectToRun)' == 'true'" Include="complus_zaprequirelist=$(_CLRTestToRunFileFullPath)" />
-      <CLRTestBashEnvironmentVariable Condition="'$(CrossGen)' == 'true' AND '$(_CLRTestNeedsProjectToRun)' == 'false'" Include="complus_zaprequirelist=$(MSBuildProjectName)" />
-    </ItemGroup>
     
     <PropertyGroup>
       <_CLRTestRunFile Condition="'$(CLRTestIsHosted)'=='true'">"$CORE_ROOT/corerun"</_CLRTestRunFile>
@@ -312,7 +277,29 @@ $(BashCLRTestArgPrep)
       <!-- NOTE! semicolons must be escaped with %3B boooo -->
       <_CLRTestExecutionScriptText>
         <![CDATA[
+TakeLock()
+{
+    echo "in takeLock"
+    if mkdir $LockFile%3B then
+        return 2
+    else
+        sleep 10
+        TakeLock
+    fi
+    echo "exiting takelock"
+}
+
+ReleaseLock()
+{
+    echo "in ReleaseLock"
+    if [ -d "$LockFile" ]%3B then
+        rm -rf "$LockFile"
+        return 3
+    fi
+}
 cd "$%28dirname "$0")"
+LockFile="lock"
+
 
 # The __TestEnv variable may be used to specify something to run before the test.
 $__TestEnv
@@ -324,8 +311,6 @@ $(BashCLRTestExitCodePrep)
 # Long-running GC test checks
 $(BashCLRTestGCSimulatorSkipCondition)
 $(BashCLRTestGCLongTestSkipCondition)
-# CrossGen Script (when /p:CrossGen=true)
-$(CrossgenBashScript)
 # IlasmRoundTrip Script
 $(IlasmRoundTripBashScript)
 # PreCommands
index a1688b3..284a2ee 100644 (file)
@@ -19,35 +19,8 @@ WARNING:   When setting properties based on their current state (for example:
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
   <ItemGroup>
-    <CLRTestBatchEnvironmentVariable Condition="'$(CrossGen)' == 'true'" Include="set complus_zaprequire=2" />
-    <CLRTestBatchEnvironmentVariable Condition="'$(CrossGen)' == 'true'" Include="set complus_zaprequireexcludelist=corerun" />
     <CLRTestBatchEnvironmentVariable Condition="'$(GCStressLevel)' != '' and '$(GCStressLevel)' != '0'" Include="set complus_gcstress=$(GCStressLevel)" />
   </ItemGroup>
-  <!--
-    Target: GetBatchCrossgenScript
-    This returns the portion of the execution script that generates the required lines to crossgen the test executable.
-  -->
-  <Target
-    Condition="'$(CrossGen)'=='true'"
-    Name="GetCrossgenBatchScript"
-    Returns="$(CrossgenBatchScript)">
-    
-    <PropertyGroup>
-<!-- CrossGen will create output if it needs to crossgen. Otherwise there will be silence. -->
-      <CrossgenBatchScript Condition="'$(CLRTestKind)' == 'BuildAndRun'">
-        <![CDATA[
-if not exist "$(MSBuildProjectName).ni.exe" (
-    echo "%CORE_ROOT%\crossgen.exe" /Platform_Assemblies_Paths %CORE_ROOT%%3B%~dp0 $(MSBuildProjectName).exe
-    "%CORE_ROOT%\crossgen.exe" /Platform_Assemblies_Paths %CORE_ROOT%%3B%~dp0 $(MSBuildProjectName).exe
-    IF NOT "!ERRORLEVEL!"=="0" (
-    ECHO Crossgen failed with exitcode - !ERRORLEVEL!
-    Exit /b 1
-    )
-  )      
-        ]]>
-      </CrossgenBatchScript>
-    </PropertyGroup>
-  </Target>
 
   <Target
     Name="GetIlasmRoundTripBatchScript"
@@ -126,7 +99,7 @@ IF NOT "!ERRORLEVEL!"=="0" (
   <Target Name="GenerateBatchExecutionScript"
     Inputs="$(MSBuildProjectFullPath)"
     Outputs="$(OutputPath)\$(MSBuildProjectName).cmd"
-    DependsOnTargets="FetchExternalProperties;GetCrossgenBatchScript;GetIlasmRoundTripBatchScript">
+    DependsOnTargets="FetchExternalProperties;$(BatchScriptSnippetGen);GetIlasmRoundTripBatchScript">
 
     <Message Text="Project depends on $(_CLRTestToRunFileFullPath)." Condition="'$(_CLRTestNeedsProjectToRun)' == 'True'" />
 
@@ -185,6 +158,19 @@ IF NOT "%CLRTestExitCode%"=="%CLRTestExpectedExitCode%" (
   ECHO PASSED
   Exit /b 0
 )
+
+:TakeLock
+md %lockFolder%
+IF NOT "!ERRORLEVEL!"=="0" (
+timeout /t 10 /nobreak
+goto :TakeLock
+)
+Exit /b 2
+
+
+:ReleaseLock
+if exist %lockFolder% rd /s /q %lockFolder%
+Exit /b 0
       ]]></BatchCLRTestExitCodeCheck>
     </PropertyGroup>
   
@@ -228,11 +214,6 @@ IF NOT "%CLRTestExitCode%"=="%CLRTestExpectedExitCode%" (
         <Description>Set CORE_ROOT to the specified value before running the test.</Description>
       </BatchCLRTestExecutionScriptArgument>
     </ItemGroup>
-      
-    <ItemGroup>
-      <CLRTestBatchEnvironmentVariable Condition="'$(CrossGen)' == 'true' AND '$(_CLRTestNeedsProjectToRun)' == 'true'" Include="set complus_zaprequirelist=$([MSBuild]::MakeRelative($(OutputPath), $(_CLRTestToRunFileFullPath)))" />
-      <CLRTestBatchEnvironmentVariable Condition="'$(CrossGen)' == 'true' AND '$(_CLRTestNeedsProjectToRun)' == 'false'" Include="set complus_zaprequirelist=$(MSBuildProjectName)" />
-    </ItemGroup>
 
     <PropertyGroup> 
       <_CLRTestRunFile Condition="'$(CLRTestIsHosted)'=='true'">"%CORE_ROOT%\corerun.exe"</_CLRTestRunFile>
@@ -344,7 +325,9 @@ $(BatchCLRTestArgPrep)
   <![CDATA[
 @ECHO OFF
 setlocal ENABLEDELAYEDEXPANSION
+set "lockFolder=%~dp0\lock"
 pushd %~dp0
+
 $(BatchCLRTestArgPrep)
 $(BatchCLRTestExitCodePrep)
 
@@ -356,9 +339,6 @@ $(BatchEnvironmentVariables)
 
 $(BatchCLRTestEnvironmentCompatibilityCheck)
 
-REM CrossGen Script (when /p:CrossGen=true)
-$(CrossgenBatchScript)
-
 REM IlasmRoundTrip Script
 $(IlasmRoundTripBatchScript)
 
index 71ae0f2..6c34df6 100644 (file)
@@ -99,7 +99,13 @@ This file contains the logic for providing Execution Script generation.
     <ExecutionScriptKind Include="Batch" />
     <ExecutionScriptKind Include="Bash" />
   </ItemGroup>
-  
+
+  <PropertyGroup>
+    <BashScriptSnippetGen></BashScriptSnippetGen>
+    <BatchScriptSnippetGen></BatchScriptSnippetGen>
+  </PropertyGroup>
+  <Import Project="CLRTest.CrossGen.targets" />
   <Import Project="CLRTest.Execute.*.targets" />
   
   <Target Name="GenerateExecutionScriptsInternal"