This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 14/16] tree.c: add selftests
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Bernd Schmidt <bschmidt at redhat dot com>, Jeff Law <law at redhat dot com>, David Malcolm <dmalcolm at redhat dot com>
- Date: Thu, 2 Jun 2016 17:07:03 -0400
- Subject: [PATCH 14/16] tree.c: add selftests
- Authentication-results: sourceware.org; auth=none
- References: <1464874868 dot 11895 dot 41 dot camel at redhat dot com> <1464901625-54547-1-git-send-email-dmalcolm at redhat dot com>
Jeff approved an earlier version of this (as
unittests/test-tree.c):
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03303.html
> OK if/when prereqs are approved. Minor twiddling if we end up
> moving it elsewhere or standardizing/reducing header files is
> pre-approved.
gcc/ChangeLog:
* tree.c: Include "selftest.h".
(test_integer_constants): New function.
(test_identifiers): New function.
(test_labels): New function.
(selftest::tree_c_tests): New function.
---
gcc/tree.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/gcc/tree.c b/gcc/tree.c
index 5a1d167..ba22525 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -61,6 +61,7 @@ along with GCC; see the file COPYING3. If not see
#include "builtins.h"
#include "print-tree.h"
#include "ipa-utils.h"
+#include "selftest.h"
/* Tree code classes. */
@@ -14179,4 +14180,63 @@ combined_fn_name (combined_fn fn)
return internal_fn_name (as_internal_fn (fn));
}
+#if CHECKING_P
+
+/* Selftests for tree. */
+
+/* Verify that integer constants are sane. */
+
+static void
+test_integer_constants ()
+{
+ ASSERT_TRUE (integer_type_node != NULL);
+ ASSERT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
+
+ tree type = integer_type_node;
+
+ tree zero = build_zero_cst (type);
+ ASSERT_EQ (INTEGER_CST, TREE_CODE (zero));
+ ASSERT_EQ (type, TREE_TYPE (zero));
+
+ tree one = build_int_cst (type, 1);
+ ASSERT_EQ (INTEGER_CST, TREE_CODE (one));
+ ASSERT_EQ (type, TREE_TYPE (zero));
+}
+
+/* Verify identifiers. */
+
+static void
+test_identifiers ()
+{
+ tree identifier = get_identifier ("foo");
+ ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier));
+ ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
+}
+
+/* Verify LABEL_DECL. */
+
+static void
+test_labels ()
+{
+ tree identifier = get_identifier ("err");
+ tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
+ identifier, void_type_node);
+ ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
+ ASSERT_FALSE (FORCED_LABEL (label_decl));
+}
+
+namespace selftest {
+
+void
+tree_c_tests ()
+{
+ test_integer_constants ();
+ test_identifiers ();
+ test_labels ();
+}
+
+} // namespace selftest
+
+#endif /* CHECKING_P */
+
#include "gt-tree.h"
--
1.8.5.3