1 /************************************************************************
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 ************************************************************************/
25 /************************************************************************
27 * author: devenkong(18151155@qq.com)
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 ************************************************************************/
43 * @ UnDeQueue() testing.
44 * @ create opr func & opr size struct, operating data by specified size type.
57 /*******************************
58 *******************************
60 *******************************
61 *******************************/
62 #define MODULE_NAME MODULE_CLASS_SYSLIB
66 /* System include files */
70 /* Project module include files */
80 //#include "System/Thread/Thread.h"
84 /* Private include files */
86 /* дÔÚÍ·ÎļþÒýÓõÄ×îºó£¬ÒÔÃâ¸úÄÚºËÍ·ÎļþµÄ¶¨ÒåÓгåÍ» */
90 /*******************************
91 *******************************
92 * 2. Global Variables &
96 *******************************
97 *******************************/
100 /*******************************
101 *******************************
102 * 3. Private Functions Implement
103 *******************************
104 *******************************/
108 /*******************************
109 *******************************
110 * 4. Public Functions Implement
111 *******************************
112 *******************************/
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};
127 static char *OprTypeName
[] = {
134 uint32
ForeachBuffPrint (QSTACK
*pstQStack
, int i
, void * pvData
)
137 printf("%02x ", pvData
);
139 printf("%02x\n", pvData
);
144 void AQStkBuffPrint (QSTACK
*pstAQStk
)
146 QStackIF_Foreach(pstAQStk
, ForeachBuffPrint
);
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
);
163 * note:: testing for functions:
164 * @ QStackIF_InitStack()
165 * @ QStackIF_SetDataOprType()
169 void Stack_testing (int type
)
172 CPU_UINT cpuData
= 0x1122334455667788;
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;
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)
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)
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
)
230 CPU_UINT cpuData
= 0x1122334455667788;
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;
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)
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)
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)
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)
297 AQStkCtxPrint(&gstTestingQStack
);
300 printf("pay attension on the sequence of DeQueue data.\n");
303 void StackN_testing (void)
306 CPU_UINT cpuData
= 0x1122334455667788;
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);
332 void QueueN_testing (void)
335 CPU_UINT cpuData
= 0x1122334455667788;
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
)
363 CPU_UINT cpuData
= 0x1122334455667788;
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;
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)
394 AQStkCtxPrint(&gstTestingQStack
);
397 /* Index Read/Write */
399 /* MemCpy From Mem/Array to Array/Mem */
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;
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)
434 AQStkCtxPrint(&gstTestingQStack
);
437 /* Index Read/Write */
439 /* MemCpy From Mem/Array to Array/Mem */
444 void CalcFunc_testing (int type
)
447 CPU_UINT cpuData
= 0x1122334455667788;
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;
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)
478 AQStkCtxPrint(&gstTestingQStack
);
481 printf("CheckSum() = %d;", CheckSum(pstAQStk
));
482 printf("Average() = %d;", Average(pstAQStk
));
483 printf("SignedAverage() = %d;", SignedAverage(pstAQStk
));
488 void MiscFunc_testing (int type
)
491 CPU_UINT cpuData
= 0x1122334455667788;
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;
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)
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
);
541 void ReEntrance_testing (int type
)
546 void QStackIF__Testing (void)
549 static int typelist
[] = {
556 #define FOREACH_TYPE(func) for (i=0; i<sizeof(typelist)/sizeof(typelist[0]); i++) \
561 FOREACH_TYPE(Stack_testing
);
562 FOREACH_TYPE(Queue_testing
);
567 FOREACH_TYPE(QueueOverLoop_testing
);
568 FOREACH_TYPE(Array_testing
);
569 FOREACH_TYPE(MiscFunc_testing
);
570 FOREACH_TYPE(CalcFunc_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.
595 /*******************************
596 *******************************
598 *******************************
599 *******************************/
607 void QStackIF__Testing_bak (void)
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
)
635 void QueueBoundary_testing (int type
)
637 /* DeQueue when empty */
639 /* EnQueue when full */
641 /* UnDeQueue when full */