mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-09 09:14:57 +00:00
The daemon-conf test would fail on my system if there was a system libvirtd running. In the course of troubleshooting that problem, I discovered that the daemon-conf script would always fail if run by itself because it found the line: \# that each "PARAMETER = VALUE" line in this file have the parameter which it mistook for a line containing a parameter. I have changed the test to avoid mistaking a line containing \"PARAMETER = VALUE\" for a parameter line. The corrupted config tests turned out to be failing because the test daemon was discovering the pid file from the running daemon and exiting before it processed the test config file. Specifying the pid file for the corrupt config tests in the same way as for the valid config test solved that problem.
99 lines
2.9 KiB
Bash
Executable File
99 lines
2.9 KiB
Bash
Executable File
#!/bin/sh
|
|
# Get coverage of libvirtd's config-parsing code.
|
|
|
|
test -z "$srcdir" && srcdir=$(pwd)
|
|
LC_ALL=C
|
|
. "$srcdir/test-lib.sh"
|
|
|
|
if test "$verbose" = yes; then
|
|
$abs_top_builddir/daemon/libvirtd --version
|
|
fi
|
|
|
|
test_intro "$this_test"
|
|
|
|
test -z "$CONFIG_HEADER" && CONFIG_HEADER="$abs_top_builddir/config.h"
|
|
|
|
grep '^#define WITH_QEMU 1' "$CONFIG_HEADER" > /dev/null ||
|
|
skip_test_ "configured without QEMU support"
|
|
|
|
conf="$abs_top_srcdir/daemon/libvirtd.conf"
|
|
|
|
# Ensure that each commented out PARAMETER = VALUE line has the expected form.
|
|
grep -v '\"PARAMETER = VALUE\"' "$conf" | grep '[a-z_] *= *[^ ]' | grep -vE '^#[a-z_]+ = ' \
|
|
&& { echo "$0: found unexpected lines (above) in $conf" 1>&2; exit 1; }
|
|
|
|
# Start with the sample libvirtd.conf file, uncommenting all real directives.
|
|
sed -n 's/^#\([^ #]\)/\1/p' "$conf" > tmp.conf
|
|
|
|
# Iterate through that list of directives, corrupting one RHS at a
|
|
# time and running libvirtd with the resulting config. Each libvirtd
|
|
# invocation must fail.
|
|
n=$(wc -l < tmp.conf)
|
|
i=0
|
|
fail=0
|
|
while :; do
|
|
i=$(expr $i + 1)
|
|
|
|
param_name=$(sed -n "$i"'s/ = .*//p' tmp.conf)
|
|
rhs=$(sed -n "$i"'s/.* = \(.*\)/\1/p' tmp.conf)
|
|
f=in$i.conf
|
|
case $rhs in
|
|
# Change an RHS that starts with '"' or '[' to "3".
|
|
[[\"]*) sed "$i"'s/ = [["].*/ = 3/' tmp.conf > $f;;
|
|
# Change an RHS that starts with a digit to the string '"foo"'.
|
|
[0-9]*) sed "$i"'s/ = [0-9].*/ = "foo"/' tmp.conf > $f;;
|
|
esac
|
|
|
|
# Run libvirtd, expecting it to fail.
|
|
$abs_top_builddir/daemon/libvirtd --pid-file=pid-file --config=$f 2> err && fail=1
|
|
|
|
case $rhs in
|
|
# '"'*) msg='should be a string';;
|
|
'"'*) msg='invalid type: got long; expected string';;
|
|
[0-9]*) msg='invalid type: got string; expected long';;
|
|
'['*) msg='must be a string or list of strings';;
|
|
*) echo "unexpected RHS: $rhs" 1>&2; fail=1;;
|
|
esac
|
|
|
|
test $i = $n && break
|
|
|
|
# Check that the diagnostic we want appears
|
|
grep "$msg" err 1>/dev/null 2>&1
|
|
RET=$?
|
|
test_result $i "corrupted config $param_name" $RET
|
|
test "$RET" = "0" || fail=1
|
|
done
|
|
|
|
# Run with the unmodified config file.
|
|
sleep_secs=2
|
|
|
|
# Be careful to specify a non-default socket directory:
|
|
sed 's,^unix_sock_dir.*,unix_sock_dir="'"$(pwd)"'",' tmp.conf > k || fail=1
|
|
mv k tmp.conf || fail=1
|
|
|
|
# Also, specify a test-specific log directory:
|
|
sed 's,^log_outputs.*,log_outputs="3:file:'"$(pwd)/log"'",' tmp.conf > k \
|
|
|| fail=1
|
|
mv k tmp.conf || fail=1
|
|
|
|
$abs_top_builddir/daemon/libvirtd --pid-file=pid-file --config=tmp.conf > log 2>&1 & pid=$!
|
|
sleep $sleep_secs
|
|
kill $pid
|
|
|
|
RET=0
|
|
# Expect an orderly shut-down and successful exit.
|
|
wait $pid || RET=1
|
|
|
|
test_result $i "valid config file (sleeping $sleep_secs seconds)" $RET
|
|
test $RET = 0 || fail=1
|
|
|
|
test_final $i $fail
|
|
|
|
# "cat log" would print this for non-root:
|
|
# Cannot set group when not running as root
|
|
# Shutting down on signal 15
|
|
# And normally, we'd require that output, but obviously
|
|
# it'd be different for root.
|
|
|
|
exit $fail
|