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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/test_bpf_ma.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) 2023. Huawei Technologies Co., Ltd */
  3 #define _GNU_SOURCE
  4 #include <sched.h>
  5 #include <pthread.h>
  6 #include <stdbool.h>
  7 #include <bpf/btf.h>
  8 #include <test_progs.h>
  9 
 10 #include "test_bpf_ma.skel.h"
 11 
 12 static void do_bpf_ma_test(const char *name)
 13 {
 14         struct test_bpf_ma *skel;
 15         struct bpf_program *prog;
 16         struct btf *btf;
 17         int i, err, id;
 18         char tname[32];
 19 
 20         skel = test_bpf_ma__open();
 21         if (!ASSERT_OK_PTR(skel, "open"))
 22                 return;
 23 
 24         btf = bpf_object__btf(skel->obj);
 25         if (!ASSERT_OK_PTR(btf, "btf"))
 26                 goto out;
 27 
 28         for (i = 0; i < ARRAY_SIZE(skel->rodata->data_sizes); i++) {
 29                 snprintf(tname, sizeof(tname), "bin_data_%u", skel->rodata->data_sizes[i]);
 30                 id = btf__find_by_name_kind(btf, tname, BTF_KIND_STRUCT);
 31                 if (!ASSERT_GT(id, 0, tname))
 32                         goto out;
 33                 skel->rodata->data_btf_ids[i] = id;
 34         }
 35 
 36         for (i = 0; i < ARRAY_SIZE(skel->rodata->percpu_data_sizes); i++) {
 37                 snprintf(tname, sizeof(tname), "percpu_bin_data_%u", skel->rodata->percpu_data_sizes[i]);
 38                 id = btf__find_by_name_kind(btf, tname, BTF_KIND_STRUCT);
 39                 if (!ASSERT_GT(id, 0, tname))
 40                         goto out;
 41                 skel->rodata->percpu_data_btf_ids[i] = id;
 42         }
 43 
 44         prog = bpf_object__find_program_by_name(skel->obj, name);
 45         if (!ASSERT_OK_PTR(prog, "invalid prog name"))
 46                 goto out;
 47         bpf_program__set_autoload(prog, true);
 48 
 49         err = test_bpf_ma__load(skel);
 50         if (!ASSERT_OK(err, "load"))
 51                 goto out;
 52 
 53         err = test_bpf_ma__attach(skel);
 54         if (!ASSERT_OK(err, "attach"))
 55                 goto out;
 56 
 57         skel->bss->pid = getpid();
 58         usleep(1);
 59         ASSERT_OK(skel->bss->err, "test error");
 60 out:
 61         test_bpf_ma__destroy(skel);
 62 }
 63 
 64 void test_test_bpf_ma(void)
 65 {
 66         if (test__start_subtest("batch_alloc_free"))
 67                 do_bpf_ma_test("test_batch_alloc_free");
 68         if (test__start_subtest("free_through_map_free"))
 69                 do_bpf_ma_test("test_free_through_map_free");
 70         if (test__start_subtest("batch_percpu_alloc_free"))
 71                 do_bpf_ma_test("test_batch_percpu_alloc_free");
 72         if (test__start_subtest("percpu_free_through_map_free"))
 73                 do_bpf_ma_test("test_percpu_free_through_map_free");
 74 }
 75 

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