Skip to content

Commit 78f2c06

Browse files
author
Evgenii Shatokhin
committed
kpatch-test: make it easier to use custom kpatch and kpatch-build commands
The commands used to build the livepatches and to load or unload them are currently hard-coded in kpatch-test. This patch adds 2 options to kpatch-test to make it easier to use custom kpatch and kpatch-build commands: * --system-kpatch-tools - if set, 'sudo kpatch' will be used to load/unload the patches; 'kpatch-build' - to build them. To use custom tools here, the user can adjust $PATH. If the option is not set, kpatch-test will assume it is in kpatch source tree, same as before this commit, and will use the tools from there. * --kpatch-build-opts="..." - additional options to pass to kpatch-build. Example: ./kpatch-test \ --system-kpatch-tools \ --kpatch-build-opts="-s ./linux-src -c ./config -v ./vmlinux" \ -d my_kpatch_tests/test/integration/v01 In this case, kpatch and kpatch-build installed in the system will be used, and kpatch-build will look for the kernel source tree, configuration file and vmlinux binary in the current directory. Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
1 parent 01b8d34 commit 78f2c06

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

test/integration/kpatch-test

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ shopt -s nullglob
4343
# shellcheck disable=SC2046
4444
SCRIPTDIR=$(readlink -f $(dirname $(type -p "$0")))
4545
ROOTDIR=$(readlink -f "$SCRIPTDIR/../..")
46-
# TODO: option to use system-installed binaries instead
4746
KPATCH="sudo $ROOTDIR/kpatch/kpatch"
4847
unset CCACHE_HASHDIR
4948
KPATCHBUILD="$ROOTDIR"/kpatch-build/kpatch-build
@@ -64,9 +63,11 @@ usage() {
6463
echo " -c, --cached Don't rebuild patch modules" >&2
6564
echo " -d, --directory Patch directory" >&2
6665
echo " -q, --quick Test combined patch and -FAIL patches only" >&2
66+
echo " --system-kpatch-tools Use kpatch tools installed in the system" >&2
67+
echo " --kpatch-build-opts Additional options to pass to kpatch-build" >&2
6768
}
6869

69-
options=$(getopt -o hcd:q -l "help,cached,directory,quick" -- "$@") || exit 1
70+
options=$(getopt -o hcd:q -l "help,cached,directory,quick,system-kpatch-tools,kpatch-build-opts:" -- "$@") || exit 1
7071

7172
eval set -- "$options"
7273

@@ -86,6 +87,14 @@ while [[ $# -gt 0 ]]; do
8687
-q|--quick)
8788
QUICK=1
8889
;;
90+
--system-kpatch-tools)
91+
KPATCH="sudo kpatch"
92+
KPATCHBUILD="kpatch-build"
93+
;;
94+
--kpatch-build-opts)
95+
KPATCHBUILD_OPTS=$2
96+
shift
97+
;;
8998
*)
9099
[[ "$1" = "--" ]] && shift && continue
91100
PATCH_LIST+=("$1")
@@ -143,7 +152,10 @@ build_module() {
143152

144153
log "build: $prefix"
145154

146-
if ! $KPATCHBUILD -n "$modname" "$file" >> $LOG 2>&1; then
155+
# shellcheck disable=SC2086
156+
# KPATCHBUILD_OPTS may contain several space-separated options,
157+
# it should remain without quotes.
158+
if ! $KPATCHBUILD $KPATCHBUILD_OPTS -n "$modname" "$file" >> $LOG 2>&1; then
147159
if [[ $shouldfail -eq 0 ]]; then
148160
error "$prefix: build failed"
149161
cp "$HOME/.kpatch/build.log" "$prefix.log"
@@ -231,7 +243,8 @@ build_combined_module() {
231243

232244
log "build: combined module"
233245

234-
if ! $KPATCHBUILD -n test-COMBINED "${COMBINED_LIST[@]}" >> $LOG 2>&1; then
246+
# shellcheck disable=SC2086
247+
if ! $KPATCHBUILD $KPATCHBUILD_OPTS -n test-COMBINED "${COMBINED_LIST[@]}" >> $LOG 2>&1; then
235248
error "combined build failed"
236249
cp "$HOME/.kpatch/build.log" combined.log
237250
fi

0 commit comments

Comments
 (0)