kpatch/test/integration/common/multiple.template

81 lines
1.7 KiB
Plaintext
Executable File

SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))"
ROOTDIR="$(readlink -f $SCRIPTDIR/../../..)"
KPATCH="sudo $ROOTDIR/kpatch/kpatch"
MODULE_PREFIX="test-"
MODULE_POSTFIX=".ko"
TEST_POSTFIX="-LOADED.test"
PATCH_POSTFIX=".patch"
DISABLED_POSTFIX="${PATCH_POSTFIX}.disabled"
set -o errexit
declare -a loaded_modules
cleanup_modules() {
for ((idx=${#loaded_modules[@]}-1 ; idx>=0 ; idx--)); do
mod=${loaded_modules[idx]}
$KPATCH unload $mod
done
}
die_clean() {
cleanup_modules
exit 1
}
die() {
echo "ERROR: $@" >&2
die_clean
}
ko_to_test() {
tmp=${1%${MODULE_POSTFIX}}${TEST_POSTFIX}
echo ${tmp#${MODULE_PREFIX}}
}
# make sure any modules added here are disjoint
declare -a modules
for file in "${SCRIPTDIR}"/*"${TEST_POSTFIX}"; do
name=$(basename ${file})
skip=0
for bname in "${blacklist[@]}"; do
if [ "${bname}" == "${name}" ]; then
skip=1
break
fi
done
if ! [ -e ${file/${TEST_POSTFIX}/${PATCH_POSTFIX}} ] && \
[ -e ${file/${TEST_POSTFIX}/${DISABLED_POSTFIX}} ]; then
skip=1
fi
if [ ${skip} -eq 0 ]; then
modules+=(${MODULE_PREFIX}${name%${TEST_POSTFIX}}${MODULE_POSTFIX})
fi
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded before loading any modules"
done
for mod in "${modules[@]}"; do
$KPATCH load $mod || die_clean
loaded_modules+=($mod)
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog || die "$SCRIPTDIR/$testprog failed after loading modules"
done
cleanup_modules
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded after unloading modules"
done
exit 0