2016-03-28 Ben Elliston <bje@gnu.org>
+ * runtest.exp: Fixes identified by the Frink static analyser:
+ (1) use -- in switch commands for safety,
+ (2) remove unreachable return commands after error commands,
+ (3) replace abbreviated "info proc" with "info procs",
+ (4) use -- in unset commands for safety where the variable name
+ is itself a variable.
+ * lib/dg.exp: Likewise.
+ * lib/debugger.exp: Likewise.
+ * lib/framework.exp: Likewise.
+ * lib/remote.exp: Likewise.
+ * lib/target.exp: Likewise.
+ * lib/targetdb.exp: Likewise.
+ * lib/telnet.exp: Likewise.
+ * lib/utils.exp: Likewise.
+
+2016-03-28 Ben Elliston <bje@gnu.org>
+
* Makefile.am: Remove references to Docbook and friends.
* configure.ac: Likewise.
* Makefile.in: Regenerate.
#
proc watcharray { array element op } {
upvar [set array]($element) avar
- switch $op {
+ switch -- $op {
"w" { puts "New value of [set array]($element) is $avar" }
"r" { puts "[set array]($element) (= $avar) was just read" }
"u" { puts "[set array]($element) (= $avar) was just unset" }
proc watchvar { v ignored op } {
upvar $v var
- switch $op {
+ switch -- $op {
"w" { puts "New value of $v is $var" }
"r" { puts "$v (=$var) was just read" }
"u" { puts "$v (=$var) was just unset" }
# Tests for optional arguments are coded with ">=" to simplify adding new ones.
#
proc dg-prms-id { args } {
- global prms_id ;# this is a testing framework variable
+ global prms_id
if { [llength $args] > 2 } {
error "[lindex $args 0]: too many arguments"
- return
}
set prms_id [lindex $args 1]
if { [llength $args] > 3 } {
error "[lindex $args 0]: too many arguments"
- return
}
if { [llength $args] >= 3 } {
- switch [dg-process-target [lindex $args 2]] {
+ switch -- [dg-process-target [lindex $args 2]] {
"S" { set extra-tool-flags [lindex $args 1] }
"N" { }
"F" { error "[lindex $args 0]: `xfail' not allowed here" }
if { [llength $args] > 3 } {
error "[lindex $args 0]: too many arguments"
- return
}
set selected [lindex ${do-what} 1] ;# selected? (""/S/N)
set expected [lindex ${do-what} 2] ;# expected to pass/fail (P/F)
if { [llength $args] >= 3 } {
- switch [dg-process-target [lindex $args 2]] {
+ switch -- [dg-process-target [lindex $args 2]] {
"S" {
set selected "S"
}
set expected P
}
- switch [lindex $args 1] {
+ switch -- [lindex $args 1] {
"preprocess" { }
"compile" { }
"assemble" { }
if { [llength $args] > 5 } {
error "[lindex $args 0]: too many arguments"
- return
}
set xfail ""
if { [llength $args] >= 4 } {
- switch [dg-process-target [lindex $args 3]] {
+ switch -- [dg-process-target [lindex $args 3]] {
"F" { set xfail "X" }
"P" { set xfail "" }
"N" {
}
if { [llength $args] >= 5 } {
- switch [lindex $args 4] {
+ switch -- [lindex $args 4] {
"." { set line [dg-format-linenum [lindex $args 0]] }
"0" { set line "" }
"default" { set line [dg-format-linenum [lindex $args 4]] }
if { [llength $args] > 5 } {
error "[lindex $args 0]: too many arguments"
- return
}
set xfail ""
if { [llength $args] >= 4 } {
- switch [dg-process-target [lindex $args 3]] {
+ switch -- [dg-process-target [lindex $args 3]] {
"F" { set xfail "X" }
"P" { set xfail "" }
"N" {
}
if { [llength $args] >= 5 } {
- switch [lindex $args 4] {
+ switch -- [lindex $args 4] {
"." { set line [dg-format-linenum [lindex $args 0]] }
"0" { set line "" }
"default" { set line [dg-format-linenum [lindex $args 4]] }
if { [llength $args] > 5 } {
error "[lindex $args 0]: too many arguments"
- return
}
set xfail ""
if { [llength $args] >= 4 } {
- switch [dg-process-target [lindex $args 3]] {
+ switch -- [dg-process-target [lindex $args 3]] {
"F" { set xfail "X" }
"P" { set xfail "" }
"N" {
}
if { [llength $args] >= 5 } {
- switch [lindex $args 4] {
+ switch -- [lindex $args 4] {
"." { set line [dg-format-linenum [lindex $args 0]] }
"0" { set line "" }
"default" { set line [dg-format-linenum [lindex $args 4]] }
if { [llength $args] > 4 } {
error "[lindex $args 0]: too many arguments"
- return
}
set xfail ""
if { [ llength $args] >= 4 } {
- switch [dg-process-target [lindex $args 3]] {
+ switch -- [dg-process-target [lindex $args 3]] {
"F" { set xfail "X" }
"P" { set xfail "" }
"N" {
if { [llength $args] > 3 } {
error "[lindex $args 0]: too many arguments"
- return
}
if { [llength $args] >= 3 } {
- switch [dg-process-target [lindex $args 2]] {
+ switch -- [dg-process-target [lindex $args 2]] {
"F" { set excess-errors-flag 1 }
"S" { set excess-errors-flag 1 }
}
if { [llength $args] > 3 } {
error "[lindex $args 0]: too many arguments"
- return
}
# Allow target dependent output.
set expected [lindex ${output-text} 0]
if { [llength $args] >= 3 } {
- switch [dg-process-target [lindex $args 2]] {
+ switch -- [dg-process-target [lindex $args 2]] {
"N" { return }
"S" { }
"F" { set expected "F" }
if { [llength $args] > 2 } {
error "[lindex $args 0]: too many arguments"
- return
}
append final-code "[lindex $args 1]\n"
# $line will either be a formatted line number or a number all by
# itself. Delete the formatting.
scan $line ${dg-linenum-format} line
- switch [lindex $i 1] {
+ switch -- [lindex $i 1] {
"ERROR" {
$ok "$name $comment (test for errors, line $line)"
}
# Remove messages from the tool that we can ignore.
set comp_output [prune_warnings $comp_output]
- if { [info proc ${tool}-dg-prune] != "" } {
+ if { [info procs ${tool}-dg-prune] != "" } {
set comp_output [${tool}-dg-prune $target_triplet $comp_output]
- switch -glob $comp_output {
+ switch -glob -- $comp_output {
"::untested::*" {
regsub "::untested::" $comp_output "" message
untested "$name: $message"
setup_xfail "*-*-*"
}
set texttmp [lindex ${dg-output-text} 1]
- if { ![regexp $texttmp ${output}] } {
+ if { ![regexp -- $texttmp ${output}] } {
fail "$name output pattern test"
send_log "Output was:\n${output}\nShould match:\n$texttmp\n"
verbose "Failed test for output pattern $texttmp" 3
}
regsub "^\[ \t\]*(\[^ \t\]+).*$" "$message" "\\1" firstword
- switch -glob "$firstword" {
+ switch -glob -- "$firstword" {
"PASS:" -
"XFAIL:" -
"KFAIL:" -
set argc [ llength $args ]
for { set i 0 } { $i < $argc } { incr i } {
set sub_arg [ lindex $args $i ]
- switch -glob $sub_arg {
+ switch -glob -- $sub_arg {
"*-*-*" { # is a configuration triplet
if {[istarget $sub_arg]} {
set xfail_flag 0
set argc [ llength $args ]
for { set i 0 } { $i < $argc } { incr i } {
set sub_arg [ lindex $args $i ]
- switch -glob $sub_arg {
+ switch -glob -- $sub_arg {
"*-*-*" { # is a configuration triplet
if {[istarget $sub_arg]} {
set kfail_flag 0
xml_output " </test>"
}
- switch $type {
+ switch -- $type {
PASS {
if {$prms_id} {
set message [concat $message "\t(PRMS $prms_id)"]
if {[board_info $host exists name]} {
set host [board_info $host name]
}
- if { [info proc ${host}_init] != "" } {
+ if { [info procs ${host}_init] != "" } {
${host}_init $host
}
return $status
if { $proc == "close" || $proc == "open" } {
foreach try "$high_prot [board_info $dest connect] telnet standard" {
if { $try != "" } {
- if { [info proc "${try}_${proc}"] != "" } {
+ if { [info procs "${try}_${proc}"] != "" } {
verbose "call_remote calling ${try}_${proc}" 3
set result [eval ${try}_${proc} \"$dest\" $args]
break
}
}
set ft "[board_info $dest file_transfer]"
- if { [info proc "${ft}_${proc}"] != "" } {
+ if { [info procs "${ft}_${proc}"] != "" } {
verbose "calling ${ft}_${proc} $dest $args" 3
set result2 [eval ${ft}_${proc} \"$dest\" $args]
}
foreach try "${high_prot} [board_info $dest file_transfer] [board_info $dest connect] telnet standard" {
verbose "looking for ${try}_${proc}" 4
if { $try != "" } {
- if { [info proc "${try}_${proc}"] != "" } {
+ if { [info procs "${try}_${proc}"] != "" } {
verbose "call_remote calling ${try}_${proc}" 3
return [eval ${try}_${proc} \"$dest\" $args]
}
return ""
}
error "No procedure for '$proc' in call_remote"
- return -1
}
# Send FILE through the existing session established to DEST.
set file [lindex $args 0]
verbose "dest in proc standard_file is $dest" 3
if { ![is_remote $dest] } {
- switch $op {
+ switch -- $op {
cmp {
set otherfile [lindex $args 1]
if { [file exists $file] && [file exists $otherfile]
file delete -force -- $x
}
}
- return
+ return {}
}
}
} else {
- switch $op {
+ switch -- $op {
exists {
set status [remote_exec $dest "test -f $file"]
- return [expr [lindex $status 0] == 0]
+ return [expr {[lindex $status 0] == 0}]
}
delete {
set file ""
#
proc target_compile {source destfile type options} {
set target [target_info name]
- if { [info proc ${target}_compile] != "" } {
+ if { [info procs ${target}_compile] != "" } {
return [${target}_compile $source $destfile $type $options]
} else {
return [default_target_compile $source $destfile $type $options]
if { [llength $args] == 0 } {
return [info exists board_info($machine,name)]
} else {
- return [info exists "board_info($machine,[lindex $args 0])"]
+ return [info exists board_info($machine,[lindex $args 0])]
}
}
if { [llength $args] == 0 } {
set raw 0
foreach arg $args {
- switch $arg {
+ switch -- $arg {
"raw" { set raw 1 }
}
}
if {[regexp -- "$pattern" $cur_line match]} {
if {![string match "" $options]} {
foreach opt $options {
- switch $opt {
+ switch -- $opt {
"line" {
lappend grep_out [concat $i $match]
}
#
# Remove elements based on patterns. elements are delimited by spaces.
# pattern is the pattern to look for using glob style matching
-# list is the list to check against
+# lst is the list to check against
# returns the new list
#
-proc prune { list pattern } {
+proc prune { lst pattern } {
set tmp {}
- foreach i $list {
+ foreach i $lst {
verbose "Checking pattern \"$pattern\" against $i" 3
if {![string match $pattern $i]} {
lappend tmp $i
exit 1
}
catch "exec $config_guess" build_triplet
- switch $build_triplet {
+ switch -- $build_triplet {
"No uname command or uname output not recognized" -
"Unable to guess system type" {
verbose "WARNING: Uname output not recognized"
unset board
unset board_type
push_host $name
- if { [info proc ${name}_init] != "" } {
+ if { [info procs ${name}_init] != "" } {
${name}_init $name
}
}
unset board
unset board_type
push_build $name
- if { [info proc ${name}_init] != "" } {
+ if { [info procs ${name}_init] != "" } {
${name}_init $name
}
}
default {
if {[info exists tool]} {
- if { [info proc ${tool}_option_proc] != "" } {
+ if { [info procs ${tool}_option_proc] != "" } {
if {[${tool}_option_proc $option]} {
continue
}
set [lindex $varval 0] [lindex $varval 1]
} else {
verbose "Restoring [lindex $varval 0] to `unset'" 4
- unset [lindex $varval 0]
+ unset -- [lindex $varval 0]
}
}
}