Skip to content

Commit

Permalink
[WIP] Introduce Phd
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyAkinshin committed Mar 10, 2024
1 parent 68b7416 commit 53cb18c
Show file tree
Hide file tree
Showing 165 changed files with 3,269 additions and 99 deletions.
20 changes: 20 additions & 0 deletions src/Perfolizer/Perfolizer.Tests/Common/PrecisionHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Perfolizer.Mathematics.Common;

namespace Perfolizer.Tests.Common;

public class PrecisionHelperTests
{
[Theory]
[InlineData(2, 1.0)]
[InlineData(1, 10.0)]
[InlineData(1, 100.0)]
[InlineData(3, 0.1)]
[InlineData(4, 0.01)]
[InlineData(5, 0.001)]
[InlineData(5, 0.001, 10.0)]
public void PrecisionHelperTest(int expected, params double[] values)
{
int actual = PrecisionHelper.GetOptimalPrecision(values);
Assert.Equal(expected, actual);
}
}
17 changes: 0 additions & 17 deletions src/Perfolizer/Perfolizer.Tests/Common/SampleTests.cs

This file was deleted.

35 changes: 35 additions & 0 deletions src/Perfolizer/Perfolizer.Tests/Helpers/CpuBrandHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Text;
using Perfolizer.Helpers;
using Perfolizer.Phd.Dto;
using Perfolizer.Tests.Infra;

namespace Perfolizer.Tests.Helpers
{
[Collection("VerifyTests")]
public class CpuBrandHelperTests
{
[Fact]
public Task CpuBrandHelperTest01()
{
var captions = new StringBuilder();
foreach (string? processorName in new[] { null, "", "Intel" })
foreach (int? physicalProcessorCount in new int?[] { null, 0, 1, 2 })
foreach (int? physicalCoreCount in new int?[] { null, 0, 1, 2 })
foreach (int? logicalCoreCount in new int?[] { null, 0, 1, 2 })
{
var cpu = new PhdCpu
{
ProcessorName = processorName,
PhysicalProcessorCount = physicalProcessorCount,
PhysicalCoreCount = physicalCoreCount,
LogicalCoreCount = logicalCoreCount,
};

captions.AppendLine(cpu.ToFullBrandName());
}

var settings = VerifyHelper.CreateSettings("Cpu");
return Verifier.Verify(captions.ToString(), settings);
}
}
}
63 changes: 63 additions & 0 deletions src/Perfolizer/Perfolizer.Tests/Helpers/OsBrandHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Perfolizer.Helpers;

namespace Perfolizer.Tests.Helpers;

public class OsBrandHelperTests(ITestOutputHelper output)
{
private void Check(string actual, string expected)
{
output.WriteLine("LENGTH : " + actual.Length);
output.WriteLine("ACTUAL : " + actual);
output.WriteLine("EXPECTED : " + expected);
Assert.Equal(expected, actual);

// The line with OsBrandString is one of the longest lines in the summary.
// When people past in on GitHub, it can be a reason of an ugly horizontal scrollbar.
// To avoid this, we are trying to minimize this line and use the minimum possible number of characters.
// In this test, we check that the length of the OS brand string for typical Windows versions
// is less than 61 characters.
const int maxLength = 61;
Assert.True(actual.Length <= maxLength, $"The brand string name length should be <= {maxLength}");
}

[Theory]
[InlineData("6.3.9600", "Windows 8.1 (6.3.9600)")]
[InlineData("10.0.14393", "Windows 10 (10.0.14393/1607/AnniversaryUpdate/Redstone1)")]
public void WindowsIsPrettified(string originalVersion, string prettifiedName)
=> Check(OsBrandHelper.Prettify("Windows", originalVersion), prettifiedName);

[Theory]
[InlineData("10.0.10240", 17797, "Windows 10 (10.0.10240.17797/1507/RTM/Threshold1)")]
[InlineData("10.0.10586", 1478, "Windows 10 (10.0.10586.1478/1511/NovemberUpdate/Threshold2)")]
[InlineData("10.0.14393", 2156, "Windows 10 (10.0.14393.2156/1607/AnniversaryUpdate/Redstone1)")]
[InlineData("10.0.15063", 997, "Windows 10 (10.0.15063.997/1703/CreatorsUpdate/Redstone2)")]
[InlineData("10.0.16299", 334, "Windows 10 (10.0.16299.334/1709/FallCreatorsUpdate/Redstone3)")]
[InlineData("10.0.17134", 48, "Windows 10 (10.0.17134.48/1803/April2018Update/Redstone4)")]
[InlineData("10.0.17763", 1, "Windows 10 (10.0.17763.1/1809/October2018Update/Redstone5)")]
[InlineData("10.0.18362", 693, "Windows 10 (10.0.18362.693/1903/May2019Update/19H1)")]
[InlineData("10.0.18363", 657, "Windows 10 (10.0.18363.657/1909/November2019Update/19H2)")]
[InlineData("10.0.19041", 1, "Windows 10 (10.0.19041.1/2004/May2020Update/20H1)")]
[InlineData("10.0.19042", 746, "Windows 10 (10.0.19042.746/20H2/October2020Update)")]
[InlineData("10.0.19043", 964, "Windows 10 (10.0.19043.964/21H1/May2021Update)")]
[InlineData("10.0.19044", 1147, "Windows 10 (10.0.19044.1147/21H2/November2021Update)")]
[InlineData("10.0.19099", 1729, "Windows 10 (10.0.19099.1729)")]
[InlineData("10.0.19045", 0, "Windows 10 (10.0.19045.0/22H2/2022Update)")]
[InlineData("10.0.22000", 348, "Windows 11 (10.0.22000.348/21H2/SunValley)")]
[InlineData("10.0.22518", 1012, "Windows 11 (10.0.22518.1012)")]
[InlineData("10.0.22621", 0, "Windows 11 (10.0.22621.0/22H2/2022Update/SunValley2)")]
[InlineData("10.0.22631", 2428, "Windows 11 (10.0.22631.2428/23H2/2023Update/SunValley3)")]
public void WindowsWithUbrIsPrettified(string originalVersion, int ubr, string prettifiedName)
=> Check(OsBrandHelper.Prettify("Windows", originalVersion, ubr.ToString()), prettifiedName);

[Theory]
[InlineData("macOS 10.12.6 (16G29)", "Darwin 16.7.0", "macOS Sierra 10.12.6 (16G29) [Darwin 16.7.0]")]
[InlineData("macOS 10.13.4 (17E199)", "Darwin 17.5.0", "macOS High Sierra 10.13.4 (17E199) [Darwin 17.5.0]")]
[InlineData("macOS 10.15.4 (19E266)", "Darwin 19.4.0", "macOS Catalina 10.15.4 (19E266) [Darwin 19.4.0]")]
[InlineData("macOS 11.1 (20C69)", "Darwin 20.2.0", "macOS Big Sur 11.1 (20C69) [Darwin 20.2.0]")]
[InlineData("macOS 11.3.1 (20E241)", "Darwin 20.4.0", "macOS Big Sur 11.3.1 (20E241) [Darwin 20.4.0]")]
[InlineData("macOS 12.1 (21C52)", "Darwin 21.2.0", "macOS Monterey 12.1 (21C52) [Darwin 21.2.0]")]
[InlineData("macOS 13.0.1 (22A400)", "Darwin 22.1.0", "macOS Ventura 13.0.1 (22A400) [Darwin 22.1.0]")]
[InlineData("macOS 14.0.0", "Darwin 23.0.0", "macOS Sonoma 14.0.0 [Darwin 23.0.0]")]
public void MacOSXIsPrettified(string systemVersion, string kernelVersion, string prettifiedName)
=> Check(OsBrandHelper.PrettifyMacOSX(systemVersion, kernelVersion), prettifiedName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Perfolizer.Helpers;
using Perfolizer.Horology;
using Perfolizer.Mathematics.Common;
using Perfolizer.Phd.Dto;

namespace Perfolizer.Tests.Helpers;

// ReSharper disable StringLiteralTypo
// ReSharper disable CommentTypo
public class ProcessorBrandStringTests
{
[Theory]
[InlineData("Intel(R) Pentium(TM) G4560 CPU @ 3.50GHz", "Intel Pentium G4560 CPU 3.50GHz")]
[InlineData("Intel(R) Core(TM) i7 CPU 970 @ 3.20GHz", "Intel Core i7 CPU 970 3.20GHz (Nehalem)")] // Nehalem/Westmere/Gulftown
[InlineData("Intel(R) Core(TM) i7-920 CPU @ 2.67GHz", "Intel Core i7-920 CPU 2.67GHz (Nehalem)")]
[InlineData("Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz", "Intel Core i7-2600 CPU 3.40GHz (Sandy Bridge)")]
[InlineData("Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz", "Intel Core i7-3770 CPU 3.40GHz (Ivy Bridge)")]
[InlineData("Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz", "Intel Core i7-4770K CPU 3.50GHz (Haswell)")]
[InlineData("Intel(R) Core(TM) i7-5775R CPU @ 3.30GHz", "Intel Core i7-5775R CPU 3.30GHz (Broadwell)")]
[InlineData("Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz", "Intel Core i7-6700HQ CPU 2.60GHz (Skylake)")]
[InlineData("Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz", "Intel Core i7-7700 CPU 3.60GHz (Kaby Lake)")]
[InlineData("Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz ", "Intel Core i7-8650U CPU 1.90GHz (Kaby Lake R)")]
[InlineData("Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz", "Intel Core i7-8700K CPU 3.70GHz (Coffee Lake)")]
public void IntelCoreIsPrettified(string processorName, string cpuBrandName) =>
Assert.Equal(cpuBrandName, new PhdCpu { ProcessorName = processorName }.ToShortBrandName());

[Theory]
[InlineData("Intel(R) Pentium(TM) G4560 CPU @ 3.50GHz", "Intel Pentium G4560 CPU 3.50GHz (Max: 3.70GHz)", 3.7)]
[InlineData("Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz", "Intel Core i5-2500 CPU 3.30GHz (Max: 3.70GHz) (Sandy Bridge)", 3.7)]
[InlineData("Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz", "Intel Core i7-2600 CPU 3.40GHz (Max: 3.70GHz) (Sandy Bridge)", 3.7)]
[InlineData("Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz", "Intel Core i7-3770 CPU 3.40GHz (Max: 3.50GHz) (Ivy Bridge)", 3.5)]
[InlineData("Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz", "Intel Core i7-4770K CPU 3.50GHz (Max: 3.60GHz) (Haswell)", 3.6)]
[InlineData("Intel(R) Core(TM) i7-5775R CPU @ 3.30GHz", "Intel Core i7-5775R CPU 3.30GHz (Max: 3.40GHz) (Broadwell)", 3.4)]
public void CoreIsPrettifiedWithDiffFrequencies(string processorName, string brandName, double nominalFrequency)
{
var cpu = new PhdCpu
{
ProcessorName = processorName,
NominalFrequencyHz = Frequency.FromGHz(nominalFrequency).Hertz.RoundToLong()
};
Assert.Equal(brandName, cpu.ToShortBrandName(includeMaxFrequency: true));
}

[Theory]
[InlineData("AMD Ryzen 7 2700X Eight-Core Processor", "AMD Ryzen 7 2700X 4.10GHz", 4.1, 8, 16)]
[InlineData("AMD Ryzen 7 2700X Eight-Core Processor", "AMD Ryzen 7 2700X Eight-Core Processor 4.10GHz", 4.1, null, null)]
public void AmdIsPrettifiedWithDiffFrequencies(
string processorName,
string brandName,
double nominalFrequency,
int? physicalCoreCount,
int? logicalCoreCount)
{
var cpu = new PhdCpu
{
ProcessorName = processorName,
NominalFrequencyHz = Frequency.FromGHz(nominalFrequency).Hertz.RoundToLong(),
PhysicalCoreCount = physicalCoreCount,
LogicalCoreCount = logicalCoreCount
};
Assert.Equal(brandName, cpu.ToShortBrandName(includeMaxFrequency: true));
}

[Theory]
[InlineData("8130U", "Kaby Lake")]
[InlineData("9900K", "Coffee Lake")]
[InlineData("8809G", "Kaby Lake G")]
public void IntelCoreMicroarchitecture(string modelNumber, string microarchitecture)
{
Assert.Equal(microarchitecture, CpuBrandHelper.ParseIntelCoreMicroarchitecture(modelNumber));
}

[Theory]
[InlineData("", "Unknown processor")]
[InlineData(null, "Unknown processor")]
public void UnknownProcessorDoesNotThrow(string? processorName, string brandName)
{
var cpu = new PhdCpu { ProcessorName = processorName };
Assert.Equal(brandName, cpu.ToShortBrandName(includeMaxFrequency: true));
}
}
Loading

0 comments on commit 53cb18c

Please sign in to comment.