From: Cyril Hrubis <chrubis@suse.cz>
To: Petr Vorel <pvorel@suse.cz>
Cc: Sebastian Chlad <sebastian.chlad@suse.com>, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 2/6] tst_env.sh: Backport common functions from tst_test.sh
Date: Wed, 18 Mar 2026 15:26:00 +0100 [thread overview]
Message-ID: <abq1-BcXR1nfLGcU@yuki.lan> (raw)
In-Reply-To: <20260313142600.243939-3-pvorel@suse.cz>
Hi!
> * ROD()
> * ROD_SILENT()
> * EXPECT_PASS()
> * EXPECT_PASS_BRK()
> * EXPECT_FAIL()
> * EXPECT_FAIL_BRK()
> + their dependencies.
>
> ROD_SILENT will be used in du01.sh rewrite, others will be used likely
> in other tests later.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> testcases/lib/tst_env.sh | 71 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 71 insertions(+)
>
> diff --git a/testcases/lib/tst_env.sh b/testcases/lib/tst_env.sh
> index 585790a7d0..13d8a8f954 100644
> --- a/testcases/lib/tst_env.sh
> +++ b/testcases/lib/tst_env.sh
> @@ -1,6 +1,7 @@
> #!/bin/sh
> # SPDX-License-Identifier: GPL-2.0-or-later
> # Copyright (c) 2024-2025 Cyril Hrubis <chrubis@suse.cz>
> +# Copyright (c) Linux Test Project, 2026
> #
> # This is a minimal test environment for a shell scripts executed from C by
> # tst_run_shell() function. Shell tests must use the tst_loader.sh instead!
> @@ -30,3 +31,73 @@ tst_brk_()
>
> alias tst_res="tst_res_ $tst_script_name \$LINENO"
> alias tst_brk="tst_brk_ $tst_script_name \$LINENO"
> +
> +ROD_SILENT()
> +{
> + local tst_out
> +
> + tst_out=$(tst_rod "$@" 2>&1)
> + if [ $? -ne 0 ]; then
> + echo "$tst_out"
> + tst_brk TBROK "$@ failed"
> + fi
> +}
> +
> +ROD()
> +{
> + tst_rod "$@"
> + if [ $? -ne 0 ]; then
> + tst_brk TBROK "$@ failed"
> + fi
> +}
Since we are starting from a scratch I wonder if we should call this
SAFE instead so that the name is closer to the SAFE_XXX macros in C.
> +_tst_expect_pass()
> +{
> + local fnc="$1"
> + shift
> +
> + tst_rod "$@"
If I remmeber correctly the whole reason why we introduced tst_rod.c was
that passing the $@ like this causes the $@ to be evaluated twice and
produces unexpected results.
> + if [ $? -eq 0 ]; then
> + tst_res TPASS "$@ passed as expected"
> + return 0
> + else
> + $fnc TFAIL "$@ failed unexpectedly"
> + return 1
> + fi
> +}
> +
> +_tst_expect_fail()
> +{
> + local fnc="$1"
> + shift
> +
> + # redirect stderr since we expect the command to fail
> + tst_rod "$@" 2> /dev/null
> + if [ $? -ne 0 ]; then
> + tst_res TPASS "$@ failed as expected"
> + return 0
> + else
> + $fnc TFAIL "$@ passed unexpectedly"
> + return 1
> + fi
> +}
> +
> +EXPECT_PASS()
> +{
> + _tst_expect_pass tst_res "$@"
> +}
> +
> +EXPECT_PASS_BRK()
> +{
> + _tst_expect_pass tst_brk "$@"
> +}
I'm not sure that adding the PASS_BRK and FAIL_BRK is a good idea. I
would stick to simple EXPECT_PASS and EXPECT_FAIL. And maybe we can
export TST_PASS variable as we do in C to match the API. I think that
the closer the C and shell API are the better.
> +EXPECT_FAIL()
> +{
> + _tst_expect_fail tst_res "$@"
> +}
> +
> +EXPECT_FAIL_BRK()
> +{
> + _tst_expect_fail tst_brk "$@"
> +}
> --
> 2.51.0
>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-03-18 14:26 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 14:25 [LTP] [PATCH 0/6] [RFC,WIP] shell loader fixes + du01.sh rewrite Petr Vorel
2026-03-13 14:25 ` [LTP] [PATCH 1/6] tst_run.sh: Fix passing arguments Petr Vorel
2026-03-17 7:36 ` Li Wang via ltp
2026-03-18 14:17 ` Cyril Hrubis
2026-03-18 15:10 ` Petr Vorel
2026-03-13 14:25 ` [LTP] [PATCH 2/6] tst_env.sh: Backport common functions from tst_test.sh Petr Vorel
2026-03-17 7:54 ` Li Wang via ltp
2026-03-18 14:26 ` Cyril Hrubis [this message]
2026-03-18 15:02 ` Petr Vorel
2026-03-20 16:20 ` Cyril Hrubis
2026-03-23 12:06 ` Petr Vorel
2026-03-23 12:41 ` [LTP] isofs.sh rewrite [was Re: [PATCH 2/6] tst_env.sh: Backport common functions from tst_test.sh] Petr Vorel
2026-03-13 14:25 ` [LTP] [PATCH 3/6] shell_loader: Start test count from 1 Petr Vorel
2026-03-17 8:00 ` Li Wang via ltp
2026-03-13 14:25 ` [LTP] [RFC][PATCH 4/6] run_shell_tcnt: Add test count also for test_all Petr Vorel
2026-03-17 9:45 ` Li Wang via ltp
2026-03-13 14:25 ` [LTP] [PATCH 5/6] [WIP,RFC] tst_run.sh: Run setup() only once Petr Vorel
2026-03-17 9:42 ` Li Wang via ltp
2026-03-18 11:23 ` Cyril Hrubis
2026-03-18 12:26 ` Cyril Hrubis
2026-03-18 15:40 ` Petr Vorel
2026-03-20 15:15 ` Cyril Hrubis
2026-03-23 21:20 ` Petr Vorel
2026-03-13 14:26 ` [LTP] [PATCH 6/6] du01.sh: Rewrite into shell loader 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=abq1-BcXR1nfLGcU@yuki.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=pvorel@suse.cz \
--cc=sebastian.chlad@suse.com \
/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