ReactOS 0.4.16-dev-257-g6aa11ac
test_timers.c File Reference
#include "test_timers.h"
#include "lwip/def.h"
#include "lwip/timeouts.h"
#include "arch/sys_arch.h"
Include dependency graph for test_timers.c:

Go to the source code of this file.

Macros

#define HANDLER_EXECUTION_TIME   5
 

Functions

static void timers_setup (void)
 
static void timers_teardown (void)
 
static void dummy_handler (void *arg)
 
static void dummy_cyclic_handler (void)
 
static void do_test_cyclic_timers (u32_t offset)
 
 START_TEST (test_cyclic_timers)
 
END_TEST START_TEST (test_bug52748)
 
static END_TEST void do_test_timers (u32_t offset)
 
 START_TEST (test_timers)
 
END_TEST START_TEST (test_long_timer)
 
END_TEST Suite * timers_suite (void)
 

Variables

static struct sys_timeo * old_list_head
 
static int fired [3]
 
static int cyclic_fired
 
struct lwip_cyclic_timer test_cyclic = {10, dummy_cyclic_handler}
 

Macro Definition Documentation

◆ HANDLER_EXECUTION_TIME

#define HANDLER_EXECUTION_TIME   5

Definition at line 35 of file test_timers.c.

Function Documentation

◆ do_test_cyclic_timers()

static void do_test_cyclic_timers ( u32_t  offset)
static

Definition at line 47 of file test_timers.c.

48{
49 struct sys_timeo** list_head = sys_timeouts_get_next_timeout();
50
51 /* verify normal timer expiration */
52 lwip_sys_now = offset + 0;
53 sys_timeout(test_cyclic.interval_ms, lwip_cyclic_timer, &test_cyclic);
54
55 cyclic_fired = 0;
56 sys_check_timeouts();
57 fail_unless(cyclic_fired == 0);
58
59 lwip_sys_now = offset + test_cyclic.interval_ms;
60 sys_check_timeouts();
61 fail_unless(cyclic_fired == 1);
62
63 fail_unless((*list_head)->time == (u32_t)(lwip_sys_now + test_cyclic.interval_ms - HANDLER_EXECUTION_TIME));
64
65 sys_untimeout(lwip_cyclic_timer, &test_cyclic);
66
67
68 /* verify "overload" - next cyclic timer execution is already overdue twice */
69 lwip_sys_now = offset + 0;
70 sys_timeout(test_cyclic.interval_ms, lwip_cyclic_timer, &test_cyclic);
71
72 cyclic_fired = 0;
73 sys_check_timeouts();
74 fail_unless(cyclic_fired == 0);
75
76 lwip_sys_now = offset + 2*test_cyclic.interval_ms;
77 sys_check_timeouts();
78 fail_unless(cyclic_fired == 1);
79
80 fail_unless((*list_head)->time == (u32_t)(lwip_sys_now + test_cyclic.interval_ms));
81}
GLintptr offset
Definition: glext.h:5920
uint32_t u32_t
Definition: arch.h:129
u32_t lwip_sys_now
Definition: sys_arch.c:45
Definition: list.h:15
static int cyclic_fired
Definition: test_timers.c:36
struct lwip_cyclic_timer test_cyclic
Definition: test_timers.c:44
#define HANDLER_EXECUTION_TIME
Definition: test_timers.c:35

Referenced by START_TEST().

◆ do_test_timers()

static END_TEST void do_test_timers ( u32_t  offset)
static

Definition at line 128 of file test_timers.c.

129{
130 struct sys_timeo** list_head = sys_timeouts_get_next_timeout();
131
132 lwip_sys_now = offset + 0;
133
134 sys_timeout(10, dummy_handler, LWIP_PTR_NUMERIC_CAST(void*, 0));
135 fail_unless(sys_timeouts_sleeptime() == 10);
136 sys_timeout(20, dummy_handler, LWIP_PTR_NUMERIC_CAST(void*, 1));
137 fail_unless(sys_timeouts_sleeptime() == 10);
138 sys_timeout( 5, dummy_handler, LWIP_PTR_NUMERIC_CAST(void*, 2));
139 fail_unless(sys_timeouts_sleeptime() == 5);
140
141 /* linked list correctly sorted? */
142 fail_unless((*list_head)->time == (u32_t)(lwip_sys_now + 5));
143 fail_unless((*list_head)->next->time == (u32_t)(lwip_sys_now + 10));
144 fail_unless((*list_head)->next->next->time == (u32_t)(lwip_sys_now + 20));
145
146 /* check timers expire in correct order */
147 memset(&fired, 0, sizeof(fired));
148
149 lwip_sys_now += 4;
150 sys_check_timeouts();
151 fail_unless(fired[2] == 0);
152
153 lwip_sys_now += 1;
154 sys_check_timeouts();
155 fail_unless(fired[2] == 1);
156
157 lwip_sys_now += 4;
158 sys_check_timeouts();
159 fail_unless(fired[0] == 0);
160
161 lwip_sys_now += 1;
162 sys_check_timeouts();
163 fail_unless(fired[0] == 1);
164
165 lwip_sys_now += 9;
166 sys_check_timeouts();
167 fail_unless(fired[1] == 0);
168
169 lwip_sys_now += 1;
170 sys_check_timeouts();
171 fail_unless(fired[1] == 1);
172
173 sys_untimeout(dummy_handler, LWIP_PTR_NUMERIC_CAST(void*, 0));
174 sys_untimeout(dummy_handler, LWIP_PTR_NUMERIC_CAST(void*, 1));
175 sys_untimeout(dummy_handler, LWIP_PTR_NUMERIC_CAST(void*, 2));
176}
#define LWIP_PTR_NUMERIC_CAST(target_type, val)
Definition: arch.h:252
#define memset(x, y, z)
Definition: compat.h:39
static int fired[3]
Definition: test_timers.c:27
static void dummy_handler(void *arg)
Definition: test_timers.c:29

Referenced by START_TEST().

◆ dummy_cyclic_handler()

static void dummy_cyclic_handler ( void  )
static

Definition at line 38 of file test_timers.c.

◆ dummy_handler()

static void dummy_handler ( void arg)
static

Definition at line 29 of file test_timers.c.

30{
32 fired[index] = 1;
33}
#define index(s, c)
Definition: various.h:29
GLuint index
Definition: glext.h:6031

Referenced by do_test_timers(), and START_TEST().

◆ START_TEST() [1/4]

END_TEST START_TEST ( test_bug52748  )

Definition at line 96 of file test_timers.c.

97{
99
100 memset(&fired, 0, sizeof(fired));
101
102 lwip_sys_now = 50;
103 sys_timeout(20, dummy_handler, LWIP_PTR_NUMERIC_CAST(void*, 0));
104 sys_timeout( 5, dummy_handler, LWIP_PTR_NUMERIC_CAST(void*, 2));
105
106 lwip_sys_now = 55;
107 sys_check_timeouts();
108 fail_unless(fired[0] == 0);
109 fail_unless(fired[1] == 0);
110 fail_unless(fired[2] == 1);
111
112 lwip_sys_now = 60;
113 sys_timeout(10, dummy_handler, LWIP_PTR_NUMERIC_CAST(void*, 1));
114 sys_check_timeouts();
115 fail_unless(fired[0] == 0);
116 fail_unless(fired[1] == 0);
117 fail_unless(fired[2] == 1);
118
119 lwip_sys_now = 70;
120 sys_check_timeouts();
121 fail_unless(fired[0] == 1);
122 fail_unless(fired[1] == 1);
123 fail_unless(fired[2] == 1);
124}
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373

◆ START_TEST() [2/4]

START_TEST ( test_cyclic_timers  )

Definition at line 83 of file test_timers.c.

84{
86
87 /* check without u32_t wraparound */
89
90 /* check with u32_t wraparound */
91 do_test_cyclic_timers(0xfffffff0);
92}
static void do_test_cyclic_timers(u32_t offset)
Definition: test_timers.c:47

◆ START_TEST() [3/4]

END_TEST START_TEST ( test_long_timer  )

Definition at line 190 of file test_timers.c.

191{
192 LWIP_UNUSED_ARG(_i);
193
194 memset(&fired, 0, sizeof(fired));
195 lwip_sys_now = 0;
196
197 sys_timeout(LWIP_UINT32_MAX / 4, dummy_handler, LWIP_PTR_NUMERIC_CAST(void*, 0));
198 fail_unless(sys_timeouts_sleeptime() == LWIP_UINT32_MAX / 4);
199
200 sys_check_timeouts();
201 fail_unless(fired[0] == 0);
202
204
205 sys_check_timeouts();
206 fail_unless(fired[0] == 0);
207
209
210 sys_check_timeouts();
211 fail_unless(fired[0] == 0);
212
213 lwip_sys_now += 1;
214
215 sys_check_timeouts();
216 fail_unless(fired[0] == 1);
217
218 sys_untimeout(dummy_handler, LWIP_PTR_NUMERIC_CAST(void*, 0));
219}
#define LWIP_UINT32_MAX
Definition: arch.h:207

◆ START_TEST() [4/4]

START_TEST ( test_timers  )

Definition at line 178 of file test_timers.c.

179{
180 LWIP_UNUSED_ARG(_i);
181
182 /* check without u32_t wraparound */
184
185 /* check with u32_t wraparound */
186 do_test_timers(0xfffffff0);
187}
static END_TEST void do_test_timers(u32_t offset)
Definition: test_timers.c:128

◆ timers_setup()

static void timers_setup ( void  )
static

Definition at line 12 of file test_timers.c.

13{
14 struct sys_timeo** list_head = sys_timeouts_get_next_timeout();
16 *list_head = NULL;
17}
#define NULL
Definition: types.h:112
static struct sys_timeo * old_list_head
Definition: test_timers.c:9

Referenced by timers_suite().

◆ timers_suite()

END_TEST Suite * timers_suite ( void  )

Create the suite including all tests for this module

Definition at line 224 of file test_timers.c.

225{
226 testfunc tests[] = {
227 TESTFUNC(test_bug52748),
228 TESTFUNC(test_cyclic_timers),
230 TESTFUNC(test_long_timer),
231 };
233}
#define LWIP_ARRAYSIZE(x)
Definition: def.h:69
Suite * create_suite(const char *name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
#define TESTFUNC(x)
Definition: lwip_check.h:22
static struct test_info tests[]
static void test_timers(void)
Definition: msg.c:10249
static void timers_setup(void)
Definition: test_timers.c:12
static void timers_teardown(void)
Definition: test_timers.c:20

Referenced by main().

◆ timers_teardown()

static void timers_teardown ( void  )
static

Definition at line 20 of file test_timers.c.

21{
22 struct sys_timeo** list_head = sys_timeouts_get_next_timeout();
24 lwip_sys_now = 0;
25}

Referenced by timers_suite().

Variable Documentation

◆ cyclic_fired

int cyclic_fired
static

Definition at line 36 of file test_timers.c.

Referenced by do_test_cyclic_timers(), and dummy_cyclic_handler().

◆ fired

int fired[3]
static

Definition at line 27 of file test_timers.c.

Referenced by do_test_timers(), dummy_handler(), and START_TEST().

◆ old_list_head

struct sys_timeo* old_list_head
static

Definition at line 9 of file test_timers.c.

Referenced by timers_setup(), and timers_teardown().

◆ test_cyclic

Definition at line 44 of file test_timers.c.

Referenced by do_test_cyclic_timers().