Live Patching
 help / color / mirror / Atom feed
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 07/11] selftests/livepatch: Test klp-build with created and deleted files
Date: Fri, 16 Oct 2026 17:24:37 -0700	[thread overview]
Message-ID: <20261017002441.716615-8-song@kernel.org> (raw)
In-Reply-To: <20261017002441.716615-1-song@kernel.org>

Add a test of patches which create and delete files.  Both are diffed
against /dev/null, and the created file gets no #line directive, as it
has no original line numbers to preserve.  A file created by one patch
and changed by the next is a new file in the combined patch.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Song Liu <song@kernel.org>
---
 .../livepatch/test_klp_build/Makefile         |  3 +-
 .../test-new-and-deleted-files.sh             | 94 +++++++++++++++++++
 2 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/livepatch/test_klp_build/test-new-and-deleted-files.sh

diff --git a/tools/testing/selftests/livepatch/test_klp_build/Makefile b/tools/testing/selftests/livepatch/test_klp_build/Makefile
index b3191b5c1925..96144f99b1aa 100644
--- a/tools/testing/selftests/livepatch/test_klp_build/Makefile
+++ b/tools/testing/selftests/livepatch/test_klp_build/Makefile
@@ -4,7 +4,8 @@ TEST_PROGS := \
 	test-basic.sh \
 	test-dependent-patches.sh \
 	test-independent-patches.sh \
-	test-cancelling-patches.sh
+	test-cancelling-patches.sh \
+	test-new-and-deleted-files.sh
 
 TEST_PROGS_EXTENDED := functions.sh
 
diff --git a/tools/testing/selftests/livepatch/test_klp_build/test-new-and-deleted-files.sh b/tools/testing/selftests/livepatch/test_klp_build/test-new-and-deleted-files.sh
new file mode 100755
index 000000000000..2acec2df98ff
--- /dev/null
+++ b/tools/testing/selftests/livepatch/test_klp_build/test-new-and-deleted-files.sh
@@ -0,0 +1,94 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+. "$(dirname "$0")/functions.sh"
+
+setup_tree
+
+add_file drivers/foo/old.c <<'EOT'
+int old(void)
+{
+	return 0;
+}
+EOT
+
+# - created and deleted files are diffed against /dev/null, and a created
+#   file gets no #line directive since it has no original line numbers
+
+start_test "created and deleted files"
+
+add_patch 0001-new-and-old.patch <<'EOT'
+--- /dev/null
++++ b/drivers/foo/new.c
+@@ -0,0 +1,4 @@
++int new(void)
++{
++	return 1;
++}
+--- a/drivers/foo/old.c
++++ /dev/null
+@@ -1,4 +0,0 @@
+-int old(void)
+-{
+-	return 0;
+-}
+EOT
+
+run_klp_build 0001-new-and-old.patch
+
+expect_patch <<'EOT'
+--- /dev/null
++++ b/drivers/foo/new.c
+@@ -0,0 +1,4 @@
++int new(void)
++{
++	return 1;
++}
+--- a/drivers/foo/old.c
++++ /dev/null
+@@ -1,4 +0,0 @@
+-int old(void)
+-{
+-	return 0;
+-}
+EOT
+
+# - a file created by one patch and changed by the next is a new file in the
+#   combined patch
+
+start_test "created file changed by a later patch"
+
+add_patch 0001-new.patch <<'EOT'
+--- /dev/null
++++ b/drivers/foo/new.c
+@@ -0,0 +1,4 @@
++int new(void)
++{
++	return 1;
++}
+EOT
+
+add_patch 0002-new-again.patch <<'EOT'
+--- a/drivers/foo/new.c
++++ b/drivers/foo/new.c
+@@ -1,4 +1,4 @@
+ int new(void)
+ {
+-	return 1;
++	return 2;
+ }
+EOT
+
+run_klp_build 0001-new.patch 0002-new-again.patch
+
+expect_patch <<'EOT'
+--- /dev/null
++++ b/drivers/foo/new.c
+@@ -0,0 +1,4 @@
++int new(void)
++{
++	return 2;
++}
+EOT
+
+exit 0
-- 
2.53.0-Meta


  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 ` Song Liu [this message]
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 ` [PATCH 11/11] selftests/livepatch: Test klp-build with patches which need offset or fuzz Song Liu

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-8-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox