From: Song Liu <song@kernel.org>
To: live-patching@vger.kernel.org, linux-kselftest@vger.kernel.org
Cc: jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz,
pmladek@suse.com, joe.lawrence@redhat.com, shuah@kernel.org,
linux-kernel@vger.kernel.org, Song Liu <song@kernel.org>
Subject: [PATCH 11/11] selftests/livepatch: Test klp-build with patches which need offset or fuzz
Date: Fri, 16 Oct 2026 17:24:41 -0700 [thread overview]
Message-ID: <20261017002441.716615-12-song@kernel.org> (raw)
In-Reply-To: <20261017002441.716615-1-song@kernel.org>
klp-build accepts patches which apply with an offset or fuzz, and warns
about them. Add a test that both are accepted with a warning, and that
the fixed patch has the line numbers and context of the real source, so
the #line directives refer to the right lines.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Song Liu <song@kernel.org>
---
.../livepatch/test_klp_build/Makefile | 3 +-
.../test_klp_build/test-offset-and-fuzz.sh | 120 ++++++++++++++++++
2 files changed, 122 insertions(+), 1 deletion(-)
create mode 100755 tools/testing/selftests/livepatch/test_klp_build/test-offset-and-fuzz.sh
diff --git a/tools/testing/selftests/livepatch/test_klp_build/Makefile b/tools/testing/selftests/livepatch/test_klp_build/Makefile
index 2513105b3e1c..a62ae5340fa4 100644
--- a/tools/testing/selftests/livepatch/test_klp_build/Makefile
+++ b/tools/testing/selftests/livepatch/test_klp_build/Makefile
@@ -8,7 +8,8 @@ TEST_PROGS := \
test-new-and-deleted-files.sh \
test-line-directives.sh \
test-unsupported-files.sh \
- test-patch-not-applying.sh
+ test-patch-not-applying.sh \
+ test-offset-and-fuzz.sh
TEST_PROGS_EXTENDED := functions.sh
diff --git a/tools/testing/selftests/livepatch/test_klp_build/test-offset-and-fuzz.sh b/tools/testing/selftests/livepatch/test_klp_build/test-offset-and-fuzz.sh
new file mode 100755
index 000000000000..413b39b83431
--- /dev/null
+++ b/tools/testing/selftests/livepatch/test_klp_build/test-offset-and-fuzz.sh
@@ -0,0 +1,120 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+. "$(dirname "$0")/functions.sh"
+
+# expect_warning(msg) - check that klp-build warned, and drop the warning so
+# expect_patch() doesn't complain about it
+# msg - the warning, without the "warning: klp-build: " prefix
+function expect_warning() {
+ local line="warning: klp-build: $1"
+
+ grep -qxF "$line" "$WORK_DIR/stderr" ||
+ not_ok "klp-build didn't warn \"$1\":" "$WORK_DIR/stderr"
+
+ grep -vxF "$line" "$WORK_DIR/stderr" > "$WORK_DIR/stderr.rest"
+ mv "$WORK_DIR/stderr.rest" "$WORK_DIR/stderr"
+}
+
+setup_tree
+
+add_file drivers/foo/foo.c <<'EOT'
+int foo(int x)
+{
+ if (x < 0)
+ return -1;
+ return x;
+}
+
+int bar(void)
+{
+ return __LINE__;
+}
+
+int baz(int x)
+{
+ if (x > 100)
+ return 100;
+ return x;
+}
+EOT
+
+# - a patch made against a source with fewer lines applies at an offset, and
+# the fixed patch has the real line numbers
+
+start_test "patch with an offset"
+
+add_patch 0001-offset.patch <<'EOT'
+--- a/drivers/foo/foo.c
++++ b/drivers/foo/foo.c
+@@ -9,7 +9,7 @@
+
+ int baz(int x)
+ {
+- if (x > 100)
+- return 100;
++ if (x > 1000)
++ return 1000;
+ return x;
+ }
+EOT
+
+run_klp_build 0001-offset.patch
+
+expect_warning "$PATCH_DIR/0001-offset.patch applied with fuzz"
+expect_patch <<'EOT'
+--- a/drivers/foo/foo.c
++++ b/drivers/foo/foo.c
+@@ -12,7 +12,8 @@ int bar(void)
+
+ int baz(int x)
+ {
+- if (x > 100)
+- return 100;
++ if (x > 1000)
++ return 1000;
++#line 17
+ return x;
+ }
+EOT
+
+# - a patch whose context differs from the source applies with fuzz, and the
+# fixed patch has the real context
+
+start_test "patch with fuzz"
+
+add_patch 0001-fuzz.patch <<'EOT'
+--- a/drivers/foo/foo.c
++++ b/drivers/foo/foo.c
+@@ -12,7 +12,7 @@
+ /* clamp x */
+ int baz(int x)
+ {
+- if (x > 100)
+- return 100;
++ if (x > 1000)
++ return 1000;
+ return x;
+ }
+EOT
+
+run_klp_build 0001-fuzz.patch
+
+expect_warning "$PATCH_DIR/0001-fuzz.patch applied with fuzz"
+expect_patch <<'EOT'
+--- a/drivers/foo/foo.c
++++ b/drivers/foo/foo.c
+@@ -12,7 +12,8 @@ int bar(void)
+
+ int baz(int x)
+ {
+- if (x > 100)
+- return 100;
++ if (x > 1000)
++ return 1000;
++#line 17
+ return x;
+ }
+EOT
+
+exit 0
--
2.53.0-Meta
prev parent reply other threads:[~2026-10-17 0:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 0:24 [PATCH 00/11] klp-build: Fix dependent patches, add selftests Song Liu
2026-10-17 0:24 ` [PATCH 01/11] klp-build: Fix dependent patches in a series Song Liu
2026-10-17 0:24 ` [PATCH 02/11] klp-build: Add --patch-only option Song Liu
2026-10-17 0:24 ` [PATCH 03/11] selftests/livepatch: Add tests for klp-build's patch handling Song Liu
2026-10-17 0:24 ` [PATCH 04/11] selftests/livepatch: Test klp-build with dependent patches Song Liu
2026-10-17 0:30 ` sashiko-bot
2026-10-17 0:24 ` [PATCH 05/11] selftests/livepatch: Test klp-build with patches to different functions Song Liu
2026-10-17 0:24 ` [PATCH 06/11] selftests/livepatch: Test klp-build with patches which cancel out Song Liu
2026-10-17 0:24 ` [PATCH 07/11] selftests/livepatch: Test klp-build with created and deleted files Song Liu
2026-10-17 0:24 ` [PATCH 08/11] selftests/livepatch: Test where klp-build adds #line directives Song Liu
2026-10-17 0:24 ` [PATCH 09/11] selftests/livepatch: Test klp-build's rejection of unsupported files Song Liu
2026-10-17 0:24 ` [PATCH 10/11] selftests/livepatch: Test klp-build with patches which don't apply Song Liu
2026-10-17 0:24 ` Song Liu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261017002441.716615-12-song@kernel.org \
--to=song@kernel.org \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.