]>
git.proxmox.com Git - qemu-server.git/blob - test/run_config2command_tests.pl
160f872f53772acfccefc35469ae080c9ddbfd2e
11 use PVE
::Tools
qw(file_get_contents file_set_contents run_command);
22 path
=> '/var/lib/vz',
28 path
=> '/mnt/pve/cifs-store',
30 server
=> '127.0.0.42',
38 monhost
=> '127.0.0.42,127.0.0.21,::1',
49 bwlimit
=> 'restore=1024',
59 real_qemu_version
=> PVE
::QemuServer
::kvm_user_version
(), # not yet mocked
62 my $current_test; # = {
63 # description => 'Test description', # if available
64 # qemu_version => '2.12',
65 # host_arch => 'HOST_ARCH',
66 # config => { config hash },
67 # expected => [ expected outcome cmd line array ],
70 # use the config description to allow changing environment, fields are:
71 # TEST: A single line describing the test, gets outputted
72 # QEMU_VERSION: \d+\.\d+(\.\d+)? (defaults to current version)
73 # HOST_ARCH: x86_64 | aarch64 (default to x86_64, to make tests stable)
74 # all fields are optional
78 $current_test = {}; # reset
80 my $fake_config_fn ="$config_fn/qemu-server/8006.conf";
81 my $config_raw = file_get_contents
($config_fn);
82 my $config = PVE
::QemuServer
::parse_vm_config
($fake_config_fn, $config_raw);
84 $current_test->{config
} = $config;
86 my $description = $config->{description
} // '';
88 while ($description =~ /^\h*(.*?)\h*$/gm) {
90 next if !$line || $line =~ /^#/;
94 if ($line =~ /^TEST:\s*(.*)\s*$/) {
95 $current_test->{description
} = "$1";
96 } elsif ($line =~ /^QEMU_VERSION:\s*(.*)\s*$/) {
97 $current_test->{qemu_version
} = "$1";
98 } elsif ($line =~ /^HOST_ARCH:\s*(.*)\s*$/) {
99 $current_test->{host_arch
} = "$1";
104 my $qemu_server_module;
105 $qemu_server_module = Test
::MockModule-
>new('PVE::QemuServer');
106 $qemu_server_module->mock(
107 kvm_user_version
=> sub {
108 return $current_test->{qemu_version
} // $base_env->{real_qemu_version
};
110 get_host_arch
=> sub() {
111 return $current_test->{host_arch
} // 'x86_64';
113 get_initiator_name
=> sub {
114 return 'iqn.1993-08.org.debian:01:aabbccddeeff';
118 my $qemu_server_config;
119 $qemu_server_config = Test
::MockModule-
>new('PVE::QemuConfig');
120 $qemu_server_config->mock(
122 my ($class, $vmid, $node) = @_;
124 return $current_test->{config
};
132 my ($ra, $wa) = POSIX
::pipe();
133 my ($rb, $wb) = POSIX
::pipe();
134 my $ha = IO
::Handle-
>new_from_fd($wa, 'w');
135 my $hb = IO
::Handle-
>new_from_fd($wb, 'w');
137 open my $diffproc, '-|', 'diff', '-up', "/dev/fd/$ra", "/dev/fd/$rb"
138 or die "failed to run program 'diff': $!";
142 open my $f1, '<', \
$a;
143 open my $f2, '<', \
$b;
146 $ha->print($line1) if defined($line1 = <$f1>);
147 $hb->print($line2) if defined($line2 = <$f2>);
148 } while (defined($line1 // $line2));
155 my $diff = <$diffproc>;
157 die "files differ:\n$diff";
161 my ($config_fn) = @_;
163 die "no such input test config: $config_fn\n" if ! -f
$config_fn;
165 parse_test
$config_fn;
167 $config_fn =~ /([^\/]+)$/;
169 if (my $desc = $current_test->{description
}) {
170 $testname = "'$testname' - $desc";
173 my ($vmid, $storecfg) = $base_env->@{qw(vmid storage_config)};
175 my $cmdline = PVE
::QemuServer
::vm_commandline
($storecfg, $vmid);
177 $cmdline =~ s/ -/ \\\n -/g; # same as qm showcmd --pretty
180 my $cmd_fn = "$config_fn.cmd";
183 my $cmdline_expected = file_get_contents
($cmd_fn);
185 my $cmd_expected = [ sort split /\s*\\?\n\s*/, $cmdline_expected ];
186 my $cmd = [ sort split /\s*\\?\n\s*/, $cmdline ];
188 # comment out for easier debugging
189 #file_set_contents("$cmd_fn.tmp", $cmdline);
191 my $exp = join("\n", @$cmd_expected);
192 my $got = join("\n", @$cmd);
193 eval { diff
($exp, $got) };
201 file_set_contents
($cmd_fn, $cmdline);
205 print "testing config to command stabillity\n";
208 if (my $file = shift) {
211 foreach my $file (<cfg2cmd
/*.conf
>) {