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

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. UTC
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(+)

Patch
diff mbox series

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