This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 04/15] Add selftests to et-forest.c
- 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, 19 Nov 2015 12:04:48 -0500
- Subject: [PATCH 04/15] Add selftests to et-forest.c
- Authentication-results: sourceware.org; auth=none
- References: <564A1DAB dot 1030700 at redhat dot com> <1447952699-40820-1-git-send-email-dmalcolm at redhat dot com>
Jeff approved an earlier version of this:
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03295.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:
* et-forest.c: Include "selftest.h".
(et_forest_test, single_node): New selftest.
(et_forest_test, simple_tree): New selftest.
---
gcc/et-forest.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+)
diff --git a/gcc/et-forest.c b/gcc/et-forest.c
index bf2f765..e4a2a49 100644
--- a/gcc/et-forest.c
+++ b/gcc/et-forest.c
@@ -27,6 +27,7 @@ License along with libiberty; see the file COPYING3. If not see
#include "coretypes.h"
#include "alloc-pool.h"
#include "et-forest.h"
+#include "selftest.h"
/* We do not enable this with CHECKING_P, since it is awfully slow. */
#undef DEBUG_ET
@@ -764,3 +765,101 @@ et_root (struct et_node *node)
return r->of;
}
+
+#if CHECKING_P
+
+namespace {
+
+TEST (et_forest_test, single_node)
+{
+ void *test_data = (void *)0xcafebabe;
+
+ et_node *n = et_new_tree (test_data);
+ EXPECT_EQ (n->data, test_data);
+ EXPECT_EQ (n, et_root (n));
+ et_free_tree (n);
+}
+
+/* Test of this tree:
+ a
+ / \
+ / \
+ b c
+ / \ |
+ d e f. */
+
+TEST (et_forest_test, simple_tree)
+{
+ et_node *a = et_new_tree (NULL);
+ et_node *b = et_new_tree (NULL);
+ et_node *c = et_new_tree (NULL);
+ et_node *d = et_new_tree (NULL);
+ et_node *e = et_new_tree (NULL);
+ et_node *f = et_new_tree (NULL);
+
+ et_set_father (b, a);
+ et_set_father (c, a);
+ et_set_father (d, b);
+ et_set_father (e, b);
+ et_set_father (f, c);
+
+ EXPECT_TRUE (et_below (a, a));
+ EXPECT_TRUE (et_below (b, a));
+ EXPECT_TRUE (et_below (c, a));
+ EXPECT_TRUE (et_below (d, a));
+ EXPECT_TRUE (et_below (e, a));
+ EXPECT_TRUE (et_below (f, a));
+
+ EXPECT_FALSE (et_below (a, b));
+ EXPECT_TRUE (et_below (b, b));
+ EXPECT_FALSE (et_below (c, b));
+ EXPECT_TRUE (et_below (d, b));
+ EXPECT_TRUE (et_below (e, b));
+ EXPECT_FALSE (et_below (f, b));
+
+ EXPECT_FALSE (et_below (a, c));
+ EXPECT_FALSE (et_below (b, c));
+ EXPECT_TRUE (et_below (c, c));
+ EXPECT_FALSE (et_below (d, c));
+ EXPECT_FALSE (et_below (e, c));
+ EXPECT_TRUE (et_below (f, c));
+
+ EXPECT_FALSE (et_below (a, d));
+ EXPECT_FALSE (et_below (b, d));
+ EXPECT_FALSE (et_below (c, d));
+ EXPECT_TRUE (et_below (d, d));
+ EXPECT_FALSE (et_below (e, d));
+ EXPECT_FALSE (et_below (f, d));
+
+ EXPECT_FALSE (et_below (a, e));
+ EXPECT_FALSE (et_below (b, e));
+ EXPECT_FALSE (et_below (c, e));
+ EXPECT_FALSE (et_below (d, e));
+ EXPECT_TRUE (et_below (e, e));
+ EXPECT_FALSE (et_below (f, e));
+
+ EXPECT_FALSE (et_below (a, f));
+ EXPECT_FALSE (et_below (b, f));
+ EXPECT_FALSE (et_below (c, f));
+ EXPECT_FALSE (et_below (d, f));
+ EXPECT_FALSE (et_below (e, f));
+ EXPECT_TRUE (et_below (f, f));
+
+ et_free_tree_force (a);
+}
+
+TEST (et_forest_test, disconnected_nodes)
+{
+ et_node *a = et_new_tree (NULL);
+ et_node *b = et_new_tree (NULL);
+
+ EXPECT_FALSE (et_below (a, b));
+ EXPECT_FALSE (et_below (b, a));
+
+ et_free_tree (a);
+ et_free_tree (b);
+}
+
+} // anon namespace
+
+#endif /* CHECKING_P */
--
1.8.5.3