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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/percpu_alloc.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 #include <test_progs.h>
  3 #include "percpu_alloc_array.skel.h"
  4 #include "percpu_alloc_cgrp_local_storage.skel.h"
  5 #include "percpu_alloc_fail.skel.h"
  6 
  7 static void test_array(void)
  8 {
  9         struct percpu_alloc_array *skel;
 10         int err, prog_fd;
 11         LIBBPF_OPTS(bpf_test_run_opts, topts);
 12 
 13         skel = percpu_alloc_array__open();
 14         if (!ASSERT_OK_PTR(skel, "percpu_alloc_array__open"))
 15                 return;
 16 
 17         bpf_program__set_autoload(skel->progs.test_array_map_1, true);
 18         bpf_program__set_autoload(skel->progs.test_array_map_2, true);
 19         bpf_program__set_autoload(skel->progs.test_array_map_3, true);
 20         bpf_program__set_autoload(skel->progs.test_array_map_4, true);
 21 
 22         skel->bss->my_pid = getpid();
 23         skel->rodata->nr_cpus = libbpf_num_possible_cpus();
 24 
 25         err = percpu_alloc_array__load(skel);
 26         if (!ASSERT_OK(err, "percpu_alloc_array__load"))
 27                 goto out;
 28 
 29         err = percpu_alloc_array__attach(skel);
 30         if (!ASSERT_OK(err, "percpu_alloc_array__attach"))
 31                 goto out;
 32 
 33         prog_fd = bpf_program__fd(skel->progs.test_array_map_1);
 34         err = bpf_prog_test_run_opts(prog_fd, &topts);
 35         ASSERT_OK(err, "test_run array_map 1-4");
 36         ASSERT_EQ(topts.retval, 0, "test_run array_map 1-4");
 37         ASSERT_EQ(skel->bss->cpu0_field_d, 2, "cpu0_field_d");
 38         ASSERT_EQ(skel->bss->sum_field_c, 1, "sum_field_c");
 39 out:
 40         percpu_alloc_array__destroy(skel);
 41 }
 42 
 43 static void test_array_sleepable(void)
 44 {
 45         struct percpu_alloc_array *skel;
 46         int err, prog_fd;
 47         LIBBPF_OPTS(bpf_test_run_opts, topts);
 48 
 49         skel = percpu_alloc_array__open();
 50         if (!ASSERT_OK_PTR(skel, "percpu_alloc__open"))
 51                 return;
 52 
 53         bpf_program__set_autoload(skel->progs.test_array_map_10, true);
 54 
 55         skel->bss->my_pid = getpid();
 56         skel->rodata->nr_cpus = libbpf_num_possible_cpus();
 57 
 58         err = percpu_alloc_array__load(skel);
 59         if (!ASSERT_OK(err, "percpu_alloc_array__load"))
 60                 goto out;
 61 
 62         err = percpu_alloc_array__attach(skel);
 63         if (!ASSERT_OK(err, "percpu_alloc_array__attach"))
 64                 goto out;
 65 
 66         prog_fd = bpf_program__fd(skel->progs.test_array_map_10);
 67         err = bpf_prog_test_run_opts(prog_fd, &topts);
 68         ASSERT_OK(err, "test_run array_map_10");
 69         ASSERT_EQ(topts.retval, 0, "test_run array_map_10");
 70         ASSERT_EQ(skel->bss->cpu0_field_d, 2, "cpu0_field_d");
 71         ASSERT_EQ(skel->bss->sum_field_c, 1, "sum_field_c");
 72 out:
 73         percpu_alloc_array__destroy(skel);
 74 }
 75 
 76 static void test_cgrp_local_storage(void)
 77 {
 78         struct percpu_alloc_cgrp_local_storage *skel;
 79         int err, cgroup_fd, prog_fd;
 80         LIBBPF_OPTS(bpf_test_run_opts, topts);
 81 
 82         cgroup_fd = test__join_cgroup("/percpu_alloc");
 83         if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup /percpu_alloc"))
 84                 return;
 85 
 86         skel = percpu_alloc_cgrp_local_storage__open();
 87         if (!ASSERT_OK_PTR(skel, "percpu_alloc_cgrp_local_storage__open"))
 88                 goto close_fd;
 89 
 90         skel->bss->my_pid = getpid();
 91         skel->rodata->nr_cpus = libbpf_num_possible_cpus();
 92 
 93         err = percpu_alloc_cgrp_local_storage__load(skel);
 94         if (!ASSERT_OK(err, "percpu_alloc_cgrp_local_storage__load"))
 95                 goto destroy_skel;
 96 
 97         err = percpu_alloc_cgrp_local_storage__attach(skel);
 98         if (!ASSERT_OK(err, "percpu_alloc_cgrp_local_storage__attach"))
 99                 goto destroy_skel;
100 
101         prog_fd = bpf_program__fd(skel->progs.test_cgrp_local_storage_1);
102         err = bpf_prog_test_run_opts(prog_fd, &topts);
103         ASSERT_OK(err, "test_run cgrp_local_storage 1-3");
104         ASSERT_EQ(topts.retval, 0, "test_run cgrp_local_storage 1-3");
105         ASSERT_EQ(skel->bss->cpu0_field_d, 2, "cpu0_field_d");
106         ASSERT_EQ(skel->bss->sum_field_c, 1, "sum_field_c");
107 
108 destroy_skel:
109         percpu_alloc_cgrp_local_storage__destroy(skel);
110 close_fd:
111         close(cgroup_fd);
112 }
113 
114 static void test_failure(void) {
115         RUN_TESTS(percpu_alloc_fail);
116 }
117 
118 void test_percpu_alloc(void)
119 {
120         if (test__start_subtest("array"))
121                 test_array();
122         if (test__start_subtest("array_sleepable"))
123                 test_array_sleepable();
124         if (test__start_subtest("cgrp_local_storage"))
125                 test_cgrp_local_storage();
126         if (test__start_subtest("failure_tests"))
127                 test_failure();
128 }
129 

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