public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [pushed] [gdb/testsuite] Factor out proc linux_kernel_version
@ 2023-02-14 10:54 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2023-02-14 10:54 UTC (permalink / raw)
  To: gdb-patches

Factor out new proc linux_kernel_version from test-case
gdb.arch/i386-pkru.exp.

Tested on x86_64-linux.
---
 gdb/testsuite/gdb.arch/i386-pkru.exp | 20 ++++++--------------
 gdb/testsuite/lib/gdb.exp            | 23 +++++++++++++++++++++++
 2 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/gdb/testsuite/gdb.arch/i386-pkru.exp b/gdb/testsuite/gdb.arch/i386-pkru.exp
index 90d8c1d9d4c..1f047df68ef 100644
--- a/gdb/testsuite/gdb.arch/i386-pkru.exp
+++ b/gdb/testsuite/gdb.arch/i386-pkru.exp
@@ -59,20 +59,12 @@ if { !$supports_pkru } {
 # the PKRU using ptrace, see commit 4a804c4f8356 ("x86/fpu: Allow PKRU to be
 # (once again) written by ptrace.").
 set have_xfail 0
-if { [istarget *-*-linux*] } {
-    set res [remote_exec target "uname -r"]
-    set status [lindex $res 0]
-    set output [lindex $res 1]
-
-    set re ^($decimal)\\.($decimal)\\.($decimal)
-    if { $status == 0
-	 && [regexp $re $output dummy v1 v2 v3] == 1 } {
-	set v [list $v1 $v2 $v3]
-	set have_xfail \
-	    [expr \
-		 [version_compare [list 5 14 0] <= $v] \
-		 && [version_compare $v < [list 6 2 0]]]
-    }
+set v [linux_kernel_version]
+if { $v != {} } {
+    set have_xfail \
+	[expr \
+	     [version_compare [list 5 14 0] <= $v] \
+	     && [version_compare $v < [list 6 2 0]]]
 }
 
 # Test pkru register at startup
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 7f98f080328..e48228ed4f6 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -9374,5 +9374,28 @@ proc has_dependency { file dep } {
     return [regexp $dep $output]
 }
 
+# Detect linux kernel version and return as list of 3 numbers: major, minor,
+# and patchlevel.  On failure, return an empty list.
+
+gdb_caching_proc linux_kernel_version {
+    if { ![istarget *-*-linux*] } {
+	return {}
+    }
+
+    set res [remote_exec target "uname -r"]
+    set status [lindex $res 0]
+    set output [lindex $res 1]
+    if { $status != 0 } {
+	return {}
+    }
+
+    set re ^($::decimal)\\.($::decimal)\\.($::decimal)
+    if { [regexp $re $output dummy v1 v2 v3] != 1 } {
+	return {}
+    }
+
+    return [list $v1 $v2 $v3]
+}
+
 # Always load compatibility stuff.
 load_lib future.exp

base-commit: 0d79a2a8e2d91fc258ac795c19c13e3ab505a6c2
-- 
2.35.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-14 10:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14 10:54 [pushed] [gdb/testsuite] Factor out proc linux_kernel_version Tom de Vries

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).