2018-09-19 08:30:29 +03:00
#!/bin/bash
set -e
TEST_DESCRIPTION = "Run unit tests under containers"
RUN_IN_UNPRIVILEGED_CONTAINER = yes
. $TEST_BASE_DIR /test-functions
check_result_nspawn( ) {
local _ret = 1
[ [ -e $TESTDIR /$1 /testok ] ] && _ret = 0
if [ [ -s $TESTDIR /$1 /failed ] ] ; then
_ret = $(( $_ret + 1 ))
echo "=== Failed test log ==="
cat $TESTDIR /$1 /failed
else
if [ [ -s $TESTDIR /$1 /skipped ] ] ; then
echo "=== Skipped test log =="
cat $TESTDIR /$1 /skipped
fi
if [ [ -s $TESTDIR /$1 /testok ] ] ; then
echo "=== Passed tests ==="
cat $TESTDIR /$1 /testok
fi
fi
cp -a $TESTDIR /$1 /var/log/journal $TESTDIR
[ [ -n " $TIMED_OUT " ] ] && _ret = $(( $_ret + 1 ))
return $_ret
}
check_result_qemu( ) {
local _ret = 1
2019-08-15 16:39:31 +03:00
mkdir -p $initdir
mount ${ LOOPDEV } p1 $initdir
[ [ -e $initdir /testok ] ] && _ret = 0
if [ [ -s $initdir /failed ] ] ; then
2018-09-19 08:30:29 +03:00
_ret = $(( $_ret + 1 ))
echo "=== Failed test log ==="
2019-08-15 16:39:31 +03:00
cat $initdir /failed
2018-09-19 08:30:29 +03:00
else
2019-08-15 16:39:31 +03:00
if [ [ -s $initdir /skipped ] ] ; then
2018-09-19 08:30:29 +03:00
echo "=== Skipped test log =="
2019-08-15 16:39:31 +03:00
cat $initdir /skipped
2018-09-19 08:30:29 +03:00
fi
2019-08-15 16:39:31 +03:00
if [ [ -s $initdir /testok ] ] ; then
2018-09-19 08:30:29 +03:00
echo "=== Passed tests ==="
2019-08-15 16:39:31 +03:00
cat $initdir /testok
2018-09-19 08:30:29 +03:00
fi
fi
2019-08-15 16:39:31 +03:00
cp -a $initdir /var/log/journal $TESTDIR
umount $initdir
2018-09-19 08:30:29 +03:00
[ [ -n " $TIMED_OUT " ] ] && _ret = $(( $_ret + 1 ))
return $_ret
}
test_setup( ) {
if type -P meson && [ [ " $( meson configure $BUILD_DIR | grep install-tests | awk '{ print $2 }' ) " != "true" ] ] ; then
dfatal "Needs to be built with -Dinstall-tests=true"
exit 1
fi
2019-07-12 18:47:26 +03:00
create_empty_image_rootdir
2018-09-19 08:30:29 +03:00
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL = 5
eval $( udevadm info --export --query= env --name= ${ LOOPDEV } p2)
for i in getfacl dirname basename capsh cut rev stat mktemp rmdir ionice unshare uname tr awk getent diff xzcat lz4cat; do
inst_binary $i
done
inst /etc/hosts
setup_basic_environment
install_keymaps yes
install_zoneinfo
2019-03-05 15:50:28 +03:00
# Install nproc to determine # of CPUs for correct parallelization
inst_binary nproc
2018-09-19 08:30:29 +03:00
# setup the testsuite service
cat >$initdir /etc/systemd/system/testsuite.service <<EOF
[ Unit]
Description = Testsuite service
[ Service]
ExecStart = /testsuite.sh
Type = oneshot
EOF
cp testsuite.sh $initdir /
setup_testsuite
2019-07-08 22:11:32 +03:00
)
2018-09-19 08:30:29 +03:00
setup_nspawn_root
# mask some services that we do not want to run in these tests
2019-07-30 10:33:58 +03:00
ln -fs /dev/null $initdir /etc/systemd/system/systemd-networkd.service
ln -fs /dev/null $initdir /etc/systemd/system/systemd-networkd.socket
ln -fs /dev/null $initdir /etc/systemd/system/systemd-resolved.service
2018-09-19 08:30:29 +03:00
}
do_test " $@ "