summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-10-25 16:46:54 +0000
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-10-25 16:46:54 +0000
commit09c2dc4c39047fcdb0209a8ef21bc52fd7ed9482 (patch)
tree9ed4ccf669a1c2f72ab19b46f518c6f399e4c206
parent6a2e2a85f498e8fe00e4781ab4c41ae090063cdd (diff)
downloadgcc-09c2dc4c39047fcdb0209a8ef21bc52fd7ed9482.tar.gz
Expose forcibly_ggc_collect and run it after all selftests
gcc/ChangeLog: * ggc-tests.c (forcibly_ggc_collect): Rename to... (selftest::forcibly_ggc_collect): ...this, and remove "static". (test_basic_struct): Update for above renaming. (test_length): Likewise. (test_union): Likewise. (test_finalization): Likewise. (test_deletable_global): Likewise. (test_inheritance): Likewise. (test_chain_next): Likewise. (test_user_struct): Likewise. (test_tree_marking): Likewise. * selftest-run-tests.c (selftest::run_tests): Call selftest::forcibly_ggc_collect at the end of the selftests. * selftest.h (selftest::forcibly_ggc_collect): New decl. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241527 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog17
-rw-r--r--gcc/ggc-tests.c28
-rw-r--r--gcc/selftest-run-tests.c6
-rw-r--r--gcc/selftest.h5
4 files changed, 42 insertions, 14 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e7ab456ffc0..68ae6878416 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,20 @@
+2016-10-25 David Malcolm <dmalcolm@redhat.com>
+
+ * ggc-tests.c (forcibly_ggc_collect): Rename to...
+ (selftest::forcibly_ggc_collect): ...this, and remove "static".
+ (test_basic_struct): Update for above renaming.
+ (test_length): Likewise.
+ (test_union): Likewise.
+ (test_finalization): Likewise.
+ (test_deletable_global): Likewise.
+ (test_inheritance): Likewise.
+ (test_chain_next): Likewise.
+ (test_user_struct): Likewise.
+ (test_tree_marking): Likewise.
+ * selftest-run-tests.c (selftest::run_tests): Call
+ selftest::forcibly_ggc_collect at the end of the selftests.
+ * selftest.h (selftest::forcibly_ggc_collect): New decl.
+
2016-10-25 Jakub Jelinek <jakub@redhat.com>
PR target/78102
diff --git a/gcc/ggc-tests.c b/gcc/ggc-tests.c
index 7f972314981..b9cd276ba34 100644
--- a/gcc/ggc-tests.c
+++ b/gcc/ggc-tests.c
@@ -27,19 +27,19 @@ along with GCC; see the file COPYING3. If not see
#if CHECKING_P
-/* The various GTY markers must be outside of a namespace to be seen by
- gengtype, so we don't put this file within the selftest namespace. */
-
/* A helper function for writing ggc tests. */
-static void
-forcibly_ggc_collect ()
+void
+selftest::forcibly_ggc_collect ()
{
ggc_force_collect = true;
ggc_collect ();
ggc_force_collect = false;
}
+/* The various GTY markers must be outside of a namespace to be seen by
+ gengtype, so we don't put this file within the selftest namespace. */
+
/* Verify that a simple struct works, and that it can
@@ -58,7 +58,7 @@ test_basic_struct ()
root_test_struct = ggc_cleared_alloc <test_struct> ();
root_test_struct->other = ggc_cleared_alloc <test_struct> ();
- forcibly_ggc_collect ();
+ selftest::forcibly_ggc_collect ();
ASSERT_TRUE (ggc_marked_p (root_test_struct));
ASSERT_TRUE (ggc_marked_p (root_test_struct->other));
@@ -88,7 +88,7 @@ test_length ()
for (int i = 0; i < count; i++)
root_test_of_length->elem[i] = ggc_cleared_alloc <test_of_length> ();
- forcibly_ggc_collect ();
+ selftest::forcibly_ggc_collect ();
ASSERT_TRUE (ggc_marked_p (root_test_of_length));
for (int i = 0; i < count; i++)
@@ -162,7 +162,7 @@ test_union ()
test_struct *referenced_by_other = ggc_cleared_alloc <test_struct> ();
other->m_ptr = referenced_by_other;
- forcibly_ggc_collect ();
+ selftest::forcibly_ggc_collect ();
ASSERT_TRUE (ggc_marked_p (root_test_of_union_1));
ASSERT_TRUE (ggc_marked_p (ts));
@@ -202,7 +202,7 @@ test_finalization ()
test_struct_with_dtor::dtor_call_count = 0;
- forcibly_ggc_collect ();
+ selftest::forcibly_ggc_collect ();
/* Verify that the destructor was run for each instance. */
ASSERT_EQ (count, test_struct_with_dtor::dtor_call_count);
@@ -220,7 +220,7 @@ test_deletable_global ()
test_of_deletable = ggc_cleared_alloc <test_struct> ();
ASSERT_TRUE (test_of_deletable != NULL);
- forcibly_ggc_collect ();
+ selftest::forcibly_ggc_collect ();
ASSERT_EQ (NULL, test_of_deletable);
}
@@ -293,7 +293,7 @@ test_inheritance ()
test_some_subclass_as_base_ptr = new some_subclass ();
test_some_other_subclass_as_base_ptr = new some_other_subclass ();
- forcibly_ggc_collect ();
+ selftest::forcibly_ggc_collect ();
/* Verify that the roots and everything referenced by them got marked
(both for fields in the base class and those in subclasses). */
@@ -372,7 +372,7 @@ test_chain_next ()
tail_node = new_node;
}
- forcibly_ggc_collect ();
+ selftest::forcibly_ggc_collect ();
/* If we got here, we survived. */
@@ -439,7 +439,7 @@ test_user_struct ()
num_calls_to_user_gt_ggc_mx = 0;
- forcibly_ggc_collect ();
+ selftest::forcibly_ggc_collect ();
ASSERT_TRUE (ggc_marked_p (root_user_struct_ptr));
ASSERT_TRUE (ggc_marked_p (referenced));
@@ -457,7 +457,7 @@ test_tree_marking ()
{
dummy_unittesting_tree = build_int_cst (integer_type_node, 1066);
- forcibly_ggc_collect ();
+ selftest::forcibly_ggc_collect ();
ASSERT_TRUE (ggc_marked_p (dummy_unittesting_tree));
}
diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
index d9d3ea13ab6..54a9b0f6c7e 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -80,6 +80,12 @@ selftest::run_tests ()
/* Run any lang-specific selftests. */
lang_hooks.run_lang_selftests ();
+ /* Force a GC at the end of the selftests, to shake out GC-related
+ issues. For example, if any GC-managed items have buggy (or missing)
+ finalizers, this last collection will ensure that things that were
+ failed to be finalized can be detected by valgrind. */
+ forcibly_ggc_collect ();
+
/* Finished running tests. */
long finish_time = get_run_time ();
long elapsed_time = finish_time - start_time;
diff --git a/gcc/selftest.h b/gcc/selftest.h
index 1a55e4b836e..845eb01b125 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -153,6 +153,11 @@ for_each_line_table_case (void (*testcase) (const line_table_case &));
extern char *read_file (const location &loc, const char *path);
+/* A helper function for writing tests that interact with the
+ garbage collector. */
+
+extern void forcibly_ggc_collect ();
+
/* Declarations for specific families of tests (by source file), in
alphabetical order. */
extern void bitmap_c_tests ();