1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-09-19 01:45:00 +03:00

test: Write state and log files into $BUILD_DIR

This avoids clobbering the source tree with .testdir/test.log files and
makes the tests work in situations where the source tree is read-only.
This commit is contained in:
Martin Pitt
2017-08-07 17:30:11 +02:00
parent 7a0019d373
commit 22077c9c91

View File

@@ -23,6 +23,10 @@ fi
BASICTOOLS="sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm" BASICTOOLS="sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm"
DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname find" DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname find"
STATEDIR="${BUILD_DIR:-.}/test/$(basename $(dirname $(realpath $0)))"
STATEFILE="$STATEDIR/.testdir"
TESTLOG="$STATEDIR/test.log"
function find_qemu_bin() { function find_qemu_bin() {
# SUSE and Red Hat call the binary qemu-kvm # SUSE and Red Hat call the binary qemu-kvm
# Debian and Gentoo call it kvm # Debian and Gentoo call it kvm
@@ -626,7 +630,6 @@ inst_libs() {
} }
import_testdir() { import_testdir() {
STATEFILE=".testdir"
[[ -e $STATEFILE ]] && . $STATEFILE [[ -e $STATEFILE ]] && . $STATEFILE
if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then
TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX) TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX)
@@ -1421,6 +1424,8 @@ do_test() {
[[ -d $usrlibdir ]] && libdirs+=" $usrlibdir" && break [[ -d $usrlibdir ]] && libdirs+=" $usrlibdir" && break
done done
mkdir -p "$STATEDIR"
import_testdir import_testdir
import_initdir import_initdir
@@ -1444,7 +1449,7 @@ do_test() {
echo "TEST CLEANUP: $TEST_DESCRIPTION" echo "TEST CLEANUP: $TEST_DESCRIPTION"
test_cleanup test_cleanup
rm -fr "$TESTDIR" rm -fr "$TESTDIR"
rm -f .testdir rm -f "$STATEFILE"
exit $?;; exit $?;;
--all) --all)
echo -n "TEST: $TEST_DESCRIPTION "; echo -n "TEST: $TEST_DESCRIPTION ";
@@ -1453,16 +1458,16 @@ do_test() {
ret=$? ret=$?
test_cleanup test_cleanup
rm -fr "$TESTDIR" rm -fr "$TESTDIR"
rm -f .testdir rm -f "$STATEFILE"
exit $ret exit $ret
) </dev/null >test.log 2>&1 ) </dev/null >"$TESTLOG" 2>&1
ret=$? ret=$?
if [ $ret -eq 0 ]; then if [ $ret -eq 0 ]; then
rm test.log rm "$TESTLOG"
echo "[OK]" echo "[OK]"
else else
echo "[FAILED]" echo "[FAILED]"
echo "see $(pwd)/test.log" echo "see $TESTLOG"
fi fi
exit $ret;; exit $ret;;
*) break ;; *) break ;;