test.sh revision 7c1856aacd4f5d41dc320860490afda18c4a7495
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering#!/bin/bash
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering# ex: ts=8 sw=4 sts=4 et filetype=sh
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringTEST_DESCRIPTION="Basic systemd setup"
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringKVERSION=${KVERSION-$(uname -r)}
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering# Uncomment this to debug failures
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering#DEBUGFAIL="systemd.unit=multi-user.target"
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poetteringtest_run() {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering qemu-kvm \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering -hda $TESTDIR/rootdisk.img \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering -m 256M -nographic \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering -net none -kernel /boot/vmlinuz-$KVERSION \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart 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"
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering ret=1
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering mkdir -p $TESTDIR/root
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering mount ${LOOPDEV}p1 $TESTDIR/root
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering [[ -e $TESTDIR/root/testok ]] && ret=0
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering cp -a $TESTDIR/root/var/log/journal $TESTDIR
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering cp -a $TESTDIR/root/failed $TESTDIR
4871690d9e32608bbd9b18505b5326c2079c9690Allin Cottrell umount $TESTDIR/root
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering cat $TESTDIR/failed
c79e98eadd3056a36a662699fa650db5b1bca0c3Lennart Poettering ls -l $TESTDIR/journal/*/*.journal
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering test -s $TESTDIR/failed && ret=$(($ret+1))
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering return $ret
1dfa7e79a60de680086b1d93fcc3629b463f58bdLennart Poettering}
d682b3a7e7c7c2941a4d3e193f1e330dbc9fae89Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmektest_setup() {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering rm -f $TESTDIR/rootdisk.img
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # Create the blank file to use as a root filesystem
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=100
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
40b71e89bae4e51768db4dc50ec64c1e9c96eec4Sebastian Thorarensen [ -b $LOOPDEV ] || return 1
a09abc4ae0bdc0200324eaa0416f23ff2170ec4eLennart Poettering echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering sfdisk -C 3200 -H 2 -S 32 -L $LOOPDEV <<EOF
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek,
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringEOF
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering mkfs.ext3 -L systemd ${LOOPDEV}p1
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering mkdir -p $TESTDIR/root
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering mount ${LOOPDEV}p1 $TESTDIR/root
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering mkdir -p $TESTDIR/root/run
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering kernel=$KVERSION
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # Create what will eventually be our root filesystem onto an overlay
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering (
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering LOG_LEVEL=5
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering initdir=$TESTDIR/root
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # create the basic filesystem layout
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering setup_basic_dirs
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # install compiled files
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek (cd ../..; make DESTDIR=$initdir install)
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # install possible missing libraries
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering inst_libs $i
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering done
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # activate kmsg import
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek # make a journal directory
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek mkdir -p $initdir/var/log/journal
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # install some basic config files
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering inst /etc/sysconfig/init
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering inst /etc/passwd
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering inst /etc/shadow
3b3154df7e2773332bb814e167187367a0ccae4aLennart Poettering inst /etc/group
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek inst /etc/shells
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek inst /etc/nsswitch.conf
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek inst /etc/pam.conf
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering inst /etc/securetty
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering inst /etc/os-release
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering inst /etc/localtime
3b3154df7e2773332bb814e167187367a0ccae4aLennart Poettering # we want an empty environment
3b3154df7e2773332bb814e167187367a0ccae4aLennart Poettering > $initdir/etc/environment
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # set the hostname
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering echo systemd-testsuite > $initdir/etc/hostname
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # setup the testsuite target
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek cat >$initdir/etc/systemd/system/testsuite.target <<EOF
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering[Unit]
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringDescription=Testsuite target
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-SzmekRequires=multi-user.target
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringAfter=multi-user.target
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringConflicts=rescue.target
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringAllowIsolate=yes
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringEOF
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # setup the testsuite service
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering cat >$initdir/etc/systemd/system/testsuite.service <<EOF
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering[Unit]
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringDescription=Testsuite service
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringAfter=multi-user.target
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering[Service]
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringExecStart=/bin/sh -c 'systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok'
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringExecStartPost=/usr/sbin/poweroff
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringType=oneshot
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart PoetteringEOF
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek # make the testsuite the default target
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek ln -fs testsuite.target $initdir/etc/systemd/system/default.target
8c0b803b97bb0ee6603d9be85fb6b69cd6081eafLennart Poettering
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek # install basic tools needed
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek dracut_install sh bash setsid loadkeys setfont \
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek login sushell sulogin gzip sleep echo
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # install libnss_files for login
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering inst_libdir_file "libnss_files*"
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # install dbus and pam
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering find \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering /etc/dbus-1 \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering /etc/pam.d \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering /etc/security \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering /lib64/security \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering /lib/security -xtype f \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering | while read file; do
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering inst $file
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering done
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # install dbus socket and service file
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering inst /usr/lib/systemd/system/dbus.socket
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering inst /usr/lib/systemd/system/dbus.service
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # install basic keyboard maps and fonts
12a717f8347f3daf0ae46a2b71c7d011d9c12feaZbigniew Jędrzejewski-Szmek for i in \
92ee6447b1deef7c79962a8121fdf8e58acb3a83Zbigniew Jędrzejewski-Szmek /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek /usr/lib/kbd/keymaps/include/* \
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek /usr/lib/kbd/keymaps/i386/include/* \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering [[ -f $i ]] || continue
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering inst $i
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering done
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # some basic terminfo files
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering [ -f ${_terminfodir}/l/linux ] && break
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering done
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering dracut_install -o ${_terminfodir}/l/linux
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # softlink mtab
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering ln -fs /proc/self/mounts $initdir/etc/mtab
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # install any Exec's from the service files
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
a174f94d529c7ae9be589867308b669ec9b4dcc0Lennart Poettering | while read i; do
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering i=${i##Exec*=}; i=${i##-}
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering inst $i
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering done
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # install plymouth, if found... else remove plymouth service files
2a0e0692565f0435657c93498e09cbb2d3517152Shawn Landden if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering dracut_install plymouth plymouthd
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering else
2a0e0692565f0435657c93498e09cbb2d3517152Shawn Landden rm -f $initdir/usr/lib/systemd/system/plymouth* $initdir/usr/lib/systemd/system/*/plymouth*
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering fi
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # some helper tools for debugging
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering dracut_install sh df free ls shutdown poweroff \
2a0e0692565f0435657c93498e09cbb2d3517152Shawn Landden stty cat ps ln ip route \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering mount dmesg dhclient mkdir cp ping dhclient \
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering umount strace less grep id tty touch
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering # install ld.so.conf* and run ldconfig
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering cp -a /etc/ld.so.conf* $initdir/etc
2a0e0692565f0435657c93498e09cbb2d3517152Shawn Landden ldconfig -r "$initdir"
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering )
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering umount $TESTDIR/root
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering}
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poetteringtest_cleanup() {
1f6b411372076426c0faf0bb350437fb4d82931fLennart Poettering umount $TESTDIR/root 2>/dev/null
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering [[ $LOOPDEV ]] && losetup -d $LOOPDEV
2a0e0692565f0435657c93498e09cbb2d3517152Shawn Landden return 0
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering}
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering. $TEST_BASE_DIR/test-functions
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poetteringdo_test "$@"
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering