test-functions revision 1c36b4a73b876258fbe01fbe9bc9b750b7dcc9ce
af313f59287bea73d6e453a1bdb397c3f68c3160Jonathan von Schroeder# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
af313f59287bea73d6e453a1bdb397c3f68c3160Jonathan von Schroeder# ex: ts=8 sw=4 sts=4 et filetype=sh
a84a8d508a0778b13a4d097a6dd34b95feae78acJens ElknerLOOKS_LIKE_DEBIAN=$(source /etc/os-release && [[ "$ID" = "debian" || "$ID_LIKE" = "debian" ]] && echo yes)
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elknerif ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2
a84a8d508a0778b13a4d097a6dd34b95feae78acJens ElknerBASICTOOLS="sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee"
a84a8d508a0778b13a4d097a6dd34b95feae78acJens ElknerDEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname"
73677326fdbc1d154208000f6f37d7524d8f90cfJens Elkner [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a kvm qemu-kvm 2>/dev/null | grep '^/' -m1)
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner # QEMU's own build system calls it qemu-system-x86_64
730ccc63c301363853cba9286760d511b456671eChristian Maeder [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-x86_64 2>/dev/null | grep '^/' -m1)
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-i386 2>/dev/null | grep '^/' -m1)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu 2>/dev/null | grep '^/' -m1)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder echo "Could not find a suitable QEMU binary" >&2
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder if [ -f /etc/machine-id ]; then
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder [ -z "$INITRD" ] && [ -e "/boot/$MACHINE_ID/$KERNEL_VER/initrd" ] \
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder && INITRD="/boot/$MACHINE_ID/$KERNEL_VER/initrd"
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder [ -z "$KERNEL_BIN" ] && [ -e "/boot/$MACHINE_ID/$KERNEL_VER/linux" ] \
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder && KERNEL_BIN="/boot/$MACHINE_ID/$KERNEL_VER/linux"
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder [ "$KERNEL_BIN" ] || KERNEL_BIN=/boot/vmlinuz-$KERNEL_VER
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder [ "$INITRD" ] || INITRD=/boot/initramfs-${KERNEL_VER}.img
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroederraid=noautodetect \
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder QEMU_OPTIONS="-machine accel=kvm:tcg \
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder QEMU_OPTIONS="$QEMU_OPTIONS -initrd $INITRD"
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND" $TESTDIR/rootdisk.img ) || return 1
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder ../../systemd-nspawn --boot --directory=$TESTDIR/nspawn-root $ROOTLIBDIR/systemd $KERNEL_APPEND
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder ln -fs /proc/self/mounts $initdir/etc/mtab
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder type -P dmeventd >/dev/null && dracut_install dmeventd
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder inst_libdir_file "libdevmapper-event.so*"
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder (cd $TEST_BASE_DIR/..; set -x; make DESTDIR=$initdir install)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder # we strip binaries since debug symbols increase binaries size a lot
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder # and it could fill the available space
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder # Create the blank file to use as a root filesystem
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder dd if=/dev/null of="$TESTDIR/rootdisk.img" bs=1M seek=300
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder [[ -f $TESTDIR/nspawn-root/failed ]] && cp -a $TESTDIR/nspawn-root/failed $TESTDIR
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder test -s $TESTDIR/failed && ret=$(($ret+1))
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | xargs strip --strip-unneeded | ddebug
6aad75f5233b1f80eb84f53395f7bb44e9ed7b88Jonathan von Schroeder cat >$initdir/etc/rc.d/rc.local <<EOF
8d632882ae6a59db929b7f87816da6c4d795594eJonathan von Schroeder chmod 0755 $initdir/etc/rc.d/rc.local
73677326fdbc1d154208000f6f37d7524d8f90cfJens Elkner ddebug "install any Execs from the service files"
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;;