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

Li Wang liwang@redhat.com
Sat Sep 7 03:29:46 CEST 2024


On Fri, Sep 6, 2024 at 9:30 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> Hi!
> > The difference is that /bin/sh links to dash in debian. But as you
> > pointed out even if all /bin/sh is changed to /bin/bash in the scripts
> > the tests stil fails.
> >
> > It looks like on RPi alias with variables does not work at all.
>
> So it looks like aliases may not be expanded on non-interactive shells
> unless it's enabled explicitely.
>
> This patch uses shopt to enable that and also works around dash that
> does not support $LINENO:
>
> diff --git a/testcases/lib/tst_env.sh b/testcases/lib/tst_env.sh
> index 67ba80744..bb0c586d7 100644
> --- a/testcases/lib/tst_env.sh
> +++ b/testcases/lib/tst_env.sh
> @@ -6,6 +6,16 @@
>
>  tst_script_name=$(basename $0)
>
> +# bash does not expand aliases in non-iteractive mode, enable it
> +if [ -n "$BASH_VERSION" ]; then
> +       shopt -s expand_aliases
> +fi
> +
> +# dash does not support line numbers even though this is mandated by POSIX
> +if [ -z "$LINENO" ]; then
> +       LINENO=-1
> +fi
> +
>  if [ -z "$LTP_IPC_PATH" ]; then
>         echo "This script has to be executed from a LTP loader!"
>         exit 1


LGTM.

This ensures that the script will work in both bash (with alias expansion
enabled)
and dash (with a fallback for LINENO). I confirmed that works correctly in
my RPi4.
Thanks!


-- 
Regards,
Li Wang


More information about the ltp mailing list