From 1c248e0b46877b22877c794221ebfc3b10429b8b Mon Sep 17 00:00:00 2001 From: Kevin Ransom Date: Mon, 1 May 2023 14:36:33 -0700 Subject: [PATCH 1/2] Move trim tests to separate AheadOfTime location and widen trim test to net472 and net7.0 --- azure-pipelines.yml | 11 +++--- tests/AheadOfTime/Directory.Build.props | 3 ++ tests/AheadOfTime/Directory.Build.targets | 3 ++ .../NuGet.Config | 2 +- .../Program.fs | 0 .../SelfContained_Trimming_Test.fsproj | 4 +-- .../SelfContained_Trimming_Test/check.cmd | 0 .../SelfContained_Trimming_Test/check.ps1 | 35 +++++++++++++++++++ tests/AheadOfTime/buildtools.proj | 32 +++++++++++++++++ .../SelfContained_Trimming_Test/check.ps1 | 23 ------------ 10 files changed, 83 insertions(+), 30 deletions(-) create mode 100644 tests/AheadOfTime/Directory.Build.props create mode 100644 tests/AheadOfTime/Directory.Build.targets rename tests/{projects/SelfContained_Trimming_Test => AheadOfTime}/NuGet.Config (89%) rename tests/{projects/SelfContained_Trimming_Test => AheadOfTime}/Program.fs (100%) rename tests/{projects => AheadOfTime}/SelfContained_Trimming_Test/SelfContained_Trimming_Test.fsproj (93%) rename tests/{projects => AheadOfTime}/SelfContained_Trimming_Test/check.cmd (100%) create mode 100644 tests/AheadOfTime/SelfContained_Trimming_Test/check.ps1 create mode 100644 tests/AheadOfTime/buildtools.proj delete mode 100644 tests/projects/SelfContained_Trimming_Test/check.ps1 diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9e8a716978b..192d43ed35e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -650,16 +650,19 @@ stages: displayName: Report dotnet SDK versions - script: .\Build.cmd $(_kind) -pack -c $(_BuildConfig) displayName: Initial build and prepare packages. - - script: dotnet publish -c $(_BuildConfig) -bl:\"./bin/$(_BuildConfig)/net7.0/win-x64/publish/Trimming.binlog\" + - script: dotnet publish -c Release -f:net472 -bl:"./artifacts/log/Release/AheadOfTime/SelfContained_Trimming_net472.binlog" displayName: Build and publish a trim test package. - workingDirectory: $(Build.SourcesDirectory)/tests/projects/SelfContained_Trimming_Test + workingDirectory: $(Build.SourcesDirectory)/tests/AheadOfTime/SelfContained_Trimming_Test + - script: dotnet publish -c Release -f:net7.0 -bl:"./artifacts/log/Release/AheadOfTime/SelfContained_Trimming_net7.0.binlog" + displayName: Build and publish a trim test package. + workingDirectory: $(Build.SourcesDirectory)/tests/AheadOfTime/SelfContained_Trimming_Test - script: .\check.cmd displayName: Check the state of the trimmed app. - workingDirectory: $(Build.SourcesDirectory)/tests/projects/SelfContained_Trimming_Test + workingDirectory: $(Build.SourcesDirectory)/tests/AheadOfTime/SelfContained_Trimming_Test - task: PublishPipelineArtifact@1 displayName: Publish Trim Tests Logs inputs: - targetPath: '$(Build.SourcesDirectory)/tests/projects/SelfContained_Trimming_Test/bin/$(_BuildConfig)/net7.0/win-x64/publish' + targetPath: './artifacts/log/Release/AheadOfTime' artifactName: 'Trim Test Logs Attempt $(System.JobAttempt) Logs $(_kind)' continueOnError: true condition: always() diff --git a/tests/AheadOfTime/Directory.Build.props b/tests/AheadOfTime/Directory.Build.props new file mode 100644 index 00000000000..bb5b23d29d0 --- /dev/null +++ b/tests/AheadOfTime/Directory.Build.props @@ -0,0 +1,3 @@ + + + diff --git a/tests/AheadOfTime/Directory.Build.targets b/tests/AheadOfTime/Directory.Build.targets new file mode 100644 index 00000000000..bb5b23d29d0 --- /dev/null +++ b/tests/AheadOfTime/Directory.Build.targets @@ -0,0 +1,3 @@ + + + diff --git a/tests/projects/SelfContained_Trimming_Test/NuGet.Config b/tests/AheadOfTime/NuGet.Config similarity index 89% rename from tests/projects/SelfContained_Trimming_Test/NuGet.Config rename to tests/AheadOfTime/NuGet.Config index 2a97bd3b1ce..62abe1e410c 100644 --- a/tests/projects/SelfContained_Trimming_Test/NuGet.Config +++ b/tests/AheadOfTime/NuGet.Config @@ -5,7 +5,7 @@ - + diff --git a/tests/projects/SelfContained_Trimming_Test/Program.fs b/tests/AheadOfTime/Program.fs similarity index 100% rename from tests/projects/SelfContained_Trimming_Test/Program.fs rename to tests/AheadOfTime/Program.fs diff --git a/tests/projects/SelfContained_Trimming_Test/SelfContained_Trimming_Test.fsproj b/tests/AheadOfTime/SelfContained_Trimming_Test/SelfContained_Trimming_Test.fsproj similarity index 93% rename from tests/projects/SelfContained_Trimming_Test/SelfContained_Trimming_Test.fsproj rename to tests/AheadOfTime/SelfContained_Trimming_Test/SelfContained_Trimming_Test.fsproj index 06b29764abb..026a3f391a8 100644 --- a/tests/projects/SelfContained_Trimming_Test/SelfContained_Trimming_Test.fsproj +++ b/tests/AheadOfTime/SelfContained_Trimming_Test/SelfContained_Trimming_Test.fsproj @@ -2,7 +2,7 @@ Exe - net7.0 + net472;net7.0 preview true true @@ -24,7 +24,7 @@ - + diff --git a/tests/projects/SelfContained_Trimming_Test/check.cmd b/tests/AheadOfTime/SelfContained_Trimming_Test/check.cmd similarity index 100% rename from tests/projects/SelfContained_Trimming_Test/check.cmd rename to tests/AheadOfTime/SelfContained_Trimming_Test/check.cmd diff --git a/tests/AheadOfTime/SelfContained_Trimming_Test/check.ps1 b/tests/AheadOfTime/SelfContained_Trimming_Test/check.ps1 new file mode 100644 index 00000000000..914c3fd9105 --- /dev/null +++ b/tests/AheadOfTime/SelfContained_Trimming_Test/check.ps1 @@ -0,0 +1,35 @@ +function CheckTrim($tfm, $expected_len) { + Write-Host "Verify trimming ${tfm}: Expected length: ${expected_len}" + + $cwd = Get-Location + Set-Location (Join-Path $PSScriptRoot "bin\Release\${tfm}\win-x64\publish\") + $output = .\SelfContained_Trimming_Test.exe + Set-Location ${cwd} + + # Checking that it is actually running. + if (-not ($LASTEXITCODE -eq 0)) + { + Write-Error "Test failed with exit code ${LASTEXITCODE}" -ErrorAction Stop + } + + # Checking that the output is as expected. + $expected = "All tests passed" + if (-not ($output -eq $expected)) + { + Write-Error "Test failed with unexpected output:`nExpected:`n`t${expected}`nActual`n`t${output}" -ErrorAction Stop + } + + # Checking that the trimmed FSharp.Core binary is of expected size (needs adjustments if test is updated). + $file = Get-Item (Join-Path $PSScriptRoot "bin\Release\net7.0\win-x64\publish\FSharp.Core.dll") + $file_len = $file.Length + if (-not ($file_len -eq $expected_len)) + { + Write-Error "Test failed with unexpected ${tfm} - trimmed FSharp.Core length:`nExpected:`n`t${expected_len} Bytes`nActual:`n`t${file_len} Bytes`nEither codegen or trimming logic have changed. Please investigate and update expected dll size or report an issue." -ErrorAction Stop + } +} + +# Check net472 trimmed assemblies +CheckTrim -tfm "net472" -expected_len 287744 + +# Check net7.0 trimmed assemblies +CheckTrim -tfm "net7.0" -expected_len 287744 diff --git a/tests/AheadOfTime/buildtools.proj b/tests/AheadOfTime/buildtools.proj new file mode 100644 index 00000000000..467b217ec02 --- /dev/null +++ b/tests/AheadOfTime/buildtools.proj @@ -0,0 +1,32 @@ + + + + Release + $(NoWarn);NU1504 + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/projects/SelfContained_Trimming_Test/check.ps1 b/tests/projects/SelfContained_Trimming_Test/check.ps1 deleted file mode 100644 index 0c959cb1715..00000000000 --- a/tests/projects/SelfContained_Trimming_Test/check.ps1 +++ /dev/null @@ -1,23 +0,0 @@ -$output = .\bin\Release\net7.0\win-x64\publish\SelfContained_Trimming_Test.exe - -# Checking that it is actually running. -if (-not ($LASTEXITCODE -eq 0)) -{ - Write-Error "Test failed with exit code ${LASTEXITCODE}" -ErrorAction Stop -} - -# Checking that the output is as expected. -$expected = "All tests passed" -if (-not ($output -eq $expected)) -{ - Write-Error "Test failed with unexpected output:`nExpected:`n`t${expected}`nActual`n`t${output}" -ErrorAction Stop -} - -# Checking that FSharp.Core binary is of expected size (needs adjustments if test is updated). -$expected_len = 287744 # In bytes -$file = Get-Item .\bin\Release\net7.0\win-x64\publish\FSharp.Core.dll -$file_len = $file.Length -if (-not ($file_len -eq $expected_len)) -{ - Write-Error "Test failed with unexpected FSharp.Core length:`nExpected:`n`t${expected_len} Bytes`nActual:`n`t${file_len} Bytes`nEither codegen or trimming logic have changed. Please investigate and update expected dll size or report an issue." -ErrorAction Stop -} From 595dbcfec2fdad573c079e6a5ef99f26a5b2fa42 Mon Sep 17 00:00:00 2001 From: "Kevin Ransom (msft)" Date: Mon, 1 May 2023 19:57:49 -0700 Subject: [PATCH 2/2] trimming doesn't work for tfm net472 --- tests/AheadOfTime/SelfContained_Trimming_Test/check.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/AheadOfTime/SelfContained_Trimming_Test/check.ps1 b/tests/AheadOfTime/SelfContained_Trimming_Test/check.ps1 index 914c3fd9105..5121275bb96 100644 --- a/tests/AheadOfTime/SelfContained_Trimming_Test/check.ps1 +++ b/tests/AheadOfTime/SelfContained_Trimming_Test/check.ps1 @@ -20,7 +20,7 @@ function CheckTrim($tfm, $expected_len) { } # Checking that the trimmed FSharp.Core binary is of expected size (needs adjustments if test is updated). - $file = Get-Item (Join-Path $PSScriptRoot "bin\Release\net7.0\win-x64\publish\FSharp.Core.dll") + $file = Get-Item (Join-Path $PSScriptRoot "bin\Release\${tfm}\win-x64\publish\FSharp.Core.dll") $file_len = $file.Length if (-not ($file_len -eq $expected_len)) { @@ -28,8 +28,8 @@ function CheckTrim($tfm, $expected_len) { } } -# Check net472 trimmed assemblies -CheckTrim -tfm "net472" -expected_len 287744 +# Check net472 trimmed assemblies trimming doesn't work for tfm net472 +### CheckTrim -tfm "net472" -expected_len 287744 # Check net7.0 trimmed assemblies CheckTrim -tfm "net7.0" -expected_len 287744