Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2021 Facebook */
3#include <test_progs.h>
4#include "timer.skel.h"
5#include "timer_failure.skel.h"
6
7static int timer(struct timer *timer_skel)
8{
9 int err, prog_fd;
10 LIBBPF_OPTS(bpf_test_run_opts, topts);
11
12 err = timer__attach(timer_skel);
13 if (!ASSERT_OK(err, "timer_attach"))
14 return err;
15
16 ASSERT_EQ(timer_skel->data->callback_check, 52, "callback_check1");
17 ASSERT_EQ(timer_skel->data->callback2_check, 52, "callback2_check1");
18 ASSERT_EQ(timer_skel->bss->pinned_callback_check, 0, "pinned_callback_check1");
19
20 prog_fd = bpf_program__fd(timer_skel->progs.test1);
21 err = bpf_prog_test_run_opts(prog_fd, &topts);
22 ASSERT_OK(err, "test_run");
23 ASSERT_EQ(topts.retval, 0, "test_run");
24 timer__detach(timer_skel);
25
26 usleep(50); /* 10 usecs should be enough, but give it extra */
27 /* check that timer_cb1() was executed 10+10 times */
28 ASSERT_EQ(timer_skel->data->callback_check, 42, "callback_check2");
29 ASSERT_EQ(timer_skel->data->callback2_check, 42, "callback2_check2");
30
31 /* check that timer_cb2() was executed twice */
32 ASSERT_EQ(timer_skel->bss->bss_data, 10, "bss_data");
33
34 /* check that timer_cb3() was executed twice */
35 ASSERT_EQ(timer_skel->bss->abs_data, 12, "abs_data");
36
37 /* check that timer_cb_pinned() was executed twice */
38 ASSERT_EQ(timer_skel->bss->pinned_callback_check, 2, "pinned_callback_check");
39
40 /* check that there were no errors in timer execution */
41 ASSERT_EQ(timer_skel->bss->err, 0, "err");
42
43 /* check that code paths completed */
44 ASSERT_EQ(timer_skel->bss->ok, 1 | 2 | 4, "ok");
45
46 return 0;
47}
48
49/* TODO: use pid filtering */
50void serial_test_timer(void)
51{
52 struct timer *timer_skel = NULL;
53 int err;
54
55 timer_skel = timer__open_and_load();
56 if (!ASSERT_OK_PTR(timer_skel, "timer_skel_load"))
57 return;
58
59 err = timer(timer_skel);
60 ASSERT_OK(err, "timer");
61 timer__destroy(timer_skel);
62
63 RUN_TESTS(timer_failure);
64}