test.sh revision 889a90422dd47284dffa32b9234a6e58991b000c
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering#!/bin/bash
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering# ex: ts=8 sw=4 sts=4 et filetype=sh
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart PoetteringTEST_DESCRIPTION="Job-related tests"
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering. $TEST_BASE_DIR/test-functions
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering# Uncomment this to debug failures
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering#DEBUGFAIL="systemd.unit=multi-user.target"
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringcheck_result_qemu() {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering ret=1
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering mkdir -p $TESTDIR/root
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering mount ${LOOPDEV}p1 $TESTDIR/root
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering [[ -e $TESTDIR/root/testok ]] && ret=0
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering cp -a $TESTDIR/root/var/log/journal $TESTDIR
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering umount $TESTDIR/root
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering ls -l $TESTDIR/journal/*/*.journal
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering test -s $TESTDIR/failed && ret=$(($ret+1))
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering return $ret
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering}
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
4871690d9e32608bbd9b18505b5326c2079c9690Allin Cottrelltest_run() {
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering if check_qemu ; then
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering run_qemu
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering check_result_qemu || return 1
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering else
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering dwarn "can't run qemu-kvm, skipping"
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering fi
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering if check_nspawn; then
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek run_nspawn
35e2e347d38cc2f8bd7c38a0d8a5129f5fbb0ab9Lennart Poettering check_result_nspawn || return 1
0b452006de98294d1690f045f6ea2f7f6630ec3bRonny Chevalier else
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering dwarn "can't run systemd-nspawn, skipping"
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering fi
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering return 0
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering}
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringtest_setup() {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering create_empty_image
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering mkdir -p $TESTDIR/root
3b3154df7e2773332bb814e167187367a0ccae4aLennart Poettering mount ${LOOPDEV}p1 $TESTDIR/root
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering # Create what will eventually be our root filesystem onto an overlay
3b97fcbd28f92a1e51887fef5de8844a89bde523Lennart Poettering (
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek LOG_LEVEL=5
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering setup_basic_environment
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering # setup the testsuite service
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering cat >$initdir/etc/systemd/system/testsuite.service <<EOF
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering[Unit]
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart PoetteringDescription=Testsuite service
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart PoetteringAfter=multi-user.target
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering[Service]
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart PoetteringExecStart=/test-jobs.sh
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart PoetteringType=oneshot
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart PoetteringEOF
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering # copy the units used by this test
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering cp $TEST_BASE_DIR/{hello.service,sleep.service,hello-after-sleep.target,unstoppable.service} \
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering $initdir/etc/systemd/system
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering cp test-jobs.sh $initdir/
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering setup_testsuite
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering )
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering setup_nspawn_root
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering ddebug "umount $TESTDIR/root"
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering umount $TESTDIR/root
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering}
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringtest_cleanup() {
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek umount $TESTDIR/root 2>/dev/null
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering [[ $LOOPDEV ]] && losetup -d $LOOPDEV
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering return 0
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering}
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringdo_test "$@"
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering