Back in
commit bd6c46fa0cfe275c24debc1152cfc5206c04b59b
Author: Juerg Haefliger <juerg.haefliger(a)hp.com>
Date: Mon Jan 31 06:42:57 2011 -0500
tests: handle backspace-newline pairs in test input files
all the test argv files were line wrapped so that the args
were less than 80 characters.
The way the line wrapping was done turns out to be quite
undesirable, because it often leaves multiple parameters
on the same line. If we later need to add or remove
individual parameters, then it leaves us having to redo
line wrapping.
This commit changes the line wrapping so that every
single "-param value" is one its own new line. If the
"value" is still too long, then we break on ',' or ':'
or ' ' as needed.
This means that when we come to add / remove parameters
from the test files line, the patch diffs will only
ever show a single line added/removed which will greatly
simplify review work.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
cfg.mk | 16 ++-
.../bhyvexml2argvdata/bhyvexml2argv-acpiapic.args | 10 +-
.../networkxml2firewalldata/nat-default-linux.args | 137 ++++++++++++++++-----
.../qemuxml2argv-aarch64-aavmf-virtio-mmio.args | 33 +++--
tests/test-wrap-argv.pl | 106 ++++++++++++++++
5 files changed, 262 insertions(+), 40 deletions(-)
create mode 100644 tests/test-wrap-argv.pl
Changed in v2:
- Added hook in syntax-check to run test-wrap-argv
to validate files
diff --git a/cfg.mk b/cfg.mk
index a9bba38..db513be 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1068,7 +1068,7 @@ _autogen:
# regenerate HACKING as part of the syntax-check
ifneq ($(_gl-Makefile),)
-syntax-check: $(top_srcdir)/HACKING bracket-spacing-check
+syntax-check: $(top_srcdir)/HACKING bracket-spacing-check test-wrap-argv
endif
bracket-spacing-check:
@@ -1077,6 +1077,20 @@ bracket-spacing-check:
{ echo '$(ME): incorrect formatting, see HACKING for rules' 1>&2; \
exit 1; }
+test-wrap-argv:
+ $(AM_V_GEN)files=`$(VC_LIST) | grep -E '\.(ldargs|args)'`; \
+ for file in $$files ; \
+ do \
+ $(PERL) $(top_srcdir)/tests/test-wrap-argv.pl $$file > $${file}-t ; \
+ diff $$file $${file}-t; \
+ res=$$? ; \
+ rm $${file}-t ; \
+ test $$res == 0 || { \
+ echo "$(ME): Incorrect line wrapping in $$file." 1>&2; \
+ echo "$(ME): Use test-wrap-argv.pl to wrap test data files"
1>&2; \
+ exit 1; } \
+ done
+
# sc_po_check can fail if generated files are not built first
sc_po_check: \
$(srcdir)/daemon/remote_dispatch.h \
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-acpiapic.args
b/tests/bhyvexml2argvdata/bhyvexml2argv-acpiapic.args
index 6b26964..e1afefd 100644
--- a/tests/bhyvexml2argvdata/bhyvexml2argv-acpiapic.args
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-acpiapic.args
@@ -1,3 +1,11 @@
-/usr/sbin/bhyve -c 1 -m 214 -A -I -u -H -P -s 0:0,hostbridge \
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-A \
+-I \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve
diff --git a/tests/networkxml2firewalldata/nat-default-linux.args
b/tests/networkxml2firewalldata/nat-default-linux.args
index b92a845..ffdafdf 100644
--- a/tests/networkxml2firewalldata/nat-default-linux.args
+++ b/tests/networkxml2firewalldata/nat-default-linux.args
@@ -1,30 +1,107 @@
-iptables --table filter --insert INPUT --in-interface virbr0 --protocol tcp \
---destination-port 67 --jump ACCEPT
-iptables --table filter --insert INPUT --in-interface virbr0 --protocol udp \
---destination-port 67 --jump ACCEPT
-iptables --table filter --insert OUTPUT --out-interface virbr0 --protocol udp \
---destination-port 68 --jump ACCEPT
-iptables --table filter --insert INPUT --in-interface virbr0 --protocol tcp \
---destination-port 53 --jump ACCEPT
-iptables --table filter --insert INPUT --in-interface virbr0 --protocol udp \
---destination-port 53 --jump ACCEPT
-iptables --table filter --insert FORWARD --in-interface virbr0 --jump REJECT
-iptables --table filter --insert FORWARD --out-interface virbr0 --jump REJECT
-iptables --table filter --insert FORWARD --in-interface virbr0 \
---out-interface virbr0 --jump ACCEPT
-iptables --table filter --insert FORWARD --source 192.168.122.0/24 \
---in-interface virbr0 --jump ACCEPT
-iptables --table filter --insert FORWARD --destination 192.168.122.0/24 \
---out-interface virbr0 --match conntrack --ctstate ESTABLISHED,RELATED --jump ACCEPT
-iptables --table nat --insert POSTROUTING --source 192.168.122.0/24 '!' \
---destination 192.168.122.0/24 --jump MASQUERADE
-iptables --table nat --insert POSTROUTING --source 192.168.122.0/24 \
--p udp '!' --destination 192.168.122.0/24 --jump MASQUERADE --to-ports
1024-65535
-iptables --table nat --insert POSTROUTING --source 192.168.122.0/24 \
--p tcp '!' --destination 192.168.122.0/24 --jump MASQUERADE --to-ports
1024-65535
-iptables --table nat --insert POSTROUTING --source 192.168.122.0/24 \
---destination 255.255.255.255/32 --jump RETURN
-iptables --table nat --insert POSTROUTING --source 192.168.122.0/24 \
---destination 224.0.0.0/24 --jump RETURN
-iptables --table mangle --insert POSTROUTING --out-interface virbr0 \
---protocol udp --destination-port 68 --jump CHECKSUM --checksum-fill
+iptables \
+--table filter \
+--insert INPUT \
+--in-interface virbr0 \
+--protocol tcp \
+--destination-port 67 \
+--jump ACCEPT
+iptables \
+--table filter \
+--insert INPUT \
+--in-interface virbr0 \
+--protocol udp \
+--destination-port 67 \
+--jump ACCEPT
+iptables \
+--table filter \
+--insert OUTPUT \
+--out-interface virbr0 \
+--protocol udp \
+--destination-port 68 \
+--jump ACCEPT
+iptables \
+--table filter \
+--insert INPUT \
+--in-interface virbr0 \
+--protocol tcp \
+--destination-port 53 \
+--jump ACCEPT
+iptables \
+--table filter \
+--insert INPUT \
+--in-interface virbr0 \
+--protocol udp \
+--destination-port 53 \
+--jump ACCEPT
+iptables \
+--table filter \
+--insert FORWARD \
+--in-interface virbr0 \
+--jump REJECT
+iptables \
+--table filter \
+--insert FORWARD \
+--out-interface virbr0 \
+--jump REJECT
+iptables \
+--table filter \
+--insert FORWARD \
+--in-interface virbr0 \
+--out-interface virbr0 \
+--jump ACCEPT
+iptables \
+--table filter \
+--insert FORWARD \
+--source 192.168.122.0/24 \
+--in-interface virbr0 \
+--jump ACCEPT
+iptables \
+--table filter \
+--insert FORWARD \
+--destination 192.168.122.0/24 \
+--out-interface virbr0 \
+--match conntrack \
+--ctstate ESTABLISHED,RELATED \
+--jump ACCEPT
+iptables \
+--table nat \
+--insert POSTROUTING \
+--source 192.168.122.0/24 '!' \
+--destination 192.168.122.0/24 \
+--jump MASQUERADE
+iptables \
+--table nat \
+--insert POSTROUTING \
+--source 192.168.122.0/24 \
+-p udp '!' \
+--destination 192.168.122.0/24 \
+--jump MASQUERADE \
+--to-ports 1024-65535
+iptables \
+--table nat \
+--insert POSTROUTING \
+--source 192.168.122.0/24 \
+-p tcp '!' \
+--destination 192.168.122.0/24 \
+--jump MASQUERADE \
+--to-ports 1024-65535
+iptables \
+--table nat \
+--insert POSTROUTING \
+--source 192.168.122.0/24 \
+--destination 255.255.255.255/32 \
+--jump RETURN
+iptables \
+--table nat \
+--insert POSTROUTING \
+--source 192.168.122.0/24 \
+--destination 224.0.0.0/24 \
+--jump RETURN
+iptables \
+--table mangle \
+--insert POSTROUTING \
+--out-interface virbr0 \
+--protocol udp \
+--destination-port 68 \
+--jump CHECKSUM \
+--checksum-fill
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-aavmf-virtio-mmio.args
b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-aavmf-virtio-mmio.args
index d6d8aed..4cc4cd2 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-aavmf-virtio-mmio.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-aavmf-virtio-mmio.args
@@ -1,14 +1,31 @@
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
-/usr/bin/qemu-system-aarch64 -S -M virt -cpu cortex-a53 \
--m 1024 -smp 1 -nographic \
--nodefconfig -nodefaults -monitor unix:/tmp/test-monitor,server,nowait \
--boot c -kernel /aarch64.kernel -initrd /aarch64.initrd -append \
-'earlyprintk console=ttyAMA0,115200n8 rw root=/dev/vda rootwait' \
--dtb /aarch64.dtb -device virtio-serial-device,id=virtio-serial0 -usb \
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-aarch64 \
+-S \
+-M virt \
+-cpu cortex-a53 \
+-m 1024 \
+-smp 1 \
+-nographic \
+-nodefconfig \
+-nodefaults \
+-monitor unix:/tmp/test-monitor,server,nowait \
+-boot c \
+-kernel /aarch64.kernel \
+-initrd /aarch64.initrd \
+-append 'earlyprintk console=ttyAMA0,115200n8 rw root=/dev/vda rootwait' \
+-dtb /aarch64.dtb \
+-device virtio-serial-device,id=virtio-serial0 \
+-usb \
-drive file=/aarch64.raw,if=none,id=drive-virtio-disk0 \
-device virtio-blk-device,drive=drive-virtio-disk0,id=virtio-disk0 \
-device virtio-net-device,vlan=0,id=net0,mac=52:54:00:09:a4:37 \
--net user,vlan=0,name=hostnet0 -chardev pty,id=charconsole0 \
+-net user,vlan=0,name=hostnet0 \
+-chardev pty,id=charconsole0 \
-device virtconsole,chardev=charconsole0,id=console0 \
-device virtio-balloon-device,id=balloon0 \
-object rng-random,id=objrng0,filename=/dev/random \
diff --git a/tests/test-wrap-argv.pl b/tests/test-wrap-argv.pl
new file mode 100644
index 0000000..dc70271
--- /dev/null
+++ b/tests/test-wrap-argv.pl
@@ -0,0 +1,106 @@
+#!/usr/bin/perl
+
+
+
+foreach my $file (@ARGV) {
+ &rewrap($file);
+}
+
+sub rewrap {
+ my $file = shift;
+
+ # Read the original file
+ open FILE, "<", $file or die "cannot read $file: $!";
+ my @lines;
+ while (<FILE>) {
+ # If there is a trailing '\' then kill the new line
+ if (/\\$/) {
+ chomp;
+ $_ =~ s/\\$//;
+ }
+
+ push @lines, $_;
+ }
+
+ # Skip empty files
+ return unless @lines;
+
+ # Kill the last new line in the file
+ chomp @lines[$#lines];
+ close FILE;
+
+ # Reconstruct the master data by joining all lines
+ # and then split again based on the real desired
+ # newlines
+ @lines = split /\n/, join('', @lines);
+
+ # Now each @lines represents a single command, we
+ # can process them
+ foreach my $line (@lines) {
+ my @bits = split / /, join('', $line);
+
+ # @bits contains env vars, then the command line
+ # and then the arguments
+ my @env;
+ my $cmd;
+ my @args;
+
+ if ($bits[0] !~ /=/) {
+ $cmd = shift @bits;
+ }
+
+ foreach my $bit (@bits) {
+ # If no command is defined yet, we must still
+ # have env vars
+ if (!defined $cmd) {
+ # Look for leading / to indicate command name
+ if ($bit =~ m,^/,) {
+ $cmd = $bit;
+ } else {
+ push @env, $bit;
+ }
+ } else {
+ # If there's a leading '-' then this is a new
+ # parameter, otherwise its a value for the prev
+ # parameter.
+ if ($bit =~ m,^-,) {
+ push @args, $bit;
+ } else {
+ $args[$#args] .= " " . $bit;
+ }
+ }
+ }
+
+ # Print env + command first
+ print join(" \\\n", @env, $cmd), " \\\n";
+ # We might have to split line argument values...
+ for (my $i = 0; $i <= $#args; $i++) {
+ my $arg = $args[$i];
+ while (length($arg) > 80) {
+ my $split = rindex $arg, ",", 80;
+ if ($split == -1) {
+ $split = rindex $arg, ":", 80;
+ }
+ if ($split == -1) {
+ $split = rindex $arg, " ", 80;
+ }
+ if ($split == -1) {
+ warn "$file: cannot find nice place to split '$arg'
below 80 chars\n";
+ $split = 79;
+ }
+ $split++;
+
+ my $head = substr $arg, 0, $split;
+ $arg = substr $arg, $split;
+
+ print $head, "\\\n";
+ }
+ print $arg;
+ if ($i != $#args) {
+ print " \\\n";
+ } else {
+ print "\n";
+ }
+ }
+ }
+}
--
2.5.0