test-functions revision 3486cb6cfa3d32a95c0daf02c7510fdf372507bf
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# ex: ts=8 sw=4 sts=4 et filetype=sh
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersenif ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom GundersenBASICTOOLS="sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe"
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom GundersenDEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort"
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a kvm qemu-kvm 2>/dev/null | grep '^/' -m1)
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen # QEMU's own build system calls it qemu-system-x86_64
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-x86_64 2>/dev/null | grep '^/' -m1)
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-i386 2>/dev/null | grep '^/' -m1)
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu 2>/dev/null | grep '^/' -m1)
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen echo "Could not find a suitable QEMU binary" >&2
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [ "$KERNEL_BIN" ] || KERNEL_BIN=/boot/vmlinuz-$KERNEL_VER
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [ "$INITRD" ] || INITRD=/boot/initramfs-${KERNEL_VER}.img
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersenraid=noautodetect \
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersenconsole=ttyS0 \
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND" $TESTDIR/rootdisk.img ) || return 1
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen ../../systemd-nspawn --boot --directory=$TESTDIR/nspawn-root $ROOTLIBDIR/systemd $KERNEL_APPEND
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen type -P dmeventd >/dev/null && dracut_install dmeventd
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen (cd $TEST_BASE_DIR/..; set -x; make DESTDIR=$initdir install)
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen # we strip binaries since debug symbols increase binaries size a lot
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen # Create the blank file to use as a root filesystem
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen dd if=/dev/null of="$TESTDIR/rootdisk.img" bs=1M seek=300
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [[ -f $TESTDIR/nspawn-root/failed ]] && cp -a $TESTDIR/nspawn-root/failed $TESTDIR
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | xargs strip --strip-unneeded | ddebug
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen | while read i; do
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen # install plymouth, if found... else remove plymouth service files
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen echo systemd-testsuite > $initdir/etc/hostname
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom GundersenLABEL=systemd / ext3 rw 0 1
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [[ $BASICTOOLS ]] && dracut_install $BASICTOOLS
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen | while read file; do
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen | while read file; do
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [[ -f $i ]] || continue
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen /usr/lib/kbd/consolefonts/latarcyrheb-sun16*; do
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [[ -f $i ]] || continue
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [ -f ${_terminfodir}/l/linux ] && break
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen cp $TEST_BASE_DIR/{testsuite.target,end.service} $initdir/etc/systemd/system/
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen ln -fs $TEST_BASE_DIR/testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen ln -fs $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/testsuite.target.wants/end.service
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen ln -fs testsuite.target $initdir/etc/systemd/system/default.target
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen 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
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [[ $_line = 'not a dynamic executable' ]] && break
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen if [[ $_line =~ $_so_regex ]]; then
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [[ -e ${initdir}/$_file ]] && continue
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen if [[ $_line =~ not\ found ]]; then
f0c4b1c3fd827b429ba36aa45fd39e0a023cbf2cTom Gundersen dfatal "Missing a shared library required by $_bin."
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen dfatal "Run \"ldd $_bin\" to find out what it is."
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX)
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen## @brief Converts numeric logging level to the first letter of level name.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @param lvl Numeric logging level in range from 1 to 6.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @retval 1 if @a lvl is out of range.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @retval 0 if @a lvl is correct.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @result Echoes first letter of level name.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen *) return 1;;
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen## @brief Internal helper function for _do_dlog()
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @param lvl Numeric logging level.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @param msg Message.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @retval 0 It's always returned, even if logging failed.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @note This function is not supposed to be called manually. Please use
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# dtrace(), ddebug(), or others instead which wrap this one.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# This function calls _do_dlog() either with parameter msg, or if
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# none is given, it will read standard input and will use every line as
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# This enables:
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# dwarn "This is a warning"
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# echo "This is a warning" | dwarn
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen [ $1 -le $LOG_LEVEL ] || return 0
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen if [ $# -ge 1 ]; then
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen while read line; do
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen## @brief Logs message at TRACE level (6)
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @param msg Message.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @retval 0 It's always returned, even if logging failed.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen## @brief Logs message at DEBUG level (5)
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @param msg Message.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @retval 0 It's always returned, even if logging failed.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# [ -n "$debug" ] && set -x || :
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen## @brief Logs message at INFO level (4)
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @param msg Message.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @retval 0 It's always returned, even if logging failed.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen## @brief Logs message at WARN level (3)
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @param msg Message.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @retval 0 It's always returned, even if logging failed.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen## @brief Logs message at ERROR level (2)
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @param msg Message.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# @retval 0 It's always returned, even if logging failed.
23fbe14f503c1e98292efc4ba1238adb7dc38d80Tom Gundersen# [ -n "$debug" ] && set -x || :
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;;