]>
Commit | Line | Data |
---|---|---|
d7d698f6 TL |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use experimental 'smartmatch'; | |
6 | ||
7 | use lib qw(..); | |
8 | ||
9 | use Test::More; | |
10 | ||
11 | use PVE::QemuServer::PCI; | |
12 | ||
13 | print "testing PCI(e) address conflicts\n"; | |
14 | ||
15 | # exec tests | |
16 | ||
17 | #FIXME: make cross PCI <-> PCIe check sense at all?? | |
18 | my $addr_map = {}; | |
19 | my ($fail, $ignored) = (0, 0); | |
20 | sub check_conflict { | |
21 | my ($id, $what) = @_; | |
22 | ||
23 | my ($bus, $addr) = $what->@{qw(bus addr)}; | |
24 | my $full_addr = "$bus:$addr"; | |
25 | ||
26 | if (defined(my $conflict = $addr_map->{$full_addr})) { | |
27 | if (my @ignores = $what->{conflict_ok}) { | |
28 | if ($conflict ~~ @ignores) { | |
29 | note("OK: ignore conflict for '$full_addr' between '$id' and '$conflict'"); | |
30 | $ignored++; | |
31 | return; | |
32 | } | |
33 | } | |
34 | note("ERR: conflict for '$full_addr' between '$id' and '$conflict'"); | |
35 | $fail++; | |
36 | } else { | |
37 | $addr_map->{$full_addr} = $id; | |
38 | } | |
39 | } | |
40 | ||
41 | ||
42 | my $pci_map = PVE::QemuServer::PCI::get_pci_addr_map(); | |
43 | while (my ($id, $what) = each %$pci_map) { | |
44 | check_conflict($id, $what); | |
45 | } | |
46 | ||
47 | my $pcie_map = PVE::QemuServer::PCI::get_pcie_addr_map(); | |
48 | while (my ($id, $what) = each %$pcie_map) { | |
49 | check_conflict($id, $what); | |
50 | } | |
51 | ||
52 | if ($fail) { | |
53 | fail("PCI(e) address conflict check, ignored: $ignored, conflicts: $fail"); | |
54 | } else { | |
55 | pass("PCI(e) address conflict check, ignored: $ignored"); | |
56 | } | |
57 | ||
58 | done_testing(); |