From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696428370; 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: in-reply-to:in-reply-to:references:references; bh=UuFHRYQXDafCr4+3b2lu7nIBqvz97foLXZQu2gvARtk=; b=PY7bRcTQ/unvcStoST7MGlphR8nUsCBhaq2pBNahvTgEXOq1lqM+0pD/P71v+AEJdk/E1h OcaDHLU4fHrA2f27lNYOtZkJBzDc4n0m7496zyzBEgpubfbL7aLtawUjX9pQNzI83CsDjl 7h0hBHur3o3IxmLxAGogc31IzOUu9A4= 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) From: Guinevere Larsen 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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 -- 2.41.0