Only run test on centos8, refactor ProcessEntryName, revert GetTarballContentNames changes

This commit is contained in:
Ella Hathaway 2023-08-31 21:15:01 +00:00
parent 7bb5b649af
commit f891d66573
9 changed files with 28 additions and 16753 deletions

View file

@ -26,6 +26,7 @@ jobs:
targetRid: centos.8-x64
architecture: x64
dotnetDotnetRunId: ${{ parameters.dotnetDotnetRunId }}
excludeArtifactsSize: false
- template: templates/jobs/sdk-diff-tests.yml
parameters:

View file

@ -11,6 +11,10 @@ parameters:
- name: dotnetDotnetRunId
type: string
- name: excludeArtifactsSize
type: boolean
default: true
jobs:
- job: ${{ parameters.buildName }}_${{ parameters.architecture }}
timeoutInMinutes: 150
@ -117,7 +121,8 @@ jobs:
-e SMOKE_TESTS_RUNNING_IN_CI=true
-e SMOKE_TESTS_TARGET_RID=${{ parameters.targetRid }}
-e SMOKE_TESTS_PORTABLE_RID=linux-${{ parameters.architecture }}
-e SMOKE_TESTS_CUSTOM_PACKAGES_PATH=
-e SMOKE_TESTS_CUSTOM_PACKAGES_PATH=
-e SMOKE_TESTS_EXCLUDE_ARTIFACTSSIZE=${{ parameters.excludeArtifactsSize }}
displayName: Run Tests
workingDirectory: $(Build.SourcesDirectory)

View file

@ -19,7 +19,8 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests;
public class ArtifactsSizeTest : SmokeTests
{
private static readonly string BaselineFilePath = BaselineHelper.GetBaselineFilePath($"ArtifactsSizes/{Config.TargetRid}.txt");
private static readonly Dictionary<string, long> BaselineFileContent = new Dictionary<string, long>();
private readonly Dictionary<string, long> BaselineFileContent = new();
private Dictionary<string, int> FilePathCountMap = new();
private const int SizeThresholdPercentage = 25;
@ -40,7 +41,7 @@ public class ArtifactsSizeTest : SmokeTests
}
}
[SkippableFact(new[] { Config.SourceBuiltArtifactsPathEnv, Config.SdkTarballPathEnv, Config.TargetRidEnv }, skipOnNullOrWhiteSpaceEnv: true)]
[SkippableFact(new[] { Config.SourceBuiltArtifactsPathEnv, Config.SdkTarballPathEnv, Config.TargetRidEnv, Config.ExcludeArtifactsSizeEnv }, skipOnNullOrWhiteSpaceEnv: true, skipOnTrueEnv: true)]
public void CompareArtifactsToBaseline()
{
Assert.NotNull(Config.SourceBuiltArtifactsPath);
@ -53,13 +54,12 @@ public class ArtifactsSizeTest : SmokeTests
Utilities.ExtractTarball(Config.SdkTarballPath, tempTarballDir, OutputHelper);
Utilities.ExtractTarball(Config.SourceBuiltArtifactsPath, tempTarballDir, OutputHelper);
var filePathCountMap = new Dictionary<string, int>();
(string FilePath, long Bytes)[] tarEntries = Directory.EnumerateFiles(tempTarballDir, "*", SearchOption.AllDirectories)
.Where(filepath => !filepath.Contains("SourceBuildReferencePackages"))
.Select(filePath =>
{
string result = filePath.Substring(tempTarballDir.Length + 1);
result = ProcessEntryName(result, filePathCountMap);
result = ProcessFilePath(result);
return (FilePath: result, Bytes: new FileInfo(filePath).Length);
})
.OrderBy(entry => entry.FilePath)
@ -90,17 +90,24 @@ public class ArtifactsSizeTest : SmokeTests
}
}
private string ProcessEntryName(string originalName, Dictionary<string, int> filePathCountMap)
private string ProcessFilePath(string originalPath)
{
string result = BaselineHelper.RemoveRids(originalName);
string result = BaselineHelper.RemoveRids(originalPath);
result = BaselineHelper.RemoveVersions(result);
return AddDifferenciatingSuffix(result);
}
// Because version numbers are abstracted, it is possible to have duplicate FilePath entries.
// This code adds a numeric suffix to differentiate duplicate FilePath entries.
private string AddDifferenciatingSuffix(string filePath)
{
string[] patterns = {@"x\.y\.z", @"x\.y(?!\.z)"};
int matchIndex = -1;
string matchPattern = "";
foreach (string pattern in patterns)
{
MatchCollection matches = Regex.Matches(result, pattern);
MatchCollection matches = Regex.Matches(filePath, pattern);
if (matches.Count > 0)
{
@ -114,16 +121,16 @@ public class ArtifactsSizeTest : SmokeTests
if (matchIndex != -1)
{
int count = filePathCountMap.TryGetValue(result, out count) ? count : 0;
filePathCountMap[result] = count + 1;
int count = FilePathCountMap.TryGetValue(filePath, out count) ? count : 0;
FilePathCountMap[filePath] = count + 1;
if (count > 0)
{
result = result.Substring(0, matchIndex) + $"{matchPattern}-{count}" + result.Substring(matchIndex + matchPattern.Length);
return filePath.Substring(0, matchIndex) + $"{matchPattern}-{count}" + filePath.Substring(matchIndex + matchPattern.Length);
}
}
return result;
return filePath;
}
private void CompareFileSizes(string filePath, long fileSize, long baselineSize)

View file

@ -11,6 +11,7 @@ internal static class Config
{
public const string DotNetDirectoryEnv = "SMOKE_TESTS_DOTNET_DIR";
public const string ExcludeOmniSharpEnv = "SMOKE_TESTS_EXCLUDE_OMNISHARP";
public const string ExcludeArtifactsSizeEnv = "SMOKE_TESTS_EXCLUDE_ARTIFACTSSIZE";
public const string MsftSdkTarballPathEnv = "SMOKE_TESTS_MSFT_SDK_TARBALL_PATH";
public const string PoisonReportPathEnv = "SMOKE_TESTS_POISON_REPORT_PATH";
public const string PortableRidEnv = "SMOKE_TESTS_PORTABLE_RID";

View file

@ -48,10 +48,7 @@ public static class Utilities
}
}
public static IEnumerable<string> GetTarballContentNames(string tarballPath) =>
GetTarballContent(tarballPath).Select(entry => entry.Name);
public static IEnumerable<TarEntry> GetTarballContent(string tarballPath)
public static IEnumerable<string> GetTarballContentNames(string tarballPath)
{
using FileStream fileStream = File.OpenRead(tarballPath);
using GZipStream decompressorStream = new(fileStream, CompressionMode.Decompress);
@ -60,7 +57,7 @@ public static class Utilities
TarEntry entry;
while ((entry = reader.GetNextEntry()) is not null)
{
yield return entry;
yield return entry.Name;
}
}