aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Bachmeyer <jcb@gnu.org>2022-11-26 23:23:55 -0600
committerJacob Bachmeyer <jcb@gnu.org>2022-11-26 23:23:55 -0600
commite8446c3ff0dafab7bf3615712dbe1cd621f09f5b (patch)
tree91c8c9470af132ca08b6d9453e5c91fc83de5500
parentc173c009bd41b821e9fad4938d69d2204de69e55 (diff)
Add tests for C unit test library
-rw-r--r--ChangeLog9
-rw-r--r--Makefile.am9
-rw-r--r--Makefile.in55
-rw-r--r--testsuite/libdejagnu/unit-c.c60
-rw-r--r--testsuite/libdejagnu/unit.exp127
5 files changed, 251 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 2bc6eb7..172ba6f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2022-11-26 Jacob Bachmeyer <jcb@gnu.org>
+ * Makefile.in: Regenerate.
+ * Makefile.am (AM_CXXFLAGS): Change this...
+ (AM_CPPFLAGS): ...to this. (Also remove -g flag.)
+ (check_PROGRAMS): Add testsuite/libdejagnu/unit-c.
+ (testsuite_libdejagnu_unit_c_SOURCES): Add.
+ (TESTSUITE_FILES): Update.
+ * testsuite/libdejagnu/unit-c.c: New file.
+ * testsuite/libdejagnu/unit.exp: New file.
+
* dejagnu.h (xpass): Fix use of wrong counter.
(xfail): Likewise.
(totals): Report unexpected passes if any occurred.
diff --git a/Makefile.am b/Makefile.am
index a10f836..4ca6097 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-# Copyright (C) 1992-2019, 2020 Free Software Foundation, Inc.
+# Copyright (C) 1992-2019, 2020, 2022 Free Software Foundation, Inc.
#
# This file is part of DejaGnu.
#
@@ -220,6 +220,7 @@ TESTSUITE_FILES = \
testsuite/lib/report-card.exp \
testsuite/lib/runtest.exp \
testsuite/lib/util-defs.exp \
+ testsuite/libdejagnu/unit.exp \
testsuite/libdejagnu/tunit.exp
DEJATOOL = launcher libdejagnu report-card runtest
@@ -228,9 +229,11 @@ DEJATOOL = launcher libdejagnu report-card runtest
# of DejaGnu instead of an installed version.
RUNTEST = ${top_srcdir}/runtest
-AM_CXXFLAGS = -I$(top_srcdir) -g
-check_PROGRAMS = unit
+AM_CPPFLAGS = -I$(top_srcdir)
+check_PROGRAMS = unit \
+ testsuite/libdejagnu/unit-c
unit_SOURCES = testsuite/libdejagnu/unit.cc
+testsuite_libdejagnu_unit_c_SOURCES = testsuite/libdejagnu/unit-c.c
# Documentation.
diff --git a/Makefile.in b/Makefile.in
index a20e6c2..efd8195 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -14,7 +14,7 @@
@SET_MAKE@
-# Copyright (C) 1992-2019, 2020 Free Software Foundation, Inc.
+# Copyright (C) 1992-2019, 2020, 2022 Free Software Foundation, Inc.
#
# This file is part of DejaGnu.
#
@@ -108,7 +108,7 @@ POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
-check_PROGRAMS = unit$(EXEEXT)
+check_PROGRAMS = unit$(EXEEXT) testsuite/libdejagnu/unit-c$(EXEEXT)
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
@@ -123,6 +123,11 @@ mkinstalldirs = $(install_sh) -d
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
am__dirstamp = $(am__leading_dot)dirstamp
+am_testsuite_libdejagnu_unit_c_OBJECTS = \
+ testsuite/libdejagnu/unit-c.$(OBJEXT)
+testsuite_libdejagnu_unit_c_OBJECTS = \
+ $(am_testsuite_libdejagnu_unit_c_OBJECTS)
+testsuite_libdejagnu_unit_c_LDADD = $(LDADD)
am_unit_OBJECTS = testsuite/libdejagnu/unit.$(OBJEXT)
unit_OBJECTS = $(am_unit_OBJECTS)
unit_LDADD = $(LDADD)
@@ -175,6 +180,18 @@ DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
AM_V_CXX = $(am__v_CXX_@AM_V@)
@@ -188,8 +205,8 @@ AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
am__v_CXXLD_0 = @echo " CXXLD " $@;
am__v_CXXLD_1 =
-SOURCES = $(unit_SOURCES)
-DIST_SOURCES = $(unit_SOURCES)
+SOURCES = $(testsuite_libdejagnu_unit_c_SOURCES) $(unit_SOURCES)
+DIST_SOURCES = $(testsuite_libdejagnu_unit_c_SOURCES) $(unit_SOURCES)
AM_V_DVIPS = $(am__v_DVIPS_@AM_V@)
am__v_DVIPS_ = $(am__v_DVIPS_@AM_DEFAULT_V@)
am__v_DVIPS_0 = @echo " DVIPS " $@;
@@ -560,6 +577,7 @@ TESTSUITE_FILES = \
testsuite/lib/report-card.exp \
testsuite/lib/runtest.exp \
testsuite/lib/util-defs.exp \
+ testsuite/libdejagnu/unit.exp \
testsuite/libdejagnu/tunit.exp
DEJATOOL = launcher libdejagnu report-card runtest
@@ -567,8 +585,9 @@ DEJATOOL = launcher libdejagnu report-card runtest
# We override runtest so that the testsuite is run with this version
# of DejaGnu instead of an installed version.
RUNTEST = ${top_srcdir}/runtest
-AM_CXXFLAGS = -I$(top_srcdir) -g
+AM_CPPFLAGS = -I$(top_srcdir)
unit_SOURCES = testsuite/libdejagnu/unit.cc
+testsuite_libdejagnu_unit_c_SOURCES = testsuite/libdejagnu/unit-c.c
# Documentation.
TEXINFO_TEX = doc/texinfo.tex
@@ -582,7 +601,7 @@ doc_dejagnu_TEXINFOS = doc/fdl.texi
all: all-am
.SUFFIXES:
-.SUFFIXES: .cc .dvi .o .obj .ps
+.SUFFIXES: .c .cc .dvi .o .obj .ps
am--refresh: Makefile
@:
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
@@ -625,6 +644,13 @@ testsuite/libdejagnu/$(am__dirstamp):
testsuite/libdejagnu/$(DEPDIR)/$(am__dirstamp):
@$(MKDIR_P) testsuite/libdejagnu/$(DEPDIR)
@: > testsuite/libdejagnu/$(DEPDIR)/$(am__dirstamp)
+testsuite/libdejagnu/unit-c.$(OBJEXT): \
+ testsuite/libdejagnu/$(am__dirstamp) \
+ testsuite/libdejagnu/$(DEPDIR)/$(am__dirstamp)
+
+testsuite/libdejagnu/unit-c$(EXEEXT): $(testsuite_libdejagnu_unit_c_OBJECTS) $(testsuite_libdejagnu_unit_c_DEPENDENCIES) $(EXTRA_testsuite_libdejagnu_unit_c_DEPENDENCIES) testsuite/libdejagnu/$(am__dirstamp)
+ @rm -f testsuite/libdejagnu/unit-c$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(testsuite_libdejagnu_unit_c_OBJECTS) $(testsuite_libdejagnu_unit_c_LDADD) $(LIBS)
testsuite/libdejagnu/unit.$(OBJEXT): \
testsuite/libdejagnu/$(am__dirstamp) \
testsuite/libdejagnu/$(DEPDIR)/$(am__dirstamp)
@@ -710,8 +736,25 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@testsuite/libdejagnu/$(DEPDIR)/unit-c.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@testsuite/libdejagnu/$(DEPDIR)/unit.Po@am__quote@
+.c.o:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
.cc.o:
@am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
diff --git a/testsuite/libdejagnu/unit-c.c b/testsuite/libdejagnu/unit-c.c
new file mode 100644
index 0000000..aeccbd5
--- /dev/null
+++ b/testsuite/libdejagnu/unit-c.c
@@ -0,0 +1,60 @@
+/* Exerciser for DejaGnu C unit test support library
+ *
+ * Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ * This file is part of DejaGnu.
+ *
+ * DejaGnu 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DejaGnu 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 DejaGnu; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * This file was written by Jacob Bachmeyer.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "dejagnu.h"
+
+int
+main(int argc, char ** argv)
+{
+ int i;
+
+ if (argc < 2) {
+ fprintf(stderr,
+ "usage: %s <test name>...\n see source for details\n", argv[0]);
+ return 2;
+ }
+
+ for (i = 1; i < argc; i++) {
+ if (!strcmp("pass", argv[i])) pass("test");
+ else if (!strcmp("xpass", argv[i])) xpass("test");
+ else if (!strcmp("fail", argv[i])) fail("test");
+ else if (!strcmp("xfail", argv[i])) xfail("test");
+ else if (!strcmp("untested", argv[i])) untested("test");
+ else if (!strcmp("unresolved", argv[i])) unresolved("test");
+ else if (!strcmp("note", argv[i])) note("test");
+ else {
+ fprintf(stderr, "%s: unknown test `%s'\n", argv[0], argv[i]);
+ return 2;
+ }
+ }
+
+ totals();
+
+ return 0;
+}
+
+/* EOF */
diff --git a/testsuite/libdejagnu/unit.exp b/testsuite/libdejagnu/unit.exp
new file mode 100644
index 0000000..d572f47
--- /dev/null
+++ b/testsuite/libdejagnu/unit.exp
@@ -0,0 +1,127 @@
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of DejaGnu.
+#
+# DejaGnu 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 3 of the License, or
+# (at your option) any later version.
+#
+# DejaGnu 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 DejaGnu; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+
+# This file is a test driver for the unit test protocol library.
+
+# Each test program must accept test outcomes on the command line, and
+# produce exactly those results in that order.
+
+proc test_libdejagnu_unit { language tests } {
+ set test_program [testsuite file -object -test "unit-${language}"]
+
+ # map messages from dejagnu.h:totals() to result types
+ array set expected_totals_map {
+ passed pass "real failed" fail
+ "unexpected passes" xpass
+ "expected failures" xfail
+ untested untested
+ unresolved unresolved
+ }
+
+ foreach test $tests {
+ array set expected_totals {
+ pass 0 fail 0
+ xpass 0 xfail 0
+ untested 0 unresolved 0
+ }
+ set test_idx 0
+ set result pass
+
+ verbose -log "Spawning $test_program $test ..."
+ eval [list spawn $test_program] $test
+
+ expect_after {
+ -re {^[^\n]*\n} { exp_continue }
+ full_buffer {
+ perror "Expect matching buffer overrun during test."
+ }
+ eof {
+ # No end marker? -> Fail!
+ verbose -log " unit test did not emit an end marker"
+ set result fail
+ }
+ timeout {
+ catch close
+ set result unresolved
+ }
+ }
+
+ # Check that the reported results match.
+ expect {
+ -re {^[\r\n]*Totals:[\r\n]+} {
+ # done with results, but fail if there should be more
+ if { [lindex $test $test_idx] ne "" } {
+ verbose -log " expected [lindex $test $test_idx]"
+ set result fail
+ }
+ }
+ -re {(?:\A|\n)\t([][[:upper:]]+):([^\n]+)\n} {
+ # above pattern copied from lib/dejagnu.exp:host_execute
+ switch -- [lindex $test $test_idx] {
+ pass { set expected PASSED }
+ fail { set expected FAILED }
+ xpass { set expected XPASSED }
+ xfail { set expected XFAILED }
+ untested { set expected UNTESTED }
+ unresolved { set expected UNRESOLVED }
+ }
+ if { [info exists expected_totals([lindex $test $test_idx])]} {
+ incr expected_totals([lindex $test $test_idx])
+ }
+ if { $expected ne $expect_out(1,string) } {
+ set result fail
+ }
+ incr test_idx
+ exp_continue
+ }
+ }
+ # Now ensure that the reported totals are as expected.
+ expect {
+ -re {^\n*\t#([^:]+):\t+([[:digit:]]+)\r*\n} {
+ set type $expected_totals_map($expect_out(1,string))
+ set count $expect_out(2,string)
+
+ if { $expected_totals($type) != $count } {
+ verbose -log " expected $expected_totals($type)\
+ $type; got $count"
+ set result fail
+ }
+ unset expected_totals($type)
+ exp_continue
+ }
+ -re {^\n*\tEND:[^\n]+\n} {
+ # flush to EOF
+ expect -re {.+} { exp_continue } eof
+ }
+ }
+ catch close
+ wait -nowait
+
+ foreach { type count } [array get expected_totals] {
+ if { $count == 0 } { continue }
+ verbose -log " expected $count $type; got no report"
+ set result fail
+ }
+
+ $result "test $test_program with: $test"
+ }
+}
+
+test_libdejagnu_unit c {
+ pass fail xpass xfail untested unresolved
+}