~ubuntu-branches/ubuntu/feisty/dejagnu/feisty

« back to all changes in this revision

Viewing changes to lib/dejagnu.exp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Jacobowitz
  • Date: 2004-02-09 15:07:58 UTC
  • Revision ID: james.westby@ubuntu.com-20040209150758-oaj7r5zrop60v8sb
Tags: upstream-1.4.4
ImportĀ upstreamĀ versionĀ 1.4.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
 
2
# 2001, 2002, 2003 Free Software Foundation, Inc.
 
3
#
 
4
# This file is part of DejaGnu.
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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.
 
19
 
 
20
# This file was written by Rob Savoye. (rob@welcomehome.org)
 
21
 
 
22
# a hairy pattern to recognize text
 
23
set text "\[- A-Za-z0-9\.\;\"\_\:\'\`\(\)\!\#\=\+\?\&\*]"
 
24
 
 
25
set SIZE size
 
26
if { [which $SIZE] == 0 } {
 
27
    perror "Can't find $SIZE."
 
28
}
 
29
 
 
30
# Get the size of the various section in an object file
 
31
proc exe_size {object} {
 
32
    global SIZE
 
33
 
 
34
    # Make sure size exists
 
35
    if { [which $SIZE] == 0 } {
 
36
        return [list "-1" "Can't find $SIZE."]
 
37
    } else {
 
38
        verbose "Using $SIZE for \"size\" program." 2
 
39
    }
 
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."]
 
44
    }
 
45
 
 
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
 
50
 
 
51
    # Remove the header line from the size output. This currently only
 
52
    # works with GNU size
 
53
    regsub "text.*filename\[\r\n\]*" $output "" output
 
54
 
 
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
 
58
 
 
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
 
62
 
 
63
    # Values returns as hex
 
64
    return [list $text $data]
 
65
}
 
66
 
 
67
# Run the host's native compiler, not the cross one. Filter out the
 
68
# warnings and other extraneous stuff.
 
69
#    Returns:
 
70
#       A "" (empty) string if everything worked, or the
 
71
#       output if there was a problem.
 
72
proc host_compile {compline} {
 
73
    global INCLUDES
 
74
    global LIBS
 
75
    global CXX, CC
 
76
 
 
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
 
81
 
 
82
    # prune common warnings and other stuff we can safely ignore
 
83
    set comp_output [prune_warnings $comp_output]
 
84
 
 
85
    # Trim multiple CR/LF pairs out to keep things consistant
 
86
    regsub "^\[\r\n\]+" $comp_output "" comp_output
 
87
 
 
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]"
 
91
    }
 
92
    if { [lindex $status 1] != "" } {
 
93
        verbose -log "output is:\n[lindex $status 1]" 2
 
94
    }
 
95
 
 
96
    # return the filtered output
 
97
    return ${comp_output}
 
98
}
 
99
 
 
100
# Execute the executable file, and anaylyse the output for the
 
101
# test state keywords.
 
102
#    Returns:
 
103
#       A "" (empty) string if everything worked, or an error message
 
104
#       if there was a problem.
 
105
proc host_execute {args} {
 
106
    global text
 
107
 
 
108
    set timeoutmsg "Timed out: Never got started, "
 
109
    set timeout 100
 
110
    set file all
 
111
    set timetol 0
 
112
    set arguments ""
 
113
 
 
114
    expect_before buffer_full { perror "Buffer full" }
 
115
 
 
116
    if { [llength $args] == 0} {
 
117
        set executable $args
 
118
    } else {
 
119
        set executable [string trimleft [lindex [split $args " "] 0] "\{"]
 
120
        set params [string trimleft [lindex [split $args " "] 1] "\{"]
 
121
        set params [string trimright $params "\}"]
 
122
    }
 
123
 
 
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"
 
128
    }
 
129
 
 
130
    # spawn the executable and look for the DejaGnu output messages from the
 
131
    # test case.
 
132
    # spawn -noecho -open [open "|./${executable}" "r"]
 
133
    spawn -noecho "./${executable}" ${params}
 
134
    expect {
 
135
        -re "\[0-9\]\[0-9\]:..:..:${text}\r\n" {
 
136
            regsub "\[\n\r\t\]*NOTE: $text\r\n" $expect_out(0,string) "" output
 
137
            verbose "$output" 3
 
138
            set timetol 0
 
139
            exp_continue
 
140
        }
 
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]
 
144
            verbose "$output" 2
 
145
            set timetol 0
 
146
            exp_continue
 
147
        }
 
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]
 
151
            pass "$output"
 
152
            set timetol 0
 
153
            exp_continue
 
154
        }
 
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]
 
158
            fail "$output"
 
159
            set timetol 0
 
160
            exp_continue
 
161
        }
 
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]
 
165
            untested "$output"
 
166
            set timetol 0
 
167
            exp_continue
 
168
        }
 
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]
 
172
            unresolved "$output"
 
173
            set timetol 0
 
174
            exp_continue
 
175
        }
 
176
        -re "Totals" {
 
177
            verbose "All done" 2
 
178
        }
 
179
        eof {
 
180
            #       unresolved "${executable} died prematurely"
 
181
            #       catch close
 
182
            #       return "${executable} died prematurely"
 
183
        }
 
184
        timeout {
 
185
            warning "Timed out executing test case"
 
186
            if { $timetol <= 2 } {
 
187
                incr timetol
 
188
                exp_continue
 
189
            } else {
 
190
                -               catch close
 
191
                return "Timed out executing test case"
 
192
            }
 
193
        }
 
194
    }
 
195
 
 
196
    # force a close of the executable to be safe.
 
197
    catch close
 
198
    return ""
 
199
}
 
200