test.sh revision 6b197f2a03fa03a2a853cf726d47be2ea4c623b6
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#!/bin/bash
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen# ex: ts=8 sw=4 sts=4 et filetype=sh
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenTEST_DESCRIPTION="Basic systemd setup"
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenKVERSION=${KVERSION-$(uname -r)}
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen# Uncomment this to debug failures
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#DEBUGFAIL="systemd.unit=multi-user.target"
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersentest_run() {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen qemu-kvm \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen -hda $TESTDIR/rootdisk.img \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen -m 256M -nographic \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen -net none -kernel /boot/vmlinuz-$KVERSION \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd rw console=ttyS0,115200n81 selinux=0 $DEBUGFAIL"
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen ret=1
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen mkdir -p $TESTDIR/root
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen mount ${LOOPDEV}p1 $TESTDIR/root
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen [[ -e $TESTDIR/root/testok ]] && ret=0
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen cp -a $TESTDIR/root/var/log/journal $TESTDIR
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen cp -a $TESTDIR/root/failed $TESTDIR
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen umount $TESTDIR/root
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen cat $TESTDIR/failed
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen ls -l $TESTDIR/journal/*/*.journal
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen test -s $TESTDIR/failed && ret=$(($ret+1))
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen return $ret
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen}
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersentest_setup() {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen rm -f $TESTDIR/rootdisk.img
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # Create the blank file to use as a root filesystem
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=100
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen [ -b $LOOPDEV ] || return 1
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen sfdisk -C 3200 -H 2 -S 32 -L $LOOPDEV <<EOF
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenEOF
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen mkfs.ext3 -L systemd ${LOOPDEV}p1
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen mkdir -p $TESTDIR/root
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen mount ${LOOPDEV}p1 $TESTDIR/root
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen mkdir -p $TESTDIR/root/run
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen kernel=$KVERSION
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # Create what will eventually be our root filesystem onto an overlay
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen (
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen LOG_LEVEL=5
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen initdir=$TESTDIR/root
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # create the basic filesystem layout
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen setup_basic_dirs
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # install compiled files
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen (cd ../..; make DESTDIR=$initdir install)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # install possible missing libraries
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst_libs $i
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen done
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # activate kmsg import
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # make a journal directory
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen mkdir -p $initdir/var/log/journal
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # install some basic config files
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst /etc/sysconfig/init
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst /etc/passwd
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst /etc/shadow
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst /etc/group
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst /etc/shells
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst /etc/nsswitch.conf
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst /etc/pam.conf
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst /etc/securetty
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst /etc/os-release
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst /etc/localtime
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # we want an empty environment
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen > $initdir/etc/environment
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # set the hostname
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen echo systemd-testsuite > $initdir/etc/hostname
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # setup the testsuite target
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen cat >$initdir/etc/systemd/system/testsuite.target <<EOF
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen[Unit]
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenDescription=Testsuite target
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenRequires=multi-user.target
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenAfter=multi-user.target
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenConflicts=rescue.target
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenAllowIsolate=yes
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenEOF
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # setup the testsuite service
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen cat >$initdir/etc/systemd/system/testsuite.service <<EOF
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen[Unit]
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenDescription=Testsuite service
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenAfter=multi-user.target
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen[Service]
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenExecStart=/bin/sh -c 'systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok'
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenExecStartPost=/usr/sbin/poweroff
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenType=oneshot
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenEOF
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # make the testsuite the default target
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen ln -fs testsuite.target $initdir/etc/systemd/system/default.target
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen mkdir -p $initdir/etc/rc.d
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen cat >$initdir/etc/rc.d/rc.local <<EOF
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#!/bin/bash
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenexit 0
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenEOF
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen chmod 0755 $initdir/etc/rc.d/rc.local
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # install basic tools needed
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen dracut_install sh bash setsid loadkeys setfont \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen login sushell sulogin gzip sleep echo
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # install libnss_files for login
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst_libdir_file "libnss_files*"
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # install dbus and pam
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen find \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /etc/dbus-1 \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /etc/pam.d \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /etc/security \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /lib64/security \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /lib/security -xtype f \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen | while read file; do
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst $file
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen done
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # install dbus socket and service file
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst /usr/lib/systemd/system/dbus.socket
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst /usr/lib/systemd/system/dbus.service
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # install basic keyboard maps and fonts
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen for i in \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /usr/lib/kbd/keymaps/include/* \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /usr/lib/kbd/keymaps/i386/include/* \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen [[ -f $i ]] || continue
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen inst $i
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen done
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # some basic terminfo files
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen [ -f ${_terminfodir}/l/linux ] && break
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen done
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen dracut_install -o ${_terminfodir}/l/linux
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # softlink mtab
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen ln -fs /proc/self/mounts $initdir/etc/mtab
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # install any Exec's from the service files
08232a020bd2571088d3ee06dda07732c5e963d1Tom Gundersen egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
08232a020bd2571088d3ee06dda07732c5e963d1Tom Gundersen | while read i; do
08232a020bd2571088d3ee06dda07732c5e963d1Tom Gundersen i=${i##Exec*=}; i=${i##-}
08232a020bd2571088d3ee06dda07732c5e963d1Tom Gundersen inst $i
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen done
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # install plymouth, if found... else remove plymouth service files
08232a020bd2571088d3ee06dda07732c5e963d1Tom Gundersen if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
08232a020bd2571088d3ee06dda07732c5e963d1Tom Gundersen PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
08232a020bd2571088d3ee06dda07732c5e963d1Tom Gundersen /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
08232a020bd2571088d3ee06dda07732c5e963d1Tom Gundersen dracut_install plymouth plymouthd
e53fc357a9bb9d0a5362ccc4246d598cb0febd5eLennart Poettering else
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen rm -f $initdir/usr/lib/systemd/system/plymouth* $initdir/usr/lib/systemd/system/*/plymouth*
08232a020bd2571088d3ee06dda07732c5e963d1Tom Gundersen fi
e53fc357a9bb9d0a5362ccc4246d598cb0febd5eLennart Poettering
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # some helper tools for debugging
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen dracut_install sh df free ls shutdown poweroff \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen stty cat ps ln ip route \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen mount dmesg dhclient mkdir cp ping dhclient \
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen umount strace less grep id tty touch
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen # install ld.so.conf* and run ldconfig
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen cp -a /etc/ld.so.conf* $initdir/etc
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen ldconfig -r "$initdir"
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
52d629010db73a9466c359201916494bd55186d1Tom Gundersen )
52d629010db73a9466c359201916494bd55186d1Tom Gundersen umount $TESTDIR/root
52d629010db73a9466c359201916494bd55186d1Tom Gundersen
52d629010db73a9466c359201916494bd55186d1Tom Gundersen}
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersentest_cleanup() {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen umount $TESTDIR/root 2>/dev/null
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen [[ $LOOPDEV ]] && losetup -d $LOOPDEV
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen return 0
52d629010db73a9466c359201916494bd55186d1Tom Gundersen}
52d629010db73a9466c359201916494bd55186d1Tom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen. $TEST_BASE_DIR/test-functions
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersendo_test "$@"
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen