Re: [PATCH] selftests/bpf: check for timeout in perf_link test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Oct 10, 2024 at 4:24 PM Ihor Solodrai <ihor.solodrai@xxxxx> wrote:
>
> Recently perf_link test started unreliably failing on libbpf CI:
>   * https://github.com/libbpf/libbpf/actions/runs/11260672407/job/31312405473
>   * https://github.com/libbpf/libbpf/actions/runs/11260992334/job/31315514626
>   * https://github.com/libbpf/libbpf/actions/runs/11263162459/job/31320458251
>
> Part of the test is running a dummy loop for a while and then checking
> for a counter incremented by the test program.
>
> Instead of waiting for an arbitrary number of loop iterations once,
> check for the test counter in a loop and use get_time_ns() helper to
> enforce a 100ms timeout.
>
> Signed-off-by: Ihor Solodrai <ihor.solodrai@xxxxx>
> ---
>  tools/testing/selftests/bpf/prog_tests/perf_link.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/perf_link.c b/tools/testing/selftests/bpf/prog_tests/perf_link.c
> index 3a25f1c743a1..c1f13d77c464 100644
> --- a/tools/testing/selftests/bpf/prog_tests/perf_link.c
> +++ b/tools/testing/selftests/bpf/prog_tests/perf_link.c
> @@ -4,8 +4,12 @@
>  #include <pthread.h>
>  #include <sched.h>
>  #include <test_progs.h>
> +#include "testing_helpers.h"
>  #include "test_perf_link.skel.h"
>
> +#define BURN_TIMEOUT_MS 100
> +#define BURN_TIMEOUT_NS BURN_TIMEOUT_MS * 1000000
> +
>  static void burn_cpu(void)
>  {
>         volatile int j = 0;
> @@ -63,8 +67,14 @@ void serial_test_perf_link(void)
>         ASSERT_GT(info.prog_id, 0, "link_prog_id");
>
>         /* ensure we get at least one perf_event prog execution */
> -       burn_cpu();
> -       ASSERT_GT(skel->bss->run_cnt, 0, "run_cnt");
> +       __u64 timeout_time_ns = get_time_ns() + BURN_TIMEOUT_NS;

nit: this is not really a kernel C89 code style (even though we don't
enforce that in selftests, but still), can you please move variable
*declaration* up to the top of the function?

> +       while (1) {

nit: true

pw-bot: cr

> +               burn_cpu();
> +               if (skel->bss->run_cnt > 0)
> +                       break;
> +               if (!ASSERT_LT(get_time_ns(), timeout_time_ns, "run_cnt_timeout"))
> +                       break;
> +       }
>
>         /* perf_event is still active, but we close link and BPF program
>          * shouldn't be executed anymore
> --
> 2.39.5 (Apple Git-154)
>





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux