Skip to content

Commit 4169c12

Browse files
committed
tests: event_manager: Fix sys_reboot misuse
`sys_reboot()` function is expected to be non-return function (marked now explicitly with FUNC_NORETURN attribute). As the OOM event_manger test case reimplements this function as returning, the compiler complains with a warning and the code crashed when executing test. Fix this by implementing the function as truly non-return. Since the test case is consdered successful when `sys_reboot()` is called, end it explicitly from there, releasing resources beforehand. Finally, rework the rest of the test, to be executed directly from the test thread instead of system workqueue via event manager. The reason for this, is that after non-returning `sys_reboot()` is called from the workqueue context, it will remain blocked. When calling `sys_reboot()` from the test thread, the test suite takes care of aborting the test thread and starting fresh for the next test case. Signed-off-by: Robert Lubos <[email protected]>
1 parent 5378986 commit 4169c12

File tree

2 files changed

+24
-51
lines changed

2 files changed

+24
-51
lines changed

tests/subsys/event_manager/src/main.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,13 @@ static void test_subs_order(void)
5959
test_start(TEST_SUBSCRIBER_ORDER);
6060
}
6161

62-
static void test_oom_reset(void)
63-
{
64-
test_start(TEST_OOM_RESET);
65-
}
66-
6762
static void test_multicontext(void)
6863
{
6964
test_start(TEST_MULTICONTEXT);
7065
}
7166

67+
void test_oom_reset(void);
68+
7269
void test_main(void)
7370
{
7471
ztest_test_suite(event_manager_tests,

tests/subsys/event_manager/src/modules/test_oom.c

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,63 +14,39 @@
1414
#define TEST_EVENTS_CNT 150
1515

1616
static struct data_event *event_tab[TEST_EVENTS_CNT];
17-
static bool oom_error;
1817

1918
/* Custom reboot handler to check if sys_reboot is called when OOM. */
2019
void sys_reboot(int type)
2120
{
22-
oom_error = true;
23-
}
24-
25-
static bool event_handler(const struct event_header *eh)
26-
{
27-
if (is_test_start_event(eh)) {
28-
struct test_start_event *st = cast_test_start_event(eh);
29-
30-
switch (st->test_id) {
31-
case TEST_OOM_RESET:
32-
{
33-
/* Sending large number of events to cause out of memory error. */
34-
int i;
21+
int i = 0;
3522

36-
for (i = 0; i < ARRAY_SIZE(event_tab); i++) {
37-
event_tab[i] = new_data_event();
38-
if (event_tab[i] == NULL) {
39-
break;
40-
}
41-
}
23+
/* Freeing memory to enable further testing. */
24+
while (event_tab[i] != NULL) {
25+
k_free(event_tab[i]);
26+
i++;
27+
}
4228

43-
zassert_true(i < ARRAY_SIZE(event_tab),
44-
"No OOM detected, increase TEST_EVENTS_CNT");
45-
zassert_true(oom_error, "OOM error not detected");
29+
ztest_test_pass();
4630

47-
/* Freeing memory to enable further testing. */
48-
while (i >= 0) {
49-
k_free(event_tab[i]);
50-
i--;
51-
}
31+
while (true) {
32+
;
33+
}
34+
}
5235

53-
struct test_end_event *et = new_test_end_event();
36+
void test_oom_reset(void)
37+
{
38+
/* Sending large number of events to cause out of memory error. */
39+
int i;
5440

55-
zassert_not_null(et, "Failed to allocate event");
56-
et->test_id = st->test_id;
57-
EVENT_SUBMIT(et);
58-
break;
59-
}
60-
default:
61-
/* Ignore other test cases, check if proper test_id. */
62-
zassert_true(st->test_id < TEST_CNT,
63-
"test_id out of range");
41+
for (i = 0; i < ARRAY_SIZE(event_tab); i++) {
42+
event_tab[i] = new_data_event();
43+
if (event_tab[i] == NULL) {
6444
break;
6545
}
66-
67-
return false;
6846
}
6947

70-
zassert_true(false, "Event unhandled");
71-
72-
return false;
48+
/* This shall only be executed if OOM is not triggered. */
49+
zassert_true(i < ARRAY_SIZE(event_tab),
50+
"No OOM detected, increase TEST_EVENTS_CNT");
51+
zassert_unreachable("OOM error not detected");
7352
}
74-
75-
EVENT_LISTENER(MODULE, event_handler);
76-
EVENT_SUBSCRIBE(MODULE, test_start_event);

0 commit comments

Comments
 (0)