diff options
author | Richard Sandiford <rdsandiford@googlemail.com> | 2010-11-20 15:36:34 +0000 |
---|---|---|
committer | Richard Sandiford <rdsandiford@googlemail.com> | 2010-11-20 15:36:34 +0000 |
commit | eb22018c4c91268d4a6a11dc636493082ca33049 (patch) | |
tree | ec129abe37420ae293af6694fecea4fea14574d5 /binutils | |
parent | f3097f3364542da446c96759eb04abb0d0507bc2 (diff) | |
download | gdb-eb22018c4c91268d4a6a11dc636493082ca33049.zip gdb-eb22018c4c91268d4a6a11dc636493082ca33049.tar.gz gdb-eb22018c4c91268d4a6a11dc636493082ca33049.tar.bz2 |
binutils/testsuite/
* lib/binutils-common.exp (regexp_diff): New procedure.
* lib/utils-lib.exp (regexp_diff): Delete.
gas/testsuite/
* lib/gas-defs.exp (regexp_diff): Delete.
(run_dump_test): Remove final "" argument in call to regexp_diff.
(run_list_test): Likewise.
(run_list_test_stdin): Likewise.
* gas/all/gas.exp (test_cond): Likewise.
* gas/elf/elf.exp (run_elf_list_test): Likewise.
* gas/m68k/all.exp: Likewise.
* gas/mep/complex-relocs.exp (regexp_test): Likewise.
* gas/mt/relocs.exp (regexp_test): Likewise.
* gas/symver/symver.exp (run_error_test): Likewise.
ld/testsuite/
* lib/ld-lib.exp (regexp_diff, simple_diff): Delete.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | binutils/testsuite/lib/binutils-common.exp | 154 | ||||
-rw-r--r-- | binutils/testsuite/lib/utils-lib.exp | 108 |
3 files changed, 161 insertions, 106 deletions
diff --git a/binutils/testsuite/ChangeLog b/binutils/testsuite/ChangeLog index 0c29b9c..e044acc 100644 --- a/binutils/testsuite/ChangeLog +++ b/binutils/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2010-11-20 Richard Sandiford <rdsandiford@googlemail.com> + * lib/binutils-common.exp (regexp_diff): New procedure. + * lib/utils-lib.exp (regexp_diff): Delete. + +2010-11-20 Richard Sandiford <rdsandiford@googlemail.com> + * lib/binutils-common.exp: New file. * lib/utils-lib.exp (load_common_lib): New function. Load binutils-common.exp. diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp index 96b1955..2f8b426 100644 --- a/binutils/testsuite/lib/binutils-common.exp +++ b/binutils/testsuite/lib/binutils-common.exp @@ -149,3 +149,157 @@ proc is_elf64 { binary_file } { return 0 } + +# Compare two files line-by-line. FILE_1 is the actual output and FILE_2 +# is the expected output. Ignore blank lines in either file. +# +# FILE_2 is a series of regexps, comments and # directives. The directives +# are: +# +# #pass +# Treat the test as a PASS if everything up till this point has +# matched. Ignore any remaining lines in either FILE_1 or FILE_2. +# +# #failif +# Reverse the sense of the test: expect differences to exist. +# +# #... +# REGEXP +# Skip all lines in FILE_1 until the first that matches REGEXP. +# +# Other # lines are comments. Skip empty lines in both files. +# +# The first optional argument is a list of regexp substitutions of the form: +# +# EXP1 SUBSPEC1 EXP2 SUBSPEC2 ... +# +# This tells the function to apply each regexp substitution EXPi->SUBSPECi +# in order to every line of FILE_2. +# +# Return nonzero if differences exist. +proc regexp_diff { file_1 file_2 args } { + set eof -1 + set end_1 0 + set end_2 0 + set differences 0 + set diff_pass 0 + set fail_if_match 0 + set ref_subst "" + if { [llength $args] > 0 } { + set ref_subst [lindex $args 0] + } + if { [llength $args] > 1 } { + perror "Too many arguments to regexp_diff" + return 1 + } + + if [file exists $file_1] then { + set file_a [open $file_1 r] + } else { + perror "$file_1 doesn't exist" + return 1 + } + + if [file exists $file_2] then { + set file_b [open $file_2 r] + } else { + perror "$file_2 doesn't exist" + close $file_a + return 1 + } + + verbose " Regexp-diff'ing: $file_1 $file_2" 2 + + while { 1 } { + set line_a "" + set line_b "" + while { [string length $line_a] == 0 } { + # Ignore blank line in FILE_1. + if { [gets $file_a line_a] == $eof } { + set end_1 1 + break + } + } + while { [string length $line_b] == 0 || [string match "#*" $line_b] } { + if { [string match "#pass" $line_b] } { + set end_2 1 + set diff_pass 1 + break + } elseif { [string match "#failif" $line_b] } { + send_log "fail if no difference\n" + verbose "fail if no difference" 3 + set fail_if_match 1 + } elseif { [string match "#..." $line_b] } { + if { [gets $file_b line_b] == $eof } { + set end_2 1 + set diff_pass 1 + break + } + # Substitute on the reference. + foreach {name value} $ref_subst { + regsub -- $name $line_b $value line_b + } + verbose "looking for \"^$line_b$\"" 3 + while { ![regexp "^$line_b$" "$line_a"] } { + verbose "skipping \"$line_a\"" 3 + if { [gets $file_a line_a] == $eof } { + set end_1 1 + break + } + } + break + } + if { [gets $file_b line_b] == $eof } { + set end_2 1 + break + } + } + + if { $diff_pass } { + break + } elseif { $end_1 && $end_2 } { + break + } elseif { $end_1 } { + send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n" + verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3 + set differences 1 + break + } elseif { $end_2 } { + send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" + verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3 + set differences 1 + break + } else { + # Substitute on the reference. + foreach {name value} $ref_subst { + regsub -- $name $line_b $value line_b + } + verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3 + if { ![regexp "^$line_b$" "$line_a"] } { + send_log "regexp_diff match failure\n" + send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n" + verbose "regexp_diff match failure\n" 3 + set differences 1 + } + } + } + + if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } { + send_log "$file_1 and $file_2 are different lengths\n" + verbose "$file_1 and $file_2 are different lengths" 3 + set differences 1 + } + + if { $fail_if_match } { + if { $differences == 0 } { + set differences 1 + } else { + set differences 0 + } + } + + close $file_a + close $file_b + + return $differences +} diff --git a/binutils/testsuite/lib/utils-lib.exp b/binutils/testsuite/lib/utils-lib.exp index 6dbbecf..72e368c 100644 --- a/binutils/testsuite/lib/utils-lib.exp +++ b/binutils/testsuite/lib/utils-lib.exp @@ -242,8 +242,8 @@ proc exe_ext {} { # # After the option lines come regexp lines. `run_dump_test' calls # `regexp_diff' to compare the output of the dumping tool against the -# regexps in FILE.d. `regexp_diff' is defined later in this file; see -# further comments there. +# regexps in FILE.d. `regexp_diff' is defined in binutils-common.exp; +# see further comments there. proc run_dump_test { name {extra_options {}} } { global subdir srcdir @@ -538,110 +538,6 @@ proc slurp_options { file } { return $opt_array } -# regexp_diff, based on simple_diff taken from ld test suite -# compares two files line-by-line -# file1 contains strings, file2 contains regexps and #-comments -# blank lines are ignored in either file -# returns non-zero if differences exist -# -proc regexp_diff { file_1 file_2 } { - - set eof -1 - set end_1 0 - set end_2 0 - set differences 0 - set diff_pass 0 - - if [file exists $file_1] then { - set file_a [open $file_1 r] - } else { - perror "$file_1 doesn't exist" - return 1 - } - - if [file exists $file_2] then { - set file_b [open $file_2 r] - } else { - perror "$file_2 doesn't exist" - close $file_a - return 1 - } - - verbose " Regexp-diff'ing: $file_1 $file_2" 2 - - while { 1 } { - set line_a "" - set line_b "" - while { [string length $line_a] == 0 } { - if { [gets $file_a line_a] == $eof } { - set end_1 1 - break - } - } - while { [string length $line_b] == 0 || [string match "#*" $line_b] } { - if [ string match "#pass" $line_b ] { - set end_2 1 - set diff_pass 1 - break - } elseif [ string match "#..." $line_b ] { - if { [gets $file_b line_b] == $eof } { - set end_2 1 - set diff_pass 1 - break - } - verbose "looking for \"^$line_b$\"" 3 - while { ![regexp "^$line_b$" "$line_a"] } { - verbose "skipping \"$line_a\"" 3 - if { [gets $file_a line_a] == $eof } { - set end_1 1 - break - } - } - break - } - if { [gets $file_b line_b] == $eof } { - set end_2 1 - break - } - } - - if { $diff_pass } { - break - } elseif { $end_1 && $end_2 } { - break - } elseif { $end_1 } { - send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n" - verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3 - set differences 1 - break - } elseif { $end_2 } { - send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" - verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3 - set differences 1 - break - } else { - verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3 - if ![regexp "^$line_b$" "$line_a"] { - send_log "regexp_diff match failure\n" - send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n" - verbose "regexp_diff match failure\n" 3 - set differences 1 - } - } - } - - if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } { - send_log "$file_1 and $file_2 are different lengths\n" - verbose "$file_1 and $file_2 are different lengths" 3 - set differences 1 - } - - close $file_a - close $file_b - - return $differences -} - proc file_contents { filename } { set file [open $filename r] set contents [read $file] |