chiark / gitweb /
test/TEST-01-BASIC: untabified
[elogind.git] / test / TEST-01-BASIC / 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="Basic systemd setup"
5
6 KVERSION=${KVERSION-$(uname -r)}
7
8 # Uncomment this to debug failures
9 #DEBUGFAIL="systemd.unit=multi-user.target"
10
11 test_run() {
12     qemu-kvm \
13         -hda $TESTDIR/rootdisk.img \
14         -m 256M -nographic \
15         -net none -kernel /boot/vmlinuz-$KVERSION \
16         -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd rw console=ttyS0,115200n81 selinux=0 $DEBUGFAIL"
17     ret=1
18     mkdir -p $TESTDIR/root
19     mount ${LOOPDEV}p1 $TESTDIR/root
20     [[ -e $TESTDIR/root/testok ]] && ret=0
21     cp -a $TESTDIR/root/var/log/journal $TESTDIR
22     cp -a $TESTDIR/root/failed $TESTDIR
23     umount $TESTDIR/root
24     cat $TESTDIR/failed
25     ls -l $TESTDIR/journal/*/*.journal
26     test -s $TESTDIR/failed && ret=$(($ret+1))
27     return $ret
28 }
29
30 test_setup() {
31     rm -f $TESTDIR/rootdisk.img
32     # Create the blank file to use as a root filesystem
33     dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=100
34     LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
35     [ -b $LOOPDEV ] || return 1
36     echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
37     sfdisk -C 3200 -H 2 -S 32 -L $LOOPDEV <<EOF
38 ,
39 EOF
40
41     mkfs.ext3 -L systemd ${LOOPDEV}p1
42     mkdir -p $TESTDIR/root
43     mount ${LOOPDEV}p1 $TESTDIR/root
44     mkdir -p $TESTDIR/root/run
45
46     kernel=$KVERSION
47     # Create what will eventually be our root filesystem onto an overlay
48     (
49         LOG_LEVEL=5
50         initdir=$TESTDIR/root
51
52         # create the basic filesystem layout
53         setup_basic_dirs
54
55         # install compiled files
56         (cd ../..; make DESTDIR=$initdir install)
57
58         # install possible missing libraries
59         for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
60             inst_libs $i
61         done
62
63         # activate kmsg import
64         echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf
65
66         # make a journal directory
67         mkdir -p $initdir/var/log/journal
68
69         # install some basic config files
70         inst /etc/sysconfig/init
71         inst /etc/passwd
72         inst /etc/shadow
73         inst /etc/group
74         inst /etc/shells
75         inst /etc/nsswitch.conf
76         inst /etc/pam.conf
77         inst /etc/securetty
78         inst /etc/os-release
79         inst /etc/localtime
80         # we want an empty environment
81         > $initdir/etc/environment
82
83         # set the hostname
84         echo  systemd-testsuite > $initdir/etc/hostname
85
86         # setup the testsuite target
87         cat >$initdir/etc/systemd/system/testsuite.target <<EOF
88 [Unit]
89 Description=Testsuite target
90 Requires=multi-user.target
91 After=multi-user.target
92 Conflicts=rescue.target
93 AllowIsolate=yes
94 EOF
95
96         # setup the testsuite service
97         cat >$initdir/etc/systemd/system/testsuite.service <<EOF
98 [Unit]
99 Description=Testsuite service
100 After=multi-user.target
101
102 [Service]
103 ExecStart=/bin/sh -c 'systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok'
104 ExecStartPost=/usr/sbin/poweroff
105 Type=oneshot
106
107 EOF
108         mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
109         ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
110
111         # make the testsuite the default target
112         ln -fs testsuite.target $initdir/etc/systemd/system/default.target
113         mkdir -p $initdir/etc/rc.d
114         cat >$initdir/etc/rc.d/rc.local <<EOF
115 #!/bin/bash
116 exit 0
117 EOF
118         chmod 0755 $initdir/etc/rc.d/rc.local
119         # install basic tools needed
120         dracut_install sh bash setsid loadkeys setfont \
121             login sushell sulogin gzip sleep echo
122
123         # install libnss_files for login
124         inst_libdir_file "libnss_files*"
125
126         # install dbus and pam
127         find \
128             /etc/dbus-1 \
129             /etc/pam.d \
130             /etc/security \
131             /lib64/security \
132             /lib/security -xtype f \
133             | while read file; do
134             inst $file
135         done
136
137         # install dbus socket and service file
138         inst /usr/lib/systemd/system/dbus.socket
139         inst /usr/lib/systemd/system/dbus.service
140
141         # install basic keyboard maps and fonts
142         for i in \
143             /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
144             /usr/lib/kbd/keymaps/include/* \
145             /usr/lib/kbd/keymaps/i386/include/* \
146             /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
147                 [[ -f $i ]] || continue
148                 inst $i
149         done
150
151         # some basic terminfo files
152         for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
153             [ -f ${_terminfodir}/l/linux ] && break
154         done
155         dracut_install -o ${_terminfodir}/l/linux
156
157         # softlink mtab
158         ln -fs /proc/self/mounts $initdir/etc/mtab
159
160         # install any Exec's from the service files
161         egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
162             | while read i; do
163             i=${i##Exec*=}; i=${i##-}
164             inst $i
165         done
166
167         # install plymouth, if found... else remove plymouth service files
168         if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
169             PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
170                 /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
171                 dracut_install plymouth plymouthd
172         else
173                 rm -f $initdir/usr/lib/systemd/system/plymouth* $initdir/usr/lib/systemd/system/*/plymouth*
174         fi
175
176         # some helper tools for debugging
177         dracut_install sh df free ls shutdown poweroff \
178             stty cat ps ln ip route \
179             mount dmesg dhclient mkdir cp ping dhclient \
180             umount strace less grep id tty touch
181
182         # install ld.so.conf* and run ldconfig
183         cp -a /etc/ld.so.conf* $initdir/etc
184         ldconfig -r "$initdir"
185
186     )
187     umount $TESTDIR/root
188
189 }
190
191 test_cleanup() {
192     umount $TESTDIR/root 2>/dev/null
193     [[ $LOOPDEV ]] && losetup -d $LOOPDEV
194     return 0
195 }
196
197 . $TEST_BASE_DIR/test-functions
198 do_test "$@"