Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sysctl: Add a selftest for handling empty dirs

Basic test to ensure that empty directories can be registered and that
they in turn can serve as a base dir for other registrations.

Add one test to the sysctl selftest module. It first registers an empty
directory under "empty_add" and then uses that as a base to register
another empty dir.
The sysctl bash script then checks that "empty_add" is present and that
there an empty directory within it.

Signed-off-by: Joel Granados <j.granados@samsung.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

authored by

Joel Granados and committed by
Luis Chamberlain
77774077 31555231

+52
+29
lib/test_sysctl.c
··· 35 35 struct ctl_table_header *test_h_setup_node; 36 36 struct ctl_table_header *test_h_mnt; 37 37 struct ctl_table_header *test_h_mnterror; 38 + struct ctl_table_header *empty_add; 39 + struct ctl_table_header *empty; 38 40 } sysctl_test_headers; 39 41 40 42 struct test_sysctl_data { ··· 222 220 return 0; 223 221 } 224 222 223 + static struct ctl_table test_table_empty[] = { }; 224 + 225 + static int test_sysctl_run_register_empty(void) 226 + { 227 + /* Tets that an empty dir can be created */ 228 + sysctl_test_headers.empty_add 229 + = register_sysctl("debug/test_sysctl/empty_add", test_table_empty); 230 + if (!sysctl_test_headers.empty_add) 231 + return -ENOMEM; 232 + 233 + /* Test that register on top of an empty dir works */ 234 + sysctl_test_headers.empty 235 + = register_sysctl("debug/test_sysctl/empty_add/empty", test_table_empty); 236 + if (!sysctl_test_headers.empty) 237 + return -ENOMEM; 238 + 239 + return 0; 240 + } 241 + 225 242 static int __init test_sysctl_init(void) 226 243 { 227 244 int err; ··· 254 233 goto out; 255 234 256 235 err = test_sysctl_run_register_mount_point(); 236 + if (err) 237 + goto out; 238 + 239 + err = test_sysctl_run_register_empty(); 257 240 258 241 out: 259 242 return err; ··· 273 248 unregister_sysctl_table(sysctl_test_headers.test_h_mnt); 274 249 if (sysctl_test_headers.test_h_mnterror) 275 250 unregister_sysctl_table(sysctl_test_headers.test_h_mnterror); 251 + if (sysctl_test_headers.empty) 252 + unregister_sysctl_table(sysctl_test_headers.empty); 253 + if (sysctl_test_headers.empty_add) 254 + unregister_sysctl_table(sysctl_test_headers.empty_add); 276 255 } 277 256 278 257 module_exit(test_sysctl_exit);
+23
tools/testing/selftests/sysctl/sysctl.sh
··· 35 35 ALL_TESTS="$ALL_TESTS 0008:1:1:match_int:1" 36 36 ALL_TESTS="$ALL_TESTS 0009:1:1:unregister_error:0" 37 37 ALL_TESTS="$ALL_TESTS 0010:1:1:mnt/mnt_error:0" 38 + ALL_TESTS="$ALL_TESTS 0011:1:1:empty_add:0" 38 39 39 40 function allow_user_defaults() 40 41 { ··· 829 828 return 0 830 829 } 831 830 831 + sysctl_test_0011() 832 + { 833 + TARGET="${SYSCTL}/$(get_test_target 0011)" 834 + echo -n "Testing empty dir handling in ${TARGET} ... " 835 + if [ ! -d ${TARGET} ]; then 836 + echo -e "FAIL\nCould not create ${TARGET}" >&2 837 + rc=1 838 + test_rc 839 + fi 840 + 841 + TARGET2="${TARGET}/empty" 842 + if [ ! -d ${TARGET2} ]; then 843 + echo -e "FAIL\nCould not create ${TARGET2}" >&2 844 + rc=1 845 + test_rc 846 + fi 847 + 848 + echo "OK" 849 + return 0 850 + } 851 + 832 852 list_tests() 833 853 { 834 854 echo "Test ID list:" ··· 868 846 echo "0008 x $(get_test_count 0008) - tests sysctl macro values match" 869 847 echo "0009 x $(get_test_count 0009) - tests sysct unregister" 870 848 echo "0010 x $(get_test_count 0010) - tests sysct mount point" 849 + echo "0011 x $(get_test_count 0011) - tests empty directories" 871 850 } 872 851 873 852 usage()