aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore3
-rw-r--r--tests/Makefile.am37
-rw-r--r--tests/config/default.exp221
-rw-r--r--tests/gdbmtool/base.exp9
-rw-r--r--tests/gdbmtool00.at37
-rw-r--r--tests/gdbmtool01.at37
-rw-r--r--tests/gdbmtool02.at31
-rw-r--r--tests/testsuite.at5
8 files changed, 377 insertions, 3 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index a339f8d..7aef06b 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -24,4 +24,5 @@ num2word
package.m4
testsuite
testsuite.dir
-testsuite.log
+*.log
+*.sum
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b85110d..409ce0b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -22,7 +22,6 @@ EXTRA_DIST = \
DISTCLEANFILES = atconfig
MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
-
## ------------ ##
## package.m4. ##
## ------------ ##
@@ -73,6 +72,9 @@ TESTSUITE_AT = \
delete00.at\
delete01.at\
delete02.at\
+ gdbmtool00.at\
+ gdbmtool01.at\
+ gdbmtool02.at\
fetch00.at\
fetch01.at\
setopt00.at\
@@ -135,4 +137,35 @@ 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
diff --git a/tests/config/default.exp b/tests/config/default.exp
new file mode 100644
index 0000000..7802ea6
--- /dev/null
+++ b/tests/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/base.exp b/tests/gdbmtool/base.exp
new file mode 100644
index 0000000..6a831ac
--- /dev/null
+++ b/tests/gdbmtool/base.exp
@@ -0,0 +1,9 @@
+gdbmtool_start
+gdbmtool_test "status" \
+ "No database name" \
+ "Database is not open" \
+ "define key string" \
+ "define content string"
+gdbmtool_test "version" \
+ -re "^GDBM version .*"
+gdbmtool_stop
diff --git a/tests/gdbmtool00.at b/tests/gdbmtool00.at
new file mode 100644
index 0000000..baec9a4
--- /dev/null
+++ b/tests/gdbmtool00.at
@@ -0,0 +1,37 @@
+# This file is part of GDBM. -*- autoconf -*-
+# Copyright (C) 2018 Free Software Foundation, Inc.
+#
+# GDBM is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GDBM is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
+
+AT_SETUP([Input from file])
+AT_KEYWORDS([gdbmtool])
+
+AT_CHECK([
+
+AT_DATA([input],[
+status
+version
+quit
+])
+
+gdbmtool -f input | sed 's/^GDBM version.*/GDBM version/'
+],
+[0],
+[No database name
+Database is not open
+define key string
+define content string
+GDBM version
+])
+AT_CLEANUP
diff --git a/tests/gdbmtool01.at b/tests/gdbmtool01.at
new file mode 100644
index 0000000..91203f6
--- /dev/null
+++ b/tests/gdbmtool01.at
@@ -0,0 +1,37 @@
+# This file is part of GDBM. -*- autoconf -*-
+# Copyright (C) 2018 Free Software Foundation, Inc.
+#
+# GDBM is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GDBM is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
+
+AT_SETUP([Input from stdin])
+AT_KEYWORDS([gdbmtool])
+
+AT_CHECK([
+
+AT_DATA([input],[
+status
+version
+quit
+])
+
+gdbmtool < input | sed 's/^GDBM version.*/GDBM version/'
+],
+[0],
+[No database name
+Database is not open
+define key string
+define content string
+GDBM version
+])
+AT_CLEANUP
diff --git a/tests/gdbmtool02.at b/tests/gdbmtool02.at
new file mode 100644
index 0000000..0c2d35f
--- /dev/null
+++ b/tests/gdbmtool02.at
@@ -0,0 +1,31 @@
+# This file is part of GDBM. -*- autoconf -*-
+# Copyright (C) 2018 Free Software Foundation, Inc.
+#
+# GDBM is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GDBM is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
+
+AT_SETUP([Input from command line])
+AT_KEYWORDS([gdbmtool])
+
+AT_CHECK([
+gtload t.db < /dev/null
+gdbmtool t.db status \; version | sed 's/^GDBM version.*/GDBM version/'
+],
+[0],
+[Database file: t.db
+Database is not open
+define key string
+define content string
+GDBM version
+])
+AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 9488245..176a2d6 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -86,4 +86,9 @@ m4_include([dump02.at])
m4_include([dump03.at])
m4_include([dump04.at])
+AT_BANNER([gdbmtool])
+m4_include([gdbmtool00.at])
+m4_include([gdbmtool01.at])
+m4_include([gdbmtool02.at])
+
# End of testsuite.at

Return to:

Send suggestions and report system problems to the System administrator.