[PATCH 19/35] virshtest: Adapt 'event' option arg handling tests from 'virsh-optparse'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux