Skip to content

Commit de4a8e5

Browse files
authored
[tests] Build, run, and clean up missing test suites (#3859)
Context: https://dev.azure.com/devdiv/DevDiv/_build/results?buildId=3196159&view=artifacts I recently noticed the win-build-test-results artifact that we were uploading was enormous, even when all tests had passed. This was due to the fact that we weren't cleaning up after successful tests from the CodeBehind, CodeGen-MkBundle, and EmbeddedDSOs suites. I've also updated our result-packaging globbing to exclude NuGet packages from our test result zips to further reduce unnecessary uploading. This also identified an issue in our test execution. The three suites mentioned above are not running in any test stages against an installer. To address this our build pipeline has been updated to ensure these assemblies are built and uploaded during the Mac Build job, and then downloadedd and ran in the Test MSBuild - macOS job.
1 parent 4d2ac4a commit de4a8e5

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

build-tools/Xamarin.Android.Tools.BootstrapTasks/result-packaging.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<_TestResultFiles Include="$(XamarinAndroidSourcePath)bin\Test$(Configuration)\compatibility\*" />
2727
<_TestResultFiles Include="$(XamarinAndroidSourcePath)bin\Test$(Configuration)\logcat*" />
2828
<_TestResultFiles Include="$(XamarinAndroidSourcePath)bin\Test$(Configuration)\*log" />
29-
<_TestResultFiles Include="$(XamarinAndroidSourcePath)bin\Test$(Configuration)\temp\**\*">
29+
<_TestResultFiles Include="$(XamarinAndroidSourcePath)bin\Test$(Configuration)\temp\**\*" Exclude="$(XamarinAndroidSourcePath)bin\Test$(Configuration)\temp\packages\**">
3030
<SubDirectory>temp\</SubDirectory>
3131
</_TestResultFiles>
3232
<_TestResultFiles Include="$(XamarinAndroidSourcePath)bin\Test$(Configuration)\TestOutput-*.txt" />

build-tools/automation/azure-pipelines.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ stages:
6868
inputs:
6969
version: $(DotNetCoreVersion)
7070

71+
# Prepare and build everything
7172
- script: make prepare-update-mono V=1 CONFIGURATION=$(XA.Build.Configuration) PREPARE_CI=1 PREPARE_AUTOPROVISION=1
7273
displayName: make prepare-update-mono
7374

@@ -80,6 +81,25 @@ stages:
8081
- script: make jenkins V=1 CONFIGURATION=$(XA.Build.Configuration) PREPARE_CI=1 PREPARE_AUTOPROVISION=1
8182
displayName: make jenkins
8283

84+
# Build and package test assemblies
85+
- task: MSBuild@1
86+
displayName: msbuild tests/CodeBehind/UnitTests/CodeBehindUnitTests.csproj
87+
inputs:
88+
solution: $(System.DefaultWorkingDirectory)/tests/CodeBehind/UnitTests/CodeBehindUnitTests.csproj
89+
configuration: $(XA.Build.Configuration)
90+
91+
- task: MSBuild@1
92+
displayName: msbuild tests/CodeGen-MkBundle/Xamarin.Android.MakeBundle-UnitTests/Xamarin.Android.MakeBundle-UnitTests.csproj
93+
inputs:
94+
solution: $(System.DefaultWorkingDirectory)/tests/CodeGen-MkBundle/Xamarin.Android.MakeBundle-UnitTests/Xamarin.Android.MakeBundle-UnitTests.csproj
95+
configuration: $(XA.Build.Configuration)
96+
97+
- task: MSBuild@1
98+
displayName: msbuild tests/EmbeddedDSOs/EmbeddedDSO-UnitTests/EmbeddedDSO-UnitTests.csproj
99+
inputs:
100+
solution: $(System.DefaultWorkingDirectory)/tests/EmbeddedDSOs/EmbeddedDSO-UnitTests/EmbeddedDSO-UnitTests.csproj
101+
configuration: $(XA.Build.Configuration)
102+
83103
- script: |
84104
cp -r bin/$(XA.Build.Configuration)/bcl-tests bin/Test$(XA.Build.Configuration)/bcl-tests
85105
cp bin/Build$(XA.Build.Configuration)/ProfileAssemblies.projitems bin/Test$(XA.Build.Configuration)/bcl-tests/
@@ -91,6 +111,7 @@ stages:
91111
artifactName: $(TestAssembliesArtifactName)
92112
targetPath: bin/Test$(XA.Build.Configuration)
93113

114+
# Create installers
94115
- template: install-certificates.yml@yaml
95116
parameters:
96117
DeveloperIdApplication: $(developer-id-application)
@@ -549,6 +570,24 @@ stages:
549570
artifactName: $(TestAssembliesArtifactName)
550571
downloadPath: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)
551572

573+
- template: yaml-templates/run-nunit-tests.yaml
574+
parameters:
575+
testRunTitle: CodeBehindUnitTests - macOS
576+
testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/CodeBehind/CodeBehindUnitTests.dll
577+
testResultsFile: TestResult-CodeBehindUnitTests-macOS-$(XA.Build.Configuration).xml
578+
579+
- template: yaml-templates/run-nunit-tests.yaml
580+
parameters:
581+
testRunTitle: Xamarin.Android.MakeBundle-UnitTests - macOS
582+
testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/Xamarin.Android.MakeBundle-UnitTests.dll
583+
testResultsFile: TestResult-MakeBundleUnitTests-macOS-$(XA.Build.Configuration).xml
584+
585+
- template: yaml-templates/run-nunit-tests.yaml
586+
parameters:
587+
testRunTitle: EmbeddedDSOUnitTests - macOS
588+
testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/EmbeddedDSOUnitTests.dll
589+
testResultsFile: TestResult-EmbeddedDSOUnitTests-macOS-$(XA.Build.Configuration).xml
590+
552591
- template: yaml-templates/run-nunit-tests.yaml
553592
parameters:
554593
testRunTitle: Xamarin.Android.Build.Tests - macOS

tests/CodeBehind/UnitTests/BuildTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,15 @@ void RunTest (string testName, bool many, bool dtb, Action<TestProjectInfo, bool
553553
}
554554
} catch {
555555
CopyLogs (testInfo, false);
556+
foreach (var file in Directory.GetFiles (testInfo.OutputDirectory, "*.log", SearchOption.AllDirectories)) {
557+
TestContext.AddTestAttachment (file);
558+
}
556559
throw;
557560
}
561+
562+
// Clean up successful tests
563+
FileSystemUtils.SetDirectoryWriteable (testInfo.OutputDirectory);
564+
Directory.Delete (testInfo.OutputDirectory, recursive: true);
558565
}
559566

560567
bool WasParsedInParallel (TestProjectInfo testInfo)

tests/CodeGen-MkBundle/Xamarin.Android.MakeBundle-UnitTests/BuildTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ public void BuildProject ()
9090
Assert.That (success, Is.True, "Should have been built");
9191
}
9292

93+
[OneTimeTearDown]
94+
public void CleanUp ()
95+
{
96+
if (TestContext.CurrentContext.Result.FailCount == 0) {
97+
FileSystemUtils.SetDirectoryWriteable (TestOutputDir);
98+
Directory.Delete (TestOutputDir, recursive: true);
99+
}
100+
}
101+
93102
[Test]
94103
public void BinariesExist ()
95104
{

tests/EmbeddedDSOs/EmbeddedDSO-UnitTests/BuildTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ public void BuildProject ()
8383
androidSdkDir = AndroidSdkResolver.GetAndroidSdkPath ();
8484
}
8585

86+
[OneTimeTearDown]
87+
public void CleanUp ()
88+
{
89+
if (TestContext.CurrentContext.Result.FailCount == 0) {
90+
FileSystemUtils.SetDirectoryWriteable (TestOutputDir);
91+
Directory.Delete (TestOutputDir, recursive: true);
92+
}
93+
}
94+
8695
[Test]
8796
public void BinariesExist ()
8897
{

0 commit comments

Comments
 (0)