[RFC v1 06/12] kunit: expose kunit_set_failure() for use by mocking

From: Daniel Latypov
Date: Fri Sep 18 2020 - 14:32:12 EST


Being able to fail the test outside of expectations and assertions is a
requirement for new features, e.g. mocking, dynamic analysis, etc.

Signed-off-by: Daniel Latypov <dlatypov@xxxxxxxxxx>
---
include/kunit/test.h | 2 ++
lib/kunit/test.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index 0eb3abb00da4..05330593243d 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -233,6 +233,8 @@ struct kunit {

void kunit_init_test(struct kunit *test, const char *name, char *log);

+void kunit_set_failure(struct kunit *test);
+
int kunit_run_tests(struct kunit_suite *suite);

size_t kunit_suite_num_test_cases(struct kunit_suite *suite);
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index 4e8c74c89073..1ccf6dbecd73 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -15,7 +15,7 @@
#include "debugfs.h"
#include "try-catch-impl.h"

-static void kunit_set_failure(struct kunit *test)
+void kunit_set_failure(struct kunit *test)
{
WRITE_ONCE(test->success, false);
}
--
2.28.0.681.g6f77f65b4e-goog