linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Uriel Guajardo <urielguajardojr@gmail.com>
To: brendanhiggins@google.com, catalin.marinas@arm.com,
	akpm@linux-foundtation.org
Cc: changbin.du@intel.com, rdunlap@infradead.org,
	masahiroy@kernel.org, 0x7f454c46@gmail.com,
	urielguajardo@google.com, krzk@kernel.org,
	kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	kunit-dev@googlegroups.com, linux-mm@kvack.org
Subject: [PATCH 1/2] kunit: support kunit failures from debugging tools
Date: Mon,  6 Jul 2020 21:03:26 +0000	[thread overview]
Message-ID: <20200706210327.3313498-2-urielguajardojr@gmail.com> (raw)
In-Reply-To: <20200706210327.3313498-1-urielguajardojr@gmail.com>

From: Uriel Guajardo <urielguajardo@google.com>

Dynamic analyis tools can now fail the currently running kunit
test case by calling kunit_fail_current_test().

A new header file is created so that no circular dependencies are
created with external tools.

This patch requires "kunit: KASAN integration", which places the
currently running kunit test in task_struct. [1]

[1] https://lore.kernel.org/linux-kselftest/20200606040349.246780-2-davidgow@google.com

Signed-off-by: Uriel Guajardo <urielguajardo@google.com>
---
 include/kunit/test-bug.h | 15 +++++++++++++++
 include/kunit/test.h     |  1 +
 lib/kunit/test.c         | 10 ++++++----
 3 files changed, 22 insertions(+), 4 deletions(-)
 create mode 100644 include/kunit/test-bug.h

diff --git a/include/kunit/test-bug.h b/include/kunit/test-bug.h
new file mode 100644
index 000000000000..69ec3dd91c52
--- /dev/null
+++ b/include/kunit/test-bug.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Base unit test (KUnit) API.
+ *
+ * Copyright (C) 2020, Google LLC.
+ * Author: Uriel Guajardo <urielguajardo@google.com>
+ */
+
+#if IS_ENABLED(CONFIG_KUNIT)
+extern void kunit_fail_current_test(void);
+#else
+static inline void kunit_fail_current_test(void)
+{
+}
+#endif
diff --git a/include/kunit/test.h b/include/kunit/test.h
index 1dc3d118f64b..c46715c739b5 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -11,6 +11,7 @@
 
 #include <kunit/assert.h>
 #include <kunit/try-catch.h>
+#include <kunit/test-bug.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/slab.h>
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index ef3bfb9fae48..8580ed831a8f 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -16,6 +16,12 @@
 #include "string-stream.h"
 #include "try-catch-impl.h"
 
+void kunit_fail_current_test(void)
+{
+	if (current->kunit_test)
+		kunit_set_failure(current->kunit_test);
+}
+
 static void kunit_print_tap_version(void)
 {
 	static bool kunit_has_printed_tap_version;
@@ -284,9 +290,7 @@ static void kunit_try_run_case(void *data)
 	struct kunit_suite *suite = ctx->suite;
 	struct kunit_case *test_case = ctx->test_case;
 
-#if (IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT))
 	current->kunit_test = test;
-#endif /* IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT) */
 
 	/*
 	 * kunit_run_case_internal may encounter a fatal error; if it does,
@@ -603,9 +607,7 @@ void kunit_cleanup(struct kunit *test)
 		spin_unlock(&test->lock);
 		kunit_remove_resource(test, res);
 	}
-#if (IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT))
 	current->kunit_test = NULL;
-#endif /* IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT)*/
 }
 EXPORT_SYMBOL_GPL(kunit_cleanup);
 
-- 
2.27.0.212.ge8ba1cc988-goog



  reply	other threads:[~2020-07-06 21:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-06 21:03 [PATCH 0/2] KUnit-Kmemleak Integration Uriel Guajardo
2020-07-06 21:03 ` Uriel Guajardo [this message]
2020-07-06 21:03 ` [PATCH 2/2] kunit: kmemleak integration Uriel Guajardo
2020-07-06 21:13 [PATCH 0/2] KUnit-Kmemleak Integration Uriel Guajardo
2020-07-06 21:13 ` [PATCH 1/2] kunit: support kunit failures from debugging tools Uriel Guajardo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200706210327.3313498-2-urielguajardojr@gmail.com \
    --to=urielguajardojr@gmail.com \
    --cc=0x7f454c46@gmail.com \
    --cc=akpm@linux-foundtation.org \
    --cc=brendanhiggins@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=changbin.du@intel.com \
    --cc=kernel@vger.kernel.org \
    --cc=krzk@kernel.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=masahiroy@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=urielguajardo@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox