From patchwork Mon Aug 21 17:04:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 136414 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp3142746vqi; Mon, 21 Aug 2023 10:05:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4tOKq7KFv2oD2ZpNEbwUygyijHZDEMiLalpMd2Nz0h9BYnQH+lm25pSTywQS7jhLuW4Ax X-Received: by 2002:a17:906:519b:b0:9a1:85c2:ad4a with SMTP id y27-20020a170906519b00b009a185c2ad4amr6849569ejk.4.1692637542104; Mon, 21 Aug 2023 10:05:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692637542; cv=none; d=google.com; s=arc-20160816; b=O3yaavnJKmPQK8H8lJ568THYqdO8geJFnbKuKjPNCdQcn0k/HaohShml0K2PJzegVN PC976bOlKWs4xOYsVAD8l9X1yTtb4FYnBgWnvgFr0tfH7F/hJF6VNeurfZdO1cNPzi81 TVmT9j+JF8kCUuP0M7XTucgiW1DqkDp6vrmYefmm3Xm5AOJcjmxHu2cTmEk6kH0DwOaB Wo8Wk4a+5N/y9pp6s1+P6r1bAiBECSb/vdJyHc2mn3Eh1Jdp1AiVTNmT3qm3gbt6TxA2 FI9BIQ7buhYzrAvfI5ODHxCze6ntEY6RF8z1cH7kifTpO6Hb+PlgLMg36mnYbFQceaaC WskQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:cc:to :content-language:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=+4GMVlDXjciYyvWvp8ikWYnRjSHXtIrHyz4xAwgs4cg=; fh=I2ZikstH4IIsv8gM4OvoosTgP0ASJj6WB/YQ3XqwPBs=; b=ahPvgicZUPnfzr6K57iV89yluwKBGgOU71GXAZ+pj487csJqrmK8VlRzhnTbHA0P9b dneAnkp4HoP2iOrjpdotRqhnUwrTu+lwTke6KfC0sgmkMrH+XluhbW5RoK0SvrfM210a A7859JyzH2q8yB7iuJHxGg2HcO2MWv9ynsjH8dMHuH87EeiOKHnhzpQ83ntYXnu56gTF GgVaOhG/C22qr2NTYKLewRdvpsEitF4v/ns7/HlS78Aks++5xYHv1o+1Eb+h2ge33FM0 Wjbl0uDIpSO308dmHxmYhDXYtC88pMgjVgp/qFntJcGQDwNnJ1JTcZv2A4NRSdvetRZI fRzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RaFkFsrt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v8-20020a17090606c800b00992d0de875dsi6113975ejb.912.2023.08.21.10.05.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Aug 2023 10:05:42 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RaFkFsrt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3DBBF385C301 for ; Mon, 21 Aug 2023 17:05:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DBBF385C301 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692637522; bh=+4GMVlDXjciYyvWvp8ikWYnRjSHXtIrHyz4xAwgs4cg=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=RaFkFsrts/wD3gYFNjIXmebuF/vWIOZxBgP+z770l7vfT40RAlhSu0ikn2kZWwD1b tssIK4/cz3Al+RJvqhQ+rPK+yC4Hc3cIFHKczlHaUAHMrGbwNzE5ZEr+qefaEaBGAO MyL7HFkMV5wvqVkZaPOBcRCbY4Wm0LrzpuMFangg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 234CD3858C41; Mon, 21 Aug 2023 17:04:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 234CD3858C41 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-51a52a7d859so9619782a12.0; Mon, 21 Aug 2023 10:04:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692637472; x=1693242272; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+4GMVlDXjciYyvWvp8ikWYnRjSHXtIrHyz4xAwgs4cg=; b=Kk6tpb9uIIb+EU2txGJ6m+3tjJXeY73qT1qAHuISHQ3wCjgy08oNRtmq4gu6oQU0FX e3B0rfEePjVrNuU8bMpbz8TbvGyoHBFlHhO9sIJYxDBQZLQCtTv7lxseYJEwLlROJ7x+ BYgzOKHDb7ApqF8dxoxRgRRpswkRTRN82kwNc9xvecn/OAZJKU+V6SKV71XiLFKPbSsi XfwlEfPVSWnW6nzrPj4WG01VW9n+fLHex1x7t5lxl4BbCouoK4b8pZnu5d4ZOYwRtwAz 2Dj5X4UZqvRo747X1IEQI3t+V0ZVc4onuHOW8fhOxRNeEqF0lhTzgFpxGAc1LYse8KQn rXkw== X-Gm-Message-State: AOJu0Yz1PUtAVN1bcZbxDqr7wtpn6JaFgVJViDIRLEfJZ/kYBse9V632 s0BuKC1La/x0ZP9AXSMIggGAzEXYV1Y= X-Received: by 2002:a17:907:3f10:b0:99c:10b5:7650 with SMTP id hq16-20020a1709073f1000b0099c10b57650mr9010496ejc.1.1692637471400; Mon, 21 Aug 2023 10:04:31 -0700 (PDT) Received: from [10.34.0.253] ([89.207.171.102]) by smtp.gmail.com with ESMTPSA id jw11-20020a17090776ab00b0099d0a8ccb5fsm6815157ejc.152.2023.08.21.10.04.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Aug 2023 10:04:30 -0700 (PDT) Message-ID: <70988952-dab7-3ba6-4694-2d90c035f80f@gmail.com> Date: Mon, 21 Aug 2023 19:04:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US To: libstdc++ Cc: gcc-patches Subject: [PATCH] Fix tests sensitive to internal library allocations X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Fran=C3=A7ois_Dumont_via_Gcc-patches?= From: =?utf-8?q?Fran=C3=A7ois_Dumont?= Reply-To: =?utf-8?q?Fran=C3=A7ois_Dumont?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774859103614740375 X-GMAIL-MSGID: 1774859103614740375 Hi Here is a propocal to fix tests sensitive to libstdc++ internal allocations. Tested by restoring allocation in tzdb.cc. As announced I'm also adding a test to detect such allocations. If it is ok let me know if you prefer to see it in a different place.     libstdc++: Fix tests relying on operator new/delete overload     Fix tests that are checking for an allocation plan. They are failing if     an allocation is taking place outside the test.     libstdc++-v3/ChangeLog             * testsuite/util/replacement_memory_operators.h             (counter::_M_pre_enter_count): New.             (counter::enter, counter::exit): New static methods to call on main() enter/exit.             * testsuite/23_containers/unordered_map/96088.cc (main):             Call __gnu_test::counter::enter/exit.             * testsuite/23_containers/unordered_multimap/96088.cc (main): Likewise.             * testsuite/23_containers/unordered_multiset/96088.cc (main): Likewise.             * testsuite/23_containers/unordered_set/96088.cc (main): Likewise.             * testsuite/ext/malloc_allocator/deallocate_local.cc (main): Likewise.             * testsuite/ext/new_allocator/deallocate_local.cc (main): Likewise.             * testsuite/ext/throw_allocator/deallocate_local.cc (main): Likewise.             * testsuite/ext/pool_allocator/allocate_chunk.cc (started): New global.             (operator new(size_t)): Check started.             (main): Set/Unset started.             * testsuite/ext/no_library_allocation.cc: New test case. Ok to commit ? François diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc index c6d50c20fbf..bcae891e5ec 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc @@ -268,6 +268,7 @@ test03() int main() { + __gnu_test::counter::enter(); test01(); test02(); test11(); @@ -275,5 +276,6 @@ main() test21(); test22(); test03(); + __gnu_test::counter::exit(); return 0; } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/96088.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/96088.cc index 214bc91a559..9f16ad68218 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/96088.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/96088.cc @@ -61,7 +61,9 @@ test02() int main() { + __gnu_test::counter::enter(); test01(); test02(); + __gnu_test::counter::exit(); return 0; } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/96088.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/96088.cc index 838ce8d5bc5..b34cfe67092 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multiset/96088.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/96088.cc @@ -61,7 +61,9 @@ test02() int main() { + __gnu_test::counter::enter(); test01(); test02(); + __gnu_test::counter::exit(); return 0; } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/96088.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/96088.cc index 0f7dce2b38c..d5717fcec2b 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/96088.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/96088.cc @@ -269,6 +269,7 @@ test03() int main() { + __gnu_test::counter::enter(); test01(); test02(); test11(); @@ -277,5 +278,6 @@ main() test22(); test23(); test03(); + __gnu_test::counter::exit(); return 0; } diff --git a/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc b/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc index 79b583bd716..3aa65f298b1 100644 --- a/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc +++ b/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc @@ -27,6 +27,7 @@ typedef std::basic_string string_t; int main() { + __gnu_test::counter::enter(); { string_t s; s += "bayou bend"; @@ -34,5 +35,7 @@ int main() if (__gnu_test::counter::count() != 0) throw std::runtime_error("count not zero"); + + __gnu_test::counter::exit(); return 0; } diff --git a/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc b/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc index fcde46e6e10..ac4996698c7 100644 --- a/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc +++ b/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc @@ -27,6 +27,7 @@ typedef std::basic_string string_t; int main() { + __gnu_test::counter::enter(); { string_t s; s += "bayou bend"; @@ -34,5 +35,7 @@ int main() if (__gnu_test::counter::count() != 0) throw std::runtime_error("count not zero"); + + __gnu_test::counter::exit(); return 0; } diff --git a/libstdc++-v3/testsuite/ext/no_library_allocation.cc b/libstdc++-v3/testsuite/ext/no_library_allocation.cc new file mode 100644 index 00000000000..278d4757c93 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/no_library_allocation.cc @@ -0,0 +1,8 @@ +#include +#include + +int main() +{ + VERIFY( __gnu_test::counter::count() == 0 ); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/pool_allocator/allocate_chunk.cc b/libstdc++-v3/testsuite/ext/pool_allocator/allocate_chunk.cc index 17f8e3c7dcb..b11b450bf9e 100644 --- a/libstdc++-v3/testsuite/ext/pool_allocator/allocate_chunk.cc +++ b/libstdc++-v3/testsuite/ext/pool_allocator/allocate_chunk.cc @@ -32,16 +32,29 @@ struct big char c[64]; }; +bool started = false; + void* operator new(size_t n) THROW(std::bad_alloc) { - static bool first = true; - if (!first) - throw std::bad_alloc(); - first = false; + if (started) + { + static bool first = true; + if (!first) + throw std::bad_alloc(); + first = false; + } + return std::malloc(n); } +void +operator delete(void* p) throw() +{ + if (p) + std::free(p); +} + // http://gcc.gnu.org/ml/libstdc++/2004-10/msg00098.html void test01() { @@ -59,5 +72,7 @@ void test01() int main() { + started = true; test01(); + started = false; } diff --git a/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc b/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc index c6fd3538b82..268ae91f1ff 100644 --- a/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc +++ b/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc @@ -30,6 +30,7 @@ typedef std::basic_string string_t; int main() { + __gnu_test::counter::enter(); { string_t s; s += "bayou bend"; @@ -38,5 +39,6 @@ int main() if (__gnu_test::counter::count() != 0) throw std::runtime_error("count not zero"); + __gnu_test::counter::exit(); return 0; } diff --git a/libstdc++-v3/testsuite/util/replacement_memory_operators.h b/libstdc++-v3/testsuite/util/replacement_memory_operators.h index 6b1b3a82364..c2d1315691a 100644 --- a/libstdc++-v3/testsuite/util/replacement_memory_operators.h +++ b/libstdc++-v3/testsuite/util/replacement_memory_operators.h @@ -28,11 +28,11 @@ namespace __gnu_test struct counter { - std::size_t _M_count; + std::size_t _M_count, _M_pre_enter_count; std::size_t _M_increments, _M_decrements; bool _M_throw; - counter() : _M_count(0), _M_throw(true) { } + counter() : _M_count(0), _M_pre_enter_count(0), _M_throw(true) { } ~counter() THROW (counter_error) { @@ -75,17 +75,35 @@ namespace __gnu_test counter& cntr = get(); cntr._M_increments = cntr._M_decrements = 0; } + + static void + enter() + { + counter& cntr = get(); + cntr._M_pre_enter_count = cntr._M_count; + cntr._M_count = 0; + } + + static void + exit() + { + counter& cntr = get(); + cntr._M_count = cntr._M_pre_enter_count; + cntr._M_pre_enter_count = 0; + } }; template bool check_new(Alloc a = Alloc()) { + __gnu_test::counter::enter(); __gnu_test::counter::exceptions(false); (void) a.allocate(10); const bool __b((__gnu_test::counter::count() > 0) == uses_global_new); if (!__b) throw std::logic_error("counter not incremented"); + __gnu_test::counter::exit(); return __b; }