diff options
author | Morgan Deters <mdeters@gmail.com> | 2010-04-14 06:21:26 +0000 |
---|---|---|
committer | Morgan Deters <mdeters@gmail.com> | 2010-04-14 06:21:26 +0000 |
commit | 7c83d004874a46efe36d58717f7a4d72553b3693 (patch) | |
tree | 40fdb91a99c0ea0a9e4ce884126c0f572959a003 /test/unit | |
parent | 12a8a7f9a90e45e8313f26af527a52e6dda943d3 (diff) |
* Better dependency tracking for unit test building and linking, and
auto-generated headers (metakind.h etc.), so they don't have to be
recompiled every time. This drastically improves build time when
only small updates are made.
* Added "memory.h" unit test header for checking out-of-memory
conditions. cdlist_black uses it.
* Added helpful output when you "make lcov" in a non-coverage-enabled
build.
* Removed strict aliasing warning when compiling metakind.h header
with optimization on.
* Removed const version of NodeBuilder::operator Node()---it was
poorly performing, better to not permit it---and fixed the
convenience builders to use the non-const version
(re: code review #63)
* Color-coded test output on capable terminals.
* Fixed some warnings in unit tests.
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/Makefile.am | 76 | ||||
-rw-r--r-- | test/unit/context/cdlist_black.h | 21 | ||||
-rw-r--r-- | test/unit/expr/attribute_black.h | 24 | ||||
-rw-r--r-- | test/unit/memory.h | 69 |
4 files changed, 148 insertions, 42 deletions
diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index a190152d3..1f56434c9 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -30,21 +30,8 @@ UNIT_TESTS = \ # Things that aren't tests but that tests rely on and need to # go into the distribution -TEST_DEPS_DIST = - -# Make-level dependencies; these don't go in the source distribution -# but should trigger a re-compile of all unit tests. Libraries are -# included here because (1) if static-linking, the tests must be -# relinked, and (2) if they've changed that means the sources changed, -# and that means we should ensure the tests compile against any -# changes made in the header files. -TEST_DEPS_NODIST = \ - $(abs_top_builddir)/src/libcvc4.la \ - $(abs_top_builddir)/src/parser/libcvc4parser.la - -TEST_DEPS = \ - $(TEST_DEPS_DIST) \ - $(TEST_DEPS_NODIST) +TEST_DEPS_DIST = \ + memory.h if HAVE_CXXTESTGEN @@ -57,13 +44,16 @@ AM_LDFLAGS = $(TEST_LDFLAGS) AM_CXXFLAGS_WHITE = -fno-access-control -D__BUILDING_CVC4LIB_UNIT_TEST -D__BUILDING_CVC4PARSERLIB_UNIT_TEST AM_CXXFLAGS_BLACK = -D__BUILDING_CVC4LIB_UNIT_TEST -D__BUILDING_CVC4PARSERLIB_UNIT_TEST AM_CXXFLAGS_PUBLIC = -AM_LDFLAGS_WHITE = \ +AM_LDFLAGS_WHITE = +AM_LDFLAGS_BLACK = +AM_LDFLAGS_PUBLIC = +AM_LIBADD_WHITE = \ @abs_top_builddir@/src/parser/libcvc4parser_noinst.la \ @abs_top_builddir@/src/libcvc4_noinst.la -AM_LDFLAGS_BLACK = \ +AM_LIBADD_BLACK = \ @abs_top_builddir@/src/parser/libcvc4parser_noinst.la \ @abs_top_builddir@/src/libcvc4_noinst.la -AM_LDFLAGS_PUBLIC = \ +AM_LIBADD_PUBLIC = \ @abs_top_builddir@/src/libcvc4.la EXTRA_DIST = \ @@ -84,18 +74,48 @@ else unit_LINK = $(CXXLINK) endif +@AMDEP_TRUE@@am__include@ $(UNIT_TESTS:%=@am__quote@./$(DEPDIR)/%.Plo@am__quote@) + +$(UNIT_TESTS:%=@am__quote@./$(DEPDIR)/%.Plo@am__quote@): %.Plo: + $(AM_V_at)$(MKDIR_P) `dirname "$@"` + $(AM_V_GEN)test -e "$@" || touch "$@" + $(UNIT_TESTS:%=%.cpp): %.cpp: %.h - $(AM_V_at)mkdir -p `dirname "$@"` + $(AM_V_at)$(MKDIR_P) `dirname "$@"` $(AM_V_GEN)$(CXXTESTGEN) --have-eh --have-std --error-printer -o "$@" "$<" -$(WHITE_TESTS): %_white: %_white.cpp $(TEST_DEPS) - $(AM_V_CXX)$(LTCXXCOMPILE) $(AM_CXXFLAGS_WHITE) -c -o $@.lo @abs_builddir@/$< - $(AM_V_CXXLD)$(unit_LINK) $(AM_LDFLAGS_WHITE) $@.lo -$(BLACK_TESTS): %_black: %_black.cpp $(TEST_DEPS) - $(AM_V_CXX)$(LTCXXCOMPILE) $(AM_CXXFLAGS_BLACK) -c -o $@.lo @abs_builddir@/$< - $(AM_V_CXXLD)$(unit_LINK) $(AM_LDFLAGS_BLACK) $@.lo -$(PUBLIC_TESTS): %_public: %_public.cpp $(TEST_DEPS) - $(AM_V_CXX)$(LTCXXCOMPILE) $(AM_CXXFLAGS_PUBLIC) -c -o $@.lo @abs_builddir@/$< - $(AM_V_CXXLD)$(unit_LINK) $(AM_LDFLAGS_PUBLIC) $@.lo + +$(WHITE_TESTS:%=%.lo): %_white.lo: %_white.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) $(AM_CXXFLAGS_WHITE) -MT $@ -MD -MP -MF $(DEPDIR)/$(@:%.lo=%).Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$(@:%.lo=%).Tpo $(DEPDIR)/$(@:%.lo=%).Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) $(AM_CXXFLAGS_WHITE) -c -o $@ $< + +$(WHITE_TESTS): %_white: %_white.lo $(AM_LIBADD_WHITE) + $(AM_V_CXXLD)$(unit_LINK) $(AM_LIBADD_WHITE) $(AM_LDFLAGS_WHITE) $< + +$(BLACK_TESTS:%=%.lo): %_black.lo: %_black.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) $(AM_CXXFLAGS_BLACK) -MT $@ -MD -MP -MF $(DEPDIR)/$(@:%.lo=%).Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$(@:%.lo=%).Tpo $(DEPDIR)/$(@:%.lo=%).Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) $(AM_CXXFLAGS_BLACK) -c -o $@ $< + +$(BLACK_TESTS): %_black: %_black.lo $(AM_LIBADD_BLACK) + $(AM_V_CXXLD)$(unit_LINK) $(AM_LIBADD_BLACK) $(AM_LDFLAGS_BLACK) $< + +$(PUBLIC_TESTS:%=%.lo): %_public.lo: %_public.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) $(AM_CXXFLAGS_PUBLIC) -MT $@ -MD -MP -MF $(DEPDIR)/$(@:%.lo=%).Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$(@:%.lo=%).Tpo $(DEPDIR)/$(@:%.lo=%).Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) $(AM_CXXFLAGS_PUBLIC) -c -o $@ $< + +$(PUBLIC_TESTS): %_public: %_public.lo $(AM_LIBADD_PUBLIC) + $(AM_V_CXXLD)$(unit_LINK) $(AM_LIBADD_PUBLIC) $(AM_LDFLAGS_PUBLIC) $< else diff --git a/test/unit/context/cdlist_black.h b/test/unit/context/cdlist_black.h index 418357630..bcc95b470 100644 --- a/test/unit/context/cdlist_black.h +++ b/test/unit/context/cdlist_black.h @@ -17,12 +17,17 @@ #include <vector> #include <iostream> + +#include <limits.h> + +#include "memory.h" + #include "context/context.h" #include "context/cdlist.h" using namespace std; using namespace CVC4::context; - +using namespace CVC4::test; struct DtorSensitiveObject { bool& d_dtorCalled; @@ -30,7 +35,6 @@ struct DtorSensitiveObject { ~DtorSensitiveObject() { d_dtorCalled = true; } }; - class CDListBlack : public CxxTest::TestSuite { private: @@ -125,4 +129,17 @@ public: TS_ASSERT_EQUALS(shouldAlsoRemainFalse, false); TS_ASSERT_EQUALS(aThirdFalse, false); } + + void testOutOfMemory() { + CDList<unsigned> list(d_context); + WithLimitedMemory wlm(0); + + TS_ASSERT_THROWS({ + // We cap it at UINT_MAX, preferring to terminate with a + // failure than run indefinitely. + for(unsigned i = 0; i < UINT_MAX; ++i) { + list.push_back(i); + } + }, bad_alloc); + } }; diff --git a/test/unit/expr/attribute_black.h b/test/unit/expr/attribute_black.h index 92aacf509..5ae644193 100644 --- a/test/unit/expr/attribute_black.h +++ b/test/unit/expr/attribute_black.h @@ -91,8 +91,8 @@ public: Type* booleanType = d_nodeManager->booleanType(); Node* node = new Node(d_nodeManager->mkVar(booleanType)); const uint64_t val = 63489; - uint64_t data0; - uint64_t data1; + uint64_t data0 = 0; + uint64_t data1 = 0; PrimitiveIntAttribute attr; TS_ASSERT(!node->getAttribute(attr, data0)); @@ -100,8 +100,8 @@ public: TS_ASSERT(node->getAttribute(attr, data1)); TS_ASSERT_EQUALS(data1, val); - uint64_t data2; - uint64_t data3; + uint64_t data2 = 0; + uint64_t data3 = 0; CDPrimitiveIntAttribute cdattr; TS_ASSERT(!node->getAttribute(cdattr, data2)); node->setAttribute(cdattr, val); @@ -155,8 +155,8 @@ public: Node* node = new Node(d_nodeManager->mkVar(booleanType)); Foo* val = new Foo(63489); - Foo* data0; - Foo* data1; + Foo* data0 = NULL; + Foo* data1 = NULL; PtrAttribute attr; TS_ASSERT(!node->getAttribute(attr, data0)); @@ -164,8 +164,8 @@ public: TS_ASSERT(node->getAttribute(attr, data1)); TS_ASSERT_EQUALS(data1, val); - Foo* data2; - Foo* data3; + Foo* data2 = NULL; + Foo* data3 = NULL; CDPtrAttribute cdattr; TS_ASSERT(!node->getAttribute(cdattr, data2)); node->setAttribute(cdattr, val); @@ -186,8 +186,8 @@ public: Node* node = new Node(d_nodeManager->mkVar(booleanType)); const Foo* val = new Foo(63489); - const Foo* data0; - const Foo* data1; + const Foo* data0 = NULL; + const Foo* data1 = NULL; ConstPtrAttribute attr; TS_ASSERT(!node->getAttribute(attr, data0)); @@ -195,8 +195,8 @@ public: TS_ASSERT(node->getAttribute(attr, data1)); TS_ASSERT_EQUALS(data1, val); - const Foo* data2; - const Foo* data3; + const Foo* data2 = NULL; + const Foo* data3 = NULL; CDConstPtrAttribute cdattr; TS_ASSERT(!node->getAttribute(cdattr, data2)); node->setAttribute(cdattr, val); diff --git a/test/unit/memory.h b/test/unit/memory.h new file mode 100644 index 000000000..38ac63e65 --- /dev/null +++ b/test/unit/memory.h @@ -0,0 +1,69 @@ +/********************* */ +/** memory.h + ** Original author: mdeters + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 prototype. + ** Copyright (c) 2009, 2010 The Analysis of Computer Systems Group (ACSys) + ** Courant Institute of Mathematical Sciences + ** New York University + ** See the file COPYING in the top-level source directory for licensing + ** information. + ** + ** Utility class to help testing out-of-memory conditions. + ** + ** Use it like this (for example): + ** + ** CVC4::test::WithLimitedMemory wlm(amount); + ** TS_ASSERT_THROWS( foo(), bad_alloc ); + ** + ** The WithLimitedMemory destructor will re-establish the previous limit. + **/ + +#include <cxxtest/TestSuite.h> + +#ifndef __CVC4__TEST__MEMORY_H +#define __CVC4__TEST__MEMORY_H + +#include <sys/time.h> +#include <sys/resource.h> + +namespace CVC4 { +namespace test { + +class WithLimitedMemory { + rlim_t d_prevAmount; + + void remember() { + struct rlimit rlim; + TS_ASSERT_EQUALS(getrlimit(RLIMIT_AS, &rlim), 0); + d_prevAmount = rlim.rlim_cur; + } + +public: + + WithLimitedMemory() { + remember(); + } + + WithLimitedMemory(rlim_t amount) { + remember(); + set(amount); + } + + ~WithLimitedMemory() { + set(d_prevAmount); + } + + void set(rlim_t amount) { + struct rlimit rlim; + rlim.rlim_cur = amount; + rlim.rlim_max = RLIM_INFINITY; + TS_ASSERT_EQUALS(setrlimit(RLIMIT_AS, &rlim), 0); + } +}; + +}/* CVC4::test namespace */ +}/* CVC4 namespace */ + +#endif /* __CVC4__TEST__MEMORY_H */ |