use strbuff instead of str_buff & str_idx
[build-config.git] / src / config / lxrgmr-code / AQStack_test.c
blob641311fc077c76e927521ee0d055e5456b1fba37
1 /************************************************************************
2 * libcxt Project
4 * (c) Copyright 2021, devenkong(18151155@qq.com), Hangzhou, China
5 * (c) Copyright 2021, devenkong(18151155@qq.com), º¼ÖÝ, Öйú
6 ************************************************************************
7 * filename: QStack_test.c
8 * function: QStackÄ£¿é²âÊÔ³ÌÐò¡£
9 * createdate: 2023-06-13
10 * author: devenkong(18151155@qq.com)
11 * \note:: test for AQStack module.
12 * @ StackTesting(): general 8/16/32/64 bit stack testing.
13 * @ StackTesting(): general 8/16/32/64 bit queue testing.
14 * @ StackTesting(): general N byte stack testing.
15 * @ StackTesting(): general N byte queue testing.
16 * @ StackTesting(): general stack boundary testing.
17 * @ StackTesting(): general queue boundary testing.
18 * @ StackTesting(): EnQueue over-loop testing.
19 * @ StackTesting(): general Array(Index/Memcpy) testing.
20 * @ StackTesting(): general GetHeadData/GetTailData/CheckSum/HeadSubTail/
21 * Average/SignedAverage testing.
22 * @ Clear/IsEmpty/IsFull/GetBuffSize/ValidCnt/BlankCnt testing.
23 ************************************************************************/
24 /* Modify record */
25 /************************************************************************
26 * date: 2021-05-01
27 * author: devenkong(18151155@qq.com)
28 * note:
30 ----------------------------------------------------------------------
31 Version-Date------Author-----Explanation
32 ----------------------------------------------------------------------
33 1.00 06-12-06 ¿×µÂ·å QueueµÚÒ»°æ
34 1.01 08-12-01 ¿×µÂ·å Ôö¼ÓÁËQueueValideCnt
35 1.02 20-05-30 ¿×µÂ·å ÓÃÓÚlinuxÇý¶¯
36 1.03 21-04-23 ¿×µÂ·å Ìí¼Óstack¹¦ÄÜ£¬¶ÓÁÐÊý¾Ý²Ù×÷·Ö³É8/16/32bitÒÔ¼°N×Ö½Ú²Ù×÷
37 1.04 21-05-01 ¿×µÂ·å ½«Queue,StackºÍArray¹¦ÄÜÌí¼Óµ½QStack,²¢·Ö±ð¿ÉʹÓÃÔ­ÓнӿÚÃû³Æ.
38 ----------------------------------------------------------------------
39 ************************************************************************/
42 * TBD:
43 * @ UnDeQueue() testing.
44 * @ create opr func & opr size struct, operating data by specified size type.
48 Ä£¿éÒýÈ뺯Êý£º
53 Êý¾Ý½Ó¿Ú£º
57 /*******************************
58 *******************************
59 * 1. Include Files
60 *******************************
61 *******************************/
62 #define MODULE_NAME MODULE_CLASS_SYSLIB
63 #define DATA_TYPE 4
66 /* System include files */
67 #include "type.h"
70 /* Project module include files */
71 #include "AQStack.h"
73 #ifdef MUL_TASK
74 #include <stdio.h>
75 #include <stdlib.h>
76 #include <memory.h>
77 #endif
79 #ifdef LINUX
80 //#include "System/Thread/Thread.h"
81 #endif
84 /* Private include files */
86 /* дÔÚÍ·ÎļþÒýÓõÄ×îºó£¬ÒÔÃâ¸úÄÚºËÍ·ÎļþµÄ¶¨ÒåÓгåÍ» */
87 //#include "type.h"
90 /*******************************
91 *******************************
92 * 2. Global Variables &
93 * Micro Defines &
94 * Type Defines &
95 * Type Proto
96 *******************************
97 *******************************/
100 /*******************************
101 *******************************
102 * 3. Private Functions Implement
103 *******************************
104 *******************************/
108 /*******************************
109 *******************************
110 * 4. Public Functions Implement
111 *******************************
112 *******************************/
114 #ifdef TESTING
116 XXX(QStack_Testing);
118 #define TEST_BUFF_SIZE 256
119 static volatile uint8 gau8QStackTestingBuf[TEST_BUFF_SIZE];
120 static QSTACK gstTestingQStack;
121 uint8 Buff[100]={0x00, 0x01, 0x02, 0x03, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15};
123 #endif
125 #ifdef TESTING
127 static char *OprTypeName[] = {
128 "OPR_UINT8",
129 "OPR_UINT16",
130 "OPR_UINT32",
131 "OPR_UINT64",
134 uint32 ForeachBuffPrint (QSTACK *pstQStack, int i, void * pvData)
136 if (i&0xF)
137 printf("%02x ", pvData);
138 else
139 printf("%02x\n", pvData);
141 return 0;
144 void AQStkBuffPrint (QSTACK *pstAQStk)
146 QStackIF_Foreach(pstAQStk, ForeachBuffPrint);
148 return;
151 void AQStkCtxPrint (QSTACK *pstAQStk)
153 printf("buffer=0x%08x, size=%d;\n", pstAQStk.buffer, pstAQStk.size);
154 printf("count=%d, head=%d, tail=%d;\n", pstAQStk.count, pstAQStk.head, pstAQStk.tail);
155 printf("opr->type = %s;\n", OprTypeName[pstAQStk.opr->type & 0x03]);
156 printf("len=%d, mask=0x%08x;\n", pstAQStk.opr->len, pstAQStk.opr->mask);
157 printf("pfnGet = 0x%08x, pfnSet = 0x%08x;\n", pstAQStk.opr->pfnGet, pstAQStk.opr->pfnSet);
159 return;
163 * note:: testing for functions:
164 * @ QStackIF_InitStack()
165 * @ QStackIF_SetDataOprType()
166 * @ QStackIF_Push()
167 * @ QStackIF_Pop()
169 void Stack_testing (int type)
171 int i = 0;
172 CPU_UINT cpuData = 0x1122334455667788;
173 int cnt;
175 printf("=======================================\n");
176 printf("= Stack_testing(%s).\n", OprTypeName[type&0x03]);
177 printf("=======================================\n");
178 printf("= init stack.\n");
179 QStackIF_InitStack(&gstTestingQStack, (char *)&gau8QStackTestingBuf, TEST_BUFF_SIZE);
180 printf("= set data opr type.\n");
181 QStackIF_SetDataOprType(type);
183 if (type == OPR_UINT8)
184 cnt = TEST_BUFF_SIZE;
185 else if (type == OPR_UINT16)
186 cnt = TEST_BUFF_SIZE>>1;
187 else if (type == OPR_UINT32)
188 cnt = TEST_BUFF_SIZE>>2;
189 else if (type == OPR_UINT64)
190 cnt = TEST_BUFF_SIZE>>3;
191 cnt += 2;
193 printf("=======================================\n");
194 printf("Push() %d num of data\n", cnt);
195 for (i=0; i<cnt; i++)
197 cpuData = (cpuData & ~0xFF) + i;
198 printf("===== %03d.Push(%d)", i, cpuData & pstAQStk->opr->mask);
199 if (QStackIF_Push (&gstTestingQStack, cpuData) == false)
200 printf("false\n");
201 else
202 printf("\n");
203 AQStkCtxPrint(&gstTestingQStack);
206 printf("Pop() %d num of data\n", cnt);
207 for (i=0; i<cnt; i++)
209 cpuData = (cpuData & ~0xFF) + i;
210 printf("===== %03d.Pop(%d)", i, cpuData & pstAQStk->opr->mask);
211 if (QStackIF_Pop (&gstTestingQStack, cpuData) == false)
212 printf("false\n");
213 else
214 printf("\n");
215 AQStkCtxPrint(&gstTestingQStack);
220 * note:: testing for functions:
221 * @ QStackIF_InitQueue()
222 * @ QStackIF_SetDataOprType()
223 * @ QStackIF_EnQueue()
224 * @ QStackIF_DeQueue()
225 * @ QStackIF_UnDeQueue()
227 void Queue_testing (int type)
229 int i = 0;
230 CPU_UINT cpuData = 0x1122334455667788;
231 int cnt;
233 printf("=======================================\n");
234 printf("= Queue_testing(%s).\n", OprTypeName[type&0x03]);
235 printf("=======================================\n");
236 printf("= init queue.\n");
237 QStackIF_InitQueue(&gstTestingQStack, (char *)&gau8QStackTestingBuf, TEST_BUFF_SIZE);
238 printf("= set data opr type.\n");
239 QStackIF_SetDataOprType(type);
241 if (type == OPR_UINT8)
242 cnt = TEST_BUFF_SIZE;
243 else if (type == OPR_UINT16)
244 cnt = TEST_BUFF_SIZE>>1;
245 else if (type == OPR_UINT32)
246 cnt = TEST_BUFF_SIZE>>2;
247 else if (type == OPR_UINT64)
248 cnt = TEST_BUFF_SIZE>>3;
249 cnt += 2;
251 printf("=======================================\n");
252 printf("EnQueue() %d num of data\n", cnt);
253 for (i=0; i<cnt; i++)
255 cpuData = (cpuData & ~0xFF) + i;
256 printf("===== %03d.EnQueue(%d)", i, cpuData & pstAQStk->opr->mask);
257 if (QStackIF_EnQueue (&gstTestingQStack, cpuData) == false)
258 printf("false\n");
259 else
260 printf("\n");
261 AQStkCtxPrint(&gstTestingQStack);
264 printf("DeQueue() %d num of data\n", cnt);
265 for (i=0; i<cnt; i++)
267 cpuData = (cpuData & ~0xFF) + i;
268 printf("===== %03d.DeQueue(%d)", i, cpuData & pstAQStk->opr->mask);
269 if (QStackIF_DeQueue (&gstTestingQStack, cpuData) == false)
270 printf("false\n");
271 else
272 printf("\n");
273 AQStkCtxPrint(&gstTestingQStack);
276 printf("UnDeQueue() %d num of data\n", cnt);
277 for (i=0; i<cnt; i++)
279 cpuData = (cpuData & ~0xFF) + i;
280 printf("===== %03d.UnDeQueue(%d)", i, cpuData & pstAQStk->opr->mask);
281 if (QStackIF_DeQueue (&gstTestingQStack, cpuData) == false)
282 printf("false\n");
283 else
284 printf("\n");
285 AQStkCtxPrint(&gstTestingQStack);
288 printf("DeQueue() %d num of data\n", cnt);
289 for (i=0; i<cnt; i++)
291 cpuData = (cpuData & ~0xFF) + i;
292 printf("===== %03d.DeQueue(%d)", i, cpuData & pstAQStk->opr->mask);
293 if (QStackIF_DeQueue (&gstTestingQStack, cpuData) == false)
294 printf("false\n");
295 else
296 printf("\n");
297 AQStkCtxPrint(&gstTestingQStack);
300 printf("pay attension on the sequence of DeQueue data.\n");
303 void StackN_testing (void)
305 int i = 0;
306 CPU_UINT cpuData = 0x1122334455667788;
307 int cnt;
309 printf("=======================================\n");
310 printf("= Queue_testing(%s).\n", OprTypeName[type&0x03]);
311 printf("=======================================\n");
312 printf("= init queue.\n");
313 QStackIF_InitQueue(&gstTestingQStack, (char *)&gau8QStackTestingBuf, TEST_BUFF_SIZE);
314 printf("= set data opr type.\n");
315 QStackIF_SetDataOprType(type);
317 printf("=======================================\n");
318 printf("EnQueueN() %d bytes data.\n", cnt);
320 for (i=0; i<200; i++)
322 QStackIF_PushN (&gstTestingQStack, &Buff[0], 20);
323 memset(Buff, 0xaa, 100);
324 QStackIF_PopN (&gstTestingQStack, &Buff[0], 6);
325 QStackIF_PopN (&gstTestingQStack, &Buff[6], 14);
327 DbgOutBuff(i, Buff, 20);
329 return;
332 void QueueN_testing (void)
334 int i = 0;
335 CPU_UINT cpuData = 0x1122334455667788;
336 int cnt;
338 printf("=======================================\n");
339 printf("= Queue_testing(%s).\n", OprTypeName[type&0x03]);
340 printf("=======================================\n");
341 printf("= init queue.\n");
342 QStackIF_InitQueue(&gstTestingQStack, (char *)&gau8QStackTestingBuf, TEST_BUFF_SIZE);
343 printf("= set data opr type.\n");
344 QStackIF_SetDataOprType(type);
346 printf("=======================================\n");
347 printf("EnQueueN() %d bytes data.\n", cnt);
349 for (i=0; i<200; i++)
351 QStackIF_EnQueueN (&gstTestingQStack, &Buff[0], 20);
352 memset(Buff, 0xaa, 100);
353 QStackIF_DeQueueN (&gstTestingQStack, &Buff[0], 6);
354 QStackIF_DeQueueN (&gstTestingQStack, &Buff[6], 14);
356 DbgOutBuff(i, Buff, 20);
360 void QueueOverLoop_testing (int type)
362 int i = 0;
363 CPU_UINT cpuData = 0x1122334455667788;
364 int cnt;
366 printf("=======================================\n");
367 printf("= Queue_testing(%s).\n", OprTypeName[type&0x03]);
368 printf("=======================================\n");
369 printf("= init queue.\n");
370 QStackIF_InitQueue(&gstTestingQStack, (char *)&gau8QStackTestingBuf, TEST_BUFF_SIZE);
371 printf("= set data opr type.\n");
372 QStackIF_SetDataOprType(type);
374 if (type == OPR_UINT8)
375 cnt = TEST_BUFF_SIZE;
376 else if (type == OPR_UINT16)
377 cnt = TEST_BUFF_SIZE>>1;
378 else if (type == OPR_UINT32)
379 cnt = TEST_BUFF_SIZE>>2;
380 else if (type == OPR_UINT64)
381 cnt = TEST_BUFF_SIZE>>3;
382 cnt += 2;
384 printf("=======================================\n");
385 printf("EnQueue() %d num of data\n", cnt);
386 for (i=0; i<cnt; i++)
388 cpuData = (cpuData & ~0xFF) + i;
389 printf("===== %03d.EnQueue(%d)", i, cpuData & pstAQStk->opr->mask);
390 if (QStackIF_EnQueue (&gstTestingQStack, cpuData) == false)
391 printf("false\n");
392 else
393 printf("\n");
394 AQStkCtxPrint(&gstTestingQStack);
397 /* Index Read/Write */
399 /* MemCpy From Mem/Array to Array/Mem */
401 return;
404 void Array_testing (int type)
406 printf("=======================================\n");
407 printf("= Queue_testing(%s).\n", OprTypeName[type&0x03]);
408 printf("=======================================\n");
409 printf("= init queue.\n");
410 QStackIF_InitQueue(&gstTestingQStack, (char *)&gau8QStackTestingBuf, TEST_BUFF_SIZE);
411 printf("= set data opr type.\n");
412 QStackIF_SetDataOprType(type);
414 if (type == OPR_UINT8)
415 cnt = TEST_BUFF_SIZE;
416 else if (type == OPR_UINT16)
417 cnt = TEST_BUFF_SIZE>>1;
418 else if (type == OPR_UINT32)
419 cnt = TEST_BUFF_SIZE>>2;
420 else if (type == OPR_UINT64)
421 cnt = TEST_BUFF_SIZE>>3;
422 cnt += 2;
424 printf("=======================================\n");
425 printf("IndexWrite() %d num of data\n", cnt);
426 for (i=0; i<cnt; i++)
428 cpuData = (cpuData & ~0xFF) + i;
429 printf("===== %03d.IndexWrite(%d)", i, cpuData & pstAQStk->opr->mask);
430 if (QStackIF_EnQueue (&gstTestingQStack, cpuData) == false)
431 printf("false\n");
432 else
433 printf("\n");
434 AQStkCtxPrint(&gstTestingQStack);
437 /* Index Read/Write */
439 /* MemCpy From Mem/Array to Array/Mem */
441 return;
444 void CalcFunc_testing (int type)
446 int i = 0;
447 CPU_UINT cpuData = 0x1122334455667788;
448 int cnt;
450 printf("=======================================\n");
451 printf("= Queue_testing(%s).\n", OprTypeName[type&0x03]);
452 printf("=======================================\n");
453 printf("= init queue.\n");
454 QStackIF_InitQueue(&gstTestingQStack, (char *)&gau8QStackTestingBuf, TEST_BUFF_SIZE);
455 printf("= set data opr type.\n");
456 QStackIF_SetDataOprType(type);
458 if (type == OPR_UINT8)
459 cnt = TEST_BUFF_SIZE;
460 else if (type == OPR_UINT16)
461 cnt = TEST_BUFF_SIZE>>1;
462 else if (type == OPR_UINT32)
463 cnt = TEST_BUFF_SIZE>>2;
464 else if (type == OPR_UINT64)
465 cnt = TEST_BUFF_SIZE>>3;
466 cnt += 2;
468 printf("=======================================\n");
469 printf("EnQueue() %d num of data\n", cnt);
470 for (i=0; i<cnt; i++)
472 cpuData = (cpuData & ~0xFF) + i;
473 printf("===== %03d.EnQueue(%d)", i, cpuData & pstAQStk->opr->mask);
474 if (QStackIF_EnQueue (&gstTestingQStack, cpuData) == false)
475 printf("false\n");
476 else
477 printf("\n");
478 AQStkCtxPrint(&gstTestingQStack);
481 printf("CheckSum() = %d;", CheckSum(pstAQStk));
482 printf("Average() = %d;", Average(pstAQStk));
483 printf("SignedAverage() = %d;", SignedAverage(pstAQStk));
485 return;
488 void MiscFunc_testing (int type)
490 int i = 0;
491 CPU_UINT cpuData = 0x1122334455667788;
492 int cnt;
494 printf("=======================================\n");
495 printf("= Queue_testing(%s).\n", OprTypeName[type&0x03]);
496 printf("=======================================\n");
497 printf("= init queue.\n");
498 QStackIF_InitQueue(&gstTestingQStack, (char *)&gau8QStackTestingBuf, TEST_BUFF_SIZE);
499 printf("= set data opr type.\n");
500 QStackIF_SetDataOprType(type);
502 if (type == OPR_UINT8)
503 cnt = TEST_BUFF_SIZE;
504 else if (type == OPR_UINT16)
505 cnt = TEST_BUFF_SIZE>>1;
506 else if (type == OPR_UINT32)
507 cnt = TEST_BUFF_SIZE>>2;
508 else if (type == OPR_UINT64)
509 cnt = TEST_BUFF_SIZE>>3;
510 cnt += 2;
511 cnt /= 2;
513 printf("=======================================\n");
514 printf("EnQueue() %d num of data\n", cnt);
515 for (i=0; i<cnt; i++)
517 cpuData = (cpuData & ~0xFF) + i;
518 printf("===== %03d.EnQueue(%d)", i, cpuData & pstAQStk->opr->mask);
519 if (QStackIF_EnQueue (&gstTestingQStack, cpuData) == false)
520 printf("false\n");
521 else
522 printf("\n");
525 printf("=============\n");
526 AQStkCtxPrint(&gstTestingQStack);
527 printf("=============\n");
528 printf("IsEmpty() = %d;", IsEmpty(pstAQStk));
529 printf("IsFull() = %d;", IsFull(pstAQStk));
530 printf("GetBuffSize() = %d;", GetBuffSize(pstAQStk));
531 printf("ValidCnt() = %d;", ValidCnt(pstAQStk));
532 printf("BlankCnt() = %d;", BlankCnt(pstAQStk));
534 printf("=============\n");
535 printf("Clear();", Clear(pstAQStk));
536 AQStkCtxPrint(&gstTestingQStack);
538 return;
541 void ReEntrance_testing (int type)
546 void QStackIF__Testing (void)
548 int i;
549 static int typelist[] = {
550 OPR_UINT8,
551 OPR_UINT16,
552 OPR_UINT32,
553 OPR_UINT64,
556 #define FOREACH_TYPE(func) for (i=0; i<sizeof(typelist)/sizeof(typelist[0]); i++) \
558 func(typelist[i]); \
561 FOREACH_TYPE(Stack_testing);
562 FOREACH_TYPE(Queue_testing);
564 StackN_testing();
565 QueueN_testing();
567 FOREACH_TYPE(QueueOverLoop_testing);
568 FOREACH_TYPE(Array_testing);
569 FOREACH_TYPE(MiscFunc_testing);
570 FOREACH_TYPE(CalcFunc_testing);
573 int main ()
575 QStackIF__Testing();
578 * @ StackTesting(): general 8/16/32/64 bit stack testing.
579 * @ StackTesting(): general 8/16/32/64 bit queue testing.
580 * @ StackTesting(): general N byte stack testing.
581 * @ StackTesting(): general N byte queue testing.
582 * @ StackTesting(): general stack boundary testing.
583 * @ StackTesting(): general queue boundary testing.
584 * @ StackTesting(): EnQueue over-loop testing.
585 * @ StackTesting(): general Array(Index/Memcpy) testing.
586 * @ StackTesting(): general GetHeadData/GetTailData/CheckSum/HeadSubTail/
587 * Average/SignedAverage testing.
588 * @ Clear/IsEmpty/IsFull/GetBuffSize/ValidCnt/BlankCnt testing.
590 return 0;
593 #endif
595 /*******************************
596 *******************************
597 * End Of File
598 *******************************
599 *******************************/
607 void QStackIF__Testing_bak (void)
609 int i = 0;
610 uint8 Buff[100]={0x00, 0x01, 0x02, 0x03, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15};
612 QStackIF_InitQueue (&gstTestingQStack, (char *)&gau8QStackTestingBuf, 1500);
614 for (i=0; i<200; i++)
616 QStackIF_EnQueueN (&gstTestingQStack, &Buff[0], 20);
617 memset(Buff, 0xaa, 100);
618 QStackIF_DeQueueN (&gstTestingQStack, &Buff[0], 6);
619 QStackIF_DeQueueN (&gstTestingQStack, &Buff[6], 14);
620 //QStackIF_DeQueueN (&gstTestingQStack, &Buff[10], 5);
621 //QStackIF_DeQueueN (&gstTestingQStack, &Buff[15], 5);
623 DbgOutBuff(i, Buff, 20);
626 void StackBoundary_testing (int type)
628 /* pop when empty */
630 /* push when full */
632 return;
635 void QueueBoundary_testing (int type)
637 /* DeQueue when empty */
639 /* EnQueue when full */
641 /* UnDeQueue when full */
643 return;