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

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

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ 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 /* Copyright (c) 2021 Facebook */
  3 #include <test_progs.h>
  4 #include "syscall.skel.h"
  5 
  6 struct args {
  7         __u64 log_buf;
  8         __u32 log_size;
  9         int max_entries;
 10         int map_fd;
 11         int prog_fd;
 12         int btf_fd;
 13 };
 14 
 15 static void test_syscall_load_prog(void)
 16 {
 17         static char verifier_log[8192];
 18         struct args ctx = {
 19                 .max_entries = 1024,
 20                 .log_buf = (uintptr_t) verifier_log,
 21                 .log_size = sizeof(verifier_log),
 22         };
 23         LIBBPF_OPTS(bpf_test_run_opts, tattr,
 24                 .ctx_in = &ctx,
 25                 .ctx_size_in = sizeof(ctx),
 26         );
 27         struct syscall *skel = NULL;
 28         __u64 key = 12, value = 0;
 29         int err, prog_fd;
 30 
 31         skel = syscall__open_and_load();
 32         if (!ASSERT_OK_PTR(skel, "skel_load"))
 33                 goto cleanup;
 34 
 35         prog_fd = bpf_program__fd(skel->progs.load_prog);
 36         err = bpf_prog_test_run_opts(prog_fd, &tattr);
 37         ASSERT_EQ(err, 0, "err");
 38         ASSERT_EQ(tattr.retval, 1, "retval");
 39         ASSERT_GT(ctx.map_fd, 0, "ctx.map_fd");
 40         ASSERT_GT(ctx.prog_fd, 0, "ctx.prog_fd");
 41         ASSERT_OK(memcmp(verifier_log, "processed", sizeof("processed") - 1),
 42                   "verifier_log");
 43 
 44         err = bpf_map_lookup_elem(ctx.map_fd, &key, &value);
 45         ASSERT_EQ(err, 0, "map_lookup");
 46         ASSERT_EQ(value, 34, "map lookup value");
 47 cleanup:
 48         syscall__destroy(skel);
 49         if (ctx.prog_fd > 0)
 50                 close(ctx.prog_fd);
 51         if (ctx.map_fd > 0)
 52                 close(ctx.map_fd);
 53         if (ctx.btf_fd > 0)
 54                 close(ctx.btf_fd);
 55 }
 56 
 57 static void test_syscall_update_outer_map(void)
 58 {
 59         LIBBPF_OPTS(bpf_test_run_opts, opts);
 60         struct syscall *skel;
 61         int err, prog_fd;
 62 
 63         skel = syscall__open_and_load();
 64         if (!ASSERT_OK_PTR(skel, "skel_load"))
 65                 goto cleanup;
 66 
 67         prog_fd = bpf_program__fd(skel->progs.update_outer_map);
 68         err = bpf_prog_test_run_opts(prog_fd, &opts);
 69         ASSERT_EQ(err, 0, "err");
 70         ASSERT_EQ(opts.retval, 1, "retval");
 71 cleanup:
 72         syscall__destroy(skel);
 73 }
 74 
 75 void test_syscall(void)
 76 {
 77         if (test__start_subtest("load_prog"))
 78                 test_syscall_load_prog();
 79         if (test__start_subtest("update_outer_map"))
 80                 test_syscall_update_outer_map();
 81 }
 82 

~ [ 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