2007-12-11 21:20:13 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Get coverage of libvirtd's config-parsing code.
|
|
|
|
|
2009-09-23 07:32:10 +00:00
|
|
|
test -z "$srcdir" && srcdir=$(pwd)
|
2009-11-30 19:01:31 +00:00
|
|
|
LC_ALL=C
|
|
|
|
. "$srcdir/test-lib.sh"
|
2009-09-23 07:32:10 +00:00
|
|
|
|
2009-11-30 19:01:31 +00:00
|
|
|
if test "$verbose" = yes; then
|
2009-09-23 07:32:10 +00:00
|
|
|
$abs_top_builddir/daemon/libvirtd --version
|
2008-12-01 15:04:28 +00:00
|
|
|
fi
|
|
|
|
|
2009-11-30 19:01:31 +00:00
|
|
|
test_intro "$this_test"
|
2009-09-23 07:32:10 +00:00
|
|
|
|
|
|
|
test -z "$CONFIG_HEADER" && CONFIG_HEADER="$abs_top_builddir/config.h"
|
2009-02-17 10:23:48 +00:00
|
|
|
|
2009-09-23 07:32:10 +00:00
|
|
|
grep '^#define WITH_QEMU 1' "$CONFIG_HEADER" > /dev/null ||
|
2009-02-17 10:23:48 +00:00
|
|
|
skip_test_ "configured without QEMU support"
|
2007-12-11 21:20:13 +00:00
|
|
|
|
2009-09-15 14:49:29 +00:00
|
|
|
conf="$abs_top_srcdir/daemon/libvirtd.conf"
|
2008-12-01 15:04:28 +00:00
|
|
|
|
|
|
|
# Ensure that each commented out PARAMETER = VALUE line has the expected form.
|
|
|
|
grep '[a-z_] *= *[^ ]' "$conf" | grep -vE '^#[a-z_]+ = ' \
|
|
|
|
&& { echo "$0: found unexpected lines (above) in $conf" 1>&2; exit 1; }
|
|
|
|
|
2007-12-11 21:20:13 +00:00
|
|
|
# Start with the sample libvirtd.conf file, uncommenting all real directives.
|
2008-12-01 15:04:28 +00:00
|
|
|
sed -n 's/^#\([^ #]\)/\1/p' "$conf" > tmp.conf
|
2007-12-11 21:20:13 +00:00
|
|
|
|
|
|
|
# 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)
|
2009-11-30 19:01:31 +00:00
|
|
|
i=0
|
|
|
|
fail=0
|
2007-12-11 21:20:13 +00:00
|
|
|
while :; do
|
2009-11-30 19:01:31 +00:00
|
|
|
i=$(expr $i + 1)
|
|
|
|
|
2007-12-11 21:20:13 +00:00
|
|
|
param_name=$(sed -n "$i"'s/ = .*//p' tmp.conf)
|
|
|
|
rhs=$(sed -n "$i"'s/.* = \(.*\)/\1/p' tmp.conf)
|
|
|
|
f=in$i.conf
|
2008-12-01 15:04:28 +00:00
|
|
|
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.
|
2009-09-23 07:32:10 +00:00
|
|
|
$abs_top_builddir/daemon/libvirtd --config=$f 2> err && fail=1
|
2008-12-01 15:04:28 +00:00
|
|
|
|
2007-12-11 21:20:13 +00:00
|
|
|
case $rhs in
|
|
|
|
# '"'*) msg='should be a string';;
|
|
|
|
'"'*) msg='invalid type: got long; expected string';;
|
2008-12-01 15:04:28 +00:00
|
|
|
[0-9]*) msg='invalid type: got string; expected long';;
|
2007-12-11 21:20:13 +00:00
|
|
|
'['*) msg='must be a string or list of strings';;
|
|
|
|
*) echo "unexpected RHS: $rhs" 1>&2; fail=1;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
test $i = $n && break
|
|
|
|
|
2009-03-04 13:04:06 +00:00
|
|
|
# Check that the diagnostic we want appears
|
|
|
|
grep "$msg" err 1>/dev/null 2>&1
|
|
|
|
RET=$?
|
2009-11-30 19:01:31 +00:00
|
|
|
test_result $i "corrupted config $param_name" $RET
|
2009-03-04 13:04:06 +00:00
|
|
|
test "$RET" = "0" || fail=1
|
2007-12-11 21:20:13 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Run with the unmodified config file.
|
2008-12-01 15:04:28 +00:00
|
|
|
sleep_secs=2
|
2009-03-02 20:01:26 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2009-09-23 07:32:10 +00:00
|
|
|
$abs_top_builddir/daemon/libvirtd --pid-file=pid-file --config=tmp.conf > log 2>&1 & pid=$!
|
2008-12-01 15:04:28 +00:00
|
|
|
sleep $sleep_secs
|
2007-12-11 21:20:13 +00:00
|
|
|
kill $pid
|
|
|
|
|
2009-11-30 19:01:31 +00:00
|
|
|
RET=0
|
2007-12-11 21:20:13 +00:00
|
|
|
# Expect an orderly shut-down and successful exit.
|
2009-11-30 19:01:31 +00:00
|
|
|
wait $pid || RET=1
|
|
|
|
|
|
|
|
test_result $i "valid config file (sleeping $sleep_secs seconds)" $RET
|
|
|
|
test $RET = 0 || fail=1
|
|
|
|
|
|
|
|
test_final $i $fail
|
2007-12-11 21:20:13 +00:00
|
|
|
|
|
|
|
# "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
|