From 4e004176bacb0160007102742ec62e79a9d958bb Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 11 Apr 2015 22:46:08 -0700 Subject: 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. --- tests/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/main.cpp') 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(g_memory_total_size), static_cast(g_memory_total_count)); -- cgit v1.2.3