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/memory.h | |
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/memory.h')
-rw-r--r-- | test/unit/memory.h | 69 |
1 files changed, 69 insertions, 0 deletions
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 */ |