From 9cda192f9f5ee9ffb5d8d6962651d950a7b0fd76 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Thu, 10 Jun 2021 10:47:50 +0200 Subject: Add Libvirt PCI, shared memory and hypervisor features for GPU passthrough --- .../domain/device/HostdevPciDeviceAddressTest.java | 79 ++++++++++++++++++++++ .../device/HostdevPciDeviceDescriptionTest.java | 75 ++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 src/test/java/org/openslx/libvirt/domain/device/HostdevPciDeviceAddressTest.java create mode 100644 src/test/java/org/openslx/libvirt/domain/device/HostdevPciDeviceDescriptionTest.java (limited to 'src/test') diff --git a/src/test/java/org/openslx/libvirt/domain/device/HostdevPciDeviceAddressTest.java b/src/test/java/org/openslx/libvirt/domain/device/HostdevPciDeviceAddressTest.java new file mode 100644 index 0000000..377e126 --- /dev/null +++ b/src/test/java/org/openslx/libvirt/domain/device/HostdevPciDeviceAddressTest.java @@ -0,0 +1,79 @@ +package org.openslx.libvirt.domain.device; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class HostdevPciDeviceAddressTest +{ + @Test + @DisplayName( "Test that a PCI device address instance is not created if invalid values are specified" ) + public void testHostdevPciDeviceAddressInstanceInvalid() + { + assertThrows( IllegalArgumentException.class, + () -> new HostdevPciDeviceAddress( Integer.MIN_VALUE, 0x03, 0x0a, 0x7 ) ); + assertThrows( IllegalArgumentException.class, + () -> new HostdevPciDeviceAddress( 0x72ab, 0x0c, 0x1a, Integer.MAX_VALUE ) ); + } + + @Test + @DisplayName( "Test that a PCI device address instance is parsed from a valid String" ) + public void testHostdevPciDeviceAddressValueOfValid() + { + final HostdevPciDeviceAddress pciDeviceAddr = HostdevPciDeviceAddress.valueOf( "002b:2a:1f.1" ); + + assertNotNull( pciDeviceAddr ); + assertEquals( 0x002b, pciDeviceAddr.getPciDomain() ); + assertEquals( "002b", pciDeviceAddr.getPciDomainAsString() ); + assertEquals( 0x2a, pciDeviceAddr.getPciBus() ); + assertEquals( "2a", pciDeviceAddr.getPciBusAsString() ); + assertEquals( 0x1f, pciDeviceAddr.getPciDevice() ); + assertEquals( "1f", pciDeviceAddr.getPciDeviceAsString() ); + assertEquals( 0x1, pciDeviceAddr.getPciFunction() ); + assertEquals( "1", pciDeviceAddr.getPciFunctionAsString() ); + } + + @Test + @DisplayName( "Test that no PCI device address instance is parsed from an invalid String" ) + public void testHostdevPciDeviceAddressValueOfInvalid() + { + final HostdevPciDeviceAddress pciDeviceAddr = HostdevPciDeviceAddress.valueOf( "0000b2ac1f31" ); + + assertNull( pciDeviceAddr ); + } + + @Test + @DisplayName( "Test that two PCI device address instances are equal" ) + public void testHostdevPciDeviceAddressEquals() + { + final HostdevPciDeviceAddress pciDeviceAddr1 = new HostdevPciDeviceAddress( 0x0000, 0x2a, 0x1f, 0x1 ); + final HostdevPciDeviceAddress pciDeviceAddr2 = new HostdevPciDeviceAddress( 0x0000, 0x2a, 0x1f, 0x1 ); + + assertTrue( pciDeviceAddr1.equals( pciDeviceAddr2 ) ); + } + + @Test + @DisplayName( "Test that two PCI device address instances are not equal" ) + public void testHostdevPciDeviceAddressNotEquals() + { + final HostdevPciDeviceAddress pciDeviceAddr1 = new HostdevPciDeviceAddress( 0x0000, 0x2a, 0x1f, 0x1 ); + final HostdevPciDeviceAddress pciDeviceAddr2 = new HostdevPciDeviceAddress( 0x0000, 0x2a, 0x1f, 0x2 ); + + assertFalse( pciDeviceAddr1.equals( pciDeviceAddr2 ) ); + } + + @Test + @DisplayName( "Test that a PCI device address can be dumped to a String" ) + public void testHostdevPciDeviceAddressToString() + { + final HostdevPciDeviceAddress pciDeviceAddr = new HostdevPciDeviceAddress( 0x0000, 0x2a, 0x1f, 0x1 ); + + assertEquals( "0000:2a:1f.1", pciDeviceAddr.toString() ); + } +} diff --git a/src/test/java/org/openslx/libvirt/domain/device/HostdevPciDeviceDescriptionTest.java b/src/test/java/org/openslx/libvirt/domain/device/HostdevPciDeviceDescriptionTest.java new file mode 100644 index 0000000..7a740ac --- /dev/null +++ b/src/test/java/org/openslx/libvirt/domain/device/HostdevPciDeviceDescriptionTest.java @@ -0,0 +1,75 @@ +package org.openslx.libvirt.domain.device; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class HostdevPciDeviceDescriptionTest +{ + @Test + @DisplayName( "Test that a PCI device description instance is not created if invalid values are specified" ) + public void testHostdevPciDeviceDescriptionInstanceInvalid() + { + assertThrows( IllegalArgumentException.class, + () -> new HostdevPciDeviceDescription( Integer.MIN_VALUE, 0x293a ) ); + assertThrows( IllegalArgumentException.class, + () -> new HostdevPciDeviceDescription( 0x8086, Integer.MAX_VALUE ) ); + } + + @Test + @DisplayName( "Test that a PCI device description instance is parsed from a valid String" ) + public void testHostdevPciDeviceDescriptionValueOfValid() + { + final HostdevPciDeviceDescription pciDeviceDesc = HostdevPciDeviceDescription.valueOf( "8086:293a" ); + + assertNotNull( pciDeviceDesc ); + assertEquals( 0x8086, pciDeviceDesc.getVendorId() ); + assertEquals( "8086", pciDeviceDesc.getVendorIdAsString() ); + assertEquals( 0x293a, pciDeviceDesc.getDeviceId() ); + assertEquals( "293a", pciDeviceDesc.getDeviceIdAsString() ); + } + + @Test + @DisplayName( "Test that no PCI device description instance is parsed from an invalid String" ) + public void testHostdevPciDeviceDescriptionValueOfInvalid() + { + final HostdevPciDeviceDescription pciDeviceDesc = HostdevPciDeviceDescription.valueOf( "bba93e215" ); + + assertNull( pciDeviceDesc ); + } + + @Test + @DisplayName( "Test that two PCI device description instances are equal" ) + public void testHostdevPciDeviceDescriptionEquals() + { + final HostdevPciDeviceDescription pciDeviceDesc1 = new HostdevPciDeviceDescription( 0x8086, 0x293a ); + final HostdevPciDeviceDescription pciDeviceDesc2 = new HostdevPciDeviceDescription( 0x8086, 0x293a ); + + assertTrue( pciDeviceDesc1.equals( pciDeviceDesc2 ) ); + } + + @Test + @DisplayName( "Test that two PCI device description instances are not equal" ) + public void testHostdevPciDeviceDescriptionNotEquals() + { + final HostdevPciDeviceDescription pciDeviceDesc1 = new HostdevPciDeviceDescription( 0x8086, 0x293a ); + final HostdevPciDeviceDescription pciDeviceDesc2 = new HostdevPciDeviceDescription( 0x293a, 0x8086 ); + + assertFalse( pciDeviceDesc1.equals( pciDeviceDesc2 ) ); + } + + @Test + @DisplayName( "Test that a PCI device description can be dumped to a String" ) + public void testHostdevPciDeviceDescriptionToString() + { + final HostdevPciDeviceDescription pciDeviceDesc = new HostdevPciDeviceDescription( 0x00b1, 0x293a ); + + assertEquals( "00b1:293a", pciDeviceDesc.toString() ); + } +} -- cgit v1.2.3-55-g7522