public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] sim: testsuite: fix objdir handling
@ 2021-11-27  0:29 Mike Frysinger
  0 siblings, 0 replies; only message in thread
From: Mike Frysinger @ 2021-11-27  0:29 UTC (permalink / raw)
  To: gdb-patches

The tests assume that the cwd is the objdir directory and write its
intermediates to there all the time.  When using runtest's --objdir
setting though, this puts the files in the wrong place.  This isn't
a big problem currently as we never change --objdir, but in order to
support parallel test execution, we're going to start setting that
option, so clean up the code ahead of time.

We also have to tweak some of the cris tests which were making
assumptions about the argv[0] value.
---
 sim/Makefile.in                         | 21 ++++++++++++---------
 sim/testsuite/bfin/allinsn.exp          |  6 ++++--
 sim/testsuite/cris/c/c.exp              |  9 +++++----
 sim/testsuite/cris/c/openpf1.c          |  2 +-
 sim/testsuite/cris/c/rename2.c          |  6 ------
 sim/testsuite/cris/c/stat3.c            |  2 +-
 sim/testsuite/cris/hw/rv-n-cris/rvc.exp | 11 ++++++-----
 sim/testsuite/lib/sim-defs.exp          | 20 ++++++++++----------
 sim/testsuite/local.mk                  | 11 +++++++----
 9 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/sim/Makefile.in b/sim/Makefile.in
index 35f807b84df6..671d63c30b8f 100644
--- a/sim/Makefile.in
+++ b/sim/Makefile.in
@@ -1251,12 +1251,12 @@ CLEANFILES = common/version.c common/version.c-stamp \
 	testsuite/common/bits32m31.c testsuite/common/bits64m0.c \
 	testsuite/common/bits64m63.c
 DISTCLEANFILES = 
-MOSTLYCLEANFILES = core $(am__append_5) site-srcdir.exp testrun.log \
-	testrun.sum $(am__append_7) $(am__append_10) $(am__append_12) \
-	$(am__append_15) $(am__append_17) $(am__append_19) \
-	$(am__append_21) $(am__append_24) $(am__append_26) \
-	$(am__append_29) $(am__append_31) $(am__append_33) \
-	$(am__append_36) $(am__append_38)
+MOSTLYCLEANFILES = core $(am__append_5) site-sim-config.exp \
+	testrun.log testrun.sum $(am__append_7) $(am__append_10) \
+	$(am__append_12) $(am__append_15) $(am__append_17) \
+	$(am__append_19) $(am__append_21) $(am__append_24) \
+	$(am__append_26) $(am__append_29) $(am__append_31) \
+	$(am__append_33) $(am__append_36) $(am__append_38)
 AM_CFLAGS = $(WERROR_CFLAGS) $(WARN_CFLAGS)
 AM_CPPFLAGS = -I$(srcroot)/include $(SIM_INLINE) -I$(srcdir)/common
 COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(AM_CPPFLAGS) $(CFLAGS_FOR_BUILD)
@@ -1336,7 +1336,7 @@ common_libcommon_a_SOURCES = \
 
 
 # Tweak the site.exp so it works with plain `runtest` from user.
-EXTRA_DEJAGNU_SITE_CONFIG = site-srcdir.exp
+EXTRA_DEJAGNU_SITE_CONFIG = site-sim-config.exp
 
 # Custom verbose test variables that automake doesn't provide (yet?).
 AM_V_RUNTEST = $(AM_V_RUNTEST_@AM_V@)
@@ -2662,8 +2662,11 @@ common/version.c-stamp: $(srcroot)/gdb/version.in $(srcroot)/bfd/version.h $(src
 @SIM_ENABLE_IGEN_TRUE@igen/%-main.o: igen/%.c
 @SIM_ENABLE_IGEN_TRUE@	$(AM_V_CC)$(COMPILE_FOR_BUILD) -DMAIN -c $< -o $@
 
-site-srcdir.exp: Makefile
-	$(AM_V_GEN)echo "set srcdir \"$(srcdir)/testsuite\"" > $@
+site-sim-config.exp: Makefile
+	$(AM_V_GEN)( \
+	echo "set builddir \"$(builddir)\""; \
+	echo "set srcdir \"$(srcdir)/testsuite\""; \
+	) > $@
 
 check-DEJAGNU: site.exp
 	$(AM_V_RUNTEST)LC_ALL=C; export LC_ALL; \
diff --git a/sim/testsuite/bfin/allinsn.exp b/sim/testsuite/bfin/allinsn.exp
index aa304eaa9b4a..f250d2309258 100644
--- a/sim/testsuite/bfin/allinsn.exp
+++ b/sim/testsuite/bfin/allinsn.exp
@@ -4,8 +4,10 @@ if [istarget bfin-*-elf] {
     # all machines
     set all_machs "bfin"
 
+    global objdir
+
     # See if we have a preprocessor available.
-    if { [target_compile $srcdir/$subdir/usp.S compilercheck.x "preprocess" \
+    if { [target_compile $srcdir/$subdir/usp.S $objdir/compilercheck.x "preprocess" \
 	  [list "incdir=$srcdir/$subdir"]] == "" } {
 	set has_cpp 1
     } {
@@ -14,7 +16,7 @@ if [istarget bfin-*-elf] {
     }
 
     # See if we have a compiler available.
-    if { [target_compile $srcdir/$subdir/argc.c compilercheck.x "executable" \
+    if { [target_compile $srcdir/$subdir/argc.c $objdir/compilercheck.x "executable" \
 	  [list "incdir=$srcdir/$subdir" "additional_flags=-msim"]] == "" } {
 	set has_cc 1
     } {
diff --git a/sim/testsuite/cris/c/c.exp b/sim/testsuite/cris/c/c.exp
index 233ed8533778..bd51d73432fb 100644
--- a/sim/testsuite/cris/c/c.exp
+++ b/sim/testsuite/cris/c/c.exp
@@ -31,7 +31,8 @@ if [istarget cris*-*-elf] {
 }
 
 # Using target_compile, since it is less noisy,
-if { [target_compile $srcdir/$subdir/hello.c compilercheck.x \
+global objdir
+if { [target_compile $srcdir/$subdir/hello.c $objdir/compilercheck.x \
 	  "executable" "" ] == "" } {
     set has_cc 1
 
@@ -43,7 +44,7 @@ if { [target_compile $srcdir/$subdir/hello.c compilercheck.x \
     # detrimental effects on the executable from the specs and
     # -static in the board ldflags, we just add -Bdynamic.
     if [regexp "(.*/lib)/libc.so" \
-	    [target_compile $srcdir/$subdir/hello.c compilercheck.x \
+	    [target_compile $srcdir/$subdir/hello.c $objdir/compilercheck.x \
 		 "executable" \
 		 "ldflags=-print-file-name=libc.so -Wl,-Bdynamic"] \
 	    xxx libcsodir]  {
@@ -169,7 +170,7 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
 
     verbose -log "Compiling $src with $opts(cc)"
 
-    if { [target_compile $src "$testname.x" "executable" "$opts(cc)" ] != "" } {
+    if { [target_compile $src "$objdir/$testname.x" "executable" "$opts(cc)" ] != "" } {
 	unresolved $testname
 	continue
     }
@@ -192,7 +193,7 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
 	eval setup_kfail $opts(kfail)
     }
 
-    set result [sim_run "$testname.x" "$opts(sim,$mach)" "$opts(progoptions)" \
+    set result [sim_run "$objdir/$testname.x" "$opts(sim,$mach)" "$opts(progoptions)" \
 	"" ""]
     set return_code [lindex $result 0]
     set output [lindex $result 1]
diff --git a/sim/testsuite/cris/c/openpf1.c b/sim/testsuite/cris/c/openpf1.c
index fe767f71f370..92d12bfc4371 100644
--- a/sim/testsuite/cris/c/openpf1.c
+++ b/sim/testsuite/cris/c/openpf1.c
@@ -21,7 +21,7 @@ int main (int argc, char *argv[])
       if (fnam == NULL)
 	abort ();
       strcpy (fnam, "/");
-      strcat (fnam, argv[0]);
+      strcat (fnam, basename (argv[0]));
     }
 
   f = fopen (fnam, "rb");
diff --git a/sim/testsuite/cris/c/rename2.c b/sim/testsuite/cris/c/rename2.c
index 39387d1ff312..3b62837017c4 100644
--- a/sim/testsuite/cris/c/rename2.c
+++ b/sim/testsuite/cris/c/rename2.c
@@ -17,12 +17,6 @@ void err (const char *s)
 
 int main (int argc, char *argv[])
 {
-  /* Avoid getting files with random characters due to errors
-     elsewhere.  */
-  if (argc != 1
-      || (argv[0][0] != '.' && argv[0][0] != '/' && argv[0][0] != 'r'))
-    abort ();
-
   if (rename (argv[0], NULL) != -1
       || errno != EFAULT)
     err ("rename 1 ");
diff --git a/sim/testsuite/cris/c/stat3.c b/sim/testsuite/cris/c/stat3.c
index fa9fcc14b487..eac4da9ea8d9 100644
--- a/sim/testsuite/cris/c/stat3.c
+++ b/sim/testsuite/cris/c/stat3.c
@@ -13,7 +13,7 @@ int main (int argc, char *argv[])
   char path[1024] = "/";
   struct stat buf;
 
-  strcat (path, argv[0]);
+  strcat (path, basename (argv[0]));
   if (stat (".", &buf) != 0
       || !S_ISDIR (buf.st_mode))
     abort ();
diff --git a/sim/testsuite/cris/hw/rv-n-cris/rvc.exp b/sim/testsuite/cris/hw/rv-n-cris/rvc.exp
index 5d7126cc6e3f..42de37d896cd 100644
--- a/sim/testsuite/cris/hw/rv-n-cris/rvc.exp
+++ b/sim/testsuite/cris/hw/rv-n-cris/rvc.exp
@@ -21,6 +21,7 @@
 proc sim_has_rv_and_cris {} {
     global srcdir
     global subdir
+    global objdir
     global SIMFLAGS_FOR_TARGET
 
     # We need to assemble and link a trivial program and pass that, in
@@ -34,7 +35,7 @@ proc sim_has_rv_and_cris {} {
 	set SIMFLAGS_FOR_TARGET ""
     }
 
-    set comp_output [target_assemble $srcdir/$subdir/quit.s quit.o \
+    set comp_output [target_assemble $srcdir/$subdir/quit.s $objdir/quit.o \
 			 "-I$srcdir/$subdir"]
 
     if ![string match "" $comp_output] {
@@ -43,7 +44,7 @@ proc sim_has_rv_and_cris {} {
 	return 0
     }
 
-    set comp_output [target_link quit.o quit.x ""]
+    set comp_output [target_link $objdir/quit.o $objdir/quit.x ""]
 
     if ![string match "" $comp_output] {
 	verbose -log "$comp_output" 3
@@ -52,7 +53,7 @@ proc sim_has_rv_and_cris {} {
     }
 
     set result \
-	[sim_run quit.x \
+	[sim_run $objdir/quit.x \
 	     "$SIMFLAGS_FOR_TARGET --hw-device rv --hw-device cris --hw-info" \
 	     "" "" ""]
     set return_code [lindex $result 0]
@@ -117,8 +118,8 @@ if [istarget cris*-*-*] {
     # See the logic in sim-defs.exp for more details.
     set sim [board_info target sim]
     if [string equal "" $sim] {
-	global objdir
-	set rvdummy "$objdir/cris/rvdummy"
+	global builddir
+	set rvdummy "$builddir/cris/rvdummy"
     } else {
 	set rvdummy "[file dirname [board_info target sim]]/rvdummy"
     }
diff --git a/sim/testsuite/lib/sim-defs.exp b/sim/testsuite/lib/sim-defs.exp
index d10246e52385..405f1b7f9f81 100644
--- a/sim/testsuite/lib/sim-defs.exp
+++ b/sim/testsuite/lib/sim-defs.exp
@@ -40,13 +40,13 @@ proc sim_tool_path {} {
     global sim_path
     set sim "$sim_path"
     if [string equal "" $sim] {
-	global objdir
+	global builddir
 	global subdir
 	set arch "$subdir"
 	while { [file dirname $arch] != "." } {
 	    set arch [file dirname $arch]
 	}
-	return "$objdir/$arch/run"
+	return "$builddir/$arch/run"
     }
     return "$sim"
 }
@@ -181,7 +181,7 @@ proc sim_run { prog sim_opts prog_opts redir options } {
 # optional for xfail.
 
 proc run_sim_test { name requested_machs } {
-    global subdir srcdir
+    global subdir srcdir objdir
     global opts
     global cpu_option
     global cpu_option_sep
@@ -328,16 +328,16 @@ proc run_sim_test { name requested_machs } {
 	}
 
 	if [string match "*.c" $sourcefile] {
-	    set comp_output [target_compile $sourcefile ${name}.x "executable" \
+	    set comp_output [target_compile $sourcefile $objdir/${name}.x "executable" \
 		[list "incdir=$srcdir/$subdir" "additional_flags=$c_as_options $c_ld_options $opts(cc,$mach)"]]
 	    set method "compiling/linking"
 	} else {
 	    if [string match "*.S" $sourcefile] {
-		set comp_output [target_compile $sourcefile ${name}.o "object" \
+		set comp_output [target_compile $sourcefile $objdir/${name}.o "object" \
 		    [list "incdir=$srcdir/$subdir" "additional_flags=$c_as_options"]]
 		set method "compiling"
 	    } else {
-		set comp_output [target_assemble $sourcefile ${name}.o "$as_options"]
+		set comp_output [target_assemble $sourcefile $objdir/${name}.o "$as_options"]
 		set method "assembling"
 	    }
 
@@ -347,7 +347,7 @@ proc run_sim_test { name requested_machs } {
 		continue
 	    }
 
-	    set comp_output [target_link ${name}.o ${name}.x "$opts(ld,$mach)"]
+	    set comp_output [target_link $objdir/${name}.o $objdir/${name}.x "$opts(ld,$mach)"]
 	    set method "linking"
 	}
 
@@ -368,7 +368,7 @@ proc run_sim_test { name requested_machs } {
 	    set options "$options timeout=$opts(timeout)"
 	}
 
-	set result [sim_run ${name}.x "$opts(sim,$mach) $SIMFLAGS_FOR_TARGET" "$opts(progopts)" "" "$options"]
+	set result [sim_run $objdir/${name}.x "$opts(sim,$mach) $SIMFLAGS_FOR_TARGET" "$opts(progopts)" "" "$options"]
 	set return_code [lindex $result 0]
 	set output [lindex $result 1]
 
@@ -383,7 +383,7 @@ proc run_sim_test { name requested_machs } {
 	    if { "$opts(xerror)" == "no" } {
 		if [string match $opts(output) $output] {
 		    pass "$mach $testname"
-		    file delete ${name}.o ${name}.x
+		    file delete $objdir/${name}.o $objdir/${name}.x
 		} else {
 		    verbose -log "status:  $return_code" 3
 		    verbose -log "output:  $output" 3
@@ -400,7 +400,7 @@ proc run_sim_test { name requested_machs } {
 	    } else {
 		if [string match $opts(output) $output] {
 		    pass "$mach $testname"
-		    file delete ${name}.o ${name}.x
+		    file delete $objdir/${name}.o $objdir/${name}.x
 		} else {
 		    verbose -log "status:  $return_code" 3
 		    verbose -log "output:  $output" 3
diff --git a/sim/testsuite/local.mk b/sim/testsuite/local.mk
index 4da63ea49fa0..5ffa9eca745c 100644
--- a/sim/testsuite/local.mk
+++ b/sim/testsuite/local.mk
@@ -16,7 +16,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # Tweak the site.exp so it works with plain `runtest` from user.
-EXTRA_DEJAGNU_SITE_CONFIG = site-srcdir.exp
+EXTRA_DEJAGNU_SITE_CONFIG = site-sim-config.exp
 
 # Custom verbose test variables that automake doesn't provide (yet?).
 AM_V_RUNTEST = $(AM_V_RUNTEST_@AM_V@)
@@ -24,8 +24,11 @@ AM_V_RUNTEST_ = $(AM_V_RUNTEST_@AM_DEFAULT_V@)
 AM_V_RUNTEST_0 =  @echo "  RUNTEST  $(RUNTESTFLAGS)";
 AM_V_RUNTEST_1 =
 
-site-srcdir.exp: Makefile
-	$(AM_V_GEN)echo "set srcdir \"$(srcdir)/testsuite\"" > $@
+site-sim-config.exp: Makefile
+	$(AM_V_GEN)( \
+	echo "set builddir \"$(builddir)\""; \
+	echo "set srcdir \"$(srcdir)/testsuite\""; \
+	) > $@
 
 check-DEJAGNU: site.exp
 	$(AM_V_RUNTEST)LC_ALL=C; export LC_ALL; \
@@ -37,6 +40,6 @@ check-DEJAGNU: site.exp
 	fi
 
 MOSTLYCLEANFILES += \
-	site-srcdir.exp testrun.log testrun.sum
+	site-sim-config.exp testrun.log testrun.sum
 
 include %D%/common/local.mk
-- 
2.33.0


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

only message in thread, other threads:[~2021-11-27  0:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-27  0:29 [PATCH] sim: testsuite: fix objdir handling Mike Frysinger

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