test-functions revision 739d81ddd005fae2bb82edce5b8a6173c7c48b34
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poettering# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poettering# ex: ts=8 sw=4 sts=4 et filetype=sh
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart PoetteringBASICTOOLS="sh bash setsid loadkeys setfont login sushell sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe"
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart PoetteringDEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort"
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poettering # SUSE and Red Hat call the binary qemu-kvm
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poettering [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a kvm qemu-kvm 2>/dev/null | grep '^/' -m1)
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poettering # QEMU's own build system calls it qemu-system-x86_64
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersen [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-x86_64 2>/dev/null | grep '^/' -m1)
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-i386 2>/dev/null | grep '^/' -m1)
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poettering [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu 2>/dev/null | grep '^/' -m1)
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poettering echo "Could not find a suitable QEMU binary" >&2
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poettering [ "$KERNEL_BIN" ] || KERNEL_BIN=/boot/vmlinuz-$KERNEL_VER
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poettering [ "$INITRD" ] || INITRD=/boot/initramfs-${KERNEL_VER}.img
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poetteringraid=noautodetect \
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poetteringconsole=ttyS0 \
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering QEMU_OPTIONS="$QEMU_OPTIONS -initrd $INITRD"
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND" $TESTDIR/rootdisk.img || return 1
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering ../../systemd-nspawn --boot --directory=$TESTDIR/nspawn-root /usr/lib/systemd/systemd
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering ln -fs /proc/self/mounts $initdir/etc/mtab
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering type -P dmeventd >/dev/null && dracut_install dmeventd
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering inst_libdir_file "libdevmapper-event.so*"
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering (cd $TEST_BASE_DIR/..; make DESTDIR=$initdir install)
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering rm -fr $initdir/usr/share/{man,doc,gtk-doc}
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering # we strip binaries since debug symbols increase binaries size a lot
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering # Create the blank file to use as a root filesystem
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering dd if=/dev/null of="$TESTDIR/rootdisk.img" bs=1M seek=200
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering sfdisk -C 6400 -H 2 -S 32 -L "$LOOPDEV" <<EOF
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering [[ -f $TESTDIR/nspawn-root/failed ]] && cp -a $TESTDIR/nspawn-root/failed $TESTDIR
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering test -s $TESTDIR/failed && ret=$(($ret+1))
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | xargs strip --strip-unneeded | ddebug
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering # install any Execs from the service files
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering | while read i; do
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering ! depmod -a -b "$initdir" $KERNEL_VER; then
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering dfatal "\"depmod -a $KERNEL_VER\" failed."
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering inst /lib/modules/$KERNEL_VER/modules.order
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering inst /lib/modules/$KERNEL_VER/modules.builtin
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering # install plymouth, if found... else remove plymouth service files
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering echo systemd-testsuite > $initdir/etc/hostname
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart PoetteringLABEL=systemd / ext3 rw 0 1
d0a7c5f69207b6719bab94893035fc8f5f6f87cbLennart Poettering [[ $BASICTOOLS ]] && dracut_install $BASICTOOLS
99d4f5e5c0d2532159542519e683f976f881f0f5Lennart Poettering [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
99d4f5e5c0d2532159542519e683f976f881f0f5Lennart Poettering inst /usr/lib/systemd/system/dbus.service
99d4f5e5c0d2532159542519e683f976f881f0f5Lennart Poettering | while read file; do
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poettering | while read file; do
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poettering /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poettering [[ -f $i ]] || continue
78f22b973fa2c9b09bd974680836df17163d9ee0Lennart Poettering /usr/lib/kbd/consolefonts/latarcyrheb-sun16*; do
inst $i
[ -f ${_terminfodir}/l/linux ] && break
dracut_install -o ${_terminfodir}/l/linux
ln -fs $TEST_BASE_DIR/testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
for d in usr/bin usr/sbin bin etc lib "$libdir" sbin tmp usr var var/log dev proc sys sysroot root run run/lock run/initramfs; do
local _bin=$1
if [[ $_line =~ $_so_regex ]]; then
_file=${BASH_REMATCH[1]}
[[ -e $STATEFILE ]] && . $STATEFILE
export TESTDIR
export initdir
[ $1 -le $LOG_LEVEL ] || return 0
if [ $# -ge 1 ]; then
while read line; do
while [[ ${__absolute[__level]} == ${__current[__level]} ]]
if [[ -n $__newpath ]]
if [[ -L $_file ]]; then
# rev_lib_symlinks libfoo.so.8.1
if [[ -L $_src ]]; then
[[ -L $_bin ]] && inst_symlink $_bin $_target && return 0
if [[ $_line =~ $_so_regex ]]; then
_file=${BASH_REMATCH[1]}
local _bin
local _line _shebang_regex
[[ $_line =~ $_shebang_regex ]] || return 1
if [[ -d $_realsrc ]]; then
if [[ -f $r/$_rule ]]; then
if [[ -f ${r}$_rule ]]; then
local _x
case $# in
[[ $initdir = $2 ]] && set $1;;
for _x in inst_symlink inst_script inst_binary inst_simple; do
local to f
if [[ $_optional = yes ]]; then
if [[ $omit_drivers ]]; then
_found=1
local _modname _filtercmd
if ! [[ $hostonly ]]; then
if ! [[ $hostonly ]]; then
[[ $no_kernel = yes ]] && return
local _fderr=9
| instmods
| instmods
local _moddirname=${KERNEL_MODS%%/lib/modules/*}
--set-version $KERNEL_VER ${_moddirname} $_mpargs
return $_ret
while read _mod; do
set -o pipefail
| while read line; do [[ "$line" =~ $_filter_not_found ]] && echo $line || echo $line >&2 ;done | derror
_ret=$?
set +o pipefail
return $_ret
local _pattern=$1
case $1 in
--run)
ret=$?
exit $ret;;
--setup)
--clean)
--all)
ret=$?
exit $ret
ret=$?
exit $ret;;