From patchwork Mon Jan 30 04:45:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 63903 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 7ABA938582BE for ; Mon, 30 Jan 2023 04:47:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7ABA938582BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675054026; bh=iWwMV1Gi9uSU9JBvHPYGf2sqQAqYOYs5ehhavy0VFw4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ORc+KSPsDL2VbPNwCCk7G9sRwAYb0En0399l5z+DCFyeMTb3oh2GFE0h0h93GorcD evpOXAVFkI7TZnvysnF2A2ab/oRdcIwrZ5yS3Pyb2RwqmLHoYucsCJji+BXZzrFGG5 H7X5BoMIE/JsFEMPVCFZZDVQVMaS98Grv+9nIl/k= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id F0B913858409 for ; Mon, 30 Jan 2023 04:46:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F0B913858409 Received: by mail-ot1-x330.google.com with SMTP id r17-20020a056830449100b0068bb088317aso2406658otv.12 for ; Sun, 29 Jan 2023 20:46:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iWwMV1Gi9uSU9JBvHPYGf2sqQAqYOYs5ehhavy0VFw4=; b=l0IhLnlQQ3OcP6Y5OQ1dFrAXG3gvx7uqB27vRmifrQGFSqmFVkeztKQ43auo9JAZBg fDC6xgdTTG6EgwSAijS8h6MI300FVy1u6d10r4za9xz1AL1GhMLvZ5gaNXGfe8nnvP6Q Xl6Hu9kktkI9oM9d5VVOteoSNB547n6wD/wzZJ5ytvRCQZ0+zmPu2y7TK/Xuq4VN3skD 6gxQyISJmEA9xh8L+bV/OBzHoKoCYkCNFU1ewWQoyY4rqZ0UV5xY7w+KkKc1cFgJTMQ6 TcYJ/YIIYDAticnEEKSa9i1LNG+1UaDTWTOiEXsgmgWGL0ogAaNlzk93moniGhYe6lKW s2dQ== X-Gm-Message-State: AO0yUKUUNHICZIIAV7PIjJruAGrV7K8Vfuf8SU/wl8czC5o5aFk/HBJ/ GeWMog5T0sfIq+HTxbwgPzNzf9PpZYJ+neYO X-Google-Smtp-Source: AK7set+VBjgb3PeNb7DPtN/mmDnByxCF6ylrevnEcS3AIcrNJLW/5wZa4V7EorCZ3H/qxRAPyzTRMQ== X-Received: by 2002:a05:6830:160f:b0:68b:b96b:ec5 with SMTP id g15-20020a056830160f00b0068bb96b0ec5mr5218329otr.9.1675053960234; Sun, 29 Jan 2023 20:46:00 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:df99:10bd:7dca:b2e9]) by smtp.gmail.com with ESMTPSA id c9-20020a056830000900b0068bd3f19016sm445650otp.66.2023.01.29.20.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Jan 2023 20:45:59 -0800 (PST) To: gdb-patches@sourceware.org Cc: Thiago Jung Bauermann Subject: [PATCH v3 8/8] gdb/testsuite: Add test to exercise multi-threaded AArch64 SVE inferiors Date: Mon, 30 Jan 2023 04:45:18 +0000 Message-Id: <20230130044518.3322695-9-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230130044518.3322695-1-thiago.bauermann@linaro.org> References: <20230130044518.3322695-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Thiago Jung Bauermann via Gdb-patches From: Thiago Jung Bauermann Reply-To: Thiago Jung Bauermann Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This testcase exercises two scenarios with a multi-threaded inferior, one proposed by Luis and another one proposed by Simon. In the first scenario, one of the inferior threads changes its vector length and then hits a breakpoint. In the second one, the main thread hits a breakpoint and then GDB switches to another thread. --- gdb/testsuite/gdb.arch/aarch64-sve-threads.c | 125 ++++++++++++++++++ .../gdb.arch/aarch64-sve-threads.exp | 70 ++++++++++ 2 files changed, 195 insertions(+) create mode 100644 gdb/testsuite/gdb.arch/aarch64-sve-threads.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-sve-threads.exp diff --git a/gdb/testsuite/gdb.arch/aarch64-sve-threads.c b/gdb/testsuite/gdb.arch/aarch64-sve-threads.c new file mode 100644 index 000000000000..7fad77008da3 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sve-threads.c @@ -0,0 +1,125 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Exercise AArch64's Scalable Vector Extension in a multi-threaded program. */ + +#include +#include +#include +#include +#include +#include + +/* For one of the tests, the thread needs to sleep after setting the vector + length. This variable is set by GDB. */ +volatile bool should_sleep = false; + +/* Used to signal to the main thread that the additional thread's vector length + was changed. */ +sem_t vl_changed; + +/* Start routine for the additional thread. Sets a new vector length, sleeps if + requested then restores the original vector length. */ + +static void * +thread_function (void *unused) +{ + unsigned int vl; + int rc; + + rc = prctl (PR_SVE_GET_VL, 0, 0, 0, 0); + if (rc < 0) + { + perror ("FAILED to PR_SVE_GET_VL"); + sem_post (&vl_changed); + return NULL; + } + + vl = rc & PR_SVE_VL_LEN_MASK; + + /* Decrease vector length by 16 bytes. */ + vl -= 16; + + rc = prctl (PR_SVE_SET_VL, vl, 0, 0, 0, 0); + if (rc < 0) + { + perror ("FAILED to PR_SVE_SET_VL"); + sem_post (&vl_changed); + return NULL; + } + + /* Let the main thread continue. */ + rc = sem_post (&vl_changed); + if (rc != 0) + { + perror ("sem_post"); + return NULL; + } + + if (should_sleep) + sleep (10); + + /* Restore original vector length. */ + vl += 16; /* break here 1 */ + + rc = prctl (PR_SVE_SET_VL, vl, 0, 0, 0, 0); + if (rc < 0) + { + perror ("FAILED to PR_SVE_SET_VL"); + return NULL; + } + + return NULL; /* break here 2 */ +} + +int +main (int argc, char **argv) +{ + pthread_t thread; + int rc; + + rc = sem_init (&vl_changed, 0, 0); + if (rc != 0) + { + perror ("sem_init"); + return 1; + } + + rc = pthread_create (&thread, NULL, thread_function, NULL); + if (rc != 0) + { + perror ("pthread_create"); + return 1; + } + + /* Wait until the additional thread changes it's vector length. */ + rc = sem_wait (&vl_changed); + if (rc != 0) + { + perror ("sem_wait"); + return 1; + } + + rc = pthread_join (thread, NULL); /* break here 3 */ + if (rc != 0) + { + perror ("pthread_join"); + return 1; + } + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/aarch64-sve-threads.exp b/gdb/testsuite/gdb.arch/aarch64-sve-threads.exp new file mode 100644 index 000000000000..48197650e1de --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sve-threads.exp @@ -0,0 +1,70 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test a multi-threaded binary that uses SVE and changes the SVE vector length +# in the additional thread. + +if {[skip_aarch64_sve_tests]} { + verbose "Skipping ${gdb_test_file_name}." + return +} + +standard_testfile +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ + {debug pthreads}] == -1} { + return -1 +} + +if ![runto_main] { + return -1 +} + +# Stop after the additional thread has changed its vector length. +gdb_breakpoint [gdb_get_line_number "break here 1"] +gdb_continue_to_breakpoint "break here 1" + +# If GDB and gdbserver don't agree on the thread's vector length, this command +# will fail. +gdb_test "print \$z0" " = {q = {u = {.*}}}" "print z0 register" + +# Stop after the additional thread has restored its original vector length. +gdb_breakpoint [gdb_get_line_number "break here 2"] +gdb_continue_to_breakpoint "break here 2" + +# Test that going back to the original vector length doesn't confuse GDB or +# gdbserver. +gdb_test "print \$z0" " = {q = {u = {.*}}}" "print z0 register again" + +# Restart GDB to test a scenario where GDB switches to a thread that changed its +# vector length but hasn't hit any breakpoints yet. +clean_restart ${binfile} + +if ![runto_main] { + return -1 +} + +# Make the thread sleep after changing its vector length. +gdb_test_no_output -nopass "set var should_sleep = 1" "make thread sleep" + +# Stop after the additional thread has been created. +gdb_breakpoint [gdb_get_line_number "break here 3"] +gdb_continue_to_breakpoint "break here 3" + +# The regexp accounts for two lines of output after the "Switching to thread" message. +gdb_test_lines "thread 2" "switch to another thread" \ + {\[Switching to thread 2 \(.*\)\]\r\n#0 [[:print:]]+} + +# Make sure everything is still fine. +gdb_test "print \$z0" " = {q = {u = {.*}}}" "print z0 register in thread 2"