Linux Test Project
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 2/2] shell lib: Add support for test cleanup
Date: Fri, 14 Feb 2025 14:55:31 +0100	[thread overview]
Message-ID: <20250214135531.GB2221874@pevik> (raw)
In-Reply-To: <20250214112135.18947-3-chrubis@suse.cz>

Hi Cyril,


> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  testcases/lib/run_tests.sh                    |  4 +++-
>  .../lib/tests/shell_loader_brk_cleanup.sh     | 20 ++++++++++++++++++
>  testcases/lib/tests/shell_loader_cleanup.sh   | 21 +++++++++++++++++++
>  testcases/lib/tst_env.sh                      |  4 ++++
>  4 files changed, 48 insertions(+), 1 deletion(-)
>  create mode 100755 testcases/lib/tests/shell_loader_brk_cleanup.sh
>  create mode 100755 testcases/lib/tests/shell_loader_cleanup.sh

> diff --git a/testcases/lib/run_tests.sh b/testcases/lib/run_tests.sh
> index 168dbb451..d568d4614 100755
> --- a/testcases/lib/run_tests.sh
> +++ b/testcases/lib/run_tests.sh
> @@ -9,6 +9,7 @@ shell_loader_filesystems.sh
>  shell_loader_kconfigs.sh
>  shell_loader_supported_archs.sh
>  shell_loader_tcnt.sh
> +shell_loader_cleanup.sh
>  shell_test01
>  shell_test02
>  shell_test03
> @@ -21,7 +22,8 @@ TESTS_TBROK="
>  shell_loader_invalid_block.sh
>  shell_loader_invalid_metadata.sh
>  shell_loader_no_metadata.sh
> -shell_loader_wrong_metadata.sh"
> +shell_loader_wrong_metadata.sh
> +shell_loader_brk_cleanup.sh"

>  TESTS_TCONF="shell_test06"

> diff --git a/testcases/lib/tests/shell_loader_brk_cleanup.sh b/testcases/lib/tests/shell_loader_brk_cleanup.sh
> new file mode 100755
> index 000000000..8c704a540
> --- /dev/null
> +++ b/testcases/lib/tests/shell_loader_brk_cleanup.sh
> @@ -0,0 +1,20 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2024-2025 Cyril Hrubis <chrubis@suse.cz>
> +#
> +# ---
> +# env
> +# {
> +# }
> +# ---
> +
> +TST_CLEANUP=cleanup
> +
> +. tst_loader.sh
> +
> +cleanup()
> +{
> +	tst_res TINFO "Cleanup runs"
> +}
> +
> +tst_brk TBROK "Test exits"
> diff --git a/testcases/lib/tests/shell_loader_cleanup.sh b/testcases/lib/tests/shell_loader_cleanup.sh
> new file mode 100755
> index 000000000..b183f1d28
> --- /dev/null
> +++ b/testcases/lib/tests/shell_loader_cleanup.sh
> @@ -0,0 +1,21 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2024-2025 Cyril Hrubis <chrubis@suse.cz>
> +#
> +# ---
> +# env
> +# {
> +# }
> +# ---
> +
> +TST_CLEANUP=do_cleanup
> +
> +. tst_loader.sh
> +
> +do_cleanup()
> +{
> +	tst_res TINFO "Cleanup executed"
> +}
> +
> +tst_res TPASS "Test is executed"
> +
> diff --git a/testcases/lib/tst_env.sh b/testcases/lib/tst_env.sh
> index 68f9a0daa..b13bab37c 100644
> --- a/testcases/lib/tst_env.sh
> +++ b/testcases/lib/tst_env.sh
> @@ -35,3 +35,7 @@ tst_brk_()

>  alias tst_res="tst_res_ $tst_script_name \$LINENO"
>  alias tst_brk="tst_brk_ $tst_script_name \$LINENO"
> +
> +if [ -n "$TST_CLEANUP" ]; then
> +	trap $TST_CLEANUP EXIT
> +fi

thanks!

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Unfortunately TST_SETUP will not work that way - function is not found or if you
load tst_env.sh at the end, it complains about missing tst_res or tst_brk:

./tests/./shell_loader_brk_cleanup.sh: line 16: tst_res: command not found

Obviously it does not help to add it to tst_loader.sh.

I'm surprised it checks that, is there shopt option which could disable it?

Kind regards,
Petr


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2025-02-14 13:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-14 11:21 [LTP] [PATCH 0/2] shell lib: Add very simple cleanup support Cyril Hrubis
2025-02-14 11:21 ` [LTP] [PATCH 1/2] testcases/lib/run_tests.sh Cyril Hrubis
2025-02-14 13:37   ` Petr Vorel
2025-02-28 11:49     ` Petr Vorel
2025-02-14 11:21 ` [LTP] [PATCH 2/2] shell lib: Add support for test cleanup Cyril Hrubis
2025-02-14 13:55   ` Petr Vorel [this message]
2025-02-14 14:07     ` Cyril Hrubis
2025-02-14 14:18       ` Cyril Hrubis
2025-02-17  7:44   ` Petr Vorel
2025-02-25 10:25     ` Cyril Hrubis
2025-02-25 11:00       ` Petr Vorel

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=20250214135531.GB2221874@pevik \
    --to=pvorel@suse.cz \
    --cc=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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