public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: David Malcolm <dmalcolm@redhat.com>
Subject: [PATCH 08/16] (partially-approved): Introduce selftest::locate_file
Date: Wed, 05 Oct 2016 15:44:00 -0000	[thread overview]
Message-ID: <1475684110-2521-9-git-send-email-dmalcolm@redhat.com> (raw)
In-Reply-To: <1475684110-2521-1-git-send-email-dmalcolm@redhat.com>

Jeff:
> I do think we should go ahead and plan for a target subdirectory.  With
> that added, this should be OK once dependencies are in.

Loading RTL dumps from files rather than embedding them as strings
in the source requires a way to locate the relevant files.

This patch adds a selftest::locate_file function for locating such
files, relative to "$(SRCDIR)/gcc/testsuite/selftests".  This is
done via a new argument to -fself-test, which supplies the current
value of "$(SRCDIR)/gcc" to cc1.

I chose "$(SRCDIR)/gcc/testsuite/selftests", so as to be below
gcc/testsuite, but not below any of the existing DejaGnu subdirectories,
to avoid selftest-specific files from being picked up by .exp globbing
patterns.

(Depends on the approved-when-needed
  "[PATCH 2/9] Add selftest::read_file"
    https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00476.html ).

gcc/ChangeLog:
	* Makefile.in (s-selftest) Add $(srcdir) as an argument of
	-fself-test.
	(selftest-gdb): Likewise.
	(selftest-valgrind): Likewise.
	* common.opt (fself-test): Rename to...
	(fself-test=): ...this, documenting the meaning of the argument.
	* selftest-run-tests.c: Include "options.h".
	(selftest::run_tests): Initialize selftest::path_to_src_gcc from
	flag_self_test.
	* selftest.c (selftest::path_to_src_gcc): New global.
	(selftest::locate_file): New function.
	(selftest::test_locate_file): New function.
	(selftest::selftest_c_tests): Call test_locate_file.
	* selftest.h (selftest::locate_file): New decl.
	(selftest::path_to_src_gcc): New decl.

gcc/testsuite/ChangeLog:
	* gcc.dg/cpp/pr71591.c: Add a fake value for the argument of
	-fself-test.
	* selftests/example.txt: New file.
---
 gcc/Makefile.in                     |  7 ++++---
 gcc/common.opt                      |  6 +++---
 gcc/selftest-run-tests.c            |  7 +++++++
 gcc/selftest.c                      | 28 ++++++++++++++++++++++++++++
 gcc/selftest.h                      | 10 ++++++++++
 gcc/testsuite/gcc.dg/cpp/pr71591.c  |  2 +-
 gcc/testsuite/selftests/example.txt |  1 +
 7 files changed, 54 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/selftests/example.txt

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 15c48bc..4b50f0b 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1883,18 +1883,19 @@ rest.cross: specs
 .PHONY: selftest
 selftest: s-selftest
 s-selftest: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
-	$(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test
+	$(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test=$(srcdir)
 	$(STAMP) $@
 
 # Convenience method for running selftests under gdb:
 .PHONY: selftest-gdb
 selftest-gdb: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
-	$(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test -wrapper gdb,--args
+	$(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test=$(srcdir) \
+	  -wrapper gdb,--args
 
 # Convenience method for running selftests under valgrind:
 .PHONY: selftest-valgrind
 selftest-valgrind: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
-	$(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test \
+	$(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test=$(srcdir) \
 	  -wrapper valgrind,--leak-check=full
 
 # Recompile all the language-independent object files.
diff --git a/gcc/common.opt b/gcc/common.opt
index 3425c19..c3cf4c2 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2106,9 +2106,9 @@ fselective-scheduling2
 Common Report Var(flag_selective_scheduling2) Optimization
 Run selective scheduling after reload.
 
-fself-test
-Common Undocumented Var(flag_self_test)
-Run self-tests.
+fself-test=
+Common Undocumented Joined Var(flag_self_test)
+Run self-tests, using the given path to locate test files.
 
 fsel-sched-pipelining
 Common Report Var(flag_sel_sched_pipelining) Init(0) Optimization
diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
index 54a9b0f..ecc3d71 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "selftest.h"
 #include "tree.h"
 #include "langhooks.h"
+#include "options.h"
 
 /* This function needed to be split out from selftest.c as it references
    tests from the whole source tree, and so is within
@@ -37,6 +38,12 @@ along with GCC; see the file COPYING3.  If not see
 void
 selftest::run_tests ()
 {
+  /* Makefile.in has -fself-test=$(srcdir), so that flag_self_test
+     contains the path to the "gcc" subdirectory of the source tree
+     (without a trailing slash).  Copy it up to path_to_src_gcc, to
+     avoid selftest.c depending on option-handling.  */
+  path_to_src_gcc = flag_self_test;
+
   long start_time = get_run_time ();
 
   /* Run all the tests, in hand-coded order of (approximate) dependencies:
diff --git a/gcc/selftest.c b/gcc/selftest.c
index cf7031f..2a481ad 100644
--- a/gcc/selftest.c
+++ b/gcc/selftest.c
@@ -198,6 +198,21 @@ read_file (const location &loc, const char *path)
   return result;
 }
 
+/* The path of SRCDIR/gcc.  */
+
+const char *path_to_src_gcc = NULL;
+
+/* Convert a path relative to SRCDIR/gcc/testsuite/selftests
+   to a real path (either absolute, or relative to pwd).
+   The result should be freed by the caller.  */
+
+char *
+locate_file (const char *name)
+{
+  ASSERT_NE (NULL, path_to_src_gcc);
+  return concat (path_to_src_gcc, "/testsuite/selftests/", name, NULL);
+}
+
 /* Selftests for the selftest system itself.  */
 
 /* Sanity-check the ASSERT_ macros with various passing cases.  */
@@ -240,6 +255,18 @@ test_read_file ()
   free (buf);
 }
 
+/* Verify locate_file (and read_file).  */
+
+static void
+test_locate_file ()
+{
+  char *path = locate_file ("example.txt");
+  char *buf = read_file (SELFTEST_LOCATION, path);
+  ASSERT_STREQ ("example of a selftest file\n", buf);
+  free (buf);
+  free (path);
+}
+
 /* Run all of the selftests within this file.  */
 
 void
@@ -248,6 +275,7 @@ selftest_c_tests ()
   test_assertions ();
   test_named_temp_file ();
   test_read_file ();
+  test_locate_file ();
 }
 
 } // namespace selftest
diff --git a/gcc/selftest.h b/gcc/selftest.h
index 86ad14c..8b9c007 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -187,6 +187,16 @@ class temp_override
 
 extern void forcibly_ggc_collect ();
 
+/* Convert a path relative to SRCDIR/gcc/testsuite/selftests
+   to a real path (either absolute, or relative to pwd).
+   The result should be freed by the caller.  */
+
+extern char *locate_file (const char *path);
+
+/* The path of SRCDIR/gcc.  */
+
+extern const char *path_to_src_gcc;
+
 /* Declarations for specific families of tests (by source file), in
    alphabetical order.  */
 extern void bitmap_c_tests ();
diff --git a/gcc/testsuite/gcc.dg/cpp/pr71591.c b/gcc/testsuite/gcc.dg/cpp/pr71591.c
index e92cb52..0e3d7b1 100644
--- a/gcc/testsuite/gcc.dg/cpp/pr71591.c
+++ b/gcc/testsuite/gcc.dg/cpp/pr71591.c
@@ -1,5 +1,5 @@
 /* PR rtl-optimization/71591 */
 /* { dg-do preprocess } */
-/* { dg-options "-fself-test" } */
+/* { dg-options "-fself-test=fake-value" } */
 
 /* { dg-message "self-tests incompatible with -E" "" { target *-*-* } 0 } */
diff --git a/gcc/testsuite/selftests/example.txt b/gcc/testsuite/selftests/example.txt
new file mode 100644
index 0000000..fbfaa33
--- /dev/null
+++ b/gcc/testsuite/selftests/example.txt
@@ -0,0 +1 @@
+example of a selftest file
-- 
1.8.5.3

  parent reply	other threads:[~2016-10-05 15:44 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-05 15:44 [PATCH 00/16] RTL frontend (v3) David Malcolm
2016-10-05 15:44 ` [PATCH 07/16] read-md: add some helper functions David Malcolm
2016-10-05 15:57   ` Bernd Schmidt
2016-10-05 15:44 ` David Malcolm [this message]
2016-10-05 16:10   ` [PATCH 08/16] (partially-approved): Introduce selftest::locate_file Bernd Schmidt
2016-10-05 15:44 ` [PATCH 01/16] read-md.c: Add various cleanups to ~rtx_reader David Malcolm
2016-10-05 15:51   ` Bernd Schmidt
2016-10-11 15:15     ` David Malcolm
2016-10-12 21:57       ` Richard Sandiford
2016-10-14 17:45         ` [PATCH] read-md.c: Move various state to within class rtx_reader David Malcolm
2016-10-17 11:05           ` Bernd Schmidt
2016-10-17 11:37           ` Richard Sandiford
2016-10-17 16:27             ` [PATCH] read-md.c: Move various state to within class rtx_reader (v3) David Malcolm
2016-10-17 20:23               ` Richard Sandiford
2016-10-05 15:44 ` [PATCH 11/16] df selftests (v3) David Malcolm
2016-10-05 15:45 ` [PATCH 02/16] (approved) Add selftest::read_file David Malcolm
2016-10-05 15:45 ` [PATCH 13/16] cse.c selftests David Malcolm
2016-10-05 15:45 ` [PATCH 12/16] combine.c selftests (v2) David Malcolm
2016-10-05 15:45 ` [PATCH 15/16] RTL frontend (rtl1), on top of dump reader David Malcolm
2016-10-06 13:30   ` Bernd Schmidt
2016-10-06 19:53     ` RTL frontend input format again (was Re: [PATCH 15/16] RTL frontend (rtl1), on top of dump reader) David Malcolm
2016-10-06 19:59       ` David Malcolm
2016-10-07 10:38       ` Bernd Schmidt
2016-10-07 13:27         ` David Malcolm
2016-10-07 13:58           ` Bernd Schmidt
2016-10-07 18:08             ` David Malcolm
2016-10-12 10:45             ` [PATCH] print_rtx_function: integrate dumping of the CFG into the insn chain David Malcolm
2016-10-12 10:50               ` Bernd Schmidt
2016-10-12 17:17             ` [PATCH] Add a "compact" mode to print_rtx_function David Malcolm
2016-10-12 17:31               ` Bernd Schmidt
2016-10-12 20:06                 ` [PATCH] (v2) " David Malcolm
2016-10-13 10:21                   ` Bernd Schmidt
2016-10-13 15:22                     ` [PATCH] Omit INSN_LOCATION from compact dumps David Malcolm
2016-10-13 15:50                       ` Bernd Schmidt
2016-11-22 13:18                   ` [PATCH] (v2) Add a "compact" mode to print_rtx_function Dominik Vogt
2016-11-22 13:32                     ` Bernd Schmidt
2016-11-22 13:37                       ` Jakub Jelinek
2016-11-22 14:25                         ` David Malcolm
2016-11-22 14:39                           ` Dominik Vogt
2016-11-22 14:38                         ` Bernd Schmidt
2016-11-22 14:45                           ` Jakub Jelinek
2016-11-22 15:38                             ` David Malcolm
2016-11-25 16:37                               ` Dominik Vogt
2016-12-01 10:13                               ` [PING] " Dominik Vogt
2016-12-01 12:28                                 ` Bernd Schmidt
2016-12-02 12:36                                   ` Andreas Krebbel
2016-10-12 20:33                 ` [PATCH] Tweaks " David Malcolm
2016-10-13 10:24                   ` Bernd Schmidt
2016-10-13 14:08                     ` David Malcolm
2016-10-13 14:18                       ` Bernd Schmidt
2016-10-14 19:41                         ` [PATCH] (v2) " David Malcolm
2016-10-14 20:07                           ` Bernd Schmidt
2016-10-19 14:36             ` RTL frontend input format again (was Re: [PATCH 15/16] RTL frontend (rtl1), on top of dump reader) David Malcolm
2016-10-19 14:42               ` Bernd Schmidt
2016-10-19 17:19                 ` David Malcolm
2016-10-19 17:22                   ` Bernd Schmidt
2016-10-19 17:54                     ` David Malcolm
2016-10-20 13:55     ` INSN_UIDs " David Malcolm
2016-10-20 14:11       ` Bernd Schmidt
2016-10-20 14:20         ` David Malcolm
2016-10-20 14:22           ` Bernd Schmidt
2016-10-26 18:19         ` [PATCH] Show INSN_UIDs in compact mode David Malcolm
2016-10-26 18:20           ` Bernd Schmidt
2016-10-06 15:24   ` [PATCH 15/16] RTL frontend (rtl1), on top of dump reader Bernd Schmidt
2016-10-07 16:22     ` [PATCH] RTL frontend (rtl1), on top of dump reader (v4) David Malcolm
2016-10-05 15:45 ` [PATCH 05/16] Introduce rtl_data::init_stack_alignment David Malcolm
2016-10-05 15:52   ` Bernd Schmidt
2016-10-05 15:45 ` [PATCH 10/16] Introduce class function_reader (v3) David Malcolm
2016-10-05 16:00   ` Bernd Schmidt
2016-10-07 13:44     ` David Malcolm
2016-10-10 18:53       ` Richard Sandiford
2016-10-05 15:45 ` [PATCH 04/16] (approved) Expose forcibly_ggc_collect and run it after all selftests David Malcolm
2016-10-05 15:45 ` [PATCH 06/16] Introduce emit_status::ensure_regno_capacity David Malcolm
2016-10-05 15:55   ` Bernd Schmidt
2016-10-05 15:55   ` Bernd Schmidt
2016-11-18 20:47     ` [PATCH] Introduce emit_status::ensure_regno_capacity (v5) David Malcolm
2016-11-22 13:34       ` Bernd Schmidt
2016-10-05 15:45 ` [PATCH 09/16] Split class rtx_reader into base_rtx_reader vs rtx_reader David Malcolm
2016-10-11 15:53   ` Bernd Schmidt
2016-10-18 20:30     ` David Malcolm
2016-10-19 14:45       ` Bernd Schmidt
2016-10-20 19:14         ` Richard Sandiford
2016-10-05 15:45 ` [PATCH 14/16] RTL interpreter (work-in-progress) David Malcolm
2016-10-05 15:45 ` [PATCH 03/16] (approved) selftest.h: add temp_override fixture David Malcolm
2016-10-05 15:45 ` [PATCH 16/16] Add "__RTL" to cc1 David Malcolm
2016-10-05 16:10   ` Joseph Myers
2016-10-07 15:27     ` [PATCH] Add "__RTL" to cc1 (v2) David Malcolm
2016-10-13 13:49       ` Richard Biener
2016-10-13 13:52         ` Bernd Schmidt
2016-10-14  9:33           ` Richard Biener
2016-10-14  9:48             ` Bernd Schmidt
2016-10-14  9:50               ` Richard Biener
2016-10-14 19:25             ` David Malcolm
2016-10-14 19:27               ` Bernd Schmidt
2016-10-14 19:35                 ` David Malcolm
2016-10-14 19:23         ` David Malcolm

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=1475684110-2521-9-git-send-email-dmalcolm@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).