From 25491ae33963e23e9fb3a41c1ab76781689a7cab Mon Sep 17 00:00:00 2001 From: Nikola Milosavljevic Date: Fri, 13 Oct 2023 11:30:45 -0700 Subject: [PATCH] Validate sourcelinks of all source-built symbols (#17477) --- .../SourcelinkTests.cs | 89 +++++++++---------- 1 file changed, 41 insertions(+), 48 deletions(-) diff --git a/src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SourcelinkTests.cs b/src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SourcelinkTests.cs index dc08c3650..0fc8735d9 100644 --- a/src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SourcelinkTests.cs +++ b/src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SourcelinkTests.cs @@ -14,6 +14,15 @@ using Xunit.Abstractions; namespace Microsoft.DotNet.SourceBuild.SmokeTests; +/// +/// Separate test collection for Sourcelink tests. This is needed due to intra-test parallelization, +/// which can cause less CPU time to be allocated to other tests. +/// This would make other tests run too long and fail due to timeouts. +/// +[CollectionDefinition(nameof(SourcelinkTestCollection), DisableParallelization = true)] +public class SourcelinkTestCollection { } + +[Collection(nameof(SourcelinkTestCollection))] public class SourcelinkTests : SdkTests { private static string SourcelinkRoot { get; } = Path.Combine(Directory.GetCurrentDirectory(), nameof(SourcelinkTests)); @@ -26,24 +35,40 @@ public class SourcelinkTests : SdkTests [SkippableFact(Config.SourceBuiltArtifactsPathEnv, skipOnNullOrWhiteSpaceEnv: true)] public void VerifySourcelinks() { - if (Directory.Exists(SourcelinkRoot)) + try + { + if (Directory.Exists(SourcelinkRoot)) + { + Directory.Delete(SourcelinkRoot, true); + } + Directory.CreateDirectory(SourcelinkRoot); + + string symbolsRoot = Directory.CreateDirectory(Path.Combine(SourcelinkRoot, "symbols")).FullName; + + // We are validating dotnet-symbols-all-*.tar.gz which contains all source-built symbols, including + // SDK-specific symbols that are also packaged in dotnet-symbols-sdk-*.tar.gz. + Utilities.ExtractTarball( + Utilities.GetFile(Path.GetDirectoryName(Config.SourceBuiltArtifactsPath), "dotnet-symbols-all-*.tar.gz"), + symbolsRoot, + OutputHelper); + + IList failedFiles = ValidateSymbols(symbolsRoot, InitializeSourcelinkTool()); + + if (failedFiles.Count > 0) + { + OutputHelper.WriteLine($"Sourcelink verification failed for the following files:"); + foreach (string file in failedFiles) + { + OutputHelper.WriteLine(file); + } + } + + Assert.True(failedFiles.Count == 0); + } + finally { Directory.Delete(SourcelinkRoot, true); } - Directory.CreateDirectory(SourcelinkRoot); - - IList failedFiles = ValidateSymbols(ExtractSymbolsPackages(GetAllSymbolsPackages()), InitializeSourcelinkTool()); - - if (failedFiles.Count > 0) - { - OutputHelper.WriteLine($"Sourcelink verification failed for the following files:"); - foreach (string file in failedFiles) - { - OutputHelper.WriteLine(file); - } - } - - Assert.True(failedFiles.Count == 0); } /// @@ -67,38 +92,6 @@ public class SourcelinkTests : SdkTests return Utilities.GetFile(extractedToolPath, SourcelinkToolBinaryFilename); } - private IEnumerable GetAllSymbolsPackages() - { - /* - At the moment we validate sourcelinks from runtime symbols package. - The plan is to make symbols, from all repos, available in source-build artifacts. - Once that's available, this code will be modified to validate all available symbols. - Tracking issue: https://github.com/dotnet/source-build/issues/3612 - */ - - // Runtime symbols package lives in the same directory as PSB artifacts. - // i.e. /artifacts/x64/Release/runtime/dotnet-runtime-symbols-fedora.36-x64-8.0.0-preview.7.23355.7.tar.gz - yield return Utilities.GetFile(Path.GetDirectoryName(Config.SourceBuiltArtifactsPath), "dotnet-runtime-symbols-*.tar.gz"); - } - - /// - /// Extracts symbols packages to subdirectories of the common symbols root directory. - /// - /// Path to common symbols root directory. - private string ExtractSymbolsPackages(IEnumerable packages) - { - string symbolsRoot = Directory.CreateDirectory(Path.Combine(SourcelinkRoot, "symbols")).FullName; - - foreach (string package in packages) - { - Assert.True(package.EndsWith(".tar.gz"), $"Package extension is not supported: {package}"); - DirectoryInfo targetDirInfo = Directory.CreateDirectory(Path.Combine(symbolsRoot, Path.GetFileNameWithoutExtension(package))); - Utilities.ExtractTarball(package, targetDirInfo.FullName, OutputHelper); - } - - return symbolsRoot; - } - private IList ValidateSymbols(string path, string sourcelinkToolPath) { Assert.True(Directory.Exists(path), $"Path, with symbol files to validate, does not exist: {path}"); @@ -114,7 +107,7 @@ public class SourcelinkTests : SdkTests OutputHelper, logOutput: false, excludeInfo: true, // Exclude info messages, as there can be 1,000+ processes - millisecondTimeout: 5000, + millisecondTimeout: 60000, configureCallback: (process) => DotNetHelper.ConfigureProcess(process, null)); if (executeResult.Process.ExitCode != 0)