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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/arena_htab.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) 2024 Meta Platforms, Inc. and affiliates. */
  3 #include <test_progs.h>
  4 #include <sys/mman.h>
  5 #include <network_helpers.h>
  6 #include <sys/user.h>
  7 #ifndef PAGE_SIZE /* on some archs it comes in sys/user.h */
  8 #include <unistd.h>
  9 #define PAGE_SIZE getpagesize()
 10 #endif
 11 #include "arena_htab_asm.skel.h"
 12 #include "arena_htab.skel.h"
 13 
 14 #include "bpf_arena_htab.h"
 15 
 16 static void test_arena_htab_common(struct htab *htab)
 17 {
 18         int i;
 19 
 20         printf("htab %p buckets %p n_buckets %d\n", htab, htab->buckets, htab->n_buckets);
 21         ASSERT_OK_PTR(htab->buckets, "htab->buckets shouldn't be NULL");
 22         for (i = 0; htab->buckets && i < 16; i += 4) {
 23                 /*
 24                  * Walk htab buckets and link lists since all pointers are correct,
 25                  * though they were written by bpf program.
 26                  */
 27                 int val = htab_lookup_elem(htab, i);
 28 
 29                 ASSERT_EQ(i, val, "key == value");
 30         }
 31 }
 32 
 33 static void test_arena_htab_llvm(void)
 34 {
 35         LIBBPF_OPTS(bpf_test_run_opts, opts);
 36         struct arena_htab *skel;
 37         struct htab *htab;
 38         size_t arena_sz;
 39         void *area;
 40         int ret;
 41 
 42         skel = arena_htab__open_and_load();
 43         if (!ASSERT_OK_PTR(skel, "arena_htab__open_and_load"))
 44                 return;
 45 
 46         area = bpf_map__initial_value(skel->maps.arena, &arena_sz);
 47         /* fault-in a page with pgoff == 0 as sanity check */
 48         *(volatile int *)area = 0x55aa;
 49 
 50         /* bpf prog will allocate more pages */
 51         ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.arena_htab_llvm), &opts);
 52         ASSERT_OK(ret, "ret");
 53         ASSERT_OK(opts.retval, "retval");
 54         if (skel->bss->skip) {
 55                 printf("%s:SKIP:compiler doesn't support arena_cast\n", __func__);
 56                 test__skip();
 57                 goto out;
 58         }
 59         htab = skel->bss->htab_for_user;
 60         test_arena_htab_common(htab);
 61 out:
 62         arena_htab__destroy(skel);
 63 }
 64 
 65 static void test_arena_htab_asm(void)
 66 {
 67         LIBBPF_OPTS(bpf_test_run_opts, opts);
 68         struct arena_htab_asm *skel;
 69         struct htab *htab;
 70         int ret;
 71 
 72         skel = arena_htab_asm__open_and_load();
 73         if (!ASSERT_OK_PTR(skel, "arena_htab_asm__open_and_load"))
 74                 return;
 75 
 76         ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.arena_htab_asm), &opts);
 77         ASSERT_OK(ret, "ret");
 78         ASSERT_OK(opts.retval, "retval");
 79         htab = skel->bss->htab_for_user;
 80         test_arena_htab_common(htab);
 81         arena_htab_asm__destroy(skel);
 82 }
 83 
 84 void test_arena_htab(void)
 85 {
 86         if (test__start_subtest("arena_htab_llvm"))
 87                 test_arena_htab_llvm();
 88         if (test__start_subtest("arena_htab_asm"))
 89                 test_arena_htab_asm();
 90 }
 91 

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