test-functions revision 24be78d72b931b0175f08cee12fd23d631c024bf
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering# ex: ts=8 sw=4 sts=4 et filetype=sh
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart PoetteringLOOKS_LIKE_DEBIAN=$(source /etc/os-release && [[ "$ID" = "debian" || "$ID_LIKE" = "debian" ]] && echo yes)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poetteringif ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart PoetteringBASICTOOLS="sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee"
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart PoetteringDEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname"
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering # SUSE and Red Hat call the binary qemu-kvm
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a kvm qemu-kvm 2>/dev/null | grep '^/' -m1)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering # QEMU's own build system calls it qemu-system-x86_64
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-x86_64 2>/dev/null | grep '^/' -m1)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-i386 2>/dev/null | grep '^/' -m1)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu 2>/dev/null | grep '^/' -m1)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering echo "Could not find a suitable QEMU binary" >&2
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering if [ -f /etc/machine-id ]; then
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering [ -z "$INITRD" ] && [ -e "/boot/$MACHINE_ID/$KERNEL_VER/initrd" ] \
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering && INITRD="/boot/$MACHINE_ID/$KERNEL_VER/initrd"
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering [ -z "$KERNEL_BIN" ] && [ -e "/boot/$MACHINE_ID/$KERNEL_VER/linux" ] \
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering && KERNEL_BIN="/boot/$MACHINE_ID/$KERNEL_VER/linux"
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering default_fedora_initrd=/boot/initramfs-${KERNEL_VER}.img
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering default_debian_initrd=/boot/initrd.img-${KERNEL_VER}
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering [ "$KERNEL_BIN" ] || KERNEL_BIN=/boot/vmlinuz-$KERNEL_VER
875c6e1b48f37a07dfbb80d6653c73f205e94260Lennart Poettering [ "$INITRD" ] || { [ -e "$default_fedora_initrd" ] && INITRD=$default_fedora_initrd; }
875c6e1b48f37a07dfbb80d6653c73f205e94260Lennart Poettering [ "$INITRD" ] || { [ "$LOOKS_LIKE_DEBIAN" ] && [ -e "$default_debian_initrd" ] && INITRD=$default_debian_initrd; }
875c6e1b48f37a07dfbb80d6653c73f205e94260Lennart Poetteringraid=noautodetect \
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poetteringconsole=ttyS0 \
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering QEMU_OPTIONS="$QEMU_OPTIONS -initrd $INITRD"
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering if [ -c /dev/kvm ]; then
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering QEMU_OPTIONS="$QEMU_OPTIONS -machine accel=kvm -enable-kvm -cpu host"
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND" $TESTDIR/rootdisk.img ) || return 1
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering ../../systemd-nspawn --register=no --directory=$TESTDIR/nspawn-root $ROOTLIBDIR/systemd $KERNEL_APPEND
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering if ! type -p valgrind; then
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering local _valgrind_bins=$(strace -e execve valgrind /bin/true 2>&1 >/dev/null | perl -lne 'print $1 if /^execve\("([^"]+)"/')
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering local _valgrind_libs=$(LD_DEBUG=files valgrind /bin/true 2>&1 >/dev/null | perl -lne 'print $1 if m{calling init: (/.*vgpreload_.*)}')
perl -lne 'if (my ($fname) = /^open\("([^"]+).*= (?!-)\d+/) { print $fname if $fname =~ /debug|\.supp$/ }'
cat >$_valgrind_wrapper <<EOF
chmod 0755 $_valgrind_wrapper
type -P dmeventd >/dev/null && dracut_install dmeventd
inst_libs $i
ret=1
[[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
[[ -f $TESTDIR/nspawn-root/failed ]] && cp -a $TESTDIR/nspawn-root/failed $TESTDIR
return $ret
find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | xargs strip --strip-unneeded | ddebug
export PKG_CONFIG_PATH=$TEST_BASE_DIR/../src/core/
inst $i
if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
cp -a /etc/ld.so.conf* $initdir/etc
[[ $BASICTOOLS ]] && dracut_install $BASICTOOLS
[[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
NSS_LIBS=$(LD_DEBUG=files getent passwd 2>&1 >/dev/null |sed -n '/calling init: .*libnss_/ {s!^.* /!/!; p}')
find \
| while read file; do
[[ "$LOOKS_LIKE_DEBIAN" ]] && type -p dpkg-architecture &>/dev/null && find "/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/security" -xtype f
find \
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;;