[LTP] [PATCH] lib/tst_test.c: Fix tst_brk() handling
Petr Vorel
pvorel@suse.cz
Fri Apr 4 14:55:17 CEST 2025
> Hi!
> > diff --git a/lib/tst_test.c b/lib/tst_test.c
> > index c6395a5eb..6b1100b09 100644
> > --- a/lib/tst_test.c
> > +++ b/lib/tst_test.c
> > @@ -407,7 +407,8 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
> > * current process.
> > */
> > if (TTYPE_RESULT(ttype) == TBROK) {
> > - tst_atomic_inc(&results->abort_flag);
> > + if (results)
> > + tst_atomic_inc(&results->abort_flag);
> > /*
> > * If TBROK was called from one of the child processes we kill
> And it's a bit more complex we also need to make sure to exit properly
> when tst_brk() was called before the library was initialized, so we also
+1
> need:
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index 758e62823..d19908d94 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -386,6 +386,14 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
> va_list va)
> {
> print_result(file, lineno, ttype, fmt, va);
> +
> + /*
> + * If tst_brk() is called from some of the C helpers even before the
> + * library was initialized, just exit.
> + */
> + if (!lib_pid)
> + exit(TTYPE_RESULT(ttype));
Interesting, I never noticed lib_pid :). It's assigned in tst_run_tcases() -
library gets initialized there. As that's the very first call in main(), this
really applies for helpers in testcases/lib/ which define TST_NO_DEFAULT_MAIN.
I suppose this is the part of the fix for core dumped helpers.
> +
> update_results(TTYPE_RESULT(ttype));
> /*
> @@ -415,7 +423,7 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
> * the main test process. That in turn triggers the code that
> * kills leftover children once the main test process did exit.
> */
> - if (tst_getpid() != main_pid) {
> + if (main_pid && tst_getpid() != main_pid) {
> tst_res(TINFO, "Child process reported TBROK killing the test");
> kill(main_pid, SIGKILL);
> }
> I will send v2 later on.
+1
Kind regards,
Petr
More information about the ltp
mailing list