linux/tools/testing/selftests/bpf/prog_tests/enable_stats.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2#include <test_progs.h>
   3#include "test_enable_stats.skel.h"
   4
   5void test_enable_stats(void)
   6{
   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);
  11        int duration = 0;
  12
  13        skel = test_enable_stats__open_and_load();
  14        if (CHECK(!skel, "skel_open_and_load", "skeleton open/load failed\n"))
  15                return;
  16
  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);
  20                return;
  21        }
  22
  23        err = test_enable_stats__attach(skel);
  24        if (CHECK(err, "attach_raw_tp", "err %d\n", err))
  25                goto cleanup;
  26
  27        test_enable_stats__detach(skel);
  28
  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))
  34                goto cleanup;
  35        if (CHECK(info.run_time_ns == 0, "check_stats_enabled",
  36                  "failed to enable run_time_ns stats\n"))
  37                goto cleanup;
  38
  39        CHECK(info.run_cnt != skel->bss->count, "check_run_cnt_valid",
  40              "invalid run_cnt stats\n");
  41
  42cleanup:
  43        test_enable_stats__destroy(skel);
  44        close(stats_fd);
  45}
  46