From patchwork Tue Oct 29 17:08:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 2003829 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Qbn/Toa/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XdGvN0nGRz1xwK for ; Wed, 30 Oct 2024 04:09:20 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 56C3C385842A for ; Tue, 29 Oct 2024 17:09:18 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id AD39B3858408 for ; Tue, 29 Oct 2024 17:08:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD39B3858408 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AD39B3858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730221740; cv=none; b=nOnNdBtc/WEJXvEoqRPnz5fSrgbtyfiCc/89QIkozt8UHbXmeZ3YUgcuYnb94AZwRmPQC+3RDl0rOnSzqyq/bFfvaapcUdobCsdqis2k7JVQY3GChB+8NMbFrqxahzQQVa4NgjUYhrUdvE14spydLlmMEOdpVT2P36BYKii740g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730221740; c=relaxed/simple; bh=onLZaclRpogwEJ+2iRetSDW6QFqbwEqYU3mLjbcvJzc=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=vdQnmwI/afVspSwAeLx3b3ODbRTBksfD30ZLRFz4XycoZJFstHnphsTbxV3LkMthSXhLEYBUIX6Q9IPy1KUBMkp1MV50j46XQDe5nxnpYRDZ/e5EmJcqDIAOiMveE0g9YrVK6h3xyytexl9xRrCbPojf39tc6wkjpTcye8Wpelk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730221738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=QthK3pe0/9DupvG9uoJXb3cADP/P+Il/0JU9pMIJ6Wg=; b=Qbn/Toa/1bjomByjYQ9hHu2fGILjefm3AMQ7F7tLo6gAyE8m+gswm+0iv8StlKp/g91HEC yygcM9UadriK0WUynKE0pcX7IfPkKPLtHlMc9WkU0j1WuoPhBi8cuBQTw71vC8nJc8AxgG qtEpxGD6yjctH5e2kl5+z+CPyMlwEyE= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-611-tLhwCo_aMuuGa_WoNwgHwQ-1; Tue, 29 Oct 2024 13:08:57 -0400 X-MC-Unique: tLhwCo_aMuuGa_WoNwgHwQ-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-37d52ccc50eso2619975f8f.3 for ; Tue, 29 Oct 2024 10:08:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730221735; x=1730826535; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QthK3pe0/9DupvG9uoJXb3cADP/P+Il/0JU9pMIJ6Wg=; b=Rx0QlISVLKu8h3SHbvQql9APJ9UR+Ox61uPDnWDapKxHQYQaFUYIjpJPBDrV71FjHt m6A8ufwqXHLMyrjeMpq6OA1cyxI30PTyRUPrKTcwaP8b5SvC5sDjVI4H+JFX1hHhC/C3 mtIkoQg76QPO/yGePBIsBpAtwgDeFta3uzFO5z9F22+/acn8gsH4QxlVIUIdq8nmYKWQ fHROwAjNMJeQG0jCgTZX5E8y28eRK8N6iQ7rhJKjbCgXnoJco2yxrEon8Xgb7xwQS+9j EHpb9n/Hf210M4HgYpsf18ZLhXAwqbBsgBe5Y/YDyt24trQuGhKj6gp3TGFa1PGMaGnt dQ6A== X-Gm-Message-State: AOJu0YzKg9S5h7bvjpVx7pkcge+8Z/GoPYdvRkJHgpMUs3YmyA+JAIJK DFxrvEF2axgxP3UqOPN6IcH1abWhD45xRX03RDyk28zjv+aQAS/BJAyKaGmi9Aqb51gbTHGqYgc yTBhRKAwDDdD7TUq2rTsOMmoz5PlqQJooqrSiSL3QMeAKfWbvCOb+eHVAEJh2Mthqlg== X-Received: by 2002:adf:e28a:0:b0:37d:45f0:dd0a with SMTP id ffacd0b85a97d-380610f2a9emr9381791f8f.1.1730221734798; Tue, 29 Oct 2024 10:08:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpcKMFMsP++4LxTDYTWwJEBeDEYRcuUUhfD0GsvcYtn1Cpk6SVajWCc0mlPmCU8lTeVEU74A== X-Received: by 2002:adf:e28a:0:b0:37d:45f0:dd0a with SMTP id ffacd0b85a97d-380610f2a9emr9381775f8f.1.1730221734389; Tue, 29 Oct 2024 10:08:54 -0700 (PDT) Received: from digraph.polyomino.org.uk (digraph.polyomino.org.uk. [2001:8b0:bf73:93f7::51bb:e332]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b70d5csm13159567f8f.89.2024.10.29.10.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 10:08:54 -0700 (PDT) Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.97) (envelope-from ) id 1t5pi8-00000003PPw-26LU; Tue, 29 Oct 2024 17:08:52 +0000 Date: Tue, 29 Oct 2024 17:08:52 +0000 (UTC) From: Joseph Myers To: Florian Weimer cc: libc-alpha@sourceware.org Subject: [PATCH v2] Add more tests of pthread attributes initial values In-Reply-To: <875xpbkvk6.fsf@oldenburg.str.redhat.com> Message-ID: References: <441c3d7f-2bd8-50bf-12f0-6eb0ce9a9b48@redhat.com> <875xpbkvk6.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org On Tue, 29 Oct 2024, Florian Weimer wrote: > * Joseph Myers: > > > There are various existing tests that call pthread_attr_init and then > > verify properties of the resulting initial values retrieved with > > pthread_attr_get* functions. However, those are missing coverage of > > the initial values retrieved with pthread_attr_getschedparam and > > pthread_attr_getstacksize. Add testing for initial values from those > > functions as well. > > > > (tst-attr2 covers pthread_attr_getdetachstate, > > pthread_attr_getguardsize, pthread_attr_getinheritsched, > > pthread_attr_getschedpolicy, pthread_attr_getscope. tst-attr3 covers > > some of those together with pthread_attr_getaffinity_np. > > tst-pthread-attr-sigmask covers pthread_attr_getsigmask_np. > > pthread_attr_getstack has unspecified results if called before the > > relevant attributes have been set, while pthread_attr_getstackaddr is > > deprecated.) > > > > Tested for x86_64. > > Missing xpthread_attr_destroy. Rest looks good. Added in this version. Add more tests of pthread attributes initial values There are various existing tests that call pthread_attr_init and then verify properties of the resulting initial values retrieved with pthread_attr_get* functions. However, those are missing coverage of the initial values retrieved with pthread_attr_getschedparam and pthread_attr_getstacksize. Add testing for initial values from those functions as well. (tst-attr2 covers pthread_attr_getdetachstate, pthread_attr_getguardsize, pthread_attr_getinheritsched, pthread_attr_getschedpolicy, pthread_attr_getscope. tst-attr3 covers some of those together with pthread_attr_getaffinity_np. tst-pthread-attr-sigmask covers pthread_attr_getsigmask_np. pthread_attr_getstack has unspecified results if called before the relevant attributes have been set, while pthread_attr_getstackaddr is deprecated.) Tested for x86_64. Reviewed-by: Florian Weimer --- Change in v2: call xpthread_attr_destroy at end. diff --git a/nptl/Makefile b/nptl/Makefile index bf4c29b6ed..ceb91afafc 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -276,6 +276,7 @@ LDLIBS-tst-minstack-throw = -lstdc++ tests = \ tst-attr2 \ tst-attr3 \ + tst-attr4 \ tst-cancel4_1 \ tst-cancel4_2 \ tst-cancel7 \ diff --git a/nptl/tst-attr4.c b/nptl/tst-attr4.c new file mode 100644 index 0000000000..c53781e7f3 --- /dev/null +++ b/nptl/tst-attr4.c @@ -0,0 +1,62 @@ +/* Test initial values of pthread attributes. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +#include +#include +#include + + +int +do_test (void) +{ + pthread_attr_t a; + int ret; + + xpthread_attr_init (&a); + + size_t stacksize = 0; + verbose_printf ("testing default stack size\n"); + ret = pthread_attr_getstacksize (&a, &stacksize); + TEST_VERIFY_EXIT (ret == 0); + TEST_VERIFY (stacksize >= PTHREAD_STACK_MIN); + TEST_VERIFY (stacksize <= SIZE_MAX / 2); + + int policy; + verbose_printf ("testing default scheduler parameters\n"); + ret = pthread_attr_getschedpolicy (&a, &policy); + TEST_VERIFY_EXIT (ret == 0); + struct sched_param param; + ret = pthread_attr_getschedparam (&a, ¶m); + TEST_VERIFY_EXIT (ret == 0); + int min = sched_get_priority_min (policy); + TEST_VERIFY (min != -1); + int max = sched_get_priority_max (policy); + TEST_VERIFY (max != -1); + TEST_VERIFY (param.sched_priority >= min); + TEST_VERIFY (param.sched_priority <= max); + + xpthread_attr_destroy (&a); + + return 0; +} + +#include