test.sh revision 6ea4364c7b40d21464b5fc64d6c5506658eb9401
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering#!/bin/bash
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 PoetteringTEST_DESCRIPTION="Basic systemd setup"
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringKVERSION=${KVERSION-$(uname -r)}
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
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
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringrun_qemu() {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering qemu-kvm \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering -hda $TESTDIR/rootdisk.img \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering -m 256M -nographic \
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
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering ret=1
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering mkdir -p $TESTDIR/root
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering mount ${LOOPDEV}p1 $TESTDIR/root
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering [[ -e $TESTDIR/root/testok ]] && ret=0
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering cp -a $TESTDIR/root/var/log/journal $TESTDIR
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering cp -a $TESTDIR/root/failed $TESTDIR
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering umount $TESTDIR/root
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering cat $TESTDIR/failed
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering ls -l $TESTDIR/journal/*/*.journal
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering test -s $TESTDIR/failed && ret=$(($ret+1))
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering return $ret
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering}
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringrun_nspawn() {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering systemd-nspawn -b -D $TESTDIR/nspawn-root /usr/lib/systemd/systemd
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering ret=1
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 cat $TESTDIR/failed
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering ls -l $TESTDIR/journal/*/*.journal
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering test -s $TESTDIR/failed && ret=$(($ret+1))
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering return $ret
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering}
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringtest_run() {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering run_qemu || return 1
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering if [[ -d /sys/fs/cgroup/systemd ]]; then
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering run_nspawn || return 1
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering fi
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering return 0
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering}
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringtest_setup() {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering rm -f $TESTDIR/rootdisk.img
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 echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering sfdisk -C 3200 -H 2 -S 32 -L $LOOPDEV <<EOF
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering,
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringEOF
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering mkfs.ext3 -L systemd ${LOOPDEV}p1
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering mkdir -p $TESTDIR/root
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering mount ${LOOPDEV}p1 $TESTDIR/root
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering mkdir -p $TESTDIR/root/run
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering kernel=$KVERSION
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # Create what will eventually be our root filesystem onto an overlay
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering (
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering LOG_LEVEL=5
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering initdir=$TESTDIR/root
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # create the basic filesystem layout
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering setup_basic_dirs
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # install compiled files
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering (cd ../..; make DESTDIR=$initdir install)
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # install possible missing libraries
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst_libs $i
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering done
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # activate kmsg import
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # make a journal directory
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering mkdir -p $initdir/var/log/journal
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # install some basic config files
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst /etc/sysconfig/init
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst /etc/passwd
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst /etc/shadow
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst /etc/group
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst /etc/shells
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst /etc/nsswitch.conf
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst /etc/pam.conf
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst /etc/securetty
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst /etc/os-release
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst /etc/localtime
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # we want an empty environment
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering > $initdir/etc/environment
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # set the hostname
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering echo systemd-testsuite > $initdir/etc/hostname
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # setup the testsuite target
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering cat >$initdir/etc/systemd/system/testsuite.target <<EOF
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering[Unit]
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringDescription=Testsuite target
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringRequires=multi-user.target
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringAfter=multi-user.target
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringConflicts=rescue.target
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringAllowIsolate=yes
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringEOF
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # setup the testsuite service
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering cat >$initdir/etc/systemd/system/testsuite.service <<EOF
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering[Unit]
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringDescription=Testsuite service
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringAfter=multi-user.target
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering[Service]
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringExecStart=/bin/sh -c 'systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok'
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringExecStartPost=/usr/sbin/poweroff
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringType=oneshot
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringEOF
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
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # make the testsuite the default target
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering ln -fs testsuite.target $initdir/etc/systemd/system/default.target
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering mkdir -p $initdir/etc/rc.d
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering cat >$initdir/etc/rc.d/rc.local <<EOF
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering#!/bin/bash
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringexit 0
84ac7bea360cd369df26910e9685a7eed2327088Lennart PoetteringEOF
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering chmod 0755 $initdir/etc/rc.d/rc.local
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # install basic tools needed
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering dracut_install sh bash setsid loadkeys setfont \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering login sushell sulogin gzip sleep echo
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # install libnss_files for login
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst_libdir_file "libnss_files*"
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # install dbus and pam
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering find \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering /etc/dbus-1 \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering /etc/pam.d \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering /etc/security \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering /lib64/security \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering /lib/security -xtype f \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering | while read file; do
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst $file
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering done
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # install dbus socket and service file
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst /usr/lib/systemd/system/dbus.socket
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst /usr/lib/systemd/system/dbus.service
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # install basic keyboard maps and fonts
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering for i in \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering /usr/lib/kbd/keymaps/include/* \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering /usr/lib/kbd/keymaps/i386/include/* \
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering [[ -f $i ]] || continue
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst $i
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering done
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # some basic terminfo files
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering [ -f ${_terminfodir}/l/linux ] && break
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering done
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering dracut_install -o ${_terminfodir}/l/linux
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # softlink mtab
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering ln -fs /proc/self/mounts $initdir/etc/mtab
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
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 i=${i##Exec*=}; i=${i##-}
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering inst $i
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering done
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
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 dracut_install plymouth plymouthd
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering else
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering rm -f $initdir/usr/lib/systemd/system/plymouth* $initdir/usr/lib/systemd/system/*/plymouth*
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering fi
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering # some helper tools for debugging
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering # install ld.so.conf* and run ldconfig
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering cp -a /etc/ld.so.conf* $initdir/etc
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering ldconfig -r "$initdir"
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering )
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering rm -fr $TESTDIR/nspawn-root
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering cp -avr $TESTDIR/root $TESTDIR/nspawn-root
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering umount $TESTDIR/root
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering}
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringtest_cleanup() {
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering umount $TESTDIR/root 2>/dev/null
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering [[ $LOOPDEV ]] && losetup -d $LOOPDEV
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering return 0
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering}
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering. $TEST_BASE_DIR/test-functions
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poetteringdo_test "$@"
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering