diff mbox

Add selftests to selftest.c

Message ID 1470792354-8483-1-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm Aug. 10, 2016, 1:25 a.m. UTC
This patch adds some initial selftesting of selftest.c/h itself.
This may seem like overdoing it, but I have some followup patches
that add non-trivial logic to selftest.c, which we should verify, so it
makes sense to test the existing functionality and then build on that.

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.

OK for trunk?

gcc/ChangeLog:
	* selftest-run-tests.c (selftest::run_tests): Call selftest_c_tests.
	* selftest.c (selftest::test_assertions): New function.
	(selftest::selftest_c_tests): New function.
	* selftest.h (selftest::selftest_c_tests): New declaration.
---
 gcc/selftest-run-tests.c |  3 +++
 gcc/selftest.c           | 28 ++++++++++++++++++++++++++++
 gcc/selftest.h           |  1 +
 3 files changed, 32 insertions(+)

Comments

Jeff Law Aug. 11, 2016, 10:30 p.m. UTC | #1
On 08/09/2016 07:25 PM, David Malcolm wrote:
> This patch adds some initial selftesting of selftest.c/h itself.
> This may seem like overdoing it, but I have some followup patches
> that add non-trivial logic to selftest.c, which we should verify, so it
> makes sense to test the existing functionality and then build on that.
>
> Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.
>
> OK for trunk?
>
> gcc/ChangeLog:
> 	* selftest-run-tests.c (selftest::run_tests): Call selftest_c_tests.
> 	* selftest.c (selftest::test_assertions): New function.
> 	(selftest::selftest_c_tests): New function.
> 	* selftest.h (selftest::selftest_c_tests): New declaration.
OK.
jeff
diff mbox

Patch

diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
index 9d75a8e..6453e31 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -42,6 +42,9 @@  selftest::run_tests ()
   /* Run all the tests, in hand-coded order of (approximate) dependencies:
      run the tests for lowest-level code first.  */
 
+  /* Sanity-check for selftests themselves.  */
+  selftest_c_tests ();
+
   /* Low-level data structures.  */
   bitmap_c_tests ();
   et_forest_c_tests ();
diff --git a/gcc/selftest.c b/gcc/selftest.c
index 76a4c41..2951c3c 100644
--- a/gcc/selftest.c
+++ b/gcc/selftest.c
@@ -88,4 +88,32 @@  selftest::assert_streq (const location &loc,
 }
 
 
+/* Selftests for the selftest system itself.  */
+
+namespace selftest {
+
+/* Sanity-check the ASSERT_ macros with various passing cases.  */
+
+static void
+test_assertions ()
+{
+  ASSERT_TRUE (true);
+  ASSERT_FALSE (false);
+  ASSERT_EQ (1, 1);
+  ASSERT_EQ_AT (SELFTEST_LOCATION, 1, 1);
+  ASSERT_NE (1, 2);
+  ASSERT_STREQ ("test", "test");
+  ASSERT_STREQ_AT (SELFTEST_LOCATION, "test", "test");
+}
+
+/* Run all of the selftests within this file.  */
+
+void
+selftest_c_tests ()
+{
+  test_assertions ();
+}
+
+} // namespace selftest
+
 #endif /* #if CHECKING_P */
diff --git a/gcc/selftest.h b/gcc/selftest.h
index 397e998..55601ef 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -85,6 +85,7 @@  extern void hash_set_tests_c_tests ();
 extern void input_c_tests ();
 extern void pretty_print_c_tests ();
 extern void rtl_tests_c_tests ();
+extern void selftest_c_tests ();
 extern void spellcheck_c_tests ();
 extern void spellcheck_tree_c_tests ();
 extern void sreal_c_tests ();