test.sh revision cd949ee7348982d90fb8bdf4a37128928b82925f
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier#!/bin/bash
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier# ex: ts=8 sw=4 sts=4 et filetype=sh
106ecd769d57116ad81efdea2c27557fba062138Ronny ChevalierTEST_DESCRIPTION="Job-related tests"
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier. $TEST_BASE_DIR/test-functions
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevaliercheck_result_qemu() {
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier ret=1
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier mkdir -p $TESTDIR/root
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier mount ${LOOPDEV}p1 $TESTDIR/root
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier [[ -e $TESTDIR/root/testok ]] && ret=0
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier cp -a $TESTDIR/root/var/log/journal $TESTDIR
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier umount $TESTDIR/root
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier ls -l $TESTDIR/journal/*/*.journal
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier test -s $TESTDIR/failed && ret=$(($ret+1))
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier return $ret
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier}
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevaliertest_run() {
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering if run_qemu; then
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier check_result_qemu || return 1
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier else
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering dwarn "can't run QEMU, skipping"
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier fi
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier if check_nspawn; then
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier run_nspawn
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier check_result_nspawn || return 1
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier else
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier dwarn "can't run systemd-nspawn, skipping"
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier fi
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier return 0
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier}
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevaliertest_setup() {
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier create_empty_image
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier mkdir -p $TESTDIR/root
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier mount ${LOOPDEV}p1 $TESTDIR/root
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier # Create what will eventually be our root filesystem onto an overlay
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier (
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier LOG_LEVEL=5
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier setup_basic_environment
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier # setup the testsuite service
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier cat >$initdir/etc/systemd/system/testsuite.service <<EOF
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier[Unit]
106ecd769d57116ad81efdea2c27557fba062138Ronny ChevalierDescription=Testsuite service
106ecd769d57116ad81efdea2c27557fba062138Ronny ChevalierAfter=multi-user.target
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier[Service]
106ecd769d57116ad81efdea2c27557fba062138Ronny ChevalierExecStart=/test-jobs.sh
106ecd769d57116ad81efdea2c27557fba062138Ronny ChevalierType=oneshot
106ecd769d57116ad81efdea2c27557fba062138Ronny ChevalierEOF
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier # copy the units used by this test
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier cp $TEST_BASE_DIR/{hello.service,sleep.service,hello-after-sleep.target,unstoppable.service} \
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier $initdir/etc/systemd/system
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier cp test-jobs.sh $initdir/
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier setup_testsuite
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier ) || return 1
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier setup_nspawn_root
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier ddebug "umount $TESTDIR/root"
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier umount $TESTDIR/root
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier}
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevaliertest_cleanup() {
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier umount $TESTDIR/root 2>/dev/null
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier [[ $LOOPDEV ]] && losetup -d $LOOPDEV
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier return 0
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier}
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalierdo_test "$@"
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier