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)}
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"
15 -hda $TESTDIR/rootdisk.img \
17 -net none -kernel /boot/vmlinuz-$KVERSION \
18 -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd rw console=ttyS0,115200n81 selinux=0 $DEBUGFAIL"
20 mkdir -p $TESTDIR/root
21 mount ${LOOPDEV}p1 $TESTDIR/root
22 [[ -e $TESTDIR/root/testok ]] && ret=0
23 cp -a $TESTDIR/root/var/log/journal $TESTDIR
24 cp -a $TESTDIR/root/failed $TESTDIR
27 ls -l $TESTDIR/journal/*/*.journal
28 test -s $TESTDIR/failed && ret=$(($ret+1))
34 systemd-nspawn -b -D $TESTDIR/nspawn-root /usr/lib/systemd/systemd
36 [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
37 cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
38 cp -a $TESTDIR/nspawn-root/failed $TESTDIR
40 ls -l $TESTDIR/journal/*/*.journal
41 test -s $TESTDIR/failed && ret=$(($ret+1))
48 if [[ -d /sys/fs/cgroup/systemd ]]; then
49 run_nspawn || return 1
55 rm -f $TESTDIR/rootdisk.img
56 # Create the blank file to use as a root filesystem
57 dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=100
58 LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
59 [ -b $LOOPDEV ] || return 1
60 echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
61 sfdisk -C 3200 -H 2 -S 32 -L $LOOPDEV <<EOF
65 mkfs.ext3 -L systemd ${LOOPDEV}p1
66 mkdir -p $TESTDIR/root
67 mount ${LOOPDEV}p1 $TESTDIR/root
68 mkdir -p $TESTDIR/root/run
71 # Create what will eventually be our root filesystem onto an overlay
76 # create the basic filesystem layout
79 # install compiled files
80 (cd ../..; make DESTDIR=$initdir install)
82 # install possible missing libraries
83 for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
87 # activate kmsg import
88 echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf
90 # make a journal directory
91 mkdir -p $initdir/var/log/journal
93 # install some basic config files
94 inst /etc/sysconfig/init
99 inst /etc/nsswitch.conf
104 # we want an empty environment
105 > $initdir/etc/environment
108 echo systemd-testsuite > $initdir/etc/hostname
110 # setup the testsuite target
111 cat >$initdir/etc/systemd/system/testsuite.target <<EOF
113 Description=Testsuite target
114 Requires=multi-user.target
115 After=multi-user.target
116 Conflicts=rescue.target
120 # setup the testsuite service
121 cat >$initdir/etc/systemd/system/testsuite.service <<EOF
123 Description=Testsuite service
124 After=multi-user.target
127 ExecStart=/bin/sh -c 'systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok'
128 ExecStartPost=/usr/sbin/poweroff
132 mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
133 ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
135 # make the testsuite the default target
136 ln -fs testsuite.target $initdir/etc/systemd/system/default.target
137 mkdir -p $initdir/etc/rc.d
138 cat >$initdir/etc/rc.d/rc.local <<EOF
142 chmod 0755 $initdir/etc/rc.d/rc.local
143 # install basic tools needed
144 dracut_install sh bash setsid loadkeys setfont \
145 login sushell sulogin gzip sleep echo
147 # install libnss_files for login
148 inst_libdir_file "libnss_files*"
150 # install dbus and pam
156 /lib/security -xtype f \
157 | while read file; do
161 # install dbus socket and service file
162 inst /usr/lib/systemd/system/dbus.socket
163 inst /usr/lib/systemd/system/dbus.service
165 # install basic keyboard maps and fonts
167 /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
168 /usr/lib/kbd/keymaps/include/* \
169 /usr/lib/kbd/keymaps/i386/include/* \
170 /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
171 [[ -f $i ]] || continue
175 # some basic terminfo files
176 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
177 [ -f ${_terminfodir}/l/linux ] && break
179 dracut_install -o ${_terminfodir}/l/linux
182 ln -fs /proc/self/mounts $initdir/etc/mtab
184 # install any Exec's from the service files
185 egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
187 i=${i##Exec*=}; i=${i##-}
191 # install plymouth, if found... else remove plymouth service files
192 if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
193 PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
194 /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
195 dracut_install plymouth plymouthd
197 rm -f $initdir/usr/lib/systemd/system/plymouth* $initdir/usr/lib/systemd/system/*/plymouth*
200 # some helper tools for debugging
201 [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
203 # install ld.so.conf* and run ldconfig
204 cp -a /etc/ld.so.conf* $initdir/etc
205 ldconfig -r "$initdir"
208 rm -fr $TESTDIR/nspawn-root
209 cp -avr $TESTDIR/root $TESTDIR/nspawn-root
215 umount $TESTDIR/root 2>/dev/null
216 [[ $LOOPDEV ]] && losetup -d $LOOPDEV
220 . $TEST_BASE_DIR/test-functions