From: Petr Mladek <pmladek@suse.com>
To: Song Liu <song@kernel.org>
Cc: live-patching@vger.kernel.org, jpoimboe@kernel.org,
jikos@kernel.org, mbenes@suse.cz, joe.lawrence@redhat.com,
kernel-team@fb.com
Subject: Re: [PATCH v2 2/2] selftests/livepatch: add sysfs test
Date: Fri, 2 Sep 2022 14:37:19 +0200 [thread overview]
Message-ID: <20220902123719.GB25533@pathway.suse.cz> (raw)
In-Reply-To: <20220802010857.3574103-3-song@kernel.org>
On Mon 2022-08-01 18:08:57, Song Liu wrote:
> Add a test for livepatch sysfs entries.
>
> Signed-off-by: Song Liu <song@kernel.org>
> ---
> tools/testing/selftests/livepatch/Makefile | 3 +-
> .../testing/selftests/livepatch/test-sysfs.sh | 40 +++++++++++++++++++
> 2 files changed, 42 insertions(+), 1 deletion(-)
> create mode 100755 tools/testing/selftests/livepatch/test-sysfs.sh
>
> diff --git a/tools/testing/selftests/livepatch/Makefile b/tools/testing/selftests/livepatch/Makefile
> index 1acc9e1fa3fb..02fadc9d55e0 100644
> --- a/tools/testing/selftests/livepatch/Makefile
> +++ b/tools/testing/selftests/livepatch/Makefile
> @@ -6,7 +6,8 @@ TEST_PROGS := \
> test-callbacks.sh \
> test-shadow-vars.sh \
> test-state.sh \
> - test-ftrace.sh
> + test-ftrace.sh \
> + test-sysfs.sh
>
> TEST_FILES := settings
>
> diff --git a/tools/testing/selftests/livepatch/test-sysfs.sh b/tools/testing/selftests/livepatch/test-sysfs.sh
> new file mode 100755
> index 000000000000..eb4a69ba1c2c
> --- /dev/null
> +++ b/tools/testing/selftests/livepatch/test-sysfs.sh
> @@ -0,0 +1,40 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2022 Song Liu <song@kernel.org>
> +
> +. $(dirname $0)/functions.sh
> +
> +MOD_LIVEPATCH=test_klp_livepatch
> +
> +setup_config
> +
> +# - load a livepatch and verifies the sysfs entries work as expected
> +
> +start_test "sysfs test"
> +
> +load_lp $MOD_LIVEPATCH
> +
> +grep . "/sys/kernel/livepatch/$MOD_LIVEPATCH"/* > /dev/kmsg
> +grep . "/sys/kernel/livepatch/$MOD_LIVEPATCH"/*/* > /dev/kmsg
> +
I see the following when I run the test:
host:kernel/linux/tools/testing/selftests/livepatch # ./test-sysfs.sh
TEST: sysfs test ... grep: /sys/kernel/livepatch/test_klp_livepatch/force: Permission denied
grep: /sys/kernel/livepatch/test_klp_livepatch/vmlinux: Is a directory
grep: /sys/kernel/livepatch/test_klp_livepatch/vmlinux/cmdline_proc_show,1: Is a directory
ok
The errors are expected. A solution would be to redirect 2>&1 or
2>/dev/null. Both looks a bit ugly to me.
Instead, I would suggest to create some helper scripts in functions.sh,
for example:
# check_sysfs_exists(modname, rel_path, expected_rights) - check sysfs interface
# modname - livepatch module creating the sysfs interface
# rel_patch - relative patch of the sysfs interface
# expected_rights - expected access rights
function check_sysfs_rights() {
local mod="$1"; shift
local rel_path="$1"; shift
local expected_rights="$1"; shift
local path="$KLP_SYSFS_DIR/$mod/$rel_path"
local rights=`ls -l -d $path | cut -d " " -f 1`
if test "$rights" != "$expected_rights" ; then
die "Unexpected access rights of $path: $expected_rights vs. $rights"
fi
}
# check_sysfs_exists(modname, rel_path, expected_value) - check sysfs interface
# modname - livepatch module creating the sysfs interface
# rel_patch - relative patch of the sysfs interface
# expected_value - expected value read from the file
function check_sysfs_value() {
local mod="$1"; shift
local rel_path="$1"; shift
local expected_value="$1"; shift
local path="$KLP_SYSFS_DIR/$mod/$rel_path"
local value=`cat $path`
if test "$value" != "$expected_value" ; then
die "Unexpected value in $path: $expected_value vs. $value"
fi
}
It would allow to create a fine tuned tests, for example:
check_sysfs_rights "$MOD_LIVEPATCH" "" "drwxr-xr-x"
check_sysfs_rights "$MOD_LIVEPATCH" "enabled" "-rw-r--r--"
check_sysfs_value "$MOD_LIVEPATCH" "enabled" "1"
Also it would be great to test that the "patched" value is "0"
when the object is not patched. I would require to create
a test module that might be livepatched. I mean something like:
check_sysfs_value $MOD_LIVEPATCH "$TEST_MODULE/patched" "0"
load_mod $TEST_MODULE
check_sysfs_value $MOD_LIVEPATCH "$TEST_MODULE/patched" "1"
unload_mod $TEST_MODULE
check_sysfs_value $MOD_LIVEPATCH "$TEST_MODULE/patched" "0"
Best Regards,
Petr
next prev parent reply other threads:[~2022-09-02 14:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-02 1:08 [PATCH v2 0/2] add sysfs entry "patched" for each klp_object Song Liu
2022-08-02 1:08 ` [PATCH v2 1/2] livepatch: " Song Liu
2022-09-02 11:49 ` Petr Mladek
2022-08-02 1:08 ` [PATCH v2 2/2] selftests/livepatch: add sysfs test Song Liu
2022-08-02 21:36 ` Joe Lawrence
2022-09-02 12:37 ` Petr Mladek [this message]
2022-09-02 15:42 ` Joe Lawrence
2022-08-02 21:37 ` [PATCH v2 0/2] add sysfs entry "patched" for each klp_object Joe Lawrence
2022-08-30 19:09 ` 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=20220902123719.GB25533@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=kernel-team@fb.com \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=song@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.