Re: Re: Re: [RFC PATCH v3 4/4] ftracetest: Add XFAIL/XPASS and POSIX.3 std. result codes

From: Masami Hiramatsu
Date: Mon Sep 08 2014 - 06:42:05 EST


(2014/09/04 13:39), Masami Hiramatsu wrote:
> (2014/09/04 11:29), Namhyung Kim wrote:
>>> diff --git a/tools/testing/ftrace/test.d/basic3.tc b/tools/testing/ftrace/test.d/basic3.tc
>>> index 0c1a3a2..7bc5a53 100644
>>> --- a/tools/testing/ftrace/test.d/basic3.tc
>>> +++ b/tools/testing/ftrace/test.d/basic3.tc
>>> @@ -1,8 +1,9 @@
>>> #!/bin/sh
>>> # description: Basic trace clock test
>>> -[ -f trace_clock ] || exit 1
>>> +[ -f trace_clock ] || exit $FAIL # this is basic feature, must be there
>>> for c in `cat trace_clock | tr -d \[\]`; do
>>> - echo $c > trace_clock || exit 1
>>> - grep '\['$c'\]' trace_clock || exit 1
>>> + echo $c > trace_clock || exit $FAIL
>>> + grep '\['$c'\]' trace_clock || exit $FAIL
>>> done
>>> -echo local > trace_clock
>>> +echo local > trace_clock || exit $FAIL
>>> +exit $PASS
>>
>> IMHO it's a bit sad that we need to write every test in this way -
>> adding '|| exit $FAIL' for every command. It'd be better if only
>> exceptional cases require that explicitly and normal cases live in
>> simple.
>>
>> Can we do better - like using trap or something?
>
> Hmm, no, trap is only for the signal trapping, and using signal
> means run "kill" command for special errors. That may not be what
> you want... :(

I've changed my mind. I've checked that the possibility of simplification
of the testcases with signal traps. :)
Here I've added the following functions,

-----
exit_unsupported () {
kill -s $SIG_UNSUPPORTED $SIG_PID
exit 0
}
trap_unsupported () {
SIG_RESULT=$UNSUPPORTED
}
trap trap_unsupported $SIG_UNSUPPORTED
-----

And add "set -e;"(errexit) for sub-shell testcases.

-----
#!/bin/sh
# description: Kprobe dynamic event - adding and removing

[ -f kprobe_events ] || exit_unsupported

# If we have any error, sub shell exits soon with error code.
echo 0 > events/enable
echo > kprobe_events
echo p:myevent do_fork > kprobe_events
grep myevent kprobe_events
test -d events/kprobes/myevent
echo > kprobe_events
exit 0
-----

So, we'll have no return code in the testcases.

>
> Perhaps, "set -e" may help you to simplify the script. But
> since it also returns various exit code, you can not control it.
> (I hope to have the "atexit" for dash...)

I've found that trap with 0 can catch the exit of subshell, but
it can not know the exit code...

BTW, I've found that $PPID and $$ in subshell doesn't updated automatically.
PPID can be updated, but $$ cannnot. I'll pass $PID so that the testcases
can use it instead of $$. Or, should I use $SHELL to run testcases?

Thank you,


--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@xxxxxxxxxxx


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/