All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rae Moar <rmoar@google.com>
To: shuah@kernel.org, davidgow@google.com, dlatypov@google.com,
	brendan.higgins@linux.dev, sadiyakazi@google.com
Cc: keescook@chromium.org, arnd@arndb.de,
	linux-kselftest@vger.kernel.org, linux-arch@vger.kernel.org,
	kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org,
	Rae Moar <rmoar@google.com>
Subject: [PATCH v3 3/6] kunit: add example suite to test init suites
Date: Mon,  4 Dec 2023 22:19:28 +0000	[thread overview]
Message-ID: <20231204221932.1465004-3-rmoar@google.com> (raw)
In-Reply-To: <20231204221932.1465004-1-rmoar@google.com>

Add example_init_test_suite to allow for testing the feature of running
test suites marked as init to indicate they use init data and/or
functions.

This suite should always pass and uses a simple init function.

This suite can also be used to test the is_init attribute introduced in
the next patch.

Signed-off-by: Rae Moar <rmoar@google.com>
---
 lib/kunit/kunit-example-test.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c
index 6bb5c2ef6696..262a68a59800 100644
--- a/lib/kunit/kunit-example-test.c
+++ b/lib/kunit/kunit-example-test.c
@@ -287,4 +287,33 @@ static struct kunit_suite example_test_suite = {
  */
 kunit_test_suites(&example_test_suite);
 
+static int __init init_add(int x, int y)
+{
+	return (x + y);
+}
+
+/*
+ * This test should always pass. Can be used to test init suites.
+ */
+static void example_init_test(struct kunit *test)
+{
+	KUNIT_EXPECT_EQ(test, init_add(1, 1), 2);
+}
+
+static struct kunit_case example_init_test_cases[] = {
+	KUNIT_CASE(example_init_test),
+	{}
+};
+
+static struct kunit_suite example_init_test_suite = {
+	.name = "example_init",
+	.test_cases = example_init_test_cases,
+};
+
+/*
+ * This registers the test suite and marks the suite as using init data
+ * and/or functions.
+ */
+kunit_test_init_section_suites(&example_init_test_suite);
+
 MODULE_LICENSE("GPL v2");
-- 
2.43.0.rc2.451.g8631bc7472-goog


  parent reply	other threads:[~2023-12-04 22:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-04 22:19 [PATCH v3 1/6] kunit: move KUNIT_TABLE out of INIT_DATA Rae Moar
2023-12-04 22:19 ` [PATCH v3 2/6] kunit: add KUNIT_INIT_TABLE to init linker section Rae Moar
2023-12-09  7:57   ` David Gow
2023-12-04 22:19 ` Rae Moar [this message]
2023-12-09  7:57   ` [PATCH v3 3/6] kunit: add example suite to test init suites David Gow
2023-12-04 22:19 ` [PATCH v3 4/6] kunit: add is_init test attribute Rae Moar
2023-12-09  7:57   ` David Gow
2023-12-11 22:24     ` Rae Moar
2023-12-04 22:19 ` [PATCH v3 5/6] kunit: add ability to run tests after boot using debugfs Rae Moar
2023-12-09  7:57   ` David Gow
2023-12-04 22:19 ` [PATCH v3 6/6] Documentation: Add debugfs docs with run after boot Rae Moar
2023-12-09  7:57   ` David Gow
2023-12-11 22:16     ` Rae Moar
2023-12-09  7:48 ` [PATCH v3 1/6] kunit: move KUNIT_TABLE out of INIT_DATA David Gow
2023-12-11 22:08   ` Rae Moar

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=20231204221932.1465004-3-rmoar@google.com \
    --to=rmoar@google.com \
    --cc=arnd@arndb.de \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=dlatypov@google.com \
    --cc=keescook@chromium.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=sadiyakazi@google.com \
    --cc=shuah@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.