Skip to content

Commit

Permalink
Add tests for C unit test library
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Bachmeyer committed Nov 27, 2022
1 parent c173c00 commit e8446c3
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 9 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
2022-11-26 Jacob Bachmeyer <[email protected]>

* 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.
Expand Down
9 changes: 6 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down Expand Up @@ -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
Expand All @@ -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.

Expand Down
55 changes: 49 additions & 6 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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@)
Expand All @@ -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 " $@;
Expand Down Expand Up @@ -560,15 +577,17 @@ 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

# 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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 $@ $< &&\
Expand Down
60 changes: 60 additions & 0 deletions testsuite/libdejagnu/unit-c.c
Original file line number Diff line number Diff line change
@@ -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 */
127 changes: 127 additions & 0 deletions testsuite/libdejagnu/unit.exp
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit e8446c3

Please sign in to comment.