[3/3] GAS/testsuite: Make a copy of none.s before operating on it as output

Message ID alpine.DEB.2.21.2406111205191.9248@angie.orcam.me.uk
State New
Headers
Series GAS/testsuite: Make sure none.s is not overwritten |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Test passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Maciej W. Rozycki June 11, 2024, 11:51 a.m. UTC
  From: Maciej W. Rozycki <macro@redhat.com>

The "Output file must be distinct from input" test in gas/all/gas.exp 
operates on none.s as output.  Should the test fail it may happen that 
GAS will delete the output file requested in which case none.s will be 
removed.  Since the test operates directly on the source tree it will be 
clobbered as a result.  It has actually been observed in the field in 
the form of intermittent:

FAIL: gas/all/none

regressions in a parallel run of many configurations.

Prevent this from happening by copying none.s first to the test object 
directory and operating on it instead.  It does not prevent the file 
from being removed should the test fail, but the source tree won't be 
clobbered in that case.

A nice side effect is that syntactically different paths will now be 
used in this test for the input and the output file each, so coverage 
will extend to verifying that a file is checked against itself even if 
referred to via different paths.  Previously "$srcdir/$subdir/none.s"
was used for both paths and now "tmpdir/none.s" is referred to directly 
and via a relative path from "$srcdir/$subdir" respectively.

I note that we have no previous use of the UNRESOLVED test result in the 
GAS testsuite, but it seems the correct one should copying none.s fail, 
as this is an unexpected situation that requires a human intervention 
and the test proper has not been evaluated.
---
 gas/testsuite/gas/all/gas.exp |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

binutils-test-gas-all-none-copy.diff
  

Patch

Index: binutils-gdb/gas/testsuite/gas/all/gas.exp
===================================================================
--- binutils-gdb.orig/gas/testsuite/gas/all/gas.exp
+++ binutils-gdb/gas/testsuite/gas/all/gas.exp
@@ -86,9 +86,18 @@  gas_test_error "equiv1.s" "" ".equiv for
 gas_test_error "equiv2.s" "" ".equiv for symbol already set to an expression"
 
 # The inode comparison used to detect identical input and output files
-# doesn't work on non-Posix hosts.
+# doesn't work on non-Posix hosts.  Make a copy of the input file and
+# operate on it so as not to clobber the source tree should this test
+# fail.
 if { ![ishost "*-*-mingw*"] } then {
-    gas_test_error "none.s" "-o $srcdir/$subdir/none.s" "Output file must be distinct from input"
+    set testname "Output file must be distinct from input"
+    set filename tmpdir/none.s
+    if [catch {file copy -force $srcdir/$subdir/none.s $filename}] {
+	perror "Could not make a copy of the input file"
+	unresolved $testname
+    } else {
+	gas_test_error [gas_srcdir_path $filename] "-o $filename" $testname
+    }
 }
 
 # .equ works differently on some targets.