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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/preempted_bpf_ma_op.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 <test_progs.h>
  8 
  9 #include "preempted_bpf_ma_op.skel.h"
 10 
 11 #define ALLOC_THREAD_NR 4
 12 #define ALLOC_LOOP_NR 512
 13 
 14 struct alloc_ctx {
 15         /* output */
 16         int run_err;
 17         /* input */
 18         int fd;
 19         bool *nomem_err;
 20 };
 21 
 22 static void *run_alloc_prog(void *data)
 23 {
 24         struct alloc_ctx *ctx = data;
 25         cpu_set_t cpu_set;
 26         int i;
 27 
 28         CPU_ZERO(&cpu_set);
 29         CPU_SET(0, &cpu_set);
 30         pthread_setaffinity_np(pthread_self(), sizeof(cpu_set), &cpu_set);
 31 
 32         for (i = 0; i < ALLOC_LOOP_NR && !*ctx->nomem_err; i++) {
 33                 LIBBPF_OPTS(bpf_test_run_opts, topts);
 34                 int err;
 35 
 36                 err = bpf_prog_test_run_opts(ctx->fd, &topts);
 37                 ctx->run_err |= err | topts.retval;
 38         }
 39 
 40         return NULL;
 41 }
 42 
 43 void test_preempted_bpf_ma_op(void)
 44 {
 45         struct alloc_ctx ctx[ALLOC_THREAD_NR];
 46         struct preempted_bpf_ma_op *skel;
 47         pthread_t tid[ALLOC_THREAD_NR];
 48         int i, err;
 49 
 50         skel = preempted_bpf_ma_op__open_and_load();
 51         if (!ASSERT_OK_PTR(skel, "open_and_load"))
 52                 return;
 53 
 54         err = preempted_bpf_ma_op__attach(skel);
 55         if (!ASSERT_OK(err, "attach"))
 56                 goto out;
 57 
 58         for (i = 0; i < ARRAY_SIZE(ctx); i++) {
 59                 struct bpf_program *prog;
 60                 char name[8];
 61 
 62                 snprintf(name, sizeof(name), "test%d", i);
 63                 prog = bpf_object__find_program_by_name(skel->obj, name);
 64                 if (!ASSERT_OK_PTR(prog, "no test prog"))
 65                         goto out;
 66 
 67                 ctx[i].run_err = 0;
 68                 ctx[i].fd = bpf_program__fd(prog);
 69                 ctx[i].nomem_err = &skel->bss->nomem_err;
 70         }
 71 
 72         memset(tid, 0, sizeof(tid));
 73         for (i = 0; i < ARRAY_SIZE(tid); i++) {
 74                 err = pthread_create(&tid[i], NULL, run_alloc_prog, &ctx[i]);
 75                 if (!ASSERT_OK(err, "pthread_create"))
 76                         break;
 77         }
 78 
 79         for (i = 0; i < ARRAY_SIZE(tid); i++) {
 80                 if (!tid[i])
 81                         break;
 82                 pthread_join(tid[i], NULL);
 83                 ASSERT_EQ(ctx[i].run_err, 0, "run prog err");
 84         }
 85 
 86         ASSERT_FALSE(skel->bss->nomem_err, "ENOMEM");
 87 out:
 88         preempted_bpf_ma_op__destroy(skel);
 89 }
 90 

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