aboutsummaryrefslogtreecommitdiff
path: root/gcc/selftest.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-12-15 01:47:48 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-12-15 01:47:48 +0000
commitecfc21ff34ddc6f8aa517251fb51494c68ff741f (patch)
tree308b5533291220862bf4989c1182e3793e2ad200 /gcc/selftest.c
parente98ac2584c0237cbd81df626b8d446f21f54fa39 (diff)
downloadgcc-ecfc21ff34ddc6f8aa517251fb51494c68ff741f.zip
gcc-ecfc21ff34ddc6f8aa517251fb51494c68ff741f.tar.gz
gcc-ecfc21ff34ddc6f8aa517251fb51494c68ff741f.tar.bz2
Introduce selftest::locate_file
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
Diffstat (limited to 'gcc/selftest.c')
-rw-r--r--gcc/selftest.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/gcc/selftest.c b/gcc/selftest.c
index 40c6cb5..3ff3b3d 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/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