]>
Commit | Line | Data |
---|---|---|
bb368aad | 1 | # Support routines for display-testing machinery in gprofng testsuite. |
fd67aa11 | 2 | # Copyright (C) 1994-2024 Free Software Foundation, Inc. |
bb368aad VM |
3 | # |
4 | # This file is part of the GNU Binutils. | |
5 | # | |
6 | # This file is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 3 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
19 | # MA 02110-1301, USA. | |
20 | ||
21 | # Run the COMMAND on the host and return a list of the form | |
22 | # { exit-status OUTPUT }. | |
23 | proc run_native_host_cmd { command } { | |
9d9f26d8 | 24 | global TEST_TIMEOUT |
bb368aad VM |
25 | |
26 | verbose -log "$command" | |
27 | set run_output "" | |
28 | try { | |
9d9f26d8 VM |
29 | send_log "% timeout $TEST_TIMEOUT sh -c '$command' 2>&1\n" |
30 | set run_output [exec "timeout" $TEST_TIMEOUT "sh" "-c" "$command" "2>&1"] | |
bb368aad VM |
31 | set status 0 |
32 | } trap CHILDSTATUS {results options} { | |
33 | set status [lindex [dict get $options -errorcode] 2] | |
9d9f26d8 VM |
34 | set run_output "$results" |
35 | if { $status == 124 || $status == 133 } { | |
36 | send_log " ERROR: TIMEOUT($TEST_TIMEOUT sec.)\n" | |
37 | } | |
bb368aad VM |
38 | } |
39 | regsub "\n$" $run_output "" run_output | |
40 | if { [lindex $status 0] != 0 && [string match "" $run_output] } then { | |
41 | append run_output "child process exited abnormally" | |
42 | } | |
9d9f26d8 | 43 | return [list [lindex $status 0] "$run_output"] |
bb368aad VM |
44 | } |
45 | ||
46 | # Run a display test in DIR. | |
47 | # Unanswered questions: do we want to cycle through compilation flags, | |
48 | # display options, collect flags, app options? Do we want these to be | |
49 | # set on a per-app basis? (If so, they should probably be driven by a | |
50 | # file in the test dir.) | |
defb7341 | 51 | proc run_display_test { dir cflags gprofflags tflags } { |
bb368aad VM |
52 | global srcdir MAKE CC CFLAGS LDFLAGS LIBS BUILDDIR |
53 | set stripped [string map {" " ""} $dir] | |
54 | set testdir [string map {" " ""} "$dir.$cflags,$gprofflags"] | |
55 | set sdir "$srcdir/gprofng.display/$dir" | |
56 | set tdir "tmpdir/$testdir" | |
57 | send_log "create dir: $tdir\n" | |
58 | set output [run_native_host_cmd "mkdir -p $tdir"] | |
defb7341 | 59 | set gprofng $::env(GPROFNG) |
bb368aad VM |
60 | |
61 | set fd [open "$tdir/rules.txt" "w"] | |
62 | switch -regexp -- $testdir { | |
63 | {-p,on.*-h,on} { | |
64 | set DISPLAY_FLAGS "-metrics i.totalcpu:i.cycles -func" | |
65 | puts $fd "Cpu, 2, 0\n" | |
66 | puts $fd "Cycles, 2, 1\n" | |
67 | } | |
68 | {-h,on} { | |
69 | set DISPLAY_FLAGS "-metrics i.cycles -func" | |
70 | puts $fd "Cycles, 2, 0\n" | |
71 | } | |
72 | default { | |
73 | set DISPLAY_FLAGS "-metrics i.totalcpu -func" | |
74 | puts $fd "Cpu, 2, 0\n" | |
75 | } | |
76 | } | |
77 | close $fd | |
78 | ||
79 | set make_args "-f $sdir/Makefile srcdir=\"$sdir\" builddir=\"$BUILDDIR\" \ | |
80 | VPATH=\"$dir\" CC=\"$CC\" CFLAGS=\"$cflags\" LDFLAGS=\"$LDFLAGS\" \ | |
defb7341 | 81 | TARGET_FLAGS=\"$tflags\" \ |
bb368aad VM |
82 | DISPLAY_FLAGS=\"$DISPLAY_FLAGS\" \ |
83 | COLLECT_FLAGS=\"$gprofflags\" GPROFNG=\"$gprofng\" MAKE=\"$MAKE\"" | |
84 | set output [run_native_host_cmd "cd $tdir && $MAKE $make_args all"] | |
85 | # send_log "run_native_host_cmd output:\n$output\n" | |
86 | if { [lindex $output 0] != 0 } then { | |
87 | set out [lindex $output 1] | |
88 | if {[file exists "$tdir/diff.out"]} then { | |
89 | send_log "comparison of results in $dir failed:\n$out\n" | |
90 | set pltf [exec uname -i] | |
91 | if { $pltf == "aarch64" } { | |
92 | xfail $dir | |
93 | return 0 | |
94 | } | |
95 | perror "comparison of results in $dir failed" | |
96 | } else { | |
97 | send_log "compilation of test program in $dir failed:\n$out\n" | |
98 | perror "compilation of test program in $dir failed" | |
99 | } | |
100 | fail $dir | |
101 | return 0 | |
102 | } | |
103 | pass $dir | |
104 | } |