From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by sourceware.org (Postfix) with ESMTPS id 83BDD3949F39 for ; Thu, 6 Oct 2022 21:43:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 83BDD3949F39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=fastmail.fm Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=fastmail.fm Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 2ED075C00A1; Thu, 6 Oct 2022 17:43:52 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 06 Oct 2022 17:43:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1665092632; x=1665179032; bh=vk P+Z8YPHABiHD8+vkilS05ZR18ewQ//TjrwMrQopVU=; b=Vq2PL+B8SI5JJ3Rn7n KVd5tS6+ek6ORN8jaOfXFjiQZkDUBpIA/kaA15e48iq9MxJTYh/1a2+He8VF+6p1 GfpCmB6t7xzRxItNI7d1cQhKsA1kEHAq0rdNdmLFnqM66pjylen8hrMQQebXMhKX TI5L8UWEjdg01abwsFvzdEWv2ZLL0BeXTkP1kjpqkGxkx8RZM+smc8PKDRhpK21M 9wJ9kUAKkAN0evrS7/1E0l9e+uH1XVPSypgE3GeTEYVYITGlYfhKk4AHiwhJbwJv 6ZrTBNK4CrVcXUBV6S7GKhG+kVMpdIUNR8eHF2Bbx1rzGk39fSPYuUiy+r0FV5+F fckA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1665092632; x=1665179032; bh=vkP+Z8YPHABiH D8+vkilS05ZR18ewQ//TjrwMrQopVU=; b=A4Xrch7kPEM9mr8lnnCFyEeJOE/BB C1Tx8+EOGudUoiMU7HP1tTgVxi2K8Jc1GsmYh+HAMaOy0IO0EgTTboohYvUmTXvr Ht6hpT0xAI03jxW3X54bv0ChFlXaAAdgpHZjkGXD3bTLdITodRDEaWAZhXqp/BSL nNAjUWULg0+cccN7KnGSwsV7xlO2WTOK4bKfxb6Wzb6BugSvNEiciKNXf2AeohkD k7LFeOuGWsP1NRfrZr5N0QOBjkxD4NutXheogLGn5KEkiBtsP66VEh1/VjrKCxBn htiyQjDido/IUDA72xtnAABZ2k6cGIVwIR9PMmy9z/VmhR5dgO7hfqQvA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeeiiedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmhgrlhht vghskhgrrhhuphhkvgesfhgrshhtmhgrihhlrdhfmhenucggtffrrghtthgvrhhnpeetge elgfeggeeuleeuffetveefgffgjedvgeehffdthfekteegtdeguefhffeftdenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmrghlthgvshhkrg hruhhpkhgvsehfrghsthhmrghilhdrfhhm X-ME-Proxy: Feedback-ID: ifa6c408f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 6 Oct 2022 17:43:51 -0400 (EDT) From: malteskarupke@fastmail.fm To: libc-alpha@sourceware.org Cc: Malte Skarupke Subject: [PATCH v3 4/6] nptl: Make test-cond-printers check the number of waiters Date: Thu, 6 Oct 2022 17:43:27 -0400 Message-Id: <20221006214329.1084244-5-malteskarupke@fastmail.fm> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006214329.1084244-1-malteskarupke@fastmail.fm> References: <20221006214329.1084244-1-malteskarupke@fastmail.fm> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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: From: Malte Skarupke In my last change I changed the semantics of how to determine the number of waiters on a condition variable. The existing test only tested that the printers print something. They didn't cover the case when there is a thread sleeping on the condition variable. In this patch I changed the test to ensure that the correct number is printed. --- nptl/test-cond-printers.c | 56 +++++++++++++++++++++++++++++++++----- nptl/test-cond-printers.py | 5 ++++ 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/nptl/test-cond-printers.c b/nptl/test-cond-printers.c index 51d7f920b3..615fd5a681 100644 --- a/nptl/test-cond-printers.c +++ b/nptl/test-cond-printers.c @@ -26,7 +26,14 @@ #define PASS 0 #define FAIL 1 -static int test_status_destroyed (pthread_cond_t *condvar); +static int test_status (pthread_cond_t *condvar); + +typedef struct +{ + pthread_mutex_t *mutex; + pthread_cond_t *condvar; + int *wait_thread_asleep; +} test_state; int main (void) @@ -36,22 +43,57 @@ main (void) int result = FAIL; if (pthread_condattr_init (&attr) == 0 - && test_status_destroyed (&condvar) == PASS) + && test_status (&condvar) == PASS) result = PASS; /* Else, one of the pthread_cond* functions failed. */ return result; } +static void * +wait (void *arg) +{ + test_state *state = (test_state *)arg; + void *result = PASS; + if (pthread_mutex_lock (state->mutex) != 0) + result = (void *)FAIL; + *state->wait_thread_asleep = 1; + if (pthread_cond_signal (state->condvar) != 0) + result = (void *)FAIL; + if (pthread_cond_wait (state->condvar, state->mutex) != 0) + result = (void *)FAIL; + if (pthread_mutex_unlock (state->mutex) != 0) + result = (void *)FAIL; + return result; +} + /* Initializes CONDVAR, then destroys it. */ static int -test_status_destroyed (pthread_cond_t *condvar) +test_status (pthread_cond_t *condvar) { - int result = FAIL; + int result = PASS; - if (pthread_cond_init (condvar, NULL) == 0 - && pthread_cond_destroy (condvar) == 0) - result = PASS; /* Test status (destroyed). */ + pthread_mutex_t mutex; + result |= pthread_mutex_init (&mutex, NULL); + result |= pthread_cond_init (condvar, NULL); + int wait_thread_asleep = 0; + test_state state = { &mutex, condvar, &wait_thread_asleep }; + result |= pthread_mutex_lock (&mutex); + pthread_t thread; + result |= pthread_create (&thread, NULL, wait, &state); + while (!wait_thread_asleep) + { + result |= pthread_cond_wait (condvar, &mutex); + } + result |= pthread_cond_signal (condvar); /* Test about to signal */ + result |= pthread_mutex_unlock (&mutex); + result |= pthread_cond_destroy (condvar); + void *retval = NULL; + result |= pthread_join (thread, &retval); /* Test status (destroyed). */ + result |= pthread_mutex_destroy (&mutex); + result = result ? FAIL : PASS; + if (retval != NULL) + result = FAIL; return result; } diff --git a/nptl/test-cond-printers.py b/nptl/test-cond-printers.py index 42329c1691..7945c7a0d5 100644 --- a/nptl/test-cond-printers.py +++ b/nptl/test-cond-printers.py @@ -33,6 +33,11 @@ try: var = 'condvar' to_string = 'pthread_cond_t' + break_at(test_source, 'Test about to signal') + continue_cmd() # Go to test_status_destroyed + test_printer(var, to_string, {'Threads known to still execute a wait function': '1'}) + + break_at(test_source, 'Test status (destroyed)') continue_cmd() # Go to test_status_destroyed test_printer(var, to_string, {'Threads known to still execute a wait function': '0'}) -- 2.25.1