| 1 |
# Copyright (C) 1992-2016 Free Software Foundation, Inc. |
| 2 |
# |
| 3 |
# This file is part of DejaGnu. |
| 4 |
# |
| 5 |
# DejaGnu is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# DejaGnu is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
# General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with DejaGnu; if not, write to the Free Software Foundation, |
| 17 |
# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 |
|
| 19 |
# This file was written by Rob Savoye <[email protected]>. |
| 20 |
|
| 21 |
# |
| 22 |
# Run a utility and test the result. |
| 23 |
# |
| 24 |
# Parameters: |
| 25 |
# First one is the command |
| 26 |
# Second one is command arguments |
| 27 |
# Third one is the file name |
| 28 |
# Fourth one is the regexp style pattern to match for a PASS |
| 29 |
# |
| 30 |
# Returns: |
| 31 |
# 1 if the test failed, |
| 32 |
# 0 if the test passes, |
| 33 |
# -1 if there was an internal error. |
| 34 |
# |
| 35 |
|
| 36 |
proc util_test { args } { |
| 37 |
global verbose |
| 38 |
# get the parameters |
| 39 |
set cmd [lindex $args 0] |
| 40 |
verbose "Utility to execute is $cmd" 2 |
| 41 |
set cmd_arg [lindex $args 1] |
| 42 |
verbose "Command line arguments are $cmd_arg" 2 |
| 43 |
set file [lindex $args 2] |
| 44 |
verbose "The file name to use is $file" 2 |
| 45 |
set pattern [lindex $args 3] |
| 46 |
verbose "The pattern to match is \"$pattern\"" 2 |
| 47 |
|
| 48 |
if [info exists file] { |
| 49 |
if {$file ne ""} { |
| 50 |
if {![file exists $file]} { |
| 51 |
perror "$file doesn't exist" |
| 52 |
return -1 |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
# Run the utility to be tested and analyze the results. |
| 58 |
|
| 59 |
set comp_output [util_start $cmd $cmd_arg $file] |
| 60 |
|
| 61 |
verbose "Output is \"$comp_output\"" 2 |
| 62 |
verbose "Pattern is \"$pattern\"" 2 |
| 63 |
|
| 64 |
if [regexp $pattern $comp_output] { |
| 65 |
verbose "Pattern matches." 2 |
| 66 |
return 0 |
| 67 |
} |
| 68 |
|
| 69 |
verbose "Pattern does not match." 2 |
| 70 |
return 1 |
| 71 |
} |
| 72 |
|
| 73 |
# |
| 74 |
# Run the utility |
| 75 |
# |
| 76 |
# Return the output or an empty string. |
| 77 |
# |
| 78 |
|
| 79 |
proc util_start { args } { |
| 80 |
global verbose |
| 81 |
set cmd [lindex $args 0] |
| 82 |
set cmd_arg [lindex $args 1] |
| 83 |
set file [lindex $args 2] |
| 84 |
|
| 85 |
if {[which $cmd] == 0} { |
| 86 |
perror "Can't find $cmd" |
| 87 |
return "" |
| 88 |
} |
| 89 |
|
| 90 |
if { $verbose > 0 } { |
| 91 |
verbose "Spawning \"$cmd $cmd_arg $file\"" |
| 92 |
} else { |
| 93 |
send_log "Spawning \"$cmd $cmd_arg $file\"\n" |
| 94 |
} |
| 95 |
catch "exec $cmd $cmd_arg $file" comp_output |
| 96 |
if {$comp_output ne ""} { |
| 97 |
send_log "$comp_output\n" |
| 98 |
} |
| 99 |
return $comp_output |
| 100 |
} |