using XFESystem.Core;
using Xunit;
namespace XFESystem.Core.Tests;
public sealed class PciGpuDiscoveryTests
{
private static PciGpuDiscovery Device(params PciGpuMemoryBar[] bars) => new(
"0000:01:00.0", 0x10DE, 0x2B85, 0x03, 0, true, 8, bars);
private static PciGpuMemoryBar Registers() => new(0, true, false, false, false, 0xF0000000, 0x1000000);
[Fact]
public void Discovers64BitFramebufferWithoutTruncatingItsAddress()
{
var device = Device(Registers(), new(1, true, false, true, true, 0x4000000000, 0x800000000),
new(2, false, false, false, false, 0, 0));
Assert.True(device.IsNvidiaDisplayController);
Assert.Empty(device.ValidateRegisterWindow());
Assert.Equal(0x4000000000ul, device.Bars[1].Address);
}
[Theory]
[InlineData(0x1002, 0x03)]
[InlineData(0x10DE, 0x04)]
public void RejectsOtherVendorsAndNvidiaAudioFunctions(int vendor, int classCode)
{
var device = Device(Registers()) with { VendorId = (ushort)vendor, ClassCode = (byte)classCode };
Assert.False(device.IsNvidiaDisplayController);
Assert.Contains("Not an NVIDIA", device.ValidateRegisterWindow());
}
[Fact]
public void RejectsFramebufferApertureInPlaceOfRegisterBar()
{
Assert.Contains("BAR 0", Device(Registers() with { IsPrefetchable = true }).ValidateRegisterWindow());
Assert.Contains("BAR 0", Device(Registers() with { IsIo = true }).ValidateRegisterWindow());
Assert.Contains("BAR 0", Device(Registers() with { IsAssigned = false }).ValidateRegisterWindow());
}
[Fact]
public void RejectsOverflowRatherThanMappingWrappedPhysicalAddress()
{
var overflow = new PciGpuMemoryBar(1, true, false, true, true, ulong.MaxValue - 127, 256);
Assert.Contains("overflowing", Device(Registers(), overflow).ValidateRegisterWindow());
}
[Fact]
public void Rejects32BitWindowBeyondAddressWidth()
{
Assert.Contains("4 GiB", Device(Registers() with { Address = 0x100000000 }).ValidateRegisterWindow());
}
[Theory]
[InlineData(0xF0001000ul, 0x1000000ul)]
[InlineData(0xF0000000ul, 0x1800ul)]
public void RejectsMisalignedOrNonPowerOfTwoResource(ulong address, ulong length)
{
Assert.Contains("aligned", Device(Registers() with { Address = address, Length = length }).ValidateRegisterWindow());
}
[Fact]
public void RejectsMissingExpressCapabilityAndDuplicateSlots()
{
Assert.Contains("PCI Express", (Device(Registers()) with { PciExpress = false }).ValidateRegisterWindow());
Assert.Contains("Duplicate", Device(Registers(), Registers()).ValidateRegisterWindow());
Assert.Contains("snapshot", Device().ValidateRegisterWindow());
}
}
using XFESystem.Core;
using Xunit;
namespace XFESystem.Core.Tests;
public sealed class PciGpuDiscoveryTests
{
private static PciGpuDiscovery Device(params PciGpuMemoryBar[] bars) => new(
"0000:01:00.0", 0x10DE, 0x2B85, 0x03, 0, true, 8, bars);
private static PciGpuMemoryBar Registers() => new(0, true, false, false, false, 0xF0000000, 0x1000000);
[Fact]
public void Discovers64BitFramebufferWithoutTruncatingItsAddress()
{
var device = Device(Registers(), new(1, true, false, true, true, 0x4000000000, 0x800000000),
new(2, false, false, false, false, 0, 0));
Assert.True(device.IsNvidiaDisplayController);
Assert.Empty(device.ValidateRegisterWindow());
Assert.Equal(0x4000000000ul, device.Bars[1].Address);
}
[Theory]
[InlineData(0x1002, 0x03)]
[InlineData(0x10DE, 0x04)]
public void RejectsOtherVendorsAndNvidiaAudioFunctions(int vendor, int classCode)
{
var device = Device(Registers()) with { VendorId = (ushort)vendor, ClassCode = (byte)classCode };
Assert.False(device.IsNvidiaDisplayController);
Assert.Contains("Not an NVIDIA", device.ValidateRegisterWindow());
}
[Fact]
public void RejectsFramebufferApertureInPlaceOfRegisterBar()
{
Assert.Contains("BAR 0", Device(Registers() with { IsPrefetchable = true }).ValidateRegisterWindow());
Assert.Contains("BAR 0", Device(Registers() with { IsIo = true }).ValidateRegisterWindow());
Assert.Contains("BAR 0", Device(Registers() with { IsAssigned = false }).ValidateRegisterWindow());
}
[Fact]
public void RejectsOverflowRatherThanMappingWrappedPhysicalAddress()
{
var overflow = new PciGpuMemoryBar(1, true, false, true, true, ulong.MaxValue - 127, 256);
Assert.Contains("overflowing", Device(Registers(), overflow).ValidateRegisterWindow());
}
[Fact]
public void Rejects32BitWindowBeyondAddressWidth()
{
Assert.Contains("4 GiB", Device(Registers() with { Address = 0x100000000 }).ValidateRegisterWindow());
}
[Theory]
[InlineData(0xF0001000ul, 0x1000000ul)]
[InlineData(0xF0000000ul, 0x1800ul)]
public void RejectsMisalignedOrNonPowerOfTwoResource(ulong address, ulong length)
{
Assert.Contains("aligned", Device(Registers() with { Address = address, Length = length }).ValidateRegisterWindow());
}
[Fact]
public void RejectsMissingExpressCapabilityAndDuplicateSlots()
{
Assert.Contains("PCI Express", (Device(Registers()) with { PciExpress = false }).ValidateRegisterWindow());
Assert.Contains("Duplicate", Device(Registers(), Registers()).ValidateRegisterWindow());
Assert.Contains("snapshot", Device().ValidateRegisterWindow());
}
}