Re: [LTP] [PATCH v3 2/4] Add support for mixing C and shell code

Li Wang
2024-09-06T07:34:57Z

Cyril Hrubis <chrubis@suse.cz> wrote:

> diff --git a/testcases/lib/tst_env.sh b/testcases/lib/tst_env.sh
> new file mode 100644
> index 000000000..948bc5024
> --- /dev/null
> +++ b/testcases/lib/tst_env.sh
> @@ -0,0 +1,21 @@
> +#!/bin/sh
> +
> +tst_script_name=$(basename $0)
> +
> +if [ -z "$LTP_IPC_PATH" ]; then
> + echo "This script has to be executed from a LTP loader!"
> + exit 1
> +fi
> +
> +tst_brk_()
> +{
> + tst_res_ "$@"
> +
> + case "$3" in
> + "TBROK") exit 2;;
> + *) exit 0;;
> + esac
> +}
> +
> +alias tst_res="tst_res_ $tst_script_name \$LINENO"
> +alias tst_brk="tst_brk_ $tst_script_name \$LINENO"
>

*** Running shell_test01 ***

tst_test.c:1860: TINFO: LTP version: 20240524
tst_test.c:1864: TINFO: Tested kernel: 6.8.0-1010-raspi #11-Ubuntu SMP
PREEMPT_DYNAMIC Thu Aug 8 23:22:41 UTC 2024 aarch64
tst_test.c:1703: TINFO: Timeout per run is 0h 00m 30s
shell_test01.c:11: TINFO: C test exits now
Usage: tst_res_ filename lineno [TPASS|TFAIL|TCONF|TINFO|TDEBUG] 'A short
description'
tst_test.c:1535: TBROK: Test haven't reported results!

Summary:
passed 0
failed 0
broken 1
skipped 0
warnings 0

Here I got test failures on my RPi4 (bash-5.2.21) that the $LINEON can't
be parsed correctly.

The reason probably is some shells or specific versions might not handle
$LINENO correctly within aliases, especially when the line number needs
to be dynamically determined.

So I suggest using a function instead of the alias.

--- a/testcases/lib/tst_env.sh
+++ b/testcases/lib/tst_env.sh
@@ -21,5 +21,12 @@ tst_brk_()
esac
}

-alias tst_res="tst_res_ $tst_script_name \$LINENO"
-alias tst_brk="tst_brk_ $tst_script_name \$LINENO"
+tst_res()
+{
+ tst_res_ "$tst_script_name" "$LINENO" "$@"
+}
+
+tst_brk()
+{
+ tst_brk_ "$tst_script_name" "$LINENO" "$@"
+}

--
Regards,
Li Wang