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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/fexit_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 "fexit_test.lskel.h"
  5 #include "fexit_many_args.skel.h"
  6 
  7 static int fexit_test_common(struct fexit_test_lskel *fexit_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 = fexit_test_lskel__attach(fexit_skel);
 15         if (!ASSERT_OK(err, "fexit_attach"))
 16                 return err;
 17 
 18         /* Check that already linked program can't be attached again. */
 19         link_fd = fexit_test_lskel__test1__attach(fexit_skel);
 20         if (!ASSERT_LT(link_fd, 0, "fexit_attach_link"))
 21                 return -1;
 22 
 23         prog_fd = fexit_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 *)fexit_skel->bss;
 29         for (i = 0; i < sizeof(*fexit_skel->bss) / sizeof(__u64); i++) {
 30                 if (!ASSERT_EQ(result[i], 1, "fexit_result"))
 31                         return -1;
 32         }
 33 
 34         fexit_test_lskel__detach(fexit_skel);
 35 
 36         /* zero results for re-attach test */
 37         memset(fexit_skel->bss, 0, sizeof(*fexit_skel->bss));
 38         return 0;
 39 }
 40 
 41 static void fexit_test(void)
 42 {
 43         struct fexit_test_lskel *fexit_skel = NULL;
 44         int err;
 45 
 46         fexit_skel = fexit_test_lskel__open_and_load();
 47         if (!ASSERT_OK_PTR(fexit_skel, "fexit_skel_load"))
 48                 goto cleanup;
 49 
 50         err = fexit_test_common(fexit_skel);
 51         if (!ASSERT_OK(err, "fexit_first_attach"))
 52                 goto cleanup;
 53 
 54         err = fexit_test_common(fexit_skel);
 55         ASSERT_OK(err, "fexit_second_attach");
 56 
 57 cleanup:
 58         fexit_test_lskel__destroy(fexit_skel);
 59 }
 60 
 61 static void fexit_many_args(void)
 62 {
 63         struct fexit_many_args *fexit_skel = NULL;
 64         int err;
 65 
 66         fexit_skel = fexit_many_args__open_and_load();
 67         if (!ASSERT_OK_PTR(fexit_skel, "fexit_many_args_skel_load"))
 68                 goto cleanup;
 69 
 70         err = fexit_many_args__attach(fexit_skel);
 71         if (!ASSERT_OK(err, "fexit_many_args_attach"))
 72                 goto cleanup;
 73 
 74         ASSERT_OK(trigger_module_test_read(1), "trigger_read");
 75 
 76         ASSERT_EQ(fexit_skel->bss->test1_result, 1,
 77                   "fexit_many_args_result1");
 78         ASSERT_EQ(fexit_skel->bss->test2_result, 1,
 79                   "fexit_many_args_result2");
 80         ASSERT_EQ(fexit_skel->bss->test3_result, 1,
 81                   "fexit_many_args_result3");
 82 
 83 cleanup:
 84         fexit_many_args__destroy(fexit_skel);
 85 }
 86 
 87 void test_fexit_test(void)
 88 {
 89         if (test__start_subtest("fexit"))
 90                 fexit_test();
 91         if (test__start_subtest("fexit_many_args"))
 92                 fexit_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