test-functions revision cb2f9d3f296bc80b55f09880d61dfdf47fc98212
341N/A# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 341N/A# ex: ts=8 sw=4 sts=4 et filetype=sh 919N/A echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&
2 919N/ABASICTOOLS=
"sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee" 919N/ADEBUGTOOLS=
"df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname" 919N/A # SUSE and Red Hat call the binary qemu-kvm 919N/A # Debian and Gentoo call it kvm 341N/A # QEMU's own build system calls it qemu-system-x86_64 341N/A # new i386 version of QEMU 341N/A echo "Could not find a suitable QEMU binary" >&2 341N/A # create the basic filesystem layout 341N/A perl -lne 'if (my ($fname) = /^open\("([^"]+).*= (?!-)\d+/) { print $fname if $fname =~ /debug|\.supp$/ }' 341N/Aexec valgrind --leak-check=full --log-file=/valgrind.out $ROOTLIBDIR/systemd "\$@" 341N/A # install compiled files 341N/A # remove unneeded documentation 341N/A # we strip binaries since debug symbols increase binaries size a lot 341N/A # and it could fill the available space 341N/A # install possible missing libraries 341N/A # Create the blank file to use as a root filesystem 341N/A i=${i##Exec*=}; i=${i##-} 341N/A # install plymouth, if found... else remove plymouth service files 341N/A # dracut_install plymouth plymouthd 341N/A # we want an empty environment 341N/ALABEL=systemd / ext3 rw 0 1 341N/A # install libnss_files for login 341N/A [[ -f $i ]] || continue 341N/A [[ -f $i ]] || continue 341N/A # make the testsuite the default target 341N/A # we don't mount in the nspawn root 341N/A## @brief Converts numeric logging level to the first letter of level name. 341N/A# @param lvl Numeric logging level in range from 1 to 6. 341N/A# @retval 1 if @a lvl is out of range. 341N/A# @retval 0 if @a lvl is correct. 341N/A# @result Echoes first letter of level name. 341N/A## @brief Internal helper function for _do_dlog() 341N/A# @param lvl Numeric logging level. 341N/A# @retval 0 It's always returned, even if logging failed. 341N/A# @note This function is not supposed to be called manually. Please use 341N/A# dtrace(), ddebug(), or others instead which wrap this one. 341N/A# This function calls _do_dlog() either with parameter msg, or if 341N/A# none is given, it will read standard input and will use every line as 341N/A# dwarn "This is a warning" 341N/A# echo "This is a warning" | dwarn 341N/A## @brief Logs message at TRACE level (6) 341N/A# @retval 0 It's always returned, even if logging failed. 341N/A## @brief Logs message at DEBUG level (5) 341N/A# @retval 0 It's always returned, even if logging failed. 341N/A# [ -n "$debug" ] && set -x || : 341N/A## @brief Logs message at INFO level (4) 341N/A# @retval 0 It's always returned, even if logging failed. 341N/A## @brief Logs message at WARN level (3) 341N/A# @retval 0 It's always returned, even if logging failed. 341N/A## @brief Logs message at ERROR level (2) 341N/A# @retval 0 It's always returned, even if logging failed. 341N/A# [ -n "$debug" ] && set -x || : 341N/A## @brief Logs message at FATAL level (1) 341N/A# @retval 0 It's always returned, even if logging failed. 341N/A# Generic substring function. If $2 is in $1, return 0. 341N/A# Prints the normalized path, where it removes any duplicated 341N/A# convert_abs_rel <from> <to> 341N/A# Prints the relative path, when creating a symlink to <to> from <from>. 341N/A # corner case #1 - self looping link 341N/A [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; } 341N/A # corner case #2 - own dir link 341N/A [[ "${1%/*}" == "$2" ]] && { echo "."; return; } 341N/A# Install a directory, keeping symlinks as on the original system. 341N/A# Example: if /lib points to /lib64 on the host, "inst_dir /lib/file" 341N/A# and a symlink ${initdir}/lib -> lib64. 341N/A while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do 341N/A # iterate over parent directories 341N/A# $1 = file to copy to ramdisk 341N/A# $2 (optional) Name for the file on the ramdisk 341N/A# Location of the image dir is assumed to be $initdir 341N/A# We never overwrite the target if it exists. 341N/A [[ -f "$1" ]] || return 1 341N/A # install checksum files also 341N/A if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then 341N/A inst "${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac" 341N/A# find symlinks linked to given library file 341N/A# Function searches for symlinks by stripping version numbers appended to 341N/A# library filename, checks if it points to the same target and finally 341N/A# prints the list of symlinks to stdout. 341N/A# Same as above, but specialized to handle dynamic libraries. 341N/A# It handles making symlinks according to how the original library 341N/A # install checksum files also 341N/A if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then 341N/A inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac" 341N/A # Create additional symlinks. See rev_symlinks description. 341N/A# find a binary. If we were not passed the full path directly, 341N/A# search in the usual places to find the binary. 341N/A if [[ -z ${1##/*} ]]; then 341N/A# Same as above, but specialized to install binary executables. 341N/A# Install binary executable, and all shared library dependencies, if any. 341N/A# same as above, except for shell scripts. 341N/A# If your shell script does not start with shebang, it is not a shell script. 341N/A # If debug is set, clean unprintable chars to prevent messing up the term 341N/A# same as above, but specialized for symlinks 341N/A [[ -L $1 ]] || return 1 341N/A# attempt to install any programs specified in a udev rule 341N/A for _prog in $(grep -E 'PROGRAM==?"[^ "]+' "$1" | sed -r 's/.*PROGRAM==?"([^ "]+).*/\1/'); do 341N/A #dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)" 341N/A# udev rules always get installed in the same place, so 341N/A# create a function to install them to make life simpler. 341N/A# general purpose installation function 341N/A# install any of listed files 341N/A# If first argument is '-d' and second some destination path, first accessible 341N/A# source is installed into this path, otherwise it will installed in the same 341N/A# path as source. If none of listed files was installed, function return 1. 341N/A# On first successful installation it returns with 0 status. 341N/A [[ $1 = '-d' ]] && to="$2" && shift 2 341N/A# dracut_install [-o ] <file> [<file> ... ] 341N/A# Install <file> to the initramfs image 341N/A# -o optionally install the <file> and don't fail, if it is not there 341N/A if [[ $1 = '-o' ]]; then 341N/A dinfo "Skipping program $1 as it cannot be found and is" \ 341N/A "flagged to be optional" 341N/A# Install a single kernel module along with any firmware it may require. 341N/A# $1 = full path to kernel module to install 341N/A # no need to go further if the module is already installed 341N/A dinfo "Possible missing firmware \"${_fw}\" for kernel module" \ 341N/A dwarn "Possible missing firmware \"${_fw}\" for kernel module" \ 341N/A# Do something with all the dependencies of a kernel module. 341N/A# Note that kernel modules depend on themselves using the technique we use 341N/A# $1 = function to call for each dependency we find 341N/A# It will be passed the full path to the found kernel module 341N/A# $2 = module to get dependencies for 341N/A# rest of args = arguments to modprobe 341N/A# _fderr specifies FD passed from surrounding scope 341N/A# filter kernel modules to install certain modules that meet specific 341N/A# $1 = search only in subdirectory of /kernel/$1 341N/A# $2 = function to call with module name to filter. 341N/A# This function will be passed the full path to the module to test. 341N/A# The behavior of this function can vary depending on whether $hostonly is set. 341N/A# If it is, we will only look at modules that are already in memory. 341N/A# If it is not, we will look at all kernel modules 341N/A# This function returns the full filenames of modules that match $1 # instmods [-c] <kernel module> [<kernel module> ... ] # instmods [-c] <kernel subsystem> # install kernel modules along with all their dependencies. # called [sub]functions inherit _fderr cat "${KERNEL_MODS}/modules.${_mod#=}" ) \ i2o_scsi) return ;; # Do not load this diagnostic-only module # if we are already installed, skip this module and go on [[ -f "$initdir/.kernelmodseen/${_mod%.ko}.ko" ]] && return # If we are building a host-specific initramfs and this # module is not already loaded, move on to the next one. # We use '-d' option in modprobe only if modules prefix path # differs from default '/'. This allows us to use Dracut with # old version of modprobe which doesn't have '-d' option. # ok, load the module, all its dependencies, and any firmware if (($# == 0)); then # filenames from stdin while (($# > 0)); do # filenames as arguments # Capture all stderr from modprobe to _fderr. We could use {var}>... # redirections, but that would make dracut require bash4 at least. eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \ # inst_libdir_file [-n <pattern>] <file> [<file>...] # Install a <file> located on a lib directory to the initramfs image # -n <pattern> install non-matching files if [[ "$1" == "-n" ]]; then if [[ $UID != "0" ]]; then