]>
git.ipfire.org Git - thirdparty/kernel/stable.git/blob - tools/testing/selftests/bpf/prog_tests/timer.c
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2021 Facebook */
3 #include <test_progs.h>
4 #include "timer.skel.h"
6 static int timer(struct timer
*timer_skel
)
9 LIBBPF_OPTS(bpf_test_run_opts
, topts
);
11 err
= timer__attach(timer_skel
);
12 if (!ASSERT_OK(err
, "timer_attach"))
15 ASSERT_EQ(timer_skel
->data
->callback_check
, 52, "callback_check1");
16 ASSERT_EQ(timer_skel
->data
->callback2_check
, 52, "callback2_check1");
18 prog_fd
= bpf_program__fd(timer_skel
->progs
.test1
);
19 err
= bpf_prog_test_run_opts(prog_fd
, &topts
);
20 ASSERT_OK(err
, "test_run");
21 ASSERT_EQ(topts
.retval
, 0, "test_run");
22 timer__detach(timer_skel
);
24 usleep(50); /* 10 usecs should be enough, but give it extra */
25 /* check that timer_cb1() was executed 10+10 times */
26 ASSERT_EQ(timer_skel
->data
->callback_check
, 42, "callback_check2");
27 ASSERT_EQ(timer_skel
->data
->callback2_check
, 42, "callback2_check2");
29 /* check that timer_cb2() was executed twice */
30 ASSERT_EQ(timer_skel
->bss
->bss_data
, 10, "bss_data");
32 /* check that timer_cb3() was executed twice */
33 ASSERT_EQ(timer_skel
->bss
->abs_data
, 12, "abs_data");
35 /* check that there were no errors in timer execution */
36 ASSERT_EQ(timer_skel
->bss
->err
, 0, "err");
38 /* check that code paths completed */
39 ASSERT_EQ(timer_skel
->bss
->ok
, 1 | 2 | 4, "ok");
44 /* TODO: use pid filtering */
45 void serial_test_timer(void)
47 struct timer
*timer_skel
= NULL
;
50 timer_skel
= timer__open_and_load();
51 if (!ASSERT_OK_PTR(timer_skel
, "timer_skel_load"))
54 err
= timer(timer_skel
);
55 ASSERT_OK(err
, "timer");
57 timer__destroy(timer_skel
);