From patchwork Thu Oct 6 21:43:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: develop--- via Libc-alpha X-Patchwork-Id: 58499 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A2E639540A6 for ; Thu, 6 Oct 2022 21:44:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A2E639540A6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665092654; bh=vkP+Z8YPHABiHD8+vkilS05ZR18ewQ//TjrwMrQopVU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=O8pNXfCgXqhG1T4eV5PivWTl02qLW+6tdjsvqcoY3LQge+l2tE0cGXZ+/vLgOeGh2 wUyZoM5K8MVFvTw2wiXCohG7lQWqOS1O+1tYj51A4uAdrSzP5Sm2kttQC9EfmUfE24 6S+Qow5K+GbpPoAdskOtfRbvuKmfPn6SzY7wWlxI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 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 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) To: libc-alpha@sourceware.org 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 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: malteskarupke--- via Libc-alpha From: develop--- via Libc-alpha Reply-To: malteskarupke@fastmail.fm Cc: Malte Skarupke Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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'})