|
14 | 14 | #define TEST_EVENTS_CNT 150 |
15 | 15 |
|
16 | 16 | static struct data_event *event_tab[TEST_EVENTS_CNT]; |
17 | | -static bool oom_error; |
18 | 17 |
|
19 | 18 | /* Custom reboot handler to check if sys_reboot is called when OOM. */ |
20 | 19 | void sys_reboot(int type) |
21 | 20 | { |
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; |
35 | 22 |
|
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 | + } |
42 | 28 |
|
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(); |
46 | 30 |
|
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 | +} |
52 | 35 |
|
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; |
54 | 40 |
|
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) { |
64 | 44 | break; |
65 | 45 | } |
66 | | - |
67 | | - return false; |
68 | 46 | } |
69 | 47 |
|
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"); |
73 | 52 | } |
74 | | - |
75 | | -EVENT_LISTENER(MODULE, event_handler); |
76 | | -EVENT_SUBSCRIBE(MODULE, test_start_event); |
0 commit comments