aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test-runner.c
diff options
context:
space:
mode:
authorU. Artie Eoff <ullysses.a.eoff@intel.com>2012-03-23 10:01:23 -0700
committerKristian Høgsberg <krh@bitplanet.net>2012-03-24 14:37:42 -0400
commita0e590a0f3ea87b7616cf197edd240b7b99fcc2e (patch)
treec02a921de509e6f1a0dc9ab3b45dabdbf7dd86c9 /tests/test-runner.c
parentconnection-test: Add test case to stress connection buffers (diff)
downloadwayland-a0e590a0f3ea87b7616cf197edd240b7b99fcc2e.tar
wayland-a0e590a0f3ea87b7616cf197edd240b7b99fcc2e.tar.gz
wayland-a0e590a0f3ea87b7616cf197edd240b7b99fcc2e.tar.bz2
wayland-a0e590a0f3ea87b7616cf197edd240b7b99fcc2e.tar.lz
wayland-a0e590a0f3ea87b7616cf197edd240b7b99fcc2e.tar.xz
wayland-a0e590a0f3ea87b7616cf197edd240b7b99fcc2e.tar.zst
wayland-a0e590a0f3ea87b7616cf197edd240b7b99fcc2e.zip
Add simple memory leak check to all tests.
Wrap all tests with a memory balance check to detect potential memory leaks. Fixed a few tests that had memory leaks contained in the tests themselves. Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
Diffstat (limited to 'tests/test-runner.c')
-rw-r--r--tests/test-runner.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 301c736..321d5c0 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -20,6 +20,8 @@
* OF THIS SOFTWARE.
*/
+#define _GNU_SOURCE
+
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
@@ -27,10 +29,28 @@
#include <sys/wait.h>
#include <string.h>
#include <assert.h>
+#include <dlfcn.h>
#include "test-runner.h"
+static int num_alloc;
+static void* (*sys_malloc)(size_t);
+static void (*sys_free)(void*);
+
extern const struct test __start_test_section, __stop_test_section;
+void* malloc(size_t size)
+{
+ num_alloc++;
+ return sys_malloc(size);
+}
+
+void free(void* mem)
+{
+ if (mem != NULL)
+ num_alloc--;
+ sys_free(mem);
+}
+
static const struct test *
find_test(const char *name)
{
@@ -46,7 +66,10 @@ find_test(const char *name)
static void
run_test(const struct test *t)
{
+ int cur_alloc = num_alloc;
+
t->run();
+ assert(("memory leak detected in test.", cur_alloc == num_alloc));
exit(EXIT_SUCCESS);
}
@@ -57,6 +80,10 @@ int main(int argc, char *argv[])
int total, pass;
siginfo_t info;
+ /* Load system malloc and free */
+ sys_malloc = dlsym(RTLD_NEXT, "malloc");
+ sys_free = dlsym(RTLD_NEXT, "free");
+
if (argc == 2) {
t = find_test(argv[1]);
if (t == NULL) {