From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id A92833857706; Mon, 21 Aug 2023 18:07:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A92833857706 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2bcc4347d2dso12301911fa.0; Mon, 21 Aug 2023 11:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692641261; x=1693246061; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=AXqokwPFSusrCsziaxXkwIRUfuf/eLyLBYUJOAOxpvQ=; b=Y8B+S/zaPtwv4NBWgu9vxPiV/BmcgwES0q+puF0Z4SpdBruYvJCTaHXwG/N8asMS/y d7S1/CJJ+/1XzzhXE44SoVs/3NOY8eyjDR19mHf/qUlxXI0UfJbd9ot0CP0tmPZWa6kf wMgjTETQ9fgYhfd+zDZcoduGy0F8cEZjUHOXuceFzrHtVlVzlXryiU72a7E2WYK6Jctf DnZGZGFbZmy0iZbQgcPI2CjM4QuZv4dZdpAJrVkxbuhXauq92nd+Xr/I/trl2uzJfQEI CfLUmZIfTzLNayy785Z0FYH6jun1lFKKPX3J7wFpSytwkz/JhAL7P+6g86JPwq/HzTsb Vybw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692641261; x=1693246061; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AXqokwPFSusrCsziaxXkwIRUfuf/eLyLBYUJOAOxpvQ=; b=XTKWSYcw+Ag5ISMu6uFYusHjvdyGpi7zV3HblKM2iAv7uuq0EylIF2CsN6EhCAQapw g9tgUTA3QNrIel34Lj/bsnaUBqoe0tZZSWobMModzgJil6eiksgr7Sa0eXPspgfCNb8W b5MT0RZ9l7Xd95rLI5pvRRQxowV+mmx0z99FRm0Qke8Tx4JAB/dmh+05M+0v+/d0RFnY Wg41zcxoGVME5wA0xw/GHWlRYmIddveuwWBfHDVYZoaPUbQkNCdq1QsNr01LNdcG9uDa 5AsisFPapzCovW8Du2MNqlkTdk+fgX96zNAIVSkWufkx0VujYd0Wb2gM/qlK4YqExf50 lrww== X-Gm-Message-State: AOJu0Yy8nXkB6ccmer4gZowH/0Lr0zkIbsSKv2Ki9fW2WZR2oIs6db0P BQW9VRw3wgFqieXK6hySmvaxkmpHgEy3XOOx/pY= X-Google-Smtp-Source: AGHT+IFZxf1AIWBKAavjMzP+xLYLlKiPBHPQxyDQceU3NDy8tN4F8abasLSMxTNwtLdEC43lyzKjgjXoNskiCniGUig= X-Received: by 2002:a2e:9d08:0:b0:2b9:cc8e:8729 with SMTP id t8-20020a2e9d08000000b002b9cc8e8729mr5192769lji.26.1692641260788; Mon, 21 Aug 2023 11:07:40 -0700 (PDT) MIME-Version: 1.0 References: <70988952-dab7-3ba6-4694-2d90c035f80f@gmail.com> In-Reply-To: <70988952-dab7-3ba6-4694-2d90c035f80f@gmail.com> From: Jonathan Wakely Date: Mon, 21 Aug 2023 19:07:29 +0100 Message-ID: Subject: Re: [PATCH] Fix tests sensitive to internal library allocations To: =?UTF-8?Q?Fran=C3=A7ois_Dumont?= Cc: "libstdc++" , gcc-patches Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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 List-Id: On Mon, 21 Aug 2023 at 18:05, Fran=C3=A7ois Dumont via Libstdc++ wrote: > > Hi > > Here is a propocal to fix tests sensitive to libstdc++ internal allocatio= ns. Surely the enter() and exit() calls should be a constructor and destructor? The constructor could use count() to get the count, and then restore it in the destructor. Something like: --- a/libstdc++-v3/testsuite/util/replacement_memory_operators.h +++ b/libstdc++-v3/testsuite/util/replacement_memory_operators.h @@ -75,12 +75,30 @@ namespace __gnu_test counter& cntr =3D get(); cntr._M_increments =3D cntr._M_decrements =3D 0; } + + struct scope + { + scope() : _M_count(counter::count()) { } + ~scope() { counter::get()._M_count =3D _M_count; } + + private: + std::size_t _M_count; + +#if __cplusplus >=3D 201103L + scope(const scope&) =3D delete; + scope& operator=3D(const scope&) =3D delete; +#else + scope(const scope&); + scope& operator=3D(const scope&); +#endif + }; }; template bool check_new(Alloc a =3D Alloc()) { + __gnu_test::counter::scope s; __gnu_test::counter::exceptions(false); __gnu_test::counter::reset(); (void) a.allocate(10); > > 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. The test is a good idea. I think 17_intro/no_library_allocation.cc would be a better place for it. > > 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=C3=A7ois