ReactOS 0.4.16-dev-297-gc569aee
test_pbuf.c File Reference
#include "test_pbuf.h"
#include "lwip/pbuf.h"
#include "lwip/stats.h"
Include dependency graph for test_pbuf.c:

Go to the source code of this file.

Macros

#define TESTBUFSIZE_1   65535
 
#define TESTBUFSIZE_2   65530
 
#define TESTBUFSIZE_3   50050
 

Functions

static void pbuf_setup (void)
 
static void pbuf_teardown (void)
 
 START_TEST (test_pbuf_alloc_zero_pbufs)
 
END_TEST START_TEST (test_pbuf_copy_zero_pbuf)
 
END_TEST START_TEST (test_pbuf_copy_unmatched_chains)
 
END_TEST START_TEST (test_pbuf_copy_partial_pbuf)
 
END_TEST START_TEST (test_pbuf_split_64k_on_small_pbufs)
 
END_TEST START_TEST (test_pbuf_queueing_bigger_than_64k)
 
END_TEST START_TEST (test_pbuf_take_at_edge)
 
END_TEST START_TEST (test_pbuf_get_put_at_edge)
 
END_TEST Suite * pbuf_suite (void)
 

Variables

static u8_t testbuf_1 [TESTBUFSIZE_1]
 
static u8_t testbuf_1a [TESTBUFSIZE_1]
 
static u8_t testbuf_2 [TESTBUFSIZE_2]
 
static u8_t testbuf_2a [TESTBUFSIZE_2]
 
static u8_t testbuf_3 [TESTBUFSIZE_3]
 
static u8_t testbuf_3a [TESTBUFSIZE_3]
 

Macro Definition Documentation

◆ TESTBUFSIZE_1

#define TESTBUFSIZE_1   65535

Definition at line 28 of file test_pbuf.c.

◆ TESTBUFSIZE_2

#define TESTBUFSIZE_2   65530

Definition at line 29 of file test_pbuf.c.

◆ TESTBUFSIZE_3

#define TESTBUFSIZE_3   50050

Definition at line 30 of file test_pbuf.c.

Function Documentation

◆ pbuf_setup()

static void pbuf_setup ( void  )
static

Definition at line 16 of file test_pbuf.c.

17{
18 lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
19}
#define SKIP_POOL(x)
Definition: lwip_check.h:48
void lwip_check_ensure_no_alloc(unsigned int skip)

Referenced by pbuf_suite().

◆ pbuf_suite()

END_TEST Suite * pbuf_suite ( void  )

Create the suite including all tests for this module

Definition at line 346 of file test_pbuf.c.

347{
348 testfunc tests[] = {
349 TESTFUNC(test_pbuf_alloc_zero_pbufs),
350 TESTFUNC(test_pbuf_copy_zero_pbuf),
351 TESTFUNC(test_pbuf_copy_unmatched_chains),
352 TESTFUNC(test_pbuf_copy_partial_pbuf),
353 TESTFUNC(test_pbuf_split_64k_on_small_pbufs),
354 TESTFUNC(test_pbuf_queueing_bigger_than_64k),
355 TESTFUNC(test_pbuf_take_at_edge),
356 TESTFUNC(test_pbuf_get_put_at_edge)
357 };
358 return create_suite("PBUF", tests, sizeof(tests)/sizeof(testfunc), pbuf_setup, pbuf_teardown);
359}
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 pbuf_setup(void)
Definition: test_pbuf.c:16
static void pbuf_teardown(void)
Definition: test_pbuf.c:22

Referenced by main().

◆ pbuf_teardown()

static void pbuf_teardown ( void  )
static

Definition at line 22 of file test_pbuf.c.

23{
24 lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
25}

Referenced by pbuf_suite().

◆ START_TEST() [1/8]

START_TEST ( test_pbuf_alloc_zero_pbufs  )

Definition at line 39 of file test_pbuf.c.

40{
41 struct pbuf *p;
43
45 fail_unless(p != NULL);
46 if (p != NULL) {
47 pbuf_free(p);
48 }
49
51 fail_unless(p != NULL);
52 if (p != NULL) {
53 pbuf_free(p);
54 }
55
57 fail_unless(p != NULL);
58 if (p != NULL) {
59 pbuf_free(p);
60 }
61
63 fail_unless(p != NULL);
64 if (p != NULL) {
65 pbuf_free(p);
66 }
67}
#define NULL
Definition: types.h:112
GLfloat GLfloat p
Definition: glext.h:8902
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
Definition: pbuf.c:224
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:727
@ PBUF_ROM
Definition: pbuf.h:156
@ PBUF_RAM
Definition: pbuf.h:152
@ PBUF_REF
Definition: pbuf.h:160
@ PBUF_POOL
Definition: pbuf.h:167
@ PBUF_RAW
Definition: pbuf.h:111
Definition: pbuf.h:186

◆ START_TEST() [2/8]

END_TEST START_TEST ( test_pbuf_copy_partial_pbuf  )

Definition at line 148 of file test_pbuf.c.

149{
150 struct pbuf *a, *b, *dest;
151 char lwip[] = "lwip ";
152 char packet[] = "packet";
153 err_t err;
154 LWIP_UNUSED_ARG(_i);
155
157 fail_unless(a != NULL);
158 a->payload = lwip;
160 fail_unless(b != NULL);
161 b->payload = packet;
162 pbuf_cat(a, b);
164 memset(dest->payload, 0, dest->len);
165 fail_unless(dest != NULL);
166
167 /* Don't copy if data will not fit */
168 err = pbuf_copy_partial_pbuf(dest, a, a->tot_len, 4);
169 fail_unless(err == ERR_ARG);
170 /* Don't copy if length is longer than source */
171 err = pbuf_copy_partial_pbuf(dest, a, a->tot_len + 1, 0);
172 fail_unless(err == ERR_ARG);
173 /* Normal copy */
174 err = pbuf_copy_partial_pbuf(dest, a, a->tot_len, 0);
175 fail_unless(err == ERR_OK);
176 fail_unless(strcmp("lwip packet", (char*)dest->payload) == 0);
177 /* Copy at offset */
178 err = pbuf_copy_partial_pbuf(dest, a, a->tot_len, 1);
179 fail_unless(err == ERR_OK);
180 fail_unless(strcmp("llwip packet", (char*)dest->payload) == 0);
181 /* Copy at offset with shorter length */
183 fail_unless(err == ERR_OK);
184 fail_unless(strcmp("llwip lwip p", (char*)dest->payload) == 0);
185 /* Copy with shorter length */
187 fail_unless(err == ERR_OK);
188 fail_unless(strcmp("lwip lwip p", (char*)dest->payload) == 0);
189
191 pbuf_free(a);
192}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
s8_t err_t
Definition: err.h:96
@ ERR_OK
Definition: err.h:55
@ ERR_ARG
Definition: err.h:88
void pbuf_cat(struct pbuf *h, struct pbuf *t)
Definition: pbuf.c:855
err_t pbuf_copy_partial_pbuf(struct pbuf *p_to, const struct pbuf *p_from, u16_t copy_len, u16_t offset)
Definition: pbuf.c:986
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
static char * dest
Definition: rtl.c:135
#define err(...)
#define memset(x, y, z)
Definition: compat.h:39
Definition: dhcpd.h:135

◆ START_TEST() [3/8]

END_TEST START_TEST ( test_pbuf_copy_unmatched_chains  )

Call pbuf_copy on pbufs with chains of different sizes

Definition at line 100 of file test_pbuf.c.

101{
102 uint16_t i, j;
103 err_t err;
104 struct pbuf *source, *dest, *p;
105 LWIP_UNUSED_ARG(_i);
106
107 source = NULL;
108 /* Build source pbuf from linked 16 byte parts,
109 * with payload bytes containing their offset */
110 for (i = 0; i < 8; i++) {
112 fail_unless(p != NULL);
113 for (j = 0; j < p->len; j++) {
114 ((u8_t*)p->payload)[j] = (u8_t)((i << 4) | j);
115 }
116 if (source) {
117 pbuf_cat(source, p);
118 } else {
119 source = p;
120 }
121 }
122 for (i = 0; i < source->tot_len; i++) {
123 fail_unless(pbuf_get_at(source, i) == i);
124 }
125
126 /* Build dest pbuf from other lengths */
128 fail_unless(dest != NULL);
130 fail_unless(p != NULL);
131 pbuf_cat(dest, p);
133 fail_unless(p != NULL);
134 pbuf_cat(dest, p);
135
136 /* Copy contents and verify data */
138 fail_unless(err == ERR_OK);
139 for (i = 0; i < source->tot_len; i++) {
140 fail_unless(pbuf_get_at(dest, i) == i);
141 }
142
145}
unsigned short int uint16_t
Definition: acefiex.h:54
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
uint8_t u8_t
Definition: arch.h:125
u8_t pbuf_get_at(const struct pbuf *p, u16_t offset)
Definition: pbuf.c:1402
err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from)
Definition: pbuf.c:959

◆ START_TEST() [4/8]

END_TEST START_TEST ( test_pbuf_copy_zero_pbuf  )

Call pbuf_copy on a pbuf with zero length

Definition at line 71 of file test_pbuf.c.

72{
73 struct pbuf *p1, *p2, *p3;
74 err_t err;
76
77 p1 = pbuf_alloc(PBUF_RAW, 1024, PBUF_RAM);
78 fail_unless(p1 != NULL);
79 fail_unless(p1->ref == 1);
80
82 fail_unless(p2 != NULL);
83 fail_unless(p2->ref == 1);
84 p2->len = p2->tot_len = 0;
85
86 pbuf_cat(p1, p2);
87 fail_unless(p1->ref == 1);
88 fail_unless(p2->ref == 1);
89
91 err = pbuf_copy(p3, p1);
92 fail_unless(err == ERR_VAL);
93
94 pbuf_free(p1);
95 pbuf_free(p3);
96}
@ ERR_VAL
Definition: err.h:67
LWIP_PBUF_REF_T ref
Definition: pbuf.h:218
u16_t tot_len
Definition: pbuf.h:200
u16_t len
Definition: pbuf.h:203

◆ START_TEST() [5/8]

END_TEST START_TEST ( test_pbuf_get_put_at_edge  )

Definition at line 317 of file test_pbuf.c.

318{
319 u8_t *out;
320 u8_t testdata = 0x01;
321 u8_t getdata;
322 struct pbuf *p = pbuf_alloc(PBUF_RAW, 1024, PBUF_POOL);
323 struct pbuf *q = p->next;
324 LWIP_UNUSED_ARG(_i);
325 /* alloc big enough to get a chain of pbufs */
326 fail_if(p->tot_len == p->len);
327 memset(p->payload, 0, p->len);
328 memset(q->payload, 0, q->len);
329
330 /* put byte at the beginning of second pbuf */
331 pbuf_put_at(p, p->len, testdata);
332
333 out = (u8_t*)q->payload;
334 fail_unless(*out == testdata,
335 "Bad data at pos %d, was %02X, expected %02X", p->len, *out, testdata);
336
337 getdata = pbuf_get_at(p, p->len);
338 fail_unless(*out == getdata,
339 "pbuf_get_at() returned bad data at pos %d, was %02X, expected %02X", p->len, getdata, *out);
340 pbuf_free(p);
341}
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
void pbuf_put_at(struct pbuf *p, u16_t offset, u8_t data)
Definition: pbuf.c:1442
static FILE * out
Definition: regtests2xml.c:44
struct pbuf * next
Definition: pbuf.h:188

◆ START_TEST() [6/8]

END_TEST START_TEST ( test_pbuf_queueing_bigger_than_64k  )

Definition at line 207 of file test_pbuf.c.

208{
209 int i;
210 err_t err;
211 struct pbuf *p1, *p2, *p3, *rest2=NULL, *rest3=NULL;
212 LWIP_UNUSED_ARG(_i);
213
214 for(i = 0; i < TESTBUFSIZE_1; i++) {
215 testbuf_1[i] = (u8_t)rand();
216 }
217 for(i = 0; i < TESTBUFSIZE_2; i++) {
218 testbuf_2[i] = (u8_t)rand();
219 }
220 for(i = 0; i < TESTBUFSIZE_3; i++) {
221 testbuf_3[i] = (u8_t)rand();
222 }
223
225 fail_unless(p1 != NULL);
227 fail_unless(p2 != NULL);
229 fail_unless(p3 != NULL);
231 fail_unless(err == ERR_OK);
233 fail_unless(err == ERR_OK);
235 fail_unless(err == ERR_OK);
236
237 pbuf_cat(p1, p2);
238 pbuf_cat(p1, p3);
239
240 pbuf_split_64k(p1, &rest2);
241 fail_unless(p1->tot_len == TESTBUFSIZE_1);
242 fail_unless(rest2->tot_len == (u16_t)((TESTBUFSIZE_2+TESTBUFSIZE_3) & 0xFFFF));
243 pbuf_split_64k(rest2, &rest3);
244 fail_unless(rest2->tot_len == TESTBUFSIZE_2);
245 fail_unless(rest3->tot_len == TESTBUFSIZE_3);
246
253
254 pbuf_free(p1);
255 pbuf_free(rest2);
256 pbuf_free(rest3);
257}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
uint16_t u16_t
Definition: arch.h:127
u16_t pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:1058
err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
Definition: pbuf.c:1227
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
static u8_t testbuf_1a[TESTBUFSIZE_1]
Definition: test_pbuf.c:32
#define TESTBUFSIZE_3
Definition: test_pbuf.c:30
static u8_t testbuf_2[TESTBUFSIZE_2]
Definition: test_pbuf.c:33
#define TESTBUFSIZE_2
Definition: test_pbuf.c:29
static u8_t testbuf_1[TESTBUFSIZE_1]
Definition: test_pbuf.c:31
static u8_t testbuf_3a[TESTBUFSIZE_3]
Definition: test_pbuf.c:36
static u8_t testbuf_3[TESTBUFSIZE_3]
Definition: test_pbuf.c:35
#define TESTBUFSIZE_1
Definition: test_pbuf.c:28
static u8_t testbuf_2a[TESTBUFSIZE_2]
Definition: test_pbuf.c:34

◆ START_TEST() [7/8]

END_TEST START_TEST ( test_pbuf_split_64k_on_small_pbufs  )

Definition at line 195 of file test_pbuf.c.

196{
197 struct pbuf *p, *rest=NULL;
198 LWIP_UNUSED_ARG(_i);
199
201 pbuf_split_64k(p, &rest);
202 fail_unless(p->tot_len == 1);
203 pbuf_free(p);
204}

◆ START_TEST() [8/8]

END_TEST START_TEST ( test_pbuf_take_at_edge  )

Definition at line 264 of file test_pbuf.c.

265{
266 err_t res;
267 u8_t *out;
268 int i;
269 u8_t testdata[] = { 0x01, 0x08, 0x82, 0x02 };
270 struct pbuf *p = pbuf_alloc(PBUF_RAW, 1024, PBUF_POOL);
271 struct pbuf *q = p->next;
272 LWIP_UNUSED_ARG(_i);
273 /* alloc big enough to get a chain of pbufs */
274 fail_if(p->tot_len == p->len);
275 memset(p->payload, 0, p->len);
276 memset(q->payload, 0, q->len);
277
278 /* copy data to the beginning of first pbuf */
279 res = pbuf_take_at(p, &testdata, sizeof(testdata), 0);
280 fail_unless(res == ERR_OK);
281
282 out = (u8_t*)p->payload;
283 for (i = 0; i < (int)sizeof(testdata); i++) {
284 fail_unless(out[i] == testdata[i],
285 "Bad data at pos %d, was %02X, expected %02X", i, out[i], testdata[i]);
286 }
287
288 /* copy data to the just before end of first pbuf */
289 res = pbuf_take_at(p, &testdata, sizeof(testdata), p->len - 1);
290 fail_unless(res == ERR_OK);
291
292 out = (u8_t*)p->payload;
293 fail_unless(out[p->len - 1] == testdata[0],
294 "Bad data at pos %d, was %02X, expected %02X", p->len - 1, out[p->len - 1], testdata[0]);
295 out = (u8_t*)q->payload;
296 for (i = 1; i < (int)sizeof(testdata); i++) {
297 fail_unless(out[i-1] == testdata[i],
298 "Bad data at pos %d, was %02X, expected %02X", p->len - 1 + i, out[i-1], testdata[i]);
299 }
300
301 /* copy data to the beginning of second pbuf */
302 res = pbuf_take_at(p, &testdata, sizeof(testdata), p->len);
303 fail_unless(res == ERR_OK);
304
305 out = (u8_t*)p->payload;
306 for (i = 0; i < (int)sizeof(testdata); i++) {
307 fail_unless(out[i] == testdata[i],
308 "Bad data at pos %d, was %02X, expected %02X", p->len+i, out[i], testdata[i]);
309 }
310 pbuf_free(p);
311}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLuint res
Definition: glext.h:9613
err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:1271
#define for
Definition: utility.h:88

Variable Documentation

◆ testbuf_1

u8_t testbuf_1[TESTBUFSIZE_1]
static

Definition at line 31 of file test_pbuf.c.

Referenced by START_TEST().

◆ testbuf_1a

u8_t testbuf_1a[TESTBUFSIZE_1]
static

Definition at line 32 of file test_pbuf.c.

Referenced by START_TEST().

◆ testbuf_2

u8_t testbuf_2[TESTBUFSIZE_2]
static

Definition at line 33 of file test_pbuf.c.

Referenced by START_TEST().

◆ testbuf_2a

u8_t testbuf_2a[TESTBUFSIZE_2]
static

Definition at line 34 of file test_pbuf.c.

Referenced by START_TEST().

◆ testbuf_3

u8_t testbuf_3[TESTBUFSIZE_3]
static

Definition at line 35 of file test_pbuf.c.

Referenced by START_TEST().

◆ testbuf_3a

u8_t testbuf_3a[TESTBUFSIZE_3]
static

Definition at line 36 of file test_pbuf.c.

Referenced by START_TEST().