[v4,2/5,gdb/testsuite] add lib/jit-elf-helpers.exp

Message ID 20200421133123.21284-3-mihails.strasuns@intel.com
State New
Headers show
Series
  • jit testsuite refactoring
Related show

Commit Message

Rogerio Alves via Gdb-patches April 21, 2020, 1:31 p.m.
New utility library to be used by jit-elf tests responsible for
compiling binary artifacts. In the next commit the compilation process
will become more complicated because of extra mandatory flag - keeping
it in one place will make tests less fragile.

gdb/testsuite/ChangeLog:

2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>

	* lib/jit-elf-helpers.exp: New file.
	* gdb.base/jit-elf.exp: Updated to use jit-elf-helpers.exp.
	* gdb.base/jit-elf-so.exp: Updated to use jit-elf-helpers.exp.
---
 gdb/testsuite/gdb.base/jit-elf-so.exp | 50 +---------------
 gdb/testsuite/gdb.base/jit-elf.exp    | 51 ----------------
 gdb/testsuite/lib/jit-elf-helpers.exp | 85 +++++++++++++++++++++++++++
 3 files changed, 87 insertions(+), 99 deletions(-)
 create mode 100644 gdb/testsuite/lib/jit-elf-helpers.exp

-- 
2.26.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

Comments

Simon Marchi April 21, 2020, 3:55 p.m. | #1
On 2020-04-21 9:31 a.m., Mihails Strasuns via Gdb-patches wrote:
> New utility library to be used by jit-elf tests responsible for

> compiling binary artifacts. In the next commit the compilation process

> will become more complicated because of extra mandatory flag - keeping

> it in one place will make tests less fragile.

> 

> gdb/testsuite/ChangeLog:

> 

> 2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>

> 

> 	* lib/jit-elf-helpers.exp: New file.

> 	* gdb.base/jit-elf.exp: Updated to use jit-elf-helpers.exp.

> 	* gdb.base/jit-elf-so.exp: Updated to use jit-elf-helpers.exp.

> ---

>  gdb/testsuite/gdb.base/jit-elf-so.exp | 50 +---------------

>  gdb/testsuite/gdb.base/jit-elf.exp    | 51 ----------------

>  gdb/testsuite/lib/jit-elf-helpers.exp | 85 +++++++++++++++++++++++++++

>  3 files changed, 87 insertions(+), 99 deletions(-)

>  create mode 100644 gdb/testsuite/lib/jit-elf-helpers.exp

> 

> diff --git a/gdb/testsuite/gdb.base/jit-elf-so.exp b/gdb/testsuite/gdb.base/jit-elf-so.exp

> index 59ca1ac8cf..af80d95d92 100644

> --- a/gdb/testsuite/gdb.base/jit-elf-so.exp

> +++ b/gdb/testsuite/gdb.base/jit-elf-so.exp

> @@ -26,6 +26,8 @@ if {[get_compiler_info]} {

>      return 1

>  }

>  

> +load_lib jit-elf-helpers.exp

> +

>  # The "real" main of this test, which loads jit-elf-main

>  # as a shared library.

>  set main_loader_basename jit-elf-dlmain

> @@ -41,25 +43,6 @@ set main_solib_binfile [standard_output_file ${main_solib_basename}.so]

>  set jit_solib_basename jit-elf-solib

>  set jit_solib_srcfile ${srcdir}/${subdir}/${jit_solib_basename}.c


Now it's a bit confusing, because jit-elf-helpers.exp uses some definitions
that must be provided by the including file.  It would be better for it to
be self-contained.  So either move the setting of these definitions to
jit-elf-helpers.exp (and work out a naming scheme that is not too confusing),
or modify the procedures to take parameters, and update the callers to pass
in the values as arguments.

>  

> -# Compile jit-elf-main.c as a shared library.

> -#

> -# OPTIONS is passed to gdb_compile when compiling the program.

> -#

> -# On success, return 0.

> -# On failure, return -1.

> -proc compile_jit_elf_main_as_so {options} {

> -    global main_solib_srcfile main_solib_binfile

> -    set options [concat $options debug]

> -

> -    if { [gdb_compile_shlib ${main_solib_srcfile} ${main_solib_binfile} \

> -	    $options] != "" } {

> -	untested "failed to compile ${main_solib_basename}.c as a shared library"

> -	return -1

> -    }

> -

> -    return 0

> -}

> -

>  # Compile the testcase shared library loader.

>  #

>  # OPTIONS is passed to gdb_compile when compiling the binary.

> @@ -79,34 +62,6 @@ proc compile_jit_dlmain {options} {

>      return 0

>  }

>  

> -# Compile jit-elf-solib.c as a shared library in multiple copies and

> -# upload them to the target.

> -#

> -# On success, return a list of target path to the shared libraries.

> -# On failure, return -1.

> -proc compile_and_download_n_jit_so {count} {

> -    global jit_solib_basename jit_solib_srcfile

> -    set binfiles_target {}

> -

> -    for {set i 1} {$i <= $count} {incr i} {

> -	set binfile [standard_output_file ${jit_solib_basename}.$i.so]

> -

> -	# Note: compiling without debug info by default: some test

> -	# do symbol renaming by munging on ELF symbol table, and that

> -	# wouldn't work for .debug sections.  Also, output for "info

> -	# function" changes when debug info is present.

> -	if { [gdb_compile_shlib ${jit_solib_srcfile} ${binfile} {}] != "" } {

> -	    untested "failed to compile ${jit_solib_basename}.c as a shared library"

> -	    return -1

> -	}

> -

> -	set path [gdb_remote_download target ${binfile}]

> -	lappend binfiles_target $path

> -    }

> -

> -    return $binfiles_target

> -}

> -

>  # Run $main_loader_binfile and load $main_solib_binfile in

>  # GDB.  Check jit-related debug output and matches `info function`

>  # output for a jit loaded function using MATCH_STR.

> @@ -117,7 +72,6 @@ proc compile_and_download_n_jit_so {count} {

>  # must match.

>  proc one_jit_test {solib_binfiles_target match_str} {

>      set count [llength $solib_binfiles_target]

> -

>      with_test_prefix "one_jit_test-$count" {

>  	global verbose

>  	global main_loader_binfile main_loader_srcfile

> diff --git a/gdb/testsuite/gdb.base/jit-elf.exp b/gdb/testsuite/gdb.base/jit-elf.exp

> index 29638bd2c0..df3199622c 100644

> --- a/gdb/testsuite/gdb.base/jit-elf.exp

> +++ b/gdb/testsuite/gdb.base/jit-elf.exp

> @@ -32,58 +32,7 @@ set main_binfile [standard_output_file ${main_basename}]

>  set jit_solib_basename jit-elf-solib

>  set jit_solib_srcfile ${srcdir}/${subdir}/${jit_solib_basename}.c

>  


We are missing a "load_lib" in this file.

Simon
Rogerio Alves via Gdb-patches April 22, 2020, 9:20 a.m. | #2
> -----Original Message-----

> From: Simon Marchi <simark@simark.ca>

> Sent: Tuesday, April 21, 2020 5:55 PM

> To: Strasuns, Mihails <mihails.strasuns@intel.com>; gdb-

> patches@sourceware.org

> Subject: Re: [PATCH v4 2/5] [gdb/testsuite] add lib/jit-elf-helpers.exp

> 

> ...

>

> >  # The "real" main of this test, which loads jit-elf-main  # as a

> > shared library.

> >  set main_loader_basename jit-elf-dlmain @@ -41,25 +43,6 @@ set

> > main_solib_binfile [standard_output_file ${main_solib_basename}.so]

> > set jit_solib_basename jit-elf-solib  set jit_solib_srcfile

> > ${srcdir}/${subdir}/${jit_solib_basename}.c

> 

> Now it's a bit confusing, because jit-elf-helpers.exp uses some definitions

> that must be provided by the including file.  It would be better for it to be

> self-contained.  So either move the setting of these definitions to jit-elf-

> helpers.exp (and work out a naming scheme that is not too confusing), or

> modify the procedures to take parameters, and update the callers to pass in

> the values as arguments.


That was my initial guess (and the previous implementation) but I got confused by your proposed patch which used globals for input parameters - I have assumed you want to keep it that way :)
Will change it back.

> >

> > -# Compile jit-elf-main.c as a shared library.

> > -#

> > -# OPTIONS is passed to gdb_compile when compiling the program.

> > -#

> > -# On success, return 0.

> > -# On failure, return -1.

> > -proc compile_jit_elf_main_as_so {options} {

> > -    global main_solib_srcfile main_solib_binfile

> > -    set options [concat $options debug]

> > -

> > -    if { [gdb_compile_shlib ${main_solib_srcfile} ${main_solib_binfile} \

> > -	    $options] != "" } {

> > -	untested "failed to compile ${main_solib_basename}.c as a shared

> library"

> > -	return -1

> > -    }

> > -

> > -    return 0

> > -}

> > -

> >  # Compile the testcase shared library loader.

> >  #

> >  # OPTIONS is passed to gdb_compile when compiling the binary.

> > @@ -79,34 +62,6 @@ proc compile_jit_dlmain {options} {

> >      return 0

> >  }

> >

> > -# Compile jit-elf-solib.c as a shared library in multiple copies and

> > -# upload them to the target.

> > -#

> > -# On success, return a list of target path to the shared libraries.

> > -# On failure, return -1.

> > -proc compile_and_download_n_jit_so {count} {

> > -    global jit_solib_basename jit_solib_srcfile

> > -    set binfiles_target {}

> > -

> > -    for {set i 1} {$i <= $count} {incr i} {

> > -	set binfile [standard_output_file ${jit_solib_basename}.$i.so]

> > -

> > -	# Note: compiling without debug info by default: some test

> > -	# do symbol renaming by munging on ELF symbol table, and that

> > -	# wouldn't work for .debug sections.  Also, output for "info

> > -	# function" changes when debug info is present.

> > -	if { [gdb_compile_shlib ${jit_solib_srcfile} ${binfile} {}] != "" } {

> > -	    untested "failed to compile ${jit_solib_basename}.c as a shared

> library"

> > -	    return -1

> > -	}

> > -

> > -	set path [gdb_remote_download target ${binfile}]

> > -	lappend binfiles_target $path

> > -    }

> > -

> > -    return $binfiles_target

> > -}

> > -

> >  # Run $main_loader_binfile and load $main_solib_binfile in  # GDB.

> > Check jit-related debug output and matches `info function`  # output

> > for a jit loaded function using MATCH_STR.

> > @@ -117,7 +72,6 @@ proc compile_and_download_n_jit_so {count} {  #

> > must match.

> >  proc one_jit_test {solib_binfiles_target match_str} {

> >      set count [llength $solib_binfiles_target]

> > -

> >      with_test_prefix "one_jit_test-$count" {

> >  	global verbose

> >  	global main_loader_binfile main_loader_srcfile diff --git

> > a/gdb/testsuite/gdb.base/jit-elf.exp

> > b/gdb/testsuite/gdb.base/jit-elf.exp

> > index 29638bd2c0..df3199622c 100644

> > --- a/gdb/testsuite/gdb.base/jit-elf.exp

> > +++ b/gdb/testsuite/gdb.base/jit-elf.exp

> > @@ -32,58 +32,7 @@ set main_binfile [standard_output_file

> > ${main_basename}]  set jit_solib_basename jit-elf-solib  set

> > jit_solib_srcfile ${srcdir}/${subdir}/${jit_solib_basename}.c

> >

> 

> We are missing a "load_lib" in this file.


Good catch, thanks!

> Simon

Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

Patch

diff --git a/gdb/testsuite/gdb.base/jit-elf-so.exp b/gdb/testsuite/gdb.base/jit-elf-so.exp
index 59ca1ac8cf..af80d95d92 100644
--- a/gdb/testsuite/gdb.base/jit-elf-so.exp
+++ b/gdb/testsuite/gdb.base/jit-elf-so.exp
@@ -26,6 +26,8 @@  if {[get_compiler_info]} {
     return 1
 }
 
+load_lib jit-elf-helpers.exp
+
 # The "real" main of this test, which loads jit-elf-main
 # as a shared library.
 set main_loader_basename jit-elf-dlmain
@@ -41,25 +43,6 @@  set main_solib_binfile [standard_output_file ${main_solib_basename}.so]
 set jit_solib_basename jit-elf-solib
 set jit_solib_srcfile ${srcdir}/${subdir}/${jit_solib_basename}.c
 
-# Compile jit-elf-main.c as a shared library.
-#
-# OPTIONS is passed to gdb_compile when compiling the program.
-#
-# On success, return 0.
-# On failure, return -1.
-proc compile_jit_elf_main_as_so {options} {
-    global main_solib_srcfile main_solib_binfile
-    set options [concat $options debug]
-
-    if { [gdb_compile_shlib ${main_solib_srcfile} ${main_solib_binfile} \
-	    $options] != "" } {
-	untested "failed to compile ${main_solib_basename}.c as a shared library"
-	return -1
-    }
-
-    return 0
-}
-
 # Compile the testcase shared library loader.
 #
 # OPTIONS is passed to gdb_compile when compiling the binary.
@@ -79,34 +62,6 @@  proc compile_jit_dlmain {options} {
     return 0
 }
 
-# Compile jit-elf-solib.c as a shared library in multiple copies and
-# upload them to the target.
-#
-# On success, return a list of target path to the shared libraries.
-# On failure, return -1.
-proc compile_and_download_n_jit_so {count} {
-    global jit_solib_basename jit_solib_srcfile
-    set binfiles_target {}
-
-    for {set i 1} {$i <= $count} {incr i} {
-	set binfile [standard_output_file ${jit_solib_basename}.$i.so]
-
-	# Note: compiling without debug info by default: some test
-	# do symbol renaming by munging on ELF symbol table, and that
-	# wouldn't work for .debug sections.  Also, output for "info
-	# function" changes when debug info is present.
-	if { [gdb_compile_shlib ${jit_solib_srcfile} ${binfile} {}] != "" } {
-	    untested "failed to compile ${jit_solib_basename}.c as a shared library"
-	    return -1
-	}
-
-	set path [gdb_remote_download target ${binfile}]
-	lappend binfiles_target $path
-    }
-
-    return $binfiles_target
-}
-
 # Run $main_loader_binfile and load $main_solib_binfile in
 # GDB.  Check jit-related debug output and matches `info function`
 # output for a jit loaded function using MATCH_STR.
@@ -117,7 +72,6 @@  proc compile_and_download_n_jit_so {count} {
 # must match.
 proc one_jit_test {solib_binfiles_target match_str} {
     set count [llength $solib_binfiles_target]
-
     with_test_prefix "one_jit_test-$count" {
 	global verbose
 	global main_loader_binfile main_loader_srcfile
diff --git a/gdb/testsuite/gdb.base/jit-elf.exp b/gdb/testsuite/gdb.base/jit-elf.exp
index 29638bd2c0..df3199622c 100644
--- a/gdb/testsuite/gdb.base/jit-elf.exp
+++ b/gdb/testsuite/gdb.base/jit-elf.exp
@@ -32,58 +32,7 @@  set main_binfile [standard_output_file ${main_basename}]
 set jit_solib_basename jit-elf-solib
 set jit_solib_srcfile ${srcdir}/${subdir}/${jit_solib_basename}.c
 
-# Compile jit-elf-main.c as an executable.
-#
-# BINSUFFIX is appended to the binary name.
-# OPTIONS is passed to gdb_compile when compiling the program.
-#
-# On success, return 0.
-# On failure, return -1.
-proc compile_jit_main {binsuffix options} {
-    global main_binfile main_srcfile main_basename
-
-    set binfile ${main_binfile}${binsuffix}
-    set options [concat $options debug]
-
-    if { [gdb_compile ${main_srcfile} ${binfile} \
-	  executable $options] != "" } {
-	      untested "failed to compile ${main_basename}.c"
-	      return -1
-    }
-
-    return 0
-}
-
-# Compile jit-elf-solib.c as a shared library in multiple copies and
-# upload them to the target.
-#
-# On success, return a list of target paths to the shared libraries.
-# On failure, return -1.
-proc compile_and_download_n_jit_so {count} {
-    global jit_solib_basename jit_solib_srcfile
-    set binfiles_target {}
-
-    for {set i 1} {$i <= $count} {incr i} {
-	set binfile [standard_output_file ${jit_solib_basename}.$i.so]
-
-	# Note: compiling without debug info by default: some test
-	# do symbol renaming by munging on ELF symbol table, and that
-	# wouldn't work for .debug sections.  Also, output for "info
-	# function" changes when debug info is present.
-	if { [gdb_compile_shlib ${jit_solib_srcfile} ${binfile} {}] != "" } {
-	    untested "failed to compile ${jit_solib_basename}.c as a shared library"
-	    return -1
-	}
-
-	set path [gdb_remote_download target ${binfile}]
-	lappend binfiles_target $path
-    }
-
-    return $binfiles_target
-}
-
 # Detach, restart GDB, and re-attach to the program.
-
 proc clean_reattach {} {
     global decimal gdb_prompt
     global main_binfile main_srcfile
diff --git a/gdb/testsuite/lib/jit-elf-helpers.exp b/gdb/testsuite/lib/jit-elf-helpers.exp
new file mode 100644
index 0000000000..a40dd94cda
--- /dev/null
+++ b/gdb/testsuite/lib/jit-elf-helpers.exp
@@ -0,0 +1,85 @@ 
+# Copyright 2020 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Compiles jit-elf-main.c as a regular executable
+
+# Compile jit-elf-main.c as an executable.
+#
+# BINSUFFIX is appended to the binary name.
+# OPTIONS is passed to gdb_compile when compiling the program.
+#
+# On success, return 0.
+# On failure, return -1.
+proc compile_jit_main {binsuffix options} {
+    global main_binfile main_srcfile main_basename
+
+    set binfile ${main_binfile}${binsuffix}
+    set options [concat $options debug]
+
+    if { [gdb_compile ${main_srcfile} ${binfile} \
+	  executable $options] != "" } {
+	      untested "failed to compile ${main_basename}.c"
+	      return -1
+    }
+
+    return 0
+}
+
+# Compile jit-elf-main.c as a shared library.
+#
+# OPTIONS is passed to gdb_compile when compiling the program.
+#
+# On success, return 0.
+# On failure, return -1.
+proc compile_jit_elf_main_as_so {options} {
+    global main_solib_srcfile main_solib_binfile
+    set options [concat $options debug]
+
+    if { [gdb_compile_shlib ${main_solib_srcfile} ${main_solib_binfile} \
+	    $options] != "" } {
+	untested "failed to compile ${main_solib_basename}.c as a shared library"
+	return -1
+    }
+
+    return 0
+}
+
+# Compile jit-elf-solib.c as a shared library in multiple copies and
+# upload them to the target.
+#
+# On success, return a list of target path to the shared libraries.
+# On failure, return -1.
+proc compile_and_download_n_jit_so {count} {
+    global jit_solib_basename jit_solib_srcfile
+    set binfiles_target {}
+
+    for {set i 1} {$i <= $count} {incr i} {
+	set binfile [standard_output_file ${jit_solib_basename}.$i.so]
+
+	# Note: compiling without debug info by default: some test
+	# do symbol renaming by munging on ELF symbol table, and that
+	# wouldn't work for .debug sections.  Also, output for "info
+	# function" changes when debug info is present.
+	if { [gdb_compile_shlib ${jit_solib_srcfile} ${binfile} {}] != "" } {
+	    untested "failed to compile ${jit_solib_basename}.c as a shared library"
+	    return -1
+	}
+
+	set path [gdb_remote_download target ${binfile}]
+	lappend binfiles_target $path
+    }
+
+    return $binfiles_target
+}
\ No newline at end of file