[LTP] [PATCH v1] include/tst_timer: Add TST_NO_LIBLTP

John Stultz jstultz@google.com
Wed Jun 26 20:58:05 CEST 2024


On Wed, Jun 26, 2024 at 6:30 AM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Older compilers (gcc-4.8) are not smart enough to eliminate the
> impossible branch with tst_brk() early enough and the sched_football
> compilation fails due to the unresolved function.
>
> Add TST_NO_LIBLTP macro that changes the tst_brk() messages into abort()
> and make use of it in sched_football.
>
> Fixes compilation on Leap-42.2.
>
> Cc: kernel-team@android.com
> Cc: Darren Hart <darren@os.amperecomputing.com>
> Cc: John Stultz <jstultz@google.com>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  include/tst_timer.h                              | 16 ++++++++++++++++
>  .../func/sched_football/sched_football.c         |  1 +
>  2 files changed, 17 insertions(+)
>
> diff --git a/include/tst_timer.h b/include/tst_timer.h
> index 6fb940020..fc0cdb5bc 100644
> --- a/include/tst_timer.h
> +++ b/include/tst_timer.h
> @@ -180,7 +180,11 @@ static inline void *tst_ts_get(struct tst_ts *t)
>         case TST_KERN_TIMESPEC:
>                 return &t->ts.kern_ts;
>         default:
> +#ifndef TST_NO_LIBLTP
>                 tst_brk(TBROK, "Invalid type: %d", t->type);
> +#else
> +               abort();
> +#endif
>                 return NULL;
>         }
>  }
> @@ -196,7 +200,11 @@ static inline void *tst_its_get(struct tst_its *t)
>         case TST_KERN_TIMESPEC:
>                 return &t->ts.kern_its;
>         default:
> +#ifndef TST_NO_LIBLTP
>                 tst_brk(TBROK, "Invalid type: %d", t->type);
> +#else
> +               abort();
> +#endif
>                 return NULL;
>         }
>  }
...
> diff --git a/testcases/realtime/func/sched_football/sched_football.c b/testcases/realtime/func/sched_football/sched_football.c
> index b6ae692af..6846978f4 100644
> --- a/testcases/realtime/func/sched_football/sched_football.c
> +++ b/testcases/realtime/func/sched_football/sched_football.c
> @@ -74,6 +74,7 @@
>  #include <librttest.h>
>  #include <tst_atomic.h>
>  #define TST_NO_DEFAULT_MAIN
> +#define TST_NO_LIBLTP
>  #include <tst_timer.h>

I don't have much background around the LTP project, so feel free to
ignore me, but this seems like it could get a little messy.

One common pattern in the kernel, which might help, is to handle
missing functions via stubs in the headers.

So instead you can implement in a header once:

#ifndef TST_NO_LIBLTP
static inline void test_brk(int i, char *s, long d)
{
    abort();
}
#endif

And then the downstream users don't need to have #ifdefs littering their logic.

Again, just an idea.

thanks
-john


More information about the ltp mailing list