From: Daniel Latypov <dlatypov@google.com>
To: dlatypov@google.com
Cc: alan.maguire@oracle.com, brendanhiggins@google.com,
davidgow@google.com, keescook@chromium.org,
kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, mcgrof@kernel.org,
sboyd@kernel.org, skhan@linuxfoundation.org
Subject: [RFC v2 03/12] kunit: test: add concept of post conditions
Date: Mon, 12 Oct 2020 15:20:41 -0700 [thread overview]
Message-ID: <20201012222050.999431-4-dlatypov@google.com> (raw)
In-Reply-To: <20201012222050.999431-1-dlatypov@google.com>
From: Brendan Higgins <brendanhiggins@google.com>
Add a way to specify that certain conditions must be met at the end of a
test case.
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Daniel Latypov <dlatypov@google.com>
---
include/kunit/test.h | 6 ++++++
lib/kunit/test.c | 11 +++++++++++
2 files changed, 17 insertions(+)
diff --git a/include/kunit/test.h b/include/kunit/test.h
index 687782fa44d9..0eb3abb00da4 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -190,6 +190,11 @@ struct kunit_suite {
char *log;
};
+struct kunit_post_condition {
+ struct list_head node;
+ void (*validate)(struct kunit_post_condition *condition);
+};
+
/**
* struct kunit - represents a running instance of a test.
*
@@ -223,6 +228,7 @@ struct kunit {
* protect it with some type of lock.
*/
struct list_head resources; /* Protected by lock. */
+ struct list_head post_conditions;
};
void kunit_init_test(struct kunit *test, const char *name, char *log);
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index 670d1cc9c105..4e8c74c89073 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -228,6 +228,7 @@ void kunit_init_test(struct kunit *test, const char *name, char *log)
{
spin_lock_init(&test->lock);
INIT_LIST_HEAD(&test->resources);
+ INIT_LIST_HEAD(&test->post_conditions);
test->name = name;
test->log = log;
if (test->log)
@@ -269,6 +270,16 @@ static void kunit_case_internal_cleanup(struct kunit *test)
static void kunit_run_case_cleanup(struct kunit *test,
struct kunit_suite *suite)
{
+ struct kunit_post_condition *condition, *condition_safe;
+
+ list_for_each_entry_safe(condition,
+ condition_safe,
+ &test->post_conditions,
+ node) {
+ condition->validate(condition);
+ list_del(&condition->node);
+ }
+
if (suite->exit)
suite->exit(test);
--
2.28.0.1011.ga647a8990f-goog
next prev parent reply other threads:[~2020-10-12 22:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-12 22:20 [RFC v2 00/12] kunit: introduce class mocking support Daniel Latypov
2020-10-12 22:20 ` [RFC v2 01/12] Revert "kunit: move string-stream.h to lib/kunit" Daniel Latypov
2020-10-12 22:20 ` [RFC v2 02/12] kunit: test: add kunit_stream a std::stream like logger Daniel Latypov
2020-10-12 22:20 ` Daniel Latypov [this message]
2020-10-12 22:20 ` [RFC v2 04/12] checkpatch: add support for struct MOCK(foo) syntax Daniel Latypov
2020-10-12 22:20 ` [RFC v2 05/12] kunit: mock: add parameter list manipulation macros Daniel Latypov
2020-10-12 22:20 ` [RFC v2 06/12] kunit: expose kunit_set_failure() for use by mocking Daniel Latypov
2020-10-12 22:20 ` [RFC v2 07/12] kunit: mock: add internal mock infrastructure Daniel Latypov
2020-10-12 22:20 ` [RFC v2 08/12] kunit: mock: add basic matchers and actions Daniel Latypov
2020-10-12 22:20 ` [RFC v2 09/12] kunit: mock: add macro machinery to pick correct format args Daniel Latypov
2020-10-12 22:20 ` [RFC v2 10/12] kunit: mock: add class mocking support Daniel Latypov
2020-10-12 22:20 ` [RFC v2 11/12] kunit: mock: add struct param matcher Daniel Latypov
2020-10-12 22:20 ` [RFC v2 12/12] kunit: mock: implement nice, strict and naggy mock distinctions Daniel Latypov
2020-11-02 18:00 ` [RFC v2 00/12] kunit: introduce class mocking support Brendan Higgins
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=20201012222050.999431-4-dlatypov@google.com \
--to=dlatypov@google.com \
--cc=alan.maguire@oracle.com \
--cc=brendanhiggins@google.com \
--cc=davidgow@google.com \
--cc=keescook@chromium.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=sboyd@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;
as well as URLs for NNTP newsgroup(s).