All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Orlov <ivan.orlov0322@gmail.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 1/3] lib: tests: Add test suite init function
Date: Tue, 23 Apr 2024 16:52:43 +0100	[thread overview]
Message-ID: <20240423155245.14541-2-ivan.orlov0322@gmail.com> (raw)
In-Reply-To: <20240423155245.14541-1-ivan.orlov0322@gmail.com>

Allow to define an init function for the test suite. It could help us
to initialize global variable once, and use them in multiple test cases
after the initialization.

For instance, if multiple test cases use the same atomic_t var, it
could be helpful to call ATOMIC_INIT once during the suite
initialization.

Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
---
 include/sbi/sbi_unit_test.h   | 2 ++
 lib/sbi/tests/sbi_unit_test.c | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/include/sbi/sbi_unit_test.h b/include/sbi/sbi_unit_test.h
index c63d900..448c048 100644
--- a/include/sbi/sbi_unit_test.h
+++ b/include/sbi/sbi_unit_test.h
@@ -19,6 +19,7 @@ struct sbiunit_test_case {
 
 struct sbiunit_test_suite {
 	const char *name;
+	void (*init)(void);
 	struct sbiunit_test_case *cases;
 };
 
@@ -34,6 +35,7 @@ struct sbiunit_test_suite {
 #define SBIUNIT_TEST_SUITE(suite_name, cases_arr)		\
 	struct sbiunit_test_suite suite_name = {		\
 		.name = #suite_name,				\
+		.init = NULL,					\
 		.cases = cases_arr				\
 	}
 
diff --git a/lib/sbi/tests/sbi_unit_test.c b/lib/sbi/tests/sbi_unit_test.c
index 1987838..c2a0be6 100644
--- a/lib/sbi/tests/sbi_unit_test.c
+++ b/lib/sbi/tests/sbi_unit_test.c
@@ -17,6 +17,9 @@ static void run_test_suite(struct sbiunit_test_suite *suite)
 
 	sbi_printf("## Running test suite: %s\n", suite->name);
 
+	if (suite->init)
+		suite->init();
+
 	s_case = suite->cases;
 	while (s_case->test_func) {
 		s_case->test_func(s_case);
-- 
2.34.1



  reply	other threads:[~2024-04-23 15:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-23 15:52 [PATCH 0/3] Add two tests and improve SBIUnit Ivan Orlov
2024-04-23 15:52 ` Ivan Orlov [this message]
2024-05-07  6:02   ` [PATCH 1/3] lib: tests: Add test suite init function Anup Patel
2024-04-23 15:52 ` [PATCH 2/3] lib: tests: Add test for atomic_t Ivan Orlov
2024-05-07  6:02   ` Anup Patel
2024-04-23 15:52 ` [PATCH 3/3] lib: tests: Add test for spinlocks Ivan Orlov
2024-05-07  6:02   ` Anup Patel

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=20240423155245.14541-2-ivan.orlov0322@gmail.com \
    --to=ivan.orlov0322@gmail.com \
    --cc=opensbi@lists.infradead.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.