Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: increase test_oom levels and oom fixes #1260

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/re_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void re_thread_async_cancel(intptr_t id);
void re_thread_async_main_cancel(intptr_t id);

void re_set_mutex(void *mutexp);
void re_fhs_flush(void);

struct tmrl *re_tmrl_get(void);

Expand Down
20 changes: 20 additions & 0 deletions src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1654,3 +1654,23 @@ void re_thread_async_main_cancel(intptr_t id)

re_async_cancel(re->async, id);
}


/**
* Flush file descriptors handlers if re loop is not running
*/
void re_fhs_flush(void)
{
struct re *re = re_get();
if (!re) {
DEBUG_WARNING("re_fhs_flush: re not ready\n");
return;
}

if (re_atomic_rlx(&re->polling)) {
DEBUG_WARNING("re_fhs_flush: re polling is running\n");
return;
}

fhsld_flush(re);
}
29 changes: 20 additions & 9 deletions test/rtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static int test_loss(const uint16_t *seqv, size_t seqc,
if (err) {
if (err == ENOENT)
err = ENOMEM;
goto out;
TEST_ERR(err);
}

/* in OOM-test, detect if member/sender was not allocated */
Expand All @@ -155,9 +155,12 @@ static int test_loss(const uint16_t *seqv, size_t seqc,
stats.rx.jit == 0) {

err = ENOMEM;
goto out;
TEST_ERR(err);
}

if (test_mode == TEST_MEMORY)
goto out;

/* verify expected packets sent and packet loss */
TEST_EQUALS(seqc, stats.rx.sent);
TEST_EQUALS(exp_lost, stats.rx.lost);
Expand All @@ -181,14 +184,22 @@ int test_rtcp_packetloss(void)
static const uint16_t seqv7[] = {1,2,8,9,10};
int err = 0;

err |= test_loss(seqv1, RE_ARRAY_SIZE(seqv1), 0);
err |= test_loss(seqv2, RE_ARRAY_SIZE(seqv2), 0);
err |= test_loss(seqv3, RE_ARRAY_SIZE(seqv3), 0);
err |= test_loss(seqv4, RE_ARRAY_SIZE(seqv4), 1);
err |= test_loss(seqv5, RE_ARRAY_SIZE(seqv5), 2);
err |= test_loss(seqv6, RE_ARRAY_SIZE(seqv6), 1);
err |= test_loss(seqv7, RE_ARRAY_SIZE(seqv7), 5);
err = test_loss(seqv1, RE_ARRAY_SIZE(seqv1), 0);
TEST_ERR(err);
err = test_loss(seqv2, RE_ARRAY_SIZE(seqv2), 0);
TEST_ERR(err);
err = test_loss(seqv3, RE_ARRAY_SIZE(seqv3), 0);
TEST_ERR(err);
err = test_loss(seqv4, RE_ARRAY_SIZE(seqv4), 1);
TEST_ERR(err);
err = test_loss(seqv5, RE_ARRAY_SIZE(seqv5), 2);
TEST_ERR(err);
err = test_loss(seqv6, RE_ARRAY_SIZE(seqv6), 1);
TEST_ERR(err);
err = test_loss(seqv7, RE_ARRAY_SIZE(seqv7), 5);
TEST_ERR(err);

out:
return err;
}

Expand Down
39 changes: 34 additions & 5 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_after.blocks_cur > mstat_before.blocks_cur) {
mem_debug();
re_assert(false && "Test leaks memory blocks");
}

if (mstat_after.bytes_cur > mstat_before.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 @@ -459,7 +488,7 @@ static int testcase_oom(const struct test *test, int levels, bool verbose)
int test_oom(const char *name, bool verbose)
{
size_t i;
const int levels = 64;
const int levels = 128;
int err = 0;

test_mode = TEST_MEMORY;
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
Loading