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

Li Wang
2024-09-06T11:06:53Z

On Fri, Sep 6, 2024 at 6:19 PM Li Wang <liwang@redhat.com> wrote:

>
>
> On Fri, Sep 6, 2024 at 5:54 PM Cyril Hrubis <chrubis@suse.cz> wrote:
>
>> Hi!
>> > 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.
>>
>> Are you sure that this is due to bash? My guess is that on RPi the
>> default shell is dash because it's debian based.
>>
>> I will try to reproduce.
>>
>> > 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" "$@"
>> > +}
>>
>> That actually does not work because unlike the alias the $LINENO is
>> expanded in the wrong place and the line is incorrect.
>>
>> The whole reason for this to be alias is that it's expanded on the
>> correct line in the test source.
>>
>
> Ah, you're right, I wasn't aware of that.
>
> Maybe we can use a trick with eval to delay the expansion
> of $LINENO until the function is actually called?
>

Hmm, seems this is also not working as expected. Please ignore.

$ cat liwang.sh
#!/bin/bash

print_line() {
eval "echo \"this is line: \$LINENO\""
}

echo "This is line $LINENO"
print_line

liwang@raspi4:~/ltp/testcases/lib$ ./liwang.sh
This is line 7
this is line: 4

>

--
Regards,
Li Wang