test_sysctl.c (35576438591e8d37c7651e6ff56f2e07c7f9615a) | test_sysctl.c (f2e7a6265e5a5e02ee663eda3d0527dd8230b832) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later OR copyleft-next-0.3.1 2/* 3 * proc sysctl test driver 4 * 5 * Copyright (C) 2017 Luis R. Rodriguez <mcgrof@kernel.org> 6 */ 7 8/* --- 16 unchanged lines hidden (view full) --- 25#include <linux/async.h> 26#include <linux/delay.h> 27#include <linux/vmalloc.h> 28 29static int i_zero; 30static int i_one_hundred = 100; 31static int match_int_ok = 1; 32 | 1// SPDX-License-Identifier: GPL-2.0-or-later OR copyleft-next-0.3.1 2/* 3 * proc sysctl test driver 4 * 5 * Copyright (C) 2017 Luis R. Rodriguez <mcgrof@kernel.org> 6 */ 7 8/* --- 16 unchanged lines hidden (view full) --- 25#include <linux/async.h> 26#include <linux/delay.h> 27#include <linux/vmalloc.h> 28 29static int i_zero; 30static int i_one_hundred = 100; 31static int match_int_ok = 1; 32 |
33 34static struct { 35 struct ctl_table_header *test_h_setup_node; 36 struct ctl_table_header *test_h_mnt; 37 struct ctl_table_header *test_h_mnterror; 38} sysctl_test_headers; 39 |
|
33struct test_sysctl_data { 34 int int_0001; 35 int int_0002; 36 int int_0003[4]; 37 38 int boot_int; 39 40 unsigned int uint_0001; --- 107 unchanged lines hidden (view full) --- 148 {.defined = *(int *)SYSCTL_NEG_ONE, .wanted = -1}, 149 }; 150 151 for (i = 0; i < ARRAY_SIZE(match_int); i++) 152 if (match_int[i].defined != match_int[i].wanted) 153 match_int_ok = 0; 154} 155 | 40struct test_sysctl_data { 41 int int_0001; 42 int int_0002; 43 int int_0003[4]; 44 45 int boot_int; 46 47 unsigned int uint_0001; --- 107 unchanged lines hidden (view full) --- 155 {.defined = *(int *)SYSCTL_NEG_ONE, .wanted = -1}, 156 }; 157 158 for (i = 0; i < ARRAY_SIZE(match_int); i++) 159 if (match_int[i].defined != match_int[i].wanted) 160 match_int_ok = 0; 161} 162 |
156static struct ctl_table_header *test_sysctl_header; 157 | |
158static int test_sysctl_setup_node_tests(void) 159{ 160 test_sysctl_calc_match_int_ok(); 161 test_data.bitmap_0001 = kzalloc(SYSCTL_TEST_BITMAP_SIZE/8, GFP_KERNEL); 162 if (!test_data.bitmap_0001) 163 return -ENOMEM; | 163static int test_sysctl_setup_node_tests(void) 164{ 165 test_sysctl_calc_match_int_ok(); 166 test_data.bitmap_0001 = kzalloc(SYSCTL_TEST_BITMAP_SIZE/8, GFP_KERNEL); 167 if (!test_data.bitmap_0001) 168 return -ENOMEM; |
164 test_sysctl_header = register_sysctl("debug/test_sysctl", test_table); 165 if (!test_sysctl_header) { | 169 sysctl_test_headers.test_h_setup_node = register_sysctl("debug/test_sysctl", test_table); 170 if (!sysctl_test_headers.test_h_setup_node) { |
166 kfree(test_data.bitmap_0001); 167 return -ENOMEM; 168 } 169 170 return 0; 171} 172 173/* Used to test that unregister actually removes the directory */ --- 16 unchanged lines hidden (view full) --- 190 test_table_unregister); 191 if (!unregister) 192 return -ENOMEM; 193 194 unregister_sysctl_table(unregister); 195 return 0; 196} 197 | 171 kfree(test_data.bitmap_0001); 172 return -ENOMEM; 173 } 174 175 return 0; 176} 177 178/* Used to test that unregister actually removes the directory */ --- 16 unchanged lines hidden (view full) --- 195 test_table_unregister); 196 if (!unregister) 197 return -ENOMEM; 198 199 unregister_sysctl_table(unregister); 200 return 0; 201} 202 |
203static int test_sysctl_run_register_mount_point(void) 204{ 205 sysctl_test_headers.test_h_mnt 206 = register_sysctl_mount_point("debug/test_sysctl/mnt"); 207 if (!sysctl_test_headers.test_h_mnt) 208 return -ENOMEM; 209 210 sysctl_test_headers.test_h_mnterror 211 = register_sysctl("debug/test_sysctl/mnt/mnt_error", 212 test_table_unregister); 213 /* 214 * Don't check the result.: 215 * If it fails (expected behavior), return 0. 216 * If successful (missbehavior of register mount point), we want to see 217 * mnt_error when we run the sysctl test script 218 */ 219 220 return 0; 221} 222 |
|
198static int __init test_sysctl_init(void) 199{ 200 int err; 201 202 err = test_sysctl_setup_node_tests(); 203 if (err) 204 goto out; 205 206 err = test_sysctl_run_unregister_nested(); | 223static int __init test_sysctl_init(void) 224{ 225 int err; 226 227 err = test_sysctl_setup_node_tests(); 228 if (err) 229 goto out; 230 231 err = test_sysctl_run_unregister_nested(); |
232 if (err) 233 goto out; |
|
207 | 234 |
235 err = test_sysctl_run_register_mount_point(); 236 |
|
208out: 209 return err; 210} 211module_init(test_sysctl_init); 212 213static void __exit test_sysctl_exit(void) 214{ 215 kfree(test_data.bitmap_0001); | 237out: 238 return err; 239} 240module_init(test_sysctl_init); 241 242static void __exit test_sysctl_exit(void) 243{ 244 kfree(test_data.bitmap_0001); |
216 if (test_sysctl_header) 217 unregister_sysctl_table(test_sysctl_header); | 245 if (sysctl_test_headers.test_h_setup_node) 246 unregister_sysctl_table(sysctl_test_headers.test_h_setup_node); 247 if (sysctl_test_headers.test_h_mnt) 248 unregister_sysctl_table(sysctl_test_headers.test_h_mnt); 249 if (sysctl_test_headers.test_h_mnterror) 250 unregister_sysctl_table(sysctl_test_headers.test_h_mnterror); |
218} 219 220module_exit(test_sysctl_exit); 221 222MODULE_AUTHOR("Luis R. Rodriguez <mcgrof@kernel.org>"); 223MODULE_LICENSE("GPL"); | 251} 252 253module_exit(test_sysctl_exit); 254 255MODULE_AUTHOR("Luis R. Rodriguez <mcgrof@kernel.org>"); 256MODULE_LICENSE("GPL"); |