[PATCH 00/35] vsh: Fix handling of commands and help - part 3 (virsh testing overhaul)

Part 3 was supposed to be the refactor of the command parser but since I wanted to add few tests I've noticed that there's a lot of old cruft and many tests are skipped. This series refactors virshtest and optimizes it to run multiple commands with one virsh instance. Doing this allows us to do more testing in the same run time allowing us to reduce the amount of "expensive" tests. Further down this removes all of the 'shell' test infra which was used for virsh. Peter Krempa (35): virshtest: Prepare for testing against output files virshtest: Allow to test failure of commands virshtest: Filter multiple occurences of string to drop in testFilterLine virshtest: Add support for testing commands read from input file and adapt alias tests virshtest: Adapt 'echo --split' tests to DO_TEST_SCRIPT virshtest: Drop some redundant 'echo' cases virshtest: Adapt some 'escaping' tests via DO_TEST_SCRIPT vrishtest: Prepare for simpler testing - echo tests virshtest: Test against output files ("echo" tests) virshtest: Drop string form of expected output data of "echo" tests virshtest: Replace list and nodeinfo tests by equivalent VIR_TEST_SCRIPT variant virshtest: Adapt tests for domain id lookup and state query to DO_TEST_SCRIPT virshtest: Adapt 'blkiotune' tests to DO_TEST_SCRIPT virshtest: Adapt 'iothread' tests to DO_TEST_SCRIPT virshtest: Drop support for testing against hardcoded strings virshtest: Adapt argument parsing tests from 'virsh-optparse' virshtest: Adapt 'snapshot-create-as' arg handling tests from 'virsh-optparse' virshtest: Adapt numeric option arg handling tests from 'virsh-optparse' virshtest: Adapt 'event' option arg handling tests from 'virsh-optparse' virshtest: Reimplement 'virsh-output' test qemuxmlconftest: Adapt XMLs from 'virsh-cpuset' and 'virsh-define-dev-segfault' cases virshtest: Adapt 'virsh-vcpupin' test virshtest: Adapt 'virsh-int-overflow' virshtest: Adapt 'virsh-schedinfo' virshtest: Adapt 'virsh-start' and 'virsh-undefine' tests as 'lifecycle' case virsh: Fix '--name' and '--parent' used together in '(snapshot|checkpoint)-list' command vsh: Allow non-interactive use of 'cd' command virshtest: Adapt 'virsh-snapshot' test virshtest: Adapt 'virsh-checkpoint' test virshtest: Adapt 'virsh-read-bufsiz' and 'virsh-read-non-seekable' virshtest: Adapt 'libvirtd-pool' tests: Re-implement '(virsh|virt-admin)-self-test' directly in meson tests: Reimplement 'libvirtd-fail' case directly in meson virshtest: Adapt virsh-uriprecedence test case tests: Drop 'test-lib.sh' build-aux/syntax-check.mk | 6 +- docs/manpages/virsh.rst | 17 +- src/meson.build | 5 + tests/libvirtd-fail | 16 - tests/libvirtd-pool | 38 - tests/meson.build | 39 +- .../console-compat-crash.x86_64-latest.args | 46 + .../console-compat-crash.x86_64-latest.xml | 65 ++ .../console-compat-crash.xml} | 36 +- .../cpuset-invalid.x86_64-latest.err | 1 + tests/qemuxmlconfdata/cpuset-invalid.xml | 12 + tests/qemuxmlconftest.c | 2 + tests/test-lib.sh | 280 ------ tests/virsh-checkpoint | 178 ---- tests/virsh-cpuset | 46 - tests/virsh-int-overflow | 18 - tests/virsh-optparse | 292 ------ tests/virsh-output | 29 - tests/virsh-output-commands | 94 -- tests/virsh-output.out | 496 ---------- tests/virsh-read-bufsiz | 49 - tests/virsh-read-non-seekable | 51 - tests/virsh-schedinfo | 40 - tests/virsh-self-test | 48 - tests/virsh-snapshot | 233 ----- tests/virsh-start | 41 - tests/virsh-undefine | 76 -- tests/virsh-uriprecedence | 97 -- tests/virsh-vcpupin | 100 -- tests/virshtest.c | 878 +++++++----------- tests/virshtestdata/argument-assignment.in | 15 + tests/virshtestdata/argument-assignment.out | 91 ++ tests/virshtestdata/attach-disk.in | 79 ++ tests/virshtestdata/attach-disk.out | 343 +++++++ tests/virshtestdata/blkiotune.in | 3 + tests/virshtestdata/blkiotune.out | 15 + tests/virshtestdata/checkpoint-c2.xml | 41 + tests/virshtestdata/checkpoint-c3.xml | 38 + tests/virshtestdata/checkpoint-redefine.out | 13 + tests/virshtestdata/checkpoint.in | 35 + tests/virshtestdata/checkpoint.out | 133 +++ tests/virshtestdata/dash-dash-argument-1.out | 1 + tests/virshtestdata/dash-dash-argument-2.out | 1 + tests/virshtestdata/dash-dash-argument-3.out | 1 + tests/virshtestdata/dash-dash-argument-4.out | 1 + tests/virshtestdata/dash-dash-argument-5.out | 1 + tests/virshtestdata/dash-dash-argument-6.out | 1 + tests/virshtestdata/domain-id-overflow.out | 3 + tests/virshtestdata/domain-id.in | 18 + tests/virshtestdata/domain-id.out | 73 ++ tests/virshtestdata/echo-alias-argv.out | 1 + tests/virshtestdata/echo-alias.in | 3 + tests/virshtestdata/echo-alias.out | 3 + tests/virshtestdata/echo-escaping-1.out | 2 + tests/virshtestdata/echo-escaping-2.out | 2 + tests/virshtestdata/echo-escaping-3.out | 2 + tests/virshtestdata/echo-escaping.in | 11 + tests/virshtestdata/echo-escaping.out | 11 + tests/virshtestdata/echo-quote-removal-1.out | 1 + tests/virshtestdata/echo-quote-removal-2.out | 1 + tests/virshtestdata/echo-quote-removal-3.out | 1 + tests/virshtestdata/echo-quote-removal-4.out | 1 + tests/virshtestdata/echo-quote-removal-5.out | 1 + tests/virshtestdata/echo-quote-removal-6.out | 1 + tests/virshtestdata/echo-quote-removal-7.out | 2 + tests/virshtestdata/echo-quote-removal-8.out | 1 + tests/virshtestdata/echo-split.in | 5 + tests/virshtestdata/echo-split.out | 24 + tests/virshtestdata/info-custom.in | 2 + tests/virshtestdata/info-custom.out | 15 + tests/virshtestdata/info-default.in | 2 + tests/virshtestdata/info-default.out | 13 + tests/virshtestdata/iothreads.in | 14 + tests/virshtestdata/iothreads.out | 51 + tests/virshtestdata/lifecycle.in | 23 + tests/virshtestdata/lifecycle.out | 106 +++ tests/virshtestdata/multiple-commands-1.out | 2 + tests/virshtestdata/multiple-commands-10.out | 1 + tests/virshtestdata/multiple-commands-11.out | 1 + tests/virshtestdata/multiple-commands-12.out | 1 + tests/virshtestdata/multiple-commands-2.out | 2 + tests/virshtestdata/multiple-commands-3.out | 2 + tests/virshtestdata/multiple-commands-4.out | 2 + tests/virshtestdata/multiple-commands-5.out | 3 + tests/virshtestdata/multiple-commands-6.out | 1 + tests/virshtestdata/multiple-commands-7.out | 2 + tests/virshtestdata/multiple-commands-8.out | 2 + tests/virshtestdata/multiple-commands-9.out | 1 + tests/virshtestdata/numeric-parsing-event.in | 26 + tests/virshtestdata/numeric-parsing-event.out | 10 + tests/virshtestdata/numeric-parsing.in | 43 + tests/virshtestdata/numeric-parsing.out | 12 + tests/virshtestdata/pool-define-as.out | 12 + tests/virshtestdata/read-big-pipe.out | 7 + .../schedinfo-invalid-argument.out | 5 + tests/virshtestdata/snapshot-create-args.in | 9 + tests/virshtestdata/snapshot-create-args.out | 82 ++ tests/virshtestdata/snapshot-redefine.out | 17 + tests/virshtestdata/snapshot-s2.xml | 43 + tests/virshtestdata/snapshot-s3.xml | 40 + tests/virshtestdata/snapshot.in | 54 ++ tests/virshtestdata/snapshot.out | 173 ++++ .../uriprecedence-LIBVIRT_DEFAULT_URI.out | 5 + ...riprecedence-VIRSH_DEFAULT_CONNECT_URI.out | 5 + tests/virshtestdata/uriprecedence-param.out | 5 + .../uriprecedence-xdg-config.out | 5 + .../bad/libvirt/libvirt.conf | 1 + .../good/libvirt/libvirt.conf | 1 + tests/virshtestdata/vcpupin.in | 23 + tests/virshtestdata/vcpupin.out | 26 + tests/virt-admin-self-test | 1 - tools/meson.build | 4 +- tools/virsh-checkpoint.c | 18 +- tools/virsh-snapshot.c | 18 +- tools/vsh.c | 5 - 115 files changed, 2352 insertions(+), 2852 deletions(-) delete mode 100755 tests/libvirtd-fail delete mode 100755 tests/libvirtd-pool create mode 100644 tests/qemuxmlconfdata/console-compat-crash.x86_64-latest.args create mode 100644 tests/qemuxmlconfdata/console-compat-crash.x86_64-latest.xml rename tests/{virsh-define-dev-segfault => qemuxmlconfdata/console-compat-crash.xml} (59%) mode change 100755 => 100644 create mode 100644 tests/qemuxmlconfdata/cpuset-invalid.x86_64-latest.err create mode 100644 tests/qemuxmlconfdata/cpuset-invalid.xml delete mode 100644 tests/test-lib.sh delete mode 100755 tests/virsh-checkpoint delete mode 100755 tests/virsh-cpuset delete mode 100755 tests/virsh-int-overflow delete mode 100755 tests/virsh-optparse delete mode 100755 tests/virsh-output delete mode 100755 tests/virsh-output-commands delete mode 100644 tests/virsh-output.out delete mode 100755 tests/virsh-read-bufsiz delete mode 100755 tests/virsh-read-non-seekable delete mode 100755 tests/virsh-schedinfo delete mode 100755 tests/virsh-self-test delete mode 100755 tests/virsh-snapshot delete mode 100755 tests/virsh-start delete mode 100755 tests/virsh-undefine delete mode 100755 tests/virsh-uriprecedence delete mode 100755 tests/virsh-vcpupin create mode 100644 tests/virshtestdata/argument-assignment.in create mode 100644 tests/virshtestdata/argument-assignment.out create mode 100755 tests/virshtestdata/attach-disk.in create mode 100644 tests/virshtestdata/attach-disk.out create mode 100644 tests/virshtestdata/blkiotune.in create mode 100644 tests/virshtestdata/blkiotune.out create mode 100644 tests/virshtestdata/checkpoint-c2.xml create mode 100644 tests/virshtestdata/checkpoint-c3.xml create mode 100644 tests/virshtestdata/checkpoint-redefine.out create mode 100755 tests/virshtestdata/checkpoint.in create mode 100644 tests/virshtestdata/checkpoint.out create mode 100644 tests/virshtestdata/dash-dash-argument-1.out create mode 100644 tests/virshtestdata/dash-dash-argument-2.out create mode 100644 tests/virshtestdata/dash-dash-argument-3.out create mode 100644 tests/virshtestdata/dash-dash-argument-4.out create mode 100644 tests/virshtestdata/dash-dash-argument-5.out create mode 100644 tests/virshtestdata/dash-dash-argument-6.out create mode 100644 tests/virshtestdata/domain-id-overflow.out create mode 100644 tests/virshtestdata/domain-id.in create mode 100644 tests/virshtestdata/domain-id.out create mode 100644 tests/virshtestdata/echo-alias-argv.out create mode 100644 tests/virshtestdata/echo-alias.in create mode 100644 tests/virshtestdata/echo-alias.out create mode 100644 tests/virshtestdata/echo-escaping-1.out create mode 100644 tests/virshtestdata/echo-escaping-2.out create mode 100644 tests/virshtestdata/echo-escaping-3.out create mode 100644 tests/virshtestdata/echo-escaping.in create mode 100644 tests/virshtestdata/echo-escaping.out create mode 100644 tests/virshtestdata/echo-quote-removal-1.out create mode 100644 tests/virshtestdata/echo-quote-removal-2.out create mode 100644 tests/virshtestdata/echo-quote-removal-3.out create mode 100644 tests/virshtestdata/echo-quote-removal-4.out create mode 100644 tests/virshtestdata/echo-quote-removal-5.out create mode 100644 tests/virshtestdata/echo-quote-removal-6.out create mode 100644 tests/virshtestdata/echo-quote-removal-7.out create mode 100644 tests/virshtestdata/echo-quote-removal-8.out create mode 100644 tests/virshtestdata/echo-split.in create mode 100644 tests/virshtestdata/echo-split.out create mode 100644 tests/virshtestdata/info-custom.in create mode 100644 tests/virshtestdata/info-custom.out create mode 100644 tests/virshtestdata/info-default.in create mode 100644 tests/virshtestdata/info-default.out create mode 100644 tests/virshtestdata/iothreads.in create mode 100644 tests/virshtestdata/iothreads.out create mode 100644 tests/virshtestdata/lifecycle.in create mode 100644 tests/virshtestdata/lifecycle.out create mode 100644 tests/virshtestdata/multiple-commands-1.out create mode 100644 tests/virshtestdata/multiple-commands-10.out create mode 100644 tests/virshtestdata/multiple-commands-11.out create mode 100644 tests/virshtestdata/multiple-commands-12.out create mode 100644 tests/virshtestdata/multiple-commands-2.out create mode 100644 tests/virshtestdata/multiple-commands-3.out create mode 100644 tests/virshtestdata/multiple-commands-4.out create mode 100644 tests/virshtestdata/multiple-commands-5.out create mode 100644 tests/virshtestdata/multiple-commands-6.out create mode 100644 tests/virshtestdata/multiple-commands-7.out create mode 100644 tests/virshtestdata/multiple-commands-8.out create mode 100644 tests/virshtestdata/multiple-commands-9.out create mode 100644 tests/virshtestdata/numeric-parsing-event.in create mode 100644 tests/virshtestdata/numeric-parsing-event.out create mode 100644 tests/virshtestdata/numeric-parsing.in create mode 100644 tests/virshtestdata/numeric-parsing.out create mode 100644 tests/virshtestdata/pool-define-as.out create mode 100644 tests/virshtestdata/read-big-pipe.out create mode 100644 tests/virshtestdata/schedinfo-invalid-argument.out create mode 100644 tests/virshtestdata/snapshot-create-args.in create mode 100644 tests/virshtestdata/snapshot-create-args.out create mode 100644 tests/virshtestdata/snapshot-redefine.out create mode 100644 tests/virshtestdata/snapshot-s2.xml create mode 100644 tests/virshtestdata/snapshot-s3.xml create mode 100755 tests/virshtestdata/snapshot.in create mode 100644 tests/virshtestdata/snapshot.out create mode 100644 tests/virshtestdata/uriprecedence-LIBVIRT_DEFAULT_URI.out create mode 100644 tests/virshtestdata/uriprecedence-VIRSH_DEFAULT_CONNECT_URI.out create mode 100644 tests/virshtestdata/uriprecedence-param.out create mode 100644 tests/virshtestdata/uriprecedence-xdg-config.out create mode 100644 tests/virshtestdata/uriprecedence-xdg/bad/libvirt/libvirt.conf create mode 100644 tests/virshtestdata/uriprecedence-xdg/good/libvirt/libvirt.conf create mode 100755 tests/virshtestdata/vcpupin.in create mode 100644 tests/virshtestdata/vcpupin.out delete mode 120000 tests/virt-admin-self-test -- 2.44.0

Modify testCompareOutputLit to take a filename argument and compare it against and populate the arguments. For tests which don't use the 'data' from virTestRun, we'll expect to pass the output filename, thus we also propagate it. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- build-aux/syntax-check.mk | 6 +- tests/virshtest.c | 130 +++++++++++++++++++++----------------- 2 files changed, 76 insertions(+), 60 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 2ac8c5760f..0759372b2b 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1386,7 +1386,7 @@ exclude_file_name_regexp--sc_prohibit_close = \ (\.p[yl]$$|\.spec\.in$$|^docs/|^(src/util/vir(file|event)\.c|src/libvirt-stream\.c|tests/(vir.+mock\.c|commandhelper\.c|qemusecuritymock\.c)|tools/nss/libvirt_nss_(leases|macs)\.c)|tools/virt-qemu-qmp-proxy$$) exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = \ - ((^tests/(nodedevmdevctl|viracpi|virhostcpu|virpcitest|virstoragetest|qemunbdkit)data/|docs/js/.*\.js|docs/fonts/.*\.woff|\.diff|tests/virconfdata/no-newline\.conf$$)|\.bin) + ((^tests/(nodedevmdevctl|viracpi|virhostcpu|virpcitest|virstoragetest|qemunbdkit|virshtest)data/|docs/js/.*\.js|docs/fonts/.*\.woff|\.diff|tests/virconfdata/no-newline\.conf$$)|\.bin) exclude_file_name_regexp--sc_prohibit_fork_wrappers = \ (^(src/(util/(vircommand|virdaemon)|lxc/lxc_controller)|tests/testutils)\.c$$) @@ -1437,7 +1437,7 @@ exclude_file_name_regexp--sc_require_config_h_first = \ ^(examples/|tools/virsh-edit\.c$$|tests/virmockstathelpers\.c$$|scripts/rpcgen/tests/test_demo\.c$$) exclude_file_name_regexp--sc_trailing_blank = \ - /sysinfodata/.*\.data|/virhostcpudata/.*\.cpuinfo$$ + /sysinfodata/.*\.data|/virhostcpudata/.*\.cpuinfo|tests/virshtestdata/.*$$ exclude_file_name_regexp--sc_unmarked_diagnostics = \ ^(scripts/apibuild.py|tests/virt-aa-helper-test|docs/js/.*\.js)$$ @@ -1466,7 +1466,7 @@ exclude_file_name_regexp--sc_prohibit_mixed_case_abbreviations = \ ^src/(vbox/vbox_CAPI.*.h|esx/esx_vi.(c|h)|esx/esx_storage_backend_iscsi.c)$$ exclude_file_name_regexp--sc_prohibit_empty_first_line = \ - ^tests/vmwareverdata/fusion-5.0.3.txt|scripts/rpcgen/tests/demo\.c$$ + ^tests/vmwareverdata/fusion-5.0.3.txt|scripts/rpcgen/tests/demo\.c|^tests/virshtestdata/.*$$ exclude_file_name_regexp--sc_prohibit_useless_translation = \ ^tests/virpolkittest.c diff --git a/tests/virshtest.c b/tests/virshtest.c index cf834bb847..5a5068dc78 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -108,8 +108,10 @@ static int testFilterLine(char *buffer, } static int -testCompareOutputLit(const char *expectData, - const char *filter, const char *const argv[]) +testCompareOutputLit(const char *expectFile, + const char *expectData, + const char *filter, + const char *const argv[]) { g_autofree char *actualData = NULL; const char *empty = ""; @@ -134,8 +136,14 @@ testCompareOutputLit(const char *expectData, if (filter && testFilterLine(actualData, filter) < 0) return -1; - if (virTestCompareToString(expectData, actualData) < 0) { - return -1; + if (expectData) { + if (virTestCompareToString(expectData, actualData) < 0) + return -1; + } + + if (expectFile) { + if (virTestCompareToFileFull(actualData, expectFile, false) < 0) + return -1; } return 0; @@ -151,7 +159,7 @@ static char *custom_uri; "--connect", \ custom_uri -static int testCompareListDefault(const void *data G_GNUC_UNUSED) +static int testCompareListDefault(const void *data) { const char *const argv[] = { VIRSH_DEFAULT, "list", NULL }; const char *exp = "\ @@ -159,10 +167,10 @@ static int testCompareListDefault(const void *data G_GNUC_UNUSED) ----------------------\n\ 1 test running\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareListCustom(const void *data G_GNUC_UNUSED) +static int testCompareListCustom(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "list", NULL }; const char *exp = "\ @@ -172,10 +180,10 @@ static int testCompareListCustom(const void *data G_GNUC_UNUSED) 2 fc4 running\n\ 3 fc5 running\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareNodeinfoDefault(const void *data G_GNUC_UNUSED) +static int testCompareNodeinfoDefault(const void *data) { const char *const argv[] = { VIRSH_DEFAULT, "nodeinfo", NULL }; const char *exp = "\ @@ -188,10 +196,10 @@ Thread(s) per core: 2\n\ NUMA cell(s): 2\n\ Memory size: 3145728 KiB\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareNodeinfoCustom(const void *data G_GNUC_UNUSED) +static int testCompareNodeinfoCustom(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, @@ -208,115 +216,115 @@ Thread(s) per core: 2\n\ NUMA cell(s): 4\n\ Memory size: 8192000 KiB\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDominfoByID(const void *data G_GNUC_UNUSED) +static int testCompareDominfoByID(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "dominfo", "2", NULL }; const char *exp = dominfo_fc4; - return testCompareOutputLit(exp, "\nCPU time:", argv); + return testCompareOutputLit((const char *) data, exp, "\nCPU time:", argv); } -static int testCompareDominfoByUUID(const void *data G_GNUC_UNUSED) +static int testCompareDominfoByUUID(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "dominfo", DOM_FC4_UUID, NULL }; const char *exp = dominfo_fc4; - return testCompareOutputLit(exp, "\nCPU time:", argv); + return testCompareOutputLit((const char *) data, exp, "\nCPU time:", argv); } -static int testCompareDominfoByName(const void *data G_GNUC_UNUSED) +static int testCompareDominfoByName(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "dominfo", "fc4", NULL }; const char *exp = dominfo_fc4; - return testCompareOutputLit(exp, "\nCPU time:", argv); + return testCompareOutputLit((const char *) data, exp, "\nCPU time:", argv); } -static int testCompareTaintedDominfoByName(const void *data G_GNUC_UNUSED) +static int testCompareTaintedDominfoByName(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "dominfo", "fc5", NULL }; const char *exp = dominfo_fc5; - return testCompareOutputLit(exp, "\nCPU time:", argv); + return testCompareOutputLit((const char *) data, exp, "\nCPU time:", argv); } -static int testCompareDomuuidByID(const void *data G_GNUC_UNUSED) +static int testCompareDomuuidByID(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "domuuid", "2", NULL }; const char *exp = domuuid_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomuuidByName(const void *data G_GNUC_UNUSED) +static int testCompareDomuuidByName(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "domuuid", "fc4", NULL }; const char *exp = domuuid_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomidByName(const void *data G_GNUC_UNUSED) +static int testCompareDomidByName(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "domid", "fc4", NULL }; const char *exp = domid_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomidByUUID(const void *data G_GNUC_UNUSED) +static int testCompareDomidByUUID(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "domid", DOM_FC4_UUID, NULL }; const char *exp = domid_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomnameByID(const void *data G_GNUC_UNUSED) +static int testCompareDomnameByID(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "domname", "2", NULL }; const char *exp = domname_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomnameByUUID(const void *data G_GNUC_UNUSED) +static int testCompareDomnameByUUID(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "domname", DOM_FC4_UUID, NULL }; const char *exp = domname_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomstateByID(const void *data G_GNUC_UNUSED) +static int testCompareDomstateByID(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "domstate", "2", NULL }; const char *exp = domstate_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomstateByUUID(const void *data G_GNUC_UNUSED) +static int testCompareDomstateByUUID(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "domstate", DOM_FC4_UUID, NULL }; const char *exp = domstate_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomstateByName(const void *data G_GNUC_UNUSED) +static int testCompareDomstateByName(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "domstate", "fc4", NULL }; const char *exp = domstate_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomControlInfoByName(const void *data G_GNUC_UNUSED) +static int testCompareDomControlInfoByName(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "domcontrol", "fc4", NULL }; const char *exp = "ok\n\n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareGetBlkioParameters(const void *data G_GNUC_UNUSED) +static int testCompareGetBlkioParameters(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "blkiotune", "fv0", NULL }; const char *exp = get_blkio_parameters; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareSetBlkioParameters(const void *data G_GNUC_UNUSED) +static int testCompareSetBlkioParameters(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "blkiotune fv0\ --weight 500\ @@ -332,10 +340,10 @@ static int testCompareSetBlkioParameters(const void *data G_GNUC_UNUSED) " SET_BLKIO_PARAMETER ";\ blkiotune fv0", NULL }; const char *exp = set_blkio_parameters; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testIOThreadAdd(const void *data G_GNUC_UNUSED) +static int testIOThreadAdd(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "iothreadinfo --domain fc4;\ iothreadadd --domain fc4 --id 6;\ @@ -353,10 +361,10 @@ static int testIOThreadAdd(const void *data G_GNUC_UNUSED) 4 0\n\ 6 0\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testIOThreadDel(const void *data G_GNUC_UNUSED) +static int testIOThreadDel(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "iothreadinfo --domain fc4;\ iothreaddel --domain fc4 --id 2;\ @@ -372,10 +380,10 @@ static int testIOThreadDel(const void *data G_GNUC_UNUSED) -----------------------------\n\ 4 0\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testIOThreadSet(const void *data G_GNUC_UNUSED) +static int testIOThreadSet(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "domstats --domain fc4;\ iothreadset --domain fc4\ @@ -404,10 +412,10 @@ Domain: 'fc4'\n\ iothread.4.poll-max-ns" EQUAL "32768\n\ iothread.4.poll-grow" EQUAL "0\n\ iothread.4.poll-shrink" EQUAL "0\n\n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testIOThreadPin(const void *data G_GNUC_UNUSED) +static int testIOThreadPin(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "iothreadadd --domain fc5 --id 2;\ @@ -425,18 +433,27 @@ static int testIOThreadPin(const void *data G_GNUC_UNUSED) -----------------------------\n\ 2 0\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } struct testInfo { + const char *testname; /* used to generate output filename */ + const char *filter; const char *const *argv; const char *result; }; -static int testCompareEcho(const void *data) +static int testCompare(const void *data) { const struct testInfo *info = data; - return testCompareOutputLit(info->result, NULL, info->argv); + g_autofree char *outfile = NULL; + + if (info->testname) { + outfile = g_strdup_printf("%s/virshtestdata/%s.out", + abs_srcdir, info->testname); + } + + return testCompareOutputLit(outfile, info->result, info->filter, info->argv); } @@ -549,9 +566,8 @@ mymain(void) # define DO_TEST(i, result, ...) \ do { \ const char *myargv[] = { VIRSH_DEFAULT, __VA_ARGS__, NULL }; \ - const struct testInfo info = { myargv, result }; \ - if (virTestRun("virsh echo " #i, \ - testCompareEcho, &info) < 0) \ + const struct testInfo info = { NULL, NULL, myargv, result }; \ + if (virTestRun("virsh echo " #i, testCompare, &info) < 0) \ ret = -1; \ } while (0) -- 2.44.0

Modify the test code so that if virsh fails both 'stdout' and 'stderr' are captured and compared against the output and also the return value is checked by appending it to the output. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 5a5068dc78..4097c1d427 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -113,36 +113,37 @@ testCompareOutputLit(const char *expectFile, const char *filter, const char *const argv[]) { - g_autofree char *actualData = NULL; + g_autofree char *actual = NULL; const char *empty = ""; g_autoptr(virCommand) cmd = NULL; - g_autofree char *errbuf = NULL; + int exitstatus = 0; cmd = virCommandNewArgs(argv); virCommandAddEnvString(cmd, "LANG=C"); virCommandSetInputBuffer(cmd, empty); - virCommandSetOutputBuffer(cmd, &actualData); - virCommandSetErrorBuffer(cmd, &errbuf); + virCommandSetOutputBuffer(cmd, &actual); + virCommandSetErrorBuffer(cmd, &actual); - if (virCommandRun(cmd, NULL) < 0) + if (virCommandRun(cmd, &exitstatus) < 0) return -1; - if (STRNEQ(errbuf, "")) { - fprintf(stderr, "Command reported error: %s", errbuf); - return -1; + if (exitstatus != 0) { + g_autofree char *tmp = g_steal_pointer(&actual); + + actual = g_strdup_printf("%s\n## Exit code: %d\n", tmp, exitstatus); } - if (filter && testFilterLine(actualData, filter) < 0) + if (filter && testFilterLine(actual, filter) < 0) return -1; if (expectData) { - if (virTestCompareToString(expectData, actualData) < 0) + if (virTestCompareToString(expectData, actual) < 0) return -1; } if (expectFile) { - if (virTestCompareToFileFull(actualData, expectFile, false) < 0) + if (virTestCompareToFileFull(actual, expectFile, false) < 0) return -1; } -- 2.44.0

Upcoming patches will require that possibly multiple occurences of the string to drop are present in the output string thus we need to adapt testFilterLine to handle them. Additionally we drop the unused return value. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 4097c1d427..e0b5cd3150 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -90,21 +90,20 @@ device_read_bytes_sec: " SET_BLKIO_PARAMETER "\n\ device_write_bytes_sec: " SET_BLKIO_PARAMETER "\n\ \n"; -static int testFilterLine(char *buffer, - const char *toRemove) +static void testFilterLine(char *buffer, + const char *toRemove) { char *start; - char *end; - if (!(start = strstr(buffer, toRemove))) - return -1; + while ((start = strstr(buffer, toRemove))) { + char *end; - if (!(end = strstr(start+1, "\n"))) { - *start = '\0'; - } else { - memmove(start, end, strlen(end)+1); + if (!(end = strstr(start+1, "\n"))) { + *start = '\0'; + } else { + memmove(start, end, strlen(end)+1); + } } - return 0; } static int @@ -134,8 +133,8 @@ testCompareOutputLit(const char *expectFile, actual = g_strdup_printf("%s\n## Exit code: %d\n", tmp, exitstatus); } - if (filter && testFilterLine(actual, filter) < 0) - return -1; + if (filter) + testFilterLine(actual, filter); if (expectData) { if (virTestCompareToString(expectData, actual) < 0) -- 2.44.0

Add support for reading a file and passing it to virsh in 'batch' mode so that multiple commands can be easily tested with one invocation of virsh. To show how it's used adapt the alias handling tests to be invoked all at once. As in batch mode the arguments are read from a string and separated inside virsh, one test is kept separate to be parsed in argv mode. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 25 +++++++++++++++++++++---- tests/virshtestdata/echo-alias.in | 3 +++ tests/virshtestdata/echo-alias.out | 3 +++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 tests/virshtestdata/echo-alias.in create mode 100644 tests/virshtestdata/echo-alias.out diff --git a/tests/virshtest.c b/tests/virshtest.c index e0b5cd3150..376fb861ed 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -561,6 +561,26 @@ mymain(void) testIOThreadPin, NULL) != 0) ret = -1; +# define DO_TEST_SCRIPT(testname_, testfilter, ...) \ + { \ + const char *testname = testname_; \ + g_autofree char *infile = g_strdup_printf("%s/virshtestdata/%s.in", \ + abs_srcdir, testname); \ + const char *myargv[] = { __VA_ARGS__, NULL, NULL }; \ + const char **tmp = myargv; \ + const struct testInfo info = { testname, testfilter, myargv, NULL }; \ + g_autofree char *scriptarg = NULL; \ + if (virFileReadAll(infile, 256 * 1024, &scriptarg) < 0) { \ + fprintf(stderr, "\nfailed to load '%s'\n", infile); \ + ret = -1; \ + } \ + while (*tmp) \ + tmp++; \ + *tmp = scriptarg; \ + if (virTestRun(testname, testCompare, &info) < 0) \ + ret = -1; \ + } while (0); + /* It's a bit awkward listing result before argument, but that's a * limitation of C99 vararg macros. */ # define DO_TEST(i, result, ...) \ @@ -644,11 +664,8 @@ mymain(void) "echo \t '-'\"-\" \t --shell \t a"); /* Tests of alias handling. */ - DO_TEST(31, "hello\n", "echo", "--string", "hello"); - DO_TEST(32, "hello\n", "echo --string hello"); + DO_TEST_SCRIPT("echo-alias", NULL, VIRSH_DEFAULT); DO_TEST(33, "hello\n", "echo", "--str", "hello"); - DO_TEST(34, "hello\n", "echo --str hello"); - DO_TEST(35, "hello\n", "echo --hi"); /* Tests of multiple commands. */ DO_TEST(36, "a\nb\n", " echo a; echo b;"); diff --git a/tests/virshtestdata/echo-alias.in b/tests/virshtestdata/echo-alias.in new file mode 100644 index 0000000000..f123437490 --- /dev/null +++ b/tests/virshtestdata/echo-alias.in @@ -0,0 +1,3 @@ +echo --string hello +echo --str hello +echo --hi; diff --git a/tests/virshtestdata/echo-alias.out b/tests/virshtestdata/echo-alias.out new file mode 100644 index 0000000000..640bb73cf1 --- /dev/null +++ b/tests/virshtestdata/echo-alias.out @@ -0,0 +1,3 @@ +hello +hello +hello -- 2.44.0

Optimize invocation of the tests to share one 'virsh' binary as they don't influence each other. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 11 +---------- tests/virshtestdata/echo-split.in | 5 +++++ tests/virshtestdata/echo-split.out | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 tests/virshtestdata/echo-split.in create mode 100644 tests/virshtestdata/echo-split.out diff --git a/tests/virshtest.c b/tests/virshtest.c index 376fb861ed..51314859b9 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -682,16 +682,7 @@ mymain(void) DO_TEST(47, "a\n", "\\# ignored;echo a\n'#also' ignored"); /* test of splitting in vshStringToArray */ - DO_TEST(48, "a\nb,c,\nd,,e,,\nf,,,e\n", - "-q", "echo", "--split", "a,b,,c,,,d,,,,e,,,,,f,,,,,,e"); - DO_TEST(49, "\na\nb,c,\nd,,e,,\nf,,,e\n\n", - "-q", "echo", "--split", ",a,b,,c,,,d,,,,e,,,,,f,,,,,,e,"); - DO_TEST(50, ",a\nb,c,\nd,,e,,\nf,,,e,\n", - "-q", "echo", "--split", ",,a,b,,c,,,d,,,,e,,,,,f,,,,,,e,,"); - DO_TEST(51, ",\na\nb,c,\nd,,e,,\nf,,,e,\n\n", - "-q", "echo", "--split", ",,,a,b,,c,,,d,,,,e,,,,,f,,,,,,e,,,"); - DO_TEST(52, ",,a\nb,c,\nd,,e,,\nf,,,e,,\n", - "-q", "echo", "--split", ",,,,a,b,,c,,,d,,,,e,,,,,f,,,,,,e,,,,"); + DO_TEST_SCRIPT("echo-split", NULL, VIRSH_DEFAULT, "-q"); # undef DO_TEST VIR_FREE(custom_uri); diff --git a/tests/virshtestdata/echo-split.in b/tests/virshtestdata/echo-split.in new file mode 100644 index 0000000000..2df9f4da97 --- /dev/null +++ b/tests/virshtestdata/echo-split.in @@ -0,0 +1,5 @@ +echo --split a,b,,c,,,d,,,,e,,,,,f,,,,,,e +echo --split ,a,b,,c,,,d,,,,e,,,,,f,,,,,,e, +echo --split ,,a,b,,c,,,d,,,,e,,,,,f,,,,,,e,, +echo --split ,,,a,b,,c,,,d,,,,e,,,,,f,,,,,,e,,, +echo --split ,,,,a,b,,c,,,d,,,,e,,,,,f,,,,,,e,,,, diff --git a/tests/virshtestdata/echo-split.out b/tests/virshtestdata/echo-split.out new file mode 100644 index 0000000000..88bf09c225 --- /dev/null +++ b/tests/virshtestdata/echo-split.out @@ -0,0 +1,24 @@ +a +b,c, +d,,e,, +f,,,e + +a +b,c, +d,,e,, +f,,,e + +,a +b,c, +d,,e,, +f,,,e, +, +a +b,c, +d,,e,, +f,,,e, + +,,a +b,c, +d,,e,, +f,,,e,, -- 2.44.0

Both argument passing and multiple command handling is already tested in the 'multiple commands' cases. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 51314859b9..a60cfdf7a0 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -592,12 +592,6 @@ mymain(void) } while (0) /* Arg parsing quote removal tests. */ - DO_TEST(0, "\n", - "echo"); - DO_TEST(1, "a\n", - "echo", "a"); - DO_TEST(2, "a b\n", - "echo", "a", "b"); DO_TEST(3, "a b\n", "echo a \t b"); DO_TEST(4, "a \t b\n", @@ -606,10 +600,6 @@ mymain(void) "echo 'a \t b'"); DO_TEST(6, "a \t b\n", "echo a\\ \\\t\\ b"); - DO_TEST(7, "\n\n", - "echo ; echo"); - DO_TEST(8, "a\nb\n", - ";echo a; ; echo b;"); DO_TEST(9, "' \" \\;echo\ta\n", "echo", "'", "\"", "\\;echo\ta"); DO_TEST(10, "' \" ;echo a\n", -- 2.44.0

Express what's possible via a "virsh script" rather than invoking separate virsh for each one. We need to keep a few for parity as the argument parser behaves differently when processing argv-like input compared to a string. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 20 +------------------- tests/virshtestdata/echo-escaping.in | 11 +++++++++++ tests/virshtestdata/echo-escaping.out | 11 +++++++++++ 3 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 tests/virshtestdata/echo-escaping.in create mode 100644 tests/virshtestdata/echo-escaping.out diff --git a/tests/virshtest.c b/tests/virshtest.c index a60cfdf7a0..4b02ef3a49 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -610,6 +610,7 @@ mymain(void) "echo \"'\" '\"' '\\'\"\\\\\""); /* Tests of echo flags. */ + DO_TEST_SCRIPT("echo-escaping", NULL, VIRSH_DEFAULT); DO_TEST(13, "a A 0 + * ; . ' \" / ? = \n < > &\n", "echo", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", "=", " ", "\n", "<", ">", "&"); @@ -619,25 +620,6 @@ mymain(void) DO_TEST(15, "a A 0 + * ; . ' " / ? = \n < > &\n", "echo", "--xml", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", "=", " ", "\n", "<", ">", "&"); - DO_TEST(16, "a A 0 + '*' ';' . ''\\''' '\"' / '?' = ' ' '\n' '<' '>' '&'\n", - "echo", "--shell", "a", "A", "0", "+", "*", ";", ".", "\'", - "\"", "/", "?", "=", " ", "\n", "<", ">", "&"); - DO_TEST(17, "\n", - "echo", ""); - DO_TEST(18, "''\n", - "echo", "--shell", ""); - DO_TEST(19, "\n", - "echo", "--xml", ""); - DO_TEST(20, "''\n", - "echo", "--shell", ""); - DO_TEST(21, "\n", - "echo ''"); - DO_TEST(22, "''\n", - "echo --shell \"\""); - DO_TEST(23, "\n", - "echo --xml ''"); - DO_TEST(24, "''\n", - "echo --shell \"\"''"); /* Tests of -- handling. */ DO_TEST(25, "a\n", diff --git a/tests/virshtestdata/echo-escaping.in b/tests/virshtestdata/echo-escaping.in new file mode 100644 index 0000000000..26d4e4cc18 --- /dev/null +++ b/tests/virshtestdata/echo-escaping.in @@ -0,0 +1,11 @@ +echo a A 0 + * . \' / ? = < > & +echo --xml a A 0 + * . \' / ? = < > & +echo --shell a A 0 + * . \' / ? = < > & +echo "" +echo --shell +echo --xml +echo --shell +echo '' +echo --shell "" +echo --xml '' +echo --shell ""'' diff --git a/tests/virshtestdata/echo-escaping.out b/tests/virshtestdata/echo-escaping.out new file mode 100644 index 0000000000..ff3e0a98b3 --- /dev/null +++ b/tests/virshtestdata/echo-escaping.out @@ -0,0 +1,11 @@ +a A 0 + * . ' / ? = < > & +a A 0 + * . ' / ? = < > & +a A 0 + '*' . ''\''' / '?' = '<' '>' '&' + + + + + +'' + +'' -- 2.44.0

Embedding the expected output in a C source code makes it very hard to extend tests. In order to be able to test the outputs against data in files on disk we need better naming of the tests themselves. Use virTestCounterNext/Reset with appropriate tags to give reasonable names to the 'virsh echo' tests' and prepare the 'DO_TEST' macro for wider use. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 99 +++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 55 deletions(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 4b02ef3a49..fc1246a96d 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -581,77 +581,66 @@ mymain(void) ret = -1; \ } while (0); - /* It's a bit awkward listing result before argument, but that's a - * limitation of C99 vararg macros. */ -# define DO_TEST(i, result, ...) \ +# define DO_TEST_FULL(testname_, filter, result, ...) \ do { \ - const char *myargv[] = { VIRSH_DEFAULT, __VA_ARGS__, NULL }; \ + const char *testname = testname_; \ + const char *myargv[] = { __VA_ARGS__, NULL }; \ const struct testInfo info = { NULL, NULL, myargv, result }; \ - if (virTestRun("virsh echo " #i, testCompare, &info) < 0) \ + if (virTestRun(testname, testCompare, &info) < 0) \ ret = -1; \ } while (0) + /* automatically numbered test invocation */ +# define DO_TEST(result, ...) \ + DO_TEST_FULL(virTestCounterNext(), NULL, result, VIRSH_DEFAULT, __VA_ARGS__); + + /* Arg parsing quote removal tests. */ - DO_TEST(3, "a b\n", - "echo a \t b"); - DO_TEST(4, "a \t b\n", - "echo \"a \t b\""); - DO_TEST(5, "a \t b\n", - "echo 'a \t b'"); - DO_TEST(6, "a \t b\n", - "echo a\\ \\\t\\ b"); - DO_TEST(9, "' \" \\;echo\ta\n", - "echo", "'", "\"", "\\;echo\ta"); - DO_TEST(10, "' \" ;echo a\n", - "echo \\' \\\" \\;echo\ta"); - DO_TEST(11, "' \" \\\na\n", - "echo \\' \\\" \\\\;echo\ta"); - DO_TEST(12, "' \" \\\\\n", - "echo \"'\" '\"' '\\'\"\\\\\""); + virTestCounterReset("echo-quote-removal-"); + DO_TEST("a b\n", "echo a \t b"); + DO_TEST("a \t b\n", "echo \"a \t b\""); + DO_TEST("a \t b\n", "echo 'a \t b'"); + DO_TEST("a \t b\n", "echo a\\ \\\t\\ b"); + DO_TEST("' \" \\;echo\ta\n", "echo", "'", "\"", "\\;echo\ta"); + DO_TEST("' \" ;echo a\n", "echo \\' \\\" \\;echo\ta"); + DO_TEST("' \" \\\na\n", "echo \\' \\\" \\\\;echo\ta"); + DO_TEST("' \" \\\\\n", "echo \"'\" '\"' '\\'\"\\\\\""); /* Tests of echo flags. */ DO_TEST_SCRIPT("echo-escaping", NULL, VIRSH_DEFAULT); - DO_TEST(13, "a A 0 + * ; . ' \" / ? = \n < > &\n", - "echo", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", - "=", " ", "\n", "<", ">", "&"); - DO_TEST(14, "a A 0 + '*' ';' . ''\\''' '\"' / '?' = ' ' '\n' '<' '>' '&'\n", - "echo", "--shell", "a", "A", "0", "+", "*", ";", ".", "'", "\"", - "/", "?", "=", " ", "\n", "<", ">", "&"); - DO_TEST(15, "a A 0 + * ; . ' " / ? = \n < > &\n", - "echo", "--xml", "a", "A", "0", "+", "*", ";", ".", "'", "\"", - "/", "?", "=", " ", "\n", "<", ">", "&"); + + virTestCounterReset("echo-escaping-"); + DO_TEST("a A 0 + * ; . ' \" / ? = \n < > &\n", "echo", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", "=", " ", "\n", "<", ">", "&"); + DO_TEST("a A 0 + '*' ';' . ''\\''' '\"' / '?' = ' ' '\n' '<' '>' '&'\n", "echo", "--shell", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", "=", " ", "\n", "<", ">", "&"); + DO_TEST("a A 0 + * ; . ' " / ? = \n < > &\n", "echo", "--xml", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", "=", " ", "\n", "<", ">", "&"); /* Tests of -- handling. */ - DO_TEST(25, "a\n", - "--", "echo", "--shell", "a"); - DO_TEST(26, "a\n", - "--", "echo", "a", "--shell"); - DO_TEST(27, "a --shell\n", - "--", "echo", "--", "a", "--shell"); - DO_TEST(28, "-- --shell a\n", - "echo", "--", "--", "--shell", "a"); - DO_TEST(29, "a\n", - "echo --s\\h'e'\"l\"l -- a"); - DO_TEST(30, "--shell a\n", - "echo \t '-'\"-\" \t --shell \t a"); + virTestCounterReset("dash-dash-argument-"); + DO_TEST("a\n", "--", "echo", "--shell", "a"); + DO_TEST("a\n", "--", "echo", "a", "--shell"); + DO_TEST("a --shell\n", "--", "echo", "--", "a", "--shell"); + DO_TEST("-- --shell a\n", "echo", "--", "--", "--shell", "a"); + DO_TEST("a\n", "echo --s\\h'e'\"l\"l -- a"); + DO_TEST("--shell a\n", "echo \t '-'\"-\" \t --shell \t a"); /* Tests of alias handling. */ DO_TEST_SCRIPT("echo-alias", NULL, VIRSH_DEFAULT); - DO_TEST(33, "hello\n", "echo", "--str", "hello"); + DO_TEST_FULL("echo-alias-argv", NULL, "hello\n", VIRSH_DEFAULT, "echo", "--str", "hello"); /* Tests of multiple commands. */ - DO_TEST(36, "a\nb\n", " echo a; echo b;"); - DO_TEST(37, "a\nb\n", "\necho a\n echo b\n"); - DO_TEST(38, "a\nb\n", "ec\\\nho a\n echo \\\n b;"); - DO_TEST(39, "a\n b\n", "\"ec\\\nho\" a\n echo \"\\\n b\";"); - DO_TEST(40, "a\n\\\n b\n", "ec\\\nho a\n echo '\\\n b';"); - DO_TEST(41, "a\n", "echo a # b"); - DO_TEST(42, "a\nc\n", "echo a #b\necho c"); - DO_TEST(43, "a\nc\n", "echo a # b\\\necho c"); - DO_TEST(44, "a # b\n", "echo a '#' b"); - DO_TEST(45, "a # b\n", "echo a \\# b"); - DO_TEST(46, "a\n", "#unbalanced; 'quotes\"\necho a # b"); - DO_TEST(47, "a\n", "\\# ignored;echo a\n'#also' ignored"); + virTestCounterReset("multiple-commands-"); + DO_TEST("a\nb\n", " echo a; echo b;"); + DO_TEST("a\nb\n", "\necho a\n echo b\n"); + DO_TEST("a\nb\n", "ec\\\nho a\n echo \\\n b;"); + DO_TEST("a\n b\n", "\"ec\\\nho\" a\n echo \"\\\n b\";"); + DO_TEST("a\n\\\n b\n", "ec\\\nho a\n echo '\\\n b';"); + DO_TEST("a\n", "echo a # b"); + DO_TEST("a\nc\n", "echo a #b\necho c"); + DO_TEST("a\nc\n", "echo a # b\\\necho c"); + DO_TEST("a # b\n", "echo a '#' b"); + DO_TEST("a # b\n", "echo a \\# b"); + DO_TEST("a\n", "#unbalanced; 'quotes\"\necho a # b"); + DO_TEST("a\n", "\\# ignored;echo a\n'#also' ignored"); /* test of splitting in vshStringToArray */ DO_TEST_SCRIPT("echo-split", NULL, VIRSH_DEFAULT, "-q"); -- 2.44.0

s/vrishtest/virshtest/ in the summary Jano On a Thursday in 2024, Peter Krempa wrote:
Embedding the expected output in a C source code makes it very hard to extend tests. In order to be able to test the outputs against data in files on disk we need better naming of the tests themselves.
Use virTestCounterNext/Reset with appropriate tags to give reasonable names to the 'virsh echo' tests' and prepare the 'DO_TEST' macro for wider use.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 99 +++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 55 deletions(-)

Managing output files is much simpler especially with VIR_TEST_REGENERATE_OUTPUT compared to putting the expected string blobs into the C source file. For now the output is tested both against the hardcoded strings as well as the output files. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 2 +- tests/virshtestdata/dash-dash-argument-1.out | 1 + tests/virshtestdata/dash-dash-argument-2.out | 1 + tests/virshtestdata/dash-dash-argument-3.out | 1 + tests/virshtestdata/dash-dash-argument-4.out | 1 + tests/virshtestdata/dash-dash-argument-5.out | 1 + tests/virshtestdata/dash-dash-argument-6.out | 1 + tests/virshtestdata/echo-alias-argv.out | 1 + tests/virshtestdata/echo-escaping-1.out | 2 ++ tests/virshtestdata/echo-escaping-2.out | 2 ++ tests/virshtestdata/echo-escaping-3.out | 2 ++ tests/virshtestdata/echo-quote-removal-1.out | 1 + tests/virshtestdata/echo-quote-removal-2.out | 1 + tests/virshtestdata/echo-quote-removal-3.out | 1 + tests/virshtestdata/echo-quote-removal-4.out | 1 + tests/virshtestdata/echo-quote-removal-5.out | 1 + tests/virshtestdata/echo-quote-removal-6.out | 1 + tests/virshtestdata/echo-quote-removal-7.out | 2 ++ tests/virshtestdata/echo-quote-removal-8.out | 1 + tests/virshtestdata/multiple-commands-1.out | 2 ++ tests/virshtestdata/multiple-commands-10.out | 1 + tests/virshtestdata/multiple-commands-11.out | 1 + tests/virshtestdata/multiple-commands-12.out | 1 + tests/virshtestdata/multiple-commands-2.out | 2 ++ tests/virshtestdata/multiple-commands-3.out | 2 ++ tests/virshtestdata/multiple-commands-4.out | 2 ++ tests/virshtestdata/multiple-commands-5.out | 3 +++ tests/virshtestdata/multiple-commands-6.out | 1 + tests/virshtestdata/multiple-commands-7.out | 2 ++ tests/virshtestdata/multiple-commands-8.out | 2 ++ tests/virshtestdata/multiple-commands-9.out | 1 + 31 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/virshtestdata/dash-dash-argument-1.out create mode 100644 tests/virshtestdata/dash-dash-argument-2.out create mode 100644 tests/virshtestdata/dash-dash-argument-3.out create mode 100644 tests/virshtestdata/dash-dash-argument-4.out create mode 100644 tests/virshtestdata/dash-dash-argument-5.out create mode 100644 tests/virshtestdata/dash-dash-argument-6.out create mode 100644 tests/virshtestdata/echo-alias-argv.out create mode 100644 tests/virshtestdata/echo-escaping-1.out create mode 100644 tests/virshtestdata/echo-escaping-2.out create mode 100644 tests/virshtestdata/echo-escaping-3.out create mode 100644 tests/virshtestdata/echo-quote-removal-1.out create mode 100644 tests/virshtestdata/echo-quote-removal-2.out create mode 100644 tests/virshtestdata/echo-quote-removal-3.out create mode 100644 tests/virshtestdata/echo-quote-removal-4.out create mode 100644 tests/virshtestdata/echo-quote-removal-5.out create mode 100644 tests/virshtestdata/echo-quote-removal-6.out create mode 100644 tests/virshtestdata/echo-quote-removal-7.out create mode 100644 tests/virshtestdata/echo-quote-removal-8.out create mode 100644 tests/virshtestdata/multiple-commands-1.out create mode 100644 tests/virshtestdata/multiple-commands-10.out create mode 100644 tests/virshtestdata/multiple-commands-11.out create mode 100644 tests/virshtestdata/multiple-commands-12.out create mode 100644 tests/virshtestdata/multiple-commands-2.out create mode 100644 tests/virshtestdata/multiple-commands-3.out create mode 100644 tests/virshtestdata/multiple-commands-4.out create mode 100644 tests/virshtestdata/multiple-commands-5.out create mode 100644 tests/virshtestdata/multiple-commands-6.out create mode 100644 tests/virshtestdata/multiple-commands-7.out create mode 100644 tests/virshtestdata/multiple-commands-8.out create mode 100644 tests/virshtestdata/multiple-commands-9.out diff --git a/tests/virshtest.c b/tests/virshtest.c index fc1246a96d..1750cc7abd 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -585,7 +585,7 @@ mymain(void) do { \ const char *testname = testname_; \ const char *myargv[] = { __VA_ARGS__, NULL }; \ - const struct testInfo info = { NULL, NULL, myargv, result }; \ + const struct testInfo info = { testname, NULL, myargv, result }; \ if (virTestRun(testname, testCompare, &info) < 0) \ ret = -1; \ } while (0) diff --git a/tests/virshtestdata/dash-dash-argument-1.out b/tests/virshtestdata/dash-dash-argument-1.out new file mode 100644 index 0000000000..7898192261 --- /dev/null +++ b/tests/virshtestdata/dash-dash-argument-1.out @@ -0,0 +1 @@ +a diff --git a/tests/virshtestdata/dash-dash-argument-2.out b/tests/virshtestdata/dash-dash-argument-2.out new file mode 100644 index 0000000000..7898192261 --- /dev/null +++ b/tests/virshtestdata/dash-dash-argument-2.out @@ -0,0 +1 @@ +a diff --git a/tests/virshtestdata/dash-dash-argument-3.out b/tests/virshtestdata/dash-dash-argument-3.out new file mode 100644 index 0000000000..b9f81e916d --- /dev/null +++ b/tests/virshtestdata/dash-dash-argument-3.out @@ -0,0 +1 @@ +a --shell diff --git a/tests/virshtestdata/dash-dash-argument-4.out b/tests/virshtestdata/dash-dash-argument-4.out new file mode 100644 index 0000000000..9367d302cc --- /dev/null +++ b/tests/virshtestdata/dash-dash-argument-4.out @@ -0,0 +1 @@ +-- --shell a diff --git a/tests/virshtestdata/dash-dash-argument-5.out b/tests/virshtestdata/dash-dash-argument-5.out new file mode 100644 index 0000000000..7898192261 --- /dev/null +++ b/tests/virshtestdata/dash-dash-argument-5.out @@ -0,0 +1 @@ +a diff --git a/tests/virshtestdata/dash-dash-argument-6.out b/tests/virshtestdata/dash-dash-argument-6.out new file mode 100644 index 0000000000..ab8d1a1b1f --- /dev/null +++ b/tests/virshtestdata/dash-dash-argument-6.out @@ -0,0 +1 @@ +--shell a diff --git a/tests/virshtestdata/echo-alias-argv.out b/tests/virshtestdata/echo-alias-argv.out new file mode 100644 index 0000000000..ce01362503 --- /dev/null +++ b/tests/virshtestdata/echo-alias-argv.out @@ -0,0 +1 @@ +hello diff --git a/tests/virshtestdata/echo-escaping-1.out b/tests/virshtestdata/echo-escaping-1.out new file mode 100644 index 0000000000..ff7ee063bf --- /dev/null +++ b/tests/virshtestdata/echo-escaping-1.out @@ -0,0 +1,2 @@ +a A 0 + * ; . ' " / ? = + < > & diff --git a/tests/virshtestdata/echo-escaping-2.out b/tests/virshtestdata/echo-escaping-2.out new file mode 100644 index 0000000000..e04d19b8e0 --- /dev/null +++ b/tests/virshtestdata/echo-escaping-2.out @@ -0,0 +1,2 @@ +a A 0 + '*' ';' . ''\''' '"' / '?' = ' ' ' +' '<' '>' '&' diff --git a/tests/virshtestdata/echo-escaping-3.out b/tests/virshtestdata/echo-escaping-3.out new file mode 100644 index 0000000000..f98b72d213 --- /dev/null +++ b/tests/virshtestdata/echo-escaping-3.out @@ -0,0 +1,2 @@ +a A 0 + * ; . ' " / ? = + < > & diff --git a/tests/virshtestdata/echo-quote-removal-1.out b/tests/virshtestdata/echo-quote-removal-1.out new file mode 100644 index 0000000000..b2901ea97c --- /dev/null +++ b/tests/virshtestdata/echo-quote-removal-1.out @@ -0,0 +1 @@ +a b diff --git a/tests/virshtestdata/echo-quote-removal-2.out b/tests/virshtestdata/echo-quote-removal-2.out new file mode 100644 index 0000000000..927ce33b9b --- /dev/null +++ b/tests/virshtestdata/echo-quote-removal-2.out @@ -0,0 +1 @@ +a b diff --git a/tests/virshtestdata/echo-quote-removal-3.out b/tests/virshtestdata/echo-quote-removal-3.out new file mode 100644 index 0000000000..927ce33b9b --- /dev/null +++ b/tests/virshtestdata/echo-quote-removal-3.out @@ -0,0 +1 @@ +a b diff --git a/tests/virshtestdata/echo-quote-removal-4.out b/tests/virshtestdata/echo-quote-removal-4.out new file mode 100644 index 0000000000..927ce33b9b --- /dev/null +++ b/tests/virshtestdata/echo-quote-removal-4.out @@ -0,0 +1 @@ +a b diff --git a/tests/virshtestdata/echo-quote-removal-5.out b/tests/virshtestdata/echo-quote-removal-5.out new file mode 100644 index 0000000000..00f7191294 --- /dev/null +++ b/tests/virshtestdata/echo-quote-removal-5.out @@ -0,0 +1 @@ +' " \;echo a diff --git a/tests/virshtestdata/echo-quote-removal-6.out b/tests/virshtestdata/echo-quote-removal-6.out new file mode 100644 index 0000000000..6af6f47e48 --- /dev/null +++ b/tests/virshtestdata/echo-quote-removal-6.out @@ -0,0 +1 @@ +' " ;echo a diff --git a/tests/virshtestdata/echo-quote-removal-7.out b/tests/virshtestdata/echo-quote-removal-7.out new file mode 100644 index 0000000000..e5ec314ba9 --- /dev/null +++ b/tests/virshtestdata/echo-quote-removal-7.out @@ -0,0 +1,2 @@ +' " \ +a diff --git a/tests/virshtestdata/echo-quote-removal-8.out b/tests/virshtestdata/echo-quote-removal-8.out new file mode 100644 index 0000000000..1b5a28c5b3 --- /dev/null +++ b/tests/virshtestdata/echo-quote-removal-8.out @@ -0,0 +1 @@ +' " \\ diff --git a/tests/virshtestdata/multiple-commands-1.out b/tests/virshtestdata/multiple-commands-1.out new file mode 100644 index 0000000000..422c2b7ab3 --- /dev/null +++ b/tests/virshtestdata/multiple-commands-1.out @@ -0,0 +1,2 @@ +a +b diff --git a/tests/virshtestdata/multiple-commands-10.out b/tests/virshtestdata/multiple-commands-10.out new file mode 100644 index 0000000000..a5ce8f1469 --- /dev/null +++ b/tests/virshtestdata/multiple-commands-10.out @@ -0,0 +1 @@ +a # b diff --git a/tests/virshtestdata/multiple-commands-11.out b/tests/virshtestdata/multiple-commands-11.out new file mode 100644 index 0000000000..7898192261 --- /dev/null +++ b/tests/virshtestdata/multiple-commands-11.out @@ -0,0 +1 @@ +a diff --git a/tests/virshtestdata/multiple-commands-12.out b/tests/virshtestdata/multiple-commands-12.out new file mode 100644 index 0000000000..7898192261 --- /dev/null +++ b/tests/virshtestdata/multiple-commands-12.out @@ -0,0 +1 @@ +a diff --git a/tests/virshtestdata/multiple-commands-2.out b/tests/virshtestdata/multiple-commands-2.out new file mode 100644 index 0000000000..422c2b7ab3 --- /dev/null +++ b/tests/virshtestdata/multiple-commands-2.out @@ -0,0 +1,2 @@ +a +b diff --git a/tests/virshtestdata/multiple-commands-3.out b/tests/virshtestdata/multiple-commands-3.out new file mode 100644 index 0000000000..422c2b7ab3 --- /dev/null +++ b/tests/virshtestdata/multiple-commands-3.out @@ -0,0 +1,2 @@ +a +b diff --git a/tests/virshtestdata/multiple-commands-4.out b/tests/virshtestdata/multiple-commands-4.out new file mode 100644 index 0000000000..fa70605cd2 --- /dev/null +++ b/tests/virshtestdata/multiple-commands-4.out @@ -0,0 +1,2 @@ +a + b diff --git a/tests/virshtestdata/multiple-commands-5.out b/tests/virshtestdata/multiple-commands-5.out new file mode 100644 index 0000000000..b89bc872d4 --- /dev/null +++ b/tests/virshtestdata/multiple-commands-5.out @@ -0,0 +1,3 @@ +a +\ + b diff --git a/tests/virshtestdata/multiple-commands-6.out b/tests/virshtestdata/multiple-commands-6.out new file mode 100644 index 0000000000..7898192261 --- /dev/null +++ b/tests/virshtestdata/multiple-commands-6.out @@ -0,0 +1 @@ +a diff --git a/tests/virshtestdata/multiple-commands-7.out b/tests/virshtestdata/multiple-commands-7.out new file mode 100644 index 0000000000..0f7bc76605 --- /dev/null +++ b/tests/virshtestdata/multiple-commands-7.out @@ -0,0 +1,2 @@ +a +c diff --git a/tests/virshtestdata/multiple-commands-8.out b/tests/virshtestdata/multiple-commands-8.out new file mode 100644 index 0000000000..0f7bc76605 --- /dev/null +++ b/tests/virshtestdata/multiple-commands-8.out @@ -0,0 +1,2 @@ +a +c diff --git a/tests/virshtestdata/multiple-commands-9.out b/tests/virshtestdata/multiple-commands-9.out new file mode 100644 index 0000000000..a5ce8f1469 --- /dev/null +++ b/tests/virshtestdata/multiple-commands-9.out @@ -0,0 +1 @@ +a # b -- 2.44.0

Now that the output is tested against files these are not needed any more. The brief existence of both proved that the output is identical. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 73 +++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 1750cc7abd..ef2b8e7ec5 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -440,7 +440,6 @@ struct testInfo { const char *testname; /* used to generate output filename */ const char *filter; const char *const *argv; - const char *result; }; static int testCompare(const void *data) @@ -453,7 +452,7 @@ static int testCompare(const void *data) abs_srcdir, info->testname); } - return testCompareOutputLit(outfile, info->result, info->filter, info->argv); + return testCompareOutputLit(outfile, NULL, info->filter, info->argv); } @@ -568,7 +567,7 @@ mymain(void) abs_srcdir, testname); \ const char *myargv[] = { __VA_ARGS__, NULL, NULL }; \ const char **tmp = myargv; \ - const struct testInfo info = { testname, testfilter, myargv, NULL }; \ + const struct testInfo info = { testname, testfilter, myargv }; \ g_autofree char *scriptarg = NULL; \ if (virFileReadAll(infile, 256 * 1024, &scriptarg) < 0) { \ fprintf(stderr, "\nfailed to load '%s'\n", infile); \ @@ -581,66 +580,66 @@ mymain(void) ret = -1; \ } while (0); -# define DO_TEST_FULL(testname_, filter, result, ...) \ +# define DO_TEST_FULL(testname_, filter, ...) \ do { \ const char *testname = testname_; \ const char *myargv[] = { __VA_ARGS__, NULL }; \ - const struct testInfo info = { testname, NULL, myargv, result }; \ + const struct testInfo info = { testname, NULL, myargv }; \ if (virTestRun(testname, testCompare, &info) < 0) \ ret = -1; \ } while (0) /* automatically numbered test invocation */ -# define DO_TEST(result, ...) \ - DO_TEST_FULL(virTestCounterNext(), NULL, result, VIRSH_DEFAULT, __VA_ARGS__); +# define DO_TEST(...) \ + DO_TEST_FULL(virTestCounterNext(), NULL, VIRSH_DEFAULT, __VA_ARGS__); /* Arg parsing quote removal tests. */ virTestCounterReset("echo-quote-removal-"); - DO_TEST("a b\n", "echo a \t b"); - DO_TEST("a \t b\n", "echo \"a \t b\""); - DO_TEST("a \t b\n", "echo 'a \t b'"); - DO_TEST("a \t b\n", "echo a\\ \\\t\\ b"); - DO_TEST("' \" \\;echo\ta\n", "echo", "'", "\"", "\\;echo\ta"); - DO_TEST("' \" ;echo a\n", "echo \\' \\\" \\;echo\ta"); - DO_TEST("' \" \\\na\n", "echo \\' \\\" \\\\;echo\ta"); - DO_TEST("' \" \\\\\n", "echo \"'\" '\"' '\\'\"\\\\\""); + DO_TEST("echo a \t b"); + DO_TEST("echo \"a \t b\""); + DO_TEST("echo 'a \t b'"); + DO_TEST("echo a\\ \\\t\\ b"); + DO_TEST("echo", "'", "\"", "\\;echo\ta"); + DO_TEST("echo \\' \\\" \\;echo\ta"); + DO_TEST("echo \\' \\\" \\\\;echo\ta"); + DO_TEST("echo \"'\" '\"' '\\'\"\\\\\""); /* Tests of echo flags. */ DO_TEST_SCRIPT("echo-escaping", NULL, VIRSH_DEFAULT); virTestCounterReset("echo-escaping-"); - DO_TEST("a A 0 + * ; . ' \" / ? = \n < > &\n", "echo", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", "=", " ", "\n", "<", ">", "&"); - DO_TEST("a A 0 + '*' ';' . ''\\''' '\"' / '?' = ' ' '\n' '<' '>' '&'\n", "echo", "--shell", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", "=", " ", "\n", "<", ">", "&"); - DO_TEST("a A 0 + * ; . ' " / ? = \n < > &\n", "echo", "--xml", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", "=", " ", "\n", "<", ">", "&"); + DO_TEST("echo", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", "=", " ", "\n", "<", ">", "&"); + DO_TEST("echo", "--shell", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", "=", " ", "\n", "<", ">", "&"); + DO_TEST("echo", "--xml", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", "=", " ", "\n", "<", ">", "&"); /* Tests of -- handling. */ virTestCounterReset("dash-dash-argument-"); - DO_TEST("a\n", "--", "echo", "--shell", "a"); - DO_TEST("a\n", "--", "echo", "a", "--shell"); - DO_TEST("a --shell\n", "--", "echo", "--", "a", "--shell"); - DO_TEST("-- --shell a\n", "echo", "--", "--", "--shell", "a"); - DO_TEST("a\n", "echo --s\\h'e'\"l\"l -- a"); - DO_TEST("--shell a\n", "echo \t '-'\"-\" \t --shell \t a"); + DO_TEST("--", "echo", "--shell", "a"); + DO_TEST("--", "echo", "a", "--shell"); + DO_TEST("--", "echo", "--", "a", "--shell"); + DO_TEST("echo", "--", "--", "--shell", "a"); + DO_TEST("echo --s\\h'e'\"l\"l -- a"); + DO_TEST("echo \t '-'\"-\" \t --shell \t a"); /* Tests of alias handling. */ DO_TEST_SCRIPT("echo-alias", NULL, VIRSH_DEFAULT); - DO_TEST_FULL("echo-alias-argv", NULL, "hello\n", VIRSH_DEFAULT, "echo", "--str", "hello"); + DO_TEST_FULL("echo-alias-argv", NULL, VIRSH_DEFAULT, "echo", "--str", "hello"); /* Tests of multiple commands. */ virTestCounterReset("multiple-commands-"); - DO_TEST("a\nb\n", " echo a; echo b;"); - DO_TEST("a\nb\n", "\necho a\n echo b\n"); - DO_TEST("a\nb\n", "ec\\\nho a\n echo \\\n b;"); - DO_TEST("a\n b\n", "\"ec\\\nho\" a\n echo \"\\\n b\";"); - DO_TEST("a\n\\\n b\n", "ec\\\nho a\n echo '\\\n b';"); - DO_TEST("a\n", "echo a # b"); - DO_TEST("a\nc\n", "echo a #b\necho c"); - DO_TEST("a\nc\n", "echo a # b\\\necho c"); - DO_TEST("a # b\n", "echo a '#' b"); - DO_TEST("a # b\n", "echo a \\# b"); - DO_TEST("a\n", "#unbalanced; 'quotes\"\necho a # b"); - DO_TEST("a\n", "\\# ignored;echo a\n'#also' ignored"); + DO_TEST(" echo a; echo b;"); + DO_TEST("\necho a\n echo b\n"); + DO_TEST("ec\\\nho a\n echo \\\n b;"); + DO_TEST("\"ec\\\nho\" a\n echo \"\\\n b\";"); + DO_TEST("ec\\\nho a\n echo '\\\n b';"); + DO_TEST("echo a # b"); + DO_TEST("echo a #b\necho c"); + DO_TEST("echo a # b\\\necho c"); + DO_TEST("echo a '#' b"); + DO_TEST("echo a \\# b"); + DO_TEST("#unbalanced; 'quotes\"\necho a # b"); + DO_TEST("\\# ignored;echo a\n'#also' ignored"); /* test of splitting in vshStringToArray */ DO_TEST_SCRIPT("echo-split", NULL, VIRSH_DEFAULT, "-q"); -- 2.44.0

Add the basic list and info commands into a script and run it via VIR_TEST_RUN_SCRIPT to simplify the code and save up on 'virsh' instances exec'd for the test. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 79 ++-------------------------- tests/virshtestdata/info-custom.in | 2 + tests/virshtestdata/info-custom.out | 15 ++++++ tests/virshtestdata/info-default.in | 2 + tests/virshtestdata/info-default.out | 13 +++++ 5 files changed, 35 insertions(+), 76 deletions(-) create mode 100644 tests/virshtestdata/info-custom.in create mode 100644 tests/virshtestdata/info-custom.out create mode 100644 tests/virshtestdata/info-default.in create mode 100644 tests/virshtestdata/info-default.out diff --git a/tests/virshtest.c b/tests/virshtest.c index ef2b8e7ec5..cdd5468bc1 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -159,66 +159,6 @@ static char *custom_uri; "--connect", \ custom_uri -static int testCompareListDefault(const void *data) -{ - const char *const argv[] = { VIRSH_DEFAULT, "list", NULL }; - const char *exp = "\ - Id Name State\n\ -----------------------\n\ - 1 test running\n\ -\n"; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareListCustom(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "list", NULL }; - const char *exp = "\ - Id Name State\n\ -----------------------\n\ - 1 fv0 running\n\ - 2 fc4 running\n\ - 3 fc5 running\n\ -\n"; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareNodeinfoDefault(const void *data) -{ - const char *const argv[] = { VIRSH_DEFAULT, "nodeinfo", NULL }; - const char *exp = "\ -CPU model: i686\n\ -CPU(s): 16\n\ -CPU frequency: 1400 MHz\n\ -CPU socket(s): 2\n\ -Core(s) per socket: 2\n\ -Thread(s) per core: 2\n\ -NUMA cell(s): 2\n\ -Memory size: 3145728 KiB\n\ -\n"; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareNodeinfoCustom(const void *data) -{ - const char *const argv[] = { - VIRSH_CUSTOM, - "nodeinfo", - NULL - }; - const char *exp = "\ -CPU model: i986\n\ -CPU(s): 50\n\ -CPU frequency: 6000 MHz\n\ -CPU socket(s): 4\n\ -Core(s) per socket: 4\n\ -Thread(s) per core: 2\n\ -NUMA cell(s): 4\n\ -Memory size: 8192000 KiB\n\ -\n"; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - static int testCompareDominfoByID(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "dominfo", "2", NULL }; @@ -464,22 +404,6 @@ mymain(void) custom_uri = g_strdup_printf("test://%s/../examples/xml/test/testnode.xml", abs_srcdir); - if (virTestRun("virsh list (default)", - testCompareListDefault, NULL) != 0) - ret = -1; - - if (virTestRun("virsh list (custom)", - testCompareListCustom, NULL) != 0) - ret = -1; - - if (virTestRun("virsh nodeinfo (default)", - testCompareNodeinfoDefault, NULL) != 0) - ret = -1; - - if (virTestRun("virsh nodeinfo (custom)", - testCompareNodeinfoCustom, NULL) != 0) - ret = -1; - if (virTestRun("virsh dominfo (by id)", testCompareDominfoByID, NULL) != 0) ret = -1; @@ -580,6 +504,9 @@ mymain(void) ret = -1; \ } while (0); + DO_TEST_SCRIPT("info-default", NULL, VIRSH_DEFAULT); + DO_TEST_SCRIPT("info-custom", NULL, VIRSH_CUSTOM); + # define DO_TEST_FULL(testname_, filter, ...) \ do { \ const char *testname = testname_; \ diff --git a/tests/virshtestdata/info-custom.in b/tests/virshtestdata/info-custom.in new file mode 100644 index 0000000000..7767ef1c49 --- /dev/null +++ b/tests/virshtestdata/info-custom.in @@ -0,0 +1,2 @@ +list +nodeinfo diff --git a/tests/virshtestdata/info-custom.out b/tests/virshtestdata/info-custom.out new file mode 100644 index 0000000000..8307baf4eb --- /dev/null +++ b/tests/virshtestdata/info-custom.out @@ -0,0 +1,15 @@ + Id Name State +---------------------- + 1 fv0 running + 2 fc4 running + 3 fc5 running + +CPU model: i986 +CPU(s): 50 +CPU frequency: 6000 MHz +CPU socket(s): 4 +Core(s) per socket: 4 +Thread(s) per core: 2 +NUMA cell(s): 4 +Memory size: 8192000 KiB + diff --git a/tests/virshtestdata/info-default.in b/tests/virshtestdata/info-default.in new file mode 100644 index 0000000000..7767ef1c49 --- /dev/null +++ b/tests/virshtestdata/info-default.in @@ -0,0 +1,2 @@ +list +nodeinfo diff --git a/tests/virshtestdata/info-default.out b/tests/virshtestdata/info-default.out new file mode 100644 index 0000000000..56559ab3e4 --- /dev/null +++ b/tests/virshtestdata/info-default.out @@ -0,0 +1,13 @@ + Id Name State +---------------------- + 1 test running + +CPU model: i686 +CPU(s): 16 +CPU frequency: 1400 MHz +CPU socket(s): 2 +Core(s) per socket: 2 +Thread(s) per core: 2 +NUMA cell(s): 2 +Memory size: 3145728 KiB + -- 2.44.0

All of the commands can be tested in one 'virsh' run in batch mode and tested against a file rather than hardcoded strings. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 204 +----------------------------- tests/virshtestdata/domain-id.in | 18 +++ tests/virshtestdata/domain-id.out | 73 +++++++++++ 3 files changed, 92 insertions(+), 203 deletions(-) create mode 100644 tests/virshtestdata/domain-id.in create mode 100644 tests/virshtestdata/domain-id.out diff --git a/tests/virshtest.c b/tests/virshtest.c index cdd5468bc1..53c9042330 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -18,59 +18,10 @@ main(void) #else -# define DOM_FC4_UUID "ef861801-45b9-11cb-88e3-afbfe5370493" -# define DOM_FC5_UUID "08721f99-3d1d-4aec-96eb-97803297bb36" -# define SECURITY_LABEL "libvirt-test (enforcing)" -# define FC4_MESSAGES "tainted: network configuration using opaque shell scripts" -# define FC5_MESSAGES "tainted: running with undesirable elevated privileges\n\ - tainted: network configuration using opaque shell scripts\n\ - tainted: use of host cdrom passthrough\n\ - tainted: custom device tree blob used\n\ - tainted: use of deprecated configuration settings\n\ - deprecated configuration: CPU model Deprecated-Test" # define GET_BLKIO_PARAMETER "/dev/hda,700" # define SET_BLKIO_PARAMETER "/dev/hda,1000" # define EQUAL "=" -static const char *dominfo_fc4 = "\ -Id: 2\n\ -Name: fc4\n\ -UUID: " DOM_FC4_UUID "\n\ -OS Type: linux\n\ -State: running\n\ -CPU(s): 1\n\ -Max memory: 261072 KiB\n\ -Used memory: 131072 KiB\n\ -Persistent: yes\n\ -Autostart: disable\n\ -Managed save: no\n\ -Security model: testSecurity\n\ -Security DOI: \n\ -Security label: " SECURITY_LABEL "\n\ -Messages: " FC4_MESSAGES "\n\ -\n"; -static const char *domuuid_fc4 = DOM_FC4_UUID "\n\n"; -static const char *domid_fc4 = "2\n\n"; -static const char *domname_fc4 = "fc4\n\n"; -static const char *domstate_fc4 = "running\n\n"; -static const char *dominfo_fc5 = "\ -Id: 3\n\ -Name: fc5\n\ -UUID: " DOM_FC5_UUID "\n\ -OS Type: linux\n\ -State: running\n\ -CPU(s): 4\n\ -Max memory: 2097152 KiB\n\ -Used memory: 2097152 KiB\n\ -Persistent: yes\n\ -Autostart: disable\n\ -Managed save: no\n\ -Security model: testSecurity\n\ -Security DOI: \n\ -Security label: " SECURITY_LABEL "\n\ -Messages: " FC5_MESSAGES "\n\ -\n"; - static const char *get_blkio_parameters = "\ weight : 800\n\ device_weight : " GET_BLKIO_PARAMETER "\n\ @@ -159,104 +110,6 @@ static char *custom_uri; "--connect", \ custom_uri -static int testCompareDominfoByID(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "dominfo", "2", NULL }; - const char *exp = dominfo_fc4; - return testCompareOutputLit((const char *) data, exp, "\nCPU time:", argv); -} - -static int testCompareDominfoByUUID(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "dominfo", DOM_FC4_UUID, NULL }; - const char *exp = dominfo_fc4; - return testCompareOutputLit((const char *) data, exp, "\nCPU time:", argv); -} - -static int testCompareDominfoByName(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "dominfo", "fc4", NULL }; - const char *exp = dominfo_fc4; - return testCompareOutputLit((const char *) data, exp, "\nCPU time:", argv); -} - -static int testCompareTaintedDominfoByName(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "dominfo", "fc5", NULL }; - const char *exp = dominfo_fc5; - return testCompareOutputLit((const char *) data, exp, "\nCPU time:", argv); -} - -static int testCompareDomuuidByID(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "domuuid", "2", NULL }; - const char *exp = domuuid_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareDomuuidByName(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "domuuid", "fc4", NULL }; - const char *exp = domuuid_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareDomidByName(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "domid", "fc4", NULL }; - const char *exp = domid_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareDomidByUUID(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "domid", DOM_FC4_UUID, NULL }; - const char *exp = domid_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareDomnameByID(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "domname", "2", NULL }; - const char *exp = domname_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareDomnameByUUID(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "domname", DOM_FC4_UUID, NULL }; - const char *exp = domname_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareDomstateByID(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "domstate", "2", NULL }; - const char *exp = domstate_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareDomstateByUUID(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "domstate", DOM_FC4_UUID, NULL }; - const char *exp = domstate_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareDomstateByName(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "domstate", "fc4", NULL }; - const char *exp = domstate_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareDomControlInfoByName(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "domcontrol", "fc4", NULL }; - const char *exp = "ok\n\n"; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - static int testCompareGetBlkioParameters(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "blkiotune", "fv0", NULL }; @@ -404,62 +257,6 @@ mymain(void) custom_uri = g_strdup_printf("test://%s/../examples/xml/test/testnode.xml", abs_srcdir); - if (virTestRun("virsh dominfo (by id)", - testCompareDominfoByID, NULL) != 0) - ret = -1; - - if (virTestRun("virsh dominfo (by uuid)", - testCompareDominfoByUUID, NULL) != 0) - ret = -1; - - if (virTestRun("virsh dominfo (by name)", - testCompareDominfoByName, NULL) != 0) - ret = -1; - - if (virTestRun("virsh dominfo (by name, more tainted messages)", - testCompareTaintedDominfoByName, NULL) != 0) - ret = -1; - - if (virTestRun("virsh domid (by name)", - testCompareDomidByName, NULL) != 0) - ret = -1; - - if (virTestRun("virsh domid (by uuid)", - testCompareDomidByUUID, NULL) != 0) - ret = -1; - - if (virTestRun("virsh domuuid (by id)", - testCompareDomuuidByID, NULL) != 0) - ret = -1; - - if (virTestRun("virsh domuuid (by name)", - testCompareDomuuidByName, NULL) != 0) - ret = -1; - - if (virTestRun("virsh domname (by id)", - testCompareDomnameByID, NULL) != 0) - ret = -1; - - if (virTestRun("virsh domname (by uuid)", - testCompareDomnameByUUID, NULL) != 0) - ret = -1; - - if (virTestRun("virsh domstate (by id)", - testCompareDomstateByID, NULL) != 0) - ret = -1; - - if (virTestRun("virsh domstate (by uuid)", - testCompareDomstateByUUID, NULL) != 0) - ret = -1; - - if (virTestRun("virsh domstate (by name)", - testCompareDomstateByName, NULL) != 0) - ret = -1; - - if (virTestRun("virsh domcontrol (by name)", - testCompareDomControlInfoByName, NULL) != 0) - ret = -1; - if (virTestRun("virsh blkiotune (get parameters)", testCompareGetBlkioParameters, NULL) != 0) ret = -1; @@ -506,6 +303,7 @@ mymain(void) DO_TEST_SCRIPT("info-default", NULL, VIRSH_DEFAULT); DO_TEST_SCRIPT("info-custom", NULL, VIRSH_CUSTOM); + DO_TEST_SCRIPT("domain-id", "\nCPU time:", VIRSH_CUSTOM); # define DO_TEST_FULL(testname_, filter, ...) \ do { \ diff --git a/tests/virshtestdata/domain-id.in b/tests/virshtestdata/domain-id.in new file mode 100644 index 0000000000..6605baa090 --- /dev/null +++ b/tests/virshtestdata/domain-id.in @@ -0,0 +1,18 @@ +dominfo ef861801-45b9-11cb-88e3-afbfe5370493 +dominfo fc4 +dominfo fc5 + +domid fc4 +domid ef861801-45b9-11cb-88e3-afbfe5370493 + +domuuid 2 +domuuid fc4 + +domname 2 +domname ef861801-45b9-11cb-88e3-afbfe5370493 + +domstate 2 +domstate ef861801-45b9-11cb-88e3-afbfe5370493 +domstate fc4 + +domcontrol fc4 diff --git a/tests/virshtestdata/domain-id.out b/tests/virshtestdata/domain-id.out new file mode 100644 index 0000000000..8e6174fd21 --- /dev/null +++ b/tests/virshtestdata/domain-id.out @@ -0,0 +1,73 @@ +Id: 2 +Name: fc4 +UUID: ef861801-45b9-11cb-88e3-afbfe5370493 +OS Type: linux +State: running +CPU(s): 1 +Max memory: 261072 KiB +Used memory: 131072 KiB +Persistent: yes +Autostart: disable +Managed save: no +Security model: testSecurity +Security DOI: +Security label: libvirt-test (enforcing) +Messages: tainted: network configuration using opaque shell scripts + +Id: 2 +Name: fc4 +UUID: ef861801-45b9-11cb-88e3-afbfe5370493 +OS Type: linux +State: running +CPU(s): 1 +Max memory: 261072 KiB +Used memory: 131072 KiB +Persistent: yes +Autostart: disable +Managed save: no +Security model: testSecurity +Security DOI: +Security label: libvirt-test (enforcing) +Messages: tainted: network configuration using opaque shell scripts + +Id: 3 +Name: fc5 +UUID: 08721f99-3d1d-4aec-96eb-97803297bb36 +OS Type: linux +State: running +CPU(s): 4 +Max memory: 2097152 KiB +Used memory: 2097152 KiB +Persistent: yes +Autostart: disable +Managed save: no +Security model: testSecurity +Security DOI: +Security label: libvirt-test (enforcing) +Messages: tainted: running with undesirable elevated privileges + tainted: network configuration using opaque shell scripts + tainted: use of host cdrom passthrough + tainted: custom device tree blob used + tainted: use of deprecated configuration settings + deprecated configuration: CPU model Deprecated-Test + +2 + +2 + +ef861801-45b9-11cb-88e3-afbfe5370493 + +ef861801-45b9-11cb-88e3-afbfe5370493 + +fc4 + +fc4 + +running + +running + +running + +ok + -- 2.44.0

The query and update can be tested in one run and validated against files rather than hardcoded strings. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 56 +------------------------------ tests/virshtestdata/blkiotune.in | 3 ++ tests/virshtestdata/blkiotune.out | 15 +++++++++ 3 files changed, 19 insertions(+), 55 deletions(-) create mode 100644 tests/virshtestdata/blkiotune.in create mode 100644 tests/virshtestdata/blkiotune.out diff --git a/tests/virshtest.c b/tests/virshtest.c index 53c9042330..6c2d4cfc67 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -18,29 +18,8 @@ main(void) #else -# define GET_BLKIO_PARAMETER "/dev/hda,700" -# define SET_BLKIO_PARAMETER "/dev/hda,1000" # define EQUAL "=" -static const char *get_blkio_parameters = "\ -weight : 800\n\ -device_weight : " GET_BLKIO_PARAMETER "\n\ -device_read_iops_sec: " GET_BLKIO_PARAMETER "\n\ -device_write_iops_sec: " GET_BLKIO_PARAMETER "\n\ -device_read_bytes_sec: " GET_BLKIO_PARAMETER "\n\ -device_write_bytes_sec: " GET_BLKIO_PARAMETER "\n\ -\n"; - -static const char *set_blkio_parameters = "\ -\n\ -weight : 500\n\ -device_weight : " SET_BLKIO_PARAMETER "\n\ -device_read_iops_sec: " SET_BLKIO_PARAMETER "\n\ -device_write_iops_sec: " SET_BLKIO_PARAMETER "\n\ -device_read_bytes_sec: " SET_BLKIO_PARAMETER "\n\ -device_write_bytes_sec: " SET_BLKIO_PARAMETER "\n\ -\n"; - static void testFilterLine(char *buffer, const char *toRemove) { @@ -110,32 +89,6 @@ static char *custom_uri; "--connect", \ custom_uri -static int testCompareGetBlkioParameters(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "blkiotune", "fv0", NULL }; - const char *exp = get_blkio_parameters; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareSetBlkioParameters(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "blkiotune fv0\ - --weight 500\ - --device-weights\ - " SET_BLKIO_PARAMETER "\ - --device-read-iops-sec\ - " SET_BLKIO_PARAMETER "\ - --device-write-iops-sec\ - " SET_BLKIO_PARAMETER "\ - --device-read-bytes-sec\ - " SET_BLKIO_PARAMETER "\ - --device-write-bytes-sec\ - " SET_BLKIO_PARAMETER ";\ - blkiotune fv0", NULL }; - const char *exp = set_blkio_parameters; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - static int testIOThreadAdd(const void *data) { const char *const argv[] = { VIRSH_CUSTOM, "iothreadinfo --domain fc4;\ @@ -257,14 +210,6 @@ mymain(void) custom_uri = g_strdup_printf("test://%s/../examples/xml/test/testnode.xml", abs_srcdir); - if (virTestRun("virsh blkiotune (get parameters)", - testCompareGetBlkioParameters, NULL) != 0) - ret = -1; - - if (virTestRun("virsh blkiotune (set parameters)", - testCompareSetBlkioParameters, NULL) != 0) - ret = -1; - if (virTestRun("virsh iothreadadd", testIOThreadAdd, NULL) != 0) ret = -1; @@ -304,6 +249,7 @@ mymain(void) DO_TEST_SCRIPT("info-default", NULL, VIRSH_DEFAULT); DO_TEST_SCRIPT("info-custom", NULL, VIRSH_CUSTOM); DO_TEST_SCRIPT("domain-id", "\nCPU time:", VIRSH_CUSTOM); + DO_TEST_SCRIPT("blkiotune", NULL, VIRSH_CUSTOM); # define DO_TEST_FULL(testname_, filter, ...) \ do { \ diff --git a/tests/virshtestdata/blkiotune.in b/tests/virshtestdata/blkiotune.in new file mode 100644 index 0000000000..db1ebb119f --- /dev/null +++ b/tests/virshtestdata/blkiotune.in @@ -0,0 +1,3 @@ +blkiotune fv0 +blkiotune fv0 --weight 500 --device-weights /dev/hda,1000 --device-read-iops-sec /dev/hda,1000 --device-write-iops-sec /dev/hda,1000 --device-read-bytes-sec /dev/hda,1000 --device-write-bytes-sec /dev/hda,1000 +blkiotune fv0 diff --git a/tests/virshtestdata/blkiotune.out b/tests/virshtestdata/blkiotune.out new file mode 100644 index 0000000000..fa267e17c7 --- /dev/null +++ b/tests/virshtestdata/blkiotune.out @@ -0,0 +1,15 @@ +weight : 800 +device_weight : /dev/hda,700 +device_read_iops_sec: /dev/hda,700 +device_write_iops_sec: /dev/hda,700 +device_read_bytes_sec: /dev/hda,700 +device_write_bytes_sec: /dev/hda,700 + + +weight : 500 +device_weight : /dev/hda,1000 +device_read_iops_sec: /dev/hda,1000 +device_write_iops_sec: /dev/hda,1000 +device_read_bytes_sec: /dev/hda,1000 +device_write_bytes_sec: /dev/hda,1000 + -- 2.44.0

Adapt the tests to be invoked in one run. Note that multiple fake VMs were used for the distinct tests so that they don't influence each other. This is the final coversion of tests to run in batch mode which halved the runtime of 'virshtest' on my machine (1.11s vs 2.33s). Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 112 +----------------------------- tests/virshtestdata/iothreads.in | 14 ++++ tests/virshtestdata/iothreads.out | 51 ++++++++++++++ 3 files changed, 66 insertions(+), 111 deletions(-) create mode 100644 tests/virshtestdata/iothreads.in create mode 100644 tests/virshtestdata/iothreads.out diff --git a/tests/virshtest.c b/tests/virshtest.c index 6c2d4cfc67..02bfb363c4 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -18,8 +18,6 @@ main(void) #else -# define EQUAL "=" - static void testFilterLine(char *buffer, const char *toRemove) { @@ -89,99 +87,6 @@ static char *custom_uri; "--connect", \ custom_uri -static int testIOThreadAdd(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "iothreadinfo --domain fc4;\ - iothreadadd --domain fc4 --id 6;\ - iothreadinfo --domain fc4", NULL}; - const char *exp = "\ - IOThread ID CPU Affinity\n\ ------------------------------\n\ - 2 0\n\ - 4 0\n\ -\n\ -\n\ - IOThread ID CPU Affinity\n\ ------------------------------\n\ - 2 0\n\ - 4 0\n\ - 6 0\n\ -\n"; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testIOThreadDel(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "iothreadinfo --domain fc4;\ - iothreaddel --domain fc4 --id 2;\ - iothreadinfo --domain fc4", NULL}; - const char *exp = "\ - IOThread ID CPU Affinity\n\ ------------------------------\n\ - 2 0\n\ - 4 0\n\ -\n\ -\n\ - IOThread ID CPU Affinity\n\ ------------------------------\n\ - 4 0\n\ -\n"; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testIOThreadSet(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, "domstats --domain fc4;\ - iothreadset --domain fc4\ - --id 2 --poll-max-ns 100\ - --poll-shrink 10 --poll-grow 10;\ - domstats --domain fc4", NULL}; - const char *exp = "\ -Domain: 'fc4'\n\ - state.state" EQUAL "1\n\ - state.reason" EQUAL "0\n\ - iothread.count" EQUAL "2\n\ - iothread.2.poll-max-ns" EQUAL "32768\n\ - iothread.2.poll-grow" EQUAL "0\n\ - iothread.2.poll-shrink" EQUAL "0\n\ - iothread.4.poll-max-ns" EQUAL "32768\n\ - iothread.4.poll-grow" EQUAL "0\n\ - iothread.4.poll-shrink" EQUAL "0\n\n\ -\n\ -Domain: 'fc4'\n\ - state.state" EQUAL "1\n\ - state.reason" EQUAL "0\n\ - iothread.count" EQUAL "2\n\ - iothread.2.poll-max-ns" EQUAL "100\n\ - iothread.2.poll-grow" EQUAL "10\n\ - iothread.2.poll-shrink" EQUAL "10\n\ - iothread.4.poll-max-ns" EQUAL "32768\n\ - iothread.4.poll-grow" EQUAL "0\n\ - iothread.4.poll-shrink" EQUAL "0\n\n"; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testIOThreadPin(const void *data) -{ - const char *const argv[] = { VIRSH_CUSTOM, - "iothreadadd --domain fc5 --id 2;\ - iothreadinfo --domain fc5;\ - iothreadpin --domain fc5 --iothread 2\ - --cpulist 0;\ - iothreadinfo --domain fc5", NULL}; - const char *exp = "\n\ - IOThread ID CPU Affinity\n\ ------------------------------\n\ - 2 0-3\n\ -\n\ -\n\ - IOThread ID CPU Affinity\n\ ------------------------------\n\ - 2 0\n\ -\n"; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - struct testInfo { const char *testname; /* used to generate output filename */ const char *filter; @@ -210,22 +115,6 @@ mymain(void) custom_uri = g_strdup_printf("test://%s/../examples/xml/test/testnode.xml", abs_srcdir); - if (virTestRun("virsh iothreadadd", - testIOThreadAdd, NULL) != 0) - ret = -1; - - if (virTestRun("virsh iothreaddel", - testIOThreadDel, NULL) != 0) - ret = -1; - - if (virTestRun("virsh iothreadset", - testIOThreadSet, NULL) != 0) - ret = -1; - - if (virTestRun("virsh iothreadpin", - testIOThreadPin, NULL) != 0) - ret = -1; - # define DO_TEST_SCRIPT(testname_, testfilter, ...) \ { \ const char *testname = testname_; \ @@ -250,6 +139,7 @@ mymain(void) DO_TEST_SCRIPT("info-custom", NULL, VIRSH_CUSTOM); DO_TEST_SCRIPT("domain-id", "\nCPU time:", VIRSH_CUSTOM); DO_TEST_SCRIPT("blkiotune", NULL, VIRSH_CUSTOM); + DO_TEST_SCRIPT("iothreads", NULL, VIRSH_CUSTOM); # define DO_TEST_FULL(testname_, filter, ...) \ do { \ diff --git a/tests/virshtestdata/iothreads.in b/tests/virshtestdata/iothreads.in new file mode 100644 index 0000000000..25ebcb5cda --- /dev/null +++ b/tests/virshtestdata/iothreads.in @@ -0,0 +1,14 @@ +iothreadinfo --domain fc4 +iothreadadd --domain fc4 --id 6 +iothreadinfo --domain fc4 +iothreaddel --domain fc4 --id 2 +iothreadinfo --domain fc4 + +domstats --domain fc4 +iothreadset --domain fc4 --id 6 --poll-max-ns 100 --poll-shrink 10 --poll-grow 10 +domstats --domain fc4 + +iothreadadd --domain fc5 --id 2 +iothreadinfo --domain fc5 +iothreadpin --domain fc5 --iothread 2 --cpulist 0 +iothreadinfo --domain fc5 diff --git a/tests/virshtestdata/iothreads.out b/tests/virshtestdata/iothreads.out new file mode 100644 index 0000000000..1e38733bcf --- /dev/null +++ b/tests/virshtestdata/iothreads.out @@ -0,0 +1,51 @@ + IOThread ID CPU Affinity +----------------------------- + 2 0 + 4 0 + + + IOThread ID CPU Affinity +----------------------------- + 2 0 + 4 0 + 6 0 + + + IOThread ID CPU Affinity +----------------------------- + 4 0 + 6 0 + +Domain: 'fc4' + state.state=1 + state.reason=0 + iothread.count=2 + iothread.4.poll-max-ns=32768 + iothread.4.poll-grow=0 + iothread.4.poll-shrink=0 + iothread.6.poll-max-ns=32768 + iothread.6.poll-grow=0 + iothread.6.poll-shrink=0 + + +Domain: 'fc4' + state.state=1 + state.reason=0 + iothread.count=2 + iothread.4.poll-max-ns=32768 + iothread.4.poll-grow=0 + iothread.4.poll-shrink=0 + iothread.6.poll-max-ns=100 + iothread.6.poll-grow=10 + iothread.6.poll-shrink=10 + + + IOThread ID CPU Affinity +----------------------------- + 2 0-3 + + + IOThread ID CPU Affinity +----------------------------- + 2 0 + -- 2.44.0

Now that all tests were converted, this is no longer needed. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virshtest.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 02bfb363c4..926f919d8d 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -36,7 +36,6 @@ static void testFilterLine(char *buffer, static int testCompareOutputLit(const char *expectFile, - const char *expectData, const char *filter, const char *const argv[]) { @@ -64,15 +63,8 @@ testCompareOutputLit(const char *expectFile, if (filter) testFilterLine(actual, filter); - if (expectData) { - if (virTestCompareToString(expectData, actual) < 0) - return -1; - } - - if (expectFile) { - if (virTestCompareToFileFull(actual, expectFile, false) < 0) - return -1; - } + if (virTestCompareToFileFull(actual, expectFile, false) < 0) + return -1; return 0; } @@ -103,7 +95,7 @@ static int testCompare(const void *data) abs_srcdir, info->testname); } - return testCompareOutputLit(outfile, NULL, info->filter, info->argv); + return testCompareOutputLit(outfile, info->filter, info->argv); } -- 2.44.0

Move the argument parsing tests excercising 'virsh setvcpus' from 'virsh-optparse' to 'virshtest'. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virsh-optparse | 29 ------- tests/virshtest.c | 3 + tests/virshtestdata/argument-assignment.in | 15 ++++ tests/virshtestdata/argument-assignment.out | 91 +++++++++++++++++++++ 4 files changed, 109 insertions(+), 29 deletions(-) create mode 100644 tests/virshtestdata/argument-assignment.in create mode 100644 tests/virshtestdata/argument-assignment.out diff --git a/tests/virsh-optparse b/tests/virsh-optparse index 3fe38b2931..77e754d73a 100755 --- a/tests/virsh-optparse +++ b/tests/virsh-optparse @@ -28,39 +28,10 @@ if test "$VERBOSE" = yes; then $VIRSH --version fi -cat <<\EOF > exp-out || framework_failure - -setvcpus: <domain> trying as domain NAME -setvcpus: count(optdata): 2 -setvcpus: domain(optdata): test -setvcpus: found option <domain>: test -EOF - fail=0 test_url=test:///default -for args in \ - 'test 2' \ - '--domain test 2' \ - '--domain=test 2' \ - 'test --count 2' \ - 'test --count=2' \ - '--domain test --count 2' \ - '--domain=test --count 2' \ - '--domain test --count=2' \ - '--domain=test --count=2' \ - '--count 2 --domain test' \ - '--count 2 --domain=test' \ - '--count=2 --domain test' \ - '--count=2 --domain=test' \ - '--count 2 test' \ - '--count=2 test' \ -; do - $VIRSH -k0 -d0 -c $test_url setvcpus $args >out 2>>err || fail=1 - LC_ALL=C sort out | compare exp-out - || fail=1 -done - # Another complex parsing example cat <<\EOF > exp-out || framework_failure <domainsnapshot> diff --git a/tests/virshtest.c b/tests/virshtest.c index 926f919d8d..1baa402648 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -198,6 +198,9 @@ mymain(void) DO_TEST_SCRIPT("echo-split", NULL, VIRSH_DEFAULT, "-q"); # undef DO_TEST + /* comprehensive coverage of argument assignment */ + DO_TEST_SCRIPT("argument-assignment", NULL, VIRSH_DEFAULT, "-k0", "-d0"); + VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/virshtestdata/argument-assignment.in b/tests/virshtestdata/argument-assignment.in new file mode 100644 index 0000000000..283f521b1c --- /dev/null +++ b/tests/virshtestdata/argument-assignment.in @@ -0,0 +1,15 @@ +setvcpus test 2 +setvcpus --domain test 2 +setvcpus --domain=test 2 +setvcpus test --count 2 +setvcpus test --count=2 +setvcpus --domain test --count 2 +setvcpus --domain=test --count 2 +setvcpus --domain test --count=2 +setvcpus --domain=test --count=2 +setvcpus --count 2 --domain test +setvcpus --count 2 --domain=test +setvcpus --count=2 --domain test +setvcpus --count=2 --domain=test +setvcpus --count 2 test +setvcpus --count=2 test diff --git a/tests/virshtestdata/argument-assignment.out b/tests/virshtestdata/argument-assignment.out new file mode 100644 index 0000000000..501f0add33 --- /dev/null +++ b/tests/virshtestdata/argument-assignment.out @@ -0,0 +1,91 @@ +commands: "setvcpus test 2 +setvcpus --domain test 2 +setvcpus --domain=test 2 +setvcpus test --count 2 +setvcpus test --count=2 +setvcpus --domain test --count 2 +setvcpus --domain=test --count 2 +setvcpus --domain test --count=2 +setvcpus --domain=test --count=2 +setvcpus --count 2 --domain test +setvcpus --count 2 --domain=test +setvcpus --count=2 --domain test +setvcpus --count=2 --domain=test +setvcpus --count 2 test +setvcpus --count=2 test +" +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: count(optdata): 2 +setvcpus: domain(optdata): test +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + +setvcpus: found option <domain>: test +setvcpus: <domain> trying as domain NAME + -- 2.44.0

Move the argument parsing tests excercising 'virsh snapshot-create-as' from 'virsh-optparse' to 'virshtest'. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virsh-optparse | 60 -------------- tests/virshtest.c | 1 + tests/virshtestdata/snapshot-create-args.in | 9 +++ tests/virshtestdata/snapshot-create-args.out | 82 ++++++++++++++++++++ 4 files changed, 92 insertions(+), 60 deletions(-) create mode 100644 tests/virshtestdata/snapshot-create-args.in create mode 100644 tests/virshtestdata/snapshot-create-args.out diff --git a/tests/virsh-optparse b/tests/virsh-optparse index 77e754d73a..10fdf7727e 100755 --- a/tests/virsh-optparse +++ b/tests/virsh-optparse @@ -32,66 +32,6 @@ fail=0 test_url=test:///default -# Another complex parsing example -cat <<\EOF > exp-out || framework_failure -<domainsnapshot> - <description>1<2</description> - <memory file='d,e'/> - <disks> - <disk name='vda' snapshot='external'> - <source file='a&b,c'/> - </disk> - <disk name='vdb'/> - </disks> -</domainsnapshot> - -EOF -$VIRSH -q -c $test_url snapshot-create-as --print-xml test \ - --diskspec 'vda,file=a&b,,c,snapshot=external' --description '1<2' \ - --diskspec vdb --memspec file=d,,e >out 2>>err || fail=1 -compare exp-out out || fail=1 - -cat <<\EOF > exp-out || framework_failure -<domainsnapshot> - <name>name</name> - <description>vda</description> - <disks> - <disk name='vdb'/> - </disks> -</domainsnapshot> - -EOF -$VIRSH -q -c $test_url snapshot-create-as --print-xml test name vda vdb \ - >out 2>>err || fail=1 -compare exp-out out || fail=1 - -cat <<\EOF > exp-out || framework_failure -<domainsnapshot> - <name>name</name> - <description>desc</description> - <disks> - <disk name='vda'/> - <disk name='vdb'/> - </disks> -</domainsnapshot> - -EOF -for args in \ - 'test name desc vda vdb' \ - 'test name desc --diskspec vda vdb' \ - 'test name desc --diskspec vda --diskspec vdb' \ - 'test name desc vda vdb' \ - 'test --diskspec vda name --diskspec vdb desc' \ - '--description desc --name name --domain test vda vdb' \ - '--description desc --diskspec vda --name name --domain test vdb' \ -; do - $VIRSH -q -c $test_url snapshot-create-as --print-xml $args \ - >out 2>>err || fail=1 - compare exp-out out || fail=1 -done - -test -s err && fail=1 - # Test a required argv cat <<\EOF > exp-err || framework_failure error: this function is not supported by the connection driver: virDomainQemuMonitorCommand diff --git a/tests/virshtest.c b/tests/virshtest.c index 1baa402648..453b1d7a9e 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -200,6 +200,7 @@ mymain(void) /* comprehensive coverage of argument assignment */ DO_TEST_SCRIPT("argument-assignment", NULL, VIRSH_DEFAULT, "-k0", "-d0"); + DO_TEST_SCRIPT("snapshot-create-args", NULL, VIRSH_DEFAULT, "-q"); VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/virshtestdata/snapshot-create-args.in b/tests/virshtestdata/snapshot-create-args.in new file mode 100644 index 0000000000..195b7d62f2 --- /dev/null +++ b/tests/virshtestdata/snapshot-create-args.in @@ -0,0 +1,9 @@ +snapshot-create-as --print-xml test name desc vda vdb +snapshot-create-as --print-xml test name desc --diskspec vda vdb +snapshot-create-as --print-xml test name desc --diskspec vda --diskspec vdb +snapshot-create-as --print-xml test name desc vda vdb +snapshot-create-as --print-xml test --diskspec vda name --diskspec vdb desc +snapshot-create-as --print-xml --description desc --name name --domain test vda vdb +snapshot-create-as --print-xml --description desc --diskspec vda --name name --domain test vdb +snapshot-create-as --print-xml test name vda vdb +snapshot-create-as --print-xml test --diskspec vda,file=a&b,,c,snapshot=external --description 1<2 --diskspec vdb --memspec file=d,,e diff --git a/tests/virshtestdata/snapshot-create-args.out b/tests/virshtestdata/snapshot-create-args.out new file mode 100644 index 0000000000..1a87b97dab --- /dev/null +++ b/tests/virshtestdata/snapshot-create-args.out @@ -0,0 +1,82 @@ +<domainsnapshot> + <name>name</name> + <description>desc</description> + <disks> + <disk name='vda'/> + <disk name='vdb'/> + </disks> +</domainsnapshot> + +<domainsnapshot> + <name>name</name> + <description>desc</description> + <disks> + <disk name='vda'/> + <disk name='vdb'/> + </disks> +</domainsnapshot> + +<domainsnapshot> + <name>name</name> + <description>desc</description> + <disks> + <disk name='vda'/> + <disk name='vdb'/> + </disks> +</domainsnapshot> + +<domainsnapshot> + <name>name</name> + <description>desc</description> + <disks> + <disk name='vda'/> + <disk name='vdb'/> + </disks> +</domainsnapshot> + +<domainsnapshot> + <name>name</name> + <description>desc</description> + <disks> + <disk name='vda'/> + <disk name='vdb'/> + </disks> +</domainsnapshot> + +<domainsnapshot> + <name>name</name> + <description>desc</description> + <disks> + <disk name='vda'/> + <disk name='vdb'/> + </disks> +</domainsnapshot> + +<domainsnapshot> + <name>name</name> + <description>desc</description> + <disks> + <disk name='vda'/> + <disk name='vdb'/> + </disks> +</domainsnapshot> + +<domainsnapshot> + <name>name</name> + <description>vda</description> + <disks> + <disk name='vdb'/> + </disks> +</domainsnapshot> + +<domainsnapshot> + <description>1<2</description> + <memory file='d,e'/> + <disks> + <disk name='vda' snapshot='external'> + <source file='a&b,c'/> + </disk> + <disk name='vdb'/> + </disks> +</domainsnapshot> + -- 2.44.0

Move the argument parsing tests excercising various numeric options (except 'virsh event') from 'virsh-optparse' to 'virshtest'. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virsh-optparse | 105 ------------------------ tests/virshtest.c | 1 + tests/virshtestdata/numeric-parsing.in | 43 ++++++++++ tests/virshtestdata/numeric-parsing.out | 12 +++ 4 files changed, 56 insertions(+), 105 deletions(-) create mode 100644 tests/virshtestdata/numeric-parsing.in create mode 100644 tests/virshtestdata/numeric-parsing.out diff --git a/tests/virsh-optparse b/tests/virsh-optparse index 10fdf7727e..e9dccdd027 100755 --- a/tests/virsh-optparse +++ b/tests/virsh-optparse @@ -32,111 +32,6 @@ fail=0 test_url=test:///default -# Test a required argv -cat <<\EOF > exp-err || framework_failure -error: this function is not supported by the connection driver: virDomainQemuMonitorCommand -EOF -$VIRSH -q -c $test_url qemu-monitor-command test a >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -### Test a regular numeric option - -# Non-numeric value -cat <<\EOF > exp-err || framework_failure -error: Numeric value 'abc' for <start> option is malformed or out of range -EOF -$VIRSH -q -c $test_url cpu-stats test --start abc >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Numeric value with invalid suffix -cat <<\EOF > exp-err || framework_failure -error: Numeric value '42WB' for <start> option is malformed or out of range -EOF -$VIRSH -q -c $test_url cpu-stats test --start 42WB >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Numeric value with valid suffix. Suffixes are not supported for -# regular numeric options, so this value is rejected -cat <<\EOF > exp-err || framework_failure -error: Numeric value '42MB' for <start> option is malformed or out of range -EOF -$VIRSH -q -c $test_url cpu-stats test --start 42MB >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Numeric value bigger than INT_MAX -cat <<\EOF > exp-err || framework_failure -error: Numeric value '2147483648' for <start> option is malformed or out of range -EOF -$VIRSH -q -c $test_url cpu-stats test --start 2147483648 >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Negative numeric value. The value is not valid for the command -# we're testing, but it has been parsed correctly -cat <<\EOF > exp-err || framework_failure -error: Invalid value for start CPU -EOF -$VIRSH -q -c $test_url cpu-stats test --start -1 >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -### Test a scaled numeric option - -# Non-numeric value -cat <<\EOF > exp-err || framework_failure -error: Scaled numeric value 'abc' for <size> option is malformed or out of range -EOF -$VIRSH -q -c $test_url setmaxmem test abc >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Numeric value with invalid suffix -cat <<\EOF > exp-err || framework_failure -error: Scaled numeric value '42WB' for <size> option is malformed or out of range -error: invalid argument: unknown suffix 'WB' -EOF -$VIRSH -q -c $test_url setmaxmem test 42WB >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Numeric value with valid suffix -$VIRSH -q -c $test_url setmaxmem test 42MB --config >out 2>err || fail=1 -test -s out && fail=1 -test -s err && fail=1 - -# Numeric value bigger than INT_MAX. No failure here because -# scaled numeric values are unsigned long long -$VIRSH -q -c $test_url setmaxmem test 2147483648 --config >out 2>err || fail=1 -test -s out && fail=1 -test -s err && fail=1 - -# Negative numeric value -cat <<\EOF > exp-err || framework_failure -error: Scaled numeric value '-1' for <size> option is malformed or out of range -EOF -$VIRSH -q -c $test_url setmaxmem test -1 >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Zero. The value is not valid for the command we're testing, but -# it has been parsed correctly -cat <<\EOF > exp-err || framework_failure -error: Unable to change MaxMemorySize -error: memory in virDomainSetMemoryFlags must not be zero -EOF -$VIRSH -q -c $test_url setmaxmem test 0 >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Numeric value -$VIRSH -q -c $test_url setmaxmem test 42 --config >out 2>err || fail=1 -test -s out && fail=1 -test -s err && fail=1 - ### Test the <timeout> option (numeric option converted to ms) # Non-numeric value diff --git a/tests/virshtest.c b/tests/virshtest.c index 453b1d7a9e..37634a68a2 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -201,6 +201,7 @@ mymain(void) /* comprehensive coverage of argument assignment */ DO_TEST_SCRIPT("argument-assignment", NULL, VIRSH_DEFAULT, "-k0", "-d0"); DO_TEST_SCRIPT("snapshot-create-args", NULL, VIRSH_DEFAULT, "-q"); + DO_TEST_SCRIPT("numeric-parsing", NULL, VIRSH_DEFAULT, "-q"); VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/virshtestdata/numeric-parsing.in b/tests/virshtestdata/numeric-parsing.in new file mode 100644 index 0000000000..d099236af5 --- /dev/null +++ b/tests/virshtestdata/numeric-parsing.in @@ -0,0 +1,43 @@ +echo Test a regular numeric option + +echo Non-numeric value +cpu-stats test --start abc + +echo Numeric value with invalid suffix +cpu-stats test --start 42WB + +echo Numeric value with valid suffix. Suffixes are not supported for +echo regular numeric options, so this value is rejected +cpu-stats test --start 42MB + +echo Numeric value bigger than INT_MAX +cpu-stats test --start 2147483648 + +echo Negative numeric value. The value is not valid for the command +echo we are testing, but it has been parsed correctly +cpu-stats test --start -1 + +echo Test a scaled numeric option + +echo Non-numeric value +setmaxmem test abc + +echo Numeric value with invalid suffix +setmaxmem test 42WB + +echo Numeric value with valid suffix +setmaxmem test 42MB --config + +echo Numeric value bigger than INT_MAX. No failure here because +echo scaled numeric values are unsigned long long +setmaxmem test 2147483648 --config + +echo Negative numeric value +setmaxmem test -1 + +echo Zero. The value is not valid for the command were testing, but +echo it has been parsed correctly +setmaxmem test 0 + +echo Numeric value +setmaxmem test 42 --config diff --git a/tests/virshtestdata/numeric-parsing.out b/tests/virshtestdata/numeric-parsing.out new file mode 100644 index 0000000000..4a0be84ac1 --- /dev/null +++ b/tests/virshtestdata/numeric-parsing.out @@ -0,0 +1,12 @@ +Test a regular numeric optionNon-numeric valueerror: Numeric value 'abc' for <start> option is malformed or out of range +Numeric value with invalid suffixerror: Numeric value '42WB' for <start> option is malformed or out of range +Numeric value with valid suffix. Suffixes are not supported forregular numeric options, so this value is rejectederror: Numeric value '42MB' for <start> option is malformed or out of range +Numeric value bigger than INT_MAXerror: Numeric value '2147483648' for <start> option is malformed or out of range +Negative numeric value. The value is not valid for the commandwe are testing, but it has been parsed correctlyerror: Invalid value for start CPU +Test a scaled numeric optionNon-numeric valueerror: Scaled numeric value 'abc' for <size> option is malformed or out of range +Numeric value with invalid suffixerror: Scaled numeric value '42WB' for <size> option is malformed or out of range +error: invalid argument: unknown suffix 'WB' +Numeric value with valid suffixNumeric value bigger than INT_MAX. No failure here becausescaled numeric values are unsigned long longNegative numeric valueerror: Scaled numeric value '-1' for <size> option is malformed or out of range +Zero. The value is not valid for the command were testing, butit has been parsed correctlyerror: Unable to change MaxMemorySize +error: memory in virDomainSetMemoryFlags must not be zero +Numeric value -- 2.44.0

On a Friday in 2024, Peter Krempa wrote:
Move the argument parsing tests excercising various numeric options (except 'virsh event') from 'virsh-optparse' to 'virshtest'.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virsh-optparse | 105 ------------------------ tests/virshtest.c | 1 + tests/virshtestdata/numeric-parsing.in | 43 ++++++++++ tests/virshtestdata/numeric-parsing.out | 12 +++ 4 files changed, 56 insertions(+), 105 deletions(-) create mode 100644 tests/virshtestdata/numeric-parsing.in create mode 100644 tests/virshtestdata/numeric-parsing.out
diff --git a/tests/virshtest.c b/tests/virshtest.c index 453b1d7a9e..37634a68a2 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -201,6 +201,7 @@ mymain(void) /* comprehensive coverage of argument assignment */ DO_TEST_SCRIPT("argument-assignment", NULL, VIRSH_DEFAULT, "-k0", "-d0"); DO_TEST_SCRIPT("snapshot-create-args", NULL, VIRSH_DEFAULT, "-q"); + DO_TEST_SCRIPT("numeric-parsing", NULL, VIRSH_DEFAULT, "-q");
Please drop the "-q" here, to make the output file human-readable.
VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Move the argument parsing tests excercising 'virsh event' options from 'virsh-optparse' to 'virshtest'. As the test invokes 'virsh event' with a timeout and thus waits for one second pointlessly the patch also adds infrastructure to mark individual cases as expensive and is skipped normally. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 1 - tests/virsh-optparse | 98 ------------------- tests/virshtest.c | 16 ++- tests/virshtestdata/numeric-parsing-event.in | 26 +++++ tests/virshtestdata/numeric-parsing-event.out | 10 ++ 5 files changed, 49 insertions(+), 102 deletions(-) delete mode 100755 tests/virsh-optparse create mode 100644 tests/virshtestdata/numeric-parsing-event.in create mode 100644 tests/virshtestdata/numeric-parsing-event.out diff --git a/tests/meson.build b/tests/meson.build index 3fcfa6b1e0..849a513f33 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -695,7 +695,6 @@ if conf.has('WITH_LIBVIRTD') 'virsh-cpuset', 'virsh-define-dev-segfault', 'virsh-int-overflow', - 'virsh-optparse', 'virsh-output', 'virsh-read-bufsiz', 'virsh-read-non-seekable', diff --git a/tests/virsh-optparse b/tests/virsh-optparse deleted file mode 100755 index e9dccdd027..0000000000 --- a/tests/virsh-optparse +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/sh -# Ensure that virsh option parsing doesn't regress - -# Copyright (C) 2011-2012, 2014 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# <http://www.gnu.org/licenses/>. - -. "$(dirname $0)/test-lib.sh" - -test_expensive - -VIRSH=$abs_top_builddir/tools/virsh - -if test "$VERBOSE" = yes; then - set -x - $VIRSH --version -fi - -fail=0 - -test_url=test:///default - -### Test the <timeout> option (numeric option converted to ms) - -# Non-numeric value -cat <<\EOF > exp-err || framework_failure -error: Numeric value 'abc' for <timeout> option is malformed or out of range -EOF -$VIRSH -q -c $test_url event --all --timeout abc >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Numeric value that's too big to be converted to ms and still -# fit inside an int -cat <<\EOF > exp-err || framework_failure -error: Numeric value '2147484' for <timeout> option is malformed or out of range -EOF -$VIRSH -q -c $test_url event --all --timeout 2147484 >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Numeric value with invalid suffix -cat <<\EOF > exp-err || framework_failure -error: Numeric value '42WB' for <timeout> option is malformed or out of range -EOF -$VIRSH -q -c $test_url event --all --timeout 42WB >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Numeric value with valid suffix. Suffixes are not supported for -# the <timeout> option, so this value is rejected -cat <<\EOF > exp-err || framework_failure -error: Numeric value '42MB' for <timeout> option is malformed or out of range -EOF -$VIRSH -q -c $test_url event --all --timeout 42MB >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Negative value -cat <<\EOF > exp-err || framework_failure -error: Numeric value '-1' for <timeout> option is malformed or out of range -EOF -$VIRSH -q -c $test_url event --all --timeout -1 >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Zero. This is not a valid timeout, but the value is parsed -# correctly -cat <<\EOF > exp-err || framework_failure -error: Numeric value '0' for <timeout> option is malformed or out of range -EOF -$VIRSH -q -c $test_url event --all --timeout 0 >out 2>err && fail=1 -test -s out && fail=1 -compare exp-err err || fail=1 - -# Numeric value. No events will be received and the command will -# fail after a second, but the value has been parsed correctly -cat <<\EOF > exp-out || framework_failure -event loop timed out -events received: 0 -EOF -$VIRSH -q -c $test_url event --all --timeout 1 >out 2>err && fail=1 -test -s err && fail=1 -compare exp-out out || fail=1 - -(exit $fail); exit $fail diff --git a/tests/virshtest.c b/tests/virshtest.c index 37634a68a2..ca0a73651a 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -83,6 +83,7 @@ struct testInfo { const char *testname; /* used to generate output filename */ const char *filter; const char *const *argv; + bool expensive; }; static int testCompare(const void *data) @@ -90,6 +91,9 @@ static int testCompare(const void *data) const struct testInfo *info = data; g_autofree char *outfile = NULL; + if (info->expensive && virTestGetExpensive() == 0) + return EXIT_AM_SKIP; + if (info->testname) { outfile = g_strdup_printf("%s/virshtestdata/%s.out", abs_srcdir, info->testname); @@ -107,14 +111,14 @@ mymain(void) custom_uri = g_strdup_printf("test://%s/../examples/xml/test/testnode.xml", abs_srcdir); -# define DO_TEST_SCRIPT(testname_, testfilter, ...) \ +# define DO_TEST_SCRIPT_FULL(testname_, expensive, testfilter, ...) \ { \ const char *testname = testname_; \ g_autofree char *infile = g_strdup_printf("%s/virshtestdata/%s.in", \ abs_srcdir, testname); \ const char *myargv[] = { __VA_ARGS__, NULL, NULL }; \ const char **tmp = myargv; \ - const struct testInfo info = { testname, testfilter, myargv }; \ + const struct testInfo info = { testname, testfilter, myargv, expensive }; \ g_autofree char *scriptarg = NULL; \ if (virFileReadAll(infile, 256 * 1024, &scriptarg) < 0) { \ fprintf(stderr, "\nfailed to load '%s'\n", infile); \ @@ -127,6 +131,9 @@ mymain(void) ret = -1; \ } while (0); +# define DO_TEST_SCRIPT(testname_, testfilter, ...) \ + DO_TEST_SCRIPT_FULL(testname_, false, testfilter, __VA_ARGS__); + DO_TEST_SCRIPT("info-default", NULL, VIRSH_DEFAULT); DO_TEST_SCRIPT("info-custom", NULL, VIRSH_CUSTOM); DO_TEST_SCRIPT("domain-id", "\nCPU time:", VIRSH_CUSTOM); @@ -137,7 +144,7 @@ mymain(void) do { \ const char *testname = testname_; \ const char *myargv[] = { __VA_ARGS__, NULL }; \ - const struct testInfo info = { testname, NULL, myargv }; \ + const struct testInfo info = { testname, NULL, myargv, false }; \ if (virTestRun(testname, testCompare, &info) < 0) \ ret = -1; \ } while (0) @@ -202,6 +209,9 @@ mymain(void) DO_TEST_SCRIPT("argument-assignment", NULL, VIRSH_DEFAULT, "-k0", "-d0"); DO_TEST_SCRIPT("snapshot-create-args", NULL, VIRSH_DEFAULT, "-q"); DO_TEST_SCRIPT("numeric-parsing", NULL, VIRSH_DEFAULT, "-q"); + /* The 'numeric-parsing-event' invokes virsh event with a 1 second timeout, + * thus is marked expensive */ + DO_TEST_SCRIPT_FULL("numeric-parsing-event", true, NULL, VIRSH_DEFAULT, "-q"); VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/virshtestdata/numeric-parsing-event.in b/tests/virshtestdata/numeric-parsing-event.in new file mode 100644 index 0000000000..44565df3e2 --- /dev/null +++ b/tests/virshtestdata/numeric-parsing-event.in @@ -0,0 +1,26 @@ +echo Test the <timeout> option (numeric option converted to ms) + +echo Non-numeric value +event --all --timeout abc + +echo Numeric value that is too big to be converted to ms and still +echo fit inside an int +event --all --timeout 2147484 + +echo Numeric value with invalid suffix +event --all --timeout 42WB + +echo Numeric value with valid suffix. Suffixes are not supported for +echo the <timeout> option, so this value is rejected +event --all --timeout 42MB + +echo Negative value +event --all --timeout -1 + +echo Zero. This is not a valid timeout, but the value is parsed +echo correctly +event --all --timeout 0 + +echo Numeric value. No events will be received and the command will +echo fail after a second, but the value has been parsed correctly +event --all --timeout 1 diff --git a/tests/virshtestdata/numeric-parsing-event.out b/tests/virshtestdata/numeric-parsing-event.out new file mode 100644 index 0000000000..3d3fcbe5fc --- /dev/null +++ b/tests/virshtestdata/numeric-parsing-event.out @@ -0,0 +1,10 @@ +Test the <timeout> option (numeric option converted to ms)Non-numeric valueerror: Numeric value 'abc' for <timeout> option is malformed or out of range +Numeric value that is too big to be converted to ms and stillfit inside an interror: Numeric value '2147484' for <timeout> option is malformed or out of range +Numeric value with invalid suffixerror: Numeric value '42WB' for <timeout> option is malformed or out of range +Numeric value with valid suffix. Suffixes are not supported forthe <timeout> option, so this value is rejectederror: Numeric value '42MB' for <timeout> option is malformed or out of range +Negative valueerror: Numeric value '-1' for <timeout> option is malformed or out of range +Zero. This is not a valid timeout, but the value is parsedcorrectlyerror: Numeric value '0' for <timeout> option is malformed or out of range +Numeric value. No events will be received and the command willfail after a second, but the value has been parsed correctlyevent loop timed out +events received: 0 + +## Exit code: 1 -- 2.44.0

On a Friday in 2024, Peter Krempa wrote:
Move the argument parsing tests excercising 'virsh event' options from 'virsh-optparse' to 'virshtest'.
As the test invokes 'virsh event' with a timeout and thus waits for one second pointlessly the patch also adds infrastructure to mark individual cases as expensive and is skipped normally.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 1 - tests/virsh-optparse | 98 ------------------- tests/virshtest.c | 16 ++- tests/virshtestdata/numeric-parsing-event.in | 26 +++++ tests/virshtestdata/numeric-parsing-event.out | 10 ++ 5 files changed, 49 insertions(+), 102 deletions(-) delete mode 100755 tests/virsh-optparse create mode 100644 tests/virshtestdata/numeric-parsing-event.in create mode 100644 tests/virshtestdata/numeric-parsing-event.out
@@ -202,6 +209,9 @@ mymain(void) DO_TEST_SCRIPT("argument-assignment", NULL, VIRSH_DEFAULT, "-k0", "-d0"); DO_TEST_SCRIPT("snapshot-create-args", NULL, VIRSH_DEFAULT, "-q"); DO_TEST_SCRIPT("numeric-parsing", NULL, VIRSH_DEFAULT, "-q"); + /* The 'numeric-parsing-event' invokes virsh event with a 1 second timeout, + * thus is marked expensive */ + DO_TEST_SCRIPT_FULL("numeric-parsing-event", true, NULL, VIRSH_DEFAULT, "-q");
Same here. Jano
VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/virshtestdata/numeric-parsing-event.out b/tests/virshtestdata/numeric-parsing-event.out new file mode 100644 index 0000000000..3d3fcbe5fc --- /dev/null +++ b/tests/virshtestdata/numeric-parsing-event.out @@ -0,0 +1,10 @@ +Test the <timeout> option (numeric option converted to ms)Non-numeric valueerror: Numeric value 'abc' for <timeout> option is malformed or out of range +Numeric value that is too big to be converted to ms and stillfit inside an interror: Numeric value '2147484' for <timeout> option is malformed or out of range +Numeric value with invalid suffixerror: Numeric value '42WB' for <timeout> option is malformed or out of range +Numeric value with valid suffix. Suffixes are not supported forthe <timeout> option, so this value is rejectederror: Numeric value '42MB' for <timeout> option is malformed or out of range +Negative valueerror: Numeric value '-1' for <timeout> option is malformed or out of range +Zero. This is not a valid timeout, but the value is parsedcorrectlyerror: Numeric value '0' for <timeout> option is malformed or out of range +Numeric value. No events will be received and the command willfail after a second, but the value has been parsed correctlyevent loop timed out +events received: 0 + +## Exit code: 1 -- 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org

Adapt the 'tests/virsh-output-commands' file from 'virsh-output' test as a source. Apart from expanding the bash function to each command, I've also had to drop the negative tests for argument population, as a command parsing error aborts the execution of the script right away rather than just reporting the error. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 1 - tests/virsh-output | 29 -- tests/virsh-output-commands | 94 ------ tests/virsh-output.out | 496 ---------------------------- tests/virshtest.c | 1 + tests/virshtestdata/attach-disk.in | 79 +++++ tests/virshtestdata/attach-disk.out | 343 +++++++++++++++++++ 7 files changed, 423 insertions(+), 620 deletions(-) delete mode 100755 tests/virsh-output delete mode 100755 tests/virsh-output-commands delete mode 100644 tests/virsh-output.out create mode 100755 tests/virshtestdata/attach-disk.in create mode 100644 tests/virshtestdata/attach-disk.out diff --git a/tests/meson.build b/tests/meson.build index 849a513f33..b70fe7732e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -695,7 +695,6 @@ if conf.has('WITH_LIBVIRTD') 'virsh-cpuset', 'virsh-define-dev-segfault', 'virsh-int-overflow', - 'virsh-output', 'virsh-read-bufsiz', 'virsh-read-non-seekable', 'virsh-schedinfo', diff --git a/tests/virsh-output b/tests/virsh-output deleted file mode 100755 index aa2d386c39..0000000000 --- a/tests/virsh-output +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -. "$(dirname $0)/test-lib.sh" - -test_expensive - -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 deleted file mode 100755 index d8e73fc1ac..0000000000 --- a/tests/virsh-output-commands +++ /dev/null @@ -1,94 +0,0 @@ -#!/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 --sourcetype file --type disk --address sata:1.2.3 -attach_disk --target sda --sourcetype file --type disk --address sata:1.2.4 -attach_disk --target sda --sourcetype file --type disk --address sata:1:2:5 -attach_disk --target hda --sourcetype file --type disk --address sata:1.2.3 -attach_disk --target vda --sourcetype file --type disk --address sata:1.2.3 - -attach_disk --target vda --sourcetype file --type disk --address pci:12.34.56.78 -attach_disk --target vda --sourcetype file --type disk --address pci:12:34:56:78 -attach_disk --target vda --sourcetype file --type disk --address pci:12.34.56.aa -attach_disk --target hda --sourcetype file --type disk --address pci:12.34.56.aa -attach_disk --target sda --sourcetype file --type disk --address pci:12.34.56.aa - -attach_disk --target vda --sourcetype file --type disk --address pci:12.34.56.78 --multifunction -attach_disk --target vda --sourcetype file --type disk --address pci:12:34:56:78 --multifunction -attach_disk --target vda --sourcetype file --type disk --address pci:12.34.56.aa --multifunction - -attach_disk --target vda --sourcetype file --type disk --address ccw:12.34.56 -attach_disk --target vda --sourcetype file --type disk --address ccw:12:34:56 -attach_disk --target vda --sourcetype file --type disk --address ccw:12.34.56 -attach_disk --target hda --sourcetype file --type disk --address ccw:12.34.56 -attach_disk --target sda --sourcetype file --type disk --address ccw:12.34.56 - -attach_disk --target vda --sourcetype file --type disk --address test:12.34.56 -attach_disk --target vda --sourcetype file --type disk --address test:12:34:56 -attach_disk --target vda --sourcetype file --type disk --address test:12.34.56 - -./virsh attach-disk --print-xml --domain testdom $@ --source "" --source-protocol AAA -./virsh attach-disk --print-xml --domain testdom $@ --source "" --source-protocol AAA -attach_disk --target hda --source-protocol AAA --sourcetype file -attach_disk --target hda --sourcetype network -attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-name hostname -attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-name hostname:port -attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-name hostname: -attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-name :port -attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-name : -attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-name hostname:port --source-host-transport trnsp -attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-transport trnsp -attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-transport trnsp --source-host-socket /nonexistent/socket -attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-socket /nonexistent/socket diff --git a/tests/virsh-output.out b/tests/virsh-output.out deleted file mode 100644 index d8ef641c2a..0000000000 --- a/tests/virsh-output.out +++ /dev/null @@ -1,496 +0,0 @@ -+ ./virsh attach-disk -error: command 'attach-disk' requires <domain> option -error: command 'attach-disk' requires <source> option -error: command 'attach-disk' requires <target> option -+ ./virsh attach-disk --print-xml --domain testdom --source '' -error: command 'attach-disk' requires <target> option -+ ./virsh attach-disk --print-xml --domain testdom --source '' --sourcetype file -error: command 'attach-disk' requires <target> option -+ ./virsh attach-disk --print-xml --domain testdom --source '' --sourcetype blah -error: command 'attach-disk' requires <target> option -+ attach_disk --target hda -+ ./virsh attach-disk --print-xml --domain testdom --target hda --source /nonexistent/file -<disk type='file'> - <source file='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype file -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --source /nonexistent/file -<disk type='file'> - <source file='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype block -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype block --source /nonexistent/file -<disk type='block'> - <source dev='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype nothing -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype nothing --source /nonexistent/file -error: Unknown source type: 'nothing' - -+ attach_disk --target hda --sourcetype file --type disk -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype block --type disk -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype block --type disk --source /nonexistent/file -<disk type='block' device='disk'> - <source dev='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type cdrom -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type cdrom --source /nonexistent/file -<disk type='file' device='cdrom'> - <source file='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype block --type cdrom -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype block --type cdrom --source /nonexistent/file -<disk type='block' device='cdrom'> - <source dev='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type blah -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type blah --source /nonexistent/file -<disk type='file' device='blah'> - <source file='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype block --type blah -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype block --type blah --source /nonexistent/file -<disk type='block' device='blah'> - <source dev='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --driver testdriver -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --driver testdriver --source /nonexistent/file -<disk type='file' device='disk'> - <driver name='testdriver'/> - <source file='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --subdriver qcow2 --source /nonexistent/file -<disk type='file' device='disk'> - <driver type='qcow2'/> - <source file='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --subdriver raw -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --subdriver raw --source /nonexistent/file -<disk type='file' device='disk'> - <driver type='raw'/> - <source file='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --cache none -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --cache none --source /nonexistent/file -<disk type='file' device='disk'> - <driver cache='none'/> - <source file='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 --cache none -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --subdriver qcow2 --cache none --source /nonexistent/file -<disk type='file' device='disk'> - <driver type='qcow2' cache='none'/> - <source file='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 --serial TEST_SERIAL -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --subdriver qcow2 --serial TEST_SERIAL --source /nonexistent/file -<disk type='file' device='disk'> - <driver type='qcow2'/> - <source file='/nonexistent/file'/> - <target dev='hda'/> - <serial>TEST_SERIAL</serial> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --mode readonly -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --mode readonly --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='hda'/> - <readonly/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --mode shareable -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --mode shareable --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='hda'/> - <shareable/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --mode whatever -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --mode whatever --source /nonexistent/file -error: No support for whatever in command 'attach-disk' - -+ attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 --alias testalias -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --subdriver qcow2 --alias testalias --source /nonexistent/file -<disk type='file' device='disk'> - <driver type='qcow2'/> - <source file='/nonexistent/file'/> - <target dev='hda'/> - <alias name='testalias'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --rawio -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --rawio --source /nonexistent/file -<disk type='file' device='disk' rawio='yes'> - <source file='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --multifunction -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --multifunction --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --subdriver qcow2 --alias testalias --iothread 3 --mode readonly --cache none --driver qemu -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --subdriver qcow2 --alias testalias --iothread 3 --mode readonly --cache none --driver qemu --source /nonexistent/file -<disk type='file' device='disk'> - <driver name='qemu' type='qcow2' iothread='3' cache='none'/> - <source file='/nonexistent/file'/> - <target dev='hda'/> - <readonly/> - <alias name='testalias'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --address ide:1.2.3 -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --address ide:1.2.3 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='hda'/> - <address type='drive' controller='1' bus='2' unit='3'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --address ide:1.2.4 -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --address ide:1.2.4 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='hda'/> - <address type='drive' controller='1' bus='2' unit='4'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --address ide:1:2:5 -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --address ide:1:2:5 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='hda'/> - <address type='drive' controller='1' bus='2' unit='5'/> -</disk> - -+ attach_disk --target sda --sourcetype file --type disk --address ide:1.2.3 -+ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcetype file --type disk --address ide:1.2.3 --source /nonexistent/file -error: expecting a scsi:00.00.00 or usb:00.00 or sata:00.00.00 address. - -+ attach_disk --target vda --sourcetype file --type disk --address ide:1.2.3 -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address ide:1.2.3 --source /nonexistent/file -error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 address. - -+ attach_disk --target sda --sourcetype file --type disk --address usb:12.34 -+ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcetype file --type disk --address usb:12.34 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='sda'/> - <address type='usb' bus='12' port='34'/> -</disk> - -+ attach_disk --target sda --sourcetype file --type disk --address usb:12.3 -+ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcetype file --type disk --address usb:12.3 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='sda'/> - <address type='usb' bus='12' port='3'/> -</disk> - -+ attach_disk --target sda --sourcetype file --type disk --address usb:12:34 -+ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcetype file --type disk --address usb:12:34 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='sda'/> - <address type='usb' bus='12' port='34'/> -</disk> - -+ attach_disk --target vda --sourcetype file --type disk --address usb:12.34 -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address usb:12.34 --source /nonexistent/file -error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 address. - -+ attach_disk --target hda --sourcetype file --type disk --address usb:12.34 -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --address usb:12.34 --source /nonexistent/file -error: expecting an ide:00.00.00 address. - -+ attach_disk --target sda --sourcetype file --type disk --address scsi:1.2.3 -+ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcetype file --type disk --address scsi:1.2.3 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='sda'/> - <address type='drive' controller='1' bus='2' unit='3'/> -</disk> - -+ attach_disk --target sda --sourcetype file --type disk --address scsi:1.2.4 -+ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcetype file --type disk --address scsi:1.2.4 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='sda'/> - <address type='drive' controller='1' bus='2' unit='4'/> -</disk> - -+ attach_disk --target sda --sourcetype file --type disk --address scsi:1:2:5 -+ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcetype file --type disk --address scsi:1:2:5 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='sda'/> - <address type='drive' controller='1' bus='2' unit='5'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --address scsi:1.2.3 -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --address scsi:1.2.3 --source /nonexistent/file -error: expecting an ide:00.00.00 address. - -+ attach_disk --target vda --sourcetype file --type disk --address scsi:1.2.3 -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address scsi:1.2.3 --source /nonexistent/file -error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 address. - -+ attach_disk --target sda --sourcetype file --type disk --address sata:1.2.3 -+ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcetype file --type disk --address sata:1.2.3 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='sda'/> - <address type='drive' controller='1' bus='2' unit='3'/> -</disk> - -+ attach_disk --target sda --sourcetype file --type disk --address sata:1.2.4 -+ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcetype file --type disk --address sata:1.2.4 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='sda'/> - <address type='drive' controller='1' bus='2' unit='4'/> -</disk> - -+ attach_disk --target sda --sourcetype file --type disk --address sata:1:2:5 -+ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcetype file --type disk --address sata:1:2:5 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='sda'/> - <address type='drive' controller='1' bus='2' unit='5'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --address sata:1.2.3 -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --address sata:1.2.3 --source /nonexistent/file -error: expecting an ide:00.00.00 address. - -+ attach_disk --target vda --sourcetype file --type disk --address sata:1.2.3 -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address sata:1.2.3 --source /nonexistent/file -error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 address. - -+ attach_disk --target vda --sourcetype file --type disk --address pci:12.34.56.78 -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address pci:12.34.56.78 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='vda'/> - <address type='pci' domain='0x0012' bus='0x34' slot='0x56' function='0x78'/> -</disk> - -+ attach_disk --target vda --sourcetype file --type disk --address pci:12:34:56:78 -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address pci:12:34:56:78 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='vda'/> - <address type='pci' domain='0x0012' bus='0x34' slot='0x56' function='0x78'/> -</disk> - -+ attach_disk --target vda --sourcetype file --type disk --address pci:12.34.56.aa -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address pci:12.34.56.aa --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='vda'/> - <address type='pci' domain='0x0012' bus='0x34' slot='0x56' function='0xaa'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --address pci:12.34.56.aa -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --address pci:12.34.56.aa --source /nonexistent/file -error: expecting an ide:00.00.00 address. - -+ attach_disk --target sda --sourcetype file --type disk --address pci:12.34.56.aa -+ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcetype file --type disk --address pci:12.34.56.aa --source /nonexistent/file -error: expecting a scsi:00.00.00 or usb:00.00 or sata:00.00.00 address. - -+ attach_disk --target vda --sourcetype file --type disk --address pci:12.34.56.78 --multifunction -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address pci:12.34.56.78 --multifunction --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='vda'/> - <address type='pci' domain='0x0012' bus='0x34' slot='0x56' function='0x78' multifunction='on'/> -</disk> - -+ attach_disk --target vda --sourcetype file --type disk --address pci:12:34:56:78 --multifunction -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address pci:12:34:56:78 --multifunction --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='vda'/> - <address type='pci' domain='0x0012' bus='0x34' slot='0x56' function='0x78' multifunction='on'/> -</disk> - -+ attach_disk --target vda --sourcetype file --type disk --address pci:12.34.56.aa --multifunction -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address pci:12.34.56.aa --multifunction --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='vda'/> - <address type='pci' domain='0x0012' bus='0x34' slot='0x56' function='0xaa' multifunction='on'/> -</disk> - -+ attach_disk --target vda --sourcetype file --type disk --address ccw:12.34.56 -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address ccw:12.34.56 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='vda'/> - <address type='ccw' cssid='0x12' ssid='0x34' devno='0x0056'/> -</disk> - -+ attach_disk --target vda --sourcetype file --type disk --address ccw:12:34:56 -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address ccw:12:34:56 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='vda'/> - <address type='ccw' cssid='0x12' ssid='0x34' devno='0x0056'/> -</disk> - -+ attach_disk --target vda --sourcetype file --type disk --address ccw:12.34.56 -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address ccw:12.34.56 --source /nonexistent/file -<disk type='file' device='disk'> - <source file='/nonexistent/file'/> - <target dev='vda'/> - <address type='ccw' cssid='0x12' ssid='0x34' devno='0x0056'/> -</disk> - -+ attach_disk --target hda --sourcetype file --type disk --address ccw:12.34.56 -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype file --type disk --address ccw:12.34.56 --source /nonexistent/file -error: expecting an ide:00.00.00 address. - -+ attach_disk --target sda --sourcetype file --type disk --address ccw:12.34.56 -+ ./virsh attach-disk --print-xml --domain testdom --target sda --sourcetype file --type disk --address ccw:12.34.56 --source /nonexistent/file -error: expecting a scsi:00.00.00 or usb:00.00 or sata:00.00.00 address. - -+ attach_disk --target vda --sourcetype file --type disk --address test:12.34.56 -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address test:12.34.56 --source /nonexistent/file -error: Invalid address. - -+ attach_disk --target vda --sourcetype file --type disk --address test:12:34:56 -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address test:12:34:56 --source /nonexistent/file -error: Invalid address. - -+ attach_disk --target vda --sourcetype file --type disk --address test:12.34.56 -+ ./virsh attach-disk --print-xml --domain testdom --target vda --sourcetype file --type disk --address test:12.34.56 --source /nonexistent/file -error: Invalid address. - -+ ./virsh attach-disk --print-xml --domain testdom --source '' --source-protocol AAA -error: command 'attach-disk' requires <target> option -+ ./virsh attach-disk --print-xml --domain testdom --source '' --source-protocol AAA -error: command 'attach-disk' requires <target> option -+ attach_disk --target hda --source-protocol AAA --sourcetype file -+ ./virsh attach-disk --print-xml --domain testdom --target hda --source-protocol AAA --sourcetype file --source /nonexistent/file -error: --source-protocol option requires --sourcetype network - -+ attach_disk --target hda --sourcetype network -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype network --source /nonexistent/file -error: --source-protocol option requires --sourcetype network - -+ attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-name hostname -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype network --source-protocol TEST --source-host-name hostname --source /nonexistent/file -<disk type='network'> - <source protocol='TEST' name='/nonexistent/file'> - <host name='hostname'/> - </source> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-name hostname:port -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype network --source-protocol TEST --source-host-name hostname:port --source /nonexistent/file -<disk type='network'> - <source protocol='TEST' name='/nonexistent/file'> - <host name='hostname' port='port'/> - </source> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-name hostname: -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype network --source-protocol TEST --source-host-name hostname: --source /nonexistent/file -<disk type='network'> - <source protocol='TEST' name='/nonexistent/file'> - <host name='hostname' port=''/> - </source> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-name :port -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype network --source-protocol TEST --source-host-name :port --source /nonexistent/file -<disk type='network'> - <source protocol='TEST' name='/nonexistent/file'> - <host name='' port='port'/> - </source> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-name : -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype network --source-protocol TEST --source-host-name : --source /nonexistent/file -<disk type='network'> - <source protocol='TEST' name='/nonexistent/file'> - <host name='' port=''/> - </source> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-name hostname:port --source-host-transport trnsp -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype network --source-protocol TEST --source-host-name hostname:port --source-host-transport trnsp --source /nonexistent/file -<disk type='network'> - <source protocol='TEST' name='/nonexistent/file'> - <host transport='trnsp' name='hostname' port='port'/> - </source> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-transport trnsp -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype network --source-protocol TEST --source-host-transport trnsp --source /nonexistent/file -<disk type='network'> - <source protocol='TEST' name='/nonexistent/file'> - <host transport='trnsp'/> - </source> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-transport trnsp --source-host-socket /nonexistent/socket -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype network --source-protocol TEST --source-host-transport trnsp --source-host-socket /nonexistent/socket --source /nonexistent/file -<disk type='network'> - <source protocol='TEST' name='/nonexistent/file'> - <host transport='trnsp' socket='/nonexistent/socket'/> - </source> - <target dev='hda'/> -</disk> - -+ attach_disk --target hda --sourcetype network --source-protocol TEST --source-host-socket /nonexistent/socket -+ ./virsh attach-disk --print-xml --domain testdom --target hda --sourcetype network --source-protocol TEST --source-host-socket /nonexistent/socket --source /nonexistent/file -error: Option --source-host-transport is required by option --source-host-socket - -end diff --git a/tests/virshtest.c b/tests/virshtest.c index ca0a73651a..78f6148733 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -212,6 +212,7 @@ mymain(void) /* The 'numeric-parsing-event' invokes virsh event with a 1 second timeout, * thus is marked expensive */ DO_TEST_SCRIPT_FULL("numeric-parsing-event", true, NULL, VIRSH_DEFAULT, "-q"); + DO_TEST_SCRIPT("attach-disk", NULL, VIRSH_DEFAULT); VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/virshtestdata/attach-disk.in b/tests/virshtestdata/attach-disk.in new file mode 100755 index 0000000000..f46b12f6dc --- /dev/null +++ b/tests/virshtestdata/attach-disk.in @@ -0,0 +1,79 @@ +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype block +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype nothing +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype block --type disk +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type cdrom +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype block --type cdrom +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type blah +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype block --type blah +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --driver testdriver +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --subdriver qcow2 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --subdriver raw +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --cache none +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --subdriver qcow2 --cache none +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --subdriver qcow2 --serial TEST_SERIAL +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --mode readonly +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --mode shareable +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --mode whatever +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --subdriver qcow2 --alias testalias +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --rawio +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --multifunction +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --subdriver qcow2 --alias testalias --iothread 3 --mode readonly --cache none --driver qemu + +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --address ide:1.2.3 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --address ide:1.2.4 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --address ide:1:2:5 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target sda --sourcetype file --type disk --address ide:1.2.3 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address ide:1.2.3 + +attach-disk --print-xml --domain testdom --source /nonexistent/file --target sda --sourcetype file --type disk --address usb:12.34 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target sda --sourcetype file --type disk --address usb:12.3 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target sda --sourcetype file --type disk --address usb:12:34 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address usb:12.34 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --address usb:12.34 + +attach-disk --print-xml --domain testdom --source /nonexistent/file --target sda --sourcetype file --type disk --address scsi:1.2.3 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target sda --sourcetype file --type disk --address scsi:1.2.4 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target sda --sourcetype file --type disk --address scsi:1:2:5 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --address scsi:1.2.3 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address scsi:1.2.3 + +attach-disk --print-xml --domain testdom --source /nonexistent/file --target sda --sourcetype file --type disk --address sata:1.2.3 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target sda --sourcetype file --type disk --address sata:1.2.4 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target sda --sourcetype file --type disk --address sata:1:2:5 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --address sata:1.2.3 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address sata:1.2.3 + +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address pci:12.34.56.78 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address pci:12:34:56:78 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address pci:12.34.56.aa +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --address pci:12.34.56.aa +attach-disk --print-xml --domain testdom --source /nonexistent/file --target sda --sourcetype file --type disk --address pci:12.34.56.aa + +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address pci:12.34.56.78 --multifunction +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address pci:12:34:56:78 --multifunction +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address pci:12.34.56.aa --multifunction + +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address ccw:12.34.56 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address ccw:12:34:56 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address ccw:12.34.56 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype file --type disk --address ccw:12.34.56 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target sda --sourcetype file --type disk --address ccw:12.34.56 + +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address test:12.34.56 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address test:12:34:56 +attach-disk --print-xml --domain testdom --source /nonexistent/file --target vda --sourcetype file --type disk --address test:12.34.56 + +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --source-protocol AAA --sourcetype file +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype network +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype network --source-protocol TEST --source-host-name hostname +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype network --source-protocol TEST --source-host-name hostname:port +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype network --source-protocol TEST --source-host-name hostname: +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype network --source-protocol TEST --source-host-name :port +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype network --source-protocol TEST --source-host-name : +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype network --source-protocol TEST --source-host-name hostname:port --source-host-transport trnsp +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype network --source-protocol TEST --source-host-transport trnsp +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype network --source-protocol TEST --source-host-transport trnsp --source-host-socket /nonexistent/socket +attach-disk --print-xml --domain testdom --source /nonexistent/file --target hda --sourcetype network --source-protocol TEST --source-host-socket /nonexistent/socket diff --git a/tests/virshtestdata/attach-disk.out b/tests/virshtestdata/attach-disk.out new file mode 100644 index 0000000000..4f7fe7d8e0 --- /dev/null +++ b/tests/virshtestdata/attach-disk.out @@ -0,0 +1,343 @@ +<disk type='file'> + <source file='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='file'> + <source file='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='block'> + <source dev='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +error: Unknown source type: 'nothing' + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='block' device='disk'> + <source dev='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='file' device='cdrom'> + <source file='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='block' device='cdrom'> + <source dev='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='file' device='blah'> + <source file='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='block' device='blah'> + <source dev='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='file' device='disk'> + <driver name='testdriver'/> + <source file='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='file' device='disk'> + <driver type='qcow2'/> + <source file='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='file' device='disk'> + <driver type='raw'/> + <source file='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='file' device='disk'> + <driver cache='none'/> + <source file='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='file' device='disk'> + <driver type='qcow2' cache='none'/> + <source file='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='file' device='disk'> + <driver type='qcow2'/> + <source file='/nonexistent/file'/> + <target dev='hda'/> + <serial>TEST_SERIAL</serial> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='hda'/> + <readonly/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='hda'/> + <shareable/> +</disk> + +error: No support for whatever in command 'attach-disk' + +<disk type='file' device='disk'> + <driver type='qcow2'/> + <source file='/nonexistent/file'/> + <target dev='hda'/> + <alias name='testalias'/> +</disk> + +<disk type='file' device='disk' rawio='yes'> + <source file='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='hda'/> +</disk> + +<disk type='file' device='disk'> + <driver name='qemu' type='qcow2' iothread='3' cache='none'/> + <source file='/nonexistent/file'/> + <target dev='hda'/> + <readonly/> + <alias name='testalias'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='hda'/> + <address type='drive' controller='1' bus='2' unit='3'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='hda'/> + <address type='drive' controller='1' bus='2' unit='4'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='hda'/> + <address type='drive' controller='1' bus='2' unit='5'/> +</disk> + +error: expecting a scsi:00.00.00 or usb:00.00 or sata:00.00.00 address. + +error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 address. + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='sda'/> + <address type='usb' bus='12' port='34'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='sda'/> + <address type='usb' bus='12' port='3'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='sda'/> + <address type='usb' bus='12' port='34'/> +</disk> + +error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 address. + +error: expecting an ide:00.00.00 address. + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='sda'/> + <address type='drive' controller='1' bus='2' unit='3'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='sda'/> + <address type='drive' controller='1' bus='2' unit='4'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='sda'/> + <address type='drive' controller='1' bus='2' unit='5'/> +</disk> + +error: expecting an ide:00.00.00 address. + +error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 address. + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='sda'/> + <address type='drive' controller='1' bus='2' unit='3'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='sda'/> + <address type='drive' controller='1' bus='2' unit='4'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='sda'/> + <address type='drive' controller='1' bus='2' unit='5'/> +</disk> + +error: expecting an ide:00.00.00 address. + +error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 address. + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='vda'/> + <address type='pci' domain='0x0012' bus='0x34' slot='0x56' function='0x78'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='vda'/> + <address type='pci' domain='0x0012' bus='0x34' slot='0x56' function='0x78'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='vda'/> + <address type='pci' domain='0x0012' bus='0x34' slot='0x56' function='0xaa'/> +</disk> + +error: expecting an ide:00.00.00 address. + +error: expecting a scsi:00.00.00 or usb:00.00 or sata:00.00.00 address. + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='vda'/> + <address type='pci' domain='0x0012' bus='0x34' slot='0x56' function='0x78' multifunction='on'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='vda'/> + <address type='pci' domain='0x0012' bus='0x34' slot='0x56' function='0x78' multifunction='on'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='vda'/> + <address type='pci' domain='0x0012' bus='0x34' slot='0x56' function='0xaa' multifunction='on'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='vda'/> + <address type='ccw' cssid='0x12' ssid='0x34' devno='0x0056'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='vda'/> + <address type='ccw' cssid='0x12' ssid='0x34' devno='0x0056'/> +</disk> + +<disk type='file' device='disk'> + <source file='/nonexistent/file'/> + <target dev='vda'/> + <address type='ccw' cssid='0x12' ssid='0x34' devno='0x0056'/> +</disk> + +error: expecting an ide:00.00.00 address. + +error: expecting a scsi:00.00.00 or usb:00.00 or sata:00.00.00 address. + +error: Invalid address. + +error: Invalid address. + +error: Invalid address. + +error: --source-protocol option requires --sourcetype network + +error: --source-protocol option requires --sourcetype network + +<disk type='network'> + <source protocol='TEST' name='/nonexistent/file'> + <host name='hostname'/> + </source> + <target dev='hda'/> +</disk> + +<disk type='network'> + <source protocol='TEST' name='/nonexistent/file'> + <host name='hostname' port='port'/> + </source> + <target dev='hda'/> +</disk> + +<disk type='network'> + <source protocol='TEST' name='/nonexistent/file'> + <host name='hostname' port=''/> + </source> + <target dev='hda'/> +</disk> + +<disk type='network'> + <source protocol='TEST' name='/nonexistent/file'> + <host name='' port='port'/> + </source> + <target dev='hda'/> +</disk> + +<disk type='network'> + <source protocol='TEST' name='/nonexistent/file'> + <host name='' port=''/> + </source> + <target dev='hda'/> +</disk> + +<disk type='network'> + <source protocol='TEST' name='/nonexistent/file'> + <host transport='trnsp' name='hostname' port='port'/> + </source> + <target dev='hda'/> +</disk> + +<disk type='network'> + <source protocol='TEST' name='/nonexistent/file'> + <host transport='trnsp'/> + </source> + <target dev='hda'/> +</disk> + +<disk type='network'> + <source protocol='TEST' name='/nonexistent/file'> + <host transport='trnsp' socket='/nonexistent/socket'/> + </source> + <target dev='hda'/> +</disk> + +error: Option --source-host-transport is required by option --source-host-socket + + +## Exit code: 1 -- 2.44.0

Rather than using 'virsh define' for the tests use the XML (or idea what the XML is testing) and use them as 'qemuxmlconftest' cases. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 2 - .../console-compat-crash.x86_64-latest.args | 46 +++++++++++++ .../console-compat-crash.x86_64-latest.xml | 65 +++++++++++++++++++ .../console-compat-crash.xml} | 36 +--------- .../cpuset-invalid.x86_64-latest.err | 1 + tests/qemuxmlconfdata/cpuset-invalid.xml | 12 ++++ tests/qemuxmlconftest.c | 2 + tests/virsh-cpuset | 46 ------------- 8 files changed, 129 insertions(+), 81 deletions(-) create mode 100644 tests/qemuxmlconfdata/console-compat-crash.x86_64-latest.args create mode 100644 tests/qemuxmlconfdata/console-compat-crash.x86_64-latest.xml rename tests/{virsh-define-dev-segfault => qemuxmlconfdata/console-compat-crash.xml} (59%) mode change 100755 => 100644 create mode 100644 tests/qemuxmlconfdata/cpuset-invalid.x86_64-latest.err create mode 100644 tests/qemuxmlconfdata/cpuset-invalid.xml delete mode 100755 tests/virsh-cpuset diff --git a/tests/meson.build b/tests/meson.build index b70fe7732e..35e8bd53bb 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -692,8 +692,6 @@ if conf.has('WITH_LIBVIRTD') 'libvirtd-pool', 'virsh-auth', 'virsh-checkpoint', - 'virsh-cpuset', - 'virsh-define-dev-segfault', 'virsh-int-overflow', 'virsh-read-bufsiz', 'virsh-read-non-seekable', diff --git a/tests/qemuxmlconfdata/console-compat-crash.x86_64-latest.args b/tests/qemuxmlconfdata/console-compat-crash.x86_64-latest.args new file mode 100644 index 0000000000..3738d252a4 --- /dev/null +++ b/tests/qemuxmlconfdata/console-compat-crash.x86_64-latest.args @@ -0,0 +1,46 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/var/lib/libvirt/qemu/domain--1-D \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/var/lib/libvirt/qemu/domain--1-D/.local/share \ +XDG_CACHE_HOME=/var/lib/libvirt/qemu/domain--1-D/.cache \ +XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-D/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=D,debug-threads=on \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain--1-D/master-key.aes"}' \ +-machine pc,usb=off,dump-guest-core=off,memory-backend=pc.ram,pcspk-audiodev=audio1,acpi=on \ +-accel kvm \ +-cpu qemu64 \ +-m size=262144k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":268435456}' \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid aaa3ae22-fed2-bfbd-ac02-3bea3bcfad82 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-boot strict=on \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \ +-chardev pty,id=charserial0 \ +-device '{"driver":"isa-serial","chardev":"charserial0","id":"serial0","index":0}' \ +-chardev pty,id=charserial1 \ +-device '{"driver":"isa-serial","chardev":"charserial1","id":"serial1","index":1}' \ +-chardev pty,id=charserial2 \ +-device '{"driver":"isa-serial","chardev":"charserial2","id":"serial2","index":2}' \ +-chardev pty,id=charparallel0 \ +-device '{"driver":"isa-parallel","chardev":"charparallel0","id":"parallel0"}' \ +-chardev pty,id=charparallel1 \ +-device '{"driver":"isa-parallel","chardev":"charparallel1","id":"parallel1"}' \ +-chardev pty,id=charparallel2 \ +-device '{"driver":"isa-parallel","chardev":"charparallel2","id":"parallel2"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-device '{"driver":"ES1370","id":"sound1","audiodev":"audio1","bus":"pci.0","addr":"0x2"}' \ +-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x3"}' \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxmlconfdata/console-compat-crash.x86_64-latest.xml b/tests/qemuxmlconfdata/console-compat-crash.x86_64-latest.xml new file mode 100644 index 0000000000..106d97b62f --- /dev/null +++ b/tests/qemuxmlconfdata/console-compat-crash.x86_64-latest.xml @@ -0,0 +1,65 @@ +<domain type='kvm'> + <name>D</name> + <uuid>aaa3ae22-fed2-bfbd-ac02-3bea3bcfad82</uuid> + <memory unit='KiB'>262144</memory> + <currentMemory unit='KiB'>262144</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='cdrom'/> + </os> + <features> + <acpi/> + </features> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <serial type='pty'> + <target type='isa-serial' port='0'> + <model name='isa-serial'/> + </target> + </serial> + <serial type='pty'> + <target type='isa-serial' port='1'> + <model name='isa-serial'/> + </target> + </serial> + <serial type='pty'> + <target type='isa-serial' port='2'> + <model name='isa-serial'/> + </target> + </serial> + <parallel type='pty'> + <target port='0'/> + </parallel> + <parallel type='pty'> + <target port='1'/> + </parallel> + <parallel type='pty'> + <target port='2'/> + </parallel> + <console type='pty'> + <target type='serial' port='0'/> + </console> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <sound model='pcspk'/> + <sound model='es1370'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </sound> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/virsh-define-dev-segfault b/tests/qemuxmlconfdata/console-compat-crash.xml old mode 100755 new mode 100644 similarity index 59% rename from tests/virsh-define-dev-segfault rename to tests/qemuxmlconfdata/console-compat-crash.xml index cc5b461932..d8795c580e --- a/tests/virsh-define-dev-segfault +++ b/tests/qemuxmlconfdata/console-compat-crash.xml @@ -1,26 +1,11 @@ -#!/bin/sh -# Exercise a bug whereby defining a valid domain could kill libvirtd. -# The bug can also be exercised with a simple define/dumpxml pair to virsh. - -. "$(dirname $0)/test-lib.sh" - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -fail=0 - -# Domain definition from Cole Robinson. -cat <<\EOF > D.xml || fail=1 -<domain type='test'> +<domain type='kvm'> <name>D</name> <uuid>aaa3ae22-fed2-bfbd-ac02-3bea3bcfad82</uuid> <memory unit='KiB'>262144</memory> <currentMemory unit='KiB'>262144</currentMemory> <vcpu placement='static'>1</vcpu> <os> - <type arch='i686' machine='pc'>hvm</type> + <type arch='x86_64' machine='pc'>hvm</type> <boot dev='cdrom'/> </os> <features> @@ -31,7 +16,7 @@ cat <<\EOF > D.xml || fail=1 <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> - <emulator>/usr/bin/qemu-system-i386</emulator> + <emulator>/usr/bin/qemu-system-x86_64</emulator> <controller type='usb' index='0'/> <serial type='pty'> <target port='0'/> @@ -59,18 +44,3 @@ cat <<\EOF > D.xml || fail=1 <memballoon model='virtio'/> </devices> </domain> -EOF - -url=test:///default -$abs_top_builddir/tools/virsh --connect "$url" 'define D.xml; dumpxml D' > out 2>&1 || fail=1 - -cat > exp <<EOF || fail=1 -Domain 'D' defined from D.xml - -$(cat D.xml) - -EOF - -compare exp out || fail=1 - -exit $fail diff --git a/tests/qemuxmlconfdata/cpuset-invalid.x86_64-latest.err b/tests/qemuxmlconfdata/cpuset-invalid.x86_64-latest.err new file mode 100644 index 0000000000..be11724ab1 --- /dev/null +++ b/tests/qemuxmlconfdata/cpuset-invalid.x86_64-latest.err @@ -0,0 +1 @@ +invalid argument: Failed to parse bitmap 'aaa' diff --git a/tests/qemuxmlconfdata/cpuset-invalid.xml b/tests/qemuxmlconfdata/cpuset-invalid.xml new file mode 100644 index 0000000000..89a6540fb9 --- /dev/null +++ b/tests/qemuxmlconfdata/cpuset-invalid.xml @@ -0,0 +1,12 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <vcpu cpuset='aaa'>2</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + </os> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + </devices> +</domain> diff --git a/tests/qemuxmlconftest.c b/tests/qemuxmlconftest.c index 9e2c7da15a..42530555f3 100644 --- a/tests/qemuxmlconftest.c +++ b/tests/qemuxmlconftest.c @@ -1799,6 +1799,7 @@ mymain(void) DO_TEST_CAPS_LATEST("console-compat"); DO_TEST_CAPS_LATEST("console-compat-auto"); + DO_TEST_CAPS_LATEST("console-compat-crash"); DO_TEST_CAPS_LATEST("serial-vc-chardev"); DO_TEST_CAPS_LATEST("serial-pty-chardev"); @@ -2287,6 +2288,7 @@ mymain(void) DO_TEST_CAPS_LATEST("cputune-numatune"); DO_TEST_CAPS_LATEST("vcpu-placement-static"); DO_TEST_CAPS_LATEST("cputune-cpuset-big-id"); + DO_TEST_CAPS_LATEST_PARSE_ERROR("cpuset-invalid"); DO_TEST_CAPS_LATEST_PARSE_ERROR("numatune-memory-invalid-nodeset"); DO_TEST_CAPS_VER("numatune-memnode", "5.2.0"); diff --git a/tests/virsh-cpuset b/tests/virsh-cpuset deleted file mode 100755 index 66163013c2..0000000000 --- a/tests/virsh-cpuset +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh -# ensure that defining with an invalid vCPU cpuset elicits a diagnostic - -# Copyright (C) 2008-2009 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# <http://www.gnu.org/licenses/>. - -. "$(dirname $0)/test-lib.sh" - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -fail=0 - -# generate input -$abs_top_builddir/tools/virsh --connect test:///default dumpxml 1 > xml || fail=1 - -# require the presence of the string we'll transform -grep '<vcpu placement' xml > /dev/null || fail=1 - -sed "s/vcpu placement='static'>/vcpu cpuset='aaa'>/" xml > xml-invalid || fail=1 - -# Require failure and a diagnostic. -$abs_top_builddir/tools/virsh --connect test:///default define xml-invalid > out 2>&1 && fail=1 -cat <<\EOF > exp || fail=1 -error: Failed to define domain from xml-invalid -error: invalid argument: Failed to parse bitmap 'aaa' - -EOF -compare exp out || fail=1 - -(exit $fail); exit $fail -- 2.44.0

As all cases are negative we can test them all in one virsh run. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 1 - tests/virsh-vcpupin | 100 -------------------------------- tests/virshtest.c | 1 + tests/virshtestdata/vcpupin.in | 23 ++++++++ tests/virshtestdata/vcpupin.out | 26 +++++++++ 5 files changed, 50 insertions(+), 101 deletions(-) delete mode 100755 tests/virsh-vcpupin create mode 100755 tests/virshtestdata/vcpupin.in create mode 100644 tests/virshtestdata/vcpupin.out diff --git a/tests/meson.build b/tests/meson.build index 35e8bd53bb..687611a50e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -701,7 +701,6 @@ if conf.has('WITH_LIBVIRTD') 'virsh-start', 'virsh-undefine', 'virsh-uriprecedence', - 'virsh-vcpupin', 'virt-admin-self-test', ] diff --git a/tests/virsh-vcpupin b/tests/virsh-vcpupin deleted file mode 100755 index 306552a8f4..0000000000 --- a/tests/virsh-vcpupin +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/sh -# ensure that an invalid CPU spec elicits a diagnostic - -# Copyright (C) 2008 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# <http://www.gnu.org/licenses/>. - -. "$(dirname $0)/test-lib.sh" - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -fail=0 - -# Invalid syntax. -$abs_top_builddir/tools/virsh --connect test:///default vcpupin test a 0,1 > out 2>&1 -test $? = 1 || fail=1 -cat <<\EOF > exp || fail=1 -error: Numeric value 'a' for <vcpu> option is malformed or out of range - -EOF -compare exp out || fail=1 - -# An out-of-range vCPU number deserves a diagnostic, too. -$abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 0,1 > out 2>&1 -test $? = 1 || fail=1 -cat <<\EOF > exp || fail=1 -error: invalid argument: requested vcpu '100' is not present in the domain - -EOF -compare exp out || fail=1 - -# Negative number -$abs_top_builddir/tools/virsh --connect test:///default vcpupin test -100 0,1 > out 2>&1 -test $? = 1 || fail=1 -cat <<\EOF > exp || fail=1 -error: Numeric value '-100' for <vcpu> option is malformed or out of range - -EOF -compare exp out || fail=1 - -# missing argument -$abs_top_builddir/tools/virsh --connect test:///default vcpupin test --cpulist 0,1 > out 2>&1 -test $? = 1 || fail=1 -cat <<\EOF > exp || fail=1 -error: vcpupin: Missing vCPU number in pin mode. - -EOF -compare exp out || fail=1 - -# An out-of-range vCPU number when get information with live flag -$abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 --live > out 2>&1 -test $? = 1 || fail=1 -cat <<\EOF > exp || fail=1 -error: vcpu 100 is out of range of live cpu count 2 - -EOF -compare exp out || fail=1 - -# An out-of-range vCPU number when get information without flag -$abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 > out 2>&1 -test $? = 1 || fail=1 -cat <<\EOF > exp || fail=1 -error: vcpu 100 is out of range of live cpu count 2 - -EOF -compare exp out || fail=1 - -# An out-of-range vCPU number when get information with config flag -$abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 --config > out 2>&1 -test $? = 1 || fail=1 -cat <<\EOF > exp || fail=1 -error: vcpu 100 is out of range of persistent cpu count 2 - -EOF -compare exp out || fail=1 - -# An out-of-range vCPU number when get information with current flag -$abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 --current > out 2>&1 -test $? = 1 || fail=1 -cat <<\EOF > exp || fail=1 -error: vcpu 100 is out of range of live cpu count 2 - -EOF -compare exp out || fail=1 -(exit $fail); exit $fail diff --git a/tests/virshtest.c b/tests/virshtest.c index 78f6148733..dd45cea405 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -213,6 +213,7 @@ mymain(void) * thus is marked expensive */ DO_TEST_SCRIPT_FULL("numeric-parsing-event", true, NULL, VIRSH_DEFAULT, "-q"); DO_TEST_SCRIPT("attach-disk", NULL, VIRSH_DEFAULT); + DO_TEST_SCRIPT("vcpupin", NULL, VIRSH_DEFAULT); VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/virshtestdata/vcpupin.in b/tests/virshtestdata/vcpupin.in new file mode 100755 index 0000000000..42e0e7f529 --- /dev/null +++ b/tests/virshtestdata/vcpupin.in @@ -0,0 +1,23 @@ +echo Invalid syntax. +vcpupin test a 0,1 + +echo An out-of-range vCPU number deserves a diagnostic, too. +vcpupin test 100 0,1 + +echo Negative number +vcpupin test -100 0,1 + +echo missing argument +vcpupin test --cpulist 0,1 + +echo An out-of-range vCPU number when get information with live flag +vcpupin test 100 --live + +echo An out-of-range vCPU number when get information without flag +vcpupin test 100 + +echo An out-of-range vCPU number when get information with config flag +vcpupin test 100 --config + +echo An out-of-range vCPU number when get information with current flag +vcpupin test 100 --current diff --git a/tests/virshtestdata/vcpupin.out b/tests/virshtestdata/vcpupin.out new file mode 100644 index 0000000000..92fc14a697 --- /dev/null +++ b/tests/virshtestdata/vcpupin.out @@ -0,0 +1,26 @@ +Invalid syntax. +error: Numeric value 'a' for <vcpu> option is malformed or out of range + +An out-of-range vCPU number deserves a diagnostic, too. +error: invalid argument: requested vcpu '100' is not present in the domain + +Negative number +error: Numeric value '-100' for <vcpu> option is malformed or out of range + +missing argument +error: vcpupin: Missing vCPU number in pin mode. + +An out-of-range vCPU number when get information with live flag +error: vcpu 100 is out of range of live cpu count 2 + +An out-of-range vCPU number when get information without flag +error: vcpu 100 is out of range of live cpu count 2 + +An out-of-range vCPU number when get information with config flag +error: vcpu 100 is out of range of persistent cpu count 2 + +An out-of-range vCPU number when get information with current flag +error: vcpu 100 is out of range of live cpu count 2 + + +## Exit code: 1 -- 2.44.0

It's a simple test case invoking one virsh command thus it can be moved to 'virshtest' Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 1 - tests/virsh-int-overflow | 18 ------------------ tests/virshtest.c | 2 ++ tests/virshtestdata/domain-id-overflow.out | 3 +++ 4 files changed, 5 insertions(+), 19 deletions(-) delete mode 100755 tests/virsh-int-overflow create mode 100644 tests/virshtestdata/domain-id-overflow.out diff --git a/tests/meson.build b/tests/meson.build index 687611a50e..cd473d4ad6 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -692,7 +692,6 @@ if conf.has('WITH_LIBVIRTD') 'libvirtd-pool', 'virsh-auth', 'virsh-checkpoint', - 'virsh-int-overflow', 'virsh-read-bufsiz', 'virsh-read-non-seekable', 'virsh-schedinfo', diff --git a/tests/virsh-int-overflow b/tests/virsh-int-overflow deleted file mode 100755 index e9eb03bfbb..0000000000 --- a/tests/virsh-int-overflow +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh -# Ensure that an invalid domain ID isn't interpreted as a valid one. -# Before, an ID of 2^32+2 would be treated just like an ID of 2. - -. "$(dirname $0)/test-lib.sh" - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -echo "error: failed to get domain '4294967298'" > exp || fail=1 -$abs_top_builddir/tools/virsh --quiet \ - --connect test://$abs_top_srcdir/examples/xml/test/testnode.xml \ - 'domname 4294967298; quit' > /dev/null 2> err || fail=1 -diff -u err exp || fail=1 - -exit $fail diff --git a/tests/virshtest.c b/tests/virshtest.c index dd45cea405..a09ab8c78b 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -215,6 +215,8 @@ mymain(void) DO_TEST_SCRIPT("attach-disk", NULL, VIRSH_DEFAULT); DO_TEST_SCRIPT("vcpupin", NULL, VIRSH_DEFAULT); + DO_TEST_FULL("domain-id-overflow", NULL, VIRSH_CUSTOM, "-q", "domname", "4294967298"); + VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/virshtestdata/domain-id-overflow.out b/tests/virshtestdata/domain-id-overflow.out new file mode 100644 index 0000000000..406d8e353c --- /dev/null +++ b/tests/virshtestdata/domain-id-overflow.out @@ -0,0 +1,3 @@ +error: failed to get domain '4294967298' + +## Exit code: 1 -- 2.44.0

It's a simple virsh invocation which can be done in 'virshtest' Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 1 - tests/virsh-schedinfo | 40 ------------------- tests/virshtest.c | 2 +- .../schedinfo-invalid-argument.out | 5 +++ 4 files changed, 6 insertions(+), 42 deletions(-) delete mode 100755 tests/virsh-schedinfo create mode 100644 tests/virshtestdata/schedinfo-invalid-argument.out diff --git a/tests/meson.build b/tests/meson.build index cd473d4ad6..8392778a76 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -694,7 +694,6 @@ if conf.has('WITH_LIBVIRTD') 'virsh-checkpoint', 'virsh-read-bufsiz', 'virsh-read-non-seekable', - 'virsh-schedinfo', 'virsh-self-test', 'virsh-snapshot', 'virsh-start', diff --git a/tests/virsh-schedinfo b/tests/virsh-schedinfo deleted file mode 100755 index e4e2509f76..0000000000 --- a/tests/virsh-schedinfo +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -# Ensure that virsh schedinfo --set invalid=val fails - -# Copyright (C) 2010-2011, 2013 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# <http://www.gnu.org/licenses/>. - -. "$(dirname $0)/test-lib.sh" - -VIRSH=$abs_top_builddir/tools/virsh - -if test "$VERBOSE" = yes; then - set -x - $VIRSH --version -fi - -printf 'Scheduler : fair\n\n' > exp-out || framework_failure -printf 'error: invalid scheduler option: j\n' > exp-err || framework_failure - -fail=0 - -test_url=test:///default - -$VIRSH -c $test_url schedinfo 1 --set j=k >out 2>err && fail=1 -compare exp-out out || fail=1 -compare exp-err err || fail=1 - -(exit $fail); exit $fail diff --git a/tests/virshtest.c b/tests/virshtest.c index a09ab8c78b..f4c41fca46 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -203,7 +203,6 @@ mymain(void) /* test of splitting in vshStringToArray */ DO_TEST_SCRIPT("echo-split", NULL, VIRSH_DEFAULT, "-q"); -# undef DO_TEST /* comprehensive coverage of argument assignment */ DO_TEST_SCRIPT("argument-assignment", NULL, VIRSH_DEFAULT, "-k0", "-d0"); @@ -216,6 +215,7 @@ mymain(void) DO_TEST_SCRIPT("vcpupin", NULL, VIRSH_DEFAULT); DO_TEST_FULL("domain-id-overflow", NULL, VIRSH_CUSTOM, "-q", "domname", "4294967298"); + DO_TEST_FULL("schedinfo-invalid-argument", NULL, VIRSH_DEFAULT, "schedinfo", "1", "--set", "j=k"); VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/virshtestdata/schedinfo-invalid-argument.out b/tests/virshtestdata/schedinfo-invalid-argument.out new file mode 100644 index 0000000000..833c6dfd6a --- /dev/null +++ b/tests/virshtestdata/schedinfo-invalid-argument.out @@ -0,0 +1,5 @@ +Scheduler : fair +error: invalid scheduler option: j + + +## Exit code: 1 -- 2.44.0

The 'virsh-start' case simply tried to start an already running VM. This can be easily tested together with the tests for undefining a VM. For this test the test driver config with multiple VMs comes handy as we need to test 3 situations when we undefine and stop the VM. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 2 - tests/virsh-start | 41 ------------ tests/virsh-undefine | 76 --------------------- tests/virshtest.c | 1 + tests/virshtestdata/lifecycle.in | 23 +++++++ tests/virshtestdata/lifecycle.out | 106 ++++++++++++++++++++++++++++++ 6 files changed, 130 insertions(+), 119 deletions(-) delete mode 100755 tests/virsh-start delete mode 100755 tests/virsh-undefine create mode 100644 tests/virshtestdata/lifecycle.in create mode 100644 tests/virshtestdata/lifecycle.out diff --git a/tests/meson.build b/tests/meson.build index 8392778a76..5a2a499461 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -696,8 +696,6 @@ if conf.has('WITH_LIBVIRTD') 'virsh-read-non-seekable', 'virsh-self-test', 'virsh-snapshot', - 'virsh-start', - 'virsh-undefine', 'virsh-uriprecedence', 'virt-admin-self-test', ] diff --git a/tests/virsh-start b/tests/virsh-start deleted file mode 100755 index cb58c3b09c..0000000000 --- a/tests/virsh-start +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh -# ensure that virsh start works properly - -# Copyright (C) 2008 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# <http://www.gnu.org/licenses/>. - -. "$(dirname $0)/test-lib.sh" - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -fail=0 - -test_url=test:///default - -# expect this to fail -$abs_top_builddir/tools/virsh -c $test_url start test > out 2> err && fail=1 - -# stdout gets a newline -echo > exp || fail=1 -compare exp out || fail=1 - -echo 'error: Domain is already active' > exp || fail=1 -compare exp err || fail=1 - -(exit $fail); exit $fail diff --git a/tests/virsh-undefine b/tests/virsh-undefine deleted file mode 100755 index dbbb367391..0000000000 --- a/tests/virsh-undefine +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh -# exercise virsh's "undefine" command - -# Copyright (C) 2008-2009, 2011 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# <http://www.gnu.org/licenses/>. - -. "$(dirname $0)/test-lib.sh" - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -fail=0 - -# Attempt to undefine a running domain, by domain name. Every time a new -# connection is opened to the test driver, it starts life with a new -# persistent running domain named 'test' with a different uuid, so -# testing this command requires batch mode use of virsh. -$abs_top_builddir/tools/virsh -c test:///default \ - 'dominfo test; undefine test; dominfo test' > out1 2>&1 -test $? = 0 || fail=1 -sed '/^Persistent/n; /:/d' < out1 > out -cat <<\EOF > exp || fail=1 -Persistent: yes - -Domain 'test' has been undefined - -Persistent: no - -EOF -compare exp out || fail=1 - -# A similar diagnostic when specifying a domain ID -$abs_top_builddir/tools/virsh -c test:///default \ - 'dominfo 1; undefine 1; dominfo 1' > out1 2>&1 -test $? = 0 || fail=1 -sed '/^Persistent/n; /:/d' < out1 > out -cat <<\EOF > exp || fail=1 -Persistent: yes - -Domain '1' has been undefined - -Persistent: no - -EOF -compare exp out || fail=1 - -# Succeed, now: first shut down, then undefine, both via name. -$abs_top_builddir/tools/virsh -c test:///default \ - 'shutdown test; undefine test; dominfo test' > out 2>&1 -test $? = 1 || fail=1 -cat <<\EOF > expout || fail=1 -Domain 'test' is being shutdown - -Domain 'test' has been undefined - -error: failed to get domain 'test' - -EOF -compare expout out || fail=1 - -(exit $fail); exit $fail diff --git a/tests/virshtest.c b/tests/virshtest.c index f4c41fca46..9cad18cf58 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -213,6 +213,7 @@ mymain(void) DO_TEST_SCRIPT_FULL("numeric-parsing-event", true, NULL, VIRSH_DEFAULT, "-q"); DO_TEST_SCRIPT("attach-disk", NULL, VIRSH_DEFAULT); DO_TEST_SCRIPT("vcpupin", NULL, VIRSH_DEFAULT); + DO_TEST_SCRIPT("lifecycle", "\nCPU time:", VIRSH_CUSTOM); DO_TEST_FULL("domain-id-overflow", NULL, VIRSH_CUSTOM, "-q", "domname", "4294967298"); DO_TEST_FULL("schedinfo-invalid-argument", NULL, VIRSH_DEFAULT, "schedinfo", "1", "--set", "j=k"); diff --git a/tests/virshtestdata/lifecycle.in b/tests/virshtestdata/lifecycle.in new file mode 100644 index 0000000000..e585ad08e1 --- /dev/null +++ b/tests/virshtestdata/lifecycle.in @@ -0,0 +1,23 @@ +list --all + +echo test failure when starting already running guest +start fv0 + +echo undefine a running domain - by domain name +dominfo fc4 +undefine fc4 +dominfo fc4 +shutdown fc4 +dominfo fc4 + +echo undefine a running domain - by domain id +dominfo 3 +undefine 3 +dominfo 3 +shutdown 3 +dominfo fc5 + +echo shutdown then undefine +shutdown fv0 +undefine fv0 +dominfo fv0 diff --git a/tests/virshtestdata/lifecycle.out b/tests/virshtestdata/lifecycle.out new file mode 100644 index 0000000000..1d87cb44f6 --- /dev/null +++ b/tests/virshtestdata/lifecycle.out @@ -0,0 +1,106 @@ + Id Name State +---------------------- + 1 fv0 running + 2 fc4 running + 3 fc5 running + +test failure when starting already running guest +error: Domain is already active + +undefine a running domain - by domain name +Id: 2 +Name: fc4 +UUID: ef861801-45b9-11cb-88e3-afbfe5370493 +OS Type: linux +State: running +CPU(s): 1 +Max memory: 261072 KiB +Used memory: 131072 KiB +Persistent: yes +Autostart: disable +Managed save: no +Security model: testSecurity +Security DOI: +Security label: libvirt-test (enforcing) +Messages: tainted: network configuration using opaque shell scripts + +Domain 'fc4' has been undefined + +Id: 2 +Name: fc4 +UUID: ef861801-45b9-11cb-88e3-afbfe5370493 +OS Type: linux +State: running +CPU(s): 1 +Max memory: 261072 KiB +Used memory: 131072 KiB +Persistent: no +Autostart: disable +Managed save: no +Security model: testSecurity +Security DOI: +Security label: libvirt-test (enforcing) +Messages: tainted: network configuration using opaque shell scripts + +Domain 'fc4' is being shutdown + +error: failed to get domain 'fc4' + +undefine a running domain - by domain id +Id: 3 +Name: fc5 +UUID: 08721f99-3d1d-4aec-96eb-97803297bb36 +OS Type: linux +State: running +CPU(s): 4 +Max memory: 2097152 KiB +Used memory: 2097152 KiB +Persistent: yes +Autostart: disable +Managed save: no +Security model: testSecurity +Security DOI: +Security label: libvirt-test (enforcing) +Messages: tainted: running with undesirable elevated privileges + tainted: network configuration using opaque shell scripts + tainted: use of host cdrom passthrough + tainted: custom device tree blob used + tainted: use of deprecated configuration settings + deprecated configuration: CPU model Deprecated-Test + +Domain '3' has been undefined + +Id: 3 +Name: fc5 +UUID: 08721f99-3d1d-4aec-96eb-97803297bb36 +OS Type: linux +State: running +CPU(s): 4 +Max memory: 2097152 KiB +Used memory: 2097152 KiB +Persistent: no +Autostart: disable +Managed save: no +Security model: testSecurity +Security DOI: +Security label: libvirt-test (enforcing) +Messages: tainted: running with undesirable elevated privileges + tainted: network configuration using opaque shell scripts + tainted: use of host cdrom passthrough + tainted: custom device tree blob used + tainted: use of deprecated configuration settings + deprecated configuration: CPU model Deprecated-Test + +Domain '3' is being shutdown + +error: failed to get domain 'fc5' + +shutdown then undefine +Domain 'fv0' is being shutdown + +Domain 'fv0' has been undefined + +error: failed to get domain 'fv0' + + +## Exit code: 1 -- 2.44.0

Until now when '--name' was used the parent was not printed and the option was ignored. One option would be to declare the options mutually exclusive, but for testing it may come handy to print both the snapshot name and parent. Adjust the code to print them tab-separated and adjust the docs. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- docs/manpages/virsh.rst | 15 ++++++++++----- tools/virsh-checkpoint.c | 18 ++++++++++++------ tools/virsh-snapshot.c | 18 ++++++++++++------ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 115b802c45..5cf510b6e9 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -7673,9 +7673,11 @@ If *--parent* is specified, add a column to the output table giving the name of the parent of each snapshot. If *--roots* is specified, the list will be filtered to just snapshots that have no parents. If *--tree* is specified, the output will be in a tree format, listing -just snapshot names. These three options are mutually exclusive. If -*--name* is specified only the snapshot name is printed. This option is -mutually exclusive with *--tree*. +just snapshot names. These three options are mutually exclusive. + +If *--name* is specified only the snapshot name is printed optionally +followed by a tab-separated name of the parent snapshot if *--parent* is used +as well. This option is mutually exclusive with *--tree*. If *--from* is provided, filter the list to snapshots which are children of the given ``snapshot``; or if *--current* is provided, @@ -7989,8 +7991,11 @@ the name of the parent of each checkpoint. If *--roots* is specified, the list will be filtered to just checkpoints that have no parents. If *--tree* is specified, the output will be in a tree format, listing just checkpoint names. These three options are -mutually exclusive. If *--name* is specified only the checkpoint name -is printed. This option is mutually exclusive with *--tree*. +mutually exclusive. + +If *--name* is specified only the checkpoint name is printed optionally +followed by a tab-separated name of the parent checkpoint if *--parent* is used +as well. This option is mutually exclusive with *--tree*. If *--from* is provided, filter the list to checkpoints which are children of the given ``checkpoint``. When used in isolation or with diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c index 869c071700..ebad2907e5 100644 --- a/tools/virsh-checkpoint.c +++ b/tools/virsh-checkpoint.c @@ -753,12 +753,6 @@ cmdCheckpointList(vshControl *ctl, chk_name = virDomainCheckpointGetName(checkpoint); assert(chk_name); - if (name) { - /* just print the checkpoint name */ - vshPrint(ctl, "%s\n", chk_name); - continue; - } - if (!(doc = virDomainCheckpointGetXMLDesc(checkpoint, 0))) continue; @@ -769,6 +763,18 @@ cmdCheckpointList(vshControl *ctl, parent_chk = virXPathString("string(/domaincheckpoint/parent/name)", ctxt); + if (name) { + vshPrint(ctl, "%s", chk_name); + + if (parent_chk) + vshPrint(ctl, "\t%s", parent_chk); + + vshPrint(ctl, "\n"); + + /* just print the checkpoint name */ + continue; + } + if (virXPathLongLong("string(/domaincheckpoint/creationTime)", ctxt, &creation_longlong) < 0) continue; diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 899bae7e9a..7b22962efb 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -1509,12 +1509,6 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) snap_name = virDomainSnapshotGetName(snapshot); assert(snap_name); - if (name) { - /* just print the snapshot name */ - vshPrint(ctl, "%s\n", snap_name); - continue; - } - if (!(doc = virDomainSnapshotGetXMLDesc(snapshot, 0))) continue; @@ -1525,6 +1519,18 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) parent_snap = virXPathString("string(/domainsnapshot/parent/name)", ctxt); + if (name) { + vshPrint(ctl, "%s", snap_name); + + if (parent_snap) + vshPrint(ctl, "\t%s", parent_snap); + + vshPrint(ctl, "\n"); + + /* just print the snapshot name */ + continue; + } + if (!(state = virXPathString("string(/domainsnapshot/state)", ctxt))) continue; -- 2.44.0

For testing purposes it will come handy to change the directory from a batch-mode script. Remove the check forbidding use of the 'cd' command in batch mode. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- docs/manpages/virsh.rst | 2 -- tools/vsh.c | 5 ----- 2 files changed, 7 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 5cf510b6e9..a20a487d60 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -326,8 +326,6 @@ Will change current directory to *directory*. The default directory for the ``cd`` command is the home directory or, if there is no *HOME* variable in the environment, the root directory. -This command is only available in interactive mode. - pwd --- diff --git a/tools/vsh.c b/tools/vsh.c index f96071060a..de71b4af40 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3171,11 +3171,6 @@ cmdCd(vshControl *ctl, const vshCmd *cmd) const char *dir = NULL; g_autofree char *dir_malloced = NULL; - if (!ctl->imode) { - vshError(ctl, "%s", _("cd: command valid only in interactive mode")); - return false; - } - if (vshCommandOptStringQuiet(ctl, cmd, "dir", &dir) <= 0) dir = dir_malloced = virGetUserDirectory(); if (!dir) -- 2.44.0

Invoke the majority of the command via DO_TEST_SCRIPT in 'virshtest'. Some adaptation was needed to avoid printing of tables with volatile data such as snapshot creation time, which were converted to list names-only. To proprely test redefinition we store XMLs rather than taking them from the defined snapshots and use them separately to test redefinition of snapshot XMLs. This makes use of the 'cd' command in non-interactive mode. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 1 - tests/virsh-snapshot | 233 ---------------------- tests/virshtest.c | 10 + tests/virshtestdata/snapshot-redefine.out | 17 ++ tests/virshtestdata/snapshot-s2.xml | 43 ++++ tests/virshtestdata/snapshot-s3.xml | 40 ++++ tests/virshtestdata/snapshot.in | 54 +++++ tests/virshtestdata/snapshot.out | 173 ++++++++++++++++ 8 files changed, 337 insertions(+), 234 deletions(-) delete mode 100755 tests/virsh-snapshot create mode 100644 tests/virshtestdata/snapshot-redefine.out create mode 100644 tests/virshtestdata/snapshot-s2.xml create mode 100644 tests/virshtestdata/snapshot-s3.xml create mode 100755 tests/virshtestdata/snapshot.in create mode 100644 tests/virshtestdata/snapshot.out diff --git a/tests/meson.build b/tests/meson.build index 5a2a499461..efbe99f55e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -695,7 +695,6 @@ if conf.has('WITH_LIBVIRTD') 'virsh-read-bufsiz', 'virsh-read-non-seekable', 'virsh-self-test', - 'virsh-snapshot', 'virsh-uriprecedence', 'virt-admin-self-test', ] diff --git a/tests/virsh-snapshot b/tests/virsh-snapshot deleted file mode 100755 index b09273917b..0000000000 --- a/tests/virsh-snapshot +++ /dev/null @@ -1,233 +0,0 @@ -#!/bin/sh -# simple testing of snapshot APIs on test driver - -# Copyright (C) 2019 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# <http://www.gnu.org/licenses/>. - -. "$(dirname $0)/test-lib.sh" - -test_expensive - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -fail=0 - -mock_xdg_ || framework_failure - -# The test driver loses states between restarts, so we perform a script -# with some convenient markers for later post-processing of output. -$abs_top_builddir/tools/virsh --connect test:///default >out 2>err ' - # Create a series of snapshots, with names that intentionally sort - # differently by topology than by name. Use revert to create fanout. - snapshot-create-as test s1 - snapshot-create-as test s1 - snapshot-create-as test s3 - snapshot-create-as test s2 - snapshot-revert test s3 - snapshot-create-as test s6 - snapshot-create-as test s5 - snapshot-revert test s6 - snapshot-create-as test s4 - snapshot-revert test s1 - snapshot-create-as test s7 - snapshot-create-as test s8 - # checkpoints cannot be created while snapshots exist - echo --err marker - checkpoint-create-as test c1 - echo --err marker - # Checking tree view (siblings sorted alphabetically) - snapshot-list test --tree - # Current was last one created, but we can change that - snapshot-current test --name - snapshot-current test s1 - snapshot-current test --name - # Deleting current root leads to multiple roots, demonstrate list filtering - snapshot-delete test --current - echo --err marker - snapshot-current test --name - echo --err marker - snapshot-list test --roots - snapshot-list test --leaves - snapshot-list test --parent --no-leaves - snapshot-list test --from s3 - snapshot-list test --from s3 --descendants --name - # More fun with delete flags, current node moves up to remaining parent - snapshot-current test s4 - snapshot-delete test --children-only s6 - snapshot-current test --name - snapshot-delete test --children s7 - snapshot-current test --name - snapshot-delete test s6 - snapshot-current test --name - # Now the tree is linear, so we have an unambiguous topological order - snapshot-list test --name - snapshot-list test --name --topological - # Capture some XML for later redefine - echo "<!--MarkerA-->" - snapshot-dumpxml test s3 - echo "<!--MarkerB-->" - snapshot-dumpxml test s2 - echo "<!--MarkerC-->" - # All done -' || fail=1 - -# First part is expected output, --tree results in trailing spaces, -# and snapshot-list produces timestamps -sed 's/ *$//; s/[0-9-]\{10\} [0-9:.]* .[0-9]\{4\}/TIMESTAMP/; - /MarkerA/,/MarkerC/d' < out > out.cooked || fail=1 -# Second part holds domain snapshot XMLs -sed -n '/MarkerA/,/MarkerB/p' < out > s3.xml || fail=1 -sed -n '/MarkerB/,/MarkerC/p' < out > s2.xml || fail=1 - -cat <<\EOF > exp || fail=1 -Domain snapshot s1 created - -Domain snapshot s3 created -Domain snapshot s2 created -Domain snapshot s3 reverted - -Domain snapshot s6 created -Domain snapshot s5 created -Domain snapshot s6 reverted - -Domain snapshot s4 created -Domain snapshot s1 reverted - -Domain snapshot s7 created -Domain snapshot s8 created - - - -s1 - | - +- s3 - | | - | +- s2 - | +- s6 - | | - | +- s4 - | +- s5 - | - +- s7 - | - +- s8 - - -s8 -Snapshot s1 set as current -s1 -Domain snapshot s1 deleted - - - - - Name Creation Time State ---------------------------------------------- - s3 TIMESTAMP running - s7 TIMESTAMP running - - Name Creation Time State ---------------------------------------------- - s2 TIMESTAMP running - s4 TIMESTAMP running - s5 TIMESTAMP running - s8 TIMESTAMP running - - Name Creation Time State Parent ------------------------------------------------------- - s3 TIMESTAMP running - s6 TIMESTAMP running s3 - s7 TIMESTAMP running - - Name Creation Time State ---------------------------------------------- - s2 TIMESTAMP running - s6 TIMESTAMP running - -s2 -s4 -s5 -s6 - -Snapshot s4 set as current -Domain snapshot s6 children deleted - -s6 -Domain snapshot s7 deleted - -s6 -Domain snapshot s6 deleted - -s3 -s2 -s3 - -s3 -s2 - -EOF -compare exp out.cooked || fail=1 - -cat <<EOF > exp || fail=1 -error: operation failed: domain moment s1 already exists -error: marker -error: Operation not supported: cannot create checkpoint while snapshot exists -error: marker -error: marker -error: domain 'test' has no current snapshot -error: marker -EOF -compare exp err || fail=1 - -# Restore state with redefine -$abs_top_builddir/tools/virsh -c test:///default >out 2>err ' - # Redefine must be in topological order; this will fail - snapshot-create test --redefine s2.xml --validate - echo --err marker - # This is the right order - snapshot-create test --redefine s3.xml --validate - snapshot-create test --redefine s2.xml --current --validate - snapshot-info test --current -' || fail=1 - -cat <<\EOF > exp || fail=1 - - -Domain snapshot s3 created from 's3.xml' -Domain snapshot s2 created from 's2.xml' -Name: s2 -Domain: test -Current: yes -State: running -Location: internal -Parent: s3 -Children: 0 -Descendants: 0 -Metadata: yes - -EOF -compare exp out || fail=1 - -cat <<EOF > exp || fail=1 -error: invalid argument: parent s3 for moment s2 not found -error: marker -EOF -compare exp err || fail=1 - -(exit $fail); exit $fail diff --git a/tests/virshtest.c b/tests/virshtest.c index 9cad18cf58..83baac8c43 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -218,6 +218,16 @@ mymain(void) DO_TEST_FULL("domain-id-overflow", NULL, VIRSH_CUSTOM, "-q", "domname", "4294967298"); DO_TEST_FULL("schedinfo-invalid-argument", NULL, VIRSH_DEFAULT, "schedinfo", "1", "--set", "j=k"); + DO_TEST_SCRIPT("snapshot", "<creationTime", VIRSH_DEFAULT); + DO_TEST_FULL("snapshot-redefine", NULL, VIRSH_DEFAULT, + "cd " abs_srcdir "/virshtestdata ;" + "echo 'Redefine must be in topological order; this will fail' ;" + "snapshot-create test --redefine snapshot-s2.xml --validate ;" + "echo 'correct order' ;" + "snapshot-create test --redefine snapshot-s3.xml --validate ;" + "snapshot-create test --redefine snapshot-s2.xml --current --validate ;" + "snapshot-info test --current"); + VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/virshtestdata/snapshot-redefine.out b/tests/virshtestdata/snapshot-redefine.out new file mode 100644 index 0000000000..cc68b5cad4 --- /dev/null +++ b/tests/virshtestdata/snapshot-redefine.out @@ -0,0 +1,17 @@ + +Redefine must be in topological order; this will fail +error: invalid argument: parent s3 for moment s2 not found + +correct order +Domain snapshot s3 created from 'snapshot-s3.xml' +Domain snapshot s2 created from 'snapshot-s2.xml' +Name: s2 +Domain: test +Current: yes +State: running +Location: internal +Parent: s3 +Children: 0 +Descendants: 0 +Metadata: yes + diff --git a/tests/virshtestdata/snapshot-s2.xml b/tests/virshtestdata/snapshot-s2.xml new file mode 100644 index 0000000000..63d13dc4bb --- /dev/null +++ b/tests/virshtestdata/snapshot-s2.xml @@ -0,0 +1,43 @@ +<domainsnapshot> + <name>s2</name> + <state>running</state> + <parent> + <name>s3</name> + </parent> + <creationTime>1234</creationTime> + <memory snapshot='internal'/> + <disks> + <disk name='vda' snapshot='internal'/> + </disks> + <domain type='test'> + <name>test</name> + <uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid> + <memory unit='KiB'>8388608</memory> + <currentMemory unit='KiB'>2097152</currentMemory> + <vcpu placement='static'>2</vcpu> + <os> + <type arch='i686'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='/guest/diskimage1'/> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> + </disk> + <interface type='network'> + <mac address='aa:bb:cc:dd:ee:ff'/> + <source network='default'/> + <target dev='testnet0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> + </interface> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> + </domain> +</domainsnapshot> diff --git a/tests/virshtestdata/snapshot-s3.xml b/tests/virshtestdata/snapshot-s3.xml new file mode 100644 index 0000000000..80d65074e1 --- /dev/null +++ b/tests/virshtestdata/snapshot-s3.xml @@ -0,0 +1,40 @@ +<domainsnapshot> + <name>s3</name> + <state>running</state> + <creationTime>5678</creationTime> + <memory snapshot='internal'/> + <disks> + <disk name='vda' snapshot='internal'/> + </disks> + <domain type='test'> + <name>test</name> + <uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid> + <memory unit='KiB'>8388608</memory> + <currentMemory unit='KiB'>2097152</currentMemory> + <vcpu placement='static'>2</vcpu> + <os> + <type arch='i686'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='/guest/diskimage1'/> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> + </disk> + <interface type='network'> + <mac address='aa:bb:cc:dd:ee:ff'/> + <source network='default'/> + <target dev='testnet0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> + </interface> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> + </domain> +</domainsnapshot> diff --git a/tests/virshtestdata/snapshot.in b/tests/virshtestdata/snapshot.in new file mode 100755 index 0000000000..9e73db7ba7 --- /dev/null +++ b/tests/virshtestdata/snapshot.in @@ -0,0 +1,54 @@ +echo Create a series of snapshots, with names that intentionally sort +echo differently by topology than by name. Use revert to create fanout. +snapshot-create-as test s1 +snapshot-create-as test s1 +snapshot-create-as test s3 +snapshot-create-as test s2 +snapshot-revert test s3 +snapshot-create-as test s6 +snapshot-create-as test s5 +snapshot-revert test s6 +snapshot-create-as test s4 +snapshot-revert test s1 +snapshot-create-as test s7 +snapshot-create-as test s8 + +echo checkpoints cannot be created while snapshots exist +checkpoint-create-as test c1 + +echo Checking tree view (siblings sorted alphabetically) +snapshot-list test --tree + +echo Current was last one created, but we can change that +snapshot-current test --name +snapshot-current test s1 +snapshot-current test --name + +echo Deleting current root leads to multiple roots, demonstrate list filtering +snapshot-delete test --current +snapshot-current test --name + +echo list roots +snapshot-list test --roots --name +echo list leaves +snapshot-list test --leaves --name +echo list no-leaves +snapshot-list test --parent --no-leaves --name +echo list from +snapshot-list test --from s3 --name +snapshot-list test --from s3 --descendants --name + +echo More fun with delete flags, current node moves up to remaining parent +snapshot-current test s4 +snapshot-delete test --children-only s6 +snapshot-current test --name +snapshot-delete test --children s7 +snapshot-current test --name +snapshot-delete test s6 +snapshot-current test --name + +echo Now the tree is linear, so we have an unambiguous topological order +snapshot-list test --name +snapshot-list test --name --topological +snapshot-dumpxml test s3 +snapshot-dumpxml test s2 diff --git a/tests/virshtestdata/snapshot.out b/tests/virshtestdata/snapshot.out new file mode 100644 index 0000000000..03268415d7 --- /dev/null +++ b/tests/virshtestdata/snapshot.out @@ -0,0 +1,173 @@ +Create a series of snapshots, with names that intentionally sort +differently by topology than by name. Use revert to create fanout. +Domain snapshot s1 created +error: operation failed: domain moment s1 already exists + +Domain snapshot s3 created +Domain snapshot s2 created +Domain snapshot s3 reverted + +Domain snapshot s6 created +Domain snapshot s5 created +Domain snapshot s6 reverted + +Domain snapshot s4 created +Domain snapshot s1 reverted + +Domain snapshot s7 created +Domain snapshot s8 created +checkpoints cannot be created while snapshots exist +error: Operation not supported: cannot create checkpoint while snapshot exists + +Checking tree view (siblings sorted alphabetically) +s1 + | + +- s3 + | | + | +- s2 + | +- s6 + | | + | +- s4 + | +- s5 + | + +- s7 + | + +- s8 + + +Current was last one created, but we can change that +s8 +Snapshot s1 set as current +s1 +Deleting current root leads to multiple roots, demonstrate list filtering +Domain snapshot s1 deleted + +error: domain 'test' has no current snapshot + +list roots +s3 +s7 + +list leaves +s2 +s4 +s5 +s8 + +list no-leaves +s3 +s6 s3 +s7 + +list from +s2 +s6 + +s2 +s4 +s5 +s6 + +More fun with delete flags, current node moves up to remaining parent +Snapshot s4 set as current +Domain snapshot s6 children deleted + +s6 +Domain snapshot s7 deleted + +s6 +Domain snapshot s6 deleted + +s3 +Now the tree is linear, so we have an unambiguous topological order +s2 +s3 + +s3 +s2 + +<domainsnapshot> + <name>s3</name> + <state>running</state> + + <memory snapshot='internal'/> + <disks> + <disk name='vda' snapshot='internal'/> + </disks> + <domain type='test'> + <name>test</name> + <uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid> + <memory unit='KiB'>8388608</memory> + <currentMemory unit='KiB'>2097152</currentMemory> + <vcpu placement='static'>2</vcpu> + <os> + <type arch='i686'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='/guest/diskimage1'/> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> + </disk> + <interface type='network'> + <mac address='aa:bb:cc:dd:ee:ff'/> + <source network='default'/> + <target dev='testnet0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> + </interface> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> + </domain> +</domainsnapshot> + +<domainsnapshot> + <name>s2</name> + <state>running</state> + <parent> + <name>s3</name> + </parent> + + <memory snapshot='internal'/> + <disks> + <disk name='vda' snapshot='internal'/> + </disks> + <domain type='test'> + <name>test</name> + <uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid> + <memory unit='KiB'>8388608</memory> + <currentMemory unit='KiB'>2097152</currentMemory> + <vcpu placement='static'>2</vcpu> + <os> + <type arch='i686'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='/guest/diskimage1'/> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> + </disk> + <interface type='network'> + <mac address='aa:bb:cc:dd:ee:ff'/> + <source network='default'/> + <target dev='testnet0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> + </interface> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> + </domain> +</domainsnapshot> + -- 2.44.0

Invoke the majority of the command via DO_TEST_SCRIPT in 'virshtest'. Some adaptation was needed to avoid printing of tables with volatile data such as checkpoint creation time, which were converted to list names-only. To proprely test redefinition we store XMLs rather than taking them from the defined checkpoints and use them separately to test redefinition of checkpoint XMLs. This makes use of the 'cd' command in non-interactive mode. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 1 - tests/virsh-checkpoint | 178 -------------------- tests/virshtest.c | 10 ++ tests/virshtestdata/checkpoint-c2.xml | 41 +++++ tests/virshtestdata/checkpoint-c3.xml | 38 +++++ tests/virshtestdata/checkpoint-redefine.out | 13 ++ tests/virshtestdata/checkpoint.in | 35 ++++ tests/virshtestdata/checkpoint.out | 133 +++++++++++++++ 8 files changed, 270 insertions(+), 179 deletions(-) delete mode 100755 tests/virsh-checkpoint create mode 100644 tests/virshtestdata/checkpoint-c2.xml create mode 100644 tests/virshtestdata/checkpoint-c3.xml create mode 100644 tests/virshtestdata/checkpoint-redefine.out create mode 100755 tests/virshtestdata/checkpoint.in create mode 100644 tests/virshtestdata/checkpoint.out diff --git a/tests/meson.build b/tests/meson.build index efbe99f55e..46e1679ad7 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -691,7 +691,6 @@ if conf.has('WITH_LIBVIRTD') 'libvirtd-fail', 'libvirtd-pool', 'virsh-auth', - 'virsh-checkpoint', 'virsh-read-bufsiz', 'virsh-read-non-seekable', 'virsh-self-test', diff --git a/tests/virsh-checkpoint b/tests/virsh-checkpoint deleted file mode 100755 index 2492d29f53..0000000000 --- a/tests/virsh-checkpoint +++ /dev/null @@ -1,178 +0,0 @@ -#!/bin/sh -# simple testing of checkpoint APIs on test driver - -# Copyright (C) 2019 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# <http://www.gnu.org/licenses/>. - -. "$(dirname $0)/test-lib.sh" - -test_expensive - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -fail=0 - -mock_xdg_ || framework_failure - -# The test driver loses states between restarts, so we perform a script -# with some convenient markers for later post-processing of output. -$abs_top_builddir/tools/virsh --connect test:///default >out 2>err ' - # Create a series of checkpoints, with names that intentionally sort - # differently by topology than by name. For now, it is not possible - # to create fanout without hacking through redefines. - checkpoint-create-as test c1 - checkpoint-create-as test c1 - checkpoint-create-as test c3 - checkpoint-create-as test c2 - # snapshots cannot be created while checkpoints exist - echo --err marker - snapshot-create-as test s1 - echo --err marker - # Checking tree view (siblings sorted alphabetically) - checkpoint-list test --tree - # Demonstrate list filtering - checkpoint-list test --roots - checkpoint-list test --leaves - checkpoint-list test --parent --no-leaves - checkpoint-list test --from c3 - checkpoint-list test --from c1 --descendants --name - # Now the tree is linear, so we have an unambiguous topological order - checkpoint-list test --name - checkpoint-list test --name --topological - # Capture some XML for later redefine - checkpoint-delete test c1 - echo "<!--MarkerA-->" - checkpoint-dumpxml test c3 - echo "<!--MarkerB-->" - checkpoint-dumpxml test c2 - echo "<!--MarkerC-->" - # Deleting current checkpoint moves current up to remaining parent - checkpoint-delete test --children-only c3 - checkpoint-list test --leaves --name - checkpoint-delete test --children c3 - checkpoint-list test --leaves --name - # All done -' || fail=1 - -# First part is expected output, --tree results in trailing spaces, -# and checkpoint-list produces timestamps -sed 's/ *$//; s/[0-9-]\{10\} [0-9:.]* .[0-9]\{4\}/TIMESTAMP/; - /MarkerA/,/MarkerC/d' < out > out.cooked || fail=1 -# Second part holds domain checkpoint XMLs -sed -n '/MarkerA/,/MarkerB/p' < out > c3.xml || fail=1 -sed -n '/MarkerB/,/MarkerC/p' < out > c2.xml || fail=1 - -cat <<\EOF > exp || fail=1 -Domain checkpoint c1 created - -Domain checkpoint c3 created -Domain checkpoint c2 created - - - -c1 - | - +- c3 - | - +- c2 - - - Name Creation Time ------------------------------------ - c1 TIMESTAMP - - Name Creation Time ------------------------------------ - c2 TIMESTAMP - - Name Creation Time Parent --------------------------------------------- - c1 TIMESTAMP - c3 TIMESTAMP c1 - - Name Creation Time ------------------------------------ - c2 TIMESTAMP - -c2 -c3 - -c1 -c2 -c3 - -c1 -c3 -c2 - -Domain checkpoint c1 deleted - -Domain checkpoint c3 children deleted - -c3 - -Domain checkpoint c3 deleted - - -EOF -compare exp out.cooked || fail=1 - -cat <<EOF > exp || fail=1 -error: operation failed: domain moment c1 already exists -error: marker -error: Operation not supported: cannot create snapshot while checkpoint exists -error: marker -EOF -compare exp err || fail=1 - -# Restore state with redefine -$abs_top_builddir/tools/virsh -c test:///default >out 2>err ' - # Redefine must be in topological order; this will fail - checkpoint-create test --redefine c2.xml - echo --err marker - # This is the right order - checkpoint-create test --redefine c3.xml - checkpoint-create test --redefine c2.xml - checkpoint-list test --leaves --name - checkpoint-info test c2 -' || fail=1 - -cat <<\EOF > exp || fail=1 - - -Domain checkpoint c3 created from 'c3.xml' -Domain checkpoint c2 created from 'c2.xml' -c2 - -Name: c2 -Domain: test -Parent: c3 -Children: 0 -Descendants: 0 - -EOF -compare exp out || fail=1 - -cat <<EOF > exp || fail=1 -error: invalid argument: parent c3 for moment c2 not found -error: marker -EOF -compare exp err || fail=1 - -(exit $fail); exit $fail diff --git a/tests/virshtest.c b/tests/virshtest.c index 83baac8c43..8bb94b7693 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -228,6 +228,16 @@ mymain(void) "snapshot-create test --redefine snapshot-s2.xml --current --validate ;" "snapshot-info test --current"); + DO_TEST_SCRIPT("checkpoint", "<creationTime", VIRSH_DEFAULT); + DO_TEST_FULL("checkpoint-redefine", NULL, VIRSH_DEFAULT, + "cd " abs_srcdir "/virshtestdata ;" + "echo 'Redefine must be in topological order; this will fail' ;" + "checkpoint-create test --redefine checkpoint-c2.xml ;" + "echo 'correct order' ;" + "checkpoint-create test --redefine checkpoint-c3.xml ;" + "checkpoint-create test --redefine checkpoint-c2.xml ;" + "checkpoint-info test c2"); + VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/virshtestdata/checkpoint-c2.xml b/tests/virshtestdata/checkpoint-c2.xml new file mode 100644 index 0000000000..6879eb992f --- /dev/null +++ b/tests/virshtestdata/checkpoint-c2.xml @@ -0,0 +1,41 @@ +<domaincheckpoint> + <name>c2</name> + <parent> + <name>c3</name> + </parent> + <creationTime>1234</creationTime> + <disks> + <disk name='vda' checkpoint='bitmap' bitmap='c2'/> + </disks> + <domain type='test'> + <name>test</name> + <uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid> + <memory unit='KiB'>8388608</memory> + <currentMemory unit='KiB'>2097152</currentMemory> + <vcpu placement='static'>2</vcpu> + <os> + <type arch='i686'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='/guest/diskimage1'/> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> + </disk> + <interface type='network'> + <mac address='aa:bb:cc:dd:ee:ff'/> + <source network='default'/> + <target dev='testnet0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> + </interface> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> + </domain> +</domaincheckpoint> diff --git a/tests/virshtestdata/checkpoint-c3.xml b/tests/virshtestdata/checkpoint-c3.xml new file mode 100644 index 0000000000..c960a8553b --- /dev/null +++ b/tests/virshtestdata/checkpoint-c3.xml @@ -0,0 +1,38 @@ +<domaincheckpoint> + <name>c3</name> + <creationTime>5678</creationTime> + <disks> + <disk name='vda' checkpoint='bitmap' bitmap='c3'/> + </disks> + <domain type='test'> + <name>test</name> + <uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid> + <memory unit='KiB'>8388608</memory> + <currentMemory unit='KiB'>2097152</currentMemory> + <vcpu placement='static'>2</vcpu> + <os> + <type arch='i686'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='/guest/diskimage1'/> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> + </disk> + <interface type='network'> + <mac address='aa:bb:cc:dd:ee:ff'/> + <source network='default'/> + <target dev='testnet0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> + </interface> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> + </domain> +</domaincheckpoint> diff --git a/tests/virshtestdata/checkpoint-redefine.out b/tests/virshtestdata/checkpoint-redefine.out new file mode 100644 index 0000000000..83fccbc799 --- /dev/null +++ b/tests/virshtestdata/checkpoint-redefine.out @@ -0,0 +1,13 @@ + +Redefine must be in topological order; this will fail +error: invalid argument: parent c3 for moment c2 not found + +correct order +Domain checkpoint c3 created from 'checkpoint-c3.xml' +Domain checkpoint c2 created from 'checkpoint-c2.xml' +Name: c2 +Domain: test +Parent: c3 +Children: 0 +Descendants: 0 + diff --git a/tests/virshtestdata/checkpoint.in b/tests/virshtestdata/checkpoint.in new file mode 100755 index 0000000000..760f1fb648 --- /dev/null +++ b/tests/virshtestdata/checkpoint.in @@ -0,0 +1,35 @@ +echo Create a series of checkpoints, with names that intentionally sort +echo differently by topology than by name. For now, it is not possible +echo to create fanout without hacking through redefines. +checkpoint-create-as test c1 +checkpoint-create-as test c1 +checkpoint-create-as test c3 +checkpoint-create-as test c2 + +echo snapshots cannot be created while checkpoints exist +snapshot-create-as test s1 + +echo Checking tree view (siblings sorted alphabetically) +checkpoint-list test --tree + +echo Demonstrate list filtering +checkpoint-list test --roots --name +checkpoint-list test --leaves --name +checkpoint-list test --parent --no-leaves --name +checkpoint-list test --from c3 --name +checkpoint-list test --from c1 --descendants --name + +echo Now the tree is linear, so we have an unambiguous topological order +checkpoint-list test --name +checkpoint-list test --name --topological + +echo validate XML +checkpoint-delete test c1 +checkpoint-dumpxml test c3 +checkpoint-dumpxml test c2 + +echo Deleting current checkpoint moves current up to remaining parent +checkpoint-delete test --children-only c3 +checkpoint-list test --leaves --name +checkpoint-delete test --children c3 +checkpoint-list test --leaves --name diff --git a/tests/virshtestdata/checkpoint.out b/tests/virshtestdata/checkpoint.out new file mode 100644 index 0000000000..285bb0648f --- /dev/null +++ b/tests/virshtestdata/checkpoint.out @@ -0,0 +1,133 @@ +Create a series of checkpoints, with names that intentionally sort +differently by topology than by name. For now, it is not possible +to create fanout without hacking through redefines. +Domain checkpoint c1 created +error: operation failed: domain moment c1 already exists + +Domain checkpoint c3 created +Domain checkpoint c2 created +snapshots cannot be created while checkpoints exist +error: Operation not supported: cannot create snapshot while checkpoint exists + +Checking tree view (siblings sorted alphabetically) +c1 + | + +- c3 + | + +- c2 + + +Demonstrate list filtering +c1 + +c2 + +c1 +c3 c1 + +c2 + +c2 +c3 + +Now the tree is linear, so we have an unambiguous topological order +c1 +c2 +c3 + +c1 +c3 +c2 + +validate XML +Domain checkpoint c1 deleted + +<domaincheckpoint> + <name>c3</name> + + <disks> + <disk name='vda' checkpoint='bitmap' bitmap='c3'/> + </disks> + <domain type='test'> + <name>test</name> + <uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid> + <memory unit='KiB'>8388608</memory> + <currentMemory unit='KiB'>2097152</currentMemory> + <vcpu placement='static'>2</vcpu> + <os> + <type arch='i686'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='/guest/diskimage1'/> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> + </disk> + <interface type='network'> + <mac address='aa:bb:cc:dd:ee:ff'/> + <source network='default'/> + <target dev='testnet0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> + </interface> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> + </domain> +</domaincheckpoint> + +<domaincheckpoint> + <name>c2</name> + <parent> + <name>c3</name> + </parent> + + <disks> + <disk name='vda' checkpoint='bitmap' bitmap='c2'/> + </disks> + <domain type='test'> + <name>test</name> + <uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid> + <memory unit='KiB'>8388608</memory> + <currentMemory unit='KiB'>2097152</currentMemory> + <vcpu placement='static'>2</vcpu> + <os> + <type arch='i686'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='/guest/diskimage1'/> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> + </disk> + <interface type='network'> + <mac address='aa:bb:cc:dd:ee:ff'/> + <source network='default'/> + <target dev='testnet0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> + </interface> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> + </domain> +</domaincheckpoint> + +Deleting current checkpoint moves current up to remaining parent +Domain checkpoint c3 children deleted + +c3 + +Domain checkpoint c3 deleted + + -- 2.44.0

Test both situations (reading from non-regular file and reading a file larger than (arbitrary) buffer size) via 'virshtest'. To feed the pipe we need to create a thread that does it, but otherwise it's fairly straightforward. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 2 - tests/virsh-read-bufsiz | 49 --------------- tests/virsh-read-non-seekable | 51 --------------- tests/virshtest.c | 90 +++++++++++++++++++++++++++ tests/virshtestdata/read-big-pipe.out | 7 +++ 5 files changed, 97 insertions(+), 102 deletions(-) delete mode 100755 tests/virsh-read-bufsiz delete mode 100755 tests/virsh-read-non-seekable create mode 100644 tests/virshtestdata/read-big-pipe.out diff --git a/tests/meson.build b/tests/meson.build index 46e1679ad7..c760fe68d9 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -691,8 +691,6 @@ if conf.has('WITH_LIBVIRTD') 'libvirtd-fail', 'libvirtd-pool', 'virsh-auth', - 'virsh-read-bufsiz', - 'virsh-read-non-seekable', 'virsh-self-test', 'virsh-uriprecedence', 'virt-admin-self-test', diff --git a/tests/virsh-read-bufsiz b/tests/virsh-read-bufsiz deleted file mode 100755 index a61816c25b..0000000000 --- a/tests/virsh-read-bufsiz +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -# ensure that reading a file larger than BUFSIZ works - -# Copyright (C) 2008, 2010 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# <http://www.gnu.org/licenses/>. - -. "$(dirname $0)/test-lib.sh" - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -fail=0 - -# Output a valid definition, to be used as input. -$abs_top_builddir/tools/virsh -c test:///default dumpxml 1 > xml.t || fail=1 - -# Change the VM name and UUID -sed -e "s|<name>test</name>|<name>newtest</name>|g" \ - -e "\|<uuid>.*</uuid>|d" \ - xml.t > xml - -for i in before after; do - # The largest BUFSIZ I've seen is 128K. This is slightly larger. - printf %132000s ' ' > sp || fail=1 - in=in-$i - # Append or prepend enough spaces to push the size over the limit: - ( test $i = before && cat sp xml || cat xml sp ) > $in || fail=1 - - $abs_top_builddir/tools/virsh --connect test:///default define $in > out || fail=1 - printf "Domain 'newtest' defined from $in\n\n" > exp || fail=1 - compare exp out || fail=1 -done - -(exit $fail); exit $fail diff --git a/tests/virsh-read-non-seekable b/tests/virsh-read-non-seekable deleted file mode 100755 index 0f7504c800..0000000000 --- a/tests/virsh-read-non-seekable +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh -# ensure that certain file-reading commands can handle non-seekable files - -# Copyright (C) 2008 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# <http://www.gnu.org/licenses/>. - -. "$(dirname $0)/test-lib.sh" - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -fail=0 - -cat <<\EOF > dom -<domain type='test' id='2'> - <name>t2</name> - <uuid>004b96e1-2d78-c30f-5aa5-000000000000</uuid> - <memory>8388608</memory> - <vcpu>2</vcpu> - <os> - <type>xen</type> - </os> - <on_reboot>restart</on_reboot> - <on_poweroff>destroy</on_poweroff> - <on_crash>restart</on_crash> -</domain> -EOF - -$abs_top_builddir/tools/virsh -c test:///default define dom > /dev/null || fail=1 - -mkfifo_or_skip_ fifo -cat dom > fifo & - -$abs_top_builddir/tools/virsh -c test:///default define fifo > /dev/null || fail=1 - -(exit $fail); exit $fail diff --git a/tests/virshtest.c b/tests/virshtest.c index 8bb94b7693..f520ff9fc9 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -1,11 +1,14 @@ #include <config.h> #include <unistd.h> +#include <fcntl.h> #include "internal.h" #include "testutils.h" #include "vircommand.h" +#include "util/virthread.h" + #define VIR_FROM_THIS VIR_FROM_NONE #ifdef WIN32 @@ -103,6 +106,90 @@ static int testCompare(const void *data) } +static void +testPipeFeeder(void *opaque) +{ + /* feed more than observed buffer size which was historically 128k in the + * test this was adapted from */ + size_t emptyspace = 140 * 1024; + const char *pipepath = opaque; + const char *xml = + "<domain type='test' id='2'>\n" + " <name>t2</name>\n" + " <uuid>004b96e1-2d78-c30f-5aa5-000000000000</uuid>\n" + " <memory>8388608</memory>\n" + " <vcpu>2</vcpu>\n" + " <os>\n" + " <type>xen</type>\n" + " </os>\n" + "</domain>\n"; + size_t xmlsize = strlen(xml); + g_autofree char *doc = g_new0(char, emptyspace + xmlsize + 1); + VIR_AUTOCLOSE fd = -1; + + if ((fd = open(pipepath, O_RDWR)) < 0) { + fprintf(stderr, "\nfailed to open pipe '%s': %s\n", pipepath, g_strerror(errno)); + return; + } + + memset(doc, ' ', emptyspace); + virStrcpy(doc + emptyspace, xml, xmlsize); + + if (safewrite(fd, doc, emptyspace + xmlsize + 1) < 0) { + fprintf(stderr, "\nfailed to write to pipe '%s': %s\n", pipepath, g_strerror(errno)); + return; + } +} + + +static int +testVirshPipe(const void *data G_GNUC_UNUSED) +{ + char tmpdir[] = "/tmp/libvirt_virshtest_XXXXXXX"; + g_autofree char *pipepath = NULL; + virThread feeder; + bool join = false; + g_autofree char *cmdstr = NULL; + const char *argv[] = { VIRSH_DEFAULT, NULL, NULL }; + int ret = -1; + + if (!g_mkdtemp(tmpdir)) { + fprintf(stderr, "\nfailed to create temporary directory\n"); + return -1; + } + + pipepath = g_strdup_printf("%s/pipe", tmpdir); + + + cmdstr = g_strdup_printf("define %s ; list --all", pipepath); + argv[3] = cmdstr; + + if (mkfifo(pipepath, 0600) < 0) { + fprintf(stderr, "\nfailed to create pipe '%s': %s\n", pipepath, g_strerror(errno)); + goto cleanup; + } + + if (virThreadCreate(&feeder, true, testPipeFeeder, pipepath) < 0) + goto cleanup; + + join = true; + + if (testCompareOutputLit(abs_srcdir "/virshtestdata/read-big-pipe.out", + "/tmp/libvirt_virshtest", argv) < 0) + goto cleanup; + + ret = 0; + + cleanup: + if (join) + virThreadJoin(&feeder); + unlink(pipepath); + rmdir(tmpdir); + + return ret; +} + + static int mymain(void) { @@ -238,6 +325,9 @@ mymain(void) "checkpoint-create test --redefine checkpoint-c2.xml ;" "checkpoint-info test c2"); + if (virTestRun("read-big-pipe", testVirshPipe, NULL) < 0) + ret = -1; + VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/virshtestdata/read-big-pipe.out b/tests/virshtestdata/read-big-pipe.out new file mode 100644 index 0000000000..340432210d --- /dev/null +++ b/tests/virshtestdata/read-big-pipe.out @@ -0,0 +1,7 @@ +Domain 't2' defined from + + Id Name State +----------------------- + 1 test running + - t2 shut off + -- 2.44.0

On Fri, Mar 22, 2024 at 06:56:08PM GMT, Peter Krempa wrote:
+static void +testPipeFeeder(void *opaque) +{ + /* feed more than observed buffer size which was historically 128k in the + * test this was adapted from */ + size_t emptyspace = 140 * 1024;
This test seems to fail consistently at least on ppc64le, among other less common architectures. This can be seen both in Debian[1] and Fedora[2]. It runs for a while, then it hits the timeout gets terminated by meson. I've reproduced it locally and this is the output: # LIBVIRT_DEBUG=1 VIR_TEST_DEBUG=1 VIR_TEST_RANGE=71 ./tests/virshtest ninja: no work to do. TEST: virshtest 71) read-big-pipe ... 2024-05-07 16:43:17.099+0000: 69735: info : libvirt version: 10.4.0 2024-05-07 16:43:17.099+0000: 69735: debug : virThreadJobSet:96 : Thread 69735 is now running job testPipeFeeder 2024-05-07 16:43:17.099+0000: 69734: debug : virCommandRunAsync:2657 : About to run LANG=C /root/libvirt/build/tools/virsh --connect test:///default 'define /tmp/libvirt_virshtest_XUTXGN2/pipe ; list --all' 2024-05-07 16:43:17.099+0000: 69735: debug : virThreadJobClear:121 : Thread 69735 finished job testPipeFeeder with ret=0 2024-05-07 16:43:17.099+0000: 69734: debug : virCommandRunAsync:2659 : Command result 0, with PID 69736 I've bumped the size of emptyspace to 1024*1024 and that causes the test to pass. 1023*1024 doesn't. Could it be something about the fifo's capacity being different across architectures? [1] https://buildd.debian.org/status/fetch.php?pkg=libvirt&arch=ppc64el&ver=10.3.0-2&stamp=1715074703&raw=0 [2] https://koji.fedoraproject.org/koji/taskinfo?taskID=117156020 -- Andrea Bolognani / Red Hat / Virtualization

On Tue, May 07, 2024 at 04:56:00PM +0000, Andrea Bolognani wrote:
On Fri, Mar 22, 2024 at 06:56:08PM GMT, Peter Krempa wrote:
+static void +testPipeFeeder(void *opaque) +{ + /* feed more than observed buffer size which was historically 128k in the + * test this was adapted from */ + size_t emptyspace = 140 * 1024;
This test seems to fail consistently at least on ppc64le, among other less common architectures. This can be seen both in Debian[1] and Fedora[2]. It runs for a while, then it hits the timeout gets terminated by meson.
I've reproduced it locally and this is the output:
# LIBVIRT_DEBUG=1 VIR_TEST_DEBUG=1 VIR_TEST_RANGE=71 ./tests/virshtest ninja: no work to do. TEST: virshtest 71) read-big-pipe ... 2024-05-07 16:43:17.099+0000: 69735: info : libvirt version: 10.4.0 2024-05-07 16:43:17.099+0000: 69735: debug : virThreadJobSet:96 : Thread 69735 is now running job testPipeFeeder 2024-05-07 16:43:17.099+0000: 69734: debug : virCommandRunAsync:2657 : About to run LANG=C /root/libvirt/build/tools/virsh --connect test:///default 'define /tmp/libvirt_virshtest_XUTXGN2/pipe ; list --all' 2024-05-07 16:43:17.099+0000: 69735: debug : virThreadJobClear:121 : Thread 69735 finished job testPipeFeeder with ret=0 2024-05-07 16:43:17.099+0000: 69734: debug : virCommandRunAsync:2659 : Command result 0, with PID 69736
I've bumped the size of emptyspace to 1024*1024 and that causes the test to pass. 1023*1024 doesn't. Could it be something about the fifo's capacity being different across architectures?
I had multiple builds fail in Fedora, but today a ppc64 build magically passed. So even on ppc64 it is racy :-( The virFileReadAll method reads in BUFSIZ chunks but that hasn't changed in years. The new test is pretty trivial, and I struggle to see why changing the buffer size would affect it, given the old test this replaced did largely the same thing. With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Tue, May 07, 2024 at 08:14:18PM GMT, Daniel P. Berrangé wrote:
On Tue, May 07, 2024 at 04:56:00PM +0000, Andrea Bolognani wrote:
On Fri, Mar 22, 2024 at 06:56:08PM GMT, Peter Krempa wrote:
+static void +testPipeFeeder(void *opaque) +{ + /* feed more than observed buffer size which was historically 128k in the + * test this was adapted from */ + size_t emptyspace = 140 * 1024;
This test seems to fail consistently at least on ppc64le, among other less common architectures. This can be seen both in Debian[1] and Fedora[2]. It runs for a while, then it hits the timeout gets terminated by meson.
I've reproduced it locally and this is the output:
# LIBVIRT_DEBUG=1 VIR_TEST_DEBUG=1 VIR_TEST_RANGE=71 ./tests/virshtest ninja: no work to do. TEST: virshtest 71) read-big-pipe ... 2024-05-07 16:43:17.099+0000: 69735: info : libvirt version: 10.4.0 2024-05-07 16:43:17.099+0000: 69735: debug : virThreadJobSet:96 : Thread 69735 is now running job testPipeFeeder 2024-05-07 16:43:17.099+0000: 69734: debug : virCommandRunAsync:2657 : About to run LANG=C /root/libvirt/build/tools/virsh --connect test:///default 'define /tmp/libvirt_virshtest_XUTXGN2/pipe ; list --all' 2024-05-07 16:43:17.099+0000: 69735: debug : virThreadJobClear:121 : Thread 69735 finished job testPipeFeeder with ret=0 2024-05-07 16:43:17.099+0000: 69734: debug : virCommandRunAsync:2659 : Command result 0, with PID 69736
I've bumped the size of emptyspace to 1024*1024 and that causes the test to pass. 1023*1024 doesn't. Could it be something about the fifo's capacity being different across architectures?
I had multiple builds fail in Fedora, but today a ppc64 build magically passed. So even on ppc64 it is racy :-(
The virFileReadAll method reads in BUFSIZ chunks but that hasn't changed in years. The new test is pretty trivial, and I struggle to see why changing the buffer size would affect it, given the old test this replaced did largely the same thing.
Maybe the shell writes to the fifo differently than libvirt does? Also "read XML from a fifo" and "read a really big XML file" were two separate test cases before. Some unexpected interaction between buffer size and fifo handling, perhaps? -- Andrea Bolognani / Red Hat / Virtualization

The test case is a fairly simple invocation of pool-create-as which can be done easily from 'virshtest'. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/libvirtd-pool | 38 -------------------------- tests/meson.build | 1 - tests/virshtest.c | 3 ++ tests/virshtestdata/pool-define-as.out | 12 ++++++++ 4 files changed, 15 insertions(+), 39 deletions(-) delete mode 100755 tests/libvirtd-pool create mode 100644 tests/virshtestdata/pool-define-as.out diff --git a/tests/libvirtd-pool b/tests/libvirtd-pool deleted file mode 100755 index 4be65c68fe..0000000000 --- a/tests/libvirtd-pool +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# Get coverage of virsh pool-define-as XML formatting - -. "$(dirname $0)/test-lib.sh" - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -fail=0 - -pwd=$(pwd) || fail=1 - -$abs_top_builddir/tools/virsh --connect test:///default \ - pool-define-as --print-xml \ - P dir src-host /src/path /src/dev S /target-path \ - 1>out 2>&1 - -cat <<EOF > pool-list-exp -<pool type='dir'> - <name>P</name> - <source> - <host name='src-host'/> - <dir path='/src/path'/> - <device path='/src/dev'/> - <name>S</name> - </source> - <target> - <path>/target-path</path> - </target> -</pool> - -EOF - -compare pool-list-exp out || fail=1 - -exit $fail diff --git a/tests/meson.build b/tests/meson.build index c760fe68d9..68f7635df9 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -689,7 +689,6 @@ test_scripts = [] if conf.has('WITH_LIBVIRTD') test_scripts += [ 'libvirtd-fail', - 'libvirtd-pool', 'virsh-auth', 'virsh-self-test', 'virsh-uriprecedence', diff --git a/tests/virshtest.c b/tests/virshtest.c index f520ff9fc9..4e11a1cb04 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -304,6 +304,9 @@ mymain(void) DO_TEST_FULL("domain-id-overflow", NULL, VIRSH_CUSTOM, "-q", "domname", "4294967298"); DO_TEST_FULL("schedinfo-invalid-argument", NULL, VIRSH_DEFAULT, "schedinfo", "1", "--set", "j=k"); + DO_TEST_FULL("pool-define-as", NULL, VIRSH_DEFAULT, "-q", + "pool-define-as", "--print-xml", "P", "dir", "src-host", + "/src/path", "/src/dev", "S", "/target-path"); DO_TEST_SCRIPT("snapshot", "<creationTime", VIRSH_DEFAULT); DO_TEST_FULL("snapshot-redefine", NULL, VIRSH_DEFAULT, diff --git a/tests/virshtestdata/pool-define-as.out b/tests/virshtestdata/pool-define-as.out new file mode 100644 index 0000000000..dade8b958c --- /dev/null +++ b/tests/virshtestdata/pool-define-as.out @@ -0,0 +1,12 @@ +<pool type='dir'> + <name>P</name> + <source> + <host name='src-host'/> + <dir path='/src/path'/> + <device path='/src/dev'/> + <name>S</name> + </source> + <target> + <path>/target-path</path> + </target> +</pool> -- 2.44.0

The self-test command for both virsh and virt-admin is self contained and directly reports success, thus we don't actually need to run a shell wrapper around it. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 16 +++++++++++-- tests/virsh-self-test | 48 -------------------------------------- tests/virt-admin-self-test | 1 - tools/meson.build | 4 ++-- 4 files changed, 16 insertions(+), 53 deletions(-) delete mode 100755 tests/virsh-self-test delete mode 120000 tests/virt-admin-self-test diff --git a/tests/meson.build b/tests/meson.build index 68f7635df9..8ccc63b3a6 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -619,6 +619,20 @@ test( suite: 'script', ) +# vsh based client self-test, which can be run directly from meson +test('virsh self-test', + virsh_prog, + args: [ '-q', '-c', 'test:///default', 'self-test' ], + suite: 'bin', +) + +if conf.has('WITH_REMOTE') + test('virt-admin self-test', + virt_admin_prog, + args: [ '-q', 'self-test' ], + suite: 'bin', + ) +endif # helpers: # each entry is a dictionary with following items: @@ -690,9 +704,7 @@ if conf.has('WITH_LIBVIRTD') test_scripts += [ 'libvirtd-fail', 'virsh-auth', - 'virsh-self-test', 'virsh-uriprecedence', - 'virt-admin-self-test', ] if conf.has('WITH_SECDRIVER_APPARMOR') diff --git a/tests/virsh-self-test b/tests/virsh-self-test deleted file mode 100755 index 22396bceee..0000000000 --- a/tests/virsh-self-test +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh -# run virsh self-test to make sure command option structures are valid - -# Copyright (C) 2016 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# <http://www.gnu.org/licenses/>. - -. "$(dirname $0)/test-lib.sh" - -fail=0 - -basename=$(basename $0) - -if test "x$basename" = "xvirsh-self-test" ; then - binary=virsh - extra_args="-c test:///default" -elif test "x$basename" = "xvirt-admin-self-test" ; then - binary=virt-admin - extra_args="" -else - echo "Unknown binary: $basename"; - exit 1 -fi - -test_intro "$0" -$abs_top_builddir/tools/${binary} ${extra_args} self-test > /dev/null -status=$? -test_result 1 "$0" ${status} - -if test "${status}" != "0" ; then - fail=1 -fi - -test_final $counter $fail - -(exit $fail); exit $fail diff --git a/tests/virt-admin-self-test b/tests/virt-admin-self-test deleted file mode 120000 index d4ad624a04..0000000000 --- a/tests/virt-admin-self-test +++ /dev/null @@ -1 +0,0 @@ -./virsh-self-test \ No newline at end of file diff --git a/tools/meson.build b/tools/meson.build index c72f760a1d..15be557dfe 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -155,7 +155,7 @@ else virsh_icon_res = [] endif -executable( +virsh_prog = executable( 'virsh', [ 'virsh.c', @@ -209,7 +209,7 @@ executable( ) if conf.has('WITH_REMOTE') - executable( + virt_admin_prog = executable( 'virt-admin', [ 'virt-admin.c', -- 2.44.0

The test simply invokes libvirtd and expects it to fail. We can do that directly in meson without the need for a wrapper script. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/meson.build | 5 +++++ tests/libvirtd-fail | 16 ---------------- tests/meson.build | 8 +++++++- 3 files changed, 12 insertions(+), 17 deletions(-) delete mode 100755 tests/libvirtd-fail diff --git a/src/meson.build b/src/meson.build index f52d2d5994..a51f40fe16 100644 --- a/src/meson.build +++ b/src/meson.build @@ -654,6 +654,11 @@ foreach daemon : virt_daemons install_dir: sbindir, install_rpath: libvirt_rpath, ) + + # libvirtd_prog is needed by the test suite + if daemon['name'] == 'libvirtd' + libvirtd_prog = bin + endif endforeach diff --git a/tests/libvirtd-fail b/tests/libvirtd-fail deleted file mode 100755 index f9e927b61f..0000000000 --- a/tests/libvirtd-fail +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -# Ensure that libvirt fails when given nonexistent --config=FILE - -. "$(dirname $0)/test-lib.sh" - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/src/libvirtd --version -fi - -fail=0 - -$abs_top_builddir/src/libvirtd --config=no-such-conf --timeout=5 2> log -RET=$? - -test "$RET" != "0" && exit 0 || exit 1 diff --git a/tests/meson.build b/tests/meson.build index 8ccc63b3a6..4da1b099e4 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -701,8 +701,14 @@ endforeach test_scripts = [] if conf.has('WITH_LIBVIRTD') + test('libvirtd fail with missing config', + libvirtd_prog, + args: [ '--config=no-such-conf', '--timeout=5' ], + should_fail: true, + suite: 'bin', + ) + test_scripts += [ - 'libvirtd-fail', 'virsh-auth', 'virsh-uriprecedence', ] -- 2.44.0

Reimplement the virsh-uriprecedence test case in virshtest. To do this we need to add infrastructure to pass extra environment variables to the tested virsh. The user config files are shipped in repo rather than created in the script. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 1 - tests/virsh-uriprecedence | 97 -------------- tests/virshtest.c | 126 ++++++++++++++++-- .../uriprecedence-LIBVIRT_DEFAULT_URI.out | 5 + ...riprecedence-VIRSH_DEFAULT_CONNECT_URI.out | 5 + tests/virshtestdata/uriprecedence-param.out | 5 + .../uriprecedence-xdg-config.out | 5 + .../bad/libvirt/libvirt.conf | 1 + .../good/libvirt/libvirt.conf | 1 + 9 files changed, 140 insertions(+), 106 deletions(-) delete mode 100755 tests/virsh-uriprecedence create mode 100644 tests/virshtestdata/uriprecedence-LIBVIRT_DEFAULT_URI.out create mode 100644 tests/virshtestdata/uriprecedence-VIRSH_DEFAULT_CONNECT_URI.out create mode 100644 tests/virshtestdata/uriprecedence-param.out create mode 100644 tests/virshtestdata/uriprecedence-xdg-config.out create mode 100644 tests/virshtestdata/uriprecedence-xdg/bad/libvirt/libvirt.conf create mode 100644 tests/virshtestdata/uriprecedence-xdg/good/libvirt/libvirt.conf diff --git a/tests/meson.build b/tests/meson.build index 4da1b099e4..3f8f3dee7c 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -710,7 +710,6 @@ if conf.has('WITH_LIBVIRTD') test_scripts += [ 'virsh-auth', - 'virsh-uriprecedence', ] if conf.has('WITH_SECDRIVER_APPARMOR') diff --git a/tests/virsh-uriprecedence b/tests/virsh-uriprecedence deleted file mode 100755 index f141d08dfd..0000000000 --- a/tests/virsh-uriprecedence +++ /dev/null @@ -1,97 +0,0 @@ -#!/bin/sh - -. "$(dirname $0)/test-lib.sh" - -# This test checks if virsh obeys the proper precedence of different -# URI settings -test_intro "virsh-uriprecedence" - -virsh_bin="$abs_top_builddir/tools/virsh" -virsh_cmd="$virsh_bin" -counter=0 -ret=0 - -mock_xdg_ || framework_failure - -is_uri_good() -{ - echo "$1" | grep -F "$good_uri" >/dev/null -} - -test_uri_internal() -{ - test_name=$1 - test_cmd="$virsh_cmd \"$2\"" - result=0 - - debug "Running '$test_cmd'" - out="$($virsh_cmd "$2")" - - if ! is_uri_good "$out"; then - debug "Invalid output: '$out'" - result=1 - ret=1 - fi - - counter="$((counter+1))" - test_result "$counter" "$1" "$result" -} - -test_uri_connect() -{ - test_uri_internal "$1" "connect; uri" -} - -test_uri_noconnect() -{ - test_uri_internal "$1" "uri" -} - -test_uri() -{ - test_uri_connect "$1" - test_uri_noconnect "$1" -} - -# Precedence is the following (lowest priority first): -# -# 1) if run as root, 'uri_default' from /etc/libvirtd/libvirt.conf, -# otherwise qemu:///session. There is no way to mock this file for -# virsh/libvirt.so and the user may have set anything in there that -# would spoil the test, so we don't test this -# -# 2) 'uri_default' from $XDG_CONFIG_HOME/libvirt/libvirt.conf -# -# 3) LIBVIRT_DEFAULT_URI -# -# 4) VIRSH_DEFAULT_CONNECT_URI -# -# 5) parameter -c (--connect) - -unset LIBVIRT_DEFAULT_URI -unset VIRSH_DEFAULT_CONNECT_URI -bad_uri="test:///default?bad_uri" -good_uri="test:///default?good_uri" - -printf "uri_default=\"%s\"\n" "$good_uri" >"$XDG_CONFIG_HOME/libvirt/libvirt.conf" -if uid_is_privileged_; then - counter="$((counter+1))" - test_skip_case "$counter" "User config file" "must not be run as root" -else - test_uri "User config file" -fi - -printf "uri_default=\"%s\"\n" "$bad_uri" >"$XDG_CONFIG_HOME/libvirt/libvirt.conf" -export LIBVIRT_DEFAULT_URI="$good_uri" -test_uri "LIBVIRT_DEFAULT_URI" - -export LIBVIRT_DEFAULT_URI="$bad_uri" -export VIRSH_DEFAULT_CONNECT_URI="$good_uri" -test_uri "VIRSH_DEFAULT_CONNECT_URI" - -export VIRSH_DEFAULT_CONNECT_URI="$bad_uri" -virsh_cmd="$virsh_bin --connect $good_uri" -test_uri "Parameter" - -test_final "$counter" "$ret" -(exit "$ret"); exit "$ret" diff --git a/tests/virshtest.c b/tests/virshtest.c index 4e11a1cb04..638fd93a0d 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -40,6 +40,7 @@ static void testFilterLine(char *buffer, static int testCompareOutputLit(const char *expectFile, const char *filter, + const char *const *env, const char *const argv[]) { g_autofree char *actual = NULL; @@ -50,6 +51,12 @@ testCompareOutputLit(const char *expectFile, cmd = virCommandNewArgs(argv); virCommandAddEnvString(cmd, "LANG=C"); + + while (env && *env) { + virCommandAddEnvString(cmd, *env); + env++; + } + virCommandSetInputBuffer(cmd, empty); virCommandSetOutputBuffer(cmd, &actual); virCommandSetErrorBuffer(cmd, &actual); @@ -87,6 +94,8 @@ struct testInfo { const char *filter; const char *const *argv; bool expensive; + const char *const *env; /* extra environment variables to pass */ + bool forbid_root; }; static int testCompare(const void *data) @@ -97,12 +106,15 @@ static int testCompare(const void *data) if (info->expensive && virTestGetExpensive() == 0) return EXIT_AM_SKIP; + if (info->forbid_root && geteuid() == 0) + return EXIT_AM_SKIP; + if (info->testname) { outfile = g_strdup_printf("%s/virshtestdata/%s.out", abs_srcdir, info->testname); } - return testCompareOutputLit(outfile, info->filter, info->argv); + return testCompareOutputLit(outfile, info->filter, info->env, info->argv); } @@ -175,7 +187,7 @@ testVirshPipe(const void *data G_GNUC_UNUSED) join = true; if (testCompareOutputLit(abs_srcdir "/virshtestdata/read-big-pipe.out", - "/tmp/libvirt_virshtest", argv) < 0) + "/tmp/libvirt_virshtest", NULL, argv) < 0) goto cleanup; ret = 0; @@ -205,7 +217,7 @@ mymain(void) abs_srcdir, testname); \ const char *myargv[] = { __VA_ARGS__, NULL, NULL }; \ const char **tmp = myargv; \ - const struct testInfo info = { testname, testfilter, myargv, expensive }; \ + const struct testInfo info = { testname, testfilter, myargv, expensive, NULL, false}; \ g_autofree char *scriptarg = NULL; \ if (virFileReadAll(infile, 256 * 1024, &scriptarg) < 0) { \ fprintf(stderr, "\nfailed to load '%s'\n", infile); \ @@ -227,13 +239,15 @@ mymain(void) DO_TEST_SCRIPT("blkiotune", NULL, VIRSH_CUSTOM); DO_TEST_SCRIPT("iothreads", NULL, VIRSH_CUSTOM); -# define DO_TEST_FULL(testname_, filter, ...) \ +# define DO_TEST_INFO(infostruct) \ + if (virTestRun((infostruct)->testname, testCompare, (infostruct)) < 0) \ + ret = -1; + +# define DO_TEST_FULL(testname, filter, ...) \ do { \ - const char *testname = testname_; \ const char *myargv[] = { __VA_ARGS__, NULL }; \ - const struct testInfo info = { testname, NULL, myargv, false }; \ - if (virTestRun(testname, testCompare, &info) < 0) \ - ret = -1; \ + const struct testInfo info = { testname, NULL, myargv, false, NULL, false }; \ + DO_TEST_INFO(&info); \ } while (0) /* automatically numbered test invocation */ @@ -331,6 +345,102 @@ mymain(void) if (virTestRun("read-big-pipe", testVirshPipe, NULL) < 0) ret = -1; + /* Test precedence of URI lookup in virsh: + * + * Precedence is the following (lowest priority first): + * + * 1) if run as root, 'uri_default' from /etc/libvirtd/libvirt.conf, + * otherwise qemu:///session. There is no way to mock this file for + * virsh/libvirt.so and the user may have set anything in there that + * would spoil the test, so we don't test this + * + * 2) 'uri_default' from $XDG_CONFIG_HOME/libvirt/libvirt.conf + * + * 3) LIBVIRT_DEFAULT_URI + * + * 4) VIRSH_DEFAULT_CONNECT_URI + * + * 5) parameter -c (--connect) + * + * There are two pre-prepared directories in tests/virshtestdata/ serving + * as mock XDG_CONFIG_HOME containing the test configs. + */ + { + const char *uriTest = "uri; connect; uri"; + const char *myargv_noconnect[] = { abs_top_builddir "/tools/virsh", uriTest, NULL }; + const char *xdgDirBad = "XDG_CONFIG_HOME=" abs_srcdir "/virshtestdata/uriprecedence-xdg/bad/"; + struct testInfo info = { NULL, NULL, myargv_noconnect, false, NULL, false }; + + /* test 1 - default from config */ + { + const char *myenv[] = { + "XDG_CONFIG_HOME=" abs_srcdir "/virshtestdata/uriprecedence-xdg/good/", + NULL, + }; + + info.testname = "uriprecedence-xdg-config"; + info.env = myenv; + info.forbid_root = true; + + DO_TEST_INFO(&info); + } + + /* all other tests don't care */ + info.forbid_root = false; + + /* test 2 - LIBVIRT_DEFAULT_URI env variable */ + { + const char *myenv[] = { + xdgDirBad, + "LIBVIRT_DEFAULT_URI=test:///default?good_uri", + NULL, + }; + + info.testname = "uriprecedence-LIBVIRT_DEFAULT_URI"; + info.env = myenv; + + DO_TEST_INFO(&info); + } + + /* test 3 - VIRSH_DEFAULT_CONNECT_URI env variable */ + { + const char *myenv[] = { + xdgDirBad, + "LIBVIRT_DEFAULT_URI=test:///default?bad_uri", + "VIRSH_DEFAULT_CONNECT_URI=test:///default?good_uri", + NULL, + }; + + info.testname = "uriprecedence-VIRSH_DEFAULT_CONNECT_URI"; + info.env = myenv; + + DO_TEST_INFO(&info); + } + + /* test 3 - --connect parameter */ + { + const char *myenv[] = { + xdgDirBad, + "LIBVIRT_DEFAULT_URI=test:///default?bad_uri", + "VIRSH_DEFAULT_CONNECT_URI=test:///default?bad_uri", + NULL, + }; + + const char *myargv[] = { + abs_top_builddir "/tools/virsh", + "--connect", "test:///default?good_uri", + uriTest, + NULL, + }; + + info.testname = "uriprecedence-param"; + info.env = myenv; + info.argv = myargv; + + DO_TEST_INFO(&info); + } + } + VIR_FREE(custom_uri); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/virshtestdata/uriprecedence-LIBVIRT_DEFAULT_URI.out b/tests/virshtestdata/uriprecedence-LIBVIRT_DEFAULT_URI.out new file mode 100644 index 0000000000..1d665485ad --- /dev/null +++ b/tests/virshtestdata/uriprecedence-LIBVIRT_DEFAULT_URI.out @@ -0,0 +1,5 @@ +test:///default?good_uri + + +test:///default?good_uri + diff --git a/tests/virshtestdata/uriprecedence-VIRSH_DEFAULT_CONNECT_URI.out b/tests/virshtestdata/uriprecedence-VIRSH_DEFAULT_CONNECT_URI.out new file mode 100644 index 0000000000..1d665485ad --- /dev/null +++ b/tests/virshtestdata/uriprecedence-VIRSH_DEFAULT_CONNECT_URI.out @@ -0,0 +1,5 @@ +test:///default?good_uri + + +test:///default?good_uri + diff --git a/tests/virshtestdata/uriprecedence-param.out b/tests/virshtestdata/uriprecedence-param.out new file mode 100644 index 0000000000..1d665485ad --- /dev/null +++ b/tests/virshtestdata/uriprecedence-param.out @@ -0,0 +1,5 @@ +test:///default?good_uri + + +test:///default?good_uri + diff --git a/tests/virshtestdata/uriprecedence-xdg-config.out b/tests/virshtestdata/uriprecedence-xdg-config.out new file mode 100644 index 0000000000..1d665485ad --- /dev/null +++ b/tests/virshtestdata/uriprecedence-xdg-config.out @@ -0,0 +1,5 @@ +test:///default?good_uri + + +test:///default?good_uri + diff --git a/tests/virshtestdata/uriprecedence-xdg/bad/libvirt/libvirt.conf b/tests/virshtestdata/uriprecedence-xdg/bad/libvirt/libvirt.conf new file mode 100644 index 0000000000..bcc732efd5 --- /dev/null +++ b/tests/virshtestdata/uriprecedence-xdg/bad/libvirt/libvirt.conf @@ -0,0 +1 @@ +uri_default="test:///default?bad_uri" diff --git a/tests/virshtestdata/uriprecedence-xdg/good/libvirt/libvirt.conf b/tests/virshtestdata/uriprecedence-xdg/good/libvirt/libvirt.conf new file mode 100644 index 0000000000..da94415a7a --- /dev/null +++ b/tests/virshtestdata/uriprecedence-xdg/good/libvirt/libvirt.conf @@ -0,0 +1 @@ +uri_default="test:///default?good_uri" -- 2.44.0

We no longer have any shell-based tests that use it. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/test-lib.sh | 280 ---------------------------------------------- 1 file changed, 280 deletions(-) delete mode 100644 tests/test-lib.sh diff --git a/tests/test-lib.sh b/tests/test-lib.sh deleted file mode 100644 index 67065a9362..0000000000 --- a/tests/test-lib.sh +++ /dev/null @@ -1,280 +0,0 @@ -# test-lib.sh: source this file; set up for tests - -# Copyright (C) 2008-2013, 2016 Red Hat, Inc. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library. If not, see -# <http://www.gnu.org/licenses/>. -# -# Based on an idea from GNU coreutils - -_scriptdir="$(unset CDPATH; cd $(dirname $0) && pwd)" -test -z "$abs_srcdir" && abs_srcdir=$_scriptdir -test -z "$abs_builddir" && abs_builddir=$_scriptdir -test -z "$abs_top_srcdir" && abs_top_srcdir=$_scriptdir/.. -test -z "$abs_top_builddir" && abs_top_builddir=$_scriptdir/.. -test -z "$LC_ALL" && LC_ALL=C - -# Skip this test if the shell lacks support for functions. -unset function_test -eval 'function_test() { return 11; }; function_test' -if test $? != 11; then - echo "$0: /bin/sh lacks support for functions; skipping this test." 1>&2 - (exit 77); exit 77 -fi - -test_intro() -{ - name=$1 - if test "$verbose" = "0" ; then - echo "TEST: $name" - printf " " - fi -} - -test_skip_case() -{ - counter=$1 - name=$2 - reason=$3 - if test "$verbose" = "0" ; then - mod=`expr \( $counter + 40 - 1 \) % 40` - if test "$counter" != 1 && test "$mod" = 0 ; then - printf " %-3d\n" `expr $counter - 1` - printf " " - fi - printf "_" - else - printf "%3d) %-60s ... SKIP\n" "$counter" "$name" - printf " case skipped: %s\n" "$reason" - fi -} - -test_result() -{ - counter=$1 - name=$2 - status=$3 - if test "$verbose" = "0" ; then - mod=`expr \( $counter + 40 - 1 \) % 40` - if test "$counter" != 1 && test "$mod" = 0 ; then - printf " %-3d\n" `expr $counter - 1` - printf " " - fi - if test "$status" = "0" ; then - printf "." - else - printf "!" - fi - else - if test "$status" = "0" ; then - printf "%3d) %-60s ... OK\n" "$counter" "$name" - else - printf "%3d) %-60s ... FAILED\n" "$counter" "$name" - fi - fi -} - -test_final() -{ - counter=$1 - status=$2 - - if test "$verbose" = "0" ; then - len=`expr 39 - \( \( $counter - 1 \) % 40 \)` - printf "%${len}s" "" - if test "$status" = "0" ; then - printf " %-3d OK\n" $counter - else - printf " %-3d FAILED\n" $counter - fi - fi -} - -skip_test_() -{ - echo "$0: skipping test: $@" 1>&2 - (exit 77); exit 77 -} - -require_acl_() -{ - getfacl --version < /dev/null > /dev/null 2>&1 \ - && setfacl --version < /dev/null > /dev/null 2>&1 \ - || skip_test_ "This test requires getfacl and setfacl." - - id -u bin > /dev/null 2>&1 \ - || skip_test_ "This test requires a local user named bin." -} - -require_ulimit_() -{ - ulimit_works=yes - # Expect to be able to exec a program in 10MB of virtual memory, - # but not in 20KB. I chose "date". It must not be a shell built-in - # function, so you can't use echo, printf, true, etc. - # Of course, in coreutils, I could use $top_builddir/src/true, - # but this should be able to work for other projects, too. - ( ulimit -v 10000; date ) > /dev/null 2>&1 || ulimit_works=no - ( ulimit -v 20; date ) > /dev/null 2>&1 && ulimit_works=no - - test $ulimit_works = no \ - && skip_test_ "this shell lacks ulimit support" -} - -require_readable_root_() -{ - test -r / || skip_test_ "/ is not readable" -} - -# Skip the current test if strace is not available or doesn't work. -require_strace_() -{ - strace -V < /dev/null > /dev/null 2>&1 || - skip_test_ 'no strace program' - - strace -qe unlink echo > /dev/null 2>&1 || - skip_test_ 'strace does not work' -} - -require_built_() -{ - skip_=no - for i in "$@"; do - case " $built_programs " in - *" $i "*) ;; - *) echo "$i: not built" 1>&2; skip_=yes ;; - esac - done - - test $skip_ = yes && skip_test_ "required program(s) not built" -} - -uid_is_privileged_() -{ - # Make sure id -u succeeds. - my_uid=$(id -u) \ - || { echo "$0: cannot run \`id -u'" 1>&2; return 1; } - - # Make sure it gives valid output. - case $my_uid in - 0) ;; - *[!0-9]*) - echo "$0: invalid output (\`$my_uid') from \`id -u'" 1>&2 - return 1 ;; - *) return 1 ;; - esac -} - -skip_if_() -{ - case $1 in - root) skip_test_ must be run as root ;; - non-root) skip_test_ must be run as non-root ;; - *) ;; # FIXME? - esac -} - -require_selinux_() -{ - case `ls -Zd .` in - '? .'|'unlabeled .') - skip_test_ "this system (or maybe just" \ - "the current file system) lacks SELinux support" - ;; - esac -} - -test_expensive() -{ - if test "$VIR_TEST_EXPENSIVE" != 1; then - skip_test_ ' -This test is very expensive, so it is disabled by default. -To change the default, configure with: meson -Dexpensive_tests=enabled -' - fi -} - -require_root_() { uid_is_privileged_ || skip_test_ "must be run as root"; } -skip_if_root_() { uid_is_privileged_ && skip_test_ "must be run as non-root"; } -error_() { echo "$0: $@" 1>&2; (exit 1); exit 1; } -framework_failure() { error_ 'failure in testing framework'; } - -mkfifo_or_skip_() -{ - test $# = 1 || framework_failure - if ! mkfifo "$1"; then - # Make an exception of this case -- usually we interpret framework-creation - # failure as a test failure. However, in this case, when running on a SunOS - # system using a disk NFS mounted from OpenBSD, the above fails like this: - # mkfifo: cannot make fifo `fifo-10558': Not owner - skip_test_ 'NOTICE: unable to create test prerequisites' - fi -} - -# Create mock XDG files/directories to avoid permission problems. -# As it points inside $test_dir_, it is automatically cleaned. -mock_xdg_() -{ - export XDG_CONFIG_HOME="$t_/.config" - export XDG_CACHE_HOME="$t_/.cache" - export XDG_RUNTIME_HOME="$XDG_CACHE_HOME" - - mkdir -p "$XDG_CONFIG_HOME/libvirt" "$XDG_CONFIG_HOME/virsh" - mkdir -p "$XDG_CACHE_HOME/libvirt" "$XDG_CACHE_HOME/virsh" - mkdir -p "$XDG_RUNTIME_HOME/libvirt" "$XDG_RUNTIME_HOME/virsh" -} - -test_dir_=$(pwd) - -this_test_() { echo "./$0" | sed 's,.*/,,'; } -this_test=$(this_test_) - -verbose=0 -if test -n "$VIR_TEST_DEBUG" || test -n "$VIR_TEST_VERBOSE" ; then - verbose=1 -fi - -debug() { :; } - -if test "$VIR_TEST_DEBUG" = "2"; then - debug() { echo "$@"; } -fi - -# This is a stub function that is run upon trap (upon regular exit and -# interrupt). Override it with a per-test function, e.g., to unmount -# a partition, or to undo any other global state changes. -cleanup_() { :; } - -t_=$("mktemp" "-d" "$test_dir_/lv-$this_test.XXXXXXXXXX") \ - || error_ "failed to create temporary directory in $test_dir_" - -# Run each test from within a temporary sub-directory named after the -# test itself, and arrange to remove it upon exception or normal exit. -trap 'st=$?; cleanup_; d='"$t_"'; - cd '"$test_dir_"' && chmod -R u+rwx "$d" && rm -rf "$d" && exit $st' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -cd "$t_" || error_ "failed to cd to $t_" - -if ( diff --version < /dev/null 2>&1 | grep GNU ) > /dev/null 2>&1; then - compare() { diff -u "$@"; } -elif ( cmp --version < /dev/null 2>&1 | grep GNU ) > /dev/null 2>&1; then - compare() { cmp -s "$@"; } -else - compare() { cmp "$@"; } -fi - -# Local Variables: -# indent-tabs-mode: nil -# End: -- 2.44.0

On a Thursday in 2024, Peter Krempa wrote:
Part 3 was supposed to be the refactor of the command parser but since I wanted to add few tests I've noticed that there's a lot of old cruft and many tests are skipped.
This series refactors virshtest and optimizes it to run multiple commands with one virsh instance. Doing this allows us to do more testing in the same run time allowing us to reduce the amount of "expensive" tests.
Further down this removes all of the 'shell' test infra which was used for virsh.
Peter Krempa (35): virshtest: Prepare for testing against output files [..] tests: Drop 'test-lib.sh'
build-aux/syntax-check.mk | 6 +- docs/manpages/virsh.rst | 17 +- src/meson.build | 5 + [..] tools/virsh-snapshot.c | 18 +- tools/vsh.c | 5 - 115 files changed, 2352 insertions(+), 2852 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (4)
-
Andrea Bolognani
-
Daniel P. Berrangé
-
Ján Tomko
-
Peter Krempa