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)}
9 # Uncomment this to debug failures
10 #DEBUGFAIL="systemd.unit=multi-user.target"
11 DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort"
14 # TODO: qemu wrapper script: http://www.spinics.net/lists/kvm/msg72389.html
16 -hda $TESTDIR/rootdisk.img \
18 -net none -kernel /boot/vmlinuz-$KERNEL_VER \
19 -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd ro console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" || return 1
22 mkdir -p $TESTDIR/root
23 mount ${LOOPDEV}p1 $TESTDIR/root
24 [[ -e $TESTDIR/root/testok ]] && ret=0
25 cp -a $TESTDIR/root/failed $TESTDIR
26 cp -a $TESTDIR/root/var/log/journal $TESTDIR
29 ls -l $TESTDIR/journal/*/*.journal
30 test -s $TESTDIR/failed && ret=$(($ret+1))
36 ../../systemd-nspawn -b -D $TESTDIR/nspawn-root /usr/lib/systemd/systemd
38 [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
39 cp -a $TESTDIR/nspawn-root/failed $TESTDIR
40 cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
42 ls -l $TESTDIR/journal/*/*.journal
43 test -s $TESTDIR/failed && ret=$(($ret+1))
52 dwarn "can't run qemu-kvm, skipping"
55 run_nspawn || return 1
57 dwarn "can't run systemd-nspawn, skipping"
63 rm -f $TESTDIR/rootdisk.img
64 # Create the blank file to use as a root filesystem
65 dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=200
66 LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
67 [ -b $LOOPDEV ] || return 1
68 echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
69 sfdisk -C 6400 -H 2 -S 32 -L $LOOPDEV <<EOF
74 mkfs.ext3 -L systemd ${LOOPDEV}p1
75 echo -n test >$TESTDIR/keyfile
76 mkdir -p $TESTDIR/root
77 mount ${LOOPDEV}p1 $TESTDIR/root
78 mkdir -p $TESTDIR/root/run
80 # Create what will eventually be our root filesystem onto an overlay
85 # create the basic filesystem layout
88 # install compiled files
89 (cd ../..; make DESTDIR=$initdir install)
91 # remove unneeded documentation
92 rm -fr $initdir/usr/share/{man,doc,gtk-doc}
94 # install possible missing libraries
95 for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
99 # make a journal directory
100 mkdir -p $initdir/var/log/journal
102 # install some basic config files
103 inst /etc/sysconfig/init
108 inst /etc/nsswitch.conf
113 # we want an empty environment
114 > $initdir/etc/environment
115 > $initdir/etc/machine-id
118 echo systemd-testsuite > $initdir/etc/hostname
120 eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
122 cat >$initdir/etc/fstab <<EOF
123 LABEL=systemd / ext3 rw 0 1
126 # setup the testsuite target and the test ending service
127 cp $TEST_BASE_DIR/{testsuite.target,end.service} $initdir/etc/systemd/system/
129 # setup the testsuite service
130 cat >$initdir/etc/systemd/system/testsuite.service <<EOF
132 Description=Testsuite service
133 After=multi-user.target
136 ExecStart=/bin/bash -c 'set -x; systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok; while : ;do echo "testsuite service waiting for journal to move to /var/log/journal" > /dev/console ; for i in /var/log/journal/*;do [ -d "\$i" ] && echo "\$i" && break 2; done; sleep 1; done; sleep 1; exit 0;'
140 mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
141 ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
142 ln -fs ../end.service $initdir/etc/systemd/system/testsuite.target.wants/end.service
144 # make the testsuite the default target
145 ln -fs testsuite.target $initdir/etc/systemd/system/default.target
146 mkdir -p $initdir/etc/rc.d
147 cat >$initdir/etc/rc.d/rc.local <<EOF
151 chmod 0755 $initdir/etc/rc.d/rc.local
152 # install basic tools needed
153 dracut_install sh bash setsid loadkeys setfont \
154 login sushell sulogin gzip sleep echo mount umount cryptsetup
155 dracut_install dmsetup modprobe
157 # install libnss_files for login
158 inst_libdir_file "libnss_files*"
160 # install dbus and pam
166 /lib/security -xtype f \
167 | while read file; do
171 # install dbus socket and service file
172 inst /usr/lib/systemd/system/dbus.socket
173 inst /usr/lib/systemd/system/dbus.service
175 # install basic keyboard maps and fonts
177 /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
178 /usr/lib/kbd/keymaps/include/* \
179 /usr/lib/kbd/keymaps/i386/include/* \
180 /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
181 [[ -f $i ]] || continue
185 # some basic terminfo files
186 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
187 [ -f ${_terminfodir}/l/linux ] && break
189 dracut_install -o ${_terminfodir}/l/linux
192 ln -fs /proc/self/mounts $initdir/etc/mtab
194 # install any Exec's from the service files
195 egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
197 i=${i##Exec*=}; i=${i##-}
201 # install plymouth, if found... else remove plymouth service files
202 # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
203 # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
204 # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
205 # dracut_install plymouth plymouthd
207 rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
210 # some helper tools for debugging
211 [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
213 # install ld.so.conf* and run ldconfig
214 cp -a /etc/ld.so.conf* $initdir/etc
215 ldconfig -r "$initdir"
216 ddebug "Strip binaries"
217 find "$initdir" -perm +111 -type f | xargs strip --strip-unneeded | ddebug
220 inst /lib/modules/$KERNEL_VER/modules.order
221 inst /lib/modules/$KERNEL_VER/modules.builtin
222 # generate module dependencies
223 if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
224 ! depmod -a -b "$initdir" $KERNEL_VER; then
225 dfatal "\"depmod -a $KERNEL_VER\" failed."
229 rm -fr $TESTDIR/nspawn-root
230 ddebug "cp -ar $TESTDIR/root $TESTDIR/nspawn-root"
231 cp -ar $TESTDIR/root $TESTDIR/nspawn-root
232 # we don't mount in the nspawn root
233 rm -f $TESTDIR/nspawn-root/etc/fstab
235 ddebug "umount $TESTDIR/root"
240 umount $TESTDIR/root 2>/dev/null
241 [[ $LOOPDEV ]] && losetup -d $LOOPDEV
245 . $TEST_BASE_DIR/test-functions