mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
virshtest: Adapt 'event' option arg handling tests from 'virsh-optparse'
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> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
2aec9b399b
commit
06f816cb7b
@ -695,7 +695,6 @@ if conf.has('WITH_LIBVIRTD')
|
|||||||
'virsh-cpuset',
|
'virsh-cpuset',
|
||||||
'virsh-define-dev-segfault',
|
'virsh-define-dev-segfault',
|
||||||
'virsh-int-overflow',
|
'virsh-int-overflow',
|
||||||
'virsh-optparse',
|
|
||||||
'virsh-output',
|
'virsh-output',
|
||||||
'virsh-read-bufsiz',
|
'virsh-read-bufsiz',
|
||||||
'virsh-read-non-seekable',
|
'virsh-read-non-seekable',
|
||||||
|
@ -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
|
|
@ -83,6 +83,7 @@ struct testInfo {
|
|||||||
const char *testname; /* used to generate output filename */
|
const char *testname; /* used to generate output filename */
|
||||||
const char *filter;
|
const char *filter;
|
||||||
const char *const *argv;
|
const char *const *argv;
|
||||||
|
bool expensive;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int testCompare(const void *data)
|
static int testCompare(const void *data)
|
||||||
@ -90,6 +91,9 @@ static int testCompare(const void *data)
|
|||||||
const struct testInfo *info = data;
|
const struct testInfo *info = data;
|
||||||
g_autofree char *outfile = NULL;
|
g_autofree char *outfile = NULL;
|
||||||
|
|
||||||
|
if (info->expensive && virTestGetExpensive() == 0)
|
||||||
|
return EXIT_AM_SKIP;
|
||||||
|
|
||||||
if (info->testname) {
|
if (info->testname) {
|
||||||
outfile = g_strdup_printf("%s/virshtestdata/%s.out",
|
outfile = g_strdup_printf("%s/virshtestdata/%s.out",
|
||||||
abs_srcdir, info->testname);
|
abs_srcdir, info->testname);
|
||||||
@ -107,14 +111,14 @@ mymain(void)
|
|||||||
custom_uri = g_strdup_printf("test://%s/../examples/xml/test/testnode.xml",
|
custom_uri = g_strdup_printf("test://%s/../examples/xml/test/testnode.xml",
|
||||||
abs_srcdir);
|
abs_srcdir);
|
||||||
|
|
||||||
# define DO_TEST_SCRIPT(testname_, testfilter, ...) \
|
# define DO_TEST_SCRIPT_FULL(testname_, expensive, testfilter, ...) \
|
||||||
{ \
|
{ \
|
||||||
const char *testname = testname_; \
|
const char *testname = testname_; \
|
||||||
g_autofree char *infile = g_strdup_printf("%s/virshtestdata/%s.in", \
|
g_autofree char *infile = g_strdup_printf("%s/virshtestdata/%s.in", \
|
||||||
abs_srcdir, testname); \
|
abs_srcdir, testname); \
|
||||||
const char *myargv[] = { __VA_ARGS__, NULL, NULL }; \
|
const char *myargv[] = { __VA_ARGS__, NULL, NULL }; \
|
||||||
const char **tmp = myargv; \
|
const char **tmp = myargv; \
|
||||||
const struct testInfo info = { testname, testfilter, myargv }; \
|
const struct testInfo info = { testname, testfilter, myargv, expensive }; \
|
||||||
g_autofree char *scriptarg = NULL; \
|
g_autofree char *scriptarg = NULL; \
|
||||||
if (virFileReadAll(infile, 256 * 1024, &scriptarg) < 0) { \
|
if (virFileReadAll(infile, 256 * 1024, &scriptarg) < 0) { \
|
||||||
fprintf(stderr, "\nfailed to load '%s'\n", infile); \
|
fprintf(stderr, "\nfailed to load '%s'\n", infile); \
|
||||||
@ -127,6 +131,9 @@ mymain(void)
|
|||||||
ret = -1; \
|
ret = -1; \
|
||||||
} while (0);
|
} 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-default", NULL, VIRSH_DEFAULT);
|
||||||
DO_TEST_SCRIPT("info-custom", NULL, VIRSH_CUSTOM);
|
DO_TEST_SCRIPT("info-custom", NULL, VIRSH_CUSTOM);
|
||||||
DO_TEST_SCRIPT("domain-id", "\nCPU time:", VIRSH_CUSTOM);
|
DO_TEST_SCRIPT("domain-id", "\nCPU time:", VIRSH_CUSTOM);
|
||||||
@ -137,7 +144,7 @@ mymain(void)
|
|||||||
do { \
|
do { \
|
||||||
const char *testname = testname_; \
|
const char *testname = testname_; \
|
||||||
const char *myargv[] = { __VA_ARGS__, NULL }; \
|
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) \
|
if (virTestRun(testname, testCompare, &info) < 0) \
|
||||||
ret = -1; \
|
ret = -1; \
|
||||||
} while (0)
|
} while (0)
|
||||||
@ -202,6 +209,9 @@ mymain(void)
|
|||||||
DO_TEST_SCRIPT("argument-assignment", NULL, VIRSH_DEFAULT, "-k0", "-d0");
|
DO_TEST_SCRIPT("argument-assignment", NULL, VIRSH_DEFAULT, "-k0", "-d0");
|
||||||
DO_TEST_SCRIPT("snapshot-create-args", NULL, VIRSH_DEFAULT, "-q");
|
DO_TEST_SCRIPT("snapshot-create-args", NULL, VIRSH_DEFAULT, "-q");
|
||||||
DO_TEST_SCRIPT("numeric-parsing", NULL, VIRSH_DEFAULT);
|
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);
|
VIR_FREE(custom_uri);
|
||||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
|
26
tests/virshtestdata/numeric-parsing-event.in
Normal file
26
tests/virshtestdata/numeric-parsing-event.in
Normal file
@ -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
|
29
tests/virshtestdata/numeric-parsing-event.out
Normal file
29
tests/virshtestdata/numeric-parsing-event.out
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
Test the <timeout> option (numeric option converted to ms)
|
||||||
|
Non-numeric value
|
||||||
|
error: Numeric value 'abc' for <timeout> 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 <timeout> option is malformed or out of range
|
||||||
|
|
||||||
|
Numeric value with invalid suffix
|
||||||
|
error: Numeric value '42WB' for <timeout> option is malformed or out of range
|
||||||
|
|
||||||
|
Numeric value with valid suffix. Suffixes are not supported for
|
||||||
|
the <timeout> option, so this value is rejected
|
||||||
|
error: Numeric value '42MB' for <timeout> option is malformed or out of range
|
||||||
|
|
||||||
|
Negative value
|
||||||
|
error: Numeric value '-1' for <timeout> 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 <timeout> 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
|
Loading…
Reference in New Issue
Block a user