1
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2
# 2001, 2002, 2003 Free Software Foundation, Inc.
4
# This file is part of DejaGnu.
6
# DejaGnu is free software; you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# DejaGnu is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
# General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with DejaGnu; if not, write to the Free Software Foundation,
18
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
# This file was written by Rob Savoye. (rob@welcomehome.org)
22
# a hairy pattern to recognize text
23
set text "\[- A-Za-z0-9\.\;\"\_\:\'\`\(\)\!\#\=\+\?\&\*]"
26
if { [which $SIZE] == 0 } {
27
perror "Can't find $SIZE."
30
# Get the size of the various section in an object file
31
proc exe_size {object} {
34
# Make sure size exists
35
if { [which $SIZE] == 0 } {
36
return [list "-1" "Can't find $SIZE."]
38
verbose "Using $SIZE for \"size\" program." 2
40
set status [catch "exec $SIZE -V" output]
41
if {[regexp "GNU size" $output] == 0} {
42
perror "Need GNU size from the binutils" 0
43
return [list "-1" "Need GNU size."]
46
# Get the object size. We pass -x, to force hex output
47
verbose "Getting the object file size for $object" 2
48
set status [catch "exec $SIZE -x $object" output]
49
verbose -log "Size of $object is\n$output" 2
51
# Remove the header line from the size output. This currently only
53
regsub "text.*filename\[\r\n\]*" $output "" output
55
# look for the size of the .text section
56
regexp "\[\r\n\]*0x\[0-9a-fA-F\]*" $output text
57
regsub "\[\r\n\]*0x\[0-9a-fA-F\]*\[ \t\]*" $output "" output
59
# look for the size of the .data section
60
regexp "0x\[0-9a-fA-F\]*\[ \t\]*" $output data
61
regsub "0x\[0-9a-fA-F\]*\[ \t\]*" $output "" output
63
# Values returns as hex
64
return [list $text $data]
67
# Run the host's native compiler, not the cross one. Filter out the
68
# warnings and other extraneous stuff.
70
# A "" (empty) string if everything worked, or the
71
# output if there was a problem.
72
proc host_compile {compline} {
77
# execute the compiler
78
verbose "Compiling for the host using: $CC $INCLUDES $LIBS $compline" 2
79
set status [catch "exec $CC $INCLUDES $LIBS $compline" comp_output]
80
verbose "Compiler returned $comp_output" 2
82
# prune common warnings and other stuff we can safely ignore
83
set comp_output [prune_warnings $comp_output]
85
# Trim multiple CR/LF pairs out to keep things consistant
86
regsub "^\[\r\n\]+" $comp_output "" comp_output
88
# if we got a compiler error, log it
89
if { [lindex $status 0] != 0 } {
90
verbose -log "compiler exited with status [lindex $status 0]"
92
if { [lindex $status 1] != "" } {
93
verbose -log "output is:\n[lindex $status 1]" 2
96
# return the filtered output
100
# Execute the executable file, and anaylyse the output for the
101
# test state keywords.
103
# A "" (empty) string if everything worked, or an error message
104
# if there was a problem.
105
proc host_execute {args} {
108
set timeoutmsg "Timed out: Never got started, "
114
expect_before buffer_full { perror "Buffer full" }
116
if { [llength $args] == 0} {
119
set executable [string trimleft [lindex [split $args " "] 0] "\{"]
120
set params [string trimleft [lindex [split $args " "] 1] "\{"]
121
set params [string trimright $params "\}"]
124
verbose "The executable is $executable" 2
125
if ![file exists ${executable}] {
126
perror "The executable, \"$executable\" is missing" 0
127
return "No source file found"
130
# spawn the executable and look for the DejaGnu output messages from the
132
# spawn -noecho -open [open "|./${executable}" "r"]
133
spawn -noecho "./${executable}" ${params}
135
-re "\[0-9\]\[0-9\]:..:..:${text}\r\n" {
136
regsub "\[\n\r\t\]*NOTE: $text\r\n" $expect_out(0,string) "" output
141
-re "NOTE:${text}*" {
142
regsub "\[\n\r\t\]*NOTE: $text\r\n" $expect_out(0,string) "" output
143
set output [string range $output 6 end]
148
-re "PASSED:${text}*" {
149
regsub "\[\n\r\t\]*PASSED: $text\r\n" $expect_out(0,string) "" output
150
set output [string range $output 8 end]
155
-re "FAILED:${text}*" {
156
regsub "\[\n\r\t\]*FAILED: $text\r\n" $expect_out(0,string) "" output
157
set output [string range $output 8 end]
162
-re "UNTESTED:${text}*" {
163
regsub "\[\n\r\t\]*TESTED: $text\r\n" $expect_out(0,string) "" output
164
set output [string range $output 8 end]
169
-re "UNRESOLVED:${text}*" {
170
regsub "\[\n\r\t\]*UNRESOLVED: $text\r\n" $expect_out(0,string) "" output
171
set output [string range $output 8 end]
180
# unresolved "${executable} died prematurely"
182
# return "${executable} died prematurely"
185
warning "Timed out executing test case"
186
if { $timetol <= 2 } {
191
return "Timed out executing test case"
196
# force a close of the executable to be safe.