diff mbox series

[2/2] kunit: ubsan integration

Message ID 20200813205722.1384108-2-urielguajardojr@gmail.com (mailing list archive)
State New
Headers show
Series [1/2] kunit: support failure from dynamic analysis tools | expand

Commit Message

Uriel Guajardo Aug. 13, 2020, 8:57 p.m. UTC
Integrates UBSAN into the KUnit testing framework. It fails KUnit tests
whenever it reports undefined behavior.

Signed-off-by: Uriel Guajardo <urielguajardo@google.com>
---
 lib/ubsan.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Shuah Khan Aug. 31, 2020, 9:29 p.m. UTC | #1
On 8/13/20 2:57 PM, Uriel Guajardo wrote:
> Integrates UBSAN into the KUnit testing framework. It fails KUnit tests
> whenever it reports undefined behavior.
> 
> Signed-off-by: Uriel Guajardo <urielguajardo@google.com>
> ---
>   lib/ubsan.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/lib/ubsan.c b/lib/ubsan.c
> index cb9af3f6b77e..1460e2c828c8 100644
> --- a/lib/ubsan.c
> +++ b/lib/ubsan.c
> @@ -14,6 +14,7 @@
>   #include <linux/types.h>
>   #include <linux/sched.h>
>   #include <linux/uaccess.h>
> +#include <kunit/test.h>
>   
>   #include "ubsan.h"
>   
> @@ -137,6 +138,7 @@ static void ubsan_prologue(struct source_location *loc, const char *reason)
>   {
>   	current->in_ubsan++;
>   
> +	kunit_fail_current_test();
>   	pr_err("========================================"
>   		"========================================\n");
>   	pr_err("UBSAN: %s in %s:%d:%d\n", reason, loc->file_name,
> 

I applied this to linux-kselftest kunit for 5.10-rc1.

thanks,
-- Shuah
diff mbox series

Patch

diff --git a/lib/ubsan.c b/lib/ubsan.c
index cb9af3f6b77e..1460e2c828c8 100644
--- a/lib/ubsan.c
+++ b/lib/ubsan.c
@@ -14,6 +14,7 @@ 
 #include <linux/types.h>
 #include <linux/sched.h>
 #include <linux/uaccess.h>
+#include <kunit/test.h>
 
 #include "ubsan.h"
 
@@ -137,6 +138,7 @@  static void ubsan_prologue(struct source_location *loc, const char *reason)
 {
 	current->in_ubsan++;
 
+	kunit_fail_current_test();
 	pr_err("========================================"
 		"========================================\n");
 	pr_err("UBSAN: %s in %s:%d:%d\n", reason, loc->file_name,