Re: [PATCH 01/16] tests: virsh: Add simple testsuite for using --print-xml of various commands

2020-11-20 Thread Daniel Henrique Barboza




On 11/19/20 1:26 PM, Peter Krempa wrote:

The test uses a script and compares the output against a template file
VIR_TEST_REGENREATE_OUTPUT can be used on test failures. This test will


A typo and ... a missing period perhaps?

"... against a template file. VIR_TEST_REGENERATE_OUTPUT can be used ..."


Reviewed-by: Daniel Henrique Barboza 



be marked as expensive once the refactors it guards are done.

Signed-off-by: Peter Krempa 
---
  tests/meson.build   |   1 +
  tests/virsh-output  |  27 +++
  tests/virsh-output-commands |  80 +++
  tests/virsh-output.out  | 408 
  4 files changed, 516 insertions(+)
  create mode 100755 tests/virsh-output
  create mode 100755 tests/virsh-output-commands
  create mode 100644 tests/virsh-output.out

diff --git a/tests/meson.build b/tests/meson.build
index f88410ff33..3ef4d06177 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -654,6 +654,7 @@ if conf.has('WITH_LIBVIRTD')
  'virsh-define-dev-segfault',
  'virsh-int-overflow',
  'virsh-optparse',
+'virsh-output',
  'virsh-read-bufsiz',
  'virsh-read-non-seekable',
  'virsh-schedinfo',
diff --git a/tests/virsh-output b/tests/virsh-output
new file mode 100755
index 00..44833c7048
--- /dev/null
+++ b/tests/virsh-output
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+. "$(dirname $0)/test-lib.sh"
+
+if [ ! -x /bin/bash ]; then
+echo skipping test - no bash
+exit 77
+fi
+
+mock_xdg_ || framework_failure
+
+export LIBVIRT_DEFAULT_URI='test:///default'
+ln -s $abs_top_builddir/tools/virsh virsh
+
+$abs_top_srcdir/tests/virsh-output-commands > out 2>&1
+
+echo end >> out
+
+if compare $abs_top_srcdir/tests/virsh-output.out out; then
+exit 0
+else
+if [ "x$VIR_TEST_REGENERATE_OUTPUT" = "x1" ]; then
+cp out $abs_top_srcdir/tests/virsh-output.out
+fi
+
+exit 1
+fi
diff --git a/tests/virsh-output-commands b/tests/virsh-output-commands
new file mode 100755
index 00..43f87bee0f
--- /dev/null
+++ b/tests/virsh-output-commands
@@ -0,0 +1,80 @@
+#!/bin/bash
+
+attach_disk()
+{
+./virsh attach-disk --print-xml --domain testdom $@ --source 
/nonexistent/file
+}
+
+set -x
+
+./virsh attach-disk
+./virsh attach-disk --print-xml --domain testdom $@ --source ""
+./virsh attach-disk --print-xml --domain testdom $@ --source "" --sourcetype 
file
+./virsh attach-disk --print-xml --domain testdom $@ --source "" --sourcetype 
blah
+attach_disk --target hda
+attach_disk --target hda --sourcetype file
+attach_disk --target hda --sourcetype block
+attach_disk --target hda --sourcetype nothing
+attach_disk --target hda --sourcetype file --type disk
+attach_disk --target hda --sourcetype block --type disk
+attach_disk --target hda --sourcetype file --type cdrom
+attach_disk --target hda --sourcetype block --type cdrom
+attach_disk --target hda --sourcetype file --type blah
+attach_disk --target hda --sourcetype block --type blah
+attach_disk --target hda --sourcetype file --type disk --driver testdriver
+attach_disk --target hda --sourcetype file --type disk --subdriver qcow2
+attach_disk --target hda --sourcetype file --type disk --subdriver raw
+attach_disk --target hda --sourcetype file --type disk --cache none
+attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 
--cache none
+attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 
--serial TEST_SERIAL
+attach_disk --target hda --sourcetype file --type disk --mode readonly
+attach_disk --target hda --sourcetype file --type disk --mode shareable
+attach_disk --target hda --sourcetype file --type disk --mode whatever
+attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 
--alias testalias
+attach_disk --target hda --sourcetype file --type disk --rawio
+attach_disk --target hda --sourcetype file --type disk --multifunction
+attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 
--alias testalias --iothread 3 --mode readonly --cache none --driver qemu
+
+attach_disk --target hda --sourcetype file --type disk --address ide:1.2.3
+attach_disk --target hda --sourcetype file --type disk --address ide:1.2.4
+attach_disk --target hda --sourcetype file --type disk --address ide:1:2:5
+attach_disk --target sda --sourcetype file --type disk --address ide:1.2.3
+attach_disk --target vda --sourcetype file --type disk --address ide:1.2.3
+
+attach_disk --target sda --sourcetype file --type disk --address usb:12.34
+attach_disk --target sda --sourcetype file --type disk --address usb:12.3
+attach_disk --target sda --sourcetype file --type disk --address usb:12:34
+attach_disk --target vda --sourcetype file --type disk --address usb:12.34
+attach_disk --target hda --sourcetype file --type disk --address usb:12.34
+
+attach_disk --target sda --sourcetype file --type disk --address scsi:1.2.3
+attach_disk --target sda --sourcetype file --type disk --address scsi:1.2.4
+attach_disk --target sda --sourcetype 

[PATCH 01/16] tests: virsh: Add simple testsuite for using --print-xml of various commands

2020-11-19 Thread Peter Krempa
The test uses a script and compares the output against a template file
VIR_TEST_REGENREATE_OUTPUT can be used on test failures. This test will
be marked as expensive once the refactors it guards are done.

Signed-off-by: Peter Krempa 
---
 tests/meson.build   |   1 +
 tests/virsh-output  |  27 +++
 tests/virsh-output-commands |  80 +++
 tests/virsh-output.out  | 408 
 4 files changed, 516 insertions(+)
 create mode 100755 tests/virsh-output
 create mode 100755 tests/virsh-output-commands
 create mode 100644 tests/virsh-output.out

diff --git a/tests/meson.build b/tests/meson.build
index f88410ff33..3ef4d06177 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -654,6 +654,7 @@ if conf.has('WITH_LIBVIRTD')
 'virsh-define-dev-segfault',
 'virsh-int-overflow',
 'virsh-optparse',
+'virsh-output',
 'virsh-read-bufsiz',
 'virsh-read-non-seekable',
 'virsh-schedinfo',
diff --git a/tests/virsh-output b/tests/virsh-output
new file mode 100755
index 00..44833c7048
--- /dev/null
+++ b/tests/virsh-output
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+. "$(dirname $0)/test-lib.sh"
+
+if [ ! -x /bin/bash ]; then
+echo skipping test - no bash
+exit 77
+fi
+
+mock_xdg_ || framework_failure
+
+export LIBVIRT_DEFAULT_URI='test:///default'
+ln -s $abs_top_builddir/tools/virsh virsh
+
+$abs_top_srcdir/tests/virsh-output-commands > out 2>&1
+
+echo end >> out
+
+if compare $abs_top_srcdir/tests/virsh-output.out out; then
+exit 0
+else
+if [ "x$VIR_TEST_REGENERATE_OUTPUT" = "x1" ]; then
+cp out $abs_top_srcdir/tests/virsh-output.out
+fi
+
+exit 1
+fi
diff --git a/tests/virsh-output-commands b/tests/virsh-output-commands
new file mode 100755
index 00..43f87bee0f
--- /dev/null
+++ b/tests/virsh-output-commands
@@ -0,0 +1,80 @@
+#!/bin/bash
+
+attach_disk()
+{
+./virsh attach-disk --print-xml --domain testdom $@ --source 
/nonexistent/file
+}
+
+set -x
+
+./virsh attach-disk
+./virsh attach-disk --print-xml --domain testdom $@ --source ""
+./virsh attach-disk --print-xml --domain testdom $@ --source "" --sourcetype 
file
+./virsh attach-disk --print-xml --domain testdom $@ --source "" --sourcetype 
blah
+attach_disk --target hda
+attach_disk --target hda --sourcetype file
+attach_disk --target hda --sourcetype block
+attach_disk --target hda --sourcetype nothing
+attach_disk --target hda --sourcetype file --type disk
+attach_disk --target hda --sourcetype block --type disk
+attach_disk --target hda --sourcetype file --type cdrom
+attach_disk --target hda --sourcetype block --type cdrom
+attach_disk --target hda --sourcetype file --type blah
+attach_disk --target hda --sourcetype block --type blah
+attach_disk --target hda --sourcetype file --type disk --driver testdriver
+attach_disk --target hda --sourcetype file --type disk --subdriver qcow2
+attach_disk --target hda --sourcetype file --type disk --subdriver raw
+attach_disk --target hda --sourcetype file --type disk --cache none
+attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 
--cache none
+attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 
--serial TEST_SERIAL
+attach_disk --target hda --sourcetype file --type disk --mode readonly
+attach_disk --target hda --sourcetype file --type disk --mode shareable
+attach_disk --target hda --sourcetype file --type disk --mode whatever
+attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 
--alias testalias
+attach_disk --target hda --sourcetype file --type disk --rawio
+attach_disk --target hda --sourcetype file --type disk --multifunction
+attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 
--alias testalias --iothread 3 --mode readonly --cache none --driver qemu
+
+attach_disk --target hda --sourcetype file --type disk --address ide:1.2.3
+attach_disk --target hda --sourcetype file --type disk --address ide:1.2.4
+attach_disk --target hda --sourcetype file --type disk --address ide:1:2:5
+attach_disk --target sda --sourcetype file --type disk --address ide:1.2.3
+attach_disk --target vda --sourcetype file --type disk --address ide:1.2.3
+
+attach_disk --target sda --sourcetype file --type disk --address usb:12.34
+attach_disk --target sda --sourcetype file --type disk --address usb:12.3
+attach_disk --target sda --sourcetype file --type disk --address usb:12:34
+attach_disk --target vda --sourcetype file --type disk --address usb:12.34
+attach_disk --target hda --sourcetype file --type disk --address usb:12.34
+
+attach_disk --target sda --sourcetype file --type disk --address scsi:1.2.3
+attach_disk --target sda --sourcetype file --type disk --address scsi:1.2.4
+attach_disk --target sda --sourcetype file --type disk --address scsi:1:2:5
+attach_disk --target hda --sourcetype file --type disk --address scsi:1.2.3
+attach_disk --target vda --sourcetype file --type disk --address scsi:1.2.3
+
+attach_disk --target sda