Is DejaGNU's testsuite useful? I admit, a strange question to have to
ask about a testsuite for a test harness package, but the results have
been pretty horrid every time I've tried it. I've attached some
patches that I used in Debian to allow make check to pass. But in the
end I had to turn the testsuite off again; it doesn't work when run
without an attached TTY.
--
Daniel Jacobowitz
CodeSourcery
---
Makefile.am | 2 +-
Makefile.in | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
Index: dejagnu-1.4.4.cvs20060709/Makefile.am
===================================================================
--- dejagnu-1.4.4.cvs20060709.orig/Makefile.am 2007-04-21 21:37:51.000000000 -0400
+++ dejagnu-1.4.4.cvs20060709/Makefile.am 2007-04-21 21:38:20.000000000 -0400
@@ -192,7 +192,7 @@ TESTSUITE_FILES = \
testsuite/libdejagnu/tunit.exp
RUNTEST = ${top_srcdir}/runtest
-RUNTESTDEFAULTFLAGS = --srcdir $(srcdir)/testsuite
+RUNTESTDEFAULTFLAGS = --srcdir $(srcdir)/testsuite RUNTEST=$(RUNTEST)
AM_CXXFLAGS = -I$(top_srcdir) -g
check_PROGRAMS = unit
Index: dejagnu-1.4.4.cvs20060709/Makefile.in
===================================================================
--- dejagnu-1.4.4.cvs20060709.orig/Makefile.in 2007-04-21 21:37:51.000000000 -0400
+++ dejagnu-1.4.4.cvs20060709/Makefile.in 2007-04-21 21:38:12.000000000 -0400
@@ -393,7 +393,7 @@ TESTSUITE_FILES = \
testsuite/libdejagnu/tunit.exp
RUNTEST = ${top_srcdir}/runtest
-RUNTESTDEFAULTFLAGS = --srcdir $(srcdir)/testsuite
+RUNTESTDEFAULTFLAGS = --srcdir $(srcdir)/testsuite RUNTEST=$(RUNTEST)
AM_CXXFLAGS = -I$(top_srcdir) -g
unit_SOURCES = testsuite/libdejagnu/unit.cc
---
lib/dejagnu.exp | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
Index: dejagnu-1.4.4.cvs20060709/lib/dejagnu.exp
===================================================================
--- dejagnu-1.4.4.cvs20060709.orig/lib/dejagnu.exp 2007-04-01 18:06:32.000000000 -0400
+++ dejagnu-1.4.4.cvs20060709/lib/dejagnu.exp 2007-04-01 18:13:06.000000000 -0400
@@ -133,49 +133,50 @@ proc host_execute {args} {
# test case.
# spawn -noecho -open [open "|./${executable}" "r"]
spawn -noecho "./${executable}" ${params}
+ set prefix "\[^\r\n\]*"
expect {
- -re "\[0-9\]\[0-9\]:..:..:${text}\r\n" {
+ -re "^$prefix\[0-9\]\[0-9\]:..:..:${text}*\r\n" {
regsub "\[\n\r\t\]*NOTE: $text\r\n" $expect_out(0,string) "" output
verbose "$output" 3
set timetol 0
exp_continue
}
- -re "NOTE:${text}*" {
+ -re "^$prefix\tNOTE:${text}*" {
regsub "\[\n\r\t\]*NOTE: $text\r\n" $expect_out(0,string) "" output
set output [string range $output 6 end]
verbose "$output" 2
set timetol 0
exp_continue
}
- -re "PASSED:${text}*" {
+ -re "^$prefix\tPASSED:${text}*" {
regsub "\[\n\r\t\]*PASSED: $text\r\n" $expect_out(0,string) "" output
set output [string range $output 8 end]
pass "$output"
set timetol 0
exp_continue
}
- -re "FAILED:${text}*" {
+ -re "^$prefix\tFAILED:${text}*" {
regsub "\[\n\r\t\]*FAILED: $text\r\n" $expect_out(0,string) "" output
set output [string range $output 8 end]
fail "$output"
set timetol 0
exp_continue
}
- -re "UNTESTED:${text}*" {
+ -re "^$prefix\tUNTESTED:${text}*" {
regsub "\[\n\r\t\]*TESTED: $text\r\n" $expect_out(0,string) "" output
set output [string range $output 8 end]
untested "$output"
set timetol 0
exp_continue
}
- -re "UNRESOLVED:${text}*" {
+ -re "^$prefix\tUNRESOLVED:${text}*" {
regsub "\[\n\r\t\]*UNRESOLVED: $text\r\n" $expect_out(0,string) "" output
set output [string range $output 8 end]
unresolved "$output"
set timetol 0
exp_continue
}
- -re "Totals" {
+ -re "^Totals" {
verbose "All done" 2
}
eof {
@@ -193,6 +194,9 @@ proc host_execute {args} {
return "Timed out executing test case"
}
}
+ -re "^$prefix\r\n" {
+ exp_continue
+ }
}
# force a close of the executable to be safe.
---
testsuite/libdejagnu/unit.cc | 46 ++++++++++++++++++++++++++-----------------
1 file changed, 28 insertions(+), 18 deletions(-)
Index: dejagnu-1.4.4.cvs20060709/testsuite/libdejagnu/unit.cc
===================================================================
--- dejagnu-1.4.4.cvs20060709.orig/testsuite/libdejagnu/unit.cc 2007-04-01 18:13:35.000000000 -0400
+++ dejagnu-1.4.4.cvs20060709/testsuite/libdejagnu/unit.cc 2007-04-01 18:14:40.000000000 -0400
@@ -22,6 +22,7 @@
#include <regex.h>
#include <string>
#include <fstream>
+#include <sstream>
#include <set>
#include <dejagnu.h>
@@ -56,17 +57,14 @@ main (int argc, char *argv[])
{
regex_t regex_pat;
outstate = os1;
+ stringstream strbuf;
+ streambuf *pbuf;
// Replace the output buffer for cout, so we can examine it to see
// what was displayed. Otherwise, there is no way we can test the
// logging functions completely.
- char buf[5120];
-#ifdef __STDC_HOSTED__
- cout.rdbuf ()->pubsetbuf (buf, 5120);
-#else
- cout.rdbuf ()->setbuf (buf, 5120);
-#endif
-
+ pbuf = cout.rdbuf ();
+
testClass1.tname = "testType1";
testClass1.tnum = 1;
testClass2.tname = "testType2";
@@ -75,50 +73,63 @@ main (int argc, char *argv[])
testClass3.tnum = 3;
// Test the pass message.
+ cout.rdbuf (strbuf.rdbuf ());
+ strbuf.str("");
test.pass ("bogus pass message for testing");
outstate = os2;
- if (strncmp (buf, "\tPAS: bogus pass message", 22) == 0)
+ cout.rdbuf(pbuf);
+ if (strncmp (strbuf.str().c_str(), "\tPAS: bogus pass message", 22) == 0)
runtest.pass ("Pass message");
else
runtest.fail ("Pass message");
// Test the fail message.
+ cout.rdbuf (strbuf.rdbuf ());
+ strbuf.str("");
outstate = os1;
test.fail ("bogus fail message for testing");
- cout.flush ();
+ cout.rdbuf(pbuf);
outstate = os2;
- if (strncmp (buf, "\tFAI: bogus fail message", 22) == 0)
+ if (strncmp (strbuf.str().c_str(), "\tFAI: bogus fail message", 22) == 0)
runtest.pass ("Fail message");
else
runtest.fail ("Fail message");
// Test the untested message.
+ cout.rdbuf (strbuf.rdbuf ());
+ strbuf.str("");
outstate = os1;
test.untested ("bogus untested message for testing");
- cout.flush ();
+ cout.rdbuf(pbuf);
outstate = os2;
- if (strncmp (buf, "\tUNT: bogus untested message", 21) == 0) {
+ if (strncmp (strbuf.str().c_str(), "\tUNT: bogus untested message", 21) == 0) {
runtest.pass ("Untested message");
} else {
runtest.fail ("Untested message");
}
// Test the unresolved message.
+ cout.rdbuf (strbuf.rdbuf ());
+ strbuf.str("");
outstate = os1;
test.unresolved ("bogus unresolved message for testing");
- cout.flush ();
+ cout.rdbuf(pbuf);
outstate = os2;
- if (strncmp (buf, "\tUNR: bogus unresolved message", 21) == 0)
+ if (strncmp (strbuf.str().c_str(), "\tUNR: bogus unresolved message", 21) == 0)
runtest.pass ("Unresolved message");
else
runtest.fail ("Unresolved message");
// Make sure we got everything in the totals.
+ cout.rdbuf (strbuf.rdbuf ());
+ strbuf.str("");
regcomp (®ex_pat,
- "\r\n\t#passed.*#failed.*#untested.*#unresolved",
- REG_NOSUB | REG_NEWLINE);
+ "\t#passed.*#real failed.*#untested.*#unresolved",
+ REG_NOSUB);
- if (regexec (®ex_pat, buf, 0, (regmatch_t *) 0, 0))
+ test.totals ();
+ cout.rdbuf(pbuf);
+ if (regexec (®ex_pat, strbuf.str().c_str(), 0, (regmatch_t *) 0, 0) == 0)
runtest.pass ("Totals message");
else
runtest.fail ("Totals message");
@@ -126,4 +137,3 @@ main (int argc, char *argv[])
return 0;
}
-
_______________________________________________
DejaGnu mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/dejagnu