From patchwork Mon Aug 26 16:36:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1976917 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=aMuJGWtZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.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 4WsxDr3P7fz1yYl for ; Tue, 27 Aug 2024 02:38:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AC938385DDC7 for ; Mon, 26 Aug 2024 16:38:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.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 9EBC8385E830 for ; Mon, 26 Aug 2024 16:36:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9EBC8385E830 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 9EBC8385E830 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=1724690178; cv=none; b=K6OVIk6MDiGxdbo+Zlj2mr0X6aAXwMNzH8HRgmVBDprQdeDn3+CXI8PVhfjIy6Mc6Iu0/yUnAHK84l527MhmZXkMKcIIUjaZOxxUsA1TbVboWVYRxA/WxOsEN8iiS+R3+3nWF0gBfnujwRwMqR0hJsf34wx3MgYZmKqnTNvgbBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724690178; c=relaxed/simple; bh=eWdtwtL4K2PrV3RgrDnsz7U6zlhd+hNm3serbuGWX88=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=vMS+ZFrTCsYnIEOOxxVJUvZv/pk1dh8x10M19DvUaUtCF4MuCu5ss27IoLhk7s3SpuBguPFBNV+OAG52QZDghHnPHNADlD8ZjQHRVx4clBWkxS+xJe3qxH1rYSFDxJ0MgQKxYLpsu7sZBRnULN4vNAdf0Otye0zZCCMKcse3Qsk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724690175; 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: content-transfer-encoding:content-transfer-encoding; bh=amGR35tAjsaMHgl8yqxNwMboKHIXL3i3j868cSDVC/s=; b=aMuJGWtZv1RyQpA6BXDN1ncbnABWIYwOZVXACUkgwrDHOzzp5PdL6ML/CO96VBQ8UaZ6aa WMmNCmutDyNRpnNnGPBH7L3q+FRLXy5sSv8x6yoS3ZVsTqVPWAUgVYpA40e7QacB/lVD8H 3rmzDFJhnRH+aeBIGHBlJhV2d+eWebk= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-mCmOB2swPYe3OrdPmaul2A-1; Mon, 26 Aug 2024 12:36:12 -0400 X-MC-Unique: mCmOB2swPYe3OrdPmaul2A-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 353181955BED for ; Mon, 26 Aug 2024 16:36:12 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.16.43]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3CE461956053; Mon, 26 Aug 2024 16:36:11 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] testsuite: add event IDs to multithreaded event plugin test Date: Mon, 26 Aug 2024 12:36:09 -0400 Message-Id: <20240826163609.2393671-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Add test coverage of "%@" in event messages in a multithreaded execution path. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r15-3199-g6a1c359e28442c. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic-test-paths-multithreaded-inline-events.c: Update expected output. * gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py: Likewise. * gcc.dg/plugin/diagnostic-test-paths-multithreaded-separate-events.c: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_paths.c (test_diagnostic_path::add_event_2): Return the id of the added event. (test_diagnostic_path::add_event_2_with_event_id): New. (example_4): Add event IDs to the deadlock messages indicating where the locks where acquired. Signed-off-by: David Malcolm --- ...c-test-paths-multithreaded-inline-events.c | 4 +- ...agnostic-test-paths-multithreaded-sarif.py | 4 +- ...test-paths-multithreaded-separate-events.c | 4 +- .../plugin/diagnostic_plugin_test_paths.c | 46 +++++++++++++------ 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-inline-events.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-inline-events.c index 333ef7359440..b306bcc1a0f3 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-inline-events.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-inline-events.c @@ -58,7 +58,7 @@ Thread: 'Thread 1' | NN | acquire_lock_b (); | | ^~~~~~~~~~~~~~~~~ | | | - | | (5) deadlocked due to waiting for lock b in thread 1... + | | (5) deadlocked due to waiting for lock b in thread 1 (acquired by thread 2 at (4))... | Thread: 'Thread 2' @@ -67,6 +67,6 @@ Thread: 'Thread 2' | NN | acquire_lock_a (); | | ^~~~~~~~~~~~~~~~~ | | | - | | (6) ...whilst waiting for lock a in thread 2 + | | (6) ...whilst waiting for lock a in thread 2 (acquired by thread 1 at (2)) | { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py index cff78aa8ac8e..cb00faf1532a 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py @@ -95,7 +95,7 @@ def test_result(sarif): == "lock a is now held by thread 1" assert tf0['locations'][2]['executionOrder'] == 5 assert tf0['locations'][2]['location']['message']['text'] \ - == "deadlocked due to waiting for lock b in thread 1..." + == "deadlocked due to waiting for lock b in thread 1 (acquired by thread 2 at (4))..." assert len(tf1['locations']) == 3 assert tf1['locations'][0]['executionOrder'] == 3 @@ -106,4 +106,4 @@ def test_result(sarif): == "lock b is now held by thread 2" assert tf1['locations'][2]['executionOrder'] == 6 assert tf1['locations'][2]['location']['message']['text'] \ - == "...whilst waiting for lock a in thread 2" + == "...whilst waiting for lock a in thread 2 (acquired by thread 1 at (2))" diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-separate-events.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-separate-events.c index 914918bb9e16..90464320b8e7 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-separate-events.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-separate-events.c @@ -7,12 +7,12 @@ extern void acquire_lock_b(void); void foo () { /* { dg-message "\\(1\\) entering 'foo'" } */ acquire_lock_a (); /* { dg-message "\\(2\\) lock a is now held by thread 1" } */ - acquire_lock_b (); /* { dg-message "\\(5\\) deadlocked due to waiting for lock b in thread 1\.\.\." } */ + acquire_lock_b (); /* { dg-message "\\(5\\) deadlocked due to waiting for lock b in thread 1 \\(acquired by thread 2 at \\(4\\)\\)\.\.\." } */ } void bar () { /* { dg-message "\\(3\\) entering 'bar'" } */ acquire_lock_b (); /* { dg-message "\\(4\\) lock b is now held by thread 2" } */ acquire_lock_a (); /* { dg-warning "deadlock due to inconsistent lock acquisition order" } */ - /* { dg-message "\\(6\\) \.\.\.whilst waiting for lock a in thread 2" "" { target *-*-* } .-1 } */ + /* { dg-message "\\(6\\) \.\.\.whilst waiting for lock a in thread 2 \\(acquired by thread 1 at \\(2\\)\\)" "" { target *-*-* } .-1 } */ } diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c index efa4ec475ab3..43e16a6fce11 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c @@ -217,14 +217,26 @@ class test_diagnostic_path : public simple_diagnostic_path : simple_diagnostic_path (event_pp) { } - void add_event_2 (event_location_t evloc, int stack_depth, - const char *desc, - diagnostic_thread_id_t thread_id = 0) + diagnostic_event_id_t + add_event_2 (event_location_t evloc, int stack_depth, + const char *desc, + diagnostic_thread_id_t thread_id = 0) { gcc_assert (evloc.m_fun); - add_thread_event (thread_id, evloc.m_loc, evloc.m_fun->decl, + return add_thread_event (thread_id, evloc.m_loc, evloc.m_fun->decl, stack_depth, desc); } + diagnostic_event_id_t + add_event_2_with_event_id (event_location_t evloc, int stack_depth, + const char *fmt, + diagnostic_thread_id_t thread_id, + diagnostic_event_id_t event_id) + { + gcc_assert (evloc.m_fun); + // FMT is assumed to have a single %@ argument + return add_thread_event (thread_id, evloc.m_loc, evloc.m_fun->decl, + stack_depth, fmt, &event_id); + } void add_entry (event_location_t evloc, int stack_depth, const char *funcname, diagnostic_thread_id_t thread_id = 0) @@ -487,17 +499,23 @@ example_4 () diagnostic_thread_id_t thread_1 = path.add_thread ("Thread 1"); diagnostic_thread_id_t thread_2 = path.add_thread ("Thread 2"); path.add_entry (entry_to_foo, 0, "foo", thread_1); - path.add_event_2 (call_to_acquire_lock_a_in_foo, 1, - "lock a is now held by thread 1", thread_1); + diagnostic_event_id_t event_a_acquired + = path.add_event_2 (call_to_acquire_lock_a_in_foo, 1, + "lock a is now held by thread 1", thread_1); path.add_entry (entry_to_bar, 0, "bar", thread_2); - path.add_event_2 (call_to_acquire_lock_b_in_bar, 1, - "lock b is now held by thread 2", thread_2); - path.add_event_2 (call_to_acquire_lock_b_in_foo, 1, - "deadlocked due to waiting for lock b in thread 1...", - thread_1); - path.add_event_2 (call_to_acquire_lock_a_in_bar, 1, - "...whilst waiting for lock a in thread 2", - thread_2); + diagnostic_event_id_t event_b_acquired + = path.add_event_2 (call_to_acquire_lock_b_in_bar, 1, + "lock b is now held by thread 2", thread_2); + path.add_event_2_with_event_id + (call_to_acquire_lock_b_in_foo, 1, + "deadlocked due to waiting for lock b in thread 1" + " (acquired by thread 2 at %@)...", + thread_1, event_b_acquired); + path.add_event_2_with_event_id + (call_to_acquire_lock_a_in_bar, 1, + "...whilst waiting for lock a in thread 2" + " (acquired by thread 1 at %@)", + thread_2, event_a_acquired); richloc.set_path (&path); diagnostic_metadata m;