Skip to content
Permalink
Browse files
kunit: ubsan integration
Integrates UBSAN into the KUnit testing framework. It fails KUnit tests
whenever it reports undefined behavior.

When CONFIG_KUNIT=n, nothing is printed or even formatted, so this has
no behavioral impact outside of tests.

kunit_fail_current_test() effectively does a pr_err() as well, so
there's some slight duplication, but it also ensures an error is
recorded in the debugfs entry for the running KUnit test.

Print a shorter version of the message to make it less spammy.

Co-developed-by: Daniel Latypov <dlatypov@google.com>
Signed-off-by: Uriel Guajardo <urielguajardo@google.com>
Signed-off-by: Daniel Latypov <dlatypov@google.com>
  • Loading branch information
Uriel Guajardo authored and intel-lab-lkp committed Feb 9, 2021
1 parent 7ee87fd commit e3ddf9fb46a603f7e8bf3918cb707a0da9681a17
Showing 1 changed file with 3 additions and 0 deletions.
@@ -14,6 +14,7 @@
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/uaccess.h>
#include <kunit/test-bug.h>

#include "ubsan.h"

@@ -141,6 +142,8 @@ static void ubsan_prologue(struct source_location *loc, const char *reason)
"========================================\n");
pr_err("UBSAN: %s in %s:%d:%d\n", reason, loc->file_name,
loc->line & LINE_MASK, loc->column & COLUMN_MASK);

kunit_fail_current_test("%s in %s", reason, loc->file_name);
}

static void ubsan_epilogue(void)

0 comments on commit e3ddf9f

Please sign in to comment.