[pushed,1/2,gdb/testsuite] Fix gdb.arch/ppc64-symtab-cordic.exp without bzip2

Message ID 20221116102028.18591-1-tdevries@suse.de
State Committed
Commit 24eb586f5c5ec119424b7bede66ada9cc94cace4
Headers
Series [pushed,1/2,gdb/testsuite] Fix gdb.arch/ppc64-symtab-cordic.exp without bzip2 |

Commit Message

Tom de Vries Nov. 16, 2022, 10:20 a.m. UTC
  After de-installing bzip2, I run into:
...
Running ppc64-symtab-cordic.exp ...
sh: bzip2: command not found
PATH: gdb.arch/ppc64-symtab-cordic.exp: failed bzip2 for \
  src/gdb/testsuite/gdb.arch/cordic.ko.bz2
...

Fix these by:
- using remote_exec instead of catch system, and
- using file tail in the untested message.

I've tried making output redirection work with remote_exec, but that seems to
be broken, so we now:
- copy the file $f.bz2 into the desired location $dir/$f.bz2, and
- decompress the bz2 file using "bzip2 -df $dir/$f.bz2", resulting in a file
  $dir/$f.

Factor out new function decompress_bz2 to make the test-case less verbose, and
also use it in gdb.arch/i386-biarch-core.exp.

Tested on x86_64-linux, without and with bzip2 installed.
---
 gdb/testsuite/gdb.arch/i386-biarch-core.exp   |  5 +++--
 .../gdb.arch/ppc64-symtab-cordic.exp          | 13 ++++++-----
 gdb/testsuite/lib/gdb.exp                     | 22 +++++++++++++++++++
 3 files changed, 32 insertions(+), 8 deletions(-)


base-commit: a715464cd2e25c8bf46190cc8bde9267c9ab6ac0
  

Patch

diff --git a/gdb/testsuite/gdb.arch/i386-biarch-core.exp b/gdb/testsuite/gdb.arch/i386-biarch-core.exp
index 607a3aaaf85..e1f65900379 100644
--- a/gdb/testsuite/gdb.arch/i386-biarch-core.exp
+++ b/gdb/testsuite/gdb.arch/i386-biarch-core.exp
@@ -45,14 +45,15 @@  gdb_test_multiple "complete set gnutarget " $test {
 }
 
 set corebz2file ${srcdir}/${subdir}/${testfile}.core.bz2
-set corefile [standard_output_file ${testfile}.core]
 # Entry point of the original executable.
 set address 0x400078
 
-if {[catch "system \"bzip2 -dc ${corebz2file} >${corefile}\""] != 0} {
+set corefile [decompress_bz2 $corebz2file]
+if { $corefile == "" } {
     untested "failed bzip2"
     return -1
 }
+
 file stat ${corefile} corestat
 if {$corestat(size) != 102400} {
     untested "bzip2 produces invalid result"
diff --git a/gdb/testsuite/gdb.arch/ppc64-symtab-cordic.exp b/gdb/testsuite/gdb.arch/ppc64-symtab-cordic.exp
index 5d2e1255d45..4464177b547 100644
--- a/gdb/testsuite/gdb.arch/ppc64-symtab-cordic.exp
+++ b/gdb/testsuite/gdb.arch/ppc64-symtab-cordic.exp
@@ -24,16 +24,17 @@  if { [lsearch -exact $supported_archs "powerpc:common64"] == -1 } {
 standard_testfile
 
 set kobz2file ${srcdir}/${subdir}/cordic.ko.bz2
-set kofile [standard_output_file cordic.ko]
 set kodebugbz2file ${srcdir}/${subdir}/cordic.ko.debug.bz2
-set kodebugfile [standard_output_file cordic.ko.debug]
 
-if {[catch "system \"bzip2 -dc ${kobz2file} >${kofile}\""] != 0} {
-    untested "failed bzip2 for ${kobz2file}"
+set kofile [decompress_bz2 $kobz2file]
+if { $kofile == "" } {
+    untested "failed bzip2 for [file tail $kobz2file]"
     return -1
 }
-if {[catch "system \"bzip2 -dc ${kodebugbz2file} >${kodebugfile}\""] != 0} {
-    untested "failed bzip2 for ${kodebugbz2file}"
+
+set kodebugfile [decompress_bz2 $kodebugbz2file]
+if { $kodebugfile == "" } {
+    untested "failed bzip2 for [file tail $kodebugbz2file]"
     return -1
 }
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 698b3f4bd79..f540770189d 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -9291,5 +9291,27 @@  gdb_caching_proc have_epilogue_line_info {
     }
 }
 
+# Decompress file BZ2, and return it.
+
+proc decompress_bz2 { bz2 } {
+    set copy [standard_output_file [file tail $bz2]]
+    set copy [remote_download build $bz2 $copy]
+    if { $copy == "" } {
+	return $copy
+    }
+
+    set res [remote_exec build "bzip2" "-df $copy"]
+    if { [lindex $res 0] == -1 } {
+	return ""
+    }
+
+    set copy [regsub {.bz2$} $copy ""]
+    if { ![remote_file build exists $copy] } {
+	return ""
+    }
+
+    return $copy
+}
+
 # Always load compatibility stuff.
 load_lib future.exp