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 -# . - -. "$(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 option (numeric option converted to ms) - -# Non-numeric value -cat <<\EOF > exp-err || framework_failure -error: Numeric value 'abc' for 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 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 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 option, so this value is rejected -cat <<\EOF > exp-err || framework_failure -error: Numeric value '42MB' for 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 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 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 08c43205bb..34217f1db1 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); + /* 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); 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 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 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..7bca2bbc14 --- /dev/null +++ b/tests/virshtestdata/numeric-parsing-event.out @@ -0,0 +1,29 @@ +Test the option (numeric option converted to ms) +Non-numeric value +error: Numeric value 'abc' for option is malformed or out of range + +Numeric value that is too big to be converted to ms and still +fit inside an int +error: Numeric value '2147484' for option is malformed or out of range + +Numeric value with invalid suffix +error: Numeric value '42WB' for option is malformed or out of range + +Numeric value with valid suffix. Suffixes are not supported for +the option, so this value is rejected +error: Numeric value '42MB' for option is malformed or out of range + +Negative value +error: Numeric value '-1' for option is malformed or out of range + +Zero. This is not a valid timeout, but the value is parsed +correctly +error: Numeric value '0' for option is malformed or out of range + +Numeric value. No events will be received and the command will +fail after a second, but the value has been parsed correctly +event loop timed out +events received: 0 + + +## Exit code: 1