On Fri, Mar 13, 2026 at 05:58:35PM -0300, Marcos Paulo de Souza wrote:
> Return 0 if the livepatch sysfs attribute don't exists, and 1 otherwise.
> This new function will be used in the next patches.
>
> Signed-off-by: Marcos Paulo de Souza <[email protected]>
> ---
> tools/testing/selftests/livepatch/functions.sh | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/tools/testing/selftests/livepatch/functions.sh
> b/tools/testing/selftests/livepatch/functions.sh
> index 8ec0cb64ad94a..781346d6e94e0 100644
> --- a/tools/testing/selftests/livepatch/functions.sh
> +++ b/tools/testing/selftests/livepatch/functions.sh
> @@ -339,6 +339,20 @@ function check_result {
> fi
> }
>
> +# check_sysfs_exists(modname, attr) - check sysfs attribute existence
> +# modname - livepatch module creating the sysfs interface
> +# attr - attribute name to be checked
> +function check_sysfs_exists() {
> + local mod="$1"; shift
> + local attr="$1"; shift
> +
> + if [[ ! -f "$SYSFS_KLP_DIR/$mod/$attr" ]]; then
> + return 0
> + fi
> +
> + return 1
> +}
> +
I don't have my shell coding hat on, but a few questions:
1. I thought shell functions usually returned 1 for a failed result and
0 on success?
2. Could this be reduced to (assuming inverting the return as well):
function check_sysfs_exists() {
local mod="$1"; shift
local attr="$1"; shift
[[ -f "$SYSFS_KLP_DIR/$mod/$attr" ]]
}
3. A higher level question, but the other check_* functions will die
"reason" on failure. Would it be better to name this one with
does_sysfs_exist() to indicate that subtle difference? (Or "has" or
some other kind of prefix.)
Regards,
--
Joe