test.sh revision 6b197f2a03fa03a2a853cf726d47be2ea4c623b6
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering#!/bin/bash
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering# ex: ts=8 sw=4 sts=4 et filetype=sh
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart PoetteringTEST_DESCRIPTION="Basic systemd setup"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart PoetteringKVERSION=${KVERSION-$(uname -r)}
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering# Uncomment this to debug failures
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering#DEBUGFAIL="systemd.unit=multi-user.target"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringtest_run() {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering qemu-kvm \
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering -hda $TESTDIR/rootdisk.img \
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering -m 256M -nographic \
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering -net none -kernel /boot/vmlinuz-$KVERSION \
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart 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"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering ret=1
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering mkdir -p $TESTDIR/root
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering mount ${LOOPDEV}p1 $TESTDIR/root
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering [[ -e $TESTDIR/root/testok ]] && ret=0
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering cp -a $TESTDIR/root/var/log/journal $TESTDIR
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering cp -a $TESTDIR/root/failed $TESTDIR
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering umount $TESTDIR/root
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering cat $TESTDIR/failed
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering ls -l $TESTDIR/journal/*/*.journal
a9cdc94f7ff40f22a3cf9472f612a80730a1b010Dave Reisner test -s $TESTDIR/failed && ret=$(($ret+1))
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering return $ret
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen}
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersentest_setup() {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering rm -f $TESTDIR/rootdisk.img
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering # Create the blank file to use as a root filesystem
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=100
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering [ -b $LOOPDEV ] || return 1
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sfdisk -C 3200 -H 2 -S 32 -L $LOOPDEV <<EOF
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering,
e1636421f46db6d06fbd028ef20a3113fa3e11f8Lennart PoetteringEOF
7085053a437456ab87d726f3697002dd811fdf7aDaniel Wallace
e1636421f46db6d06fbd028ef20a3113fa3e11f8Lennart Poettering mkfs.ext3 -L systemd ${LOOPDEV}p1
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering mkdir -p $TESTDIR/root
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering mount ${LOOPDEV}p1 $TESTDIR/root
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering mkdir -p $TESTDIR/root/run
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering kernel=$KVERSION
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering # Create what will eventually be our root filesystem onto an overlay
1b12a7b5896f94bdf33b3a6661ebabd761ea6adcHarald Hoyer (
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering LOG_LEVEL=5
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering initdir=$TESTDIR/root
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering # create the basic filesystem layout
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering setup_basic_dirs
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering # install compiled files
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering (cd ../..; make DESTDIR=$initdir install)
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering # install possible missing libraries
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering inst_libs $i
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering done
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering # activate kmsg import
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers # make a journal directory
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers mkdir -p $initdir/var/log/journal
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers # install some basic config files
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers inst /etc/sysconfig/init
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers inst /etc/passwd
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers inst /etc/shadow
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering inst /etc/group
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering inst /etc/shells
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers inst /etc/nsswitch.conf
f18ca9dcdeda247e208f7143e834fd2fb2070d80Kay Sievers inst /etc/pam.conf
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering inst /etc/securetty
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering inst /etc/os-release
9ff09bcb86fb125768667aca9bc0b10b1745370aShawn Landden inst /etc/localtime
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering # we want an empty environment
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering > $initdir/etc/environment
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
599659860c770058f2eb04d578c521c16e0b1853Lennart Poettering # set the hostname
599659860c770058f2eb04d578c521c16e0b1853Lennart Poettering echo systemd-testsuite > $initdir/etc/hostname
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering # setup the testsuite target
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering cat >$initdir/etc/systemd/system/testsuite.target <<EOF
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering[Unit]
2311eb2ff0c3ff80ec3645b02c97170c9a565454Kay SieversDescription=Testsuite target
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart PoetteringRequires=multi-user.target
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart PoetteringAfter=multi-user.target
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart PoetteringConflicts=rescue.target
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart PoetteringAllowIsolate=yes
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart PoetteringEOF
3e5e74d5b7f6fcbeff7b6e4e06abd931aab14c48Shawn Landden
9ff09bcb86fb125768667aca9bc0b10b1745370aShawn Landden # setup the testsuite service
9ff09bcb86fb125768667aca9bc0b10b1745370aShawn Landden cat >$initdir/etc/systemd/system/testsuite.service <<EOF
9ff09bcb86fb125768667aca9bc0b10b1745370aShawn Landden[Unit]
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart PoetteringDescription=Testsuite service
9ff09bcb86fb125768667aca9bc0b10b1745370aShawn LanddenAfter=multi-user.target
9ff09bcb86fb125768667aca9bc0b10b1745370aShawn Landden
9ff09bcb86fb125768667aca9bc0b10b1745370aShawn Landden[Service]
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart PoetteringExecStart=/bin/sh -c 'systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok'
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart PoetteringExecStartPost=/usr/sbin/poweroff
9ff09bcb86fb125768667aca9bc0b10b1745370aShawn LanddenType=oneshot
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-SzmekEOF
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek
9ff09bcb86fb125768667aca9bc0b10b1745370aShawn Landden # make the testsuite the default target
9ff09bcb86fb125768667aca9bc0b10b1745370aShawn Landden ln -fs testsuite.target $initdir/etc/systemd/system/default.target
9ff09bcb86fb125768667aca9bc0b10b1745370aShawn Landden mkdir -p $initdir/etc/rc.d
9ff09bcb86fb125768667aca9bc0b10b1745370aShawn Landden cat >$initdir/etc/rc.d/rc.local <<EOF
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering#!/bin/bash
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sieversexit 0
2f6a59070559786428d9eaf199ae3d61772b2225Kay SieversEOF
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering chmod 0755 $initdir/etc/rc.d/rc.local
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering # install basic tools needed
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek dracut_install sh bash setsid loadkeys setfont \
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek login sushell sulogin gzip sleep echo
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers
9ff09bcb86fb125768667aca9bc0b10b1745370aShawn Landden # install libnss_files for login
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering inst_libdir_file "libnss_files*"
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek # install dbus and pam
2667cc25896a15f82f9f1583e80d416beb1316e1Thomas Hindoe Paaboel Andersen find \
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering /etc/dbus-1 \
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering /etc/pam.d \
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering /etc/security \
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering /lib64/security \
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering /lib/security -xtype f \
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering | while read file; do
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering inst $file
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering done
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering
d95a74ed1191bb09f5be57b0619d3d77708e019dLennart Poettering # install dbus socket and service file
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek inst /usr/lib/systemd/system/dbus.socket
b90930c73b1c82a3dc4d4f2603799993f042aaffLennart Poettering inst /usr/lib/systemd/system/dbus.service
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering # install basic keyboard maps and fonts
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek for i in \
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers /usr/lib/kbd/keymaps/include/* \
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers /usr/lib/kbd/keymaps/i386/include/* \
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers [[ -f $i ]] || continue
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering inst $i
c264aeab4b0e7b69f469e12e78d4a48b3ed7a66eKay Sievers done
c264aeab4b0e7b69f469e12e78d4a48b3ed7a66eKay Sievers
c264aeab4b0e7b69f469e12e78d4a48b3ed7a66eKay Sievers # some basic terminfo files
c264aeab4b0e7b69f469e12e78d4a48b3ed7a66eKay Sievers for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
07a062a79374406e8f6b5a1e2f80c80baf031567Jason St. John [ -f ${_terminfodir}/l/linux ] && break
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering done
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering dracut_install -o ${_terminfodir}/l/linux
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen
b92bea5d2a9481de69bb627a7b442a9f58fca43dZbigniew Jędrzejewski-Szmek # softlink mtab
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers ln -fs /proc/self/mounts $initdir/etc/mtab
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers # install any Exec's from the service files
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers | while read i; do
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers i=${i##Exec*=}; i=${i##-}
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers inst $i
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers done
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers # install plymouth, if found... else remove plymouth service files
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering dracut_install plymouth plymouthd
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers else
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers rm -f $initdir/usr/lib/systemd/system/plymouth* $initdir/usr/lib/systemd/system/*/plymouth*
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers fi
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers # some helper tools for debugging
adacb9575a09981fcf11279f2f661e3fc21e58ffLennart Poettering dracut_install sh df free ls shutdown poweroff \
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt stty cat ps ln ip route \
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers mount dmesg dhclient mkdir cp ping dhclient \
adacb9575a09981fcf11279f2f661e3fc21e58ffLennart Poettering umount strace less grep id tty touch
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering # install ld.so.conf* and run ldconfig
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers cp -a /etc/ld.so.conf* $initdir/etc
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers ldconfig -r "$initdir"
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers )
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering umount $TESTDIR/root
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen}
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersentest_cleanup() {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering umount $TESTDIR/root 2>/dev/null
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering [[ $LOOPDEV ]] && losetup -d $LOOPDEV
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering return 0
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering}
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering. $TEST_BASE_DIR/test-functions
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringdo_test "$@"
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering