b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt#!/bin/bash
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt# ex: ts=8 sw=4 sts=4 et filetype=sh
d710d36375bacbf9cfb8903107bedf2c0aada84eMichal SchmidtTEST_DESCRIPTION="Job-related tests"
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt
fff87a35d9e26c0d4ea41273a963c0eb20e18da4Zbigniew Jędrzejewski-Szmek. $TEST_BASE_DIR/test-functions
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevaliercheck_result_qemu() {
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt ret=1
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt mkdir -p $TESTDIR/root
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt mount ${LOOPDEV}p1 $TESTDIR/root
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt [[ -e $TESTDIR/root/testok ]] && ret=0
41a5ef639b248aa3d10609d9af5d0043b909d93cHarald Hoyer [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt cp -a $TESTDIR/root/var/log/journal $TESTDIR
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt umount $TESTDIR/root
41a5ef639b248aa3d10609d9af5d0043b909d93cHarald Hoyer [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt ls -l $TESTDIR/journal/*/*.journal
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt test -s $TESTDIR/failed && ret=$(($ret+1))
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt return $ret
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt}
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidttest_run() {
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier if run_qemu; then
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier check_result_qemu || return 1
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt else
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier dwarn "can't run QEMU, skipping"
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt fi
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt if check_nspawn; then
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier run_nspawn
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier check_result_nspawn || return 1
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt else
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt dwarn "can't run systemd-nspawn, skipping"
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt fi
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt return 0
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt}
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidttest_setup() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier create_empty_image
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt mkdir -p $TESTDIR/root
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt mount ${LOOPDEV}p1 $TESTDIR/root
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt # Create what will eventually be our root filesystem onto an overlay
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt (
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt LOG_LEVEL=5
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier setup_basic_environment
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt # setup the testsuite service
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt cat >$initdir/etc/systemd/system/testsuite.service <<EOF
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt[Unit]
b5da077ddf01546c4a85688624d6957766d6c00cMichal SchmidtDescription=Testsuite service
b5da077ddf01546c4a85688624d6957766d6c00cMichal SchmidtAfter=multi-user.target
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt[Service]
b5da077ddf01546c4a85688624d6957766d6c00cMichal SchmidtExecStart=/test-jobs.sh
b5da077ddf01546c4a85688624d6957766d6c00cMichal SchmidtType=oneshot
b5da077ddf01546c4a85688624d6957766d6c00cMichal SchmidtEOF
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt # copy the units used by this test
d710d36375bacbf9cfb8903107bedf2c0aada84eMichal Schmidt cp $TEST_BASE_DIR/{hello.service,sleep.service,hello-after-sleep.target,unstoppable.service} \
d710d36375bacbf9cfb8903107bedf2c0aada84eMichal Schmidt $initdir/etc/systemd/system
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt cp test-jobs.sh $initdir/
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier setup_testsuite
cd949ee7348982d90fb8bdf4a37128928b82925fEvgeny Vereshchagin ) || return 1
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier setup_nspawn_root
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt ddebug "umount $TESTDIR/root"
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt umount $TESTDIR/root
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt}
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidttest_cleanup() {
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt umount $TESTDIR/root 2>/dev/null
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt [[ $LOOPDEV ]] && losetup -d $LOOPDEV
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt return 0
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt}
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidtdo_test "$@"