public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Version comparisons in the test suite
@ 2023-03-14 14:02 Tom Tromey
  2023-03-14 14:02 ` [PATCH v2 1/3] Introduce rust_at_least helper proc Tom Tromey
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Tom Tromey @ 2023-03-14 14:02 UTC (permalink / raw)
  To: gdb-patches

This series started with the patch to introduce rust_at_least, but now
also changes version_compare to allow lists of different lengths, and
finally removes version_at_least.

Let me know what you think.

Tom



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

* [PATCH v2 1/3] Introduce rust_at_least helper proc
  2023-03-14 14:02 [PATCH 0/3] Version comparisons in the test suite Tom Tromey
@ 2023-03-14 14:02 ` Tom Tromey
  2023-03-14 14:02 ` [PATCH v2 2/3] Rewrite version_compare and rust_at_least Tom Tromey
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2023-03-14 14:02 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This adds a 'rust_at_least' helper proc, for checking the version of
the Rust compiler in use.  It then changes various tests to use this
with 'require'.
---
 gdb/testsuite/gdb.rust/rawids.exp  |  8 +-------
 gdb/testsuite/gdb.rust/unicode.exp |  8 +-------
 gdb/testsuite/gdb.rust/unsized.exp |  5 +----
 gdb/testsuite/lib/rust-support.exp | 25 +++++++++++++++++++++++++
 4 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/gdb/testsuite/gdb.rust/rawids.exp b/gdb/testsuite/gdb.rust/rawids.exp
index 976b723833e..3c65efb30c0 100644
--- a/gdb/testsuite/gdb.rust/rawids.exp
+++ b/gdb/testsuite/gdb.rust/rawids.exp
@@ -16,13 +16,7 @@
 # Test raw identifiers.
 
 load_lib rust-support.exp
-require allow_rust_tests
-
-set v [split [rust_compiler_version] .]
-if {[lindex $v 0] == 1 && [lindex $v 1] < 30} {
-    untested "raw identifiers require rust 1.30 or greater"
-    return -1
-}
+require allow_rust_tests {rust_at_least 1.30}
 
 standard_testfile .rs
 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug rust}]} {
diff --git a/gdb/testsuite/gdb.rust/unicode.exp b/gdb/testsuite/gdb.rust/unicode.exp
index 2b4766b5553..3de8fefdcc0 100644
--- a/gdb/testsuite/gdb.rust/unicode.exp
+++ b/gdb/testsuite/gdb.rust/unicode.exp
@@ -16,14 +16,8 @@
 # Test raw identifiers.
 
 load_lib rust-support.exp
-require allow_rust_tests
-
 # Non-ASCII identifiers were allowed starting in 1.53.
-set v [split [rust_compiler_version] .]
-if {[lindex $v 0] == 1 && [lindex $v 1] < 53} {
-    untested "this test requires rust 1.53 or greater"
-    return -1
-}
+require allow_rust_tests {rust_at_least 1.53}
 
 # Enable basic use of UTF-8.  LC_ALL gets reset for each testfile.
 setenv LC_ALL C.UTF-8
diff --git a/gdb/testsuite/gdb.rust/unsized.exp b/gdb/testsuite/gdb.rust/unsized.exp
index f81be8a3078..c81a93a9303 100644
--- a/gdb/testsuite/gdb.rust/unsized.exp
+++ b/gdb/testsuite/gdb.rust/unsized.exp
@@ -31,10 +31,7 @@ if {![runto ${srcfile}:$line]} {
 
 gdb_test "ptype us" " = .*V<\\\[u8\\\]>.*"
 
-set v [split [rust_compiler_version] .]
-# The necessary debuginfo generation landed in 1.60, but had a bug
-# that was fixed in 1.61.
-if {[lindex $v 0] > 1 || [lindex $v 1] >= 61} {
+if {[rust_at_least 1.61]} {
     gdb_test "print us2" " = .*Box<.*> \\\[1, 2, 3\\\]"
     gdb_test "ptype us2" "type = .*"
 }
diff --git a/gdb/testsuite/lib/rust-support.exp b/gdb/testsuite/lib/rust-support.exp
index f3739e2ce02..381871e22f4 100644
--- a/gdb/testsuite/lib/rust-support.exp
+++ b/gdb/testsuite/lib/rust-support.exp
@@ -112,3 +112,28 @@ gdb_caching_proc rust_compiler_version {} {
     }
     return 0.0
 }
+
+# A helper that checks that the rust compiler is at least the given
+# version.  This is handy for use with 'require'.
+proc rust_at_least {atleast} {
+    foreach n1 [split [rust_compiler_version] .] n2 [split $atleast .] {
+	if {$n1 == ""} {
+	    # Have 1.2, wanted 1.2.1.
+	    return 0
+	}
+	if {$n2 == ""} {
+	    # Have 1.2.1, wanted 1.2.
+	    return 1
+	}
+	if {$n1 > $n2} {
+	    # Have 1.3, wanted 1.2.
+	    return 1
+	}
+	if {$n1 < $n2} {
+	    # Have 1.1, wanted 1.2.
+	    return 0
+	}
+    }
+    # Completely equal.
+    return 1
+}
-- 
2.39.1


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

* [PATCH v2 2/3] Rewrite version_compare and rust_at_least
  2023-03-14 14:02 [PATCH 0/3] Version comparisons in the test suite Tom Tromey
  2023-03-14 14:02 ` [PATCH v2 1/3] Introduce rust_at_least helper proc Tom Tromey
@ 2023-03-14 14:02 ` Tom Tromey
  2023-03-14 14:02 ` [PATCH v2 3/3] Remove version_at_least Tom Tromey
  2023-03-29 16:09 ` [PATCH 0/3] Version comparisons in the test suite Tom Tromey
  3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2023-03-14 14:02 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This rewrites version_compare to allow the input lists to have
different lengths, then rewrites rust_at_least to use version_compare.
---
 gdb/testsuite/lib/gdb-utils.exp    | 51 ++++++++++++------------------
 gdb/testsuite/lib/rust-support.exp | 22 ++-----------
 2 files changed, 23 insertions(+), 50 deletions(-)

diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp
index fb5c953a6c4..a010e14fc04 100644
--- a/gdb/testsuite/lib/gdb-utils.exp
+++ b/gdb/testsuite/lib/gdb-utils.exp
@@ -101,49 +101,40 @@ proc gdb_get_bp_addr { num } {
     return ""
 }
 
-# Compare the version numbers in L1 to those in L2 using OP, and return
-# 1 if the comparison is true.
+# Compare the version numbers in L1 to those in L2 using OP, and
+# return 1 if the comparison is true.  OP can be "<", "<=", or "==".
+# It is ok if the lengths of the lists differ.
 
 proc version_compare { l1 op l2 } {
-    set len [llength $l1]
-    if { $len != [llength $l2] } {
-	error "l2 not the same length as l1"
-    }
-
     switch -exact $op {
 	"=="    -
+	"<="    -
 	"<"     {}
-	"<="    { return [expr [version_compare $l1 < $l2] \
-			      || [version_compare $l1 == $l2]]}
 	default { error "unsupported op: $op" }
     }
 
     # Handle ops < and ==.
-    set idx 0
-    foreach v1 $l1 {
-	set v2 [lindex $l2 $idx]
-	incr idx
-	set last [expr $len == $idx]
-
-	set cmp [expr $v1 $op $v2]
-	if { $op == "==" } {
-	    if { $cmp } {
-		continue
-	    } else {
-		return 0
-	    }
-	} else {
-	    # $op == "<".
-	    if { $cmp } {
+    foreach v1 $l1 v2 $l2 {
+	if {$v1 == ""} {
+	    # This is: "1.2 OP 1.2.1".
+	    if {$op != "=="} {
 		return 1
-	    } else {
-		if { !$last && $v1 == $v2 } {
-		    continue
-		}
-		return 0
 	    }
+	    return 0
 	}
+	if {$v2 == ""} {
+	    # This is: "1.2.1 OP 1.2".
+	    return 0
+	}
+	if {$v1 == $v2} {
+	    continue
+	}
+	return [expr $v1 $op $v2]
     }
 
+    if {$op == "<"} {
+	# They are equal.
+	return 0
+    }
     return 1
 }
diff --git a/gdb/testsuite/lib/rust-support.exp b/gdb/testsuite/lib/rust-support.exp
index 381871e22f4..e9a3c5c0543 100644
--- a/gdb/testsuite/lib/rust-support.exp
+++ b/gdb/testsuite/lib/rust-support.exp
@@ -116,24 +116,6 @@ gdb_caching_proc rust_compiler_version {} {
 # A helper that checks that the rust compiler is at least the given
 # version.  This is handy for use with 'require'.
 proc rust_at_least {atleast} {
-    foreach n1 [split [rust_compiler_version] .] n2 [split $atleast .] {
-	if {$n1 == ""} {
-	    # Have 1.2, wanted 1.2.1.
-	    return 0
-	}
-	if {$n2 == ""} {
-	    # Have 1.2.1, wanted 1.2.
-	    return 1
-	}
-	if {$n1 > $n2} {
-	    # Have 1.3, wanted 1.2.
-	    return 1
-	}
-	if {$n1 < $n2} {
-	    # Have 1.1, wanted 1.2.
-	    return 0
-	}
-    }
-    # Completely equal.
-    return 1
+    return [version_compare  [split $atleast .] \
+		<= [split [rust_compiler_version] .]]
 }
-- 
2.39.1


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

* [PATCH v2 3/3] Remove version_at_least
  2023-03-14 14:02 [PATCH 0/3] Version comparisons in the test suite Tom Tromey
  2023-03-14 14:02 ` [PATCH v2 1/3] Introduce rust_at_least helper proc Tom Tromey
  2023-03-14 14:02 ` [PATCH v2 2/3] Rewrite version_compare and rust_at_least Tom Tromey
@ 2023-03-14 14:02 ` Tom Tromey
  2023-03-29 16:09 ` [PATCH 0/3] Version comparisons in the test suite Tom Tromey
  3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2023-03-14 14:02 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

version_at_least is a less capable variant of version_compare, so this
patch removes it.
---
 gdb/testsuite/lib/gdb.exp | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 23277c4ab79..3e028372191 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -1478,25 +1478,13 @@ proc gdb_test { args } {
     return [gdb_test_multiple $command $message {*}$opts $user_code]
 }
 
-# Return 1 if version MAJOR.MINOR is at least AT_LEAST_MAJOR.AT_LEAST_MINOR.
-proc version_at_least { major minor at_least_major at_least_minor} {
-    if { $major > $at_least_major } {
-        return 1
-    } elseif { $major == $at_least_major \
-		   && $minor >= $at_least_minor } {
-        return 1
-    } else {
-        return 0
-    }
-}
-
 # Return 1 if tcl version used is at least MAJOR.MINOR
 proc tcl_version_at_least { major minor } {
     global tcl_version
     regexp {^([0-9]+)\.([0-9]+)$} $tcl_version \
 	dummy tcl_version_major tcl_version_minor
-    return [version_at_least $tcl_version_major $tcl_version_minor \
-		$major $minor]
+    return [version_compare [list $major $minor] \
+		<= [list $tcl_version_major $tcl_version_minor]]
 }
 
 if { [tcl_version_at_least 8 5] == 0 } {
@@ -6869,7 +6857,7 @@ proc readelf_prints_pie { } {
     # flag is printed by readelf, but we cannot reliably construct a PIE
     # executable if the multilib_flags dictate otherwise
     # (--target_board=unix/-no-pie/-fno-PIE).
-    return [version_at_least $major $minor 2 26]
+    return [version_compare {2 26} <= [list $major $minor]]
 }
 
 # Return 1 if EXECUTABLE is a Position Independent Executable, 0 if it is not,
-- 
2.39.1


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

* Re: [PATCH 0/3] Version comparisons in the test suite
  2023-03-14 14:02 [PATCH 0/3] Version comparisons in the test suite Tom Tromey
                   ` (2 preceding siblings ...)
  2023-03-14 14:02 ` [PATCH v2 3/3] Remove version_at_least Tom Tromey
@ 2023-03-29 16:09 ` Tom Tromey
  3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2023-03-29 16:09 UTC (permalink / raw)
  To: Tom Tromey via Gdb-patches; +Cc: Tom Tromey

>>>>> "Tom" == Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> This series started with the patch to introduce rust_at_least, but now
Tom> also changes version_compare to allow lists of different lengths, and
Tom> finally removes version_at_least.

I'm checking this now.

Tom

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

end of thread, other threads:[~2023-03-29 16:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14 14:02 [PATCH 0/3] Version comparisons in the test suite Tom Tromey
2023-03-14 14:02 ` [PATCH v2 1/3] Introduce rust_at_least helper proc Tom Tromey
2023-03-14 14:02 ` [PATCH v2 2/3] Rewrite version_compare and rust_at_least Tom Tromey
2023-03-14 14:02 ` [PATCH v2 3/3] Remove version_at_least Tom Tromey
2023-03-29 16:09 ` [PATCH 0/3] Version comparisons in the test suite Tom Tromey

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