[1/1] testsuite, trace: add guards if In-Process Agent library is not found

Message ID 20240723093218.1545186-2-stephan.rohr@intel.com
State New
Headers
Series add guards if In-Process Agent library is not found |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Stephan Rohr July 23, 2024, 9:32 a.m. UTC
  Several tests in gdb.trace trigger TCL errors if the In-Process Agent
library is not found, e.g.:

  Running gdb/testsuite/gdb.trace/change-loc.exp ...
  ERROR: tcl error sourcing gdb/testsuite/gdb.trace/change-loc.exp.
  ERROR: error copying "gdb/gdb/testsuite/../../gdbserver/libinproctrace.so":
	 no such file or directory
      while executing
  "file copy -force $fromfile $tofile"
      (procedure "gdb_remote_download" line 29)
      invoked from within
  "gdb_remote_download target $target_file"
      (procedure "gdb_download_shlib" line 6)
      invoked from within
  "gdb_download_shlib $file"
      (procedure "gdb_load_shlib" line 2)
      invoked from within
  "gdb_load_shlib $libipa"
      (file "gdb/testsuite/gdb.trace/change-loc.exp" line 354)
      invoked from within
  "source gdb/testsuite/gdb.trace/change-loc.exp"
      ("uplevel" body line 1)
      invoked from within
  "uplevel #0 source gdb/testsuite/gdb.trace/change-loc.exp"
      invoked from within
  "catch "uplevel #0 source $test_file_name""

Protect against this error by checking if the library is available and
return 'unsupported' if not.
---
 gdb/testsuite/gdb.trace/change-loc.exp           | 4 ++++
 gdb/testsuite/gdb.trace/ftrace-lock.exp          | 7 ++++++-
 gdb/testsuite/gdb.trace/ftrace.exp               | 7 ++++++-
 gdb/testsuite/gdb.trace/pending.exp              | 4 ++++
 gdb/testsuite/gdb.trace/range-stepping.exp       | 4 ++++
 gdb/testsuite/gdb.trace/strace.exp               | 4 ++++
 gdb/testsuite/gdb.trace/trace-break.exp          | 4 ++++
 gdb/testsuite/gdb.trace/trace-condition.exp      | 7 ++++++-
 gdb/testsuite/gdb.trace/trace-enable-disable.exp | 7 ++++++-
 gdb/testsuite/gdb.trace/trace-mt.exp             | 4 ++++
 gdb/testsuite/gdb.trace/tspeed.exp               | 8 ++++++--
 gdb/testsuite/lib/trace-support.exp              | 8 +++++---
 12 files changed, 59 insertions(+), 9 deletions(-)
  

Comments

Keith Seitz July 23, 2024, 4:14 p.m. UTC | #1
Hi,

On 7/23/24 2:32 AM, Stephan Rohr wrote:
> Several tests in gdb.trace trigger TCL errors if the In-Process Agent
> library is not found, e.g.:
> 
>    Running gdb/testsuite/gdb.trace/change-loc.exp ...
>    ERROR: tcl error sourcing gdb/testsuite/gdb.trace/change-loc.exp.
>    ERROR: error copying "gdb/gdb/testsuite/../../gdbserver/libinproctrace.so":
> 	 no such file or directory
>        while executing
[snip]
> Protect against this error by checking if the library is available and
> return 'unsupported' if not.

Nice! Thank you for some test suite TLC!

> diff --git a/gdb/testsuite/gdb.trace/change-loc.exp b/gdb/testsuite/gdb.trace/change-loc.exp
> index fb55153bfcb..cd595ac65bc 100644
> --- a/gdb/testsuite/gdb.trace/change-loc.exp
> +++ b/gdb/testsuite/gdb.trace/change-loc.exp
> @@ -347,6 +347,10 @@ tracepoint_install_in_trace_disabled "trace"
>   
>   # Re-compile test case with IPA.
>   set libipa [get_in_proc_agent]
> +if { $libipa == "" } {
> +    unsupported "In-Process Agent library not found."
> +    return -1
> +}
>   gdb_load_shlib $libipa
>   

This bit of "check if get_in_proc_agent returns empty string..." is
repeated a lot here. I wonder if adding a "require" method might
be not only more concise but easier?

That way, when IPA tests are attempted, they could just be prefaced
with "require allow_in_proc_agent_tests" (or some such). See "proc
allow" in gdb.exp.

One other question:

> diff --git a/gdb/testsuite/lib/trace-support.exp b/gdb/testsuite/lib/trace-support.exp
> index c9c9697e180..b41ee49caf6 100644
> --- a/gdb/testsuite/lib/trace-support.exp
> +++ b/gdb/testsuite/lib/trace-support.exp
> @@ -366,16 +366,18 @@ proc gdb_find_recursion_test_baseline { filename } {
>      return $baseline
>  }
>  
> -# Return the location of the IPA library.
> +# Return the location of the IPA library or an empty string if not found.
>  
>  proc get_in_proc_agent {} {
>      global objdir
>  
>      if [target_info exists in_proc_agent] {
>  	return [target_info in_proc_agent]
> -    } else {
> +    } elseif [file exists "$objdir/../../gdbserver/libinproctrace.so"] {
>  	return $objdir/../../gdbserver/libinproctrace.so
> -    }

Can you explain the motivation for this change? Is it just to fix 
out-of-tree builds/test runs?

Keith

> +    } else {
> +	return ""
> +     }
>  }
>  
>  # Execute BINFILE on target to generate tracefile.  Return 1 if
  

Patch

diff --git a/gdb/testsuite/gdb.trace/change-loc.exp b/gdb/testsuite/gdb.trace/change-loc.exp
index fb55153bfcb..cd595ac65bc 100644
--- a/gdb/testsuite/gdb.trace/change-loc.exp
+++ b/gdb/testsuite/gdb.trace/change-loc.exp
@@ -347,6 +347,10 @@  tracepoint_install_in_trace_disabled "trace"
 
 # Re-compile test case with IPA.
 set libipa [get_in_proc_agent]
+if { $libipa == "" } {
+    unsupported "In-Process Agent library not found."
+    return -1
+}
 gdb_load_shlib $libipa
 
 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable \
diff --git a/gdb/testsuite/gdb.trace/ftrace-lock.exp b/gdb/testsuite/gdb.trace/ftrace-lock.exp
index ce2b890229a..e5bc0bb9d41 100644
--- a/gdb/testsuite/gdb.trace/ftrace-lock.exp
+++ b/gdb/testsuite/gdb.trace/ftrace-lock.exp
@@ -37,6 +37,12 @@  with_test_prefix "runtime trace support check" {
 	return
     }
 
+    set libipa [get_in_proc_agent]
+    if { $libipa == "" } {
+	unsupported "In-Process Agent library not found."
+	return -1
+    }
+
     if ![runto_main] {
 	return -1
     }
@@ -48,7 +54,6 @@  with_test_prefix "runtime trace support check" {
 }
 
 # Compile the test case with the in-process agent library.
-set libipa [get_in_proc_agent]
 set remote_libipa [gdb_load_shlib $libipa]
 
 lappend options shlib=$libipa
diff --git a/gdb/testsuite/gdb.trace/ftrace.exp b/gdb/testsuite/gdb.trace/ftrace.exp
index 9b100ced8f5..89f507e5e50 100644
--- a/gdb/testsuite/gdb.trace/ftrace.exp
+++ b/gdb/testsuite/gdb.trace/ftrace.exp
@@ -30,6 +30,12 @@  if [prepare_for_testing "failed to prepare" $executable $srcfile \
     return -1
 }
 
+set libipa [get_in_proc_agent]
+if { $libipa == "" } {
+    unsupported "In-Process Agent library not found."
+    return -1
+}
+
 if ![runto_main] {
     return -1
 }
@@ -39,7 +45,6 @@  if ![gdb_target_supports_trace] {
     return -1
 }
 
-set libipa [get_in_proc_agent]
 set remote_libipa [gdb_load_shlib $libipa]
 
 # Can't use prepare_for_testing, because that splits compiling into
diff --git a/gdb/testsuite/gdb.trace/pending.exp b/gdb/testsuite/gdb.trace/pending.exp
index b836be05533..14196f1c3df 100644
--- a/gdb/testsuite/gdb.trace/pending.exp
+++ b/gdb/testsuite/gdb.trace/pending.exp
@@ -495,6 +495,10 @@  pending_tracepoint_installed_during_trace "trace"
 
 # Re-compile test case with IPA.
 set libipa [get_in_proc_agent]
+if { $libipa == "" } {
+    unsupported "In-Process Agent library not found."
+    return -1
+}
 gdb_load_shlib $libipa
 
 lappend exec_opts "shlib=$libipa"
diff --git a/gdb/testsuite/gdb.trace/range-stepping.exp b/gdb/testsuite/gdb.trace/range-stepping.exp
index e3af2e5c77c..7e4bd8a2806 100644
--- a/gdb/testsuite/gdb.trace/range-stepping.exp
+++ b/gdb/testsuite/gdb.trace/range-stepping.exp
@@ -68,6 +68,10 @@  range_stepping_with_tracepoint "trace"
 require allow_shlib_tests
 
 set libipa [get_in_proc_agent]
+if { $libipa == "" } {
+    unsupported "In-Process Agent library not found."
+    return -1
+}
 set remote_libipa [gdb_load_shlib $libipa]
 
 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
diff --git a/gdb/testsuite/gdb.trace/strace.exp b/gdb/testsuite/gdb.trace/strace.exp
index 99b199ef5f1..a5ddf63d6fa 100644
--- a/gdb/testsuite/gdb.trace/strace.exp
+++ b/gdb/testsuite/gdb.trace/strace.exp
@@ -20,6 +20,10 @@  standard_testfile
 set executable $testfile
 
 set libipa [get_in_proc_agent]
+if { $libipa == "" } {
+    unsupported "In-Process Agent library not found."
+    return -1
+}
 
 set lib_opts debug
 
diff --git a/gdb/testsuite/gdb.trace/trace-break.exp b/gdb/testsuite/gdb.trace/trace-break.exp
index 7e5820cb0cf..3ab1bff6997 100644
--- a/gdb/testsuite/gdb.trace/trace-break.exp
+++ b/gdb/testsuite/gdb.trace/trace-break.exp
@@ -345,6 +345,10 @@  break_trace_same_addr_6 "trace" "disable" "trace" "enable"
 require allow_shlib_tests
 
 set libipa [get_in_proc_agent]
+if { $libipa == "" } {
+    unsupported "In-Process Agent library not found."
+    return -1
+}
 set remote_libipa [gdb_load_shlib $libipa]
 
 # Can't use prepare_for_testing, because that splits compiling into
diff --git a/gdb/testsuite/gdb.trace/trace-condition.exp b/gdb/testsuite/gdb.trace/trace-condition.exp
index 42453bc61c7..86b96313f5a 100644
--- a/gdb/testsuite/gdb.trace/trace-condition.exp
+++ b/gdb/testsuite/gdb.trace/trace-condition.exp
@@ -25,6 +25,12 @@  set additional_flags [gdb_target_symbol_prefix_flags]
 
 require gdb_trace_common_supports_arch
 
+set libipa [get_in_proc_agent]
+if { $libipa == "" } {
+    unsupported "In-Process Agent library not found."
+    return -1
+}
+
 if [prepare_for_testing "failed to prepare" $executable $srcfile \
 	[list debug $additional_flags]] {
     return -1
@@ -39,7 +45,6 @@  if ![gdb_target_supports_trace] {
     return -1
 }
 
-set libipa [get_in_proc_agent]
 set remote_libipa [gdb_load_shlib $libipa]
 
 # Can't use prepare_for_testing, because that splits compiling into
diff --git a/gdb/testsuite/gdb.trace/trace-enable-disable.exp b/gdb/testsuite/gdb.trace/trace-enable-disable.exp
index 280f2e4501a..597f0392d8a 100644
--- a/gdb/testsuite/gdb.trace/trace-enable-disable.exp
+++ b/gdb/testsuite/gdb.trace/trace-enable-disable.exp
@@ -30,6 +30,12 @@  if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable $options] != ""
     return -1
 }
 
+set libipa [get_in_proc_agent]
+if { $libipa == "" } {
+    unsupported "In-Process Agent library not found."
+    return -1
+}
+
 clean_restart ${testfile}
 
 if ![runto_main] {
@@ -42,7 +48,6 @@  if ![gdb_target_supports_trace] {
 }
 
 # Compile the test case with the in-process agent library.
-set libipa [get_in_proc_agent]
 gdb_load_shlib $libipa
 
 lappend options shlib=$libipa
diff --git a/gdb/testsuite/gdb.trace/trace-mt.exp b/gdb/testsuite/gdb.trace/trace-mt.exp
index e56064bbe8b..12bb049df32 100644
--- a/gdb/testsuite/gdb.trace/trace-mt.exp
+++ b/gdb/testsuite/gdb.trace/trace-mt.exp
@@ -104,6 +104,10 @@  step_over_tracepoint $binfile "trace"
 require allow_shlib_tests
 
 set libipa [get_in_proc_agent]
+if { $libipa == "" } {
+    unsupported "In-Process Agent library not found."
+    return -1
+}
 set remote_libipa [gdb_load_shlib $libipa]
 
 # Compile test case again with IPA.
diff --git a/gdb/testsuite/gdb.trace/tspeed.exp b/gdb/testsuite/gdb.trace/tspeed.exp
index 7ade5c2eedf..7d699716ab6 100644
--- a/gdb/testsuite/gdb.trace/tspeed.exp
+++ b/gdb/testsuite/gdb.trace/tspeed.exp
@@ -25,6 +25,12 @@  if [gdbserver_debug_enabled] {
 standard_testfile
 set executable $testfile
 
+set ipalib [get_in_proc_agent]
+if { $ipalib == "" } {
+    unsupported "In-Process Agent library not found."
+    return -1
+}
+
 # Check that the target supports trace.
 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } {
     untested "failed to compile"
@@ -43,8 +49,6 @@  if ![gdb_target_supports_trace] {
 }
 
 # Compile the test case with the in-process agent library.
-set ipalib [get_in_proc_agent]
-
 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
 	  executable [concat {debug c} shlib=$ipalib]] != "" } {
     untested "failed to compile"
diff --git a/gdb/testsuite/lib/trace-support.exp b/gdb/testsuite/lib/trace-support.exp
index c9c9697e180..b41ee49caf6 100644
--- a/gdb/testsuite/lib/trace-support.exp
+++ b/gdb/testsuite/lib/trace-support.exp
@@ -366,16 +366,18 @@  proc gdb_find_recursion_test_baseline { filename } {
     return $baseline
 }
 
-# Return the location of the IPA library.
+# Return the location of the IPA library or an empty string if not found.
 
 proc get_in_proc_agent {} {
     global objdir
 
     if [target_info exists in_proc_agent] {
 	return [target_info in_proc_agent]
-    } else {
+    } elseif [file exists "$objdir/../../gdbserver/libinproctrace.so"] {
 	return $objdir/../../gdbserver/libinproctrace.so
-    }
+    } else {
+	return ""
+     }
 }
 
 # Execute BINFILE on target to generate tracefile.  Return 1 if