|
2 | 2 | #include <furi.h>
|
3 | 3 | #include <furi_hal.h>
|
4 | 4 |
|
| 5 | +#include <FreeRTOS.h> |
| 6 | +#include <task.h> |
| 7 | + |
5 | 8 | #define TAG "TestFuriEventLoop"
|
6 | 9 |
|
7 | 10 | #define EVENT_LOOP_EVENT_COUNT (256u)
|
@@ -53,11 +56,31 @@ bool test_furi_event_loop_producer_mq_callback(FuriMessageQueue* queue, void* co
|
53 | 56 | int32_t test_furi_event_loop_producer(void* p) {
|
54 | 57 | furi_check(p);
|
55 | 58 |
|
56 |
| - FURI_LOG_I(TAG, "producer start"); |
57 |
| - |
58 | 59 | TestFuriData* data = p;
|
59 | 60 |
|
| 61 | + FURI_LOG_I(TAG, "producer start 1st run"); |
| 62 | + |
| 63 | + data->producer_event_loop = furi_event_loop_alloc(); |
| 64 | + furi_event_loop_message_queue_subscribe( |
| 65 | + data->producer_event_loop, |
| 66 | + data->mq, |
| 67 | + FuriEventLoopEventOut, |
| 68 | + test_furi_event_loop_producer_mq_callback, |
| 69 | + data); |
| 70 | + |
| 71 | + furi_event_loop_run(data->producer_event_loop); |
| 72 | + |
| 73 | + // 2 EventLoop index, 0xFFFFFFFF - all possible flags, emulate uncleared flags |
| 74 | + xTaskNotifyIndexed(xTaskGetCurrentTaskHandle(), 2, 0xFFFFFFFF, eSetBits); |
| 75 | + |
| 76 | + furi_event_loop_message_queue_unsubscribe(data->producer_event_loop, data->mq); |
| 77 | + furi_event_loop_free(data->producer_event_loop); |
| 78 | + |
| 79 | + FURI_LOG_I(TAG, "producer start 2nd run"); |
| 80 | + |
| 81 | + data->producer_counter = 0; |
60 | 82 | data->producer_event_loop = furi_event_loop_alloc();
|
| 83 | + |
61 | 84 | furi_event_loop_message_queue_subscribe(
|
62 | 85 | data->producer_event_loop,
|
63 | 86 | data->mq,
|
@@ -109,10 +132,29 @@ bool test_furi_event_loop_consumer_mq_callback(FuriMessageQueue* queue, void* co
|
109 | 132 | int32_t test_furi_event_loop_consumer(void* p) {
|
110 | 133 | furi_check(p);
|
111 | 134 |
|
112 |
| - FURI_LOG_I(TAG, "consumer start"); |
113 |
| - |
114 | 135 | TestFuriData* data = p;
|
115 | 136 |
|
| 137 | + FURI_LOG_I(TAG, "consumer start 1st run"); |
| 138 | + |
| 139 | + data->consumer_event_loop = furi_event_loop_alloc(); |
| 140 | + furi_event_loop_message_queue_subscribe( |
| 141 | + data->consumer_event_loop, |
| 142 | + data->mq, |
| 143 | + FuriEventLoopEventIn, |
| 144 | + test_furi_event_loop_consumer_mq_callback, |
| 145 | + data); |
| 146 | + |
| 147 | + furi_event_loop_run(data->consumer_event_loop); |
| 148 | + |
| 149 | + // 2 EventLoop index, 0xFFFFFFFF - all possible flags, emulate uncleared flags |
| 150 | + xTaskNotifyIndexed(xTaskGetCurrentTaskHandle(), 2, 0xFFFFFFFF, eSetBits); |
| 151 | + |
| 152 | + furi_event_loop_message_queue_unsubscribe(data->consumer_event_loop, data->mq); |
| 153 | + furi_event_loop_free(data->consumer_event_loop); |
| 154 | + |
| 155 | + FURI_LOG_I(TAG, "consumer start 2nd run"); |
| 156 | + |
| 157 | + data->consumer_counter = 0; |
116 | 158 | data->consumer_event_loop = furi_event_loop_alloc();
|
117 | 159 | furi_event_loop_message_queue_subscribe(
|
118 | 160 | data->consumer_event_loop,
|
@@ -156,6 +198,7 @@ void test_furi_event_loop(void) {
|
156 | 198 |
|
157 | 199 | // The test itself
|
158 | 200 | mu_assert_int_eq(data.producer_counter, data.consumer_counter);
|
| 201 | + mu_assert_int_eq(data.producer_counter, EVENT_LOOP_EVENT_COUNT); |
159 | 202 |
|
160 | 203 | // Release memory
|
161 | 204 | furi_thread_free(consumer_thread);
|
|
0 commit comments