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 cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile
27 mount /dev/mapper/varcrypt $TESTDIR/root/var
28 cp -a $TESTDIR/root/var/log/journal $TESTDIR
29 umount $TESTDIR/root/var
31 cryptsetup luksClose /dev/mapper/varcrypt
33 ls -l $TESTDIR/journal/*/*.journal
34 test -s $TESTDIR/failed && ret=$(($ret+1))
40 systemd-nspawn -b -D $TESTDIR/nspawn-root --capability=CAP_AUDIT_CONTROL,CAP_AUDIT_WRITE /usr/lib/systemd/systemd
42 [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
43 cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
44 cp -a $TESTDIR/nspawn-root/failed $TESTDIR
46 ls -l $TESTDIR/journal/*/*.journal
47 test -s $TESTDIR/failed && ret=$(($ret+1))
56 dwarn "can't run qemu-kvm, skipping"
59 run_nspawn || return 1
61 dwarn "can't run systemd-nspawn, skipping"
67 rm -f $TESTDIR/rootdisk.img
68 # Create the blank file to use as a root filesystem
69 dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=200
70 LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
71 [ -b $LOOPDEV ] || return 1
72 echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
73 sfdisk -C 6400 -H 2 -S 32 -L $LOOPDEV <<EOF
78 mkfs.ext3 -L systemd ${LOOPDEV}p1
79 echo -n test >$TESTDIR/keyfile
80 cryptsetup -q luksFormat ${LOOPDEV}p2 $TESTDIR/keyfile
81 cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile
82 mkfs.ext3 -L var /dev/mapper/varcrypt
83 mkdir -p $TESTDIR/root
84 mount ${LOOPDEV}p1 $TESTDIR/root
85 mkdir -p $TESTDIR/root/run
86 mkdir -p $TESTDIR/root/var
87 mount /dev/mapper/varcrypt $TESTDIR/root/var
89 # Create what will eventually be our root filesystem onto an overlay
94 # create the basic filesystem layout
97 # install compiled files
98 (cd ../..; make DESTDIR=$initdir install)
100 # remove unneeded documentation
101 rm -fr $initdir/usr/share/{man,doc,gtk-doc}
103 # install possible missing libraries
104 for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
108 # activate kmsg import
109 echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf
111 # make a journal directory
112 mkdir -p $initdir/var/log/journal
114 # install some basic config files
115 inst /etc/sysconfig/init
120 inst /etc/nsswitch.conf
125 # we want an empty environment
126 > $initdir/etc/environment
127 > $initdir/etc/machine-id
130 echo systemd-testsuite > $initdir/etc/hostname
132 eval $(udevadm info --export --query=env --name=/dev/mapper/varcrypt)
133 eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
135 cat >$initdir/etc/crypttab <<EOF
136 $DM_NAME UUID=$ID_FS_UUID /etc/varkey
138 echo -n test > $initdir/etc/varkey
139 cat $initdir/etc/crypttab | ddebug
141 cat >$initdir/etc/fstab <<EOF
142 LABEL=systemd / ext3 rw 0 1
143 /dev/mapper/varcrypt /var ext3 defaults 0 1
146 # setup the testsuite target
147 cat >$initdir/etc/systemd/system/testsuite.target <<EOF
149 Description=Testsuite target
150 Requires=multi-user.target
151 After=multi-user.target
152 Conflicts=rescue.target
156 # setup the testsuite service
157 cat >$initdir/etc/systemd/system/testsuite.service <<EOF
159 Description=Testsuite service
160 After=multi-user.target
163 ExecStart=/bin/bash -c 'set -x; systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok; while : ;do systemd-cat echo "testsuite service waiting for /var/log/journal" ; 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;'
164 ExecStopPost=/usr/bin/systemctl poweroff
167 mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
168 ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
170 # make the testsuite the default target
171 ln -fs testsuite.target $initdir/etc/systemd/system/default.target
172 mkdir -p $initdir/etc/rc.d
173 cat >$initdir/etc/rc.d/rc.local <<EOF
177 chmod 0755 $initdir/etc/rc.d/rc.local
178 # install basic tools needed
179 dracut_install sh bash setsid loadkeys setfont \
180 login sushell sulogin gzip sleep echo mount umount cryptsetup
181 dracut_install dmsetup modprobe
183 instmods dm_crypt =crypto
185 type -P dmeventd >/dev/null && dracut_install dmeventd
187 inst_libdir_file "libdevmapper-event.so*"
189 inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
191 # install libnss_files for login
192 inst_libdir_file "libnss_files*"
194 # install dbus and pam
200 /lib/security -xtype f \
201 | while read file; do
205 # install dbus socket and service file
206 inst /usr/lib/systemd/system/dbus.socket
207 inst /usr/lib/systemd/system/dbus.service
209 # install basic keyboard maps and fonts
211 /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
212 /usr/lib/kbd/keymaps/include/* \
213 /usr/lib/kbd/keymaps/i386/include/* \
214 /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
215 [[ -f $i ]] || continue
219 # some basic terminfo files
220 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
221 [ -f ${_terminfodir}/l/linux ] && break
223 dracut_install -o ${_terminfodir}/l/linux
226 ln -fs /proc/self/mounts $initdir/etc/mtab
228 # install any Exec's from the service files
229 egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
231 i=${i##Exec*=}; i=${i##-}
235 # install plymouth, if found... else remove plymouth service files
236 # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
237 # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
238 # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
239 # dracut_install plymouth plymouthd
241 rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
244 # some helper tools for debugging
245 [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
247 # install ld.so.conf* and run ldconfig
248 cp -a /etc/ld.so.conf* $initdir/etc
249 ldconfig -r "$initdir"
250 ddebug "Strip binaeries"
251 find "$initdir" -perm +111 -type f | xargs strip --strip-unneeded | ddebug
254 inst /lib/modules/$KERNEL_VER/modules.order
255 inst /lib/modules/$KERNEL_VER/modules.builtin
256 # generate module dependencies
257 if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
258 ! depmod -a -b "$initdir" $KERNEL_VER; then
259 dfatal "\"depmod -a $KERNEL_VER\" failed."
263 rm -fr $TESTDIR/nspawn-root
264 ddebug "cp -ar $TESTDIR/root $TESTDIR/nspawn-root"
265 cp -ar $TESTDIR/root $TESTDIR/nspawn-root
266 # we don't mount in the nspawn root
267 rm -fr $TESTDIR/nspawn-root/etc/fstab
269 ddebug "umount $TESTDIR/root/var"
270 umount $TESTDIR/root/var
271 cryptsetup luksClose /dev/mapper/varcrypt
272 ddebug "umount $TESTDIR/root"
277 umount $TESTDIR/root/var 2>/dev/null
278 [[ -b /dev/mapper/varcrypt ]] && cryptsetup luksClose /dev/mapper/varcrypt
279 umount $TESTDIR/root 2>/dev/null
280 [[ $LOOPDEV ]] && losetup -d $LOOPDEV
284 . $TEST_BASE_DIR/test-functions