2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4 TEST_DESCRIPTION="Basic systemd setup"
6 KVERSION=${KVERSION-$(uname -r)}
8 # Uncomment this to debug failures
9 #DEBUGFAIL="systemd.unit=multi-user.target"
10 DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort"
15 -hda $TESTDIR/rootdisk.img \
17 -net none -kernel /boot/vmlinuz-$KVERSION \
18 -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
21 mkdir -p $TESTDIR/root
22 mount ${LOOPDEV}p1 $TESTDIR/root
23 [[ -e $TESTDIR/root/testok ]] && ret=0
24 cp -a $TESTDIR/root/var/log/journal $TESTDIR
25 cp -a $TESTDIR/root/failed $TESTDIR
28 ls -l $TESTDIR/journal/*/*.journal
29 test -s $TESTDIR/failed && ret=$(($ret+1))
35 systemd-nspawn -b -D $TESTDIR/nspawn-root /usr/lib/systemd/systemd
37 [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
38 cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
39 cp -a $TESTDIR/nspawn-root/failed $TESTDIR
41 ls -l $TESTDIR/journal/*/*.journal
42 test -s $TESTDIR/failed && ret=$(($ret+1))
49 if [[ -d /sys/fs/cgroup/systemd ]]; then
50 run_nspawn || return 1
56 rm -f $TESTDIR/rootdisk.img
57 # Create the blank file to use as a root filesystem
58 dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=100
59 LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
60 [ -b $LOOPDEV ] || return 1
61 echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
62 sfdisk -C 3200 -H 2 -S 32 -L $LOOPDEV <<EOF
66 mkfs.ext3 -L systemd ${LOOPDEV}p1
67 mkdir -p $TESTDIR/root
68 mount ${LOOPDEV}p1 $TESTDIR/root
69 mkdir -p $TESTDIR/root/run
72 # Create what will eventually be our root filesystem onto an overlay
77 # create the basic filesystem layout
80 # install compiled files
81 (cd ../..; make DESTDIR=$initdir install)
83 # install possible missing libraries
84 for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
88 # activate kmsg import
89 echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf
91 # make a journal directory
92 mkdir -p $initdir/var/log/journal
94 # install some basic config files
95 inst /etc/sysconfig/init
100 inst /etc/nsswitch.conf
105 # we want an empty environment
106 > $initdir/etc/environment
109 echo systemd-testsuite > $initdir/etc/hostname
111 # setup the testsuite target
112 cat >$initdir/etc/systemd/system/testsuite.target <<EOF
114 Description=Testsuite target
115 Requires=multi-user.target
116 After=multi-user.target
117 Conflicts=rescue.target
121 # setup the testsuite service
122 cat >$initdir/etc/systemd/system/testsuite.service <<EOF
124 Description=Testsuite service
125 After=multi-user.target
128 ExecStart=/bin/sh -c 'systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok'
129 ExecStartPost=/usr/sbin/poweroff
133 mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
134 ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
136 # make the testsuite the default target
137 ln -fs testsuite.target $initdir/etc/systemd/system/default.target
138 mkdir -p $initdir/etc/rc.d
139 cat >$initdir/etc/rc.d/rc.local <<EOF
143 chmod 0755 $initdir/etc/rc.d/rc.local
144 # install basic tools needed
145 dracut_install sh bash setsid loadkeys setfont \
146 login sushell sulogin gzip sleep echo
148 # install libnss_files for login
149 inst_libdir_file "libnss_files*"
151 # install dbus and pam
157 /lib/security -xtype f \
158 | while read file; do
162 # install dbus socket and service file
163 inst /usr/lib/systemd/system/dbus.socket
164 inst /usr/lib/systemd/system/dbus.service
166 # install basic keyboard maps and fonts
168 /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
169 /usr/lib/kbd/keymaps/include/* \
170 /usr/lib/kbd/keymaps/i386/include/* \
171 /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
172 [[ -f $i ]] || continue
176 # some basic terminfo files
177 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
178 [ -f ${_terminfodir}/l/linux ] && break
180 dracut_install -o ${_terminfodir}/l/linux
183 ln -fs /proc/self/mounts $initdir/etc/mtab
185 # install any Exec's from the service files
186 egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
188 i=${i##Exec*=}; i=${i##-}
192 # install plymouth, if found... else remove plymouth service files
193 if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
194 PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
195 /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
196 dracut_install plymouth plymouthd
198 rm -f $initdir/usr/lib/systemd/system/plymouth* $initdir/usr/lib/systemd/system/*/plymouth*
201 # some helper tools for debugging
202 [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
204 # install ld.so.conf* and run ldconfig
205 cp -a /etc/ld.so.conf* $initdir/etc
206 ldconfig -r "$initdir"
209 rm -fr $TESTDIR/nspawn-root
210 cp -avr $TESTDIR/root $TESTDIR/nspawn-root
216 umount $TESTDIR/root 2>/dev/null
217 [[ $LOOPDEV ]] && losetup -d $LOOPDEV
221 . $TEST_BASE_DIR/test-functions