aboutsummaryrefslogtreecommitdiff
path: root/gprofng/testsuite/lib/display-lib.exp
blob: 38ecb8d258e9396d72aa1ae165e983e8ec75c14a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Support routines for display-testing machinery in gprofng testsuite.
#   Copyright (C) 1994-2021 Free Software Foundation, Inc.
#
# This file is part of the GNU Binutils.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
# MA 02110-1301, USA.

# Run the COMMAND on the host and return a list of the form
# { exit-status OUTPUT }.
proc run_native_host_cmd { command } {
    global link_output
    global ld

    verbose -log "$command"
    set run_output ""
    try {
	set run_output [exec "sh" "-c" "$command" "2>@1"]
	set status 0
    } trap CHILDSTATUS {results options} {
	set status [lindex [dict get $options -errorcode] 2]
	set run_output $results
    }
    regsub "\n$" $run_output "" run_output
    if { [lindex $status 0] != 0 && [string match "" $run_output] } then {
	append run_output "child process exited abnormally"
    }

    if [string match "" $run_output] then {
	return ""
    }

    return [list [lindex $status 0] $run_output]
}

# Run a display test in DIR.
# Unanswered questions: do we want to cycle through compilation flags,
# display options, collect flags, app options?  Do we want these to be
# set on a per-app basis? (If so, they should probably be driven by a
# file in the test dir.)
proc run_display_test { dir cflags gprofflags } {
    global srcdir MAKE CC CFLAGS LDFLAGS LIBS BUILDDIR
    set stripped [string map {" " ""} $dir]
    set testdir [string map {" " ""} "$dir.$cflags,$gprofflags"]
    set sdir "$srcdir/gprofng.display/$dir"
    set tdir "tmpdir/$testdir"
	send_log "create dir: $tdir\n"
	set output [run_native_host_cmd "mkdir -p $tdir"]
	set gprofng [exec find $BUILDDIR/tmpdir -type f -name gprofng -perm -u+x | head -1]

	set fd [open "$tdir/rules.txt" "w"]
	switch -regexp -- $testdir {
	  {-p,on.*-h,on} {
         set DISPLAY_FLAGS "-metrics i.totalcpu:i.cycles -func"
	     puts $fd "Cpu, 2, 0\n"
	     puts $fd "Cycles, 2, 1\n"
	  }
	  {-h,on} {
         set DISPLAY_FLAGS "-metrics i.cycles -func"
	     puts $fd "Cycles, 2, 0\n"
	  }
	  default {
         set DISPLAY_FLAGS "-metrics i.totalcpu -func"
	     puts $fd "Cpu, 2, 0\n"
	  }
	}
	close $fd 

    set make_args "-f $sdir/Makefile srcdir=\"$sdir\" builddir=\"$BUILDDIR\" \
        VPATH=\"$dir\" CC=\"$CC\" CFLAGS=\"$cflags\" LDFLAGS=\"$LDFLAGS\" \
        DISPLAY_FLAGS=\"$DISPLAY_FLAGS\" \
        COLLECT_FLAGS=\"$gprofflags\" GPROFNG=\"$gprofng\" MAKE=\"$MAKE\""
    set output [run_native_host_cmd "cd $tdir && $MAKE $make_args all"]
#	send_log "run_native_host_cmd output:\n$output\n"    
    if { [lindex $output 0] != 0 } then {
      set out [lindex $output 1]
      if {[file exists "$tdir/diff.out"]} then {
        send_log "comparison of results in $dir failed:\n$out\n"
        set pltf [exec uname -i]
        if { $pltf == "aarch64" } {
          xfail $dir
          return 0
        }
        perror "comparison of results in $dir failed"
      } else {
        send_log "compilation of test program in $dir failed:\n$out\n"
        perror "compilation of test program in $dir failed"
      }
      fail $dir
      return 0
    }
    pass $dir
}