kunit: test: added concept of post conditions
Adds a way to specify that certain conditions must be met at the end of
a test case.
Change-Id: I4f90a68bbedcbb71e2fe7a0353d22885f430f54f
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
diff --git a/include/test/test.h b/include/test/test.h
index 96bdef04..d68b7f0 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -145,6 +145,11 @@ struct test_initcall {
void (*exit)(struct test_initcall *this);
};
+struct test_post_condition {
+ struct list_head node;
+ void (*validate)(struct test_post_condition *condition);
+};
+
/**
* struct test - represents a running instance of a test.
* @priv: for user to store arbitrary data. Commonly used to pass data created
@@ -159,6 +164,7 @@ struct test {
void *priv;
/* private: internal use only. */
struct list_head resources;
+ struct list_head post_conditions;
const char *name;
bool death_test;
bool success;
diff --git a/test/test.c b/test/test.c
index 1c077e9..c471c378 100644
--- a/test/test.c
+++ b/test/test.c
@@ -76,6 +76,7 @@ static void __noreturn test_abort(struct test *test)
int test_init_test(struct test *test, const char *name)
{
INIT_LIST_HEAD(&test->resources);
+ INIT_LIST_HEAD(&test->post_conditions);
test->name = name;
test->vprintk = test_vprintk;
test->fail = test_fail;
@@ -134,6 +135,16 @@ static void test_run_case_cleanup(struct test *test,
struct test_module *module,
struct test_case *test_case)
{
+ struct test_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 (module->exit)
module->exit(test);