Commit 73cda7bb authored by Brendan Higgins's avatar Brendan Higgins Committed by Shuah Khan

kunit: test: add the concept of expectations

Add support for expectations, which allow properties to be specified and
then verified in tests.
Signed-off-by: default avatarBrendan Higgins <brendanhiggins@google.com>
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: default avatarLogan Gunthorpe <logang@deltatee.com>
Reviewed-by: default avatarStephen Boyd <sboyd@kernel.org>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 6b229e59
This diff is collapsed.
......@@ -120,6 +120,68 @@ static void kunit_print_test_case_ok_not_ok(struct kunit_case *test_case,
test_case->name);
}
static void kunit_print_string_stream(struct kunit *test,
struct string_stream *stream)
{
struct string_stream_fragment *fragment;
char *buf;
buf = string_stream_get_string(stream);
if (!buf) {
kunit_err(test,
"Could not allocate buffer, dumping stream:\n");
list_for_each_entry(fragment, &stream->fragments, node) {
kunit_err(test, fragment->fragment);
}
kunit_err(test, "\n");
} else {
kunit_err(test, buf);
kunit_kfree(test, buf);
}
}
static void kunit_fail(struct kunit *test, struct kunit_assert *assert)
{
struct string_stream *stream;
kunit_set_failure(test);
stream = alloc_string_stream(test, GFP_KERNEL);
if (!stream) {
WARN(true,
"Could not allocate stream to print failed assertion in %s:%d\n",
assert->file,
assert->line);
return;
}
assert->format(assert, stream);
kunit_print_string_stream(test, stream);
WARN_ON(string_stream_destroy(stream));
}
void kunit_do_assertion(struct kunit *test,
struct kunit_assert *assert,
bool pass,
const char *fmt, ...)
{
va_list args;
if (pass)
return;
va_start(args, fmt);
assert->message.fmt = fmt;
assert->message.va = &args;
kunit_fail(test, assert);
va_end(args);
}
void kunit_init_test(struct kunit *test, const char *name)
{
spin_lock_init(&test->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment