]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virshtest: Adapt numeric option arg handling tests from 'virsh-optparse'
authorPeter Krempa <pkrempa@redhat.com>
Mon, 18 Mar 2024 14:38:39 +0000 (15:38 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 2 Apr 2024 12:24:30 +0000 (14:24 +0200)
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>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/virsh-optparse
tests/virshtest.c
tests/virshtestdata/numeric-parsing.in [new file with mode: 0644]
tests/virshtestdata/numeric-parsing.out [new file with mode: 0644]

index 10fdf7727ea68a545c499067aca08c098efe31e4..e9dccdd027338842be4e841c030c2adf37b6a26a 100755 (executable)
@@ -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
index 453b1d7a9e138b006bbeacda87bc1b4476ac5264..08c43205bb0d4e352acfc40030a1c124e47181c1 100644 (file)
@@ -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);
 
     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 (file)
index 0000000..d099236
--- /dev/null
@@ -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 (file)
index 0000000..2ffbab6
--- /dev/null
@@ -0,0 +1,41 @@
+Test a regular numeric option
+Non-numeric value
+error: Numeric value 'abc' for <start> option is malformed or out of range
+
+Numeric value with invalid suffix
+error: Numeric value '42WB' for <start> option is malformed or out of range
+
+Numeric value with valid suffix. Suffixes are not supported for
+regular numeric options, so this value is rejected
+error: Numeric value '42MB' for <start> option is malformed or out of range
+
+Numeric value bigger than INT_MAX
+error: Numeric value '2147483648' for <start> option is malformed or out of range
+
+Negative numeric value. The value is not valid for the command
+we are testing, but it has been parsed correctly
+error: Invalid value for start CPU
+
+Test a scaled numeric option
+Non-numeric value
+error: Scaled numeric value 'abc' for <size> option is malformed or out of range
+
+Numeric value with invalid suffix
+error: Scaled numeric value '42WB' for <size> option is malformed or out of range
+error: invalid argument: unknown suffix 'WB'
+
+Numeric value with valid suffix
+
+Numeric value bigger than INT_MAX. No failure here because
+scaled numeric values are unsigned long long
+
+Negative numeric value
+error: Scaled numeric value '-1' for <size> option is malformed or out of range
+
+Zero. The value is not valid for the command were testing, but
+it has been parsed correctly
+error: Unable to change MaxMemorySize
+error: memory in virDomainSetMemoryFlags must not be zero
+
+Numeric value
+