GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tests/gatecore_test/test_runnables.c
Date: 2026-09-21 06:26:40
Exec Total Coverage
Lines: 102 102 100.0%
Functions: 11 11 100.0%
Branches: 32 64 50.0%

Line Branch Exec Source
1 #include "gate/tests.h"
2 #include "test_runnables.h"
3 #include "gate/runnables.h"
4
5 1 static gate_result_t GATE_CALL basic_runner(gate_dataptr_t arg)
6 {
7 1 int* ptr_data = (int*)arg;
8
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(ptr_data != NULL);
9 1 *ptr_data = 42;
10 1 return GATE_RESULT_OK;
11 }
12
13 1 GATE_TEST_FUNCTION(test_basic_runnable)
14 {
15 1 int data = 1;
16 1 gate_runnable_t* ptr_runner = NULL;
17
18 1 GATE_TEST_UNIT_BEGIN(test_basic_runnable);
19
20 1 ptr_runner = gate_runnable_create(&basic_runner, &data, 0, NULL, NULL);
21
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_runner != NULL);
22
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_OK(gate_runnable_run(ptr_runner));
23
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(data, 42);
24 1 gate_object_release(ptr_runner);
25
26 1 GATE_TEST_UNIT_END;
27 }
28
29
30
31
32 2 static gate_result_t my_runnable_sample(int a, gate_int64_t b, gate_int64_t* c)
33 {
34 2 *c = b * a;
35 2 return GATE_RESULT_OK;
36 }
37
38 1 GATE_RUNNABLE_DISPATCHER_DECLARE_3(runnable_sample_dispatcher, int, gate_int64_t, gate_int64_t*);
39
40
41 1 GATE_TEST_FUNCTION(test_runnable_dispatcher_types)
42 {
43 1 int arg_a = 1000;
44 1 gate_int64_t arg_b = 2000;
45 1 gate_int64_t var_c = 0;
46 1 gate_int64_t* arg_c = &var_c;
47 1 gate_int64_t expected_var_c = 0;
48 1 gate_runnable_t* ptr_runnable = NULL;
49
50 1 GATE_TEST_UNIT_BEGIN(test_runnable_dispatcher_types);
51
52 1 ptr_runnable = GATE_RUNNABLE_DISPATCHER_CREATE_3(runnable_sample_dispatcher, &my_runnable_sample, arg_a, arg_b, arg_c);
53
54
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(ptr_runnable != NULL);
55
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_OK(gate_runnable_run(ptr_runnable));
56 1 gate_object_release(ptr_runnable);
57
58 1 my_runnable_sample(arg_a, arg_b, &expected_var_c);
59
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(var_c == expected_var_c);
60
61
62 1 GATE_TEST_UNIT_END;
63 }
64
65
66
67
68 2 static gate_result_t sum_function(int* ptr_c, int a, int b)
69 {
70 2 *ptr_c = a + b;
71 2 return GATE_RESULT_OK;
72 }
73
74 1 GATE_RUNNABLE_DISPATCHER_DECLARE_3(sum_function, int*, int, int);
75
76 1 GATE_TEST_FUNCTION(test_runnable_dispatcher)
77 {
78 1 int a = 12;
79 1 int b = 5;
80 1 int c = 0;
81 1 int* ptr_c = &c;
82 1 gate_runnable_t* ptr_runnable = NULL;
83 gate_result_t result;
84
85 1 GATE_TEST_UNIT_BEGIN(test_runnable_dispatcher);
86
87 1 ptr_runnable = GATE_RUNNABLE_DISPATCHER_CREATE_3(sum_function, &sum_function, ptr_c, a, b);
88
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_runnable);
89
90 1 result = gate_runnable_run(ptr_runnable);
91
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE_OK(result);
92
93
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(ptr_c, &c);
94
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(c, (a + b));
95
96 1 gate_object_release(ptr_runnable);
97
98 1 GATE_TEST_UNIT_END;
99 }
100
101
102
103 1 GATE_TASK_DISPATCHER_DECLARE_2(sum_task, int, int, int);
104
105 1 GATE_TEST_FUNCTION(test_task_dispatcher)
106 {
107 1 int a = 12;
108 1 int b = 5;
109 1 int const* ptr_c = NULL;
110 1 gate_task_t* ptr_task = NULL;
111 gate_result_t result;
112 1 gate_result_t task_result = GATE_RESULT_NOTDEFINED;
113
114 1 GATE_TEST_UNIT_BEGIN(test_task_dispatcher);
115
116 {
117 /* canceled task */
118 1 ptr_task = GATE_TASK_DISPATCHER_CREATE_2(sum_task, &sum_function, int, a, b);
119
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_task);
120
121
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_object_get_interface_name(ptr_task) != NULL);
122
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_object_retain(ptr_task) > 0);
123 1 gate_object_release(ptr_task);
124
125
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_task_get_status(ptr_task), GATE_TASK_STATUS_PREPARED);
126
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_task_completed(ptr_task), false);
127
128 1 result = gate_task_timed_wait(ptr_task, 1);
129
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_RESULT(result, GATE_RESULT_TIMEOUT);
130
131 1 result = gate_task_cancel(ptr_task);
132
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE_OK(result);
133
134 1 result = gate_task_timed_wait(ptr_task, 1);
135
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_RESULT(result, GATE_RESULT_OK);
136
137
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_task_get_status(ptr_task), GATE_TASK_STATUS_CANCELED);
138
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_task_completed(ptr_task), true);
139 1 result = gate_task_get_result(ptr_task, &task_result, (void const**)&ptr_c);
140
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_RESULT(result, GATE_RESULT_OK);
141
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_RESULT(task_result, GATE_RESULT_CANCELED);
142
143 1 gate_object_release(ptr_task);
144 }
145
146 {
147 /* completed task */
148 1 ptr_task = GATE_TASK_DISPATCHER_CREATE_2(sum_task, &sum_function, int, a, b);
149
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_task);
150
151 1 result = gate_task_run(ptr_task);
152
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_OK(result);
153
154 1 result = gate_task_timed_wait(ptr_task, 1);
155
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_RESULT(result, GATE_RESULT_OK);
156
157
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_task_get_status(ptr_task), GATE_TASK_STATUS_COMPLETED);
158
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_task_completed(ptr_task), true);
159 1 result = gate_task_get_result(ptr_task, &task_result, (void const**)&ptr_c);
160
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_OK(result);
161
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_OK(task_result);
162
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_c);
163
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(*ptr_c, (a + b));
164
165 1 gate_object_release(ptr_task);
166 }
167
168 1 GATE_TEST_UNIT_END;
169 }
170
171 1 GATE_TEST_FUNCTION(test_runnables)
172 {
173 1 gate_bool_t succeeded = true;
174
175 1 succeeded &= test_basic_runnable();
176 1 succeeded &= test_runnable_dispatcher();
177 1 succeeded &= test_runnable_dispatcher_types();
178 1 succeeded &= test_task_dispatcher();
179
180 1 return succeeded;
181 }
182