Skip to content

Commit f2e7a62

Browse files
Joelgranadosmcgrof
authored andcommitted
test_sysclt: Test for registering a mount point
Test that target gets created by register_sysctl_mount_point and that no additional target can be created "on top" of a permanently empty sysctl table. Create a mount point target (mnt) in the sysctl test driver; try to create another on top of that (mnt_error). Output an error if "mnt_error" is present when we run the sysctl selftests. Signed-off-by: Joel Granados <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent ec866cc commit f2e7a62

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

lib/test_sysctl.c

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ static int i_zero;
3030
static int i_one_hundred = 100;
3131
static int match_int_ok = 1;
3232

33+
34+
static 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+
3340
struct test_sysctl_data {
3441
int int_0001;
3542
int int_0002;
@@ -153,16 +160,14 @@ static void test_sysctl_calc_match_int_ok(void)
153160
match_int_ok = 0;
154161
}
155162

156-
static struct ctl_table_header *test_sysctl_header;
157-
158163
static int test_sysctl_setup_node_tests(void)
159164
{
160165
test_sysctl_calc_match_int_ok();
161166
test_data.bitmap_0001 = kzalloc(SYSCTL_TEST_BITMAP_SIZE/8, GFP_KERNEL);
162167
if (!test_data.bitmap_0001)
163168
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) {
166171
kfree(test_data.bitmap_0001);
167172
return -ENOMEM;
168173
}
@@ -195,6 +200,26 @@ static int test_sysctl_run_unregister_nested(void)
195200
return 0;
196201
}
197202

203+
static 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+
198223
static int __init test_sysctl_init(void)
199224
{
200225
int err;
@@ -204,6 +229,10 @@ static int __init test_sysctl_init(void)
204229
goto out;
205230

206231
err = test_sysctl_run_unregister_nested();
232+
if (err)
233+
goto out;
234+
235+
err = test_sysctl_run_register_mount_point();
207236

208237
out:
209238
return err;
@@ -213,8 +242,12 @@ module_init(test_sysctl_init);
213242
static void __exit test_sysctl_exit(void)
214243
{
215244
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);
218251
}
219252

220253
module_exit(test_sysctl_exit);

tools/testing/selftests/sysctl/sysctl.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ALL_TESTS="$ALL_TESTS 0006:50:1:bitmap_0001:1"
3434
ALL_TESTS="$ALL_TESTS 0007:1:1:boot_int:1"
3535
ALL_TESTS="$ALL_TESTS 0008:1:1:match_int:1"
3636
ALL_TESTS="$ALL_TESTS 0009:1:1:unregister_error:0"
37+
ALL_TESTS="$ALL_TESTS 0010:1:1:mnt/mnt_error:0"
3738

3839
function allow_user_defaults()
3940
{
@@ -813,6 +814,20 @@ sysctl_test_0009()
813814
return 0
814815
}
815816

817+
sysctl_test_0010()
818+
{
819+
TARGET="${SYSCTL}/$(get_test_target 0010)"
820+
echo -n "Testing that $TARGET was not created ..."
821+
if [ -d $TARGET ]; then
822+
echo "TEST FAILED"
823+
rc=1
824+
test_rc
825+
fi
826+
827+
echo "ok"
828+
return 0
829+
}
830+
816831
list_tests()
817832
{
818833
echo "Test ID list:"
@@ -830,6 +845,7 @@ list_tests()
830845
echo "0007 x $(get_test_count 0007) - tests setting sysctl from kernel boot param"
831846
echo "0008 x $(get_test_count 0008) - tests sysctl macro values match"
832847
echo "0009 x $(get_test_count 0009) - tests sysct unregister"
848+
echo "0010 x $(get_test_count 0010) - tests sysct mount point"
833849
}
834850

835851
usage()

0 commit comments

Comments
 (0)