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

TOMOYO Linux Cross Reference
Linux/lib/test_ref_tracker.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-only
  2 /*
  3  * Reference tracker self test.
  4  *
  5  * Copyright (c) 2021 Eric Dumazet <edumazet@google.com>
  6  */
  7 #include <linux/init.h>
  8 #include <linux/module.h>
  9 #include <linux/delay.h>
 10 #include <linux/ref_tracker.h>
 11 #include <linux/slab.h>
 12 #include <linux/timer.h>
 13 
 14 static struct ref_tracker_dir ref_dir;
 15 static struct ref_tracker *tracker[20];
 16 
 17 #define TRT_ALLOC(X) static noinline void                               \
 18         alloctest_ref_tracker_alloc##X(struct ref_tracker_dir *dir,     \
 19                                     struct ref_tracker **trackerp)      \
 20         {                                                               \
 21                 ref_tracker_alloc(dir, trackerp, GFP_KERNEL);           \
 22         }
 23 
 24 TRT_ALLOC(1)
 25 TRT_ALLOC(2)
 26 TRT_ALLOC(3)
 27 TRT_ALLOC(4)
 28 TRT_ALLOC(5)
 29 TRT_ALLOC(6)
 30 TRT_ALLOC(7)
 31 TRT_ALLOC(8)
 32 TRT_ALLOC(9)
 33 TRT_ALLOC(10)
 34 TRT_ALLOC(11)
 35 TRT_ALLOC(12)
 36 TRT_ALLOC(13)
 37 TRT_ALLOC(14)
 38 TRT_ALLOC(15)
 39 TRT_ALLOC(16)
 40 TRT_ALLOC(17)
 41 TRT_ALLOC(18)
 42 TRT_ALLOC(19)
 43 
 44 #undef TRT_ALLOC
 45 
 46 static noinline void
 47 alloctest_ref_tracker_free(struct ref_tracker_dir *dir,
 48                            struct ref_tracker **trackerp)
 49 {
 50         ref_tracker_free(dir, trackerp);
 51 }
 52 
 53 
 54 static struct timer_list test_ref_tracker_timer;
 55 static atomic_t test_ref_timer_done = ATOMIC_INIT(0);
 56 
 57 static void test_ref_tracker_timer_func(struct timer_list *t)
 58 {
 59         ref_tracker_alloc(&ref_dir, &tracker[0], GFP_ATOMIC);
 60         atomic_set(&test_ref_timer_done, 1);
 61 }
 62 
 63 static int __init test_ref_tracker_init(void)
 64 {
 65         int i;
 66 
 67         ref_tracker_dir_init(&ref_dir, 100, "selftest");
 68 
 69         timer_setup(&test_ref_tracker_timer, test_ref_tracker_timer_func, 0);
 70         mod_timer(&test_ref_tracker_timer, jiffies + 1);
 71 
 72         alloctest_ref_tracker_alloc1(&ref_dir, &tracker[1]);
 73         alloctest_ref_tracker_alloc2(&ref_dir, &tracker[2]);
 74         alloctest_ref_tracker_alloc3(&ref_dir, &tracker[3]);
 75         alloctest_ref_tracker_alloc4(&ref_dir, &tracker[4]);
 76         alloctest_ref_tracker_alloc5(&ref_dir, &tracker[5]);
 77         alloctest_ref_tracker_alloc6(&ref_dir, &tracker[6]);
 78         alloctest_ref_tracker_alloc7(&ref_dir, &tracker[7]);
 79         alloctest_ref_tracker_alloc8(&ref_dir, &tracker[8]);
 80         alloctest_ref_tracker_alloc9(&ref_dir, &tracker[9]);
 81         alloctest_ref_tracker_alloc10(&ref_dir, &tracker[10]);
 82         alloctest_ref_tracker_alloc11(&ref_dir, &tracker[11]);
 83         alloctest_ref_tracker_alloc12(&ref_dir, &tracker[12]);
 84         alloctest_ref_tracker_alloc13(&ref_dir, &tracker[13]);
 85         alloctest_ref_tracker_alloc14(&ref_dir, &tracker[14]);
 86         alloctest_ref_tracker_alloc15(&ref_dir, &tracker[15]);
 87         alloctest_ref_tracker_alloc16(&ref_dir, &tracker[16]);
 88         alloctest_ref_tracker_alloc17(&ref_dir, &tracker[17]);
 89         alloctest_ref_tracker_alloc18(&ref_dir, &tracker[18]);
 90         alloctest_ref_tracker_alloc19(&ref_dir, &tracker[19]);
 91 
 92         /* free all trackers but first 0 and 1. */
 93         for (i = 2; i < ARRAY_SIZE(tracker); i++)
 94                 alloctest_ref_tracker_free(&ref_dir, &tracker[i]);
 95 
 96         /* Attempt to free an already freed tracker. */
 97         alloctest_ref_tracker_free(&ref_dir, &tracker[2]);
 98 
 99         while (!atomic_read(&test_ref_timer_done))
100                 msleep(1);
101 
102         /* This should warn about tracker[0] & tracker[1] being not freed. */
103         ref_tracker_dir_exit(&ref_dir);
104 
105         return 0;
106 }
107 
108 static void __exit test_ref_tracker_exit(void)
109 {
110 }
111 
112 module_init(test_ref_tracker_init);
113 module_exit(test_ref_tracker_exit);
114 
115 MODULE_DESCRIPTION("Reference tracker self test");
116 MODULE_LICENSE("GPL v2");
117 

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