1 // SPDX-License-Identifier: GPL-2.0
2 #include <test_progs.h>
3 #include "test_enable_stats.skel.h"
5 void test_enable_stats(void)
7 struct test_enable_stats
*skel
;
8 int stats_fd
, err
, prog_fd
;
9 struct bpf_prog_info info
;
10 __u32 info_len
= sizeof(info
);
13 skel
= test_enable_stats__open_and_load();
14 if (CHECK(!skel
, "skel_open_and_load", "skeleton open/load failed\n"))
17 stats_fd
= bpf_enable_stats(BPF_STATS_RUN_TIME
);
18 if (CHECK(stats_fd
< 0, "get_stats_fd", "failed %d\n", errno
)) {
19 test_enable_stats__destroy(skel
);
23 err
= test_enable_stats__attach(skel
);
24 if (CHECK(err
, "attach_raw_tp", "err %d\n", err
))
27 test_enable_stats__detach(skel
);
29 prog_fd
= bpf_program__fd(skel
->progs
.test_enable_stats
);
30 memset(&info
, 0, info_len
);
31 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &info_len
);
32 if (CHECK(err
, "get_prog_info",
33 "failed to get bpf_prog_info for fd %d\n", prog_fd
))
35 if (CHECK(info
.run_time_ns
== 0, "check_stats_enabled",
36 "failed to enable run_time_ns stats\n"))
39 CHECK(info
.run_cnt
!= skel
->bss
->count
, "check_run_cnt_valid",
40 "invalid run_cnt stats\n");
43 test_enable_stats__destroy(skel
);