]> git.proxmox.com Git - qemu-server.git/blobdiff - test/run_config2command_tests.pl
cfg2cmd: switch off ACPI hotplug on bridges for q35 VMs
[qemu-server.git] / test / run_config2command_tests.pl
index 3168176558a5084a4c5ca391c9ed9d715a58291f..04df9d93e3e22dae228a69336e5d9c1ab26bf4b4 100755 (executable)
@@ -30,6 +30,13 @@ my $base_env = {
                type => 'dir',
                shared => 0,
            },
+           'btrfs-store' => {
+               content => {
+                   images => 1,
+               },
+               path => '/butter/bread',
+               type => 'btrfs',
+           },
            'cifs-store' => {
                shared => 1,
                path => '/mnt/pve/cifs-store',
@@ -84,6 +91,8 @@ my $current_test; # = {
 #   description => 'Test description', # if available
 #   qemu_version => '2.12',
 #   host_arch => 'HOST_ARCH',
+#   expected_error => 'error message',
+#   expected_warning => 'warning message',
 #   config => { config hash },
 #   expected => [ expected outcome cmd line array ],
 # };
@@ -92,6 +101,7 @@ my $current_test; # = {
 #   TEST: A single line describing the test, gets outputted
 #   QEMU_VERSION: \d+\.\d+(\.\d+)? (defaults to current version)
 #   HOST_ARCH: x86_64 | aarch64 (default to x86_64, to make tests stable)
+#   EXPECT_ERROR: <error message> For negative tests
 # all fields are optional
 sub parse_test($) {
     my ($config_fn) = @_;
@@ -120,8 +130,17 @@ sub parse_test($) {
            $current_test->{host_arch} = "$1";
        } elsif ($line =~ /^EXPECT_ERROR:\s*(.*)\s*$/) {
            $current_test->{expect_error} = "$1";
+       } elsif ($line =~ /^EXPECT_WARN(?:ING)?:\s*(.*)\s*$/) {
+           $current_test->{expect_warning} = "$1";
        }
     }
+
+    $config_fn =~ /([^\/]+)$/;
+    my $testname = "$1";
+    if (my $desc = $current_test->{description}) {
+       $testname = "'$testname' - $desc";
+    }
+    $current_test->{testname} = $testname;
 }
 
 sub get_test_qemu_version {
@@ -207,6 +226,15 @@ EOF
     },
 );
 
+my $pve_common_network;
+$pve_common_network = Test::MockModule->new('PVE::Network');
+$pve_common_network->mock(
+    read_bridge_mtu => sub {
+       return 1500;
+    },
+);
+
+
 my $pve_common_inotify;
 $pve_common_inotify = Test::MockModule->new('PVE::INotify');
 $pve_common_inotify->mock(
@@ -267,7 +295,7 @@ sub diff($$) {
     my $ha = IO::Handle->new_from_fd($wa, 'w');
     my $hb = IO::Handle->new_from_fd($wb, 'w');
 
-    open my $diffproc, '-|', 'diff', '-up', "/proc/self/fd/$ra", "/proc/self/fd/$rb"
+    open my $diffproc, '-|', 'diff', '-up', "/proc/self/fd/$ra", "/proc/self/fd/$rb" ## no critic
        or die "failed to run program 'diff': $!";
     POSIX::close($ra);
     POSIX::close($rb);
@@ -290,6 +318,23 @@ sub diff($$) {
     die "files differ:\n$diff";
 }
 
+$SIG{__WARN__} = sub {
+    my $warning = shift;
+    chomp $warning;
+    if (my $warn_expect = $current_test->{expect_warning}) {
+       if ($warn_expect ne $warning) {
+           fail($current_test->{testname});
+           note("warning does not match expected error: '$warning' != '$warn_expect'");
+       } else {
+           note("got expected warning '$warning'");
+           return;
+       }
+    }
+
+    fail($current_test->{testname});
+    note("got unexpected warning '$warning'");
+};
+
 sub do_test($) {
     my ($config_fn) = @_;
 
@@ -297,11 +342,7 @@ sub do_test($) {
 
     parse_test $config_fn;
 
-    $config_fn =~ /([^\/]+)$/;
-    my $testname = "$1";
-    if (my $desc = $current_test->{description}) {
-       $testname = "'$testname' - $desc";
-    }
+    my $testname = $current_test->{testname};
 
     my ($vmid, $storecfg) = $base_env->@{qw(vmid storage_config)};
 
@@ -367,7 +408,7 @@ print "testing config to command stabillity\n";
 if (my $file = shift) {
     do_test $file;
 } else {
-    foreach my $file (<cfg2cmd/*.conf>) {
+    while (my $file = <cfg2cmd/*.conf>) {
        do_test $file;
     }
 }