]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld/testsuite: add support for remote testing in ld-cdtest
authorClément Chigot <chigot@adacore.com>
Fri, 20 Feb 2026 14:43:03 +0000 (15:43 +0100)
committerClément Chigot <chigot@adacore.com>
Thu, 2 Jul 2026 06:45:20 +0000 (08:45 +0200)
This converts the existing to code to use "remote_load" allowing
execution on both native and remote targets.

The "diff" between the output and the expected result has been
transformed to the usual regexp_diff. The previous could have been
transformed into `remote_exec build diff` but tends to be fickled with
new lines.

ld/testsuite/ld-cdtest/cdtest-nrv.dat
ld/testsuite/ld-cdtest/cdtest.dat
ld/testsuite/ld-cdtest/cdtest.exp

index d3f871ff108c3ae677e20e8bc4eec838e2af2e9b..76fcbaa03d4a954a2f4d220767fbff7878bff2ef 100644 (file)
@@ -1,13 +1,13 @@
-Constructing Foo(1) "static_foo"
-Constructing Foo(2) "static_foo"
-Constructing Foo(3) "automatic_foo"
-Constructing Foo(4) "default-foo"
-Constructing Foo(5) "other_foo1"
-Constructing Foo(6) "other_foo2"
-Copying Foo(5) "other_foo1" to Foo(6)
-Destructing Foo(6) "other_foo1" (remaining foos: 5)
-Destructing Foo(5) "other_foo1" (remaining foos: 4)
-Destructing Foo(4) "default-foo" (remaining foos: 3)
-Destructing Foo(3) "automatic_foo" (remaining foos: 2)
-Destructing Foo(2) "static_foo" (remaining foos: 1)
-Destructing Foo(1) "static_foo" (remaining foos: 0)
+Constructing Foo\(1\) "static_foo"
+Constructing Foo\(2\) "static_foo"
+Constructing Foo\(3\) "automatic_foo"
+Constructing Foo\(4\) "default-foo"
+Constructing Foo\(5\) "other_foo1"
+Constructing Foo\(6\) "other_foo2"
+Copying Foo\(5\) "other_foo1" to Foo\(6\)
+Destructing Foo\(6\) "other_foo1" \(remaining foos: 5\)
+Destructing Foo\(5\) "other_foo1" \(remaining foos: 4\)
+Destructing Foo\(4\) "default-foo" \(remaining foos: 3\)
+Destructing Foo\(3\) "automatic_foo" \(remaining foos: 2\)
+Destructing Foo\(2\) "static_foo" \(remaining foos: 1\)
+Destructing Foo\(1\) "static_foo" \(remaining foos: 0\)
index 39be0dbc2c7c9e5780f906e21afe66ed74a169d5..c0bdffb3c266c45b275989a979aba55645837a8e 100644 (file)
@@ -1,15 +1,15 @@
-Constructing Foo(1) "static_foo"
-Constructing Foo(2) "static_foo"
-Constructing Foo(3) "automatic_foo"
-Constructing Foo(4) "default-foo"
-Initializing Foo(5) "default-foo" with Foo(4)
-Destructing Foo(4) "default-foo" (remaining foos: 4)
-Constructing Foo(5) "other_foo1"
-Constructing Foo(6) "other_foo2"
-Copying Foo(5) "other_foo1" to Foo(6)
-Destructing Foo(6) "other_foo1" (remaining foos: 5)
-Destructing Foo(5) "other_foo1" (remaining foos: 4)
-Destructing Foo(5) "default-foo" (remaining foos: 3)
-Destructing Foo(3) "automatic_foo" (remaining foos: 2)
-Destructing Foo(2) "static_foo" (remaining foos: 1)
-Destructing Foo(1) "static_foo" (remaining foos: 0)
+Constructing Foo\(1\) "static_foo"
+Constructing Foo\(2\) "static_foo"
+Constructing Foo\(3\) "automatic_foo"
+Constructing Foo\(4\) "default-foo"
+Initializing Foo\(5\) "default-foo" with Foo\(4\)
+Destructing Foo\(4\) "default-foo" \(remaining foos: 4\)
+Constructing Foo\(5\) "other_foo1"
+Constructing Foo\(6\) "other_foo2"
+Copying Foo\(5\) "other_foo1" to Foo\(6\)
+Destructing Foo\(6\) "other_foo1" \(remaining foos: 5\)
+Destructing Foo\(5\) "other_foo1" \(remaining foos: 4\)
+Destructing Foo\(5\) "default-foo" \(remaining foos: 3\)
+Destructing Foo\(3\) "automatic_foo" \(remaining foos: 2\)
+Destructing Foo\(2\) "static_foo" \(remaining foos: 1\)
+Destructing Foo\(1\) "static_foo" \(remaining foos: 0\)
index 89fdd581abbfe19603dbd7db20fc18e38257c3ac..548d0f1a5c310336ca64149339017dff9a1a2784 100644 (file)
@@ -28,11 +28,7 @@ set test1 "cdtest"
 set test2 "cdtest with -Ur"
 
 # This test requires running the executable generated by ld.
-if ![isnative] {
-    return
-}
-
-if { [which $CXX_FOR_TARGET] == 0 } {
+if { [which $CXX_FOR_TARGET] == 0 || ![check_execution_available] } {
     untested $test1
     untested $test2
     return
@@ -51,44 +47,39 @@ set expected_output "$srcdir/$subdir/cdtest.dat"
 if ![ld_link $CC_FOR_TARGET tmpdir/cdtest "$CFLAGS_FOR_TARGET tmpdir/cdtest-foo.o tmpdir/cdtest-bar.o tmpdir/cdtest-main.o"] {
     fail $test1
 } else {
-    send_log   "tmpdir/cdtest >tmpdir/cdtest.out\n"
-    verbose    "tmpdir/cdtest >tmpdir/cdtest.out"
-    catch "exec tmpdir/cdtest >tmpdir/cdtest.out" exec_output
+    set failed 0
 
-    if ![string match "" $exec_output] then {
+    send_log "Running: tmpdir/cdtest\n"
+    verbose "Running: tmpdir/cdtest"
+    set state [remote_load target tmpdir/cdtest]
+    set status [lindex $state 0]
+    set exec_output [lindex $state 1]
+
+    if { $status != "pass"  } {
        send_log "$exec_output\n"
        verbose "$exec_output" 1
-
-       fail $test1
+       set failed 1
     } else {
-       send_log   "diff tmpdir/cdtest.out $expected_output\n"
-       verbose    "diff tmpdir/cdtest.out $expected_output"
-       catch "exec diff tmpdir/cdtest.out $expected_output" exec_output
-       set exec_output [prune_warnings $exec_output]
-
-       if ![string match "" $exec_output] then {
-           send_log "$exec_output\n"
-           verbose  "$exec_output" 1
+       set output_filename "tmpdir/cdtest.out"
+       set_file_contents $output_filename $exec_output
 
+       send_log [file_contents $output_filename]
+       verbose [file_contents $output_filename] 2
+       if [regexp_diff $output_filename $expected_output] {
            send_log "Checking against Named Return Value optimization\n"
            verbose  "Checking against Named Return Value optimization" 1
 
            set expected_output "$srcdir/$subdir/cdtest-nrv.dat"
-
-           send_log   "diff tmpdir/cdtest.out $expected_output\n"
-           verbose    "diff tmpdir/cdtest.out $expected_output"
-           catch "exec diff tmpdir/cdtest.out $expected_output" exec_output
-           set exec_output [prune_warnings $exec_output]
+           if [regexp_diff $output_filename $expected_output] {
+               set failed 1
+           }
        }
+    }
 
-       if [string match "" $exec_output] then {
-           pass $test1
-       } else {
-           send_log "$exec_output\n"
-           verbose  "$exec_output" 1
-
-           fail $test1
-       }
+    if { $failed } {
+       fail $test1
+    } else {
+       pass $test1
     }
 }
 
@@ -103,29 +94,33 @@ if ![ld_relocate $ld tmpdir/cdtest.o {-Ur tmpdir/cdtest-foo.o tmpdir/cdtest-bar.
     if ![ld_link $CC_FOR_TARGET tmpdir/cdtest "$CFLAGS_FOR_TARGET tmpdir/cdtest.o"] {
        fail $test2
     } else {
-       send_log   "tmpdir/cdtest >tmpdir/cdtest.out\n"
-       verbose    "tmpdir/cdtest >tmpdir/cdtest.out"
-       catch "exec tmpdir/cdtest >tmpdir/cdtest.out" exec_output
+       set failed 0
+
+       send_log "Running: tmpdir/cdtest\n"
+       verbose "Running: tmpdir/cdtest"
+       set state [remote_load target tmpdir/cdtest]
+       set status [lindex $state 0]
+       set exec_output [lindex $state 1]
 
-       if ![string match "" $exec_output] then {
+       if { $status != "pass" } {
            send_log "$exec_output\n"
-           verbose  "$exec_output" 1
+           verbose "$exec_output" 1
+           set failed 1
+       } else {
+           set output_filename "tmpdir/cdtest.out"
+           set_file_contents $output_filename $exec_output
 
+           send_log [file_contents $output_filename]
+           verbose [file_contents $output_filename] 2
+           if [regexp_diff $output_filename $expected_output] {
+               set failed 1
+           }
+       }
+
+       if { $failed } {
            fail $test2
        } else {
-           send_log   "diff tmpdir/cdtest.out $expected_output\n"
-           verbose    "diff tmpdir/cdtest.out $expected_output"
-           catch "exec diff tmpdir/cdtest.out $expected_output" exec_output
-           set exec_output [prune_warnings $exec_output]
-
-           if [string match "" $exec_output] then {
-               pass $test2
-           } else {
-               send_log "$exec_output\n"
-               verbose  "$exec_output" 1
-
-               fail $test2
-           }
+           pass $test2
        }
     }
 }