test.sh revision 6ea4364c7b40d21464b5fc64d6c5506658eb9401
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering# ex: ts=8 sw=4 sts=4 et filetype=sh
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering# Uncomment this to debug failures
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering#DEBUGFAIL="systemd.unit=multi-user.target"
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringDEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort"
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering -net none -kernel /boot/vmlinuz-$KVERSION \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd rw console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" || return 1
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering cp -a $TESTDIR/root/var/log/journal $TESTDIR
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering test -s $TESTDIR/failed && ret=$(($ret+1))
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering systemd-nspawn -b -D $TESTDIR/nspawn-root /usr/lib/systemd/systemd
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering cp -a $TESTDIR/nspawn-root/failed $TESTDIR
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering test -s $TESTDIR/failed && ret=$(($ret+1))
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering if [[ -d /sys/fs/cgroup/systemd ]]; then
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # Create the blank file to use as a root filesystem
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=100
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering [ -b $LOOPDEV ] || return 1
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering sfdisk -C 3200 -H 2 -S 32 -L $LOOPDEV <<EOF
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # Create what will eventually be our root filesystem onto an overlay
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering (cd ../..; make DESTDIR=$initdir install)
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering echo systemd-testsuite > $initdir/etc/hostname
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering cat >$initdir/etc/systemd/system/testsuite.target <<EOF
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringDescription=Testsuite target
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringRequires=multi-user.target
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringAfter=multi-user.target
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringConflicts=rescue.target
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringAllowIsolate=yes
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering cat >$initdir/etc/systemd/system/testsuite.service <<EOF
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringDescription=Testsuite service
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringAfter=multi-user.target
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringExecStart=/bin/sh -c 'systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok'
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringExecStartPost=/usr/sbin/poweroff
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering ln -fs testsuite.target $initdir/etc/systemd/system/default.target
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering dracut_install sh bash setsid loadkeys setfont \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering | while read file; do
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst /usr/lib/systemd/system/dbus.service
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering [[ -f $i ]] || continue
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering [ -f ${_terminfodir}/l/linux ] && break
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering dracut_install -o ${_terminfodir}/l/linux
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering ln -fs /proc/self/mounts $initdir/etc/mtab
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # install any Exec's from the service files
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering | while read i; do
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # install plymouth, if found... else remove plymouth service files
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering rm -f $initdir/usr/lib/systemd/system/plymouth* $initdir/usr/lib/systemd/system/*/plymouth*
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS