public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/testsuite: XFAIL some gdb.base/fileio.exp
@ 2023-08-11 10:21 Guinevere Larsen
  2023-08-11 13:19 ` Lancelot SIX
  2023-08-14 10:24 ` [PATCH v2] " Guinevere Larsen
  0 siblings, 2 replies; 9+ messages in thread
From: Guinevere Larsen @ 2023-08-11 10:21 UTC (permalink / raw)
  To: gdb-patches; +Cc: Guinevere Larsen

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.
---
 gdb/testsuite/gdb.base/fileio.exp |  9 ++++++++-
 gdb/testsuite/lib/gdb.exp         | 11 +++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.base/fileio.exp b/gdb/testsuite/gdb.base/fileio.exp
index 33c88d064c4..e1c7a7f955e 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 36bf738c667..de98f8bb2ac 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -9952,5 +9952,16 @@ proc have_host_locale { locale } {
     return [expr $idx != -1]
 }
 
+# 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 [exec id]
+
+    regexp -all ".*uid=(\[0-9\]+).*" $user user uid
+
+    return [expr $uid == 0]
+}
+
 # Always load compatibility stuff.
 load_lib future.exp
-- 
2.41.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-10-04 15:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-11 10:21 [PATCH] gdb/testsuite: XFAIL some gdb.base/fileio.exp Guinevere Larsen
2023-08-11 13:19 ` Lancelot SIX
2023-08-11 14:26   ` Guinevere Larsen
2023-08-14 10:24 ` [PATCH v2] " Guinevere Larsen
2023-09-14 13:12   ` [PING][PATCH " Guinevere Larsen
2023-09-26 13:21   ` [PATCH " Tom de Vries
2023-10-04 14:02   ` [PATCH v3] " Guinevere Larsen
2023-10-04 15:33     ` Tom de Vries
2023-10-04 15:47       ` Guinevere Larsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).