From patchwork Wed Oct 4 14:02:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guinevere Larsen X-Patchwork-Id: 77120 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 E2B66385AC26 for ; Wed, 4 Oct 2023 14:06:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2B66385AC26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1696428399; bh=UuFHRYQXDafCr4+3b2lu7nIBqvz97foLXZQu2gvARtk=; 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=NpRY8P/SzpEb7Gtvu1qOVXe745pH37n52jgC6MOngZHvmTJEFCyvbbe6nBDKBqCft 3ADtVl377KSSxDzz5psjl6p8KlPyEHSZqZhvOQ873+M/Emb2WNN6fy16v6rfD7Xvbs yUuSL3zANFZV3fE/XH6hgU2sRrJt6oh4qh7F2URk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E40D83858C52 for ; Wed, 4 Oct 2023 14:06:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E40D83858C52 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-696-W7fnBGrBNPGGXPCTx3a4qg-1; Wed, 04 Oct 2023 10:06:08 -0400 X-MC-Unique: W7fnBGrBNPGGXPCTx3a4qg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B34D95BC41 for ; Wed, 4 Oct 2023 14:06:08 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A9D5240C6EA8; Wed, 4 Oct 2023 14:06:07 +0000 (UTC) To: gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: [PATCH v3] gdb/testsuite: XFAIL some gdb.base/fileio.exp Date: Wed, 4 Oct 2023 16:02:48 +0200 Message-ID: <20231004140247.16091-2-blarsen@redhat.com> In-Reply-To: <20230814102449.203616-2-blarsen@redhat.com> References: <20230814102449.203616-2-blarsen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.5 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 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Guinevere Larsen via Gdb-patches From: Guinevere Larsen Reply-To: Guinevere Larsen Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Some gdb.base/fileio.exp tests expect the inferior to not have write access to some files. If the test is being run as root, this is never possible. This commit adds a way to identify if the user is root and xfails the tests that expect no write access. --- Changes for v3: * root_user can now identify if the "id" command failed. It returns that the user is not root, so that issues are more easily identified. * Fix issues pointed out by Tom de Vries. Changes for v2: * root_user now uses remote_exec instead of exec to see the uid of the inferior --- gdb/testsuite/gdb.base/fileio.exp | 9 ++++++++- gdb/testsuite/lib/gdb.exp | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/gdb.base/fileio.exp b/gdb/testsuite/gdb.base/fileio.exp index 33c88d064c4..6a708ed00ed 100644 --- a/gdb/testsuite/gdb.base/fileio.exp +++ b/gdb/testsuite/gdb.base/fileio.exp @@ -17,7 +17,6 @@ require {!target_info exists gdb,nofileio} - standard_testfile if {[is_remote host]} { @@ -75,6 +74,10 @@ gdb_test "continue" ".*" "" catch "system \"chmod -f -w [standard_output_file nowrt.fileio.test]\"" +# If the user is root, we will always have write permission. +if { [root_user] } { + setup_xfail *-*-* +} gdb_test continue \ "Continuing\\..*open 5:.*EACCES$stop_msg" \ "Open for write but no write permission returns EACCES" @@ -240,6 +243,10 @@ gdb_test continue \ if [ishost *cygwin*] { setup_xfail "*-*-*" } +# If the user is root, we will always have write permission. +if { [root_user] } { + setup_xfail *-*-* +} gdb_test continue \ "Continuing\\..*unlink 2:.*EACCES$stop_msg" \ "Unlinking a file in a directory w/o write access returns EACCES" diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index de22da8d8a8..5b90b8af3b8 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -9981,5 +9981,25 @@ gdb_caching_proc have_system_header { file } { return [gdb_can_simple_compile have_system_header_$name $src object] } +# Return 1 if the test is being run as root, 0 otherwise. + +gdb_caching_proc root_user {} { + # ID outputs to stdout, we have to use exec to capture it here. + set user [remote_exec target id] + + regexp -all "(-?\[0-9\]+).*" $user user ret_val + + # If ret_val is not 0, we couldn't run `id` on the target for some + # reason. Return that we are not root, so problems are easier to + # spot. + if {[expr $ret_val != 0]} { + return 0 + } + + regexp -all ".*uid=(\[0-9\]+).*" $user user uid + + return [expr $uid == 0] +} + # Always load compatibility stuff. load_lib future.exp