mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-03-19 05:34:02 -04:00
tests: ensure sanity leak check tests pass when leak checks are disabled.
This finalizes Robert Bradfords patch to allow NO_ASSERT_LEAK_CHECK environment variable to disable leak checks in unit tests. Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
This commit is contained in:
parent
c95c2dffb0
commit
91931bcabb
2 changed files with 13 additions and 1 deletions
|
|
@ -29,6 +29,8 @@
|
||||||
#include "test-runner.h"
|
#include "test-runner.h"
|
||||||
#include "wayland-util.h"
|
#include "wayland-util.h"
|
||||||
|
|
||||||
|
extern int leak_check_enabled;
|
||||||
|
|
||||||
TEST(empty)
|
TEST(empty)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -68,6 +70,8 @@ FAIL_TEST(sanity_malloc_direct)
|
||||||
{
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
|
assert(leak_check_enabled);
|
||||||
|
|
||||||
p = malloc(10); /* memory leak */
|
p = malloc(10); /* memory leak */
|
||||||
assert(p); /* assert that we got memory, also prevents
|
assert(p); /* assert that we got memory, also prevents
|
||||||
* the malloc from getting optimized away. */
|
* the malloc from getting optimized away. */
|
||||||
|
|
@ -78,6 +82,8 @@ FAIL_TEST(sanity_malloc_indirect)
|
||||||
{
|
{
|
||||||
struct wl_array array;
|
struct wl_array array;
|
||||||
|
|
||||||
|
assert(leak_check_enabled);
|
||||||
|
|
||||||
wl_array_init(&array);
|
wl_array_init(&array);
|
||||||
|
|
||||||
/* call into library that calls malloc */
|
/* call into library that calls malloc */
|
||||||
|
|
@ -90,6 +96,8 @@ FAIL_TEST(sanity_fd_leak)
|
||||||
{
|
{
|
||||||
int fd[2];
|
int fd[2];
|
||||||
|
|
||||||
|
assert(leak_check_enabled);
|
||||||
|
|
||||||
/* leak 2 file descriptors */
|
/* leak 2 file descriptors */
|
||||||
if (pipe(fd) < 0)
|
if (pipe(fd) < 0)
|
||||||
exit(EXIT_SUCCESS); /* failed to fail */
|
exit(EXIT_SUCCESS); /* failed to fail */
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@ static void (*sys_free)(void*);
|
||||||
static void* (*sys_realloc)(void*, size_t);
|
static void* (*sys_realloc)(void*, size_t);
|
||||||
static void* (*sys_calloc)(size_t, size_t);
|
static void* (*sys_calloc)(size_t, size_t);
|
||||||
|
|
||||||
|
int leak_check_enabled;
|
||||||
|
|
||||||
extern const struct test __start_test_section, __stop_test_section;
|
extern const struct test __start_test_section, __stop_test_section;
|
||||||
|
|
||||||
__attribute__ ((visibility("default"))) void *
|
__attribute__ ((visibility("default"))) void *
|
||||||
|
|
@ -95,7 +97,7 @@ run_test(const struct test *t)
|
||||||
|
|
||||||
cur_fds = count_open_fds();
|
cur_fds = count_open_fds();
|
||||||
t->run();
|
t->run();
|
||||||
if (!getenv("NO_ASSERT_LEAK_CHECK")) {
|
if (leak_check_enabled) {
|
||||||
assert(cur_alloc == num_alloc && "memory leak detected in test.");
|
assert(cur_alloc == num_alloc && "memory leak detected in test.");
|
||||||
assert(cur_fds == count_open_fds() && "fd leak detected");
|
assert(cur_fds == count_open_fds() && "fd leak detected");
|
||||||
}
|
}
|
||||||
|
|
@ -115,6 +117,8 @@ int main(int argc, char *argv[])
|
||||||
sys_malloc = dlsym(RTLD_NEXT, "malloc");
|
sys_malloc = dlsym(RTLD_NEXT, "malloc");
|
||||||
sys_free = dlsym(RTLD_NEXT, "free");
|
sys_free = dlsym(RTLD_NEXT, "free");
|
||||||
|
|
||||||
|
leak_check_enabled = !getenv("NO_ASSERT_LEAK_CHECK");
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
t = find_test(argv[1]);
|
t = find_test(argv[1]);
|
||||||
if (t == NULL) {
|
if (t == NULL) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue