|
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 |
#
|
|
Packit |
62fe53 |
# Run a utility and test the result.
|
|
Packit |
62fe53 |
#
|
|
Packit |
62fe53 |
# Parameters:
|
|
Packit |
62fe53 |
# First one is the command
|
|
Packit |
62fe53 |
# Second one is command arguments
|
|
Packit |
62fe53 |
# Third one is the file name
|
|
Packit |
62fe53 |
# Fourth one is the regexp style pattern to match for a PASS
|
|
Packit |
62fe53 |
#
|
|
Packit |
62fe53 |
# Returns:
|
|
Packit |
62fe53 |
# 1 if the test failed,
|
|
Packit |
62fe53 |
# 0 if the test passes,
|
|
Packit |
62fe53 |
# -1 if there was an internal error.
|
|
Packit |
62fe53 |
#
|
|
Packit |
62fe53 |
|
|
Packit |
62fe53 |
proc util_test { args } {
|
|
Packit |
62fe53 |
global verbose
|
|
Packit |
62fe53 |
# get the parameters
|
|
Packit |
62fe53 |
set cmd [lindex $args 0]
|
|
Packit |
62fe53 |
verbose "Utility to execute is $cmd" 2
|
|
Packit |
62fe53 |
set cmd_arg [lindex $args 1]
|
|
Packit |
62fe53 |
verbose "Command line arguments are $cmd_arg" 2
|
|
Packit |
62fe53 |
set file [lindex $args 2]
|
|
Packit |
62fe53 |
verbose "The file name to use is $file" 2
|
|
Packit |
62fe53 |
set pattern [lindex $args 3]
|
|
Packit |
62fe53 |
verbose "The pattern to match is \"$pattern\"" 2
|
|
Packit |
62fe53 |
|
|
Packit |
62fe53 |
if [info exists file] {
|
|
Packit |
62fe53 |
if ![string match "" $file] {
|
|
Packit |
62fe53 |
if ![file exists $file] {
|
|
Packit |
62fe53 |
perror "$file doesn't exist"
|
|
Packit |
62fe53 |
return -1
|
|
Packit |
62fe53 |
}
|
|
Packit |
62fe53 |
}
|
|
Packit |
62fe53 |
}
|
|
Packit |
62fe53 |
|
|
Packit |
62fe53 |
# Run the utility to be tested and analyze the results.
|
|
Packit |
62fe53 |
|
|
Packit |
62fe53 |
set comp_output [util_start $cmd $cmd_arg $file]
|
|
Packit |
62fe53 |
|
|
Packit |
62fe53 |
verbose "Output is \"$comp_output\"" 2
|
|
Packit |
62fe53 |
verbose "Pattern is \"$pattern\"" 2
|
|
Packit |
62fe53 |
|
|
Packit |
62fe53 |
if [regexp "$pattern" $comp_output] {
|
|
Packit |
62fe53 |
verbose "Pattern matches." 2
|
|
Packit |
62fe53 |
return 0
|
|
Packit |
62fe53 |
}
|
|
Packit |
62fe53 |
|
|
Packit |
62fe53 |
verbose "Pattern does not match." 2
|
|
Packit |
62fe53 |
return 1
|
|
Packit |
62fe53 |
}
|
|
Packit |
62fe53 |
|
|
Packit |
62fe53 |
#
|
|
Packit |
62fe53 |
# Run the utility
|
|
Packit |
62fe53 |
#
|
|
Packit |
62fe53 |
# Return NULL or the output.
|
|
Packit |
62fe53 |
#
|
|
Packit |
62fe53 |
|
|
Packit |
62fe53 |
proc util_start { args } {
|
|
Packit |
62fe53 |
global verbose
|
|
Packit |
62fe53 |
set cmd [lindex $args 0]
|
|
Packit |
62fe53 |
set cmd_arg [lindex $args 1]
|
|
Packit |
62fe53 |
set file [lindex $args 2]
|
|
Packit |
62fe53 |
|
|
Packit |
62fe53 |
if {[which $cmd] == 0} {
|
|
Packit |
62fe53 |
perror "Can't find $cmd"
|
|
Packit |
62fe53 |
return ""
|
|
Packit |
62fe53 |
}
|
|
Packit |
62fe53 |
|
|
Packit |
62fe53 |
if { $verbose > 0 } {
|
|
Packit |
62fe53 |
verbose "Spawning \"$cmd $cmd_arg $file\""
|
|
Packit |
62fe53 |
} else {
|
|
Packit |
62fe53 |
send_log "Spawning \"$cmd $cmd_arg $file\"\n"
|
|
Packit |
62fe53 |
}
|
|
Packit |
62fe53 |
catch "exec $cmd $cmd_arg $file" comp_output
|
|
Packit |
62fe53 |
if ![string match "" $comp_output] {
|
|
Packit |
62fe53 |
send_log "$comp_output\n"
|
|
Packit |
62fe53 |
}
|
|
Packit |
62fe53 |
return $comp_output
|
|
Packit |
62fe53 |
}
|