Skip to content

Commit

Permalink
Cleaner way of specifying environment variables for tests (#76458)
Browse files Browse the repository at this point in the history
Existing ways of specifying environment variables:
- [3 times] CLRTestBashEnvironmentVariable is a list of `export var=value` strings
- [2 times] CLRTestBatchEnvironmentVariable is a list of `set var=value` strings
- [~100 times] BashCLRTestPreCommands and CLRTestBatchPreCommands are set to include `export`/`set` strings for the same variables

This changes CLRTestBashEnvironmentVariable and CLRTestBatchEnvironmentVariable to be a list of Identity/Value pairs and adds a new list CLRTestEnvironmentVariable in the same format.  These are automatically expanded to the necessary `export`/`set` strings as appropriate.

A few details of note:
- "Real" changes are in CLRTest.Execute.Bash/Batch.targets.  This moves the environment variables section of the generated cmd/sh files down to the precommands area.  This is only a change for the 5 existing uses, which look ok.
- If a test has a more complicated precommands list, it may not be appropriate to extract the variables.  For example, src\tests\readytorun\tests\mainv1.csproj includes them in setlocal/endlocal because they are for crossgen2 in the precommands, not the test itself.  This change only updates otherwise blank precommands lists.
  • Loading branch information
markples authored Oct 13, 2022
1 parent c6235cd commit e514819
Show file tree
Hide file tree
Showing 114 changed files with 366 additions and 1,323 deletions.
7 changes: 4 additions & 3 deletions src/tests/Common/CLRTest.Execute.Bash.targets
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ $(CLRTestBashPostCommands)
</PropertyGroup>
<PropertyGroup>
<BashEnvironmentVariables>
@(CLRTestBashEnvironmentVariable -> '%(Identity)', '%0a')
@(CLRTestBashEnvironmentVariable -> 'export %(Identity)=%(Value)', '%0a')
@(CLRTestEnvironmentVariable -> 'export %(Identity)=%(Value)', '%0a')
</BashEnvironmentVariables>
</PropertyGroup>

Expand Down Expand Up @@ -537,15 +538,15 @@ if [ -n "$__TestEnv" ]%3B then
source $__TestEnv
fi
$(BashEnvironmentVariables)
$(BashCLRTestEnvironmentCompatibilityCheck)
$(BashCLRTestArgPrep)
$(BashCLRTestExitCodePrep)
$(IlasmRoundTripBashScript)
$(SuperPMICollectionBashScript)
# Allow precommands to override the ExePath
# Allow test environment variables or precommands to override the ExePath
ExePath=$(InputAssemblyName)
export TestExclusionListPath=$CORE_ROOT/TestExclusionList.txt
$(BashEnvironmentVariables)
# PreCommands
$(BashCLRTestPreCommands)
# Launch
Expand Down
11 changes: 6 additions & 5 deletions src/tests/Common/CLRTest.Execute.Batch.targets
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ $(CLRTestBatchPostCommands)
</PropertyGroup>
<PropertyGroup>
<BatchEnvironmentVariables>
@(CLRTestBatchEnvironmentVariable -> '%(Identity)', '%0d%0a')
@(CLRTestBatchEnvironmentVariable -> 'set %(Identity)=%(Value)', '%0d%0a')
@(CLRTestEnvironmentVariable -> 'set %(Identity)=%(Value)', '%0d%0a')
</BatchEnvironmentVariables>
</PropertyGroup>

Expand Down Expand Up @@ -434,19 +435,19 @@ IF NOT "%__TestEnv%"=="" (
)
)
REM Environment Variables
$(BatchEnvironmentVariables)
$(BatchCLRTestEnvironmentCompatibilityCheck)
$(IlasmRoundTripBatchScript)
$(SuperPMICollectionBatchScript)
REM Allow precommands to override the ExePath
REM Allow test environment variables or precommands to override the ExePath
set ExePath=$(InputAssemblyName)
set TestExclusionListPath=%CORE_ROOT%\TestExclusionList.txt
REM Environment Variables
$(BatchEnvironmentVariables)
REM Precommands
$(CLRTestBatchPreCommands)
REM Launch
Expand Down
4 changes: 2 additions & 2 deletions src/tests/Common/CLRTest.MockHosting.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ This file contains the logic for correctly hooking up a mock hostpolicy to a tes
<ItemGroup>
<CMakeProjectReference Include="$(MSBuildThisFileDirectory)hostpolicymock/CMakeLists.txt" />
<!-- %28 decodes to '('. It's needed to keep MSBuild from trying to parse $(pwd) as an MSBuild property -->
<CLRTestBashEnvironmentVariable Include="export MOCK_HOSTPOLICY=$%28pwd)/libhostpolicy" />
<CLRTestBashEnvironmentVariable Include="MOCK_HOSTPOLICY" Value="$%28pwd)/libhostpolicy" />
<!-- %25 decodes to '%'. It's needed to keep %cd itself from being decoded since we want '%cd%' directly in the script. -->
<CLRTestBatchEnvironmentVariable Include="set MOCK_HOSTPOLICY=%25cd%\hostpolicy.dll" />
<CLRTestBatchEnvironmentVariable Include="MOCK_HOSTPOLICY" Value="%25cd%\hostpolicy.dll" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Compile Include="DllImportPathTest.cs" />
</ItemGroup>
<ItemGroup>
<CLRTestBashEnvironmentVariable Include="export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$%28pwd)/Subdirectory" />
<CLRTestBashEnvironmentVariable Include="LD_LIBRARY_PATH" Value="$LD_LIBRARY_PATH:$%28pwd)/Subdirectory" />
</ItemGroup>
<PropertyGroup>
<PathEnvSetupCommands><![CDATA[
Expand Down
15 changes: 3 additions & 12 deletions src/tests/JIT/Directed/IL/Tailcall/ExplicitTailCallNoSO.ilproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,8 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="ExplicitTailCallNoSO.il" />

<CLRTestEnvironmentVariable Include="COMPlus_TC_QuickJit" Value="1" />
<CLRTestEnvironmentVariable Include="COMPlus_TC_QuickJitForLoops" Value="1" />
</ItemGroup>
<PropertyGroup>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set COMPlus_TC_QuickJit=1
set COMPlus_TC_QuickJitForLoops=1
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export COMPlus_TC_QuickJit=1
export COMPlus_TC_QuickJitForLoops=1
]]></BashCLRTestPreCommands>
</PropertyGroup>
</Project>
12 changes: 2 additions & 10 deletions src/tests/JIT/Directed/LoopAlignment/LoopsToProcess.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,10 @@
</PropertyGroup>
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<PropertyGroup>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set COMPlus_JitAggressiveInlining=1
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export COMPlus_JitAggressiveInlining=1
]]></BashCLRTestPreCommands>
</PropertyGroup>
<ItemGroup>
<Compile Include="LoopsToProcess.cs" />

<CLRTestEnvironmentVariable Include="COMPlus_JitAggressiveInlining" Value="1" />
</ItemGroup>
</Project>
15 changes: 3 additions & 12 deletions src/tests/JIT/Directed/coverage/flowgraph/gcpoll.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,11 @@
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<PropertyGroup>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set COMPlus_JitDoAssertionProp=0
set COMPlus_JitNoCSE=1
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export COMPlus_JitDoAssertionProp=0
export COMPlus_JitNoCSE=1
]]></BashCLRTestPreCommands>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />

<CLRTestEnvironmentVariable Include="COMPlus_JitDoAssertionProp" Value="0" />
<CLRTestEnvironmentVariable Include="COMPlus_JitNoCSE" Value="1" />
</ItemGroup>
</Project>
12 changes: 2 additions & 10 deletions src/tests/JIT/Directed/tailcall/more_tailcalls.ilproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).il" />

<CLRTestEnvironmentVariable Include="COMPlus_JitStressModeNamesNot" Value="STRESS_UNSAFE_BUFFER_CHECKS" />
</ItemGroup>
<PropertyGroup>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set COMPlus_JitStressModeNamesNot=STRESS_UNSAFE_BUFFER_CHECKS
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export COMPlus_JitStressModeNamesNot=STRESS_UNSAFE_BUFFER_CHECKS
]]></BashCLRTestPreCommands>
</PropertyGroup>
</Project>
12 changes: 2 additions & 10 deletions src/tests/JIT/Directed/tailcall/tailcall.ilproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).il" />

<CLRTestEnvironmentVariable Include="COMPlus_JitStressModeNamesNot" Value="STRESS_UNSAFE_BUFFER_CHECKS" />
</ItemGroup>
<PropertyGroup>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set COMPlus_JitStressModeNamesNot=STRESS_UNSAFE_BUFFER_CHECKS
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export COMPlus_JitStressModeNamesNot=STRESS_UNSAFE_BUFFER_CHECKS
]]></BashCLRTestPreCommands>
</PropertyGroup>
</Project>
12 changes: 2 additions & 10 deletions src/tests/JIT/Methodical/doublearray/dblarray4_cs_d.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="dblarray4.cs" />

<CLRTestEnvironmentVariable Include="COMPlus_DoubleArrayToLargeObjectHeap" Value="0x64" />
</ItemGroup>
<PropertyGroup>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set COMPlus_DoubleArrayToLargeObjectHeap=0x64
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export COMPlus_DoubleArrayToLargeObjectHeap=0x64
]]></BashCLRTestPreCommands>
</PropertyGroup>
</Project>
12 changes: 2 additions & 10 deletions src/tests/JIT/Methodical/doublearray/dblarray4_cs_do.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="dblarray4.cs" />

<CLRTestEnvironmentVariable Include="COMPlus_DoubleArrayToLargeObjectHeap" Value="0x64" />
</ItemGroup>
<PropertyGroup>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set COMPlus_DoubleArrayToLargeObjectHeap=0x64
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export COMPlus_DoubleArrayToLargeObjectHeap=0x64
]]></BashCLRTestPreCommands>
</PropertyGroup>
</Project>
12 changes: 2 additions & 10 deletions src/tests/JIT/Methodical/doublearray/dblarray4_cs_r.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="dblarray4.cs" />

<CLRTestEnvironmentVariable Include="COMPlus_DoubleArrayToLargeObjectHeap" Value="0x64" />
</ItemGroup>
<PropertyGroup>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set COMPlus_DoubleArrayToLargeObjectHeap=0x64
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export COMPlus_DoubleArrayToLargeObjectHeap=0x64
]]></BashCLRTestPreCommands>
</PropertyGroup>
</Project>
12 changes: 2 additions & 10 deletions src/tests/JIT/Methodical/doublearray/dblarray4_cs_ro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="dblarray4.cs" />

<CLRTestEnvironmentVariable Include="COMPlus_DoubleArrayToLargeObjectHeap" Value="0x64" />
</ItemGroup>
<PropertyGroup>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set COMPlus_DoubleArrayToLargeObjectHeap=0x64
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export COMPlus_DoubleArrayToLargeObjectHeap=0x64
]]></BashCLRTestPreCommands>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set DOTNET_TieredCompilation=1
set DOTNET_TieredPGO=1
set DOTNET_JitProfileCasts=1
set DOTNET_JitConsumeProfileForCasts=1
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export DOTNET_TieredCompilation=1
export DOTNET_TieredPGO=1
export DOTNET_JitProfileCasts=1
export DOTNET_JitConsumeProfileForCasts=1
]]></BashCLRTestPreCommands>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />

<CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_TieredPGO" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_JitProfileCasts" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_JitConsumeProfileForCasts" Value="1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set DOTNET_TieredCompilation=1
set DOTNET_TieredPGO=1
set DOTNET_JitProfileCasts=1
set DOTNET_JitConsumeProfileForCasts=1
set DOTNET_JitRandomGuardedDevirtualization=1
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export DOTNET_TieredCompilation=1
export DOTNET_TieredPGO=1
export DOTNET_JitProfileCasts=1
export DOTNET_JitConsumeProfileForCasts=1
export DOTNET_JitRandomGuardedDevirtualization=1
]]></BashCLRTestPreCommands>
</PropertyGroup>
<ItemGroup>
<Compile Include="ProfileCastClassAndIsInst.cs" />

<CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_TieredPGO" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_JitProfileCasts" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_JitConsumeProfileForCasts" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_JitRandomGuardedDevirtualization" Value="1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set DOTNET_TieredCompilation=1
set DOTNET_TieredPGO=1
set DOTNET_JitProfileCasts=1
set DOTNET_JitConsumeProfileForCasts=1
set DOTNET_JitRandomGuardedDevirtualization=2
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export DOTNET_TieredCompilation=1
export DOTNET_TieredPGO=1
export DOTNET_JitProfileCasts=1
export DOTNET_JitConsumeProfileForCasts=1
export DOTNET_JitRandomGuardedDevirtualization=2
]]></BashCLRTestPreCommands>
</PropertyGroup>
<ItemGroup>
<Compile Include="ProfileCastClassAndIsInst.cs" />

<CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_TieredPGO" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_JitProfileCasts" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_JitConsumeProfileForCasts" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_JitRandomGuardedDevirtualization" Value="2" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set DOTNET_TieredCompilation=1
set DOTNET_TieredPGO=1
set DOTNET_JitProfileCasts=1
set DOTNET_JitConsumeProfileForCasts=1
set DOTNET_JitRandomGuardedDevirtualization=3
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export DOTNET_TieredCompilation=1
export DOTNET_TieredPGO=1
export DOTNET_JitProfileCasts=1
export DOTNET_JitConsumeProfileForCasts=1
export DOTNET_JitRandomGuardedDevirtualization=3
]]></BashCLRTestPreCommands>
</PropertyGroup>
<ItemGroup>
<Compile Include="ProfileCastClassAndIsInst.cs" />

<CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_TieredPGO" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_JitProfileCasts" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_JitConsumeProfileForCasts" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_JitRandomGuardedDevirtualization" Value="3" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).il" />

<CLRTestEnvironmentVariable Include="COMPlus_JitStressRegs" Value="0x200" />
</ItemGroup>
<PropertyGroup>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set COMPlus_JitStressRegs=0x200
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export COMPlus_JitStressRegs=0x200
]]></BashCLRTestPreCommands>
</PropertyGroup>
</Project>
Loading

0 comments on commit e514819

Please sign in to comment.