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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/core_read_macros.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) 2020 Facebook */
  3 
  4 #include <test_progs.h>
  5 
  6 struct callback_head {
  7         struct callback_head *next;
  8         void (*func)(struct callback_head *head);
  9 };
 10 
 11 /* ___shuffled flavor is just an illusion for BPF code, it doesn't really
 12  * exist and user-space needs to provide data in the memory layout that
 13  * matches callback_head. We just defined ___shuffled flavor to make it easier
 14  * to work with the skeleton
 15  */
 16 struct callback_head___shuffled {
 17         struct callback_head___shuffled *next;
 18         void (*func)(struct callback_head *head);
 19 };
 20 
 21 #include "test_core_read_macros.skel.h"
 22 
 23 void test_core_read_macros(void)
 24 {
 25         int duration = 0, err;
 26         struct test_core_read_macros* skel;
 27         struct test_core_read_macros__bss *bss;
 28         struct callback_head u_probe_in;
 29         struct callback_head___shuffled u_core_in;
 30 
 31         skel = test_core_read_macros__open_and_load();
 32         if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
 33                 return;
 34         bss = skel->bss;
 35         bss->my_pid = getpid();
 36 
 37         /* next pointers have to be set from the kernel side */
 38         bss->k_probe_in.func = (void *)(long)0x1234;
 39         bss->k_core_in.func = (void *)(long)0xabcd;
 40 
 41         u_probe_in.next = &u_probe_in;
 42         u_probe_in.func = (void *)(long)0x5678;
 43         bss->u_probe_in = &u_probe_in;
 44 
 45         u_core_in.next = &u_core_in;
 46         u_core_in.func = (void *)(long)0xdbca;
 47         bss->u_core_in = &u_core_in;
 48 
 49         err = test_core_read_macros__attach(skel);
 50         if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
 51                 goto cleanup;
 52 
 53         /* trigger tracepoint */
 54         usleep(1);
 55 
 56         ASSERT_EQ(bss->k_probe_out, 0x1234, "k_probe_out");
 57         ASSERT_EQ(bss->k_core_out, 0xabcd, "k_core_out");
 58 
 59         ASSERT_EQ(bss->u_probe_out, 0x5678, "u_probe_out");
 60         ASSERT_EQ(bss->u_core_out, 0xdbca, "u_core_out");
 61 
 62 cleanup:
 63         test_core_read_macros__destroy(skel);
 64 }
 65 

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