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