test-functions revision 3486cb6cfa3d32a95c0daf02c7510fdf372507bf
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen# ex: ts=8 sw=4 sts=4 et filetype=sh
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersenif ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom GundersenBASICTOOLS="sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe"
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom GundersenDEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort"
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a kvm qemu-kvm 2>/dev/null | grep '^/' -m1)
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen # QEMU's own build system calls it qemu-system-x86_64
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-x86_64 2>/dev/null | grep '^/' -m1)
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-i386 2>/dev/null | grep '^/' -m1)
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu 2>/dev/null | grep '^/' -m1)
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen echo "Could not find a suitable QEMU binary" >&2
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen [ "$KERNEL_BIN" ] || KERNEL_BIN=/boot/vmlinuz-$KERNEL_VER
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen [ "$INITRD" ] || INITRD=/boot/initramfs-${KERNEL_VER}.img
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersenraid=noautodetect \
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersenconsole=ttyS0 \
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND" $TESTDIR/rootdisk.img ) || return 1
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen ../../systemd-nspawn --boot --directory=$TESTDIR/nspawn-root $ROOTLIBDIR/systemd $KERNEL_APPEND
79008bddf679a5e0900369950eb346c9fa687107Lennart Poettering ln -fs /proc/self/mounts $initdir/etc/mtab
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen type -P dmeventd >/dev/null && dracut_install dmeventd
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen (cd $TEST_BASE_DIR/..; set -x; make DESTDIR=$initdir install)
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen # we strip binaries since debug symbols increase binaries size a lot
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen # Create the blank file to use as a root filesystem
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen dd if=/dev/null of="$TESTDIR/rootdisk.img" bs=1M seek=300
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen [[ -f $TESTDIR/nspawn-root/failed ]] && cp -a $TESTDIR/nspawn-root/failed $TESTDIR
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | xargs strip --strip-unneeded | ddebug
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen | while read i; do
be19c5b5e0c0f78b8429b126936fa15856550a23David Herrmann if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen # install plymouth, if found... else remove plymouth service files
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
b45e4eb679ad0c9a77c4fe6e404c8842d4097fdbTom Gundersen # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen echo systemd-testsuite > $initdir/etc/hostname
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom GundersenLABEL=systemd / ext3 rw 0 1
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen [[ $BASICTOOLS ]] && dracut_install $BASICTOOLS
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
find \
| while read file; do
find \
| while read file; do
for i in \
inst $i
for i in \
/usr/lib/kbd/consolefonts/eurlatgr* \
/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;;