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 merging"
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} $initdir/etc/systemd/system
142 cp test-jobs.sh $initdir/
144 mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
145 ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
146 ln -fs ../end.service $initdir/etc/systemd/system/testsuite.target.wants/end.service
148 # make the testsuite the default target
149 ln -fs testsuite.target $initdir/etc/systemd/system/default.target
150 mkdir -p $initdir/etc/rc.d
151 cat >$initdir/etc/rc.d/rc.local <<EOF
155 chmod 0755 $initdir/etc/rc.d/rc.local
156 # install basic tools needed
157 dracut_install sh bash setsid loadkeys setfont \
158 login sushell sulogin gzip sleep echo mount umount cryptsetup date
159 dracut_install dmsetup modprobe
161 # install libnss_files for login
162 inst_libdir_file "libnss_files*"
164 # install dbus and pam
170 /lib/security -xtype f \
171 | while read file; do
175 # install dbus socket and service file
176 inst /usr/lib/systemd/system/dbus.socket
177 inst /usr/lib/systemd/system/dbus.service
179 # install basic keyboard maps and fonts
181 /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
182 /usr/lib/kbd/keymaps/include/* \
183 /usr/lib/kbd/keymaps/i386/include/* \
184 /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
185 [[ -f $i ]] || continue
189 # some basic terminfo files
190 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
191 [ -f ${_terminfodir}/l/linux ] && break
193 dracut_install -o ${_terminfodir}/l/linux
196 ln -fs /proc/self/mounts $initdir/etc/mtab
198 # install any Exec's from the service files
199 egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
201 i=${i##Exec*=}; i=${i##-}
205 # install plymouth, if found... else remove plymouth service files
206 # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
207 # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
208 # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
209 # dracut_install plymouth plymouthd
211 rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
214 # some helper tools for debugging
215 [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
217 # install ld.so.conf* and run ldconfig
218 cp -a /etc/ld.so.conf* $initdir/etc
219 ldconfig -r "$initdir"
220 ddebug "Strip binaeries"
221 find "$initdir" -perm +111 -type f | xargs strip --strip-unneeded | ddebug
224 inst /lib/modules/$KERNEL_VER/modules.order
225 inst /lib/modules/$KERNEL_VER/modules.builtin
226 # generate module dependencies
227 if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
228 ! depmod -a -b "$initdir" $KERNEL_VER; then
229 dfatal "\"depmod -a $KERNEL_VER\" failed."
233 rm -fr $TESTDIR/nspawn-root
234 ddebug "cp -ar $TESTDIR/root $TESTDIR/nspawn-root"
235 cp -ar $TESTDIR/root $TESTDIR/nspawn-root
236 # we don't mount in the nspawn root
237 rm -fr $TESTDIR/nspawn-root/etc/fstab
239 ddebug "umount $TESTDIR/root"
244 umount $TESTDIR/root 2>/dev/null
245 [[ $LOOPDEV ]] && losetup -d $LOOPDEV
249 . $TEST_BASE_DIR/test-functions