1 # Support routines for display-testing machinery in gprofng testsuite.
2 # Copyright (C) 1994-2024 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
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.
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.
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,
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 } {
26 verbose -log "$command"
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"]
32 } trap CHILDSTATUS {results options} {
33 set status [lindex [dict get $options -errorcode] 2]
34 set run_output "$results"
35 if { $status == 124 || $status == 133 } {
36 send_log " ERROR: TIMEOUT($TEST_TIMEOUT sec.)\n"
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"
43 return [list [lindex $status 0] "$run_output"]
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.)
51 proc run_display_test { dir cflags gprofflags tflags } {
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"]
59 set gprofng $::env(GPROFNG)
61 set fd [open "$tdir/rules.txt" "w"]
62 switch -regexp -- $testdir {
64 set DISPLAY_FLAGS "-metrics i.totalcpu:i.cycles -func"
65 puts $fd "Cpu, 2, 0\n"
66 puts $fd "Cycles, 2, 1\n"
69 set DISPLAY_FLAGS "-metrics i.cycles -func"
70 puts $fd "Cycles, 2, 0\n"
73 set DISPLAY_FLAGS "-metrics i.totalcpu -func"
74 puts $fd "Cpu, 2, 0\n"
79 set make_args "-f $sdir/Makefile srcdir=\"$sdir\" builddir=\"$BUILDDIR\" \
80 VPATH=\"$dir\" CC=\"$CC\" CFLAGS=\"$cflags\" LDFLAGS=\"$LDFLAGS\" \
81 TARGET_FLAGS=\"$tflags\" \
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" } {
95 perror "comparison of results in $dir failed"
97 send_log "compilation of test program in $dir failed:\n$out\n"
98 perror "compilation of test program in $dir failed"