Skip to content

Commit 1195505

Browse files
Uriel Guajardoshuahkh
authored andcommitted
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: Daniel Latypov <dlatypov@google.com> Signed-off-by: Uriel Guajardo <urielguajardo@google.com> Reviewed-by: Alan Maguire <alan.maguire@oracle.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent b0d4ada commit 1195505

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

lib/ubsan.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/types.h>
1515
#include <linux/sched.h>
1616
#include <linux/uaccess.h>
17+
#include <kunit/test-bug.h>
1718

1819
#include "ubsan.h"
1920

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

146149
static void ubsan_epilogue(void)

0 commit comments

Comments
 (0)