test: allow separate lib/log/run directories in system tests

This commit is contained in:
Miroslav Lichvar 2019-04-25 18:19:00 +02:00
parent a85f63cc15
commit 66a42fa493

View file

@ -15,7 +15,11 @@
export LC_ALL=C export LC_ALL=C
export PATH=${CHRONY_PATH:-../..}:$PATH export PATH=${CHRONY_PATH:-../..}:$PATH
export TEST_DIR=${TEST_DIR:-$(pwd)/tmp}
TEST_DIR=${TEST_DIR:-$(pwd)/tmp}
TEST_LIBDIR=${TEST_LIBDIR:-$TEST_DIR}
TEST_LOGDIR=${TEST_LOGDIR:-$TEST_DIR}
TEST_RUNDIR=${TEST_RUNDIR:-$TEST_DIR}
test_start() { test_start() {
check_chronyd_features NTP CMDMON || test_skip "NTP/CMDMON support disabled" check_chronyd_features NTP CMDMON || test_skip "NTP/CMDMON support disabled"
@ -25,6 +29,12 @@ test_start() {
rm -rf "$TEST_DIR" rm -rf "$TEST_DIR"
mkdir -p "$TEST_DIR" && chmod 700 "$TEST_DIR" || test_skip "could not create $TEST_DIR" mkdir -p "$TEST_DIR" && chmod 700 "$TEST_DIR" || test_skip "could not create $TEST_DIR"
[ -d "$TEST_LIBDIR" ] || test_skip "missing $TEST_LIBDIR"
[ -d "$TEST_LOGDIR" ] || test_skip "missing $TEST_LOGDIR"
[ -d "$TEST_RUNDIR" ] || test_skip "missing $TEST_RUNDIR"
rm -f "$TEST_LIBDIR"/* "$TEST_LOGDIR"/* "$TEST_RUNDIR"/*
if [ "$user" != "root" ]; then if [ "$user" != "root" ]; then
id -u "$user" > /dev/null 2> /dev/null || test_skip "missing user $user" id -u "$user" > /dev/null 2> /dev/null || test_skip "missing user $user"
chown "$user:$(id -g "$user")" "$TEST_DIR" || test_skip "could not chown $TEST_DIR" chown "$user:$(id -g "$user")" "$TEST_DIR" || test_skip "could not chown $TEST_DIR"
@ -151,15 +161,15 @@ get_conffile() {
} }
get_pidfile() { get_pidfile() {
echo "$TEST_DIR/chronyd.pid" echo "$TEST_RUNDIR/chronyd.pid"
} }
get_logfile() { get_logfile() {
echo "$TEST_DIR/chronyd.log" echo "$TEST_LOGDIR/chronyd.log"
} }
get_cmdsocket() { get_cmdsocket() {
echo "$TEST_DIR/chronyd.sock" echo "$TEST_RUNDIR/chronyd.sock"
} }
# Find a free port in the 10000-20000 range (their use is racy) # Find a free port in the 10000-20000 range (their use is racy)
@ -181,7 +191,7 @@ generate_chrony_conf() {
ntpport=$(get_free_port) ntpport=$(get_free_port)
cmdport=$(get_free_port) cmdport=$(get_free_port)
echo "0.0 10000" > "$TEST_DIR/driftfile" echo "0.0 10000" > "$TEST_LIBDIR/driftfile"
echo "1 MD5 abcdefghijklmnopq" > "$TEST_DIR/keys" echo "1 MD5 abcdefghijklmnopq" > "$TEST_DIR/keys"
echo "0.0" > "$TEST_DIR/tempcomp" echo "0.0" > "$TEST_DIR/tempcomp"
@ -204,15 +214,15 @@ generate_chrony_conf() {
[ "$server" = "127.0.0.1" ] && echo "bindacqaddress $server" [ "$server" = "127.0.0.1" ] && echo "bindacqaddress $server"
echo "bindaddress 127.0.0.1" echo "bindaddress 127.0.0.1"
echo "bindcmdaddress 127.0.0.1" echo "bindcmdaddress 127.0.0.1"
echo "dumpdir $TEST_DIR" echo "dumpdir $TEST_RUNDIR"
echo "logdir $TEST_DIR" echo "logdir $TEST_LOGDIR"
echo "log tempcomp rawmeasurements refclocks statistics tracking rtc" echo "log tempcomp rawmeasurements refclocks statistics tracking rtc"
echo "logbanner 0" echo "logbanner 0"
echo "smoothtime 100.0 0.001" echo "smoothtime 100.0 0.001"
echo "include /dev/null" echo "include /dev/null"
echo "keyfile $TEST_DIR/keys" echo "keyfile $TEST_DIR/keys"
echo "driftfile $TEST_DIR/driftfile" echo "driftfile $TEST_LIBDIR/driftfile"
echo "tempcomp $TEST_DIR/tempcomp 0.1 0 0 0 0" echo "tempcomp $TEST_DIR/tempcomp 0.1 0 0 0 0"
) > "$(get_conffile)" ) > "$(get_conffile)"
@ -302,11 +312,11 @@ check_chronyd_message_count() {
check_chronyd_files() { check_chronyd_files() {
test_message 1 0 "checking chronyd files" test_message 1 0 "checking chronyd files"
grep -q " $server .* 111 111 1111 " "$TEST_DIR/measurements.log" && \ grep -q " $server .* 111 111 1111 " "$TEST_LOGDIR/measurements.log" && \
grep -q " $server " "$TEST_DIR/statistics.log" && \ grep -q " $server " "$TEST_LOGDIR/statistics.log" && \
grep -q " $server " "$TEST_DIR/tracking.log" && \ grep -q " $server " "$TEST_LOGDIR/tracking.log" && \
[ -f "$TEST_DIR/tempcomp.log" ] && [ "$(wc -l < "$TEST_DIR/tempcomp.log")" -ge 2 ] && \ [ -f "$TEST_LOGDIR/tempcomp.log" ] && [ "$(wc -l < "$TEST_LOGDIR/tempcomp.log")" -ge 2 ] && \
[ -f "$TEST_DIR/$server.dat" ] && [ "$(wc -l < "$TEST_DIR/$server.dat")" -ge 5 ] && \ [ -f "$TEST_RUNDIR/$server.dat" ] && [ "$(wc -l < "$TEST_RUNDIR/$server.dat")" -ge 5 ] && \
test_ok || test_bad test_ok || test_bad
} }