Introduce selftest::locate_file
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 15 Dec 2016 01:47:48 +0000 (01:47 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Thu, 15 Dec 2016 01:47:48 +0000 (01:47 +0000)
gcc/ChangeLog:
* Makefile.in (SELFTEST_FLAGS): Add path argument to -fself-test.
(s-selftest): Add dependency on the selftests data directory.
* common.opt (fself-test): Rename to...
(fself-test=): ...this, documenting the meaning of the argument.
* selftest-run-tests.c (along): Likewise.
* selftest-run-tests.c: Include "options.h".
(selftest::run_tests): Initialize selftest::path_to_selftest_files
from flag_self_test.
* selftest.c (selftest::path_to_selftest_files): New global.
(selftest::locate_file): New function.
(selftest::test_locate_file): New function.
(selftest_c_tests): Likewise.
(selftest::selftest_c_tests): Call test_locate_file.
* selftest.h (selftest::locate_file): New decl.
(selftest::path_to_selftest_files): New decl.

gcc/testsuite/ChangeLog:
PR target/78213
* gcc.dg/cpp/pr71591.c: Add a fake value for the argument of
-fself-test.
* gcc.dg/pr78213.c: Disable this test.
* selftests/example.txt: New file.

From-SVN: r243681

gcc/ChangeLog
gcc/Makefile.in
gcc/common.opt
gcc/selftest-run-tests.c
gcc/selftest.c
gcc/selftest.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/pr71591.c
gcc/testsuite/gcc.dg/pr78213.c
gcc/testsuite/selftests/example.txt [new file with mode: 0644]

index 0aacd3b12a7511968d6d1ba3b6b9847f2671cb21..159dda09e4205cd0dc32feefbcfc9b57d41e8a36 100644 (file)
@@ -1,3 +1,21 @@
+2016-12-14  David Malcolm  <dmalcolm@redhat.com>
+
+       * Makefile.in (SELFTEST_FLAGS): Add path argument to -fself-test.
+       (s-selftest): Add dependency on the selftests data directory.
+       * common.opt (fself-test): Rename to...
+       (fself-test=): ...this, documenting the meaning of the argument.
+       * selftest-run-tests.c (along): Likewise.
+       * selftest-run-tests.c: Include "options.h".
+       (selftest::run_tests): Initialize selftest::path_to_selftest_files
+       from flag_self_test.
+       * selftest.c (selftest::path_to_selftest_files): New global.
+       (selftest::locate_file): New function.
+       (selftest::test_locate_file): New function.
+       (selftest_c_tests): Likewise.
+       (selftest::selftest_c_tests): Call test_locate_file.
+       * selftest.h (selftest::locate_file): New decl.
+       (selftest::path_to_selftest_files): New decl.
+
 2016-12-14  Andrew Pinski  <apinski@cavium.com>
 
        * config/aarch64/aarch64-cores.def: Add -1 as the variant to all
index f2c7cd017d4c42928840b0309e98cfb62be36539..2aae684cad05a43c8d9e68bd5e5b21a2fcf629e7 100644 (file)
@@ -1896,15 +1896,19 @@ rest.cross: specs
 # Specify -o /dev/null so the output of -S is discarded. More importantly
 # It does not try to create a file with the name "null.s" on POSIX and
 # "nul.s" on Windows. Because on Windows "nul" is a reserved file name.
-SELFTEST_FLAGS = -nostdinc -x c /dev/null -S -fself-test -o /dev/null
+# Specify the path to gcc/testsuite/selftests within the srcdir
+# as an argument to -fself-test.
+SELFTEST_FLAGS = -nostdinc -x c /dev/null -S -o /dev/null \
+       -fself-test=$(srcdir)/testsuite/selftests
 
 # Run the selftests during the build once we have a driver and a cc1,
 # so that self-test failures are caught as early as possible.
 # Use "s-selftest" to ensure that we only run the selftests if the
-# driver or cc1 change.
+# driver, cc1, or selftest data change.
 .PHONY: selftest
 selftest: s-selftest
-s-selftest: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
+s-selftest: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs \
+  $(srcdir)/testsuite/selftests
        $(GCC_FOR_TARGET) $(SELFTEST_FLAGS)
        $(STAMP) $@
 
index b350b07b9d8cfc99f9a9b0c16517c3dfefc7382c..de068447d3119ab260cfbe86fe96452c050d9e7e 100644 (file)
@@ -2152,9 +2152,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
index a4cdb555436b5488f2f936cc4a047186520daed2..c1cd97ece59c6578d8c0af2776cd8f029b90ef91 100644 (file)
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree.h"
 #include "target.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
@@ -38,6 +39,13 @@ along with GCC; see the file COPYING3.  If not see
 void
 selftest::run_tests ()
 {
+  /* Makefile.in has -fself-test=$(srcdir)/testsuite/selftests, so that
+     flag_self_test contains the path to the selftest subdirectory of the
+     source tree (without a trailing slash).  Copy it up to
+     path_to_selftest_files, to avoid selftest.c depending on
+     option-handling.  */
+  path_to_selftest_files = flag_self_test;
+
   long start_time = get_run_time ();
 
   /* Run all the tests, in hand-coded order of (approximate) dependencies:
index 40c6cb54b5060559b674148abc8738a8bb25a161..3ff3b3d420ab7009eca5364387375d06e143531c 100644 (file)
@@ -198,6 +198,21 @@ read_file (const location &loc, const char *path)
   return result;
 }
 
+/* The path of SRCDIR/testsuite/selftests.  */
+
+const char *path_to_selftest_files = NULL;
+
+/* Convert a path relative to SRCDIR/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_selftest_files);
+  return concat (path_to_selftest_files, "/", name, NULL);
+}
+
 /* Selftests for libiberty.  */
 
 /* Verify that xstrndup generates EXPECTED when called on SRC and N.  */
@@ -281,6 +296,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
@@ -290,6 +317,7 @@ selftest_c_tests ()
   test_assertions ();
   test_named_temp_file ();
   test_read_file ();
+  test_locate_file ();
 }
 
 } // namespace selftest
index dcce474be6e1899e46f7a9c0d1560e0b7eb60369..c39087375fa9cd50ef4e51cc9fa2c9faceb72d5a 100644 (file)
@@ -158,6 +158,16 @@ extern char *read_file (const location &loc, const char *path);
 
 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/testsuite/selftests.  */
+
+extern const char *path_to_selftest_files;
+
 /* Declarations for specific families of tests (by source file), in
    alphabetical order.  */
 extern void bitmap_c_tests ();
index 8fb754ce7d5cf8899e4381f1c495ab99fff39335..bdee8fd3e1fca3bfda50a66b6928bfca2cc6e685 100644 (file)
@@ -1,3 +1,11 @@
+2016-12-14  David Malcolm  <dmalcolm@redhat.com>
+
+       PR target/78213
+       * gcc.dg/cpp/pr71591.c: Add a fake value for the argument of
+       -fself-test.
+       * gcc.dg/pr78213.c: Disable this test.
+       * selftests/example.txt: New file.
+
 2016-12-14  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/78786
index e92cb529e600d04c4ef9a5849b66c7a3f9666510..0e3d7b1184e4a5955025dd10bf7dfd97055a7c51 100644 (file)
@@ -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 } */
index e43c83cad7506c38bdddf13a3f8bf726dc2c87ea..ebc2cce78f45a51b6189753ca5d5eb3c140c8ea9 100644 (file)
@@ -1,6 +1,13 @@
 /* { dg-do compile } */
 /* { dg-options "-fself-test" } */
 
+/* When this test was written -fself-test took no argument, but it
+   has subsequently gained a mandatory argument, giving the path
+   to selftest support files (within the srcdir).
+   It's not clear how to provide this path sanely from
+   within DejaGnu, so for now, this test is disabled.  */
+/* { dg-skip-if "" { *-*-* } } */
+
 /* Verify that -fself-test does not fail on a non empty source.  */
 
 int i;                                                                          void bar();                                                                     void foo()
diff --git a/gcc/testsuite/selftests/example.txt b/gcc/testsuite/selftests/example.txt
new file mode 100644 (file)
index 0000000..fbfaa33
--- /dev/null
@@ -0,0 +1 @@
+example of a selftest file