]> git.proxmox.com Git - qemu-server.git/blobdiff - test/run_config2command_tests.pl
add test for mapped pci devices
[qemu-server.git] / test / run_config2command_tests.pl
index dda44d99bdd3fe5cfe148631d72a7d08d13dd6f0..0871854949bf786bd6e8af9f613631a317755405 100755 (executable)
@@ -87,8 +87,37 @@ my $pci_devs = [
     "0000:f0:43.0",
     "0000:f0:43.1",
     "1234:f0:43.1",
+    "0000:01:00.4",
+    "0000:01:00.5",
+    "0000:01:00.6",
+    "0000:07:10.0",
+    "0000:07:10.1",
+    "0000:07:10.4",
 ];
 
+my $pci_map_config = {
+    ids => {
+       someGpu => {
+           type => 'pci',
+           map => [
+               'node=localhost,path=0000:01:00.4,id=10de:2231,iommugroup=1',
+               'node=localhost,path=0000:01:00.5,id=10de:2231,iommugroup=1',
+               'node=localhost,path=0000:01:00.6,id=10de:2231,iommugroup=1',
+           ],
+       },
+       someNic => {
+           type => 'pci',
+           map => [
+               'node=localhost,path=0000:07:10.0,id=8086:1520,iommugroup=2',
+               'node=localhost,path=0000:07:10.1,id=8086:1520,iommugroup=2',
+               'node=localhost,path=0000:07:10.4,id=8086:1520,iommugroup=2',
+           ],
+       },
+    },
+};
+
+my $usb_map_config = {},
+
 my $current_test; # = {
 #   description => 'Test description', # if available
 #   qemu_version => '2.12',
@@ -275,6 +304,28 @@ $pve_common_sysfstools->mock(
            } sort @$pci_devs
        ];
     },
+    pci_device_info => sub {
+       my ($path, $noerr) = @_;
+
+       if ($path =~ m/^0000:01:00/) {
+           return {
+               mdev => 1,
+               iommugroup => 1,
+               mdev => 1,
+               vendor => "0x10de",
+               device => "0x2231",
+           };
+       } elsif ($path =~ m/^0000:07:10/) {
+           return {
+               iommugroup => 2,
+               mdev => 0,
+               vendor => "0x8086",
+               device => "0x1520",
+           };
+       } else {
+           return {};
+       }
+    },
 );
 
 my $qemu_monitor_module;
@@ -303,6 +354,37 @@ $qemu_monitor_module->mock(
 );
 $qemu_monitor_module->mock('qmp_cmd', \&qmp_cmd);
 
+my $mapping_usb_module = Test::MockModule->new("PVE::Mapping::USB");
+$mapping_usb_module->mock(
+    config => sub {
+       return $usb_map_config;
+    },
+);
+
+my $mapping_pci_module = Test::MockModule->new("PVE::Mapping::PCI");
+$mapping_pci_module->mock(
+    config => sub {
+       return $pci_map_config;
+    },
+);
+
+my $pci_module = Test::MockModule->new("PVE::QemuServer::PCI");
+$pci_module->mock(
+    reserve_pci_usage => sub {
+       my ($ids, $vmid, $timeout, $pid, $dryrun) = @_;
+
+       $ids = [$ids] if !ref($ids);
+
+       for my $id (@$ids) {
+           if ($id eq "0000:07:10.1") {
+               die "reserved";
+           }
+       }
+
+       return undef;
+    },
+);
+
 sub diff($$) {
     my ($a, $b) = @_;
     return if $a eq $b;