From 5b62babd99d5de10c9ef0d1c97dfe5998dba514a Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Tue, 7 Sep 2021 09:14:35 +0300 Subject: Fix testing with DejaGNU 1.6.3 DejaGNU starting from version 1.6.3 looks for the testsuite in the directory testsuite. See https://puszcza.gnu.org.ua/bugs/index.php?519 * configure.ac: Register tests/gdbmtool/Makefile * tests/Makefile.am: Move dejagnu tests to the gdbmtool subdir. * tests/gdbmtool/Makefile.am: New file. * tests/config/default.exp: Move to tests/gdbmtool/config/default.exp * tests/gdbmtool/base.exp: Move to tests/gdbmtool/testsuite/gdbmtool/base.exp --- configure.ac | 1 + tests/Makefile.am | 34 +---- tests/config/default.exp | 221 ----------------------------- tests/gdbmtool/Makefile.am | 33 +++++ tests/gdbmtool/base.exp | 9 -- tests/gdbmtool/config/default.exp | 221 +++++++++++++++++++++++++++++ tests/gdbmtool/testsuite/gdbmtool/base.exp | 9 ++ 7 files changed, 265 insertions(+), 263 deletions(-) delete mode 100644 tests/config/default.exp create mode 100644 tests/gdbmtool/Makefile.am delete mode 100644 tests/gdbmtool/base.exp create mode 100644 tests/gdbmtool/config/default.exp create mode 100644 tests/gdbmtool/testsuite/gdbmtool/base.exp diff --git a/configure.ac b/configure.ac index 2c22ace..4a2733f 100644 --- a/configure.ac +++ b/configure.ac @@ -220,6 +220,7 @@ AM_CONDITIONAL([COND_GDBMTOOL_DEBUG], [test "$want_gdbmtool_debug" = yes]) # Initialize the test suite. AC_CONFIG_TESTDIR(tests) AC_CONFIG_FILES([tests/Makefile tests/atlocal po/Makefile.in]) +AC_CONFIG_FILES([tests/gdbmtool/Makefile]) AM_MISSING_PROG([AUTOM4TE], [autom4te]) AC_CONFIG_COMMANDS([status],[ diff --git a/tests/Makefile.am b/tests/Makefile.am index 1caa76e..337cbed 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -137,37 +137,5 @@ dtfetch_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la dtdel_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la d_creat_ce_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la -## -------------------- ## -## DejaGNU Test suite. ## -## -------------------- ## -AUTOMAKE_OPTIONS = dejagnu -DEJATOOL = gdbmtool -RUNTESTFLAGS = -CLEANFILES = *.log - -site.exp: Makefile - @echo 'Making a new site.exp file...' - @test ! -f site.bak || rm -f site.bak - @echo '## these variables are automatically generated by make ##' > $@-t - @echo '# Do not edit here. If you wish to override these values' >> $@-t - @echo '# edit the last section' >> $@-t - @echo 'set tool $(DEJATOOL)' >> $@-t - @echo "set top_srcdir `cd $(top_srcdir); pwd`" >> $@-t - @echo "set top_builddir `cd $(top_builddir); pwd`" >> $@-t - @echo "set srcdir `cd $(srcdir); pwd`" >> $@-t - @echo 'set objdir' `pwd` >> $@-t - @echo 'set host_alias "$(host_alias)"' >> $@-t - @echo 'set host_triplet $(host_triplet)' >> $@-t - @echo 'set target_alias "$(target_alias)"' >> $@-t - @echo 'set target_triplet $(target_triplet)' >> $@-t - @echo 'set build_alias "$(build_alias)"' >> $@-t - @echo 'set build_triplet $(build_triplet)' >> $@-t - @echo '## All variables above are generated by configure. Do Not Edit ##' >> $@-t - @test ! -f site.exp || sed '1,/^## All variables above are.*##/ d' site.exp >> $@-t - @test ! -f site.exp || mv site.exp site.bak - @mv $@-t site.exp - -EXTRA_DIST += \ - gdbmtool/base.exp\ - config/default.exp +SUBDIRS = gdbmtool diff --git a/tests/config/default.exp b/tests/config/default.exp deleted file mode 100644 index 7802ea6..0000000 --- a/tests/config/default.exp +++ /dev/null @@ -1,221 +0,0 @@ -verbose "STARTED" 1 - -# Make sure we use POSIX locale -set env(LC_ALL) "C" - -set gdbmtool_prompt "gdbmtool> " - -proc gdbmtool_start {args} { - global gdbmtool_spawn_id - global top_builddir - global gdbmtool_prompt - - set cmd "$top_builddir/src/gdbmtool -q $args" - verbose "running $cmd" 1 - - set gdbmtool_spawn_id [remote_spawn host $cmd] - if { $gdbmtool_spawn_id < 0 || $gdbmtool_spawn_id == "" } { - perror "Spawning $cmd failed." - return 1; - } - - remote_expect host 60 { - -re "\[\r\n\]?${gdbmtool_prompt}$" { - verbose "gdbmtool initialized." - } - default { - perror "gdbmtool not initialized" - return 1 - } - } - return 0 -} - -proc gdbmtool_stop {} { - verbose "Stopping gdbmtool" - gdbmtool_command "quit" - remote_close host -} - -proc gdbmtool_send {string} { - return [remote_send host "$string"] -} - -proc gdbmtool_command {cmd} { - set res [gdbmtool_send "$cmd\n"] - remote_expect host 60 { - -ex "\r\n" { } - default { - perror "gdbmtool_command for target failed"; - return -1 - } - } - verbose "RESULT: $res" 2 - return $res -} - -proc gdbmtool_test { command expcode } { - gdbmtool_command $command - uplevel remote_expect host 60 $expcode -# set code [catch \ -# {uplevel remote_expect host 60 $expcode} string]; -} - -# mu_test COMMAND PATTERN -# COMMAND - Command to send to the program -# PATTERN - A list of strings to expect in return -# Return value: -# -3 - eof -# -2 - timeout -# -1 - generic failure -# 1 - test fails -# 0 - test succeeds -proc seq_test { args } { - set command [lindex $args 0] - set pattern [lindex $args 1] - - set result -1 - if { "${command}" != "" } { - set res [gdbmtool_command "${command}"] - if { $res != "" } { - return $result; - } - } - - global timeout; - if [info exists timeout] { - set tmt $timeout; - } else { - set tmt 60; - } - - set result 0 - for {set i 0} {$result == 0 && $i < [llength $pattern]} {incr i} { - set regexp 0 - switch -regexp -- "[lindex ${pattern} $i]" { - ^-re.*$ { set regexp 1; incr i } - ^-- { incr i } - } - - regsub "\[ \t\]*$" [lindex ${pattern} $i] "" pat - verbose "i=$i, pat=$pat" 2 - - if {$regexp} { - verbose "REGEX for $pat / [llength $pat] " 3 - remote_expect host $tmt { - -re "$pat\[ \r\t\]*\r\n" { } - default { - set result 1 - break - } - timeout { - set result -2 - break - } - eof { - set result -3 - break - } - } - } else { - remote_expect host $tmt { - -ex "$pat" { - # go on - } - default { - set result 1 - break - } - timeout { - set result -2 - break - } - eof { - set result -3 - break - } - } - - if {$result == 0} { - remote_expect host $tmt { - -re "\[ \t]*\r\n" { } - default { set result 1 } - timeout { set result -2 } - eof { set result -3 } - } - } - } - } - return $result -} - -# mail_test [-message MESSAGE][-default (FAIL|XFAIL)][-noprompt] -# COMMAND PATTERN [PATTERN...] -# COMMAND - Command to send to mail. -# PATTERN - Sequence to expect in return. -# MESSAGE - [optional] message to output -proc gdbmtool_test { args } { - global gdbmtool_prompt - global suppress_flag; - upvar timeout timeout - - set default "" - set message "" - set wait_for_prompt 1 - for {set i 0} {$i < [llength $args]} {incr i} { - set a [lindex $args $i] - if {"$a" == "-default"} { - set default [lindex $args [expr $i + 1]] - incr i - } elseif {"$a" == "-message"} { - set message [lindex $args [expr $i + 1]] - incr i - } elseif {"$a" == "-noprompt"} { - set wait_for_prompt 0 - } else { - set args [lrange $args $i end] - break - } - } - - if {"$message" == ""} { - set message [lindex $args 0] - } - - verbose "Message is \"$message\"" 2 - - set command [lindex $args 0] - set pattern [lrange $args 1 end] - - set result [seq_test $command $pattern] - if {$wait_for_prompt} { - remote_expect host 30 { - -re "\[\r\n\]?${gdbmtool_prompt}$" {} - default { - perror "gdbmtool not initialized" - return 1 - } - } - } - - if {$result == 0} { - pass "$message" - } elseif {$result == 1} { - if { "$default" == "" || "$default" != "FAIL" } { - fail "$message" - } else { - xfail "$message" - set result 0 - } - } elseif {$result == -2} { - fail "$message (timeout)" - } elseif {$result == -3} { - fail "$message (eof)" - } else { - fail "$message" - } - return $result -} - - - diff --git a/tests/gdbmtool/Makefile.am b/tests/gdbmtool/Makefile.am new file mode 100644 index 0000000..6775f7f --- /dev/null +++ b/tests/gdbmtool/Makefile.am @@ -0,0 +1,33 @@ +## -------------------- ## +## DejaGNU Test suite. ## +## -------------------- ## +AUTOMAKE_OPTIONS = dejagnu +DEJATOOL = gdbmtool +RUNTESTFLAGS = +CLEANFILES = *.log + +site.exp: Makefile + @echo 'Making a new site.exp file...' + @test ! -f site.bak || rm -f site.bak + @echo '## these variables are automatically generated by make ##' > $@-t + @echo '# Do not edit here. If you wish to override these values' >> $@-t + @echo '# edit the last section' >> $@-t + @echo 'set tool $(DEJATOOL)' >> $@-t + @echo "set top_srcdir `cd $(top_srcdir); pwd`" >> $@-t + @echo "set top_builddir `cd $(top_builddir); pwd`" >> $@-t + @echo "set srcdir `cd $(srcdir); pwd`" >> $@-t + @echo 'set objdir' `pwd` >> $@-t + @echo 'set host_alias "$(host_alias)"' >> $@-t + @echo 'set host_triplet $(host_triplet)' >> $@-t + @echo 'set target_alias "$(target_alias)"' >> $@-t + @echo 'set target_triplet $(target_triplet)' >> $@-t + @echo 'set build_alias "$(build_alias)"' >> $@-t + @echo 'set build_triplet $(build_triplet)' >> $@-t + @echo '## All variables above are generated by configure. Do Not Edit ##' >> $@-t + @test ! -f site.exp || sed '1,/^## All variables above are.*##/ d' site.exp >> $@-t + @test ! -f site.exp || mv site.exp site.bak + @mv $@-t site.exp + +EXTRA_DIST = \ + testsuite/gdbmtool/base.exp\ + config/default.exp diff --git a/tests/gdbmtool/base.exp b/tests/gdbmtool/base.exp deleted file mode 100644 index 84128d2..0000000 --- a/tests/gdbmtool/base.exp +++ /dev/null @@ -1,9 +0,0 @@ -gdbmtool_start -gdbmtool_test "status" \ - "Database file: junk.gdbm" \ - "Database is not open" \ - "define key string" \ - "define content string" -gdbmtool_test "version" \ - -re "^GDBM version .*" -gdbmtool_stop diff --git a/tests/gdbmtool/config/default.exp b/tests/gdbmtool/config/default.exp new file mode 100644 index 0000000..7802ea6 --- /dev/null +++ b/tests/gdbmtool/config/default.exp @@ -0,0 +1,221 @@ +verbose "STARTED" 1 + +# Make sure we use POSIX locale +set env(LC_ALL) "C" + +set gdbmtool_prompt "gdbmtool> " + +proc gdbmtool_start {args} { + global gdbmtool_spawn_id + global top_builddir + global gdbmtool_prompt + + set cmd "$top_builddir/src/gdbmtool -q $args" + verbose "running $cmd" 1 + + set gdbmtool_spawn_id [remote_spawn host $cmd] + if { $gdbmtool_spawn_id < 0 || $gdbmtool_spawn_id == "" } { + perror "Spawning $cmd failed." + return 1; + } + + remote_expect host 60 { + -re "\[\r\n\]?${gdbmtool_prompt}$" { + verbose "gdbmtool initialized." + } + default { + perror "gdbmtool not initialized" + return 1 + } + } + return 0 +} + +proc gdbmtool_stop {} { + verbose "Stopping gdbmtool" + gdbmtool_command "quit" + remote_close host +} + +proc gdbmtool_send {string} { + return [remote_send host "$string"] +} + +proc gdbmtool_command {cmd} { + set res [gdbmtool_send "$cmd\n"] + remote_expect host 60 { + -ex "\r\n" { } + default { + perror "gdbmtool_command for target failed"; + return -1 + } + } + verbose "RESULT: $res" 2 + return $res +} + +proc gdbmtool_test { command expcode } { + gdbmtool_command $command + uplevel remote_expect host 60 $expcode +# set code [catch \ +# {uplevel remote_expect host 60 $expcode} string]; +} + +# mu_test COMMAND PATTERN +# COMMAND - Command to send to the program +# PATTERN - A list of strings to expect in return +# Return value: +# -3 - eof +# -2 - timeout +# -1 - generic failure +# 1 - test fails +# 0 - test succeeds +proc seq_test { args } { + set command [lindex $args 0] + set pattern [lindex $args 1] + + set result -1 + if { "${command}" != "" } { + set res [gdbmtool_command "${command}"] + if { $res != "" } { + return $result; + } + } + + global timeout; + if [info exists timeout] { + set tmt $timeout; + } else { + set tmt 60; + } + + set result 0 + for {set i 0} {$result == 0 && $i < [llength $pattern]} {incr i} { + set regexp 0 + switch -regexp -- "[lindex ${pattern} $i]" { + ^-re.*$ { set regexp 1; incr i } + ^-- { incr i } + } + + regsub "\[ \t\]*$" [lindex ${pattern} $i] "" pat + verbose "i=$i, pat=$pat" 2 + + if {$regexp} { + verbose "REGEX for $pat / [llength $pat] " 3 + remote_expect host $tmt { + -re "$pat\[ \r\t\]*\r\n" { } + default { + set result 1 + break + } + timeout { + set result -2 + break + } + eof { + set result -3 + break + } + } + } else { + remote_expect host $tmt { + -ex "$pat" { + # go on + } + default { + set result 1 + break + } + timeout { + set result -2 + break + } + eof { + set result -3 + break + } + } + + if {$result == 0} { + remote_expect host $tmt { + -re "\[ \t]*\r\n" { } + default { set result 1 } + timeout { set result -2 } + eof { set result -3 } + } + } + } + } + return $result +} + +# mail_test [-message MESSAGE][-default (FAIL|XFAIL)][-noprompt] +# COMMAND PATTERN [PATTERN...] +# COMMAND - Command to send to mail. +# PATTERN - Sequence to expect in return. +# MESSAGE - [optional] message to output +proc gdbmtool_test { args } { + global gdbmtool_prompt + global suppress_flag; + upvar timeout timeout + + set default "" + set message "" + set wait_for_prompt 1 + for {set i 0} {$i < [llength $args]} {incr i} { + set a [lindex $args $i] + if {"$a" == "-default"} { + set default [lindex $args [expr $i + 1]] + incr i + } elseif {"$a" == "-message"} { + set message [lindex $args [expr $i + 1]] + incr i + } elseif {"$a" == "-noprompt"} { + set wait_for_prompt 0 + } else { + set args [lrange $args $i end] + break + } + } + + if {"$message" == ""} { + set message [lindex $args 0] + } + + verbose "Message is \"$message\"" 2 + + set command [lindex $args 0] + set pattern [lrange $args 1 end] + + set result [seq_test $command $pattern] + if {$wait_for_prompt} { + remote_expect host 30 { + -re "\[\r\n\]?${gdbmtool_prompt}$" {} + default { + perror "gdbmtool not initialized" + return 1 + } + } + } + + if {$result == 0} { + pass "$message" + } elseif {$result == 1} { + if { "$default" == "" || "$default" != "FAIL" } { + fail "$message" + } else { + xfail "$message" + set result 0 + } + } elseif {$result == -2} { + fail "$message (timeout)" + } elseif {$result == -3} { + fail "$message (eof)" + } else { + fail "$message" + } + return $result +} + + + diff --git a/tests/gdbmtool/testsuite/gdbmtool/base.exp b/tests/gdbmtool/testsuite/gdbmtool/base.exp new file mode 100644 index 0000000..84128d2 --- /dev/null +++ b/tests/gdbmtool/testsuite/gdbmtool/base.exp @@ -0,0 +1,9 @@ +gdbmtool_start +gdbmtool_test "status" \ + "Database file: junk.gdbm" \ + "Database is not open" \ + "define key string" \ + "define content string" +gdbmtool_test "version" \ + -re "^GDBM version .*" +gdbmtool_stop -- cgit v1.2.1