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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/fentry_test.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 /* Copyright (c) 2019 Facebook */
  3 #include <test_progs.h>
  4 #include "fentry_test.lskel.h"
  5 #include "fentry_many_args.skel.h"
  6 
  7 static int fentry_test_common(struct fentry_test_lskel *fentry_skel)
  8 {
  9         int err, prog_fd, i;
 10         int link_fd;
 11         __u64 *result;
 12         LIBBPF_OPTS(bpf_test_run_opts, topts);
 13 
 14         err = fentry_test_lskel__attach(fentry_skel);
 15         if (!ASSERT_OK(err, "fentry_attach"))
 16                 return err;
 17 
 18         /* Check that already linked program can't be attached again. */
 19         link_fd = fentry_test_lskel__test1__attach(fentry_skel);
 20         if (!ASSERT_LT(link_fd, 0, "fentry_attach_link"))
 21                 return -1;
 22 
 23         prog_fd = fentry_skel->progs.test1.prog_fd;
 24         err = bpf_prog_test_run_opts(prog_fd, &topts);
 25         ASSERT_OK(err, "test_run");
 26         ASSERT_EQ(topts.retval, 0, "test_run");
 27 
 28         result = (__u64 *)fentry_skel->bss;
 29         for (i = 0; i < sizeof(*fentry_skel->bss) / sizeof(__u64); i++) {
 30                 if (!ASSERT_EQ(result[i], 1, "fentry_result"))
 31                         return -1;
 32         }
 33 
 34         fentry_test_lskel__detach(fentry_skel);
 35 
 36         /* zero results for re-attach test */
 37         memset(fentry_skel->bss, 0, sizeof(*fentry_skel->bss));
 38         return 0;
 39 }
 40 
 41 static void fentry_test(void)
 42 {
 43         struct fentry_test_lskel *fentry_skel = NULL;
 44         int err;
 45 
 46         fentry_skel = fentry_test_lskel__open_and_load();
 47         if (!ASSERT_OK_PTR(fentry_skel, "fentry_skel_load"))
 48                 goto cleanup;
 49 
 50         err = fentry_test_common(fentry_skel);
 51         if (!ASSERT_OK(err, "fentry_first_attach"))
 52                 goto cleanup;
 53 
 54         err = fentry_test_common(fentry_skel);
 55         ASSERT_OK(err, "fentry_second_attach");
 56 
 57 cleanup:
 58         fentry_test_lskel__destroy(fentry_skel);
 59 }
 60 
 61 static void fentry_many_args(void)
 62 {
 63         struct fentry_many_args *fentry_skel = NULL;
 64         int err;
 65 
 66         fentry_skel = fentry_many_args__open_and_load();
 67         if (!ASSERT_OK_PTR(fentry_skel, "fentry_many_args_skel_load"))
 68                 goto cleanup;
 69 
 70         err = fentry_many_args__attach(fentry_skel);
 71         if (!ASSERT_OK(err, "fentry_many_args_attach"))
 72                 goto cleanup;
 73 
 74         ASSERT_OK(trigger_module_test_read(1), "trigger_read");
 75 
 76         ASSERT_EQ(fentry_skel->bss->test1_result, 1,
 77                   "fentry_many_args_result1");
 78         ASSERT_EQ(fentry_skel->bss->test2_result, 1,
 79                   "fentry_many_args_result2");
 80         ASSERT_EQ(fentry_skel->bss->test3_result, 1,
 81                   "fentry_many_args_result3");
 82 
 83 cleanup:
 84         fentry_many_args__destroy(fentry_skel);
 85 }
 86 
 87 void test_fentry_test(void)
 88 {
 89         if (test__start_subtest("fentry"))
 90                 fentry_test();
 91         if (test__start_subtest("fentry_many_args"))
 92                 fentry_many_args();
 93 }
 94 

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