Skip to content

Commit

Permalink
test: add test_exec and check memory leaks
Browse files Browse the repository at this point in the history
re_fhs_flush is used to cleanup OOM tests
  • Loading branch information
sreimers committed Jan 20, 2025
1 parent f88cc44 commit d24f3e7
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,35 @@ static const struct test *find_test_int(const char *name)
}


static int test_exec(const struct test *test)
{
if (!test)
return EINVAL;

struct memstat mstat_before;
struct memstat mstat_after;

mem_get_stat(&mstat_before);

int err = test->exec();
re_fhs_flush();

mem_get_stat(&mstat_after);

if (mstat_before.blocks_cur != mstat_after.blocks_cur) {
mem_debug();
re_assert(false && "Test leaks memory blocks");
}

if (mstat_before.bytes_cur != mstat_after.bytes_cur) {
mem_debug();
re_assert(false && "Test leaks memory bytes");
}

return err;
}


/**
* Run a single testcase in OOM (Out-of-memory) mode.
*
Expand Down Expand Up @@ -418,7 +447,7 @@ static int testcase_oom(const struct test *test, int levels, bool verbose)

mem_threshold_set(i);

err = test->exec();
err = test_exec(test);
if (err == 0) {
/* success, stop now */
break;
Expand Down Expand Up @@ -522,7 +551,7 @@ static int test_unit(const char *name, bool verbose)
goto out;
}

err = test->exec();
err = test_exec(test);
if (err) {
DEBUG_WARNING("%s: test failed (%m)\n", name, err);
goto out;
Expand Down Expand Up @@ -595,7 +624,7 @@ static int testcase_perf(const struct test *test, double *usec_avgp)
usec_start = tmr_jiffies_usec();
for (i = 1; i <= DRYRUN_MAX; i++) {

err = test->exec();
err = test_exec(test);
if (err)
return err;

Expand All @@ -613,7 +642,7 @@ static int testcase_perf(const struct test *test, double *usec_avgp)
/* now for the real measurement */
usec_start = tmr_jiffies_usec();
for (i=0; i<n; i++) {
err = test->exec();
err = test_exec(test);
if (err)
return err;
}
Expand Down Expand Up @@ -786,7 +815,7 @@ static int thread_handler(void *arg)
return 0;
}

err = thr->test->exec();
err = test_exec(thr->test);
if (err) {
if (err == ESKIPPED) {
err = 0;
Expand Down Expand Up @@ -1100,7 +1129,7 @@ int test_integration(const char *name, bool verbose)
(void)re_fprintf(stderr, " %-24s: ", test->name);

if (test->exec)
err = test->exec();
err = test_exec(test);

if (err)
DEBUG_WARNING(" %-24s: NOK: %m\n", test->name, err);
Expand All @@ -1119,7 +1148,7 @@ int test_integration(const char *name, bool verbose)
(void)re_fprintf(stderr, " %-32s: ", test->name);

if (test->exec)
err = test->exec();
err = test_exec(test);

if (err) {
DEBUG_WARNING(" %-24s: NOK: %m\n", test->name, err);
Expand Down

0 comments on commit d24f3e7

Please sign in to comment.