Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added net8.0 target and tests (Fixes #94) #110

Merged
merged 20 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
423e103
Added net8.0 target and tests (fixes #94)
NightOwl888 Aug 21, 2024
cc224e7
azure-pipelines.yml + build-pack-and-publish-libraries.yml + run-test…
NightOwl888 Aug 21, 2024
f756eeb
publish-test-results.yml: Added additional crash detection messages
NightOwl888 Aug 21, 2024
f5ab082
Directory.Build.targets: Switched to using FEATURE_UNICODE_DEFINED fo…
NightOwl888 Aug 22, 2024
af536fc
J2N.Threading.Atomic (AtomicReference + AtomicReferenceArray): Use Vo…
NightOwl888 Aug 22, 2024
fb00d62
J2N.csproj: Removed <LangVersion> so we can inherit the version of th…
NightOwl888 Sep 14, 2024
7a7b75d
tests/Directory.Build.targets: Added task to update System.Runtime.Se…
NightOwl888 Sep 15, 2024
d5dc53a
SWEEP: Marked all binary serialization methods obsolete and suppresse…
NightOwl888 Sep 15, 2024
0052860
run-tests-on-os.yml: Fixed target frameworks variable name so the add…
NightOwl888 Sep 15, 2024
a3932db
BUG: J2N.Collections.Tests.HashSet_IEnumerable_NonGeneric_Tests: Fixe…
NightOwl888 Sep 15, 2024
fde7ae6
J2N.Tests.xUnit: Updated List<T> tests to pass with the current imple…
NightOwl888 Sep 15, 2024
b983d61
BUG: J2N.Collections.Tests.SortedDictionary_IDictionary_NonGeneric_Te…
NightOwl888 Sep 15, 2024
10603cd
SWEEP: Upgraded SortedSet<T> and SortedDictionary<TKey, TValue> to th…
NightOwl888 Sep 16, 2024
8e4e6e8
SWEEP: Upgraded test targets from net461 > net471, net452 > net47 bec…
NightOwl888 Sep 16, 2024
087dba8
J2N.Numerics: Suppressed build warnings in Microsoft-sourced code tha…
NightOwl888 Sep 16, 2024
f8cc6d6
run-tests-on-os.yml: Run test projects in the background in parallel
NightOwl888 Sep 16, 2024
61d72c4
run-tests-on-os.yml: Use .NET 6 SDK for testing .NET Framework, since…
NightOwl888 Sep 16, 2024
ebce776
azure-pipelines.yml: Fixed display name for net471 x64 job
NightOwl888 Sep 16, 2024
4b8f49b
J2N.Tests.xUnit (SubList_Tests<T>): removed commented code
NightOwl888 Sep 16, 2024
9faac89
J2N.TestCharacter::Test_getType_I(): Added comment to indicate this c…
NightOwl888 Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions .build/TestTargetFramework.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,39 @@
<!-- Changing this setting will allow testing on all target frameworks within Visual Studio 2017.
Note that the main libraries are multi-targeted, so this has no effect on how they are compiled,
this setting only affects the test projects. -->
<!--<TargetFramework>net452</TargetFramework>-->
<!--<TargetFramework>net461</TargetFramework>-->
<!--<TargetFramework>net47</TargetFramework>-->
<!--<TargetFramework>net471</TargetFramework>-->
<!--<TargetFramework>net472</TargetFramework>-->
<!--<TargetFramework>net48</TargetFramework>-->
<!--<TargetFramework>net5.0</TargetFramework>-->
<!--<TargetFramework>net6.0</TargetFramework>-->
<!--<TargetFramework>net8.0</TargetFramework>-->
<TestAllTargetFrameworks>true</TestAllTargetFrameworks>

<!-- Allow the build script to pass in the test frameworks to build for.
This overrides the above TargetFramework setting.
TODO: Due to a parsing bug, we cannot pass a string with a ; to dotnet msbuild, so passing true as a workaround -->

<!-- Test Client to DLL target works as follows:

Test Client | Target Under Test
net8.0 | net8.0
net6.0 | net6.0
net5.0 | netstandard2.1
net48 | net462
net472 | net45
net461 | netstandard2.0
net452 | net40
net471 | netstandard2.0
net47 | net40

-->
<TargetFrameworks Condition=" '$(TestAllTargetFrameworks)' == 'true' ">net6.0;net5.0;net48;net472;net461;net452</TargetFrameworks>
<TargetFrameworks Condition=" '$(TestAllTargetFrameworks)' == 'true' ">net8.0;net6.0;net5.0;net48;net472;net471;net47</TargetFrameworks>
<TargetFramework Condition=" '$(TargetFrameworks)' != '' "></TargetFramework>
</PropertyGroup>

<PropertyGroup Label="Mismatched Target Framework (to override the target framework under test)">
<SetTargetFramework></SetTargetFramework>
<SetTargetFramework Condition=" '$(TargetFramework)' == 'net452' ">TargetFramework=net40</SetTargetFramework>
<SetTargetFramework Condition=" '$(TargetFramework)' == 'net461' ">TargetFramework=netstandard2.0</SetTargetFramework>
<SetTargetFramework Condition=" '$(TargetFramework)' == 'net47' ">TargetFramework=net40</SetTargetFramework>
<SetTargetFramework Condition=" '$(TargetFramework)' == 'net471' ">TargetFramework=netstandard2.0</SetTargetFramework>
<SetTargetFramework Condition=" '$(TargetFramework)' == 'net472' ">TargetFramework=net45</SetTargetFramework>
</PropertyGroup>

Expand Down
7 changes: 4 additions & 3 deletions .build/azure-templates/build-pack-and-publish-libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ steps:
Contents: '**/bin/${{ parameters.buildConfiguration }}/**/*.pdb'
TargetFolder: '$(Build.ArtifactStagingDirectory)/${{ parameters.nugetArtifactName }}'

- task: PublishBuildArtifacts@1
- task: PublishPipelineArtifact@1
displayName: 'Publish Artifact: ${{ parameters.nugetArtifactName }}'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/${{ parameters.nugetArtifactName }}'
ArtifactName: '${{ parameters.nugetArtifactName }}'
targetPath: '$(Build.ArtifactStagingDirectory)/${{ parameters.nugetArtifactName }}'
artifact: '${{ parameters.nugetArtifactName }}'
publishLocation: 'pipeline'
condition: succeededOrFailed()

# Loops through each framework in the TestTargetFrameworks variable and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ steps:
EnsureNotNullOrEmpty('${{ parameters.testResultsFileName }}', 'testResultsFileName')
displayName: 'Validate Template Parameters'

- template: publish-test-results.yml
parameters:
framework: 'net8.0'
testProjectName: '${{ parameters.testProjectName }}'
osName: '${{ parameters.osName }}'
testPlatform: '${{ parameters.testPlatform }}'
testResultsFormat: '${{ parameters.testResultsFormat }}'
testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
parameters:
framework: 'net6.0'
Expand Down Expand Up @@ -66,19 +76,19 @@ steps:

- template: publish-test-results.yml
parameters:
framework: 'net461'
framework: 'net471'
testProjectName: '${{ parameters.testProjectName }}'
osName: '${{ parameters.osName }}'
testPlatform: '${{ parameters.testPlatform }}'
testResultsFormat: '${{ parameters.testResultsFormat }}'
testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
testResultsFileName: '${{ parameters.testResultsFileName }}'

# Special Case: Using lowest supported version of .NET Framework (4.5.2) in xUnit to test .NET Framework 4.0.
# Special Case: Using a supported version of .NET Framework (4.7) in xUnit to test .NET Framework 4.0.
# This only works because we are using the SetTargetFramework attribute to set the target framework of the project reference.
- template: publish-test-results.yml
parameters:
framework: 'net452'
framework: 'net47'
testProjectName: '${{ parameters.testProjectName }}'
osName: '${{ parameters.osName }}'
testPlatform: '${{ parameters.testPlatform }}'
Expand Down
20 changes: 14 additions & 6 deletions .build/azure-templates/publish-test-results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,20 @@ steps:
if ($reader.Name -eq 'RunInfos') {
$inRunInfos = $true
}
if ($inRunInfos -and !$crashed -and $reader.Name -eq 'Text' -and $reader.ReadInnerXml().Contains('Test host process crashed')) {
Write-Host "##vso[task.setvariable variable=HostCrashed;]true"
# Report all of the test projects that crashed
$crashedRuns = "$env:CRASHEDRUNS,$testProjectName".TrimStart(',')
Write-Host "##vso[task.setvariable variable=CrashedRuns;]$crashedRuns"
$crashed = $true
if ($inRunInfos -and !$crashed -and $reader.Name -eq 'Text') {
$innerXml = $reader.ReadInnerXml()
# Test for specific error messages - we may need to adjust this, as needed
if ($innerXml -and ($innerXml.Contains('Test host process crashed') `
-or $innerXml.Contains('Could not load file or assembly') `
-or $innerXml.Contains("Could not find `'dotnet.exe`' host") `
-or $innerXml.Contains('No test is available') `
-or $innerXml.Contains('exited with error'))) {
Write-Host "##vso[task.setvariable variable=HostCrashed;]true"
# Report all of the test projects that crashed
$crashedRuns = "$env:CRASHEDRUNS,$testProjectName".TrimStart(',')
Write-Host "##vso[task.setvariable variable=CrashedRuns;]$crashedRuns"
$crashed = $true
}
}
}
if ($reader.NodeType -eq [System.Xml.XmlNodeType]::EndElement -and $reader.Name -eq 'RunInfos') {
Expand Down
174 changes: 131 additions & 43 deletions .build/azure-templates/run-tests-on-os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,102 @@ steps:
EnsureNotNullOrEmpty('${{ parameters.dotNetSdkVersion }}', 'dotNetSdkVersion')
displayName: 'Validate Template Parameters'

- pwsh: |
$testTargetFrameworks = '${{ parameters.testTargetFrameworks }}'
$testPlatform = '${{ parameters.vsTestPlatform }}'
$dotnetSdkVersion = '${{ parameters.dotNetSdkVersion }}'
if ($IsWindows -eq $null) {
$IsWindows = $env:OS.StartsWith('Win')
}
# .NET Framework tests are SLOW when using the .NET 8 SDK (especially those for net47 targeting net40).
# So, we use .NET 6 SDK instead.
if ($testTargetFrameworks.StartsWith('net4')) {
$dotnetSdkVersion = '6.0.421'
}
Write-Host "Using SDK Version: $dotnetSdkVersion"
$performMulitLevelLookup = if ($IsWindows -and $testPlatform.Equals('x86')) { 'true' } else { 'false' }
Write-Host "##vso[task.setvariable variable=PerformMultiLevelLookup;]$performMulitLevelLookup"
Write-Host "##vso[task.setvariable variable=DotNetSdkVersion;]$dotnetSdkVersion"

#- template: 'show-all-environment-variables.yml' # Uncomment for debugging

- template: 'install-dotnet-sdk.yml'
parameters:
sdkVersion: '${{ parameters.dotNetSdkVersion }}'
sdkVersion: '$(DotNetSdkVersion)'
performMultiLevelLookup: '$(PerformMultiLevelLookup)'

# Hack: .NET 8 no longer installs the x86 bits and they must be installed separately. However, it is not
# trivial to get it into the path and to get it to pass the minimum SDK version check in runbuild.ps1.
# So, we install it afterward and set the environment variable so the above SDK can delegate to it.
# This code only works on Windows.
- pwsh: |
$sdkVersion = '$(DotNetSdkVersion)'
$architecture = '${{ parameters.vsTestPlatform }}'
$installScriptPath = "${env:AGENT_TEMPDIRECTORY}/dotnet-install.ps1"
$installScriptUrl = "https://raw.githubusercontent.com/dotnet/install-scripts/main/src/dotnet-install.ps1"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest $installScriptUrl -OutFile $installScriptPath -TimeoutSec 60
$installPath = "${env:ProgramFiles(x86)}/dotnet"
& $installScriptPath -Version $sdkVersion -Architecture $architecture -InstallDir $installPath
Write-Host "##vso[task.setvariable variable=DOTNET_ROOT_X86;]$installPath"
displayName: 'Use .NET SDK $(DotNetSdkVersion) (x86)'
condition: and(succeeded(), contains('${{ parameters.testTargetFrameworks }}', 'net8.'), eq('${{ parameters.vsTestPlatform }}', 'x86'))

- task: UseDotNet@2
displayName: 'Use .NET Core sdk 3.1.416'
displayName: 'Use .NET SDK 6.0.421'
inputs:
version: 3.1.416
condition: and(succeeded(), contains('${{ parameters.testTargetFrameworks }}', 'netcoreapp3.'))
packageType: 'sdk'
version: '6.0.421'
performMultiLevelLookup: '${{ variables.PerformMultiLevelLookup }}'
condition: and(succeeded(), contains('${{ parameters.testTargetFrameworks }}', 'net6.'))

# Hack: .NET 8 no longer installs the x86 bits and they must be installed separately. However, it is not
# trivial to get it into the path and to get it to pass the minimum SDK version check in runbuild.ps1.
# So, we install it afterward and set the environment variable so the above SDK can delegate to it.
# This code only works on Windows.
- pwsh: |
$sdkVersion = '6.0.421'
$architecture = '${{ parameters.vsTestPlatform }}'
$installScriptPath = "${env:AGENT_TEMPDIRECTORY}/dotnet-install.ps1"
$installScriptUrl = "https://raw.githubusercontent.com/dotnet/install-scripts/main/src/dotnet-install.ps1"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest $installScriptUrl -OutFile $installScriptPath -TimeoutSec 60
$installPath = "${env:ProgramFiles(x86)}/dotnet"
& $installScriptPath -Version $sdkVersion -Architecture $architecture -InstallDir $installPath
Write-Host "##vso[task.setvariable variable=DOTNET_ROOT_X86;]$installPath"
displayName: 'Use .NET SDK 6.0.421 (x86)'
condition: and(succeeded(), contains('${{ parameters.testTargetFrameworks }}', 'net6.'), eq('${{ parameters.vsTestPlatform }}', 'x86'))

- task: UseDotNet@2
displayName: 'Use .NET sdk 5.0.404'
displayName: 'Use .NET SDK 5.0.408'
inputs:
version: 5.0.404
packageType: 'sdk'
version: '5.0.408'
performMultiLevelLookup: '${{ variables.PerformMultiLevelLookup }}'
condition: and(succeeded(), contains('${{ parameters.testTargetFrameworks }}', 'net5.'))

- task: DownloadBuildArtifacts@0
displayName: 'Download Build Artifacts: ${{ parameters.binaryArtifactName }}'
# Hack: .NET 8 no longer installs the x86 bits and they must be installed separately. However, it is not
# trivial to get it into the path and to get it to pass the minimum SDK version check in runbuild.ps1.
# So, we install it afterward and set the environment variable so the above SDK can delegate to it.
# This code only works on Windows.
- pwsh: |
$sdkVersion = '5.0.408'
$architecture = '${{ parameters.vsTestPlatform }}'
$installScriptPath = "${env:AGENT_TEMPDIRECTORY}/dotnet-install.ps1"
$installScriptUrl = "https://raw.githubusercontent.com/dotnet/install-scripts/main/src/dotnet-install.ps1"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest $installScriptUrl -OutFile $installScriptPath -TimeoutSec 60
$installPath = "${env:ProgramFiles(x86)}/dotnet"
& $installScriptPath -Version $sdkVersion -Architecture $architecture -InstallDir $installPath
Write-Host "##vso[task.setvariable variable=DOTNET_ROOT_X86;]$installPath"
displayName: 'Use .NET SDK 5.0.408 (x86)'
condition: and(succeeded(), contains('${{ parameters.testTargetFrameworks }}', 'net5.'), eq('${{ parameters.vsTestPlatform }}', 'x86'))

- task: DownloadPipelineArtifact@2
displayName: 'Download Pipeline Artifacts: ${{ parameters.binaryArtifactName }}'
inputs:
artifactName: ${{ parameters.binaryArtifactName }}
downloadPath: '$(System.DefaultWorkingDirectory)'
targetPath: '$(System.DefaultWorkingDirectory)'

- pwsh: |
$testTargetFrameworksString = '${{ parameters.testTargetFrameworks }}'
Expand All @@ -77,54 +152,67 @@ steps:

function RunTests([string]$framework, [string]$fileRegexPattern) {
if (!(IsSupportedFramework($framework))) { continue }

$testBinaries = Get-ChildItem -Path "$testBinaryRootDirectory" -File -Recurse | Where-Object {$_.FullName -match "$framework"} | Where-Object {$_.FullName -match "$fileRegexPattern"} | Select -ExpandProperty FullName
foreach ($testBinary in $testBinaries) {
$testName = [System.IO.Path]::GetFileNameWithoutExtension($testBinary)

# Pause if we have queued too many parallel jobs
#$running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
#if ($running.Count -ge $maximumParalellJobs) {
# Write-Host ""
# Write-Host " Running tests in parallel on $($running.Count) projects." -ForegroundColor Cyan
# Write-Host " Next in queue is $projectName on $framework. This will take a bit, please wait..." -ForegroundColor Cyan
# $running | Wait-Job -Any | Out-Null
#}


if ($maximumParalellJobs -gt 1) {
# Pause if we have queued too many parallel jobs
$running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
if ($running.Count -ge $maximumParalellJobs) {
Write-Host ""
Write-Host " Running tests in parallel on $($running.Count) projects." -ForegroundColor Cyan
Write-Host " Next in queue is $projectName on $framework. This will take a bit, please wait..." -ForegroundColor Cyan
$running | Wait-Job -Any | Out-Null
}
}

$testResultDirectory = "$testResultsArtifactDirectory/$testOSName/$framework/$testPlatform/$testName"
if (!(Test-Path "$testResultDirectory")) {
New-Item "$testResultDirectory" -ItemType Directory -Force
}

Write-Host "Testing '$testBinary' on framework '$framework' and outputting test results to '$testResultDirectory/${{ parameters.testResultsFileName }}'..."
dotnet test "$testBinary" --framework "$framework" --blame --no-build --no-restore --logger:"console;verbosity=normal" --logger:"trx;LogFileName=${{ parameters.testResultsFileName }}" --results-directory:"$testResultDirectory" --blame-hang-timeout 10minutes --blame-hang-dump-type mini -- RunConfiguration.TargetPlatform=$testPlatform


$testExpression = "$testExpression -- RunConfiguration.TargetPlatform=$testPlatform"

#$scriptBlock = {
# param([string]$testBinary, [string]$fwork, [string]$testPlatform, [string]$testResultDirectory)
# dotnet test "$testBinary" --framework "$framework" --blame --no-build --no-restore --logger:"console;verbosity=normal" --logger:"trx;LogFileName=${{ parameters.testResultsFileName }}" --results-directory:"$testResultDirectory" --blame-hang-timeout 10minutes --blame-hang-dump-type mini -- RunConfiguration.TargetPlatform=$testPlatform > "$testResultDirectory/dotnet-vstest.log" 2> "$testResultDirectory/dotnet-vstest-error.log"
#}

# Execute the jobs in parallel
#Start-Job $scriptBlock -ArgumentList $testBinary,$fwork,$testPlatform,$testResultDirectory
if ($maximumParalellJobs -le 1) {
dotnet test "$testBinary" --framework "$framework" --blame --no-build --no-restore --logger:"console;verbosity=normal" --logger:"trx;LogFileName=${{ parameters.testResultsFileName }}" --results-directory:"$testResultDirectory" --blame-hang-timeout 10minutes --blame-hang-dump-type mini -- RunConfiguration.TargetPlatform=$testPlatform
} else {

$scriptBlock = {
param([string]$testName, [string]$testBinary, [string]$framework, [string]$testPlatform, [string]$testResultDirectory)
dotnet test "$testBinary" --framework "$framework" --blame --no-build --no-restore --logger:"console;verbosity=normal" --logger:"trx;LogFileName=${{ parameters.testResultsFileName }}" --results-directory:"$testResultDirectory" --blame-hang-timeout 10minutes --blame-hang-dump-type mini -- RunConfiguration.TargetPlatform=$testPlatform > "$testResultDirectory/dotnet-vstest.log" 2> "$testResultDirectory/dotnet-vstest-error.log"
}

# Avoid dotnet test collisions by delaying for 500ms
Start-Sleep -Milliseconds 500

# Execute the jobs in parallel
Start-Job -Name "$testName,$framework,$testPlatform" -ScriptBlock $scriptBlock -ArgumentList $testName,$testBinary,$framework,$testPlatform,$testResultDirectory
}
}
}

foreach ($framework in $testTargetFrameworks) {
RunTests -Framework "$framework" -FileRegexPattern "$testBinaryFilesPattern"
}

# Wait for it all to complete
#do {
# $running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
# if ($running.Count -gt 0) {
# Write-Host ""
# Write-Host " Almost finished, only $($running.Count) projects left..." -ForegroundColor Cyan
# $running | Wait-Job -Any
# }
#} until ($running.Count -eq 0)
if ($maximumParalellJobs -gt 1) {
# Wait for it all to complete
do {
$running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
if ($running.Count -gt 0) {
Write-Host ""
Write-Host " Almost finished, only $($running.Count) projects left..." -ForegroundColor Cyan
[int]$number = 0
foreach ($runningJob in $running) {
$number++
$jobName = $runningJob | Select -ExpandProperty Name
Write-Host "$number. $jobName"
}
$running | Wait-Job -Any
}
} until ($running.Count -eq 0)
}

$global:LASTEXITCODE = 0 # Force the script to continue on error
displayName: 'dotnet test ${{ parameters.testTargetFrameworks }}'
Expand All @@ -144,7 +232,7 @@ steps:
# Publish Test Results task or the (deprecated) TfsPublisher
# our only other option is to make a task for every supported
# platform and project and update it whenever a new platform
# is targeted or test project is created in ICU4N.
# is targeted or test project is created in J2N.

- template: 'publish-test-results-for-test-projects.yml'
parameters:
Expand Down
Loading