From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 103149 invoked by alias); 9 Sep 2016 00:01:30 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 102706 invoked by uid 89); 9 Sep 2016 00:01:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 spammy=shake, ggc, Hx-languages-length:5367, roots X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (208.118.235.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Sep 2016 00:01:24 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bi9Fv-0001rT-N8 for gcc-patches@gcc.gnu.org; Thu, 08 Sep 2016 20:01:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46574) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bi9Fv-0001qz-Ep for gcc-patches@gcc.gnu.org; Thu, 08 Sep 2016 20:01:19 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D058C037F62 for ; Fri, 9 Sep 2016 00:01:16 +0000 (UTC) Received: from c64.redhat.com (vpn-232-118.phx2.redhat.com [10.3.232.118]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8901Di8023199; Thu, 8 Sep 2016 20:01:15 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 4/9] Expose forcibly_ggc_collect and run it after all selftests Date: Fri, 09 Sep 2016 00:01:00 -0000 Message-Id: <1473381053-18817-5-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1473381053-18817-1-git-send-email-dmalcolm@redhat.com> References: <1473381053-18817-1-git-send-email-dmalcolm@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-IsSubscribed: yes X-SW-Source: 2016-09/txt/msg00480.txt.bz2 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. 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. --- gcc/ggc-tests.c | 28 ++++++++++++++-------------- gcc/selftest-run-tests.c | 6 ++++++ gcc/selftest.h | 5 +++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/gcc/ggc-tests.c b/gcc/ggc-tests.c index 7f97231..b9cd276 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 (); root_test_struct->other = ggc_cleared_alloc (); - 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 (); - 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 (); 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 (); 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 d9d3ea1..54a9b0f 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 4c50217..86ad14c 100644 --- a/gcc/selftest.h +++ b/gcc/selftest.h @@ -182,6 +182,11 @@ class temp_override T m_old_value; }; +/* 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 (); -- 1.8.5.3