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="Job-related tests"
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=/test-jobs.sh
140 # copy the units used by this test
141 cp $TEST_BASE_DIR/{hello.service,sleep.service,hello-after-sleep.target,unstoppable.service} \
142 $initdir/etc/systemd/system
143 cp test-jobs.sh $initdir/
145 mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
146 ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
147 ln -fs ../end.service $initdir/etc/systemd/system/testsuite.target.wants/end.service
149 # make the testsuite the default target
150 ln -fs testsuite.target $initdir/etc/systemd/system/default.target
151 mkdir -p $initdir/etc/rc.d
152 cat >$initdir/etc/rc.d/rc.local <<EOF
156 chmod 0755 $initdir/etc/rc.d/rc.local
157 # install basic tools needed
158 dracut_install sh bash setsid loadkeys setfont \
159 login sushell sulogin gzip sleep echo mount umount cryptsetup date
160 dracut_install dmsetup modprobe
162 # install libnss_files for login
163 inst_libdir_file "libnss_files*"
165 # install dbus and pam
171 /lib/security -xtype f \
172 | while read file; do
176 # install dbus socket and service file
177 inst /usr/lib/systemd/system/dbus.socket
178 inst /usr/lib/systemd/system/dbus.service
180 # install basic keyboard maps and fonts
182 /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
183 /usr/lib/kbd/keymaps/include/* \
184 /usr/lib/kbd/keymaps/i386/include/* \
185 /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
186 [[ -f $i ]] || continue
190 # some basic terminfo files
191 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
192 [ -f ${_terminfodir}/l/linux ] && break
194 dracut_install -o ${_terminfodir}/l/linux
197 ln -fs /proc/self/mounts $initdir/etc/mtab
199 # install any Exec's from the service files
200 egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
202 i=${i##Exec*=}; i=${i##-}
206 # install plymouth, if found... else remove plymouth service files
207 # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
208 # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
209 # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
210 # dracut_install plymouth plymouthd
212 rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
215 # some helper tools for debugging
216 [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
218 # install ld.so.conf* and run ldconfig
219 cp -a /etc/ld.so.conf* $initdir/etc
220 ldconfig -r "$initdir"
221 ddebug "Strip binaeries"
222 find "$initdir" -perm +111 -type f | xargs strip --strip-unneeded | ddebug
225 inst /lib/modules/$KERNEL_VER/modules.order
226 inst /lib/modules/$KERNEL_VER/modules.builtin
227 # generate module dependencies
228 if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
229 ! depmod -a -b "$initdir" $KERNEL_VER; then
230 dfatal "\"depmod -a $KERNEL_VER\" failed."
234 rm -fr $TESTDIR/nspawn-root
235 ddebug "cp -ar $TESTDIR/root $TESTDIR/nspawn-root"
236 cp -ar $TESTDIR/root $TESTDIR/nspawn-root
237 # we don't mount in the nspawn root
238 rm -fr $TESTDIR/nspawn-root/etc/fstab
240 ddebug "umount $TESTDIR/root"
245 umount $TESTDIR/root 2>/dev/null
246 [[ $LOOPDEV ]] && losetup -d $LOOPDEV
250 . $TEST_BASE_DIR/test-functions