summaryrefslogtreecommitdiff
path: root/tests/main.cpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-04-11 22:46:08 -0700
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-04-11 22:46:08 -0700
commit4e004176bacb0160007102742ec62e79a9d958bb (patch)
treee903e77b67e3a24c50238b7b60b223340fc52b8e /tests/main.cpp
parent37467c13bfdfbdbee7cc5176a8755e04353a9deb (diff)
tests: Improve out-of-memory tests
Previously there was no guarantee that the tests that check for out of memory handling behavior are actually correct - e.g. that they correctly simulate out of memory conditions. Now every simulated out of memory condition has to be "guarded" using CHECK_ALLOC_FAIL. It makes sure that every piece of code that is supposed to cause out-of-memory does so, and that no other code runs out of memory unnoticed.
Diffstat (limited to 'tests/main.cpp')
-rw-r--r--tests/main.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index c4c9341..6996eb9 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -27,11 +27,13 @@ const char* test_runner::_temp_path;
static size_t g_memory_total_size = 0;
static size_t g_memory_total_count = 0;
+static size_t g_memory_fail_triggered = false;
static void* custom_allocate(size_t size)
{
if (test_runner::_memory_fail_threshold > 0 && test_runner::_memory_fail_threshold < g_memory_total_size + size)
{
+ g_memory_fail_triggered = true;
test_runner::_memory_fail_triggered = true;
return 0;
@@ -88,6 +90,7 @@ static bool run_test(test_runner* test)
#endif
g_memory_total_size = 0;
g_memory_total_count = 0;
+ g_memory_fail_triggered = false;
test_runner::_memory_fail_threshold = 0;
test_runner::_memory_fail_triggered = false;
@@ -113,6 +116,12 @@ static bool run_test(test_runner* test)
test->run();
+ if (test_runner::_memory_fail_triggered)
+ {
+ printf("Test %s failed: unguarded memory fail triggered\n", test->_name);
+ return false;
+ }
+
if (g_memory_total_size != 0 || g_memory_total_count != 0)
{
printf("Test %s failed: memory leaks found (%u bytes in %u allocations)\n", test->_name, static_cast<unsigned int>(g_memory_total_size), static_cast<unsigned int>(g_memory_total_count));