~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/prog_run_opts.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <test_progs.h>
  3 #include <network_helpers.h>
  4 
  5 #include "test_pkt_access.skel.h"
  6 
  7 static const __u32 duration;
  8 
  9 static void check_run_cnt(int prog_fd, __u64 run_cnt)
 10 {
 11         struct bpf_prog_info info = {};
 12         __u32 info_len = sizeof(info);
 13         int err;
 14 
 15         err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
 16         if (CHECK(err, "get_prog_info", "failed to get bpf_prog_info for fd %d\n", prog_fd))
 17                 return;
 18 
 19         CHECK(run_cnt != info.run_cnt, "run_cnt",
 20               "incorrect number of repetitions, want %llu have %llu\n", run_cnt, info.run_cnt);
 21 }
 22 
 23 void test_prog_run_opts(void)
 24 {
 25         struct test_pkt_access *skel;
 26         int err, stats_fd = -1, prog_fd;
 27         char buf[10] = {};
 28         __u64 run_cnt = 0;
 29 
 30         LIBBPF_OPTS(bpf_test_run_opts, topts,
 31                 .repeat = 1,
 32                 .data_in = &pkt_v4,
 33                 .data_size_in = sizeof(pkt_v4),
 34                 .data_out = buf,
 35                 .data_size_out = 5,
 36         );
 37 
 38         stats_fd = bpf_enable_stats(BPF_STATS_RUN_TIME);
 39         if (!ASSERT_GE(stats_fd, 0, "enable_stats good fd"))
 40                 return;
 41 
 42         skel = test_pkt_access__open_and_load();
 43         if (!ASSERT_OK_PTR(skel, "open_and_load"))
 44                 goto cleanup;
 45 
 46         prog_fd = bpf_program__fd(skel->progs.test_pkt_access);
 47 
 48         err = bpf_prog_test_run_opts(prog_fd, &topts);
 49         ASSERT_EQ(errno, ENOSPC, "test_run errno");
 50         ASSERT_ERR(err, "test_run");
 51         ASSERT_OK(topts.retval, "test_run retval");
 52 
 53         ASSERT_EQ(topts.data_size_out, sizeof(pkt_v4), "test_run data_size_out");
 54         ASSERT_EQ(buf[5], 0, "overflow, BPF_PROG_TEST_RUN ignored size hint");
 55 
 56         run_cnt += topts.repeat;
 57         check_run_cnt(prog_fd, run_cnt);
 58 
 59         topts.data_out = NULL;
 60         topts.data_size_out = 0;
 61         topts.repeat = 2;
 62         errno = 0;
 63 
 64         err = bpf_prog_test_run_opts(prog_fd, &topts);
 65         ASSERT_OK(errno, "run_no_output errno");
 66         ASSERT_OK(err, "run_no_output err");
 67         ASSERT_OK(topts.retval, "run_no_output retval");
 68 
 69         run_cnt += topts.repeat;
 70         check_run_cnt(prog_fd, run_cnt);
 71 
 72 cleanup:
 73         if (skel)
 74                 test_pkt_access__destroy(skel);
 75         if (stats_fd >= 0)
 76                 close(stats_fd);
 77 }
 78 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php