#!/bin/sh
# Run the upstream system tests in a container. Destructive tests will be run in
# a VM as they may adjust/step the system clock, block the RTC, etc.
# In case of failure, test’s logs will be put into the directory specified by
# the $AUTOPKGTEST_ARTIFACTS environment variable.

set -e

testdir=$PWD/test/system
logdir="$testdir/tmp/*"

# some tests need chrony installed, but make sure to avoid the test daemon is
# fighting with the systems chrony/systemd-timesyncd services over the clock
systemctl stop systemd-timesyncd.service 2>/dev/null || true
systemctl stop chrony.service 2>/dev/null || true

run_test() {
     cd "$testdir" && ./run "$@"
}

artifacts() {
    cp $logdir "$AUTOPKGTEST_ARTIFACTS" && exit 1
}

run_test "$@" || artifacts
