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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/timer_mim.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) 2021 Facebook */
  3 #include <test_progs.h>
  4 #include "timer_mim.skel.h"
  5 #include "timer_mim_reject.skel.h"
  6 
  7 static int timer_mim(struct timer_mim *timer_skel)
  8 {
  9         __u64 cnt1, cnt2;
 10         int err, prog_fd, key1 = 1;
 11         LIBBPF_OPTS(bpf_test_run_opts, topts);
 12 
 13         err = timer_mim__attach(timer_skel);
 14         if (!ASSERT_OK(err, "timer_attach"))
 15                 return err;
 16 
 17         prog_fd = bpf_program__fd(timer_skel->progs.test1);
 18         err = bpf_prog_test_run_opts(prog_fd, &topts);
 19         ASSERT_OK(err, "test_run");
 20         ASSERT_EQ(topts.retval, 0, "test_run");
 21         timer_mim__detach(timer_skel);
 22 
 23         /* check that timer_cb[12] are incrementing 'cnt' */
 24         cnt1 = READ_ONCE(timer_skel->bss->cnt);
 25         for (int i = 0; i < 100; i++) {
 26                 cnt2 = READ_ONCE(timer_skel->bss->cnt);
 27                 if (cnt2 != cnt1)
 28                         break;
 29                 usleep(200); /* 100 times more than interval */
 30         }
 31         ASSERT_GT(cnt2, cnt1, "cnt");
 32 
 33         ASSERT_EQ(timer_skel->bss->err, 0, "err");
 34         /* check that code paths completed */
 35         ASSERT_EQ(timer_skel->bss->ok, 1 | 2, "ok");
 36 
 37         close(bpf_map__fd(timer_skel->maps.inner_htab));
 38         err = bpf_map__delete_elem(timer_skel->maps.outer_arr, &key1, sizeof(key1), 0);
 39         ASSERT_EQ(err, 0, "delete inner map");
 40 
 41         /* check that timer_cb[12] are no longer running */
 42         cnt1 = READ_ONCE(timer_skel->bss->cnt);
 43         for (int i = 0; i < 100; i++) {
 44                 usleep(200); /* 100 times more than interval */
 45                 cnt2 = READ_ONCE(timer_skel->bss->cnt);
 46                 if (cnt2 == cnt1)
 47                         break;
 48         }
 49         ASSERT_EQ(cnt2, cnt1, "cnt");
 50 
 51         return 0;
 52 }
 53 
 54 void serial_test_timer_mim(void)
 55 {
 56         struct timer_mim_reject *timer_reject_skel = NULL;
 57         libbpf_print_fn_t old_print_fn = NULL;
 58         struct timer_mim *timer_skel = NULL;
 59         int err;
 60 
 61         old_print_fn = libbpf_set_print(NULL);
 62         timer_reject_skel = timer_mim_reject__open_and_load();
 63         libbpf_set_print(old_print_fn);
 64         if (!ASSERT_ERR_PTR(timer_reject_skel, "timer_reject_skel_load"))
 65                 goto cleanup;
 66 
 67         timer_skel = timer_mim__open_and_load();
 68         if (!ASSERT_OK_PTR(timer_skel, "timer_skel_load"))
 69                 goto cleanup;
 70 
 71         err = timer_mim(timer_skel);
 72         ASSERT_OK(err, "timer_mim");
 73 cleanup:
 74         timer_mim__destroy(timer_skel);
 75         timer_mim_reject__destroy(timer_reject_skel);
 76 }
 77 

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