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 . $TEST_BASE_DIR/test-functions
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"
13 # TODO: qemu wrapper script: http://www.spinics.net/lists/kvm/msg72389.html
15 -hda $TESTDIR/rootdisk.img \
17 -net none -kernel /boot/vmlinuz-$KERNEL_VER \
18 -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
21 mkdir -p $TESTDIR/root
22 mount ${LOOPDEV}p1 $TESTDIR/root
23 [[ -e $TESTDIR/root/testok ]] && ret=0
24 cp -a $TESTDIR/root/failed $TESTDIR
25 cp -a $TESTDIR/root/var/log/journal $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/failed $TESTDIR
39 cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
41 ls -l $TESTDIR/journal/*/*.journal
42 test -s $TESTDIR/failed && ret=$(($ret+1))
51 dwarn "can't run qemu-kvm, skipping"
54 run_nspawn || return 1
56 dwarn "can't run systemd-nspawn, skipping"
62 rm -f $TESTDIR/rootdisk.img
63 # Create the blank file to use as a root filesystem
64 dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=200
65 LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
66 [ -b $LOOPDEV ] || return 1
67 echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
68 sfdisk -C 6400 -H 2 -S 32 -L $LOOPDEV <<EOF
73 mkfs.ext3 -L systemd ${LOOPDEV}p1
74 echo -n test >$TESTDIR/keyfile
75 mkdir -p $TESTDIR/root
76 mount ${LOOPDEV}p1 $TESTDIR/root
77 mkdir -p $TESTDIR/root/run
79 # Create what will eventually be our root filesystem onto an overlay
84 # create the basic filesystem layout
87 # install compiled files
88 (cd ../..; make DESTDIR=$initdir install)
90 # remove unneeded documentation
91 rm -fr $initdir/usr/share/{man,doc,gtk-doc}
93 # install possible missing libraries
94 for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
98 # make a journal directory
99 mkdir -p $initdir/var/log/journal
101 # install some basic config files
102 inst /etc/sysconfig/init
107 inst /etc/nsswitch.conf
112 # we want an empty environment
113 > $initdir/etc/environment
114 > $initdir/etc/machine-id
117 echo systemd-testsuite > $initdir/etc/hostname
119 eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
121 cat >$initdir/etc/fstab <<EOF
122 LABEL=systemd / ext3 rw 0 1
125 # setup the testsuite target and the test ending service
126 cp $TEST_BASE_DIR/{testsuite.target,end.service} $initdir/etc/systemd/system/
128 # setup the testsuite service
129 cat >$initdir/etc/systemd/system/testsuite.service <<EOF
131 Description=Testsuite service
132 After=multi-user.target
135 ExecStart=/bin/bash -c 'set -x; ( systemctl --failed --no-legend --no-pager; systemctl status --failed ) > /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;'
139 mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
140 ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
141 ln -fs ../end.service $initdir/etc/systemd/system/testsuite.target.wants/end.service
143 # make the testsuite the default target
144 ln -fs testsuite.target $initdir/etc/systemd/system/default.target
145 mkdir -p $initdir/etc/rc.d
146 cat >$initdir/etc/rc.d/rc.local <<EOF
150 chmod 0755 $initdir/etc/rc.d/rc.local
151 # install basic tools needed
152 dracut_install sh bash setsid loadkeys setfont \
153 login sushell sulogin gzip sleep echo mount umount cryptsetup
154 dracut_install dmsetup modprobe
156 # install libnss_files for login
157 inst_libdir_file "libnss_files*"
159 # install dbus and pam
165 /lib/security -xtype f \
166 | while read file; do
170 # install dbus socket and service file
171 inst /usr/lib/systemd/system/dbus.socket
172 inst /usr/lib/systemd/system/dbus.service
174 # install basic keyboard maps and fonts
176 /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
177 /usr/lib/kbd/keymaps/include/* \
178 /usr/lib/kbd/keymaps/i386/include/* \
179 /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
180 [[ -f $i ]] || continue
184 # some basic terminfo files
185 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
186 [ -f ${_terminfodir}/l/linux ] && break
188 dracut_install -o ${_terminfodir}/l/linux
191 ln -fs /proc/self/mounts $initdir/etc/mtab
193 # install any Execs from the service files
194 egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
196 i=${i##Exec*=}; i=${i##-}
200 # install plymouth, if found... else remove plymouth service files
201 # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
202 # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
203 # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
204 # dracut_install plymouth plymouthd
206 rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
209 # some helper tools for debugging
210 [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
212 # install ld.so.conf* and run ldconfig
213 cp -a /etc/ld.so.conf* $initdir/etc
214 ldconfig -r "$initdir"
215 ddebug "Strip binaries"
216 find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | xargs strip --strip-unneeded | ddebug
219 inst /lib/modules/$KERNEL_VER/modules.order
220 inst /lib/modules/$KERNEL_VER/modules.builtin
221 # generate module dependencies
222 if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
223 ! depmod -a -b "$initdir" $KERNEL_VER; then
224 dfatal "\"depmod -a $KERNEL_VER\" failed."
228 rm -fr $TESTDIR/nspawn-root
229 ddebug "cp -ar $TESTDIR/root $TESTDIR/nspawn-root"
230 cp -ar $TESTDIR/root $TESTDIR/nspawn-root
231 # we don't mount in the nspawn root
232 rm -f $TESTDIR/nspawn-root/etc/fstab
234 ddebug "umount $TESTDIR/root"
239 umount $TESTDIR/root 2>/dev/null
240 [[ $LOOPDEV ]] && losetup -d $LOOPDEV