Skip to content

Commit 7777407

Browse files
Joelgranadosmcgrof
authored andcommitted
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>
1 parent 3155523 commit 7777407

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

lib/test_sysctl.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ static struct {
3535
struct ctl_table_header *test_h_setup_node;
3636
struct ctl_table_header *test_h_mnt;
3737
struct ctl_table_header *test_h_mnterror;
38+
struct ctl_table_header *empty_add;
39+
struct ctl_table_header *empty;
3840
} sysctl_test_headers;
3941

4042
struct test_sysctl_data {
@@ -220,6 +222,25 @@ static int test_sysctl_run_register_mount_point(void)
220222
return 0;
221223
}
222224

225+
static struct ctl_table test_table_empty[] = { };
226+
227+
static int test_sysctl_run_register_empty(void)
228+
{
229+
/* Tets that an empty dir can be created */
230+
sysctl_test_headers.empty_add
231+
= register_sysctl("debug/test_sysctl/empty_add", test_table_empty);
232+
if (!sysctl_test_headers.empty_add)
233+
return -ENOMEM;
234+
235+
/* Test that register on top of an empty dir works */
236+
sysctl_test_headers.empty
237+
= register_sysctl("debug/test_sysctl/empty_add/empty", test_table_empty);
238+
if (!sysctl_test_headers.empty)
239+
return -ENOMEM;
240+
241+
return 0;
242+
}
243+
223244
static int __init test_sysctl_init(void)
224245
{
225246
int err;
@@ -233,6 +254,10 @@ static int __init test_sysctl_init(void)
233254
goto out;
234255

235256
err = test_sysctl_run_register_mount_point();
257+
if (err)
258+
goto out;
259+
260+
err = test_sysctl_run_register_empty();
236261

237262
out:
238263
return err;
@@ -248,6 +273,10 @@ static void __exit test_sysctl_exit(void)
248273
unregister_sysctl_table(sysctl_test_headers.test_h_mnt);
249274
if (sysctl_test_headers.test_h_mnterror)
250275
unregister_sysctl_table(sysctl_test_headers.test_h_mnterror);
276+
if (sysctl_test_headers.empty)
277+
unregister_sysctl_table(sysctl_test_headers.empty);
278+
if (sysctl_test_headers.empty_add)
279+
unregister_sysctl_table(sysctl_test_headers.empty_add);
251280
}
252281

253282
module_exit(test_sysctl_exit);

tools/testing/selftests/sysctl/sysctl.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ 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"
3737
ALL_TESTS="$ALL_TESTS 0010:1:1:mnt/mnt_error:0"
38+
ALL_TESTS="$ALL_TESTS 0011:1:1:empty_add:0"
3839

3940
function allow_user_defaults()
4041
{
@@ -828,6 +829,27 @@ sysctl_test_0010()
828829
return 0
829830
}
830831

832+
sysctl_test_0011()
833+
{
834+
TARGET="${SYSCTL}/$(get_test_target 0011)"
835+
echo -n "Testing empty dir handling in ${TARGET} ... "
836+
if [ ! -d ${TARGET} ]; then
837+
echo -e "FAIL\nCould not create ${TARGET}" >&2
838+
rc=1
839+
test_rc
840+
fi
841+
842+
TARGET2="${TARGET}/empty"
843+
if [ ! -d ${TARGET2} ]; then
844+
echo -e "FAIL\nCould not create ${TARGET2}" >&2
845+
rc=1
846+
test_rc
847+
fi
848+
849+
echo "OK"
850+
return 0
851+
}
852+
831853
list_tests()
832854
{
833855
echo "Test ID list:"
@@ -846,6 +868,7 @@ list_tests()
846868
echo "0008 x $(get_test_count 0008) - tests sysctl macro values match"
847869
echo "0009 x $(get_test_count 0009) - tests sysct unregister"
848870
echo "0010 x $(get_test_count 0010) - tests sysct mount point"
871+
echo "0011 x $(get_test_count 0011) - tests empty directories"
849872
}
850873

851874
usage()

0 commit comments

Comments
 (0)