Rename to util-defs.exp and turn into generic procedures.

This commit is contained in:
Rob Savoye
1993-04-08 05:26:10 +00:00
parent 3e7f73db77
commit a54a5a9ebc

View File

@ -15,12 +15,12 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
# Please email any bugs, comments, and/or additions to this file to: # Please email any bugs, comments, and/or additions to this file to:
# DejaGnu@cygnus.com # bug-dejagnu@prep.ai.mit.edu
# This file was written by Rob Savoye. (rob@cygnus.com) # This file was written by Rob Savoye. (rob@cygnus.com)
# #
# nm_test -- run nm and test the result. # util_test -- run a utility and test the result.
# Takes four parameters. # Takes four parameters.
# Parameters: # Parameters:
# First one is the command line arguments # First one is the command line arguments
@ -33,27 +33,26 @@
# 0 if the test passes, # 0 if the test passes,
# -1 if there was an internal error. # -1 if there was an internal error.
# #
proc nm_test { args } { proc util_test { args } {
global verbose global verbose
global comp_output
global NM
global NMFLAGS
# get the parameters # get the parameters
set cmd_arg [lindex $args 0] set cmd [lindex $args 0]
set file [lindex $args 1] verbose "Utility to execute is $cmd" 2
set pattern [lindex $args 2] set cmd_arg [lindex $args 1]
verbose "Command line arguments are $cmd_arg" 2
set file [lindex $args 2]
verbose "The file name to use is $file" 2
set pattern [lindex $args 3]
verbose "The pattern to match is \"$pattern\"" 2
if [llength $args]==4 then { if [llength $args]==5 then {
set message [lindex $args 3] set message [lindex $args 4]
} else { } else {
set message "$arg option" set message "$arg option"
} }
if $verbose>2 then { verbose "Looking to match \"$pattern\"\nMessage is \"$message\"" 1
send_user "Looking to match \"$pattern\"\n"
send_user "Message is \"$message\"\n"
}
if ![file exists $file] then { if ![file exists $file] then {
error "$file doesn't exist" error "$file doesn't exist"
@ -61,87 +60,44 @@ proc nm_test { args } {
} }
# #
# run nm and analyze the results # run the utility to be tested and analyze the results
# #
set nm_flags_orig $NMFLAGS set comp_output [util_start $cmd $cmd_arg $file]
append NMFLAGS " $cmd_arg"
nm_start $file
if [string match "" $comp_output] then {
fail "$message"
warning "Got no output."
set NMFLAGS $nm_flags_orig
return 1
}
if [regexp "$pattern" $comp_output] then { if [regexp "$pattern" $comp_output] then {
pass "$message" pass "$message"
set NMFLAGS $nm_flags_orig
return 0 return 0
} }
if [string match "" $comp_output] then {
warning "Got no output."
return 1
}
fail "$message" fail "$message"
set NMFLAGS $nm_flags_orig
return 1 return 1
} }
# since nm is purely host based, all the init module use these # util_start -- run the utility.
# same procedures # return NULL or the output
#
proc util_start { args } {
set cmd [lindex $args 0]
set cmd_arg [lindex $args 1]
set file [lindex $args 2]
# if {[which $cmd] == 0} then {
# default_nm_version -- extract and print the version number of nm error "Can't find $cmd"
# return ""
proc default_nm_version {} {
global NM
set tmp [exec $NM +version]
regexp " \[0-9\.\]+" $tmp version
clone_output "[which $NM] version $version\n"
unset tmp
unset version
}
#
# default_nm_load -- loads the program. For nm, we just execute it
#
proc default_nm_load { arg } {
global verbose
global exec_output
if ![file exists $args] then {
error $args does not exist"
return -1
} }
set status [catch "exec $arg" exec_output]
if $verbose>1 then {
send_user "Executed $arg\n"
}
return $status
}
# verbose "Spawning \"$cmd $cmd_arg $file\"" 1
# default_nm_exit -- just a stub for nm catch "exec $cmd $cmd_arg $file" comp_output
# if ![string match "" $comp_output] then {
proc default_nm_exit {} {
}
#
# nm_start -- start GDB running
#
proc default_nm_start { arg } {
global verbose
global NM
global NMFLAGS
global comp_output
if $verbose>1 then {
send_user "Spawning \"$NM $NMFLAGS $arg\"\n"
}
catch "exec $NM $NMFLAGS $arg" comp_output
if ![string match "" $comp_output] then {
send_log "$comp_output\n" send_log "$comp_output\n"
if $verbose>3 then { verbose "$comp_output" 1
send_user "$comp_output\n"
}
} }
return $comp_output
} }
# #