aboutsummaryrefslogtreecommitdiff
path: root/lib/dejagnu.exp
diff options
context:
space:
mode:
authorRob Savoye <rob@welcomehome.org>2001-04-12 05:32:15 +0000
committerRob Savoye <rob@welcomehome.org>2001-04-12 05:32:15 +0000
commitad5950c28155a9583b19cff68d3e7546d126c5f2 (patch)
treea6484f9f953cee37af6ad7daf7a196ffb63bde50 /lib/dejagnu.exp
parent67f23aa1c6cbc0d31adfed48dbbf0b140b4bcc12 (diff)
downloaddejagnu-ad5950c28155a9583b19cff68d3e7546d126c5f2.zip
dejagnu-ad5950c28155a9583b19cff68d3e7546d126c5f2.tar.gz
dejagnu-ad5950c28155a9583b19cff68d3e7546d126c5f2.tar.bz2
* Clean.tcl: Add -r to rm, so it gets rid of CVS directories.
* .clean: Don't install the debian or redhat packaging directories. * Makefle.am: Install dejagnu.h. Fix dist2 target, so we build our own tarballs, instead of letting automake do it for us. * examples/cala/Makefile.am: Use noist_PROGRAMS, so calc doesn't get installed. * doc/Makefile.am: Install the man page for runtest. * configure.in: Make VERSION 1.4.0, not just 1.4, so distributions get built right. * lib/dejagnu.exp: Test driver for embedded DejaGnu API. * dejagnu.h: Embedded DejaGnu API main header file. * config/default.exp: Default tool init file for simple test suites.
Diffstat (limited to 'lib/dejagnu.exp')
-rwxr-xr-xlib/dejagnu.exp174
1 files changed, 174 insertions, 0 deletions
diff --git a/lib/dejagnu.exp b/lib/dejagnu.exp
new file mode 100755
index 0000000..f98effb
--- /dev/null
+++ b/lib/dejagnu.exp
@@ -0,0 +1,174 @@
+# a hairy pattern to recognize text
+set text "\[- A-Za-z0-9\.\;\"\_\:\'\`\(\)\!\#\=\+\?\&\*]"
+
+set SIZE size
+if { [which $SIZE] == 0 } {
+ perror "Can't find $SIZE."
+}
+
+# Get the size of the various section in an object file
+proc exe_size {object} {
+ global SIZE
+
+ # Make sure size exists
+ if { [which $SIZE] == 0 } {
+ return [list "-1" "Can't find $SIZE."]
+ } else {
+ verbose "Using $SIZE for \"size\" program." 2
+ }
+ set status [catch "exec $SIZE -V" output]
+ if {[regexp "GNU size" $output] == 0} {
+ perror "Need GNU size from the binutils" 0
+ return [list "-1" "Need GNU size."]
+ }
+
+ # Get the object size. We pass -x, to force hex output
+ verbose "Getting the object file size for $object" 2
+ set status [catch "exec $SIZE -x $object" output]
+ verbose -log "Size of $object is\n$output" 2
+
+ # Remove the header line from the size output. This currently only
+ # works with GNU size
+ regsub "text.*filename\[\r\n\]*" $output "" output
+
+ # look for the size of the .text section
+ regexp "\[\r\n\]*0x\[0-9a-fA-F\]*" $output text
+ regsub "\[\r\n\]*0x\[0-9a-fA-F\]*\[ \t\]*" $output "" output
+
+ # look for the size of the .data section
+ regexp "0x\[0-9a-fA-F\]*\[ \t\]*" $output data
+ regsub "0x\[0-9a-fA-F\]*\[ \t\]*" $output "" output
+
+ # Values returns as hex
+ return [list $text $data]
+}
+
+# Run the host's native compiler, not the cross one. Filter out the
+# warnings and other extraneous stuff.
+# Returns:
+# A "" (empty) string if everything worked, or the
+# output if there was a problem.
+proc host_compile {compline} {
+ global INCLUDES
+ global LIBS
+ global CXX, CC
+
+ # execute the compiler
+ verbose "Compiling for the host using: $CC $INCLUDES $LIBS $compline" 2
+ set status [catch "exec $CC $INCLUDES $LIBS $compline" comp_output];
+ verbose "Compiler returned $comp_output" 2
+
+ # prune common warnings and other stuff we can safely ignore
+ set comp_output [prune_warnings $comp_output];
+
+ # Trim multiple CR/LF pairs out to keep things consistant
+ regsub "^\[\r\n\]+" $comp_output "" comp_output;
+
+ # if we got a compiler error, log it
+ if { [lindex $status 0] != 0 } {
+ verbose -log "compiler exited with status [lindex $status 0]";
+ }
+ if { [lindex $status 1] != "" } {
+ verbose -log "output is:\n[lindex $status 1]" 2;
+ }
+
+ # return the filtered output
+ return ${comp_output}
+}
+
+# Execute the executable file, and anaylyse the output for the
+# test state keywords.
+# Returns:
+# A "" (empty) string if everything worked, or an error message
+# if there was a problem.
+proc host_execute {args} {
+ global text
+
+ set timeoutmsg "Timed out: Never got started, "
+ set timeout 100
+ set file all
+ set timetol 0
+ set arguments ""
+
+ expect_before buffer_full { perror "Buffer full" }
+
+ if { [llength $args] == 0} {
+ set executable $args
+ } else {
+ set executable [string trimleft [lindex [split $args " "] 0] "\{"]
+ set params [string trimleft [lindex [split $args " "] 1] "\{"]
+ set params [string trimright $params "\}"]
+ }
+
+ verbose "The executable is $executable" 2
+ if ![file exists ${executable}] {
+ perror "The executable, \"$executable\" is missing" 0
+ return "No source file found"
+ }
+
+ # spawn the executable and look for the DejaGnu output messages from the
+ # test case.
+ # spawn -noecho -open [open "|./${executable}" "r"]
+ spawn -noecho "./${executable}" ${params}
+ expect {
+ -re "\[0-9\]\[0-9\]:..:..:${text}\r\n" {
+ regsub "\[\n\r\t\]*NOTE: " $expect_out(0,string) "" output
+ verbose "$output" 3
+ set timetol 0
+ exp_continue
+ }
+ -re "NOTE:${text}*" {
+ regsub "\[\n\r\t\]*NOTE: " $expect_out(0,string) "" output
+ verbose "$output" 2
+ set timetol 0
+ exp_continue
+ }
+ -re "PASSED:${text}*" {
+ regsub "\[\n\r\t\]*PASSED: " $expect_out(0,string) "" output
+ pass "$output"
+ set timetol 0
+ exp_continue
+ }
+ -re "FAILED:${text}*" {
+ regsub "\[\n\r\t\]*FAILED: " $expect_out(0,string) "" output
+ fail "$output"
+ set timetol 0
+ exp_continue
+ }
+ -re "UNTESTED:${text}*" {
+ regsub "\[\n\r\t\]*TESTED: " $expect_out(0,string) "" output
+ untested "$output"
+ set timetol 0
+ exp_continue
+ }
+ -re "UNRESOLVED:${text}*" {
+ regsub "\[\n\r\t\]*UNRESOLVED: " $expect_out(0,string) "" output
+ unresolved "$output"
+ set timetol 0
+ exp_continue
+ }
+ -re "Totals" {
+ verbose "All done" 2
+ }
+ eof {
+# unresolved "${executable} died prematurely"
+# catch close
+# return "${executable} died prematurely"
+ }
+ timeout {
+ warning "Timed out executing test case"
+ if { $timetol <= 2 } {
+ incr timetol
+ exp_continue
+ } else {
+- catch close
+ return "Timed out executing test case"
+ }
+ }
+ }
+
+ # force a close of the executable to be safe.
+ catch close
+ return ""
+}
+