kasan: test: improve failure message in KUNIT_EXPECT_KASAN_FAIL()
[linux-2.6-microblaze.git] / lib / test_kasan.c
index cacbbbd..44e08f4 100644 (file)
@@ -55,7 +55,6 @@ static int kasan_test_init(struct kunit *test)
        multishot = kasan_save_enable_multi_shot();
        kasan_set_tagging_report_once(false);
        fail_data.report_found = false;
-       fail_data.report_expected = false;
        kunit_add_named_resource(test, NULL, NULL, &resource,
                                        "kasan_data", &fail_data);
        return 0;
@@ -94,20 +93,20 @@ static void kasan_test_exit(struct kunit *test)
            !kasan_async_mode_enabled())                                \
                migrate_disable();                                      \
        KUNIT_EXPECT_FALSE(test, READ_ONCE(fail_data.report_found));    \
-       WRITE_ONCE(fail_data.report_expected, true);                    \
        barrier();                                                      \
        expression;                                                     \
        barrier();                                                      \
-       KUNIT_EXPECT_EQ(test,                                           \
-                       READ_ONCE(fail_data.report_expected),           \
-                       READ_ONCE(fail_data.report_found));             \
+       if (!READ_ONCE(fail_data.report_found)) {                       \
+               KUNIT_FAIL(test, KUNIT_SUBTEST_INDENT "KASAN failure "  \
+                               "expected in \"" #expression            \
+                                "\", but none occurred");              \
+       }                                                               \
        if (IS_ENABLED(CONFIG_KASAN_HW_TAGS)) {                         \
                if (READ_ONCE(fail_data.report_found))                  \
                        kasan_enable_tagging_sync();                    \
                migrate_enable();                                       \
        }                                                               \
        WRITE_ONCE(fail_data.report_found, false);                      \
-       WRITE_ONCE(fail_data.report_expected, false);                   \
 } while (0)
 
 #define KASAN_TEST_NEEDS_CONFIG_ON(test, config) do {                  \