[17/49] Support for adding selftests via a plugin

Message ID 1573867416-55618-18-git-send-email-dmalcolm@redhat.com
State New
Headers show
Series
  • RFC: Add a static analysis framework to GCC
Related show

Commit Message

David Malcolm Nov. 16, 2019, 1:23 a.m.
This patch provides a plugin callback for invoking selftests, so that a
plugin can add tests to those run by -fself-test=DIR.  The callback
invocation uses invoke_plugin_callbacks, which is a no-op if plugin
support is disabled.

gcc/ChangeLog:
	* plugin.c (register_callback): Add case for PLUGIN_RUN_SELFTESTS.
	(invoke_plugin_callbacks_full): Likewise.
	* plugin.def (PLUGIN_RUN_SELFTESTS): New event.
	* selftest-run-tests.c: Include "plugin.h".
	(selftest::run_tests): Run any plugin-provided selftests.
---
 gcc/plugin.c             | 2 ++
 gcc/plugin.def           | 3 +++
 gcc/selftest-run-tests.c | 4 ++++
 3 files changed, 9 insertions(+)

-- 
1.8.5.3

Comments

Jeff Law Dec. 7, 2019, 2:40 p.m. | #1
On Fri, 2019-11-15 at 20:23 -0500, David Malcolm wrote:
> This patch provides a plugin callback for invoking selftests, so that

> a

> plugin can add tests to those run by -fself-test=DIR.  The callback

> invocation uses invoke_plugin_callbacks, which is a no-op if plugin

> support is disabled.

> 

> gcc/ChangeLog:

> 	* plugin.c (register_callback): Add case for

> PLUGIN_RUN_SELFTESTS.

> 	(invoke_plugin_callbacks_full): Likewise.

> 	* plugin.def (PLUGIN_RUN_SELFTESTS): New event.

> 	* selftest-run-tests.c: Include "plugin.h".

> 	(selftest::run_tests): Run any plugin-provided selftests.

I'm generally in favor of having the ability for plugins to invoke
selftests.  But do we want to push on this now given the preferred
direction for this kit?

jeff
David Malcolm Dec. 9, 2019, 11:18 p.m. | #2
On Sat, 2019-12-07 at 07:40 -0700, Jeff Law wrote:
> On Fri, 2019-11-15 at 20:23 -0500, David Malcolm wrote:

> > This patch provides a plugin callback for invoking selftests, so

> > that

> > a

> > plugin can add tests to those run by -fself-test=DIR.  The callback

> > invocation uses invoke_plugin_callbacks, which is a no-op if plugin

> > support is disabled.

> > 

> > gcc/ChangeLog:

> > 	* plugin.c (register_callback): Add case for

> > PLUGIN_RUN_SELFTESTS.

> > 	(invoke_plugin_callbacks_full): Likewise.

> > 	* plugin.def (PLUGIN_RUN_SELFTESTS): New event.

> > 	* selftest-run-tests.c: Include "plugin.h".

> > 	(selftest::run_tests): Run any plugin-provided selftests.

> I'm generally in favor of having the ability for plugins to invoke

> selftests.  But do we want to push on this now given the preferred

> direction for this kit?

> 

> jeff


I'm dropping this for the sake of simplicity/YAGNI in the next
iteration of the kit, as it's no longer needed by the kit.

Dave

Patch

diff --git a/gcc/plugin.c b/gcc/plugin.c
index a9d3171e..6a151af 100644
--- a/gcc/plugin.c
+++ b/gcc/plugin.c
@@ -497,6 +497,7 @@  register_callback (const char *plugin_name,
       case PLUGIN_EARLY_GIMPLE_PASSES_END:
       case PLUGIN_NEW_PASS:
       case PLUGIN_INCLUDE_FILE:
+      case PLUGIN_RUN_SELFTESTS:
         {
           struct callback_info *new_callback;
           if (!callback)
@@ -577,6 +578,7 @@  invoke_plugin_callbacks_full (int event, void *gcc_data)
       case PLUGIN_EARLY_GIMPLE_PASSES_END:
       case PLUGIN_NEW_PASS:
       case PLUGIN_INCLUDE_FILE:
+      case PLUGIN_RUN_SELFTESTS:
         {
           /* Iterate over every callback registered with this event and
              call it.  */
diff --git a/gcc/plugin.def b/gcc/plugin.def
index eb31f1a..e200728 100644
--- a/gcc/plugin.def
+++ b/gcc/plugin.def
@@ -99,6 +99,9 @@  DEFEVENT (PLUGIN_NEW_PASS)
    as a const char* pointer.  */
 DEFEVENT (PLUGIN_INCLUDE_FILE)
 
+/* Called when running selftests.  */
+DEFEVENT (PLUGIN_RUN_SELFTESTS)
+
 /* When adding a new hard-coded plugin event, don't forget to edit in
    file plugin.c the functions register_callback and
    invoke_plugin_callbacks_full accordingly!  */
diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
index f41244b..d7fa69f 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -27,6 +27,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "options.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "plugin.h"
 
 /* This function needed to be split out from selftest.c as it references
    tests from the whole source tree, and so is within
@@ -114,6 +115,9 @@  selftest::run_tests ()
   /* Run any lang-specific selftests.  */
   lang_hooks.run_lang_selftests ();
 
+  /* Run any plugin-provided selftests.  */
+  invoke_plugin_callbacks (PLUGIN_RUN_SELFTESTS, NULL);
+
   /* Force a GC at the end of the selftests, to shake out GC-related
      issues.  For example, if any GC-managed items have buggy (or missing)
      finalizers, this last collection will ensure that things that were