Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Rae Moar <rmoar@google.com>
To: brendan.higgins@linux.dev, davidgow@google.com, dlatypov@google.com
Cc: skhan@linuxfoundation.org, kunit-dev@googlegroups.com,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	Rae Moar <rmoar@google.com>
Subject: [PATCH 2/2] kunit: fix kunit_executor_test to allow for run after boot
Date: Tue, 15 Aug 2023 19:45:41 +0000	[thread overview]
Message-ID: <20230815194541.497115-2-rmoar@google.com> (raw)
In-Reply-To: <20230815194541.497115-1-rmoar@google.com>

Change implementation of executor tests to allow for use of new run
after boot feature.

Without this fix, the tests will cause a kernel crash if run after boot
due to permissions issue in accessing constant strings.

Signed-off-by: Rae Moar <rmoar@google.com>
---
 lib/kunit/executor_test.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c
index 4084071d0eb5..66a02291892d 100644
--- a/lib/kunit/executor_test.c
+++ b/lib/kunit/executor_test.c
@@ -119,9 +119,12 @@ static void parse_filter_attr_test(struct kunit *test)
 {
 	int j, filter_count;
 	struct kunit_attr_filter *parsed_filters;
-	char *filters = "speed>slow, module!=example";
+	int max_char = 30;
+	char *filters = kunit_kzalloc(test, sizeof(char) * max_char, GFP_KERNEL);
 	int err = 0;
 
+	strscpy(filters, "speed>slow, module!=example", max_char);
+
 	filter_count = kunit_get_filter_count(filters);
 	KUNIT_EXPECT_EQ(test, filter_count, 2);
 
@@ -154,6 +157,8 @@ static void filter_attr_test(struct kunit *test)
 		.start = subsuite, .end = &subsuite[2],
 	};
 	struct kunit_suite_set got;
+	int max_char = 30;
+	char *filter = kunit_kzalloc(test, sizeof(char) * max_char, GFP_KERNEL);
 	int err = 0;
 
 	subsuite[0] = alloc_fake_suite(test, "normal_suite", dummy_attr_test_cases);
@@ -168,7 +173,8 @@ static void filter_attr_test(struct kunit *test)
 	 * attribute is unset and thus, the filtering is based on the parent attribute
 	 * of slow.
 	 */
-	got = kunit_filter_suites(&suite_set, NULL, "speed>slow", NULL, &err);
+	strscpy(filter, "speed>slow", max_char);
+	got = kunit_filter_suites(&suite_set, NULL, filter, NULL, &err);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, got.start);
 	KUNIT_ASSERT_EQ(test, err, 0);
 	kfree_at_end(test, got.start);
@@ -191,12 +197,15 @@ static void filter_attr_empty_test(struct kunit *test)
 		.start = subsuite, .end = &subsuite[2],
 	};
 	struct kunit_suite_set got;
+	int max_char = 30;
+	char *filter = kunit_kzalloc(test, sizeof(char) * max_char, GFP_KERNEL);
 	int err = 0;
 
 	subsuite[0] = alloc_fake_suite(test, "suite1", dummy_attr_test_cases);
 	subsuite[1] = alloc_fake_suite(test, "suite2", dummy_attr_test_cases);
 
-	got = kunit_filter_suites(&suite_set, NULL, "module!=dummy", NULL, &err);
+	strscpy(filter, "module!=dummy", max_char);
+	got = kunit_filter_suites(&suite_set, NULL, filter, NULL, &err);
 	KUNIT_ASSERT_EQ(test, err, 0);
 	kfree_at_end(test, got.start); /* just in case */
 
@@ -211,12 +220,15 @@ static void filter_attr_skip_test(struct kunit *test)
 		.start = subsuite, .end = &subsuite[1],
 	};
 	struct kunit_suite_set got;
+	int max_char = 30;
+	char *filter = kunit_kzalloc(test, sizeof(char) * max_char, GFP_KERNEL);
 	int err = 0;
 
 	subsuite[0] = alloc_fake_suite(test, "suite", dummy_attr_test_cases);
 
 	/* Want: suite(slow, normal), NULL -> suite(slow with SKIP, normal), NULL */
-	got = kunit_filter_suites(&suite_set, NULL, "speed>slow", "skip", &err);
+	strscpy(filter, "speed>slow", max_char);
+	got = kunit_filter_suites(&suite_set, NULL, filter, "skip", &err);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, got.start);
 	KUNIT_ASSERT_EQ(test, err, 0);
 	kfree_at_end(test, got.start);
-- 
2.41.0.694.ge786442a9b-goog


      reply	other threads:[~2023-08-15 19:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-15 19:45 [PATCH 1/2] kunit: add ability to run tests after boot using debugfs Rae Moar
2023-08-15 19:45 ` Rae Moar [this message]

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=20230815194541.497115-2-rmoar@google.com \
    --to=rmoar@google.com \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=dlatypov@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=skhan@linuxfoundation.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