Re: [PATCH v2 2/2] selftests/livepatch: add sysfs test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Aug 01, 2022 at 06:08:57PM -0700, Song Liu wrote:
> Add a test for livepatch sysfs entries.
> 
> Signed-off-by: Song Liu <song@xxxxxxxxxx>
> ---
>  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@xxxxxxxxxx>
> +
> +. $(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

Clever grep.  I like to use `head -n100 <pattern>` to dump debugging
filenames and content, but this "grep anything" is nice for one liner
files :)

> +
> +disable_lp $MOD_LIVEPATCH
> +
> +unload_lp $MOD_LIVEPATCH
> +
> +check_result "% modprobe $MOD_LIVEPATCH
> +livepatch: enabling patch '$MOD_LIVEPATCH'
> +livepatch: '$MOD_LIVEPATCH': initializing patching transition
> +livepatch: '$MOD_LIVEPATCH': starting patching transition
> +livepatch: '$MOD_LIVEPATCH': completing patching transition
> +livepatch: '$MOD_LIVEPATCH': patching complete
> +/sys/kernel/livepatch/test_klp_livepatch/enabled:1
> +/sys/kernel/livepatch/test_klp_livepatch/transition:0
> +/sys/kernel/livepatch/test_klp_livepatch/vmlinux/patched:1
> +% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
> +livepatch: '$MOD_LIVEPATCH': initializing unpatching transition
> +livepatch: '$MOD_LIVEPATCH': starting unpatching transition
> +livepatch: '$MOD_LIVEPATCH': completing unpatching transition
> +livepatch: '$MOD_LIVEPATCH': unpatching complete
> +% rmmod $MOD_LIVEPATCH"
> +
> +exit 0
> -- 
> 2.30.2
> 

The patch and test look fine.  I wonder how we'll modify these type of
tests if we can decouple the selftests from the kernel version.  In that
case we may need to individually verify files only if they exist.  The
upside to this version is that it will remind anyone who adds another
file to update the expected check_result value.

Also, I believe Red Hat QE has a few internal tests that verify sysfs
values during transitions, etc.  I'll inquire about those in case we can
follow up with even more sysfs verification.

--
Joe




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux Kernel]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux