File tree Expand file tree Collapse file tree
tools/testing/selftests/sysctl Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -170,12 +170,42 @@ static int test_sysctl_setup_node_tests(void)
170170 return 0 ;
171171}
172172
173+ /* Used to test that unregister actually removes the directory */
174+ static struct ctl_table test_table_unregister [] = {
175+ {
176+ .procname = "unregister_error" ,
177+ .data = & test_data .int_0001 ,
178+ .maxlen = sizeof (int ),
179+ .mode = 0644 ,
180+ .proc_handler = proc_dointvec_minmax ,
181+ },
182+ {}
183+ };
184+
185+ static int test_sysctl_run_unregister_nested (void )
186+ {
187+ struct ctl_table_header * unregister ;
188+
189+ unregister = register_sysctl ("debug/test_sysctl/unregister_error" ,
190+ test_table_unregister );
191+ if (!unregister )
192+ return - ENOMEM ;
193+
194+ unregister_sysctl_table (unregister );
195+ return 0 ;
196+ }
197+
173198static int __init test_sysctl_init (void )
174199{
175200 int err ;
176201
177202 err = test_sysctl_setup_node_tests ();
203+ if (err )
204+ goto out ;
205+
206+ err = test_sysctl_run_unregister_nested ();
178207
208+ out :
179209 return err ;
180210}
181211module_init (test_sysctl_init );
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ ALL_TESTS="$ALL_TESTS 0005:3:1:int_0003"
3131ALL_TESTS=" $ALL_TESTS 0006:50:1:bitmap_0001"
3232ALL_TESTS=" $ALL_TESTS 0007:1:1:boot_int"
3333ALL_TESTS=" $ALL_TESTS 0008:1:1:match_int"
34+ ALL_TESTS=" $ALL_TESTS 0009:1:1:unregister_error"
3435
3536function allow_user_defaults()
3637{
@@ -797,6 +798,20 @@ sysctl_test_0008()
797798 return 0
798799}
799800
801+ sysctl_test_0009 ()
802+ {
803+ TARGET=" ${SYSCTL} /$( get_test_target 0009) "
804+ echo -n " Testing if $TARGET unregistered correctly ..."
805+ if [ -d $TARGET ]; then
806+ echo " TEST FAILED"
807+ rc=1
808+ test_rc
809+ fi
810+
811+ echo " ok"
812+ return 0
813+ }
814+
800815list_tests ()
801816{
802817 echo " Test ID list:"
@@ -813,6 +828,7 @@ list_tests()
813828 echo " 0006 x $( get_test_count 0006) - tests proc_do_large_bitmap()"
814829 echo " 0007 x $( get_test_count 0007) - tests setting sysctl from kernel boot param"
815830 echo " 0008 x $( get_test_count 0008) - tests sysctl macro values match"
831+ echo " 0009 x $( get_test_count 0009) - tests sysct unregister"
816832}
817833
818834usage ()
You can’t perform that action at this time.
0 commit comments