* lib/dejagnu.exp: Add $text\r\n to all strings, to make sure we
[dejagnu.git] / lib / dejagnu.exp
blobd550c5b59fd008caf1cc440d33e5cc0de9774a5e
1 # a hairy pattern to recognize text
2 set text "\[- A-Za-z0-9\.\;\"\_\:\'\`\(\)\!\#\=\+\?\&\*]"
4 set SIZE size
5 if { [which $SIZE] == 0 } {
6 perror "Can't find $SIZE."
9 # Get the size of the various section in an object file
10 proc exe_size {object} {
11 global SIZE
13 # Make sure size exists
14 if { [which $SIZE] == 0 } {
15 return [list "-1" "Can't find $SIZE."]
16 } else {
17 verbose "Using $SIZE for \"size\" program." 2
19 set status [catch "exec $SIZE -V" output]
20 if {[regexp "GNU size" $output] == 0} {
21 perror "Need GNU size from the binutils" 0
22 return [list "-1" "Need GNU size."]
25 # Get the object size. We pass -x, to force hex output
26 verbose "Getting the object file size for $object" 2
27 set status [catch "exec $SIZE -x $object" output]
28 verbose -log "Size of $object is\n$output" 2
30 # Remove the header line from the size output. This currently only
31 # works with GNU size
32 regsub "text.*filename\[\r\n\]*" $output "" output
34 # look for the size of the .text section
35 regexp "\[\r\n\]*0x\[0-9a-fA-F\]*" $output text
36 regsub "\[\r\n\]*0x\[0-9a-fA-F\]*\[ \t\]*" $output "" output
38 # look for the size of the .data section
39 regexp "0x\[0-9a-fA-F\]*\[ \t\]*" $output data
40 regsub "0x\[0-9a-fA-F\]*\[ \t\]*" $output "" output
42 # Values returns as hex
43 return [list $text $data]
46 # Run the host's native compiler, not the cross one. Filter out the
47 # warnings and other extraneous stuff.
48 # Returns:
49 # A "" (empty) string if everything worked, or the
50 # output if there was a problem.
51 proc host_compile {compline} {
52 global INCLUDES
53 global LIBS
54 global CXX, CC
56 # execute the compiler
57 verbose "Compiling for the host using: $CC $INCLUDES $LIBS $compline" 2
58 set status [catch "exec $CC $INCLUDES $LIBS $compline" comp_output];
59 verbose "Compiler returned $comp_output" 2
61 # prune common warnings and other stuff we can safely ignore
62 set comp_output [prune_warnings $comp_output];
64 # Trim multiple CR/LF pairs out to keep things consistant
65 regsub "^\[\r\n\]+" $comp_output "" comp_output;
67 # if we got a compiler error, log it
68 if { [lindex $status 0] != 0 } {
69 verbose -log "compiler exited with status [lindex $status 0]";
71 if { [lindex $status 1] != "" } {
72 verbose -log "output is:\n[lindex $status 1]" 2;
75 # return the filtered output
76 return ${comp_output}
79 # Execute the executable file, and anaylyse the output for the
80 # test state keywords.
81 # Returns:
82 # A "" (empty) string if everything worked, or an error message
83 # if there was a problem.
84 proc host_execute {args} {
85 global text
87 set timeoutmsg "Timed out: Never got started, "
88 set timeout 100
89 set file all
90 set timetol 0
91 set arguments ""
93 expect_before buffer_full { perror "Buffer full" }
95 if { [llength $args] == 0} {
96 set executable $args
97 } else {
98 set executable [string trimleft [lindex [split $args " "] 0] "\{"]
99 set params [string trimleft [lindex [split $args " "] 1] "\{"]
100 set params [string trimright $params "\}"]
103 verbose "The executable is $executable" 2
104 if ![file exists ${executable}] {
105 perror "The executable, \"$executable\" is missing" 0
106 return "No source file found"
109 # spawn the executable and look for the DejaGnu output messages from the
110 # test case.
111 # spawn -noecho -open [open "|./${executable}" "r"]
112 spawn -noecho "./${executable}" ${params}
113 expect {
114 -re "\[0-9\]\[0-9\]:..:..:${text}\r\n" {
115 regsub "\[\n\r\t\]*NOTE: $text\r\n" $expect_out(0,string) "" output
116 verbose "$output" 3
117 set timetol 0
118 exp_continue
120 -re "NOTE:${text}*" {
121 regsub "\[\n\r\t\]*NOTE: $text\r\n" $expect_out(0,string) "" output
122 verbose "$output" 2
123 set timetol 0
124 exp_continue
126 -re "PASSED:${text}*" {
127 regsub "\[\n\r\t\]*PASSED: $text\r\n" $expect_out(0,string) "" output
128 pass "$output"
129 set timetol 0
130 exp_continue
132 -re "FAILED:${text}*" {
133 regsub "\[\n\r\t\]*FAILED: $text\r\n" $expect_out(0,string) "" output
134 fail "$output"
135 set timetol 0
136 exp_continue
138 -re "UNTESTED:${text}*" {
139 regsub "\[\n\r\t\]*TESTED: $text\r\n" $expect_out(0,string) "" output
140 untested "$output"
141 set timetol 0
142 exp_continue
144 -re "UNRESOLVED:${text}*" {
145 regsub "\[\n\r\t\]*UNRESOLVED: $text\r\n" $expect_out(0,string) "" output
146 unresolved "$output"
147 set timetol 0
148 exp_continue
150 -re "Totals" {
151 verbose "All done" 2
153 eof {
154 # unresolved "${executable} died prematurely"
155 # catch close
156 # return "${executable} died prematurely"
158 timeout {
159 warning "Timed out executing test case"
160 if { $timetol <= 2 } {
161 incr timetol
162 exp_continue
163 } else {
164 - catch close
165 return "Timed out executing test case"
170 # force a close of the executable to be safe.
171 catch close
172 return ""