From: Joel Granados <j.granados@samsung.com>
To: <mcgrof@kernel.org>
Cc: <linux-kselftest@vger.kernel.org>,
<linux-fsdevel@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Joel Granados <j.granados@samsung.com>
Subject: [PATCH v2 6/8] test_sysclt: Test for registering a mount point
Date: Fri, 16 Jun 2023 10:59:20 +0200 [thread overview]
Message-ID: <20230616085922.3066990-7-j.granados@samsung.com> (raw)
In-Reply-To: <20230616085922.3066990-1-j.granados@samsung.com>
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 <j.granados@samsung.com>
---
lib/test_sysctl.c | 45 ++++++++++++++++++++----
tools/testing/selftests/sysctl/sysctl.sh | 16 +++++++++
2 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c
index 555244687443..8036aa91a1cb 100644
--- a/lib/test_sysctl.c
+++ b/lib/test_sysctl.c
@@ -30,6 +30,13 @@ static int i_zero;
static int i_one_hundred = 100;
static int match_int_ok = 1;
+
+static struct {
+ struct ctl_table_header *test_h_setup_node;
+ struct ctl_table_header *test_h_mnt;
+ struct ctl_table_header *test_h_mnterror;
+} sysctl_test_headers;
+
struct test_sysctl_data {
int int_0001;
int int_0002;
@@ -153,16 +160,14 @@ static void test_sysctl_calc_match_int_ok(void)
match_int_ok = 0;
}
-static struct ctl_table_header *test_sysctl_header;
-
static int test_sysctl_setup_node_tests(void)
{
test_sysctl_calc_match_int_ok();
test_data.bitmap_0001 = kzalloc(SYSCTL_TEST_BITMAP_SIZE/8, GFP_KERNEL);
if (!test_data.bitmap_0001)
return -ENOMEM;
- test_sysctl_header = register_sysctl("debug/test_sysctl", test_table);
- if (!test_sysctl_header) {
+ sysctl_test_headers.test_h_setup_node = register_sysctl("debug/test_sysctl", test_table);
+ if (!sysctl_test_headers.test_h_setup_node) {
kfree(test_data.bitmap_0001);
return -ENOMEM;
}
@@ -195,6 +200,26 @@ static int test_sysctl_run_unregister_nested(void)
return 0;
}
+static int test_sysctl_run_register_mount_point(void)
+{
+ sysctl_test_headers.test_h_mnt
+ = register_sysctl_mount_point("debug/test_sysctl/mnt");
+ if (!sysctl_test_headers.test_h_mnt)
+ return -ENOMEM;
+
+ sysctl_test_headers.test_h_mnterror
+ = register_sysctl("debug/test_sysctl/mnt/mnt_error",
+ test_table_unregister);
+ /*
+ * Don't check the result.:
+ * If it fails (expected behavior), return 0.
+ * If successful (missbehavior of register mount point), we want to see
+ * mnt_error when we run the sysctl test script
+ */
+
+ return 0;
+}
+
static int __init test_sysctl_init(void)
{
int err;
@@ -204,6 +229,10 @@ static int __init test_sysctl_init(void)
goto out;
err = test_sysctl_run_unregister_nested();
+ if (err)
+ goto out;
+
+ err = test_sysctl_run_register_mount_point();
out:
return err;
@@ -213,8 +242,12 @@ module_init(test_sysctl_init);
static void __exit test_sysctl_exit(void)
{
kfree(test_data.bitmap_0001);
- if (test_sysctl_header)
- unregister_sysctl_table(test_sysctl_header);
+ if (sysctl_test_headers.test_h_setup_node)
+ unregister_sysctl_table(sysctl_test_headers.test_h_setup_node);
+ if (sysctl_test_headers.test_h_mnt)
+ unregister_sysctl_table(sysctl_test_headers.test_h_mnt);
+ if (sysctl_test_headers.test_h_mnterror)
+ unregister_sysctl_table(sysctl_test_headers.test_h_mnterror);
}
module_exit(test_sysctl_exit);
diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh
index 9c0e9711138b..444b2befda82 100755
--- a/tools/testing/selftests/sysctl/sysctl.sh
+++ b/tools/testing/selftests/sysctl/sysctl.sh
@@ -34,6 +34,7 @@ ALL_TESTS="$ALL_TESTS 0006:50:1:bitmap_0001:1"
ALL_TESTS="$ALL_TESTS 0007:1:1:boot_int:1"
ALL_TESTS="$ALL_TESTS 0008:1:1:match_int:1"
ALL_TESTS="$ALL_TESTS 0009:1:1:unregister_error:0"
+ALL_TESTS="$ALL_TESTS 0010:1:1:mnt/mnt_error:0"
function allow_user_defaults()
{
@@ -813,6 +814,20 @@ sysctl_test_0009()
return 0
}
+sysctl_test_0010()
+{
+ TARGET="${SYSCTL}/$(get_test_target 0010)"
+ echo -n "Testing that $TARGET was not created ..."
+ if [ -d $TARGET ]; then
+ echo "TEST FAILED"
+ rc=1
+ test_rc
+ fi
+
+ echo "ok"
+ return 0
+}
+
list_tests()
{
echo "Test ID list:"
@@ -830,6 +845,7 @@ list_tests()
echo "0007 x $(get_test_count 0007) - tests setting sysctl from kernel boot param"
echo "0008 x $(get_test_count 0008) - tests sysctl macro values match"
echo "0009 x $(get_test_count 0009) - tests sysct unregister"
+ echo "0010 x $(get_test_count 0010) - tests sysct mount point"
}
usage()
--
2.30.2
next prev parent reply other threads:[~2023-06-16 9:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20230616085926eucas1p10709e25a4c0246ed2b22da602f919b4e@eucas1p1.samsung.com>
2023-06-16 8:59 ` [PATCH v2 0/8] Remove child from struct ctl_table Joel Granados
[not found] ` <CGME20230616085927eucas1p265c6e3512e3102a7df507da9d3f1f094@eucas1p2.samsung.com>
2023-06-16 8:59 ` [PATCH v2 1/8] parport: plug a sysctl register leak Joel Granados
[not found] ` <CGME20230616085930eucas1p2d1b7ee012df532b3dcf15f96cd2f8c18@eucas1p2.samsung.com>
2023-06-16 8:59 ` [PATCH v2 2/8] test_sysctl: Fix test metadata getters Joel Granados
[not found] ` <CGME20230616085932eucas1p1d3d120da7944fc06d714035043697e4d@eucas1p1.samsung.com>
2023-06-16 8:59 ` [PATCH v2 3/8] test_sysctl: Group node sysctl test under one func Joel Granados
[not found] ` <CGME20230616085935eucas1p2439375978f0ee33afd6310a9f8c5d07a@eucas1p2.samsung.com>
2023-06-16 8:59 ` [PATCH v2 4/8] test_sysctl: Add an unregister sysctl test Joel Granados
[not found] ` <CGME20230616085937eucas1p2128b2ddb3c01c887a606f376de850767@eucas1p2.samsung.com>
2023-06-16 8:59 ` [PATCH v2 5/8] test_sysctl: Add an option to prevent test skip Joel Granados
[not found] ` <CGME20230616085939eucas1p24e5c916a261653ce64bb65c7d12d2830@eucas1p2.samsung.com>
2023-06-16 8:59 ` Joel Granados [this message]
[not found] ` <CGME20230616085941eucas1p152b54db1511bfdd1afab32621aec847e@eucas1p1.samsung.com>
2023-06-16 8:59 ` [PATCH v2 7/8] sysctl: Remove debugging dump_stack Joel Granados
[not found] ` <CGME20230616085944eucas1p14e8491c53f5390064035de1ffb354c7a@eucas1p1.samsung.com>
2023-06-16 8:59 ` [PATCH v2 8/8] sysctl: replace child with an enumeration Joel Granados
2023-06-18 9:33 ` [PATCH v2 0/8] Remove child from struct ctl_table Luis Chamberlain
2023-06-19 7:32 ` Joel Granados
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230616085922.3066990-7-j.granados@samsung.com \
--to=j.granados@samsung.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mcgrof@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®