Syntax fixes, regex & baseline updates

This commit is contained in:
Ella Hathaway 2023-08-24 22:26:13 +00:00
parent ed23432b07
commit 70cac71160
7 changed files with 7810 additions and 7781 deletions

View file

@ -31,13 +31,12 @@ public class ArtifactsSizeTest : SmokeTests
string[] baselineFileContent = File.ReadAllLines(BaselineFilePath);
foreach (string entry in baselineFileContent)
{
string[] splitEntry = entry.Split(':');
BaselineFileContent[splitEntry[0].Trim()] = long.Parse(splitEntry[1].Trim());
string[] splitEntry = entry.Split(':', StringSplitOptions.TrimEntries);
BaselineFileContent[splitEntry[0]] = long.Parse(splitEntry[1]);
}
}
else
{
Assert.True(Directory.Exists(BaselineHelper.GetBaselineFilePath("ArtifactsSizes/")));
Assert.False(true, $"Baseline file `{BaselineFilePath}' does not exist. Please create the baseline file then rerun the test.");
}
}
@ -52,15 +51,12 @@ public class ArtifactsSizeTest : SmokeTests
IEnumerable<TarEntry> artifactsTarEntries = Utilities.GetTarballContent(Config.SourceBuiltArtifactsPath).Where(entry => entry.EntryType == TarEntryType.RegularFile);
IEnumerable<TarEntry> sdkTarEntries = Utilities.GetTarballContent(Config.SdkTarballPath).Where(entry => entry.EntryType == TarEntryType.RegularFile);
Dictionary<string, int> fileNameCountMap = new Dictionary<string, int>();
(string FilePath, long Bytes)[] tarEntries = sdkTarEntries.Concat(artifactsTarEntries)
.Select(entry =>
{
string result = BaselineHelper.RemoveVersions(entry.Name);
result = BaselineHelper.RemoveRids(result);
result = BaselineHelper.RemoveNetTfmPaths(result);
string result = ProcessEntryName(entry.Name, fileNameCountMap);
return (FilePath: result, Bytes: entry.Length);
})
.OrderBy(entry => entry.FilePath)
.ToArray();
@ -88,13 +84,42 @@ public class ArtifactsSizeTest : SmokeTests
}
}
private string ProcessEntryName(string originalName, Dictionary<string, int> fileNameCountMap)
{
string result = BaselineHelper.RemoveRids(originalName);
result = BaselineHelper.RemoveVersions(result);
string pattern = @"x\.y\.z";
MatchCollection matches = Regex.Matches(result, pattern);
if (matches.Count > 0)
{
int count = fileNameCountMap.TryGetValue(result, out int value) ? value : 0;
fileNameCountMap[result] = count + 1;
if (count > 0)
{
int lastIndex = matches[matches.Count - 1].Index;
result = result.Substring(0, lastIndex) + $"x.y.z-{count}" + result.Substring(lastIndex + pattern.Length - 2);
}
}
return result;
}
private void CompareFileSizes(string filePath, long fileSize, long baselineSize)
{
if (fileSize == 0 && baselineSize != 0)
{
OutputHelper.LogWarningMessage($"'{filePath}' is now 0 bytes. It was {baselineSize} bytes");
}
else if (fileSize != 0 && baselineSize == 0)
{
OutputHelper.LogWarningMessage($"'{filePath}' is no longer 0 bytes. It is now {fileSize} bytes");
}
else if (baselineSize != 0 && Math.Abs(((fileSize - baselineSize) / (double)baselineSize) * 100) >= SizeThresholdPercentage)
{
OutputHelper.LogWarningMessage($"'{filePath}' increased in size by more than {SizeThresholdPercentage}%. It was originally {baselineSize} bytes and is now {fileSize} bytes");
}
}
}
}

View file

@ -81,6 +81,7 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests
{
(Process Process, string StdOut, string StdErr) diffResult =
ExecuteHelper.ExecuteProcess("git", $"diff --no-index {file1Path} {file2Path}", outputHelper);
Assert.Equal(1, diffResult.Process.ExitCode);
return diffResult.StdOut;
}
@ -103,11 +104,14 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests
{
// Remove semantic versions
// Regex source: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
Regex BuildVersionPattern = new(@"\d+(\.\d+)+([@-](alpha|preview|rc|rtm)(\.\d+)*)*");
string result = BuildVersionPattern.Replace(source, VersionPlaceholder);
Regex semanticVersionRegex = new(
$"(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)"
+ $"(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))"
+ $"?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?");
string result = semanticVersionRegex.Replace(source, VersionPlaceholder);
result = semanticVersionRegex.Replace(result, VersionPlaceholder);
return RemoveNetTfmPaths(result);
}