chiark / gitweb /
bootchart: rename log.c to store.c to aovid confusion with src/shared/log.c
[elogind.git] / test / TEST-03-JOBS / test.sh
1 #!/bin/bash
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"
5
6 KVERSION=${KVERSION-$(uname -r)}
7 KERNEL_VER=$(uname -r)
8
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"
12
13 run_qemu() {
14     # TODO: qemu wrapper script: http://www.spinics.net/lists/kvm/msg72389.html
15     qemu-kvm \
16         -hda $TESTDIR/rootdisk.img \
17         -m 512M -nographic \
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
20
21     ret=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
27     umount $TESTDIR/root
28     cat $TESTDIR/failed
29     ls -l $TESTDIR/journal/*/*.journal
30     test -s $TESTDIR/failed && ret=$(($ret+1))
31     return $ret
32 }
33
34
35 run_nspawn() {
36     ../../systemd-nspawn -b -D $TESTDIR/nspawn-root /usr/lib/systemd/systemd
37     ret=1
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
41     cat $TESTDIR/failed
42     ls -l $TESTDIR/journal/*/*.journal
43     test -s $TESTDIR/failed && ret=$(($ret+1))
44     return $ret
45 }
46
47
48 test_run() {
49     if check_qemu ; then
50         run_qemu || return 1
51     else
52         dwarn "can't run qemu-kvm, skipping"
53     fi
54     if check_nspawn; then
55         run_nspawn || return 1
56     else
57         dwarn "can't run systemd-nspawn, skipping"
58     fi
59     return 0
60 }
61
62 test_setup() {
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
70 ,3200
71 ,
72 EOF
73
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
79
80     # Create what will eventually be our root filesystem onto an overlay
81     (
82         LOG_LEVEL=5
83         initdir=$TESTDIR/root
84
85         # create the basic filesystem layout
86         setup_basic_dirs
87
88         # install compiled files
89         (cd ../..; make DESTDIR=$initdir install)
90
91         # remove unneeded documentation
92         rm -fr $initdir/usr/share/{man,doc,gtk-doc}
93
94         # install possible missing libraries
95         for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
96             inst_libs $i
97         done
98
99         # make a journal directory
100         mkdir -p $initdir/var/log/journal
101
102         # install some basic config files
103         inst /etc/sysconfig/init
104         inst /etc/passwd
105         inst /etc/shadow
106         inst /etc/group
107         inst /etc/shells
108         inst /etc/nsswitch.conf
109         inst /etc/pam.conf
110         inst /etc/securetty
111         inst /etc/os-release
112         inst /etc/localtime
113         # we want an empty environment
114         > $initdir/etc/environment
115         > $initdir/etc/machine-id
116
117         # set the hostname
118         echo  systemd-testsuite > $initdir/etc/hostname
119
120         eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
121
122         cat >$initdir/etc/fstab <<EOF
123 LABEL=systemd           /       ext3    rw 0 1
124 EOF
125
126         # setup the testsuite target and the test ending service
127         cp $TEST_BASE_DIR/{testsuite.target,end.service} $initdir/etc/systemd/system/
128
129         # setup the testsuite service
130         cat >$initdir/etc/systemd/system/testsuite.service <<EOF
131 [Unit]
132 Description=Testsuite service
133 After=multi-user.target
134
135 [Service]
136 ExecStart=/test-jobs.sh
137 Type=oneshot
138 EOF
139
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/
144
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
148
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
153 #!/bin/bash
154 exit 0
155 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
161
162         # install libnss_files for login
163         inst_libdir_file "libnss_files*"
164
165         # install dbus and pam
166         find \
167             /etc/dbus-1 \
168             /etc/pam.d \
169             /etc/security \
170             /lib64/security \
171             /lib/security -xtype f \
172             | while read file; do
173             inst $file
174         done
175
176         # install dbus socket and service file
177         inst /usr/lib/systemd/system/dbus.socket
178         inst /usr/lib/systemd/system/dbus.service
179
180         # install basic keyboard maps and fonts
181         for i in \
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
187                 inst $i
188         done
189
190         # some basic terminfo files
191         for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
192             [ -f ${_terminfodir}/l/linux ] && break
193         done
194         dracut_install -o ${_terminfodir}/l/linux
195
196         # softlink mtab
197         ln -fs /proc/self/mounts $initdir/etc/mtab
198
199         # install any Exec's from the service files
200         egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
201             | while read i; do
202             i=${i##Exec*=}; i=${i##-}
203             inst $i
204         done
205
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
211         # else
212         rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
213         # fi
214
215         # some helper tools for debugging
216         [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
217
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
223
224         # copy depmod files
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."
231                 exit 1
232         fi
233     )
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
239
240     ddebug "umount $TESTDIR/root"
241     umount $TESTDIR/root
242 }
243
244 test_cleanup() {
245     umount $TESTDIR/root 2>/dev/null
246     [[ $LOOPDEV ]] && losetup -d $LOOPDEV
247     return 0
248 }
249
250 . $TEST_BASE_DIR/test-functions
251 do_test "$@"