Blame lib/dejagnu.exp

Packit 62fe53
# Copyright (C) 1992-2016 Free Software Foundation, Inc.
Packit 62fe53
#
Packit 62fe53
# This file is part of DejaGnu.
Packit 62fe53
#
Packit 62fe53
# DejaGnu is free software; you can redistribute it and/or modify it
Packit 62fe53
# under the terms of the GNU General Public License as published by
Packit 62fe53
# the Free Software Foundation; either version 3 of the License, or
Packit 62fe53
# (at your option) any later version.
Packit 62fe53
#
Packit 62fe53
# DejaGnu is distributed in the hope that it will be useful, but
Packit 62fe53
# WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 62fe53
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 62fe53
# General Public License for more details.
Packit 62fe53
#
Packit 62fe53
# You should have received a copy of the GNU General Public License
Packit 62fe53
# along with DejaGnu; if not, write to the Free Software Foundation,
Packit 62fe53
# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
Packit 62fe53
Packit 62fe53
# This file was written by Rob Savoye <rob@welcomehome.org>.
Packit 62fe53
Packit 62fe53
# A hairy pattern to recognize text.
Packit 62fe53
set text "\[- A-Za-z0-9\.\;\"\_\:\'\`\(\)\!\#\=\+\?\&\*<>]"
Packit 62fe53
Packit 62fe53
set SIZE size
Packit 62fe53
if { [which $SIZE] == 0 } {
Packit 62fe53
    perror "Can't find $SIZE."
Packit 62fe53
}
Packit 62fe53
Packit 62fe53
# Get the size of the various section in OBJECT.
Packit 62fe53
proc exe_size {object} {
Packit 62fe53
    global SIZE
Packit 62fe53
Packit 62fe53
    # Make sure size exists
Packit 62fe53
    if { [which $SIZE] == 0 } {
Packit 62fe53
	return [list "-1" "Can't find $SIZE."]
Packit 62fe53
    } else {
Packit 62fe53
	verbose "Using $SIZE for \"size\" program." 2
Packit 62fe53
    }
Packit 62fe53
    set status [catch "exec $SIZE -V" output]
Packit 62fe53
    if {[regexp "GNU size" $output] == 0} {
Packit 62fe53
	perror "Need GNU size from the binutils" 0
Packit 62fe53
	return [list "-1" "Need GNU size."]
Packit 62fe53
    }
Packit 62fe53
Packit 62fe53
    # Get the object size. We pass -x, to force hex output
Packit 62fe53
    verbose "Getting the object file size for $object" 2
Packit 62fe53
    set status [catch "exec $SIZE -x $object" output]
Packit 62fe53
    verbose -log "Size of $object is\n$output" 2
Packit 62fe53
Packit 62fe53
    # Remove the header line from the size output. This currently only
Packit 62fe53
    # works with GNU size
Packit 62fe53
    regsub "text.*filename\[\r\n\]*" $output "" output
Packit 62fe53
Packit 62fe53
    # look for the size of the .text section
Packit 62fe53
    regexp "\[\r\n\]*0x\[0-9a-fA-F\]*" $output text
Packit 62fe53
    regsub "\[\r\n\]*0x\[0-9a-fA-F\]*\[ \t\]*" $output "" output
Packit 62fe53
Packit 62fe53
    # look for the size of the .data section
Packit 62fe53
    regexp "0x\[0-9a-fA-F\]*\[ \t\]*" $output data
Packit 62fe53
    regsub "0x\[0-9a-fA-F\]*\[ \t\]*" $output "" output
Packit 62fe53
Packit 62fe53
    # Values returns as hex
Packit 62fe53
    return [list $text $data]
Packit 62fe53
}
Packit 62fe53
Packit 62fe53
# Run the host's native compiler, not the cross one. Filter out the
Packit 62fe53
# warnings and other extraneous stuff.
Packit 62fe53
#    Returns:
Packit 62fe53
#	A "" (empty) string if everything worked, or the
Packit 62fe53
#       output if there was a problem.
Packit 62fe53
#
Packit 62fe53
proc host_compile {compline} {
Packit 62fe53
    global INCLUDES
Packit 62fe53
    global LIBS
Packit 62fe53
    global CXX, CC
Packit 62fe53
Packit 62fe53
    # execute the compiler
Packit 62fe53
    verbose "Compiling for the host using: $CC $INCLUDES $LIBS $compline" 2
Packit 62fe53
    set status [catch "exec $CC $INCLUDES $LIBS $compline" comp_output]
Packit 62fe53
    verbose "Compiler returned $comp_output" 2
Packit 62fe53
Packit 62fe53
    # prune common warnings and other stuff we can safely ignore
Packit 62fe53
    set comp_output [prune_warnings $comp_output]
Packit 62fe53
Packit 62fe53
    # Trim multiple CR/LF pairs out to keep things consistent
Packit 62fe53
    regsub "^\[\r\n\]+" $comp_output "" comp_output
Packit 62fe53
Packit 62fe53
    # if we got a compiler error, log it
Packit 62fe53
    if { [lindex $status 0] != 0 } {
Packit 62fe53
	verbose -log "compiler exited with status [lindex $status 0]"
Packit 62fe53
    }
Packit 62fe53
    if { [lindex $status 1] != "" } {
Packit 62fe53
	verbose -log "output is:\n[lindex $status 1]" 2
Packit 62fe53
    }
Packit 62fe53
Packit 62fe53
    # return the filtered output
Packit 62fe53
    return ${comp_output}
Packit 62fe53
}
Packit 62fe53
Packit 62fe53
# Execute the executable file, and analyse the output for the test
Packit 62fe53
# state keywords.
Packit 62fe53
#    Returns:
Packit 62fe53
#	A "" (empty) string if everything worked, or an error message
Packit 62fe53
#	if there was a problem.
Packit 62fe53
#
Packit 62fe53
proc host_execute {args} {
Packit 62fe53
    global text
Packit 62fe53
Packit 62fe53
    set timeoutmsg "Timed out: Never got started, "
Packit 62fe53
    set timeout 100
Packit 62fe53
    set file all
Packit 62fe53
    set timetol 0
Packit 62fe53
    set arguments ""
Packit 62fe53
Packit 62fe53
    if { [llength $args] == 0} {
Packit 62fe53
	set executable $args
Packit 62fe53
    } else {
Packit 62fe53
	set executable [string trimleft [lindex [split $args " "] 0] "\{"]
Packit 62fe53
	set params [string trimleft [lindex [split $args " "] 1] "\{"]
Packit 62fe53
	set params [string trimright $params "\}"]
Packit 62fe53
    }
Packit 62fe53
Packit 62fe53
    verbose "The executable is $executable" 2
Packit 62fe53
    if {![file exists ${executable}]} {
Packit 62fe53
	perror "The executable, \"$executable\" is missing" 0
Packit 62fe53
	return "No source file found"
Packit 62fe53
    }
Packit 62fe53
Packit 62fe53
    # spawn the executable and look for the DejaGnu output messages from the
Packit 62fe53
    # test case.
Packit 62fe53
    # spawn -noecho -open [open "|./${executable}" "r"]
Packit 62fe53
    spawn -noecho "./${executable}" ${params}
Packit 62fe53
    set prefix "\[^\r\n\]*"
Packit 62fe53
    expect {
Packit 62fe53
	-re "^$prefix\[0-9\]\[0-9\]:..:..:${text}*\r\n" {
Packit 62fe53
	    regsub "\[\n\r\t\]*NOTE: $text\r\n" $expect_out(0,string) "" output
Packit 62fe53
	    verbose "$output" 3
Packit 62fe53
	    set timetol 0
Packit 62fe53
	    exp_continue
Packit 62fe53
	}
Packit 62fe53
	-re "^$prefix\tNOTE:${text}*" {
Packit 62fe53
	    regsub "\[\n\r\t\]*NOTE: $text\r\n" $expect_out(0,string) "" output
Packit 62fe53
	    set output [string range $output 6 end]
Packit 62fe53
	    verbose "$output" 2
Packit 62fe53
	    set timetol 0
Packit 62fe53
	    exp_continue
Packit 62fe53
	}
Packit 62fe53
	-re "^$prefix\tPASSED:${text}*" {
Packit 62fe53
	    regsub "\[\n\r\t\]*PASSED: $text\r\n" $expect_out(0,string) "" output
Packit 62fe53
	    set output [string range $output 8 end]
Packit 62fe53
	    pass "$output"
Packit 62fe53
	    set timetol 0
Packit 62fe53
	    exp_continue
Packit 62fe53
	}
Packit 62fe53
	-re "^$prefix\tFAILED:${text}*" {
Packit 62fe53
	    regsub "\[\n\r\t\]*FAILED: $text\r\n" $expect_out(0,string) "" output
Packit 62fe53
	    set output [string range $output 8 end]
Packit 62fe53
	    fail "$output"
Packit 62fe53
	    set timetol 0
Packit 62fe53
	    exp_continue
Packit 62fe53
	}
Packit 62fe53
	-re "^$prefix\tUNTESTED:${text}*" {
Packit 62fe53
	    regsub "\[\n\r\t\]*TESTED: $text\r\n" $expect_out(0,string) "" output
Packit 62fe53
	    set output [string range $output 8 end]
Packit 62fe53
	    untested "$output"
Packit 62fe53
	    set timetol 0
Packit 62fe53
	    exp_continue
Packit 62fe53
	}
Packit 62fe53
	-re "^$prefix\tUNRESOLVED:${text}*" {
Packit 62fe53
	    regsub "\[\n\r\t\]*UNRESOLVED: $text\r\n" $expect_out(0,string) "" output
Packit 62fe53
	    set output [string range $output 8 end]
Packit 62fe53
	    unresolved "$output"
Packit 62fe53
	    set timetol 0
Packit 62fe53
	    exp_continue
Packit 62fe53
	}
Packit 62fe53
	-re "^Totals" {
Packit 62fe53
	    verbose "All done" 2
Packit 62fe53
	}
Packit 62fe53
	eof {
Packit 62fe53
	    #	    unresolved "${executable} died prematurely"
Packit 62fe53
	    #	    catch close
Packit 62fe53
	    #	    return "${executable} died prematurely"
Packit 62fe53
	}
Packit 62fe53
	timeout {
Packit 62fe53
	    warning "Timed out executing test case"
Packit 62fe53
	    if { $timetol <= 2 } {
Packit 62fe53
		incr timetol
Packit 62fe53
		exp_continue
Packit 62fe53
	    } else {
Packit 62fe53
		catch close
Packit 62fe53
		return "Timed out executing test case"
Packit 62fe53
	    }
Packit 62fe53
	}
Packit 62fe53
	-re "^$prefix\r\n" {
Packit 62fe53
	    exp_continue
Packit 62fe53
	}
Packit 62fe53
    }
Packit 62fe53
Packit 62fe53
    # force a close of the executable to be safe.
Packit 62fe53
    catch close
Packit 62fe53
    return ""
Packit 62fe53
}