1 #include "tx_api.h"
2 #include "nx_api.h"
3 #include <time.h>
4
5 extern void test_control_return(UINT status);
6
7 #if defined __PRODUCT_NETXDUO__ && !defined NX_DISABLE_IPV4
8 #include "nxd_mdns.h"
9 #define DEMO_STACK_SIZE 2048
10 #define BUFFER_SIZE 10240
11
12 /* Define the ThreadX and NetX object control blocks... */
13
14 static TX_THREAD ntest_0;
15 static TX_THREAD ntest_1[5];
16 static TX_THREAD ntest_2[5];
17
18 static NX_PACKET_POOL pool_0;
19 static NX_IP ip_0;
20
21 /* Define the NetX MDNS object control blocks. */
22
23 static NX_MDNS mdns_0;
24 static TX_SEMAPHORE sema_0;
25 static UCHAR buffer[BUFFER_SIZE];
26 static ULONG current_buffer_size;
27 static UCHAR mdns_stack[DEMO_STACK_SIZE];
28 static ULONG buffer_org_head;
29 static ULONG buffer_org_tail;
30 static ULONG free_buffer_size;
31 static UINT cache_state;
32
33 /* Define the counters used in the test application... */
34
35 static ULONG error_counter;
36 static CHAR *pointer;
37
38 /* Define thread prototypes. */
39
40 static void ntest_0_entry(ULONG thread_input);
41 static void ntest_1_entry(ULONG thread_input);
42 static void ntest_2_entry(ULONG thread_input);
43 extern VOID _nx_ram_network_driver(NX_IP_DRIVER *driver_req_ptr);
44 static void check_empty_buffer(UCHAR *buffer_ptr, UINT buffer_size);
45 static void empty_buffer_init(UCHAR *buffer_ptr, UINT buffer_size);
46 static VOID cache_full_notify(NX_MDNS *mdns_ptr, UINT state, UINT cache_tye);
47
48 extern UINT _nx_mdns_cache_add_resource_record(NX_MDNS *mdns_ptr, UINT cache_type, NX_MDNS_RR *record_ptr, NX_MDNS_RR **insert_ptr, UCHAR *is_present, UINT interface_index);
49 extern UINT _nx_mdns_cache_delete_resource_record(NX_MDNS *mdns_ptr, UINT cache_type, NX_MDNS_RR *record_ptr);
50 extern UINT _nx_mdns_cache_add_string(NX_MDNS *mdns_ptr, UINT cache_type, VOID *string_ptr, UINT string_len, VOID **insert_ptr, UCHAR find_string, UCHAR add_name);
51 extern UINT _nx_mdns_cache_delete_string(NX_MDNS *mdns_ptr, UINT cache_type, VOID *string_ptr, UINT string_len);
52
53 /* Define what the initial system looks like. */
54
55 #ifdef CTEST
test_application_define(void * first_unused_memory)56 VOID test_application_define(void *first_unused_memory)
57 #else
58 void netx_mdns_internal_function_test(void *first_unused_memory)
59 #endif
60 {
61
62 UINT status;
63
64 /* Setup the working pointer. */
65 pointer = (CHAR *) first_unused_memory;
66 error_counter = 0;
67
68 /* Initialize the NetX system. */
69 nx_system_initialize();
70
71 /* Create a packet pool. */
72 status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 256, pointer, 8192);
73 pointer = pointer + 8192;
74
75 if(status)
76 error_counter++;
77
78 /* Create an IP instance. */
79 status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(1, 2, 3, 4), 0xFFFFFF00UL, &pool_0,
80 _nx_ram_network_driver, pointer, 2048, 1);
81 pointer = pointer + 2048;
82
83 if(status)
84 error_counter++;
85
86 /* Enable ARP and supply ARP cache memory for IP Instance 0. */
87 status = nx_arp_enable(&ip_0, (void *) pointer, 1024);
88 pointer = pointer + 1024;
89 if(status)
90 error_counter++;
91
92 /* Enable TCP processing for both IP instances. */
93 status = nx_tcp_enable(&ip_0);
94
95 /* Check TCP enable status. */
96 if(status)
97 error_counter++;
98
99 /* Enable UDP processing for both IP instances. */
100 status = nx_udp_enable(&ip_0);
101
102 /* Check UDP enable status. */
103 if(status)
104 error_counter++;
105
106 status = nx_igmp_enable(&ip_0);
107
108 /* Check status. */
109 if(status)
110 error_counter++;
111
112 /* Create semaphore. */
113 status = tx_semaphore_create(&sema_0, "SEMA 0", 0);
114
115 /* Check status. */
116 if(status)
117 error_counter++;
118
119 /* Create the test thread. */
120 tx_thread_create(&ntest_0, "thread 0", ntest_0_entry, (ULONG)(pointer + DEMO_STACK_SIZE),
121 pointer, DEMO_STACK_SIZE,
122 3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
123
124 pointer = pointer + DEMO_STACK_SIZE;
125 }
126
127
128 /* Define the test threads. */
129
ntest_0_entry(ULONG thread_input)130 static void ntest_0_entry(ULONG thread_input)
131 {
132 UINT status;
133 ULONG actual_status;
134 CHAR *pointer = (CHAR*)thread_input;
135 UINT i;
136 NX_MDNS_RR *last_inserted;
137 NX_MDNS_RR *inserted[3];
138 ULONG head;
139 NX_MDNS_RR rr[3];
140 UCHAR *last_inserted_string;
141 CHAR test_string[32];
142 UCHAR *inserted_strings[4];
143 CHAR *test_strings[] = {"First", "Second", "Third", "M"};
144 ULONG tail;
145 NX_MDNS_RR peer_rr;
146 UINT rr_count;
147 UCHAR *insert_ptr[30];
148 CHAR *cache_string[] = {
149 "Hello0",
150 "World0",
151 "Hello world0",
152 "Hello world00",
153 "Hello world000",
154 "Hello world0000",
155 "Hello world00000",
156 "Hello world000000",
157 "Hello world0000000",
158 "Hello world00000000",
159 "Hello world000000000",
160 "Hello world0000000000",
161 "Hello world00000000000",
162 "Hello world000000000000",
163 "Hello world0000000000000",
164 "Hello world00000000000000",
165 "Hello world000000000000000",
166 "Hello world0000000000000000",
167 "Hello world00000000000000000",
168 "Hello world00000000000000000000000000000000000000000000000000000000000000000111111111111111111111122222222222222"};
169
170
171 printf("NetX Test: MDNS Internal Function Test...............................");
172
173 /* Ensure the IP instance has been initialized. */
174 status = nx_ip_status_check(&ip_0, NX_IP_INITIALIZE_DONE, &actual_status, 100);
175
176 /* Check status. */
177 if(status != NX_SUCCESS)
178 {
179 printf("ERROR!\n");
180 test_control_return(1);
181 }
182
183 /* Set pointer. */
184 pointer = (CHAR*)thread_input;
185
186
187 /**********************************************************/
188 /* Test Local and Peer cache notify */
189 /**********************************************************/
190
191 /* Create a MDNS instance. */
192 memset(buffer, 0xFF, BUFFER_SIZE);
193 current_buffer_size = 512;
194 status = _nx_mdns_create(&mdns_0, &ip_0, &pool_0, 2, pointer, DEMO_STACK_SIZE, (UCHAR *)"NETX-MDNS",
195 buffer, current_buffer_size, buffer + current_buffer_size, current_buffer_size, NX_NULL);
196
197 pointer += DEMO_STACK_SIZE;
198
199 /* Cache notify test. */
200 status = _nx_mdns_cache_notify_set(&mdns_0, cache_full_notify);
201
202 /* Check status. */
203 if(status)
204 error_counter++;
205
206 #ifndef NX_MDNS_DISABLE_SERVER
207 /* Test the local buffer full notify. */
208 /* Loop to add string to local buffer until full. */
209 i = 0;
210 while(_nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL,
211 cache_string[i], strlen(cache_string[i]), (VOID **)&insert_ptr[i], NX_FALSE, NX_TRUE) == NX_SUCCESS)
212 {
213 i++;
214 }
215
216 /* Check the cache state. */
217 if (cache_state != 1)
218 error_counter++;
219
220 /* Deleted the strings. */
221 _nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, insert_ptr[0], 0);
222
223 /* Add the string. */
224 _nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, cache_string[i], strlen(cache_string[i]), (VOID **)&insert_ptr[i], NX_FALSE, NX_TRUE);
225
226 /* Check the cache state. */
227 if (cache_state != 1)
228 error_counter++;
229
230 /* Delete the string. */
231 _nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, insert_ptr[2], 0);
232
233 /* Add the string. */
234 _nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, cache_string[i], strlen(cache_string[i]), (VOID **)&insert_ptr[i], NX_FALSE, NX_TRUE);
235
236 /* Check the cache state. */
237 if (cache_state != 1)
238 error_counter++;
239
240 /* Delete the string. */
241 _nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, insert_ptr[4], 0);
242
243 /* Add the string. */
244 _nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, cache_string[i], strlen(cache_string[i]), (VOID **)&insert_ptr[i], NX_FALSE, NX_TRUE);
245
246 /* Check the cache state. */
247 if (cache_state != 1)
248 error_counter++;
249
250 /* Delete the string. */
251 _nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, insert_ptr[6], 0);
252
253 /* Add the string. */
254 _nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, cache_string[i], strlen(cache_string[i]), (VOID **)&insert_ptr[i], NX_FALSE, NX_TRUE);
255
256 /* Check the cache state. */
257 if (cache_state != 1)
258 error_counter++;
259
260 /* Delete the string. */
261 _nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, insert_ptr[8], 0);
262
263 /* Add the string. */
264 _nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, cache_string[i], strlen(cache_string[i]), (VOID **)&insert_ptr[i], NX_FALSE, NX_TRUE);
265
266 /* Check the cache state. */
267 if (cache_state != 2)
268 error_counter++;
269 #endif /* NX_MDNS_DISABLE_SERVER */
270
271 #ifndef NX_MDNS_DISABLE_CLIENT
272 /* Test the peer buffer full notify. */
273 /* Loop to add string to local buffer until full. */
274 i = 0;
275 while(_nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER,
276 cache_string[i], strlen(cache_string[i]), (VOID **)&insert_ptr[i], NX_FALSE, NX_TRUE) == NX_SUCCESS)
277 {
278 i++;
279 }
280
281 /* Check the cache state. */
282 if (cache_state != 1)
283 error_counter++;
284
285 /* Deleted the strings. */
286 _nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, insert_ptr[0], 0);
287
288 /* Add the string. */
289 _nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, cache_string[i], strlen(cache_string[i]), (VOID **)&insert_ptr[i], NX_FALSE, NX_TRUE);
290
291 /* Check the cache state. */
292 if (cache_state != 1)
293 error_counter++;
294
295 /* Delete the string. */
296 _nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, insert_ptr[2], 0);
297
298 /* Add the string. */
299 _nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, cache_string[i], strlen(cache_string[i]), (VOID **)&insert_ptr[i], NX_FALSE, NX_TRUE);
300
301 /* Check the cache state. */
302 if (cache_state != 1)
303 error_counter++;
304
305 /* Delete the string. */
306 _nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, insert_ptr[4], 0);
307
308 /* Add the string. */
309 _nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, cache_string[i], strlen(cache_string[i]), (VOID **)&insert_ptr[i], NX_FALSE, NX_TRUE);
310
311 /* Check the cache state. */
312 if (cache_state != 1)
313 error_counter++;
314
315 /* Delete the string. */
316 _nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, insert_ptr[6], 0);
317
318 /* Add the string. */
319 _nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, cache_string[i], strlen(cache_string[i]), (VOID **)&insert_ptr[i], NX_FALSE, NX_TRUE);
320
321 /* Check the cache state. */
322 if (cache_state != 1)
323 error_counter++;
324
325 /* Delete the string. */
326 _nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, insert_ptr[8], 0);
327
328 /* Add the string. */
329 _nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, cache_string[i], strlen(cache_string[i]), (VOID **)&insert_ptr[i], NX_FALSE, NX_TRUE);
330
331 /* Check the cache state. */
332 if (cache_state != 2)
333 error_counter++;
334 #endif /* NX_MDNS_DISABLE_CLIENT */
335
336 /* Delet the MDNS instance. */
337 _nx_mdns_delete(&mdns_0);
338
339 #ifndef NX_MDNS_DISABLE_SERVER
340 /**********************************************************/
341 /* Cache String Test */
342 /**********************************************************/
343
344 /* Basic string test. */
345 /* Initialize the buffer. */
346 current_buffer_size = 512;
347 memset(buffer, 0xFF, BUFFER_SIZE);
348 status = _nx_mdns_create(&mdns_0, &ip_0, &pool_0, 2, pointer, DEMO_STACK_SIZE, (UCHAR *)"NETX-MDNS",
349 buffer, current_buffer_size, buffer + current_buffer_size, current_buffer_size, NX_NULL);
350
351 pointer += DEMO_STACK_SIZE;
352
353 /* Check status. */
354 if(status)
355 error_counter++;
356
357 empty_buffer_init(buffer, current_buffer_size);
358
359 /* Create 5 threads to test string functions. */
360 for(i = 0; i < 5; i++)
361 {
362 tx_thread_create(&ntest_2[i], "thread 2", ntest_2_entry, i + 1,
363 pointer, DEMO_STACK_SIZE,
364 3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
365
366 pointer = pointer + DEMO_STACK_SIZE;
367 }
368
369 /* Wait until all threads finish. */
370 for(i = 0; i < 5; i++)
371 {
372 if(tx_semaphore_get(&sema_0, 5 * NX_IP_PERIODIC_RATE))
373 {
374 error_counter++;
375 break;
376 }
377 }
378
379 check_empty_buffer(buffer, current_buffer_size);
380 _nx_mdns_delete(&mdns_0);
381 #endif /* NX_MDNS_DISABLE_SERVER */
382
383
384 #ifndef NX_MDNS_DISABLE_CLIENT
385 /**********************************************************/
386 /* Function Test */
387 /**********************************************************/
388
389 /* Initialize random. */
390 srand((UINT)time(0));
391
392 /* Basic RR test. */
393 /* Create a MDNS instance. */
394 current_buffer_size = 512;
395 memset(buffer, 0xFF, BUFFER_SIZE);
396 status = _nx_mdns_create(&mdns_0, &ip_0, &pool_0, 2, pointer, DEMO_STACK_SIZE, (UCHAR *)"NETX-MDNS",
397 buffer, current_buffer_size, buffer + current_buffer_size, current_buffer_size, NX_NULL);
398
399 pointer += DEMO_STACK_SIZE;
400
401 /* Check status. */
402 if(status)
403 error_counter++;
404
405 empty_buffer_init(buffer + current_buffer_size, current_buffer_size);
406
407 /* Create 5 threads to test string functions. */
408 for(i = 0; i < 5; i++)
409 {
410 tx_thread_create(&ntest_1[i], "thread 1", ntest_1_entry, i + 1,
411 pointer, DEMO_STACK_SIZE,
412 3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
413
414 pointer = pointer + DEMO_STACK_SIZE;
415 }
416
417 /* Wait until all threads finish. */
418 for(i = 0; i < 5; i++)
419 {
420 if(tx_semaphore_get(&sema_0, 5 * NX_IP_PERIODIC_RATE))
421 {
422 error_counter++;
423 break;
424 }
425 }
426
427 check_empty_buffer(buffer + current_buffer_size, current_buffer_size);
428 _nx_mdns_delete(&mdns_0);
429 #endif /* NX_MDNS_DISABLE_CLIENT */
430
431
432 #ifndef NX_MDNS_DISABLE_SERVER
433 /**********************************************************/
434 /* Local Cache RR Test */
435 /**********************************************************/
436
437 /* RR full test. */
438 /* Initialize the buffer. */
439 current_buffer_size = BUFFER_SIZE >> 1;
440 memset(buffer, 0xFF, BUFFER_SIZE);
441 status = _nx_mdns_create(&mdns_0, &ip_0, &pool_0, 2, pointer, DEMO_STACK_SIZE, (UCHAR *)"NETX-MDNS",
442 buffer, current_buffer_size, buffer + current_buffer_size, current_buffer_size, NX_NULL);
443
444 pointer += DEMO_STACK_SIZE;
445
446 /* Check status. */
447 if(status)
448 error_counter++;
449
450 empty_buffer_init(buffer, current_buffer_size);
451
452 /* Loop to add resource record to local buffer until full. */
453 i = 0;
454 memset(&rr[0], 0, sizeof(NX_MDNS_RR));
455 do
456 {
457 rr[0].nx_mdns_rr_name = (UCHAR *)"test";
458 rr[0].nx_mdns_rr_type = NX_MDNS_RR_TYPE_A;
459 rr[0].nx_mdns_rr_class = (USHORT)i;
460 rr[0].nx_mdns_rr_ttl = i;
461 rr[0].nx_mdns_rr_rdata_length = (USHORT)i;
462 rr[0].nx_mdns_rr_timer_count = 0;
463 rr[0].nx_mdns_rr_retransmit_count = (UCHAR)(i + 1);
464 rr[0].nx_mdns_rr_state = NX_MDNS_RR_STATE_VALID;
465 i++;
466 }while(_nx_mdns_cache_add_resource_record(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL,
467 &rr[0], &last_inserted, NX_NULL, 0) == NX_SUCCESS);
468
469 i--;
470
471 /* HEAD and TAIL take 4 bytes each. */
472 if(i != (free_buffer_size / sizeof(NX_MDNS_RR)))
473 error_counter++;
474
475 /* Check mdns information. */
476 if(mdns_0.nx_mdns_local_rr_count != i)
477 error_counter++;
478 if(mdns_0.nx_mdns_local_string_count != 0)
479 error_counter++;
480 if(mdns_0.nx_mdns_local_string_bytes != 0)
481 error_counter++;
482
483 /* Delete all inserted resource records. */
484 while(i > 0)
485 {
486
487 /* Add it again. */
488 i--;
489 rr[0].nx_mdns_rr_name = (UCHAR *)"test";
490 rr[0].nx_mdns_rr_type = NX_MDNS_RR_TYPE_A;
491 rr[0].nx_mdns_rr_class = (USHORT)i;
492 rr[0].nx_mdns_rr_ttl = i;
493 rr[0].nx_mdns_rr_rdata_length = (USHORT)i;
494 rr[0].nx_mdns_rr_timer_count = 0;
495 rr[0].nx_mdns_rr_retransmit_count = (UCHAR)(i + 1);
496 rr[0].nx_mdns_rr_state = NX_MDNS_RR_STATE_VALID;
497
498 if(_nx_mdns_cache_add_resource_record(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL,
499 &rr[0], &last_inserted, NX_NULL, 0))
500 {
501
502 /* No error is expected. */
503 error_counter++;
504 break;
505 }
506
507 /* Check mdns information. */
508 if(mdns_0.nx_mdns_local_rr_count != i + 1)
509 error_counter++;
510
511 if(_nx_mdns_cache_delete_resource_record(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, last_inserted))
512 {
513
514 /* No error is expected. */
515 error_counter++;
516 break;
517 }
518
519 /* Check mdns information. */
520 if(mdns_0.nx_mdns_local_rr_count != i)
521 error_counter++;
522 }
523
524 check_empty_buffer(buffer, current_buffer_size);
525 _nx_mdns_delete(&mdns_0);
526
527
528 /* RR middle usage test. */
529 /* Initialize the buffer. */
530 current_buffer_size = BUFFER_SIZE >> 1;
531 memset(buffer, 0xFF, BUFFER_SIZE);
532 status = _nx_mdns_create(&mdns_0, &ip_0, &pool_0, 2, pointer, DEMO_STACK_SIZE, (UCHAR *)"NETX-MDNS",
533 buffer, current_buffer_size, buffer + current_buffer_size, current_buffer_size, NX_NULL);
534
535 pointer += DEMO_STACK_SIZE;
536
537 /* Check status. */
538 if(status)
539 error_counter++;
540
541 empty_buffer_init(buffer, current_buffer_size);
542
543 /* Initialize RRs. */
544 memset(&rr, 0, sizeof(rr));
545 for(i = 0; i < 3; i++)
546 {
547 rr[i].nx_mdns_rr_name = (UCHAR *)"test";
548 rr[i].nx_mdns_rr_type = NX_MDNS_RR_TYPE_A;
549 rr[i].nx_mdns_rr_class = (USHORT)i;
550 rr[i].nx_mdns_rr_ttl = i;
551 rr[i].nx_mdns_rr_rdata_length = (USHORT)i;
552 rr[i].nx_mdns_rr_timer_count = 0;
553 rr[i].nx_mdns_rr_retransmit_count = (UCHAR)(i + 1);
554 rr[i].nx_mdns_rr_state = NX_MDNS_RR_STATE_VALID;
555 }
556
557 /* Add two RRs. */
558 if(_nx_mdns_cache_add_resource_record(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, &rr[0], &inserted[0], NX_NULL, 0))
559 error_counter++;
560
561 if(_nx_mdns_cache_add_resource_record(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, &rr[1], &inserted[1], NX_NULL, 0))
562 error_counter++;
563
564 /* Store HEAD. */
565 head = *((ULONG*)buffer);
566
567 /* Delete the first resource record. */
568 if(_nx_mdns_cache_delete_resource_record(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, inserted[0]))
569 error_counter++;
570
571 /* Add the third RR. */
572 if(_nx_mdns_cache_add_resource_record(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, &rr[2], &inserted[2], NX_NULL, 0))
573 error_counter++;
574
575 /* Check HEAD. */
576 if(head != *((ULONG*)buffer))
577 error_counter++;
578
579 /* Delete all RRs. */
580 if(_nx_mdns_cache_delete_resource_record(&mdns_0,NX_MDNS_CACHE_TYPE_LOCAL, inserted[1]))
581 error_counter++;
582 if(_nx_mdns_cache_delete_resource_record(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, inserted[2]))
583 error_counter++;
584
585 check_empty_buffer(buffer, current_buffer_size);
586 _nx_mdns_delete(&mdns_0);
587 #endif /* NX_MDNS_DISABLE_SERVER */
588
589
590 #ifndef NX_MDNS_DISABLE_CLIENT
591 /**********************************************************/
592 /* Peer Cache RR Test */
593 /**********************************************************/
594
595 /* Create a MDNS instance. */
596 memset(buffer, 0xFF, BUFFER_SIZE);
597 current_buffer_size = 512;
598 status = _nx_mdns_create(&mdns_0, &ip_0, &pool_0, 2, pointer, DEMO_STACK_SIZE, (UCHAR *)"NETX-MDNS",
599 buffer, current_buffer_size, buffer + current_buffer_size, current_buffer_size, NX_NULL);
600
601 pointer += DEMO_STACK_SIZE;
602
603 /* Enable the MDNS function. */
604 _nx_mdns_enable(&mdns_0, 0);
605
606 /* Loop to add resource record to peer buffer. */
607 memset(&peer_rr, 0, sizeof(NX_MDNS_RR));
608 for (i = 0; i < 100; i++)
609 {
610 if(_nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, "test", strlen("test"), (VOID **)&(peer_rr.nx_mdns_rr_name), NX_FALSE, NX_TRUE))
611 error_counter++;
612 peer_rr.nx_mdns_rr_type = NX_MDNS_RR_TYPE_A;
613 peer_rr.nx_mdns_rr_class = (USHORT)i;
614 peer_rr.nx_mdns_rr_ttl = i;
615 peer_rr.nx_mdns_rr_rdata_length = (USHORT)i;
616 peer_rr.nx_mdns_rr_timer_count = 0;
617 peer_rr.nx_mdns_rr_retransmit_count = (UCHAR)(i + 1);
618 peer_rr.nx_mdns_rr_state = NX_MDNS_RR_STATE_VALID;
619 if (_nx_mdns_cache_add_resource_record(&mdns_0, NX_MDNS_CACHE_TYPE_PEER,
620 &peer_rr, &last_inserted, NX_NULL, 0))
621 error_counter++;
622
623 rr_count = (current_buffer_size - mdns_0.nx_mdns_peer_string_bytes - 2 * sizeof(ULONG)) / sizeof(NX_MDNS_RR);
624 if (i > (rr_count - 1))
625 {
626
627 /* Check mdns information. */
628 if(mdns_0.nx_mdns_peer_rr_count != rr_count)
629 error_counter++;
630 }
631 else
632 {
633
634 /* Check mdns information. */
635 if(mdns_0.nx_mdns_peer_rr_count != i + 1)
636 error_counter++;
637 }
638 }
639
640 if(_nx_mdns_cache_delete_resource_record(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, last_inserted))
641 {
642
643 /* No error is expected. */
644 error_counter++;
645 }
646
647 /* Check mdns information. */
648 if(mdns_0.nx_mdns_peer_rr_count != (rr_count - 1))
649 error_counter++;
650
651 /* Disable the MDNS function. */
652 _nx_mdns_disable(&mdns_0, 0);
653
654 /* Delet the MDNS instance. */
655 _nx_mdns_delete(&mdns_0);
656 #endif /* NX_MDNS_DISABLE_CLIENT */
657
658
659 #ifndef NX_MDNS_DISABLE_SERVER
660 /* String full test. */
661 /* Initialize the buffer. */
662 current_buffer_size = BUFFER_SIZE >> 1;
663 memset(buffer, 0xFF, BUFFER_SIZE);
664 status = _nx_mdns_create(&mdns_0, &ip_0, &pool_0, 2, pointer, DEMO_STACK_SIZE, (UCHAR *)"NETX-MDNS",
665 buffer, current_buffer_size, buffer + current_buffer_size, current_buffer_size, NX_NULL);
666
667 pointer += DEMO_STACK_SIZE;
668
669 /* Check status. */
670 if(status)
671 error_counter++;
672
673 empty_buffer_init(buffer, current_buffer_size);
674 /* Loop to add string to local buffer until full. */
675 i = 0;
676 sprintf(test_string, "%.15d", i);
677 while(_nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL,
678 test_string, 15, (VOID **)&last_inserted_string, NX_FALSE, NX_TRUE) == NX_SUCCESS)
679 {
680 i++;
681 sprintf(test_string, "%.15d", i);
682 }
683
684 /* HEAD and TAIL take 4 bytes each. Each string take 5 extra bytes. */
685 if(i != (free_buffer_size / 20))
686 error_counter++;
687
688 /* HEAD and TAIL take 4 bytes each. Each string take 5 extra bytes. */
689 if(i != (free_buffer_size / 20))
690 error_counter++;
691
692 if(mdns_0.nx_mdns_local_rr_count != 0)
693 error_counter++;
694 if(mdns_0.nx_mdns_local_string_count != i)
695 error_counter++;
696 if(mdns_0.nx_mdns_local_string_bytes != i * 20)
697 error_counter++;
698 /* Delete all inserted strings. */
699 while(i > 0)
700 {
701
702 /* Add it again. */
703 sprintf(test_string, "%.15d", i - 1);
704
705 if(_nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL,
706 test_string, 15, (VOID **)&last_inserted_string, NX_FALSE, NX_TRUE))
707 {
708
709 /* No error is expected. */
710 error_counter++;
711 break;
712 }
713
714 /* Check mdns information. */
715 if(mdns_0.nx_mdns_local_string_count != i)
716 error_counter++;
717 if(mdns_0.nx_mdns_local_string_bytes != i * 20)
718 error_counter++;
719
720 /* Delete the string twice. */
721 if(_nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, last_inserted_string, 0))
722 {
723
724 /* No error is expected. */
725 error_counter++;
726 break;
727 }
728 if(_nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, last_inserted_string, 0))
729 {
730
731 /* No error is expected. */
732 error_counter++;
733 break;
734 }
735
736 /* Check mdns information. */
737 if(mdns_0.nx_mdns_local_string_count != (i - 1))
738 error_counter++;
739 if(mdns_0.nx_mdns_local_string_bytes != (i - 1) * 20)
740 error_counter++;
741
742 i--;
743 }
744
745 check_empty_buffer(buffer, current_buffer_size);
746
747 _nx_mdns_delete(&mdns_0);
748
749 #endif /* NX_MDNS_DISABLE_SERVER */
750
751 #ifndef NX_MDNS_DISABLE_CLIENT
752
753 /* String full test. */
754 /* Initialize the buffer. */
755 current_buffer_size = BUFFER_SIZE >> 1;
756 memset(buffer, 0xFF, BUFFER_SIZE);
757 status = _nx_mdns_create(&mdns_0, &ip_0, &pool_0, 2, pointer, DEMO_STACK_SIZE, (UCHAR *)"NETX-MDNS",
758 buffer, current_buffer_size, buffer + current_buffer_size, current_buffer_size, NX_NULL);
759
760 pointer += DEMO_STACK_SIZE;
761
762 /* Check status. */
763 if(status)
764 error_counter++;
765
766 empty_buffer_init(buffer + current_buffer_size, current_buffer_size);
767
768 /* Loop to add string to peer buffer until full. */
769 i = 0;
770 sprintf(test_string, "%.15d", i);
771 while(_nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER,
772 test_string, 15, (VOID **)&last_inserted_string, NX_FALSE, NX_TRUE) == NX_SUCCESS)
773 {
774 i++;
775 sprintf(test_string, "%.15d", i);
776 }
777
778 /* HEAD and TAIL take 4 bytes each. Each string take 5 extra bytes. */
779 if(i != (free_buffer_size / 20))
780 error_counter++;
781
782 /* Check mdns information. */
783 if(mdns_0.nx_mdns_peer_rr_count != 0)
784 error_counter++;
785 if(mdns_0.nx_mdns_peer_string_count != i)
786 error_counter++;
787 if(mdns_0.nx_mdns_peer_string_bytes != i * 20)
788 error_counter++;
789
790 /* Delete all inserted strings. */
791 while(i > 0)
792 {
793
794 /* Add it again. */
795 sprintf(test_string, "%.15d", i - 1);
796
797 if(_nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER,
798 test_string, 15, (VOID **)&last_inserted_string, NX_FALSE, NX_TRUE))
799 {
800
801 /* No error is expected. */
802 error_counter++;
803 break;
804 }
805
806 /* Check mdns information. */
807 if(mdns_0.nx_mdns_peer_string_count != i)
808 error_counter++;
809 if(mdns_0.nx_mdns_peer_string_bytes != i * 20)
810 error_counter++;
811
812 /* Delete the string twice. */
813 if(_nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, last_inserted_string, 0))
814 {
815
816 /* No error is expected. */
817 error_counter++;
818 break;
819 }
820 if(_nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_PEER, last_inserted_string, 0))
821 {
822
823 /* No error is expected. */
824 error_counter++;
825 break;
826 }
827 /* Check mdns information. */
828 if(mdns_0.nx_mdns_peer_string_count != (i - 1))
829 error_counter++;
830 if(mdns_0.nx_mdns_peer_string_bytes != (i - 1) * 20)
831 error_counter++;
832
833 i--;
834 }
835
836 check_empty_buffer(buffer + current_buffer_size, current_buffer_size);
837
838 _nx_mdns_delete(&mdns_0);
839 #endif /* NX_MDNS_DISABLE_CLIENT */
840
841
842 #ifndef NX_MDNS_DISABLE_SERVER
843 /* String middle usage. */
844 /* Initialize the buffer. */
845 current_buffer_size = 512;
846 memset(buffer, 0xFF, BUFFER_SIZE);
847 status = _nx_mdns_create(&mdns_0, &ip_0, &pool_0, 2, pointer, DEMO_STACK_SIZE, (UCHAR *)"NETX-MDNS",
848 buffer, current_buffer_size, buffer + current_buffer_size, current_buffer_size, NX_NULL);
849
850 pointer += DEMO_STACK_SIZE;
851
852 /* Check status. */
853 if(status)
854 error_counter++;
855
856 empty_buffer_init(buffer, current_buffer_size);
857
858 /* Insert 3 strings. */
859 for(i = 0; i < 3; i++)
860 {
861 if(_nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL,
862 test_strings[i], strlen(test_strings[i]), (VOID **)&inserted_strings[i], NX_FALSE, NX_TRUE))
863 {
864
865 /* No error is expected. */
866 error_counter++;
867 break;
868 }
869 }
870
871 /* Store TAIL. */
872 tail = *((ULONG*)buffer + (current_buffer_size >> 2) - 1);
873
874 /* Delete the string in middle. */
875 if(_nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, inserted_strings[1], 0))
876 error_counter++;
877
878 /* Insert a string that is less than deleted one. */
879 if(_nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL,
880 test_strings[i], strlen(test_strings[i]), (VOID **)&inserted_strings[i], NX_FALSE, NX_TRUE))
881 error_counter++;
882
883 /* Check TAIL. */
884 if(tail != *((ULONG*)buffer + (current_buffer_size >> 2) - 1))
885 error_counter++;
886
887 /* Deleted all strings. */
888 for(i = 0; i < 4; i++)
889 _nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, inserted_strings[i], 0);
890
891 check_empty_buffer(buffer, current_buffer_size);
892 _nx_mdns_delete(&mdns_0);
893 #endif /* NX_MDNS_DISABLE_SERVER */
894
895
896 /* Determine if the test was successful. */
897 if(error_counter)
898 {
899 printf("ERROR!\n");
900 test_control_return(1);
901 }
902 else
903 {
904 printf("SUCCESS!\n");
905 test_control_return(0);
906 }
907 }
908
909
ntest_1_entry(ULONG thread_input)910 static void ntest_1_entry(ULONG thread_input)
911 {
912 CHAR *test_strings[] = {
913 "1",
914 "a",
915 "b",
916 "c",
917 "MDNS",
918 "Hello world0",
919 "Hello world1",
920 "Hello world1 Hello",
921 "Hello hello Hello",
922 "Hello Hello Hello Hello",
923 "abcdefghijklmnopqrstuvwxyz",
924 "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
925 };
926 UINT string_count= sizeof(test_strings) / sizeof(CHAR*);
927 INT loop_count = 1000;
928 UINT add_count;
929 NX_MDNS_RR rr[5];
930 NX_MDNS_RR *inserted_rr[5];
931 UCHAR *inserted_strings[5];
932 UINT index;
933
934
935
936 /* Loop 1000 times to add and delete strings */
937 while(loop_count > 0)
938 {
939 if ((loop_count == 0x00000232) &&
940 (thread_input == 1))
941 thread_input = thread_input;
942
943 if ((loop_count == 0x00000235) &&
944 (thread_input == 5))
945 thread_input = thread_input;
946
947 /* Initialize variables. */
948 add_count = 0;
949 memset(rr, 0, sizeof(rr));
950 memset(inserted_strings, 0, sizeof(inserted_strings));
951 memset(inserted_rr, 0, sizeof(inserted_strings));
952
953 /* Insert records. */
954 while(add_count < thread_input)
955 {
956
957 tx_mutex_get(&mdns_0.nx_mdns_mutex, TX_WAIT_FOREVER);
958 if(add_count & 1)
959 {
960
961 /* Insert same RR when add_count is odd. */
962 memcpy(&rr[add_count], &rr[add_count - 1], sizeof(NX_MDNS_RR));
963 if(rr[add_count].nx_mdns_rr_name)
964 {
965 if(_nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL,
966 test_strings[index], strlen(test_strings[index]), (VOID **)&rr[add_count].nx_mdns_rr_name, NX_FALSE, NX_TRUE) == NX_SUCCESS)
967 {
968 inserted_strings[add_count] = rr[add_count].nx_mdns_rr_name;
969
970 /* Insert rr. */
971 if(_nx_mdns_cache_add_resource_record(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL,
972 &rr[add_count], &inserted_rr[add_count], NX_NULL, 0))
973 _nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, inserted_strings[add_count], 0);
974
975 }
976 }
977 }
978 else
979 {
980 index = rand() % string_count;
981 if(_nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL,
982 test_strings[index], strlen(test_strings[index]), (VOID **)&rr[add_count].nx_mdns_rr_name, NX_FALSE, NX_TRUE) == NX_SUCCESS)
983 {
984
985 /* Set random values. */
986 inserted_strings[add_count] = rr[add_count].nx_mdns_rr_name;
987 rr[add_count].nx_mdns_rr_type = NX_MDNS_RR_TYPE_A;
988 rr[add_count].nx_mdns_rr_class = (USHORT)thread_input;
989 rr[add_count].nx_mdns_rr_ttl = add_count + 100;
990 rr[add_count].nx_mdns_rr_rdata_length = rand() % 0xFFFF;
991 rr[add_count].nx_mdns_rr_timer_count = 0;
992 rr[add_count].nx_mdns_rr_retransmit_count = (UCHAR)(rand() % 0xFFFF);
993 rr[add_count].nx_mdns_rr_state = NX_MDNS_RR_STATE_VALID;
994
995 /* Insert rr. */
996 if(_nx_mdns_cache_add_resource_record(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL,
997 &rr[add_count], &inserted_rr[add_count], NX_NULL, 0))
998 _nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, inserted_strings[add_count], 0);
999
1000 }
1001 }
1002
1003 add_count++;
1004 loop_count--;
1005 tx_mutex_put(&mdns_0.nx_mdns_mutex);
1006 tx_thread_relinquish();
1007
1008 }
1009
1010 /* Delete all inserted strings and records. */
1011 while(add_count--)
1012 {
1013
1014 /* No error is expected. */
1015 tx_mutex_get(&mdns_0.nx_mdns_mutex, TX_WAIT_FOREVER);
1016 if ((inserted_rr[add_count]) && (inserted_rr[add_count] -> nx_mdns_rr_name))
1017 {
1018 _nx_mdns_cache_delete_resource_record(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, inserted_rr[add_count]);
1019 }
1020 tx_mutex_put(&mdns_0.nx_mdns_mutex);
1021 tx_thread_relinquish();
1022 }
1023 }
1024 tx_semaphore_put(&sema_0);
1025
1026 }
1027
1028
ntest_2_entry(ULONG thread_input)1029 static void ntest_2_entry(ULONG thread_input)
1030 {
1031 CHAR *test_strings[] = {
1032 "1",
1033 "a",
1034 "b",
1035 "c",
1036 "MDNS",
1037 "Hello world0",
1038 "Hello world1",
1039 "Hello world1 Hello",
1040 "Hello hello Hello",
1041 "Hello Hello Hello Hello",
1042 "abcdefghijklmnopqrstuvwxyz",
1043 "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
1044 };
1045 UINT string_count= sizeof(test_strings) / sizeof(CHAR*);
1046 INT loop_count = 1000;
1047 UINT add_count;
1048 UCHAR *inserted_strings[5];
1049 UINT index;
1050
1051 /* Loop 1000 times to add and delete strings */
1052 while(loop_count > 0)
1053 {
1054
1055 /* Initialize variables. */
1056 add_count = 0;
1057 memset(inserted_strings, 0, sizeof(inserted_strings));
1058
1059 /* Insert strings. */
1060 while(add_count < thread_input)
1061 {
1062 index = rand() % string_count;
1063 tx_mutex_get(&mdns_0.nx_mdns_mutex, TX_WAIT_FOREVER);
1064 if(_nx_mdns_cache_add_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL,
1065 test_strings[index], strlen(test_strings[index]), (VOID **)&inserted_strings[add_count], NX_FALSE, NX_TRUE))
1066 {
1067
1068 /* Only the last string exceed the buffer. */
1069 if(index != (string_count - 1))
1070 {
1071 tx_mutex_put(&mdns_0.nx_mdns_mutex);
1072 error_counter++;
1073 tx_semaphore_put(&sema_0);
1074 return;
1075 }
1076 }
1077 else
1078 {
1079 add_count++;
1080 loop_count--;
1081 }
1082 tx_mutex_put(&mdns_0.nx_mdns_mutex);
1083 tx_thread_relinquish();
1084 }
1085
1086 /* Delete all inserted strings. */
1087 while(add_count--)
1088 {
1089
1090 /* No error is expected. */
1091 tx_mutex_get(&mdns_0.nx_mdns_mutex, TX_WAIT_FOREVER);
1092 if(_nx_mdns_cache_delete_string(&mdns_0, NX_MDNS_CACHE_TYPE_LOCAL, inserted_strings[add_count], 0))
1093 {
1094 tx_mutex_put(&mdns_0.nx_mdns_mutex);
1095 error_counter++;
1096 tx_semaphore_put(&sema_0);
1097 return;
1098 }
1099 tx_mutex_put(&mdns_0.nx_mdns_mutex);
1100 tx_thread_relinquish();
1101 }
1102 }
1103
1104 tx_semaphore_put(&sema_0);
1105 }
1106
1107
cache_full_notify(NX_MDNS * mdns_ptr,UINT state,UINT cache_type)1108 VOID cache_full_notify(NX_MDNS *mdns_ptr, UINT state, UINT cache_type)
1109 {
1110
1111 switch(state)
1112 {
1113 case NX_MDNS_CACHE_STATE_FULL:
1114 {
1115
1116 cache_state = 1;
1117 break;
1118 }
1119 case NX_MDNS_CACHE_STATE_FRAGMENTED:
1120 {
1121 cache_state = 2;
1122 break;
1123 }
1124 default:
1125 {
1126 cache_state = 0;
1127 break;
1128 }
1129 }
1130 }
1131
check_empty_buffer(UCHAR * buffer_ptr,UINT buffer_size)1132 static void check_empty_buffer(UCHAR *buffer_ptr, UINT buffer_size)
1133 {
1134
1135 ULONG *tail, *head;
1136 UINT i;
1137
1138 /* Check the head of buffer. */
1139 head = (ULONG*)buffer_ptr;
1140 if(*head != buffer_org_head)
1141 error_counter++;
1142
1143 /* Check the tail of buffer. */
1144 /* Since all strings are deleted, tail should pointer to the end of buffer. */
1145 tail = (ULONG*)buffer_ptr + (buffer_size >> 2) - 1;
1146 if(*tail != buffer_org_tail)
1147 error_counter++;
1148
1149 /* Check buffer overflow. */
1150 for(i = (buffer_size << 1); i < buffer_size; i++)
1151 {
1152 if(buffer_ptr[i] != 0xFF)
1153 {
1154 error_counter++;
1155 break;
1156 }
1157 }
1158 }
1159
empty_buffer_init(UCHAR * buffer_ptr,UINT buffer_size)1160 static void empty_buffer_init(UCHAR *buffer_ptr, UINT buffer_size)
1161 {
1162 ULONG *tail, *head;
1163
1164 head = (ULONG*)buffer_ptr;
1165 buffer_org_head = *head;
1166
1167 tail = (ULONG*)buffer_ptr + (buffer_size >> 2) - 1;
1168 buffer_org_tail = *tail;
1169
1170 free_buffer_size = buffer_org_tail - buffer_org_head;
1171 }
1172 #else
1173 #ifdef CTEST
test_application_define(void * first_unused_memory)1174 VOID test_application_define(void *first_unused_memory)
1175 #else
1176 void netx_mdns_internal_function_test(void *first_unused_memory)
1177 #endif
1178 {
1179 printf("NetX Test: MDNS Internal Function Test...............................N/A\n");
1180 test_control_return(3);
1181 }
1182 #endif
1183