Skip to content

Commit a5b5ec5

Browse files
authored
Add dotnet cli to runtime test Helix jobs (#35426)
* Currently managed tools such as crossgen2 and XUnit are run against the built runtime which is slow on Debug builds, and can obscure errors when the XUnit test harness fails due to an introduced runtime bug. * Add `xunit.console.runtimeconfig.dev.json` which allows `xunit.console` to use the repo-local dotnet.cmd on dev boxes and the same version installed on the path in Helix. * When running crossgen2 during test execution, support both local dev and Helix scenario when deciding which dotnet to run. On Helix, simply use `dotnet` which assumes a compatible dotnet runtime is in the path. Locally, tests are run with `runtest.cmd|sh` which sets `__TestDotNetCmd` to the repo-local dotnet script. This preserves the characteristic that no machine-wide 5.0 dotnet runtime must be installed for the runtime tests. * Update batch scripting to also use `dotnet.cmd|sh` when running Crossgen2 replacing corerun.exe. * crossgen2's `runtimes` folder is not getting copied to `CORE_ROOT` which causes the runtime host to abort the launch on the Unix CI VMs since crossgen.deps.json refers to files in that subfolder. Adjust the `CORE_ROOT` pruning in `Directory.Build.targets` to include subfolders for the two tools that need it. * Improve XUnit test boilerplate. Printing `Exception.Message` doesn't include stack trace. Use `ToString()` instead. * Import notargets sdk in `helixpublicwitharcade.proj`. It doesn't use the official sdk so `BundledNETCoreAppPackageVersion` wasn't set. Import the `Microsoft.Build.NoTargets` sdk so we can find the bundled runtime package version.
1 parent adab8f2 commit a5b5ec5

File tree

8 files changed

+68
-25
lines changed

8 files changed

+68
-25
lines changed

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<MicrosoftDotNetGenAPIVersion>5.0.0-beta.20261.9</MicrosoftDotNetGenAPIVersion>
6464
<MicrosoftDotNetGenFacadesVersion>5.0.0-beta.20261.9</MicrosoftDotNetGenFacadesVersion>
6565
<MicrosoftDotNetXUnitExtensionsVersion>5.0.0-beta.20261.9</MicrosoftDotNetXUnitExtensionsVersion>
66-
<MicrosoftDotNetXUnitConsoleRunnerVersion>2.5.1-beta.20261.9</MicrosoftDotNetXUnitConsoleRunnerVersion>
66+
<MicrosoftDotNetXUnitConsoleRunnerVersion>2.5.1-beta.20264.3</MicrosoftDotNetXUnitConsoleRunnerVersion>
6767
<MicrosoftDotNetBuildTasksPackagingVersion>5.0.0-beta.20261.9</MicrosoftDotNetBuildTasksPackagingVersion>
6868
<MicrosoftDotNetRemoteExecutorVersion>5.0.0-beta.20261.9</MicrosoftDotNetRemoteExecutorVersion>
6969
<MicrosoftDotNetVersionToolsTasksVersion>5.0.0-beta.20261.9</MicrosoftDotNetVersionToolsTasksVersion>

src/coreclr/build-test.cmd

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -652,15 +652,17 @@ for %%F in ("%CORE_ROOT%\System.*.dll";"%CORE_ROOT%\Microsoft.*.dll";%CORE_ROOT%
652652
)))))
653653
)
654654

655-
echo Composite response line^: %__CompositeResponseFile%
656-
type "%__CompositeResponseFile%"
655+
if defined __CompositeBuildMode (
656+
echo Composite response line^: %__CompositeResponseFile%
657+
type "%__CompositeResponseFile%"
658+
)
657659

658660
if defined __CompositeBuildMode (
659-
set __CompositeCommandLine="%CORE_ROOT%\corerun"
661+
set __CompositeCommandLine="%__RepoRootDir%\dotnet.cmd"
660662
set __CompositeCommandLine=!__CompositeCommandLine! "%CORE_ROOT%\crossgen2\crossgen2.dll"
661663
set __CompositeCommandLine=!__CompositeCommandLine! "@%__CompositeResponseFile%"
662664
echo Building composite R2R framework^: !__CompositeCommandLine!
663-
!__CompositeCommandLine!
665+
call !__CompositeCommandLine!
664666
set __FailedToPrecompile=!ERRORLEVEL!
665667
copy /Y "!__CompositeOutputDir!\*.*" "!CORE_ROOT!\"
666668
)
@@ -684,7 +686,7 @@ if /i "%__BuildArch%" == "arm64" ( set __CrossgenExe="%__BinDir%\x64\crossgen.ex
684686
set __CrossgenExe=%__CrossgenExe%
685687

686688
if defined __DoCrossgen2 (
687-
set __CrossgenExe="%CORE_ROOT%\corerun" "%__BinDir%\crossgen2\crossgen2.dll"
689+
set __CrossgenExe="%__RepoRootDir%\dotnet.cmd" "%CORE_ROOT%\crossgen2\crossgen2.dll"
688690
)
689691

690692
REM Intentionally avoid using the .dll extension to prevent
@@ -694,12 +696,14 @@ set __CrossgenCmd=
694696

695697
if defined __DoCrossgen (
696698
set __CrossgenCmd=!__CrossgenExe! /Platform_Assemblies_Paths "!CORE_ROOT!" /in !AssemblyPath! /out !__CrossgenOutputFile!
699+
echo !__CrossgenCmd!
700+
!__CrossgenCmd!
697701
) else (
698702
set __CrossgenCmd=!__CrossgenExe! -r:"!CORE_ROOT!\System.*.dll" -r:"!CORE_ROOT!\Microsoft.*.dll" -r:"!CORE_ROOT!\mscorlib.dll" -r:"!CORE_ROOT!\netstandard.dll" -O --inputbubble --out:!__CrossgenOutputFile! !AssemblyPath!
703+
echo !__CrossgenCmd!
704+
call !__CrossgenCmd!
699705
)
700706

701-
echo %__CrossgenCmd%
702-
%__CrossgenCmd%
703707
set /a __exitCode = !errorlevel!
704708

705709
set /a "%~3+=1"

src/coreclr/build-test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ precompile_coreroot_fx()
180180

181181
local totalPrecompiled=0
182182
local failedToPrecompile=0
183-
local compositeCommandLine="$overlayDir/corerun"
184-
compositeCommandLine+=" ${__BinDir}/crossgen2/crossgen2.dll"
183+
local compositeCommandLine="${__DotNetCli}"
184+
compositeCommandLine+=" $__BinDir/crossgen2/crossgen2.dll"
185185
compositeCommandLine+=" --composite"
186186
compositeCommandLine+=" -O"
187187
compositeCommandLine+=" --out:$outputDir/framework-r2r.dll"
@@ -206,7 +206,7 @@ precompile_coreroot_fx()
206206
fi
207207

208208
if [[ "$__DoCrossgen2" != 0 ]]; then
209-
commandLine="$overlayDir/corerun $overlayDir/crossgen2/crossgen2.dll $crossgen2References -O --inputbubble --out $outputDir/$(basename $filename) $filename"
209+
commandLine="${__DotNetCli} $overlayDir/crossgen2/crossgen2.dll $crossgen2References -O --inputbubble --out $outputDir/$(basename $filename) $filename"
210210
fi
211211

212212
echo Precompiling "$filename"

src/coreclr/tests/helixpublishwitharcade.proj

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
to send test jobs to helix. -->
66

77
<Import Sdk="Microsoft.DotNet.Helix.Sdk" Project="Sdk.props" Condition=" '$(UsesHelixSdk)' == 'true' " />
8-
<Import Project="Directory.Build.props" Condition=" '$(UsesHelixSdk)' != 'true' "/>
8+
<Import Sdk="Microsoft.Build.NoTargets" Project="Sdk.props" Condition=" '$(UsesHelixSdk)' != 'true' " />
99

1010
<!-- This target runs once and creates several instances of this project (one for each scenario)
1111
that will run in parallel. -->
@@ -33,10 +33,14 @@
3333
RunInUnloadableContext=$(_RunInUnloadableContext);
3434
TimeoutPerTestCollectionInMinutes=$(_TimeoutPerTestCollectionInMinutes);
3535
TimeoutPerTestInMinutes=$(_TimeoutPerTestInMinutes);
36-
RuntimeMode=$(_RuntimeMode)
36+
RuntimeMode=$(_RuntimeMode);
37+
BundledNETCoreAppPackageVersion=$(BundledNETCoreAppPackageVersion)
3738
</_PropertiesToPass>
3839
</PropertyGroup>
3940

41+
<Message Text="DotNetCliVersion: $(DotNetCliVersion)" Importance="High" />
42+
<Message Text="DotNetCliPackageType: $(DotNetCliPackageType)" Importance="High" />
43+
<Message Text="HelixRuntimeRid: $(HelixRuntimeRid)" Importance="High" />
4044
<Error Condition="'$(_Scenarios)' == ''" Text="_Scenarios not set" />
4145

4246
<MSBuild Projects="$(MSBuildProjectFile)" Targets="PrepareCorrelationPayloadDirectory" />
@@ -59,12 +63,24 @@
5963
<MSBuild Projects="@(_ProjectsToBuild)" Targets="Test" BuildInParallel="$(_BuildInParallel)" StopOnFirstFailure="false" Properties="UsesHelixSdk=true" />
6064
</Target>
6165

66+
<!-- Choose a suitable runtime RID for Helix to restore the dotnet cli -->
67+
<PropertyGroup>
68+
<HelixRuntimeRid Condition="'$(TargetOS)' == 'Windows_NT'">win-$(TargetArchitecture)</HelixRuntimeRid>
69+
<HelixRuntimeRid Condition="'$(TargetOS)' == 'OSX'">osx-$(TargetArchitecture)</HelixRuntimeRid>
70+
<HelixRuntimeRid Condition="'$(TargetOS)' == 'Linux' or '$(TargetOS)' == 'Linux_musl'">linux-$(TargetArchitecture)</HelixRuntimeRid>
71+
</PropertyGroup>
72+
6273
<PropertyGroup>
6374
<BinDir>$([MSBuild]::NormalizeDirectory($(TestWorkingDir)))</BinDir>
6475
<CoreRootDirectory>$(BinDir)Tests\Core_Root\</CoreRootDirectory>
6576
<PayloadsRootDirectory>$(BinDir)Payloads\</PayloadsRootDirectory>
6677
<TestEnvFileName Condition=" '$(TargetsWindows)' == 'true' ">SetStressModes_$(Scenario).cmd</TestEnvFileName>
6778
<TestEnvFileName Condition=" '$(TargetsWindows)' != 'true' ">SetStressModes_$(Scenario).sh</TestEnvFileName>
79+
80+
<IncludeDotNetCli>true</IncludeDotNetCli>
81+
<DotNetCliPackageType>runtime</DotNetCliPackageType>
82+
<DotNetCliVersion>$(BundledNETCoreAppPackageVersion)</DotNetCliVersion>
83+
<DotNetCliRuntime>$(HelixRuntimeRid)</DotNetCliRuntime>
6884
</PropertyGroup>
6985

7086
<Import Project="testgrouping.proj" />
@@ -236,12 +252,10 @@
236252
</PropertyGroup>
237253

238254
<PropertyGroup Condition=" '$(TargetsWindows)' == 'true' ">
239-
<CoreRun>%CORE_ROOT%\CoreRun.exe</CoreRun>
240255
<XUnitRunnerDll>%CORE_ROOT%\xunit.console.dll</XUnitRunnerDll>
241256
</PropertyGroup>
242257

243258
<PropertyGroup Condition=" '$(TargetsWindows)' != 'true' ">
244-
<CoreRun>$CORE_ROOT/corerun</CoreRun>
245259
<XUnitRunnerDll>$CORE_ROOT/xunit.console.dll</XUnitRunnerDll>
246260
</PropertyGroup>
247261

@@ -263,12 +277,13 @@
263277

264278
<HelixWorkItem Include="@(Payloads->Metadata('PayloadGroup'))">
265279
<PayloadDirectory>%(PayloadDirectory)</PayloadDirectory>
266-
<Command>$(CoreRun) $(XUnitRunnerDll) %(XUnitWrapperDlls) $(XUnitRunnerArgs)</Command>
267-
<Command Condition=" '%(TestGroup)' != '' ">$(CoreRun) $(XUnitRunnerDll) %(XUnitWrapperDlls) $(XUnitRunnerArgs) -trait TestGroup=%(TestGroup)</Command>
280+
<Command>dotnet $(XUnitRunnerDll) %(XUnitWrapperDlls) $(XUnitRunnerArgs)</Command>
281+
<Command Condition=" '%(TestGroup)' != '' ">dotnet $(XUnitRunnerDll) %(XUnitWrapperDlls) $(XUnitRunnerArgs) -trait TestGroup=%(TestGroup)</Command>
268282
<Timeout Condition=" '$(TimeoutPerTestCollectionInMinutes)' != '' ">$([System.TimeSpan]::FromMinutes($(TimeoutPerTestCollectionInMinutes)))</Timeout>
269283
</HelixWorkItem>
270284
</ItemGroup>
271285

272286
<Import Sdk="Microsoft.DotNet.Helix.Sdk" Project="Sdk.targets" Condition=" '$(UsesHelixSdk)' == 'true' " />
287+
<Import Sdk="Microsoft.Build.NoTargets" Project="Sdk.targets" Condition=" '$(UsesHelixSdk)' != 'true' " />
273288

274289
</Project>

src/coreclr/tests/runtest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,9 @@ def run_tests(args,
934934
print("Setting CORE_ROOT=%s" % args.core_root)
935935
os.environ["CORE_ROOT"] = args.core_root
936936

937+
# Set __TestDotNetCmd so tests which need to run dotnet can use the repo-local script on dev boxes
938+
os.environ["__TestDotNetCmd"] = args.dotnetcli_script_path
939+
937940
# Set test env script path if it is set.
938941
if test_env_script_path is not None:
939942
print("Setting __TestEnv=%s" % test_env_script_path)

src/coreclr/tests/src/CLRTest.CrossGen.targets

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ if [ ! -z ${RunCrossGen2+x} ]%3B then
8383
rm $__ResponseFile
8484
8585
__Command=$_DebuggerFullPath
86-
__Command+=" $CORE_ROOT/corerun"
86+
# Tests run locally need __TestDotNetCmd (set by runtest.py) or a compatible 5.0 dotnet runtime in the path
87+
if [ ! -z ${__TestDotNetCmd+x} ] %3B then
88+
__Command+=" $__TestDotNetCmd"
89+
else
90+
__Command+=" dotnet"
91+
fi
8792
__Command+=" $CORE_ROOT/crossgen2/crossgen2.dll"
8893
__Command+=" @$__ResponseFile"
8994
__Command+=" $ExtraCrossGen2Args"
@@ -178,7 +183,12 @@ if defined RunCrossGen2 (
178183
del /Q !__ResponseFile!
179184
180185
set __Command=!_DebuggerFullPath!
181-
set __Command=!__Command! "!CORE_ROOT!\CoreRun.exe"
186+
REM Tests run locally need __TestDotNetCmd (set by runtest.py) or a compatible 5.0 dotnet runtime in the path
187+
if defined __TestDotNetCmd (
188+
set __Command=!__Command! "!__TestDotNetCmd!"
189+
) else (
190+
set __Command=!__Command! "dotnet"
191+
)
182192
set __Command=!__Command! "!CORE_ROOT!\crossgen2\crossgen2.dll"
183193
set __Command=!__Command! @"!__ResponseFile!"
184194
set __Command=!__Command! !ExtraCrossGen2Args!

src/coreclr/tests/src/Common/Directory.Build.targets

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,37 @@
5858
<RunTimeArtifactsIncludeFolders Include="IL/" />
5959

6060
<!-- Used for Crossgen2 R2R tests -->
61-
<RunTimeArtifactsIncludeFolders Include="crossgen2/" />
61+
<RunTimeArtifactsIncludeFolders Include="crossgen2/">
62+
<IncludeSubFolders>True</IncludeSubFolders>
63+
</RunTimeArtifactsIncludeFolders>
6264

6365
<!-- Used for capturing symbolic stack traces using Watson -->
6466
<RunTimeArtifactsIncludeFolders Include="PDB/" />
6567

6668
<!-- Used by the coreroot_determinism test -->
67-
<RunTimeArtifactsIncludeFolders Include="R2RTest/" />
69+
<RunTimeArtifactsIncludeFolders Include="R2RTest/">
70+
<IncludeSubFolders>True</IncludeSubFolders>
71+
</RunTimeArtifactsIncludeFolders>
6872
</ItemGroup>
6973

7074
<ItemGroup>
7175
<!-- Add binary dependencies to copy-local items -->
7276
<RunTimeDependencyCopyLocal
77+
Condition="'%(RuntimeArtifactsIncludeFolders.IncludeSubFolders)' != 'True'"
7378
Include="$(CoreCLRArtifactsPath)%(RunTimeArtifactsIncludeFolders.Identity)*"
7479
Exclude="@(RunTimeArtifactsExcludeFiles -> '$(CoreCLRArtifactsPath)%(Identity)')"
7580
TargetDir="%(RunTimeArtifactsIncludeFolders.Identity)" />
81+
82+
<RunTimeDependencyCopyLocal
83+
Condition="'%(RuntimeArtifactsIncludeFolders.IncludeSubFolders)' == 'True'"
84+
Include="$(CoreCLRArtifactsPath)%(RunTimeArtifactsIncludeFolders.Identity)**/*"
85+
Exclude="@(RunTimeArtifactsExcludeFiles -> '$(CoreCLRArtifactsPath)%(Identity)')"
86+
TargetDir="%(RunTimeArtifactsIncludeFolders.Identity)" />
7687
</ItemGroup>
7788

7889
<Copy
7990
SourceFiles="@(RunTimeDependencyCopyLocal)"
80-
DestinationFiles="@(RunTimeDependencyCopyLocal -> '$(CORE_ROOT)/%(TargetDir)%(Filename)%(Extension)')"
91+
DestinationFiles="@(RunTimeDependencyCopyLocal -> '$(CORE_ROOT)/%(TargetDir)%(RecursiveDir)%(Filename)%(Extension)')"
8192
SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
8293
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
8394
Retries="$(CopyRetryCount)"

src/coreclr/tests/src/runtest.proj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").
291291
292292
if (infraEx != null)
293293
{
294-
Assert.True(false, "Test Infrastructure Failure: " + infraEx.Message)%3B
294+
Assert.True(false, "Test Infrastructure Failure: " + infraEx.ToString())%3B
295295
}
296296
else
297297
{
@@ -304,7 +304,7 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").
304304
catch (Exception ex)
305305
{
306306
testOutput.Add("Unable to read error file: " + errorFile)%3B
307-
testOutput.Add(ex.Message)%3B
307+
testOutput.Add(ex.ToString())%3B
308308
}
309309
310310
testOutput.Add(string.Empty)%3B
@@ -319,7 +319,7 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").
319319
catch(Exception ex)
320320
{
321321
testOutput.Add("Unable to read output file: " + outputFile)%3B
322-
testOutput.Add(ex.Message)%3B
322+
testOutput.Add(ex.ToString())%3B
323323
}
324324
325325
testOutput.Add("To run the test:")%3B

0 commit comments

Comments
 (0)