blob: 099ec7cb8c7c2561db403e29634d31aef1ae3568 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001#include "kal_public_api.h"
2#include "syscomp_config.h"
3#include "task_config.h"
4#include "sys_test.h"
5#include "dcl.h"
6#include "qmu_bm_util.h"
7#include "drv_msgid.h"
8
9#if !defined ATEST_SYS_TTYCORE
10#error "This file is used for system test only."
11#endif
12
13/***************************************************************************
14 Macro Declaration
15 ***************************************************************************/
16#define ST_MOD_NAME "TTYUT"
17
18#define MOD_TTY_UT MOD_SYS_TEST
19#define DRV_TTY_UT MOD_SYS_TEST
20#define MOD_CURRENT kal_get_active_module_id()
21
22#define UART_DEV_CNT (uart_max_port - uart_port1 + 1)
23
24#define HW_BUFF_SIZE 8192
25#define UT_TEST_SIZE 8000
26#define UT_CHUNK_SIZE 512
27#define UT_DATA_MASK 0x000000CC
28
29#define DCL_UART_MAGIC_NUM 0x40000000
30
31#define DCL_UART_GET_DEV(_handle) ((DCL_DEV)((_handle) & (~DCL_UART_MAGIC_NUM)))
32
33#define FAIL_MSG(fmt, ...) do { \
34 kal_sprintf(p_ret_err_str, "%s():%s:%d " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \
35 *p_ret_err_str_sz = strlen(p_ret_err_str); \
36 } while (0)
37#define FAIL_MSG_EXT(ext, fmt, ...) do { \
38 kal_sprintf(p_ret_err_str, strcat(ext, "%s():%s:%d " fmt), __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \
39 *p_ret_err_str_sz = strlen(p_ret_err_str); \
40 } while (0)
41#define MIN(_x, _y) (((_x) > (_y)) ? (_y) : (_x))
42
43#define list_each_gpd_no_tail(_gpd, _first_gpd, _last_gpd) \
44 for ( _gpd = _first_gpd; _gpd != _last_gpd; _gpd = QBM_DES_GET_NEXT(_gpd))
45
46#define list_each_gpd(_gpd, _first_gpd, _last_gpd) QBM_DES_SET_NEXT(_last_gpd, NULL); \
47 for ( _gpd = _first_gpd; _gpd != NULL; _gpd = QBM_DES_GET_NEXT(_gpd))
48#define list_each_bd(_bd, _first_bd) for (_bd = _first_bd; _bd != NULL; _bd = QBM_DES_GET_NEXT(_bd))
49
50/***************************************************************************
51 Data Structure
52 ***************************************************************************/
53// This flag used to check event occur, and it will be "extern" in dcl_tty.c
54kal_bool ut_assert_flag = KAL_FALSE;
55
56typedef struct _UtInstance {
57/***********************
58 Upper Module
59 ***********************/
60 // For Receiving Ior From RxCb (New Rx Path)
61 tty_io_request_t *Rx_Ior;
62
63/***********************
64 Driver
65 ***********************/
66 // RxGpdQue
67 void *Rx_first_gpd;
68 void *Rx_last_gpd;
69 // TxGpdQue
70 void *Tx_first_gpd;
71 void *Tx_last_gpd;
72 // Flag
73 kal_bool Need_Tx_done_cb;
74
75/***********************
76 Hardware buffer
77 ***********************/
78 int size;
79 int start;
80 char HwBuff[HW_BUFF_SIZE];
81} UtInstance;
82
83static UtInstance Dev_Mgmt[UART_DEV_CNT];
84
85/***************************************************************************
86 Hardware Buffer Function
87 ***************************************************************************/
88/*
89 * Here is a simple hw buffer
90 * There is no check for data overflow.
91 */
92int Hw_GetRemainSpace(DCL_DEV dev)
93{
94 return HW_BUFF_SIZE - (Dev_Mgmt[dev].start + Dev_Mgmt[dev].size);
95}
96
97void Hw_PushData(DCL_DEV dev, const void *src, kal_uint32 size)
98{
99 char *hwbuff_data_end = Dev_Mgmt[dev].HwBuff + Dev_Mgmt[dev].start + Dev_Mgmt[dev].size;
100 kal_mem_cpy(hwbuff_data_end, src, size);
101 Dev_Mgmt[dev].size += size;
102}
103
104void Hw_PushDataFromTxQue(DCL_DEV dev)
105{
106 void *gpd_t;
107 void *bd_t;
108
109 list_each_gpd(gpd_t, Dev_Mgmt[dev].Tx_first_gpd, Dev_Mgmt[dev].Tx_last_gpd) {
110 // only push data of gpd with hwo equal to 1
111 if (QBM_DES_GET_HWO(gpd_t)) {
112 if (QBM_DES_GET_BDP(gpd_t)) {
113 list_each_bd(bd_t, QBM_DES_GET_DATAPTR(gpd_t)) {
114 Hw_PushData(dev, QBM_DES_GET_DATAPTR(bd_t), QBM_DES_GET_DATALEN(bd_t));
115 }
116 } else {
117 Hw_PushData(dev, QBM_DES_GET_DATAPTR(gpd_t), QBM_DES_GET_DATALEN(gpd_t));
118 }
119 }
120
121 // set hwo to 0
122 QBM_DES_CLR_HWO(gpd_t);
123 }
124}
125
126void Hw_PopData(DCL_DEV dev, void *dest, kal_uint32 size)
127{
128 char *hwbuff_data_start = Dev_Mgmt[dev].HwBuff + Dev_Mgmt[dev].start;
129 kal_mem_cpy(dest, hwbuff_data_start, size);
130 Dev_Mgmt[dev].start += size;
131 Dev_Mgmt[dev].size -= size;
132}
133
134void Hw_PopDataToRxQue(DCL_DEV dev)
135{
136 void *gpd_t;
137 void *bd_t;
138
139 list_each_gpd_no_tail(gpd_t, Dev_Mgmt[dev].Rx_first_gpd, Dev_Mgmt[dev].Rx_last_gpd) {
140 // check hardware buffer still have data
141 if (Dev_Mgmt[dev].size == 0)
142 break;
143
144 if (QBM_DES_GET_BDP(gpd_t)) {
145 list_each_bd(bd_t, QBM_DES_GET_DATAPTR(gpd_t)) {
146 kal_uint32 len = MIN(QBM_DES_GET_ALLOW_LEN(bd_t), Dev_Mgmt[dev].size);
147 if (len) {
148 Hw_PopData(dev, QBM_DES_GET_DATAPTR(bd_t), len);
149 }
150 QBM_DES_SET_DATALEN(bd_t, len);
151 }
152 } else {
153 kal_uint32 len = MIN(QBM_DES_GET_ALLOW_LEN(gpd_t), Dev_Mgmt[dev].size);
154 if (len) {
155 Hw_PopData(dev, QBM_DES_GET_DATAPTR(gpd_t), len);
156 }
157 QBM_DES_SET_DATALEN(gpd_t, len);
158 }
159
160 // set hwo to 0
161 QBM_DES_CLR_HWO(gpd_t);
162 }
163}
164
165void Hw_ClearBuff(DCL_DEV dev)
166{
167 kal_mem_set(Dev_Mgmt[dev].HwBuff, 0, HW_BUFF_SIZE);
168
169 Dev_Mgmt[dev].start = 0;
170 Dev_Mgmt[dev].size = 0;
171}
172
173/***************************************************************************
174 Tx/Rx Operator Function
175 ***************************************************************************/
176void Rx_EnQue(DCL_DEV dev, void *_ior)
177{
178 void *gpd_t;
179 tty_io_request_t *ior = (tty_io_request_t *)_ior;
180
181 // Set gpd HWO to 1,only tail gpd HWO to 0. And then En-Q
182 list_each_gpd(gpd_t, ior->first_gpd, ior->last_gpd) {
183 QBM_DES_SET_HWO(gpd_t);
184 }
185 QBM_DES_CLR_HWO(ior->last_gpd);
186
187 if (!Dev_Mgmt[dev].Rx_first_gpd) {
188 Dev_Mgmt[dev].Rx_first_gpd = ior->first_gpd;
189 Dev_Mgmt[dev].Rx_last_gpd = ior->last_gpd;
190 } else {
191 qbmt_common_en_q_rx(
192 ior->first_gpd,
193 ior->last_gpd,
194 &Dev_Mgmt[dev].Rx_first_gpd,
195 &Dev_Mgmt[dev].Rx_last_gpd);
196 }
197}
198
199void Tx_EnQue(DCL_DEV dev, void *_ior)
200{
201 void *gpd_t;
202 tty_io_request_t *ior = (tty_io_request_t *)_ior;
203
204 // Set gpd HWO to 1, And then En-Q
205 list_each_gpd(gpd_t, ior->first_gpd, ior->last_gpd) {
206 QBM_DES_SET_HWO(gpd_t);
207 }
208
209 if (!Dev_Mgmt[dev].Tx_first_gpd) {
210 Dev_Mgmt[dev].Tx_first_gpd = ior->first_gpd;
211 Dev_Mgmt[dev].Tx_last_gpd = ior->last_gpd;
212 } else {
213 QBM_DES_SET_NEXT(Dev_Mgmt[dev].Tx_last_gpd, ior->first_gpd);
214 }
215}
216
217void * Rx_DeQueToIor(DCL_DEV dev)
218{
219 void *ior = NULL;
220 void *new_head;
221 void *new_tail;
222
223 if (Dev_Mgmt[dev].Rx_first_gpd) {
224 qbmt_de_q(
225 &Dev_Mgmt[dev].Rx_first_gpd,
226 &Dev_Mgmt[dev].Rx_last_gpd,
227 &new_head,
228 &new_tail);
229
230 if (new_head) {
231 ior = QBM_DES_GET_SW_CTRL_FIELD(new_head);
232 ((tty_io_request_t *)ior)->first_gpd = new_head;
233 ((tty_io_request_t *)ior)->last_gpd = new_tail;
234 }
235 }
236
237 return ior;
238}
239
240void Rx_Flush_Gpd(DCL_DEV dev)
241{
242 void *Rx_Ior;
243 DCL_HANDLE handle;
244
245 handle = DclSerialPort_Open(dev, 0);
246
247 // Using RxCb to return the all GPD of Rx Queue
248 if (Dev_Mgmt[dev].Rx_first_gpd) {
249 Rx_Ior = QBM_DES_GET_SW_CTRL_FIELD(Dev_Mgmt[dev].Rx_first_gpd);
250 ((tty_io_request_t *)Rx_Ior)->first_gpd = Dev_Mgmt[dev].Rx_first_gpd;
251 ((tty_io_request_t *)Rx_Ior)->last_gpd = Dev_Mgmt[dev].Rx_last_gpd;
252
253 DclSerialPort_DrvRx(handle, DRV_TTY_UT, Rx_Ior);
254
255 Dev_Mgmt[dev].Rx_first_gpd = 0;
256 Dev_Mgmt[dev].Rx_last_gpd = 0;
257 }
258}
259
260/*
261 * This function maybe need to be called after Hw_PushDataFromTxQue() invoked.
262 * Because it will flush each gpd without care about whether hwo is set.
263 *
264 * The Hw_PushDataFromTxQue() will be invoked in driver callback with command "TTY_CMD_PUT_BYTES_IOR"
265 */
266void Tx_Flush_Gpd(DCL_DEV dev)
267{
268 void * Tx_Ior;
269 DCL_HANDLE handle;
270
271 handle = DclSerialPort_Open(dev, 0);
272
273 // Using TxDoneCb to return Tx GPD or Free gpds
274 if (Dev_Mgmt[dev].Tx_first_gpd) {
275 Tx_Ior = QBM_DES_GET_SW_CTRL_FIELD(Dev_Mgmt[dev].Tx_first_gpd);
276 ((tty_io_request_t *)Tx_Ior)->first_gpd = Dev_Mgmt[dev].Tx_first_gpd;
277 ((tty_io_request_t *)Tx_Ior)->last_gpd = Dev_Mgmt[dev].Tx_last_gpd;
278
279 if (Dev_Mgmt[dev].Need_Tx_done_cb) {
280 DclSerialPort_DrvTxDone(handle, DRV_TTY_UT, Tx_Ior);
281 } else {
282 qbmt_dest_q(Dev_Mgmt[dev].Tx_first_gpd, Dev_Mgmt[dev].Tx_last_gpd);
283 }
284
285 Dev_Mgmt[dev].Tx_first_gpd = 0;
286 Dev_Mgmt[dev].Tx_last_gpd = 0;
287 }
288}
289/***************************************************************************
290 Callback Test Function
291 ***************************************************************************/
292DCL_STATUS
293_drv_handler_cb(
294 DCL_DEV dev,
295 DCL_CTRL_CMD cmd,
296 DCL_CTRL_DATA_T *data)
297{
298 DCL_STATUS ret_status = STATUS_OK;
299
300 switch (cmd)
301 {
302 case SIO_CMD_INIT:
303 case SIO_CMD_OPEN:
304 {
305 ret_status = STATUS_OK;
306 }
307 break;
308
309 case SIO_CMD_CLOSE:
310 {
311 UART_CTRL_CLOSE_T *prCtrlClose;
312 prCtrlClose = &(data->rUARTCtrlCLOSE);
313
314 // Flush Tx/Rx GPD (In buffer mode, Flush will do nothing because queue is empty
315 Tx_Flush_Gpd(dev);
316 Rx_Flush_Gpd(dev);
317
318 // Clear Need_Tx_done_cb flag
319 Dev_Mgmt[dev].Need_Tx_done_cb = KAL_FALSE;
320 }
321 break;
322
323 case SIO_CMD_PUT_BYTES:
324 { // Only for Buffer Mode
325 int size;
326 UART_CTRL_PUT_BYTES_T *prCtrlPutBytes;
327
328 prCtrlPutBytes = &(data->rUARTCtrlPUTBYTES);
329 size = MIN(prCtrlPutBytes->u2Length, UT_CHUNK_SIZE);
330
331 Hw_PushData(dev, prCtrlPutBytes->puBuffaddr, size);
332 prCtrlPutBytes->u2RetSize = size;
333 }
334 break;
335
336 case SIO_CMD_GET_BYTES:
337 { // Only for Buffer Mode
338 int size;
339 UART_CTRL_GET_BYTES_T *prCtrlGetBytes;
340
341 prCtrlGetBytes = &(data->rUARTCtrlGETBYTES);
342 size = MIN(prCtrlGetBytes->u2Length, UT_CHUNK_SIZE);
343
344 Hw_PopData(dev, prCtrlGetBytes->puBuffaddr, size);
345 prCtrlGetBytes->u2RetSize = size;
346 }
347 break;
348
349 case TTY_CMD_NEED_TX_DONE_CB:
350 {
351 UART_CTRL_NEED_TX_DONE_CB_T *prCtrlNeedTxDoneCb;
352 prCtrlNeedTxDoneCb = &(data->rUARTCtrlNeedTxDoneCb);
353
354 Dev_Mgmt[dev].Need_Tx_done_cb = prCtrlNeedTxDoneCb->needTxDoneCb;
355 }
356 break;
357
358 case TTY_CMD_ASSIGN_RX_IOR:
359 {
360 UART_CTRL_ASSIGN_RX_IOR_T *prCtrlAssignRxIor;
361
362 prCtrlAssignRxIor = &(data->rUARTCtrlAssignRxIor);
363
364 // En-Q Rx_Ior
365 Rx_EnQue(dev, prCtrlAssignRxIor->ior);
366 }
367 break;
368
369 case TTY_CMD_PUT_BYTES_IOR:
370 case TTY_CMD_PUT_BYTES_IOR_LIGHT:
371 {
372 UART_CTRL_PUT_BYTES_IOR_T *prCtrlPutBytesIor;
373
374 prCtrlPutBytesIor = &(data->rUARTCtrlPUTBYTESIOR);
375
376 // En-Q Tx_Ior
377 Tx_EnQue(dev, prCtrlPutBytesIor->putIor);
378
379 // Copy GPD data to HwBuff
380 Hw_PushDataFromTxQue(dev);
381
382 }
383 break;
384
385 case TTY_CMD_GET_CHUNK_SIZE:
386 {
387 UART_CTRL_GET_CHUNK_SIZE_T *prCtrlChunkSize;
388 prCtrlChunkSize = &(data->rUARTCtrlGETCHUNKSIZE);
389 prCtrlChunkSize->chunkSize = UT_CHUNK_SIZE;
390 }
391 break;
392 case SIO_CMD_SET_OWNER:
393 {
394 // Flush Tx/Rx GPD
395 Tx_Flush_Gpd(dev);
396 Rx_Flush_Gpd(dev);
397
398 // Clear Need_Tx_done_cb flag
399 Dev_Mgmt[dev].Need_Tx_done_cb = KAL_FALSE;
400 }
401 break;
402
403 case SIO_CMD_GET_OWNER_ID:
404 break;
405
406 case SIO_CMD_CLR_RX_BUF:
407 {
408 Rx_Flush_Gpd(dev);
409 }
410 break;
411
412 case SIO_CMD_CLR_TX_BUF:
413 {
414 Tx_Flush_Gpd(dev);
415 }
416 break;
417
418 case SIO_CMD_GET_TX_AVAIL:
419 { // Only for Buffer Mode
420 UART_CTRL_TX_AVAIL_T *prCtrlTxAvail;
421
422 prCtrlTxAvail = &(data->rUARTCtrlTXAVAIL);
423
424 prCtrlTxAvail->u2RetSize = Hw_GetRemainSpace;
425 }
426 break;
427
428 case SIO_CMD_GET_RX_AVAIL:
429 { // Only for Buffer Mode
430 DCL_HANDLE handle;
431 UART_CTRL_RX_AVAIL_T *prCtrlRxAvail;
432
433 prCtrlRxAvail = &(data->rUARTCtrlRXAVAIL);
434
435 prCtrlRxAvail->u2RetSize = Dev_Mgmt[dev].size;
436
437 // Here we invoke RxCb to send ilm and clear Notify_ILM flag in Buffer Mode
438 handle = DclSerialPort_Open(dev, 0);
439 DclSerialPort_DrvRx(handle, DRV_TTY_UT, NULL);
440
441 // Get the Notify_ILM and this flag is cleared by above callback
442 {
443 ilm_struct current_ilm;
444
445 msg_receive_extq(&current_ilm);
446 if (current_ilm.msg_id != MSG_ID_UART_READY_TO_READ_IND) {
447 ret_status = STATUS_FAIL;
448 }
449 destroy_ilm(&current_ilm);
450 }
451 }
452 break;
453
454 default:
455 {
456 ret_status = STATUS_INVALID_CMD;
457 }
458 break;
459 }
460
461 return ret_status;
462}
463
464DCL_STATUS
465_tx_done_cb(
466 DCL_HANDLE handle,
467 module_type source_id,
468 tty_io_request_t *tx_ior)
469{
470 // Just Free all gpd
471 qbmt_dest_q(tx_ior->first_gpd, tx_ior->last_gpd);
472
473 return STATUS_OK;
474}
475
476DCL_STATUS
477_rx_cb(
478 DCL_HANDLE handle,
479 module_type source_id,
480 tty_io_request_t *rx_ior)
481{
482 DCL_DEV device;
483
484 device = DCL_UART_GET_DEV(handle);
485
486 Dev_Mgmt[device].Rx_Ior = rx_ior;
487
488 return STATUS_OK;
489}
490
491DCL_STATUS
492 _drv_state_change_cb(
493 DCL_HANDLE handle,
494 tty_drv_state_e state)
495{
496 switch(state)
497 {
498 case DRV_ST_DETACHED:
499 case DRV_ST_ATTACHED:
500 default:
501 break;
502 }
503
504 return STATUS_OK;
505}
506
507/****************************************************************************
508 Test Function
509 ***************************************************************************/
510
511#define IS_SUB_CASE_FAIL(_func) (_func(p_ret_err_str, p_ret_err_str_sz) == KAL_FALSE)
512/***********************************
513 Function Verification
514 ***********************************/
515
516kal_bool FuncVeri_Common(void *p_param, kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
517{
518 DCL_DEV device;
519 DCL_HANDLE handle;
520 DCL_STATUS status;
521
522 /*
523 * DclSerialPort_Initialize Test
524 */
525 status = DclSerialPort_Initialize();
526 if (status != STATUS_OK) {
527 FAIL_MSG("Initialize Failed!");
528 return KAL_FALSE;
529 }
530
531 /*
532 * DclSerialPort_Open(device, flags) Test
533 * - parameter
534 * device - which port you want to get handle
535 * flags - no used
536 *
537 * - Description
538 * This function is used to get handle only
539 * and do nothing with initialization setting of port
540 *
541 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
542 * Scenario
543 * Port range(P) | Expected result
544 * ============================================================
545 * P < uart_port1 or P > uart_max_port | STATUS_INVALID_DEVICE
546 * uart_port1 <= P <= uart_max_port | DCL_UART_MAGIC_NUM | device
547 */
548
549 for (device = 0; device < uart_port1; device++) {
550 handle = DclSerialPort_Open(device, 0);
551 if (handle != STATUS_INVALID_DEVICE) {
552 FAIL_MSG("Get handle test Failed! port # = %d", device);
553 return KAL_FALSE;
554 }
555 }
556
557 for (device = uart_port1; device <= uart_max_port; device++) {
558 handle = DclSerialPort_Open(device, 0);
559 if (handle != (DCL_UART_MAGIC_NUM | device)) {
560 FAIL_MSG("Get handle test Failed! port # = %d", device);
561 return KAL_FALSE;
562 }
563 }
564
565 for (device = uart_max_port + 1; device < uart_port_null; device++) {
566 handle = DclSerialPort_Open(device, 0);
567 if (handle != STATUS_INVALID_DEVICE) {
568 FAIL_MSG("Get handle test Failed! port # = %d", device);
569 return KAL_FALSE;
570 }
571 }
572
573 // Check there is no assert
574 if (ut_assert_flag) {
575 ut_assert_flag = KAL_FALSE; // clear flag
576 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
577 return KAL_FALSE;
578 }
579 return KAL_TRUE;
580}
581
582kal_bool FuncVeri_DrvRegDeRegCb(void *p_param, kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
583{
584 DCL_DEV device;
585 DCL_HANDLE handle;
586 DCL_STATUS status;
587 SIO_TYPE_T devtype;
588 Seriport_HANDLER_T drv_ut_handler;
589
590 /*
591 * DclSerialPort_DrvRegisterCb(handle, drv_cb)
592 * - Description
593 * Register driver callback function as uart handler for TTYCore.
594 * And specify device type(will affect chunkSize & others...
595 * This API will make port active.
596 *
597 * DclSerialPort_DrvDeRegisterCb(handle)
598 * - Description
599 * Clear uart handler for TTYCore.
600 * This API will make port inactive.
601 *
602 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
603 * Scenario
604 * Conditions | Expected result
605 * ============================================================
606 * Invalid port | STATUS_FAIL
607 | STATUS_INVALID_DCL_HANDLE
608 | STATUS_INVALID_DEVICE
609 * valid port
610 * drv_cb is null | STATUS_INVALID_ARGUMENT
611 * RegCb/DeRegCb | STATUS_OK
612 * Dup RegCb | STATUS_ALREADY_OPENED
613 * Dup DeRegCb | STATUS_INVALID_OPERATION
614 *
615 * Other Situations
616 * Each port will register with each device type
617 *
618 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
619 * TODO
620 * DeRegCb with DrvAttach
621 */
622
623 device = uart_port_null;
624 handle = DclSerialPort_Open(device, 0);
625 // Invalid Port Test
626 status = DclSerialPort_DrvRegisterCb(handle, &drv_ut_handler);
627 if (status != STATUS_FAIL) {
628 FAIL_MSG("Driver RegisterCb in Invalid port");
629 return KAL_FALSE;
630 }
631 status = DclSerialPort_DrvDeRegisterCb(handle);
632 if (status != STATUS_FAIL) {
633 FAIL_MSG("Driver De-RegisterCb in Invalid port");
634 return KAL_FALSE;
635 }
636
637 // Valid Port Test
638 for (device = uart_port1; device <= uart_max_port; device++) {
639 handle = DclSerialPort_Open(device, 0);
640
641 for (devtype = DCL_UART_TYPE; devtype < DCL_UART_DEV_TYPE_MAX; devtype++){
642 drv_ut_handler.DevType = devtype;
643
644 // Register NULL callback (will assert)
645 drv_ut_handler.SeriportHandlerCb = NULL;
646 // Check there is no assert
647 if (ut_assert_flag) {
648 ut_assert_flag = KAL_FALSE; // clear flag
649 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
650 return KAL_FALSE;
651 }
652 status = DclSerialPort_DrvRegisterCb(handle, &drv_ut_handler);
653 if ((ut_assert_flag == KAL_FALSE) || (status != STATUS_INVALID_ARGUMENT)) {
654 FAIL_MSG("Driver Register NULL Test Failed! Device# = %d, DevType = %d", device, devtype);
655 return KAL_FALSE;
656 }
657 ut_assert_flag = KAL_FALSE;
658
659 drv_ut_handler.SeriportHandlerCb = _drv_handler_cb;
660
661 // First Register callback
662 status = DclSerialPort_DrvRegisterCb(handle, &drv_ut_handler);
663 if (status != STATUS_OK) {
664 FAIL_MSG("Driver Register Callback Failed! Device# = %d, DevType = %d", device, devtype);
665 return KAL_FALSE;
666 }
667
668 // Duplicated Register callback
669 status = DclSerialPort_DrvRegisterCb(handle, &drv_ut_handler);
670 if (status != STATUS_ALREADY_OPENED) {
671 FAIL_MSG("Driver Duplicated RegisterCb Failed! Device# = %d, DevType = %d", device, devtype);
672 return KAL_FALSE;
673 }
674
675 // First De-Register callback
676 status = DclSerialPort_DrvDeRegisterCb(handle);
677 if (status != STATUS_OK) {
678 FAIL_MSG("Driver De-RegisterCb Failed! Device# = %d, DevType = %d", device, devtype);
679 return KAL_FALSE;
680 }
681
682 // Duplicated De-Register callback
683 status = DclSerialPort_DrvDeRegisterCb(handle);
684 if (status != STATUS_INVALID_OPERATION) {
685 FAIL_MSG("Driver Duplicated De-RegisterCb Failed! Device# = %d, DevType = %d", device, devtype);
686 return KAL_FALSE;
687 }
688
689 /// TODO: De-RegisterCb with DrvAttach
690 }
691 }
692
693 // Check there is no assert
694 if (ut_assert_flag) {
695 ut_assert_flag = KAL_FALSE; // clear flag
696 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
697 return KAL_FALSE;
698 }
699 return KAL_TRUE;
700}
701
702kal_bool FuncVeri_DrvAtDetach(void *p_param, kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
703{
704 DCL_DEV device;
705 DCL_HANDLE handle;
706 DCL_STATUS status;
707 SIO_TYPE_T devtype;
708 Seriport_HANDLER_T drv_ut_handler;
709
710 /*
711 * DclSerialPort_DrvAttach(handle)
712 * DclSerialPort_DrvDetach(handle)
713 * - Description
714 * Change port state to attach/detach as state of driver connect/disconnect
715 *
716 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
717 * Scenario
718 * Conditions | Expected result
719 * ============================================================
720 * Invalid port | STATUS_FAIL
721 | STATUS_INVALID_DCL_HANDLE
722 | STATUS_DEVICE_NOT_EXIST
723 * valid port
724 * port active
725 * Attach/Detach | STATUS_OK
726 * Dup Attach/Detach | STATUS_OK
727 * port inactive
728 * Attach/Detach | STATUS_DEVICE_NOT_EXIST
729 */
730
731 device = uart_port_null;
732 handle = DclSerialPort_Open(device, 0);
733 // Invalid Port Test
734 status = DclSerialPort_DrvAttach(handle);
735 if (status != STATUS_FAIL) {
736 FAIL_MSG("Driver Attach in Invalid port");
737 return KAL_FALSE;
738 }
739 status = DclSerialPort_DrvDetach(handle);
740 if (status != STATUS_FAIL) {
741 FAIL_MSG("Driver Detach in Invalid port");
742 return KAL_FALSE;
743 }
744
745 // Valid Port Test
746 for (device = uart_port1; device <= uart_max_port; device++) {
747 handle = DclSerialPort_Open(device, 0);
748
749 // Port InActive
750 status = DclSerialPort_DrvAttach(handle);
751 if (status != STATUS_DEVICE_NOT_EXIST) {
752 FAIL_MSG("Driver Attach with port inactive Failed! Device# = %d", device);
753 return KAL_FALSE;
754 }
755 status = DclSerialPort_DrvDetach(handle);
756 if (status != STATUS_DEVICE_NOT_EXIST) {
757 FAIL_MSG("Driver Detach with port inactive Failed! Device# = %d", device);
758 return KAL_FALSE;
759 }
760
761 drv_ut_handler.SeriportHandlerCb = _drv_handler_cb;
762 // Port Active with each device type
763 for (devtype = DCL_UART_TYPE; devtype < DCL_UART_DEV_TYPE_MAX; devtype++){
764 drv_ut_handler.DevType = devtype;
765
766 // Register callback (Active)
767 status = DclSerialPort_DrvRegisterCb(handle, &drv_ut_handler);
768 if (status != STATUS_OK) {
769 FAIL_MSG("Driver Register Callback Failed! Device# = %d, DevType = %d", device, devtype);
770 return KAL_FALSE;
771 }
772
773 // First Attach
774 status = DclSerialPort_DrvAttach(handle);
775 if (status != STATUS_OK) {
776 FAIL_MSG("Driver Attach Failed! Device# = %d, DevType = %d", device, devtype);
777 return KAL_FALSE;
778 }
779
780 //Duplicated Attach
781 status = DclSerialPort_DrvAttach(handle);
782 if (status != STATUS_OK) {
783 FAIL_MSG("Driver Duplicated Attach Failed! Device# = %d, DevType = %d", device, devtype);
784 return KAL_FALSE;
785 }
786
787 // First Detach
788 status = DclSerialPort_DrvDetach(handle);
789 if (status != STATUS_OK) {
790 FAIL_MSG("Driver Detach Failed! Device# = %d, DevType = %d", device, devtype);
791 return KAL_FALSE;
792 }
793
794 // Duplicated Detach
795 status = DclSerialPort_DrvDetach(handle);
796 if (status != STATUS_OK) {
797 FAIL_MSG("Driver Duplicated Detach Failed! Device# = %d, DevType = %d", device, devtype);
798 return KAL_FALSE;
799 }
800
801 // De-Register callback (InActive port - Avoid next time RegisterCb Failed)
802 status = DclSerialPort_DrvDeRegisterCb(handle);
803 if (status != STATUS_OK) {
804 FAIL_MSG("Driver De-RegisterCb Failed! Device# = %d, DevType = %d", device, devtype);
805 return KAL_FALSE;
806 }
807 }
808 }
809
810 // Check there is no assert
811 if (ut_assert_flag) {
812 ut_assert_flag = KAL_FALSE; // clear flag
813 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
814 return KAL_FALSE;
815 }
816 return KAL_TRUE;
817}
818
819kal_bool FuncVeri_UpInitDeinit(void *p_param, kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
820{
821 DCL_DEV device;
822 DCL_HANDLE handle;
823 DCL_STATUS status;
824 SIO_TYPE_T devtype;
825 Seriport_HANDLER_T drv_ut_handler;
826
827 /*
828 * DclSerialPort_UpModuleInit(handle, module_id, flag)
829 * DclSerialPort_Control(handle, SIO_CMD_OPEN, data)
830 * - Description
831 * Setup owner id and Tx/Rx path in specify port.
832 * Send SIO_CMD_OPEN to let Driver know port is opened.
833 *
834 * DclSerialPort_UpModuleDeinit(handle)
835 * DclSerialPort_Control(handle, SIO_CMD_CLOSE, data)
836 * - Description
837 * Clear owner id and Tx/Rx path in specify port.
838 * Send SIO_CMD_CLOSE to let Driver know port is closed.
839 *
840 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
841 * Scenario
842 * Conditions | Expected result
843 * ============================================================
844 * Invalid port | STATUS_FAIL
845 | STATUS_INVALID_DCL_HANDLE
846 | STATUS_INVALID_DEVICE
847 * valid port
848 * Init/Deinit | STATUS_OK
849 * Dup Init/Deinit | STATUS_ALREADY_OPENED/STATUS_NOT_OPENED
850 *
851 * Other Situations
852 * when Driver active/inactive
853 * active with each device type
854 * Kinds of Initialization
855 * New Tx, New Rx, New Tx&Rx, Conv(New API/ Conv API)
856 * Kinds of De-Initialization
857 * New API/ Conv API)
858 *
859 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
860 * TODO
861 * In this Test Case, we only test pair of Conv Init & Conv De-Init
862 * New Init & New De-Init
863 * Uncovering case
864 * pair of Conv Init & New De-Init
865 * New Init & Conv De-Init
866 *
867 * Add them If it is needed.
868 */
869
870 // Conv API Test
871 {
872 UART_CTRL_OPEN_T ur_ctrl_open;
873 UART_CTRL_CLOSE_T ur_ctrl_close;
874 char *Error_Tag = "[Conv API][Conv Tx & Conv Rx] ";
875
876 ur_ctrl_open.u4OwenrId = MOD_TTY_UT;
877 ur_ctrl_close.u4OwenrId = MOD_TTY_UT;
878
879 device = uart_port_null;
880 handle = DclSerialPort_Open(device, 0);
881 // Invalid Port Test
882 status = DclSerialPort_Control(handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*) &ur_ctrl_open);
883 if (status != STATUS_FAIL) {
884 FAIL_MSG_EXT(Error_Tag, "Init in Invalid port");
885 return KAL_FALSE;
886 }
887 status = DclSerialPort_Control(handle, SIO_CMD_CLOSE, (DCL_CTRL_DATA_T*) &ur_ctrl_close);
888 if (status != STATUS_FAIL) {
889 FAIL_MSG_EXT(Error_Tag, "De-Init in Invalid port");
890 return KAL_FALSE;
891 }
892
893 // Valid Port Test
894 for (device = uart_port1; device <= uart_max_port; device++) {
895 handle = DclSerialPort_Open(device, 0);
896
897 // Port InActive
898 {
899 // First Init
900 status = DclSerialPort_Control(handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*) &ur_ctrl_open);
901 if (status != STATUS_OK) {
902 FAIL_MSG_EXT(Error_Tag, "Init in InActive Valid port");
903 return KAL_FALSE;
904 }
905
906 // Duplicated Init
907 status = DclSerialPort_Control(handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*) &ur_ctrl_open);
908 if (status != STATUS_ALREADY_OPENED) {
909 FAIL_MSG_EXT(Error_Tag, "Duplicated Init in InActive Valid port");
910 return KAL_FALSE;
911 }
912
913 // First De-Init
914 status = DclSerialPort_Control(handle, SIO_CMD_CLOSE,(DCL_CTRL_DATA_T*) &ur_ctrl_close);
915 if (status != STATUS_OK) {
916 FAIL_MSG_EXT(Error_Tag, "De-Init in InActive Valid port");
917 return KAL_FALSE;
918 }
919
920 // Duplicated De-Init
921 status = DclSerialPort_Control(handle, SIO_CMD_CLOSE, (DCL_CTRL_DATA_T*) &ur_ctrl_close);
922 if (status != STATUS_NOT_OPENED) {
923 FAIL_MSG_EXT(Error_Tag, "Duplicated De-Init in InActive Valid port");
924 return KAL_FALSE;
925 }
926 }
927
928 drv_ut_handler.SeriportHandlerCb = _drv_handler_cb;
929 // Port Active with each device type
930 for (devtype = DCL_UART_TYPE; devtype < DCL_UART_DEV_TYPE_MAX; devtype++){
931 drv_ut_handler.DevType = devtype;
932
933 // Register callback (Active)
934 status = DclSerialPort_DrvRegisterCb(handle, &drv_ut_handler);
935 if (status != STATUS_OK) {
936 FAIL_MSG_EXT(Error_Tag, "Driver Register Callback Failed! Device# = %d, DevType = %d", device, devtype);
937 return KAL_FALSE;
938 }
939
940 // First Init
941 status = DclSerialPort_Control(handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*) &ur_ctrl_open);
942 if (status != STATUS_OK) {
943 FAIL_MSG_EXT(Error_Tag, "Init in Active Valid port");
944 return KAL_FALSE;
945 }
946
947 // Duplicated Init
948 status = DclSerialPort_Control(handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*) &ur_ctrl_open);
949 if (status != STATUS_ALREADY_OPENED) {
950 FAIL_MSG_EXT(Error_Tag, "Duplicated Init in Active Valid port");
951 return KAL_FALSE;
952 }
953
954 // First De-Init
955 status = DclSerialPort_Control(handle, SIO_CMD_CLOSE, (DCL_CTRL_DATA_T*) &ur_ctrl_close);
956 if (status != STATUS_OK) {
957 FAIL_MSG_EXT(Error_Tag, "De-Init in Active Valid port");
958 return KAL_FALSE;
959 }
960
961 // Duplicated De-Init
962 // Here is return STATUS_OK but not STATUS_NOT_OPENED
963 ///TODO: if this result of return value is BUG, please fix it.
964 status = DclSerialPort_Control(handle, SIO_CMD_CLOSE, (DCL_CTRL_DATA_T*) &ur_ctrl_close);
965 if (status != STATUS_OK) {
966 FAIL_MSG_EXT(Error_Tag, "Duplicated De-Init in Active Valid port");
967 return KAL_FALSE;
968 }
969
970 // De-Register callback (InActive port - Avoid next time RegisterCb Failed)
971 status = DclSerialPort_DrvDeRegisterCb(handle);
972 if (status != STATUS_OK) {
973 FAIL_MSG_EXT(Error_Tag, "Driver De-RegisterCb Failed! Device# = %d, DevType = %d", device, devtype);
974 return KAL_FALSE;
975 }
976 }
977 }
978 }
979
980 // New API Test
981 {
982 int i;
983 int flag;
984 int Path_Case[4] = {
985 0,
986 TTY_FLAG_NEW_TX,
987 TTY_FLAG_NEW_RX,
988 TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX};
989 char *Error_Tag[4] = {
990 "[New API][Conv Tx & Conv Rx] ",
991 "[New API][New Tx & Conv Rx] ",
992 "[New API][Conv Tx & New Rx] ",
993 "[New API][New Tx & New Rx] "};
994
995 for (i = 0; i < 4; i++) {
996 flag = Path_Case[i];
997
998 device = uart_port_null;
999 handle = DclSerialPort_Open(device, 0);
1000 // Invalid Port Test
1001 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, flag);
1002 if (status != STATUS_FAIL) {
1003 FAIL_MSG_EXT(Error_Tag[i], "Init in Invalid port");
1004 return KAL_FALSE;
1005 }
1006 status = DclSerialPort_UpModuleDeinit(handle);
1007 if (status != STATUS_FAIL) {
1008 FAIL_MSG_EXT(Error_Tag[i], "De-Init in Invalid port");
1009 return KAL_FALSE;
1010 }
1011
1012
1013 drv_ut_handler.SeriportHandlerCb = _drv_handler_cb;
1014 // Valid Port Test
1015 for (device = uart_port1; device <= uart_max_port; device++) {
1016 handle = DclSerialPort_Open(device, 0);
1017
1018 // Port InActive
1019 {
1020 // First Init
1021 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, flag);
1022 if (status != STATUS_OK) {
1023 FAIL_MSG_EXT(Error_Tag[i], "Init in InActive Valid port");
1024 return KAL_FALSE;
1025 }
1026
1027 // Duplicated Init
1028 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, flag);
1029 if (status != STATUS_ALREADY_OPENED) {
1030 FAIL_MSG_EXT(Error_Tag[i], "Duplicated Init in InActive Valid port");
1031 return KAL_FALSE;
1032 }
1033
1034 // First De-Init
1035 status = DclSerialPort_UpModuleDeinit(handle);
1036 if (status != STATUS_OK) {
1037 FAIL_MSG_EXT(Error_Tag[i], "De-Init in InActive Valid port");
1038 return KAL_FALSE;
1039 }
1040
1041 // Duplicated De-Init
1042 status = DclSerialPort_UpModuleDeinit(handle);
1043 if (status != STATUS_NOT_OPENED) {
1044 FAIL_MSG_EXT(Error_Tag[i], "Duplicated De-Init in InActive Valid port");
1045 return KAL_FALSE;
1046 }
1047 }
1048
1049 // Port Active with each device type
1050 for (devtype = DCL_UART_TYPE; devtype < DCL_UART_DEV_TYPE_MAX; devtype++){
1051 drv_ut_handler.DevType = devtype;
1052
1053 // Register callback (Active)
1054 status = DclSerialPort_DrvRegisterCb(handle, &drv_ut_handler);
1055 if (status != STATUS_OK) {
1056 FAIL_MSG_EXT(Error_Tag[i], "Driver Register Callback Failed! Device# = %d, DevType = %d", device, devtype);
1057 return KAL_FALSE;
1058 }
1059
1060 // First Init
1061 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, flag);
1062 if (status != STATUS_OK) {
1063 FAIL_MSG_EXT(Error_Tag[i], "Init in Active Valid port");
1064 return KAL_FALSE;
1065 }
1066
1067 // Duplicated Init
1068 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, flag);
1069 if (status != STATUS_ALREADY_OPENED) {
1070 FAIL_MSG_EXT(Error_Tag[i], "Duplicated Init in Active Valid port");
1071 return KAL_FALSE;
1072 }
1073
1074 // First De-Init
1075 status = DclSerialPort_UpModuleDeinit(handle);
1076 if (status != STATUS_OK) {
1077 FAIL_MSG_EXT(Error_Tag[i], "De-Init in Active Valid port");
1078 return KAL_FALSE;
1079 }
1080
1081 // Duplicated De-Init
1082 status = DclSerialPort_UpModuleDeinit(handle);
1083 if (status != STATUS_NOT_OPENED) {
1084 FAIL_MSG_EXT(Error_Tag[i], "Duplicated De-Init in Active Valid port");
1085 return KAL_FALSE;
1086 }
1087
1088 // De-Register callback (InActive port - Avoid next time RegisterCb Failed)
1089 status = DclSerialPort_DrvDeRegisterCb(handle);
1090 if (status != STATUS_OK) {
1091 FAIL_MSG_EXT(Error_Tag[i], "Driver De-RegisterCb Failed! Device# = %d, DevType = %d", device, devtype);
1092 return KAL_FALSE;
1093 }
1094 }
1095 }
1096 }
1097 }
1098
1099 // Check there is no assert
1100 if (ut_assert_flag) {
1101 ut_assert_flag = KAL_FALSE; // clear flag
1102 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
1103 return KAL_FALSE;
1104 }
1105 return KAL_TRUE;
1106}
1107
1108kal_bool FuncVeri_UpRegCb(void *p_param, kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
1109{
1110 DCL_DEV device;
1111 DCL_HANDLE handle;
1112 DCL_STATUS status;
1113
1114 /*
1115 * DclSerialPort_UpModuleRegisterCb(handle, rx_cb, tx_done_cb, drv_state_change)
1116 * - Description
1117 * Register callback in specify port.
1118 *
1119 * This API is independent with active/inactive.
1120 *
1121 * - Warning
1122 * Condition 1:
1123 * This API is for New Upper Module,
1124 * Conv Upper Module no need to use it.
1125 * There is nothing verification of it.
1126 *
1127 * Condition 2:
1128 * This API need to be used after port initializing,
1129 * but there is nothing verification of it.
1130 *
1131 * If you use this API before port initialized,
1132 * it maybe cause some unexpected result.
1133 *
1134 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1135 * Scenario
1136 * Conditions | Expected result
1137 * ============================================================
1138 * Invalid port | STATUS_FAIL
1139 | STATUS_INVALID_DCL_HANDLE
1140 | STATUS_INVALID_DEVICE
1141 * valid port
1142 * RegCb/Dup RegCb | STATUS_OK
1143 * Assert Condition | ASSERT
1144 * - Conv Rx & Rx_Cb is not null
1145 * - New Rx & Rx_Cb is null
1146 * - Conv Tx & Tx_Done_Cb is not null
1147 * - Conv Tx & Conv Rx & drv_state_change_cb is not null
1148 * - (New Tx or New Rx) & drv_state_change_cb is null
1149 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1150 * TODO
1151 * In this Test Case, we only test for New Tx/Rx case and assertion case
1152 *
1153 * The warning as mentioned above, if that is important, please add it in TTYCore.
1154 */
1155
1156 device = uart_port_null;
1157 handle = DclSerialPort_Open(device, 0);
1158 // Invalid Port Test
1159 status = DclSerialPort_UpModuleRegisterCb(handle, _rx_cb, _tx_done_cb, _drv_state_change_cb);
1160 if (status != STATUS_FAIL) {
1161 FAIL_MSG("Upper Module RegisterCb in Invalid port");
1162 return KAL_FALSE;
1163 }
1164
1165 // Valid Port Test
1166 for (device = uart_port1; device <= uart_max_port; device++) {
1167 handle = DclSerialPort_Open(device, 0);
1168
1169 // Init with New Tx & New Rx Path
1170 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX);
1171 if (status != STATUS_OK) {
1172 FAIL_MSG("Init New Tx & New Rx in Valid port");
1173 return KAL_FALSE;
1174 }
1175
1176 // First Register callback
1177 status = DclSerialPort_UpModuleRegisterCb(handle, _rx_cb, _tx_done_cb, _drv_state_change_cb);
1178 if (status != STATUS_OK) {
1179 FAIL_MSG("Upper Module RegisterCb in Valid port");
1180 return KAL_FALSE;
1181 }
1182 // Duplicated Register callback with TxDoneCb is NULL
1183 status = DclSerialPort_UpModuleRegisterCb(handle, _rx_cb, NULL, _drv_state_change_cb);
1184 if (status != STATUS_OK) {
1185 FAIL_MSG("Upper Module Duplicated RegisterCb in Valid port and TxDoneCb is NULL");
1186 return KAL_FALSE;
1187 }
1188
1189 // De-Init - Avoid next time Init Failed)
1190 status = DclSerialPort_UpModuleDeinit(handle);
1191 if (status != STATUS_OK) {
1192 FAIL_MSG("De-Init New Tx & New Rx in Valid port");
1193 return KAL_FALSE;
1194 }
1195 }
1196
1197 // Assertion Case
1198 // Conv Rx & Rx_Cb is not null
1199 // Conv Tx & Tx_Done_Cb is not null
1200 // Conv Tx & Conv Rx & drv_state_change_cb is not null
1201 for (device = uart_port1; device <= uart_max_port; device++) {
1202 handle = DclSerialPort_Open(device, 0);
1203
1204 // Init with Conv Tx & Conv Rx Path
1205 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, 0);
1206 if (status != STATUS_OK) {
1207 FAIL_MSG("Init Conv Tx & Conv Rx in Valid port");
1208 return KAL_FALSE;
1209 }
1210
1211 // Register callback - Conv Rx & Rx_Cb is not null
1212 // Check there is no assert
1213 if (ut_assert_flag) {
1214 ut_assert_flag = KAL_FALSE; // clear flag
1215 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
1216 return KAL_FALSE;
1217 }
1218 status = DclSerialPort_UpModuleRegisterCb(handle, _rx_cb, NULL, NULL);
1219 if (ut_assert_flag == KAL_FALSE) {
1220 FAIL_MSG("Upper Module Register Callback");
1221 return KAL_FALSE;
1222 }
1223 ut_assert_flag = KAL_FALSE;
1224
1225 // Register callback - Conv Tx & Tx_Done_Cb is not null
1226 // Check there is no assert
1227 if (ut_assert_flag) {
1228 ut_assert_flag = KAL_FALSE; // clear flag
1229 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
1230 return KAL_FALSE;
1231 }
1232 status = DclSerialPort_UpModuleRegisterCb(handle, NULL, _tx_done_cb, NULL);
1233 if (ut_assert_flag == KAL_FALSE) {
1234 FAIL_MSG("Upper Module Register Callback");
1235 return KAL_FALSE;
1236 }
1237 ut_assert_flag = KAL_FALSE;
1238
1239 // Register callback - Conv Tx & Conv Rx & drv_state_change_cb is not null
1240 // Check there is no assert
1241 if (ut_assert_flag) {
1242 ut_assert_flag = KAL_FALSE; // clear flag
1243 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
1244 return KAL_FALSE;
1245 }
1246 status = DclSerialPort_UpModuleRegisterCb(handle, NULL, NULL, _drv_state_change_cb);
1247 if (ut_assert_flag == KAL_FALSE) {
1248 FAIL_MSG("Upper Module Register Callback");
1249 return KAL_FALSE;
1250 }
1251 ut_assert_flag = KAL_FALSE;
1252
1253 // De-Init - Avoid next time Init Failed)
1254 status = DclSerialPort_UpModuleDeinit(handle);
1255 if (status != STATUS_OK) {
1256 FAIL_MSG("De-Init Conv Tx & Conv Rx in Valid port");
1257 return KAL_FALSE;
1258 }
1259 }
1260 // New Rx & Rx_Cb is null
1261 // (New Tx or New Rx) & drv_state_change_cb is null
1262 for (device = uart_port1; device <= uart_max_port; device++) {
1263 handle = DclSerialPort_Open(device, 0);
1264
1265 // Init with New Rx Path
1266 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, TTY_FLAG_NEW_RX);
1267 if (status != STATUS_OK) {
1268 FAIL_MSG("Init New Rx in Valid port");
1269 return KAL_FALSE;
1270 }
1271
1272 // Register callback - New Rx & Rx_Cb is null
1273 // Check there is no assert
1274 if (ut_assert_flag) {
1275 ut_assert_flag = KAL_FALSE; // clear flag
1276 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
1277 return KAL_FALSE;
1278 }
1279 status = DclSerialPort_UpModuleRegisterCb(handle, NULL, _tx_done_cb, _drv_state_change_cb);
1280 if (ut_assert_flag == KAL_FALSE) {
1281 FAIL_MSG("Upper Module Register Callback");
1282 return KAL_FALSE;
1283 }
1284 ut_assert_flag = KAL_FALSE;
1285
1286 // Register callback - (New Tx or New Rx) & drv_state_change_cb is null
1287 // Check there is no assert
1288 if (ut_assert_flag) {
1289 ut_assert_flag = KAL_FALSE; // clear flag
1290 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
1291 return KAL_FALSE;
1292 }
1293 status = DclSerialPort_UpModuleRegisterCb(handle, _rx_cb, _tx_done_cb, NULL);
1294 if (ut_assert_flag == KAL_FALSE) {
1295 FAIL_MSG("Upper Module Register Callback");
1296 return KAL_FALSE;
1297 }
1298 ut_assert_flag = KAL_FALSE;
1299
1300 // De-Init - Avoid next time Init Failed)
1301 status = DclSerialPort_UpModuleDeinit(handle);
1302 if (status != STATUS_OK) {
1303 FAIL_MSG("De-Init New Rx in Valid port");
1304 return KAL_FALSE;
1305 }
1306 }
1307
1308 // Check there is no assert
1309 if (ut_assert_flag) {
1310 ut_assert_flag = KAL_FALSE; // clear flag
1311 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
1312 return KAL_FALSE;
1313 }
1314 return KAL_TRUE;
1315}
1316
1317kal_bool FuncVeri_ChangeOwner(void *p_param, kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
1318{
1319 DCL_DEV device;
1320 DCL_STATUS status;
1321 DCL_HANDLE handle;
1322 SIO_TYPE_T devtype;
1323 UART_CTRL_OPEN_T ur_ctrl_open;
1324 UART_CTRL_OWNER_T ur_ctrl_owner;
1325 Seriport_HANDLER_T drv_ut_handler;
1326
1327 /*
1328 * DclSerialPort_Control(handle, SIO_CMD_SET_OWNER, data)
1329 * - Description
1330 * It will flush all Tx/Rx gpd, then change port owner.
1331 *
1332 * This API will be invoked by new owner but not original owner.
1333 * If port will change to convention owner, you just call this API.
1334 * Or change to New Path owner, you must call the following two API.
1335 *
1336 * DclSerialPort_UpModuleReinit(handle, module_id, flag)
1337 * - Description
1338 * Re-Initializing the port setting without closing port.
1339 * Reset flags and Re-specify the Path of new owner.
1340 * DclSerialPort_UpModuleRegisterCb(handle, rx_cb, tx_done_cb, drv_state_change_cb)
1341 * - Description
1342 * Register Callback function for new owner.
1343 *
1344 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1345 * Scenario
1346 * Conditions | Expected result
1347 * ============================================================
1348 * Invalid port | STATUS_FAIL
1349 | STATUS_INVALID_DCL_HANDLE
1350 | STATUS_INVALID_DEVICE
1351 * valid port
1352 * port InActive | STATUS_DEVICE_NOT_EXIST
1353 * port Active with Attach/Detach | STATUS_OK
1354 *
1355 * Other Conditions
1356 * 4 types
1357 * Conv to Conv, Conv to New, New to Conv, New to New
1358 */
1359
1360 device = uart_port_null;
1361 handle = DclSerialPort_Open(device, 0);
1362 ur_ctrl_owner.u4OwenrId = MOD_TTY_UT;
1363 // Invalid Port Test
1364 status = DclSerialPort_Control(handle, SIO_CMD_SET_OWNER, (DCL_CTRL_DATA_T*) &ur_ctrl_owner);
1365 if (status != STATUS_FAIL) {
1366 FAIL_MSG("Change owner in Invalid port");
1367 return KAL_FALSE;
1368 }
1369
1370
1371 drv_ut_handler.SeriportHandlerCb = _drv_handler_cb;
1372 // Valid Port Test
1373 // Port InActive
1374 for (device = uart_port1; device <= uart_max_port; device++) {
1375 handle = DclSerialPort_Open(device, 0);
1376
1377 status = DclSerialPort_Control(handle, SIO_CMD_SET_OWNER, (DCL_CTRL_DATA_T*) &ur_ctrl_owner);
1378 if (status != STATUS_DEVICE_NOT_EXIST) {
1379 FAIL_MSG("Change owner with port InActive in Valid port");
1380 return KAL_FALSE;
1381 }
1382 }
1383
1384 // Port Active
1385 for (device = uart_port1; device <= uart_max_port; device++) {
1386 handle = DclSerialPort_Open(device, 0);
1387
1388 // Port Active with each device type
1389 for (devtype = DCL_UART_TYPE; devtype < DCL_UART_DEV_TYPE_MAX; devtype++){
1390 drv_ut_handler.DevType = devtype;
1391
1392 // Register callback (Active)
1393 status = DclSerialPort_DrvRegisterCb(handle, &drv_ut_handler);
1394 if (status != STATUS_OK) {
1395 FAIL_MSG("Driver Register Callback Failed! Device# = %d, DevType = %d", device, devtype);
1396 return KAL_FALSE;
1397 }
1398
1399 // Conv to Conv
1400 {
1401 char * Error_Tag = "[Conv to Conv] ";
1402
1403 ur_ctrl_open.u4OwenrId = MOD_TTY_UT;
1404 status = DclSerialPort_Control(handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*) &ur_ctrl_open);
1405 if (status != STATUS_OK) {
1406 FAIL_MSG_EXT(Error_Tag, "Conventional initialization");
1407 return KAL_FALSE;
1408 }
1409
1410 ur_ctrl_owner.u4OwenrId = MOD_TTY_UT;
1411 status = DclSerialPort_Control(handle, SIO_CMD_SET_OWNER, (DCL_CTRL_DATA_T*) &ur_ctrl_owner);
1412 if (status != STATUS_OK) {
1413 FAIL_MSG_EXT(Error_Tag, "Change owner to Conv owner");
1414 return KAL_FALSE;
1415 }
1416
1417 status = DclSerialPort_UpModuleDeinit(handle);
1418 if (status != STATUS_OK) {
1419 FAIL_MSG_EXT(Error_Tag, "De-initialization");
1420 return KAL_FALSE;
1421 }
1422 }
1423 // Conv to New
1424 {
1425 int flag = TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX;
1426 char * Error_Tag = "[Conv to New] ";
1427
1428 ur_ctrl_open.u4OwenrId = MOD_TTY_UT;
1429 status = DclSerialPort_Control(handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*) &ur_ctrl_open);
1430 if (status != STATUS_OK) {
1431 FAIL_MSG_EXT(Error_Tag, "Conventional initialization");
1432 return KAL_FALSE;
1433 }
1434
1435 ur_ctrl_owner.u4OwenrId = MOD_TTY_UT;
1436 status = DclSerialPort_Control(handle, SIO_CMD_SET_OWNER, (DCL_CTRL_DATA_T*) &ur_ctrl_owner);
1437 if (status != STATUS_OK) {
1438 FAIL_MSG_EXT(Error_Tag, "Change owner to New owner");
1439 return KAL_FALSE;
1440 }
1441
1442 status = DclSerialPort_UpModuleReinit(handle, MOD_TTY_UT, flag);
1443 if (status != STATUS_OK) {
1444 FAIL_MSG_EXT(Error_Tag, "New owner Re-Init");
1445 return KAL_FALSE;
1446 }
1447
1448 status = DclSerialPort_UpModuleRegisterCb(handle, _rx_cb, _tx_done_cb, _drv_state_change_cb);
1449 if (status != STATUS_OK) {
1450 FAIL_MSG_EXT(Error_Tag, "New owner Re-Register Callback");
1451 return KAL_FALSE;
1452 }
1453
1454 status = DclSerialPort_UpModuleDeinit(handle);
1455 if (status != STATUS_OK) {
1456 FAIL_MSG_EXT(Error_Tag, "De-initialization");
1457 return KAL_FALSE;
1458 }
1459 }
1460 // New to Conv
1461 {
1462 int flag = TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX;
1463 char * Error_Tag = "[New to Conv] ";
1464
1465
1466 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, flag);
1467 if (status != STATUS_OK) {
1468 FAIL_MSG_EXT(Error_Tag, "New Module initialization");
1469 return KAL_FALSE;
1470 }
1471
1472 status = DclSerialPort_UpModuleRegisterCb(handle, _rx_cb, _tx_done_cb, _drv_state_change_cb);
1473 if (status != STATUS_OK) {
1474 FAIL_MSG_EXT(Error_Tag, "New Module Register Callback");
1475 return KAL_FALSE;
1476 }
1477
1478 ur_ctrl_owner.u4OwenrId = MOD_TTY_UT;
1479 status = DclSerialPort_Control(handle, SIO_CMD_SET_OWNER, (DCL_CTRL_DATA_T*) &ur_ctrl_owner);
1480 if (status != STATUS_OK) {
1481 FAIL_MSG_EXT(Error_Tag, "Change owner to Conv owner");
1482 return KAL_FALSE;
1483 }
1484
1485 status = DclSerialPort_UpModuleDeinit(handle);
1486 if (status != STATUS_OK) {
1487 FAIL_MSG_EXT(Error_Tag, "De-initialization");
1488 return KAL_FALSE;
1489 }
1490 }
1491 // New to New
1492 {
1493 int flag = TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX;
1494 char * Error_Tag = "[New to New] ";
1495
1496
1497 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, flag);
1498 if (status != STATUS_OK) {
1499 FAIL_MSG_EXT(Error_Tag, "New Module initialization");
1500 return KAL_FALSE;
1501 }
1502
1503 status = DclSerialPort_UpModuleRegisterCb(handle, _rx_cb, _tx_done_cb, _drv_state_change_cb);
1504 if (status != STATUS_OK) {
1505 FAIL_MSG_EXT(Error_Tag, "New Module Register Callback");
1506 return KAL_FALSE;
1507 }
1508
1509 ur_ctrl_owner.u4OwenrId = MOD_TTY_UT;
1510 status = DclSerialPort_Control(handle, SIO_CMD_SET_OWNER, (DCL_CTRL_DATA_T*) &ur_ctrl_owner);
1511 if (status != STATUS_OK) {
1512 FAIL_MSG_EXT(Error_Tag, "Change owner to New owner");
1513 return KAL_FALSE;
1514 }
1515
1516 status = DclSerialPort_UpModuleReinit(handle, MOD_TTY_UT, flag);
1517 if (status != STATUS_OK) {
1518 FAIL_MSG_EXT(Error_Tag, "New owner Re-Init");
1519 return KAL_FALSE;
1520 }
1521
1522 status = DclSerialPort_UpModuleRegisterCb(handle, _rx_cb, _tx_done_cb, _drv_state_change_cb);
1523 if (status != STATUS_OK) {
1524 FAIL_MSG_EXT(Error_Tag, "New owner Re-Register Callback");
1525 return KAL_FALSE;
1526 }
1527
1528 status = DclSerialPort_UpModuleDeinit(handle);
1529 if (status != STATUS_OK) {
1530 FAIL_MSG_EXT(Error_Tag, "De-initialization");
1531 return KAL_FALSE;
1532 }
1533 }
1534
1535 // De-Register callback (InActive port - Avoid next time RegisterCb Failed)
1536 status = DclSerialPort_DrvDeRegisterCb(handle);
1537 if (status != STATUS_OK) {
1538 FAIL_MSG("Driver De-RegisterCb Failed! Device# = %d, DevType = %d", device, devtype);
1539 return KAL_FALSE;
1540 }
1541 }
1542 }
1543
1544
1545 return KAL_TRUE;
1546}
1547
1548kal_bool FuncVeri_Misc(void *p_param, kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
1549{
1550 DCL_HANDLE handle;
1551 /*
1552 * This Test Case Just For Function Coverage.
1553 * Nothing to be tested here.
1554 */
1555
1556 handle = DclSerialPort_Open(uart_port_null, 0);
1557
1558 DclSerialPort_Close(handle);
1559 DclSerialPort_Configure(handle, NULL);
1560
1561 return KAL_TRUE;
1562}
1563
1564/***********************************
1565 DataPath Verification
1566 ***********************************/
1567
1568 /*
1569 * In Data path verification,
1570 * We won't Test with each port, just test one to represent all.
1571 *
1572 * In each sub-case,
1573 * We will Test driver state change callback by initialing upper module
1574 * before driver register its callback.
1575 *
1576 * Before the operation of data transfer, it never check driver is attach
1577 * due to driver attach is expected here.
1578 */
1579
1580/**************
1581 Sub-Case
1582 **************/
1583kal_bool DataPath_Setup(DCL_HANDLE handle, SIO_TYPE_T devtype, int flag)
1584{
1585 DCL_STATUS status;
1586 Seriport_HANDLER_T drv_ut_handler;
1587
1588 // Upper Module Initialize
1589 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, flag);
1590 if (status != STATUS_OK)
1591 return KAL_FALSE;
1592
1593 // Only New Upper Module Need to register callback
1594 if (flag) {
1595 switch (flag) {
1596 case TTY_FLAG_NEW_TX:
1597 status = DclSerialPort_UpModuleRegisterCb(handle, NULL, _tx_done_cb, _drv_state_change_cb);
1598 break;
1599 case TTY_FLAG_NEW_RX:
1600 status = DclSerialPort_UpModuleRegisterCb(handle, _rx_cb, NULL, _drv_state_change_cb);
1601 break;
1602 case TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX:
1603 status = DclSerialPort_UpModuleRegisterCb(handle, _rx_cb, _tx_done_cb, _drv_state_change_cb);
1604 break;
1605 default:
1606 status = STATUS_FAIL;
1607 break;
1608 }
1609
1610 if (status != STATUS_OK)
1611 return KAL_FALSE;
1612 }
1613
1614 // Driver Register callback & Attach
1615 drv_ut_handler.DevType = devtype;
1616 drv_ut_handler.SeriportHandlerCb = _drv_handler_cb;
1617
1618 status = DclSerialPort_DrvRegisterCb(handle, &drv_ut_handler);
1619 if (status != STATUS_OK)
1620 return KAL_FALSE;
1621
1622 status = DclSerialPort_DrvAttach(handle);
1623 if (status != STATUS_OK)
1624 return KAL_FALSE;
1625
1626 return KAL_TRUE;
1627}
1628
1629kal_bool DataPath_Close(DCL_HANDLE handle)
1630{
1631 DCL_STATUS status;
1632
1633 // Upper Module DeInit
1634 status = DclSerialPort_UpModuleDeinit(handle);
1635 if (status != STATUS_OK)
1636 return KAL_FALSE;
1637
1638 // Driver Detatch
1639 status = DclSerialPort_DrvDetach(handle);
1640 if (status != STATUS_OK)
1641 return KAL_FALSE;
1642
1643 // Driver DeRegister Callback
1644 status = DclSerialPort_DrvDeRegisterCb(handle);
1645 if (status != STATUS_OK)
1646 return KAL_FALSE;
1647
1648 return KAL_TRUE;
1649}
1650
1651// Directly Path Sub-Case
1652kal_bool ConvTxPath(kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
1653{
1654 DCL_DEV device;
1655 DCL_STATUS status;
1656 DCL_HANDLE handle;
1657 SIO_TYPE_T devtype;
1658 kal_bool data_corrupt;
1659
1660 // Setup Port & Driver Type
1661 device = uart_port1;
1662 devtype = DCL_UART_USB_TYPE; // Driver type is GPD_DRV_TYPE
1663 data_corrupt = KAL_FALSE;
1664
1665 // Get handle
1666 handle = DclSerialPort_Open(device, 0);
1667
1668 // Upper Module Initialize & Driver Register callback and then Attach
1669 DataPath_Setup(handle, devtype, 0);
1670
1671 // if Upper Module is conventional & not buffer mode, driver will using ilm to inform upper module driver attach.
1672 {
1673 ilm_struct current_ilm;
1674
1675 msg_receive_extq(&current_ilm);
1676 if (current_ilm.msg_id != MSG_ID_UART_PLUGIN_IND) {
1677 destroy_ilm(&current_ilm);
1678 return KAL_FALSE;
1679 }
1680 destroy_ilm(&current_ilm);
1681 }
1682
1683 // Conventional Tx Path
1684 // Send Tx Data -> TxDoneCb -> Get "Ready to Write" ilm
1685 {
1686 UART_CTRL_PUT_BYTES_T ur_ctrl_putbytes;
1687 char SendBuff[UT_TEST_SIZE];
1688 int datalen;
1689 int offset;
1690 int i;
1691
1692 // Clear Hardware Buffer
1693 Hw_ClearBuff(device);
1694
1695 // Prepare Data to Send
1696 datalen = UT_TEST_SIZE;
1697 for (i = 0; i < datalen; i++) {
1698 SendBuff[i] = i & UT_DATA_MASK;
1699 }
1700
1701 // Setup Tx Buffer Structure
1702 offset = 0;
1703 ur_ctrl_putbytes.u4OwenrId = MOD_TTY_UT;
1704 ur_ctrl_putbytes.puBuffaddr = SendBuff;
1705 ur_ctrl_putbytes.u2Length = datalen;
1706
1707 // Sending Data Until Sending Complete
1708 do {
1709 // Dummy Upper Module
1710 {
1711 DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes);
1712 offset += ur_ctrl_putbytes.u2RetSize;
1713
1714 // Update Tx Buffer Structure
1715 ur_ctrl_putbytes.puBuffaddr = SendBuff + offset;
1716 ur_ctrl_putbytes.u2Length = datalen - offset;
1717 }
1718
1719 // Dummy Driver
1720 {
1721 // Return Tx GPD to TTYCore
1722 Tx_Flush_Gpd(device);
1723 }
1724
1725 // Dummy Upper Module
1726 {
1727 // In conventional path, _tty_tx_done_cb will send ilm to inform upper module.
1728 // when data buffer have the remaining data still haven't be sent.
1729 if (offset < datalen) {
1730 ilm_struct current_ilm;
1731
1732 msg_receive_extq(&current_ilm);
1733 if (current_ilm.msg_id != MSG_ID_UART_READY_TO_WRITE_IND) {
1734 destroy_ilm(&current_ilm);
1735 return KAL_FALSE;
1736 }
1737 destroy_ilm(&current_ilm);
1738 }
1739 }
1740 } while (offset < datalen);
1741
1742 // Compare data with Hardware Buffer
1743 for (i = 0; i < datalen; i++) {
1744 if (SendBuff[i] ^ Dev_Mgmt[device].HwBuff[i]) {
1745 data_corrupt = KAL_TRUE;
1746 break;
1747 }
1748 }
1749 }
1750
1751 // Upper Module DeInit & Driver Detatch & DeRegister Callback
1752 DataPath_Close(handle);
1753
1754 // Check data no corrupt
1755 if (data_corrupt) {
1756 FAIL_MSG("[ConvTxPath] Data Corrupt in Device# = %d, DevType = %d", device, devtype);
1757 return KAL_FALSE;
1758 }
1759
1760 // Check there is no assert
1761 if (ut_assert_flag) {
1762 ut_assert_flag = KAL_FALSE; // clear flag
1763 FAIL_MSG("[ConvTxPath] There is a assertion in exception. It's found at Test Case end");
1764 return KAL_FALSE;
1765 }
1766 return KAL_TRUE;
1767}
1768
1769kal_bool ConvRxPath(kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
1770{
1771 DCL_DEV device;
1772 DCL_STATUS status;
1773 DCL_HANDLE handle;
1774 SIO_TYPE_T devtype;
1775 kal_bool data_corrupt;
1776
1777 // Setup Port & Driver Type
1778 device = uart_port1;
1779 devtype = DCL_UART_USB_TYPE; // Driver type is GPD_DRV_TYPE
1780 data_corrupt = KAL_FALSE;
1781
1782 // Get handle
1783 handle = DclSerialPort_Open(device, 0);
1784
1785 // Upper Module Initialize & Driver Register callback and then Attach
1786 DataPath_Setup(handle, devtype, 0);
1787
1788 // if Upper Module is conventional & not buffer mode, driver will using ilm to inform upper module driver attach.
1789 {
1790 ilm_struct current_ilm;
1791
1792 msg_receive_extq(&current_ilm);
1793 if (current_ilm.msg_id != MSG_ID_UART_PLUGIN_IND) {
1794 destroy_ilm(&current_ilm);
1795 return KAL_FALSE;
1796 }
1797 destroy_ilm(&current_ilm);
1798 }
1799
1800 // Conventional Rx Path
1801 // Prepare Rx Data -> RxCb -> Get "Ready to Read" ilm -> Get Rx Data
1802 {
1803 UART_CTRL_GET_BYTES_T ur_ctrl_getbytes;
1804 char RecvBuff[UT_TEST_SIZE];
1805 int datalen;
1806 int offset;
1807 int i;
1808
1809 // Clear Hardware Buffer
1810 Hw_ClearBuff(device);
1811
1812 // Prepare Rx Data
1813 datalen = UT_TEST_SIZE;
1814 for (i = 0; i < datalen; i++) {
1815 Dev_Mgmt[device].HwBuff[i] = i & UT_DATA_MASK;
1816 }
1817 Dev_Mgmt[device].size = datalen;
1818
1819 // Setup Rx Buffer Structure
1820 offset = 0;
1821 ur_ctrl_getbytes.u4OwenrId = MOD_TTY_UT;
1822 ur_ctrl_getbytes.puBuffaddr = RecvBuff;
1823 ur_ctrl_getbytes.u2Length = datalen;
1824
1825 // Receiving Data Until Data empty in Hardware
1826 do {
1827 // Dummy Hardware Operation
1828 {
1829 // Copy Data to Driver Rx GPD in the Rx Queue
1830 Hw_PopDataToRxQue(device);
1831 }
1832
1833 // Dummy Driver
1834 {
1835 // Get Rx GPDs(Contain Received Data) by De-Q
1836 void * ior = Rx_DeQueToIor(device);
1837 // Rx callback to send ior to tty
1838 if (ior) {
1839 DclSerialPort_DrvRx(handle, DRV_TTY_UT, ior);
1840 }
1841 }
1842
1843 // Dummy Upper Module
1844 {
1845 // In conventional path, _tty_rx_cb will send ilm to inform upper module data ready to read.
1846 {
1847 ilm_struct current_ilm;
1848
1849 msg_receive_extq(&current_ilm);
1850 if (current_ilm.msg_id != MSG_ID_UART_READY_TO_READ_IND) {
1851 destroy_ilm(&current_ilm);
1852 return KAL_FALSE;
1853 }
1854 destroy_ilm(&current_ilm);
1855 }
1856
1857 // Get Data
1858 DclSerialPort_Control(handle, SIO_CMD_GET_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_getbytes);
1859 offset += ur_ctrl_getbytes.u2RetSize;
1860
1861 // Update Rx Buffer Structure
1862 ur_ctrl_getbytes.puBuffaddr = RecvBuff + offset;
1863 ur_ctrl_getbytes.u2Length = datalen - offset;
1864 }
1865 } while (Dev_Mgmt[device].size);
1866
1867 // Compare data with Hardware Buffer
1868 for (i = 0; i < datalen; i++) {
1869 if (RecvBuff[i] ^ Dev_Mgmt[device].HwBuff[i]) {
1870 data_corrupt = KAL_TRUE;
1871 break;
1872 }
1873 }
1874 }
1875
1876 // Upper Module DeInit & Driver Detatch & DeRegister Callback
1877 DataPath_Close(handle);
1878
1879 // Check data no corrupt
1880 if (data_corrupt) {
1881 FAIL_MSG("[ConvRxPath] Data Corrupt in Device# = %d, DevType = %d", device, devtype);
1882 return KAL_FALSE;
1883 }
1884
1885 // Check there is no assert
1886 if (ut_assert_flag) {
1887 ut_assert_flag = KAL_FALSE; // clear flag
1888 FAIL_MSG("[ConvRxPath] There is a assertion in exception. It's found at Test Case end");
1889 return KAL_FALSE;
1890 }
1891 return KAL_TRUE;
1892}
1893
1894kal_bool NewTxPath(kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
1895{
1896 DCL_DEV device;
1897 DCL_STATUS status;
1898 DCL_HANDLE handle;
1899 SIO_TYPE_T devtype;
1900 kal_bool data_corrupt;
1901
1902 // Setup Port & Driver Type
1903 device = uart_port1;
1904 devtype = DCL_UART_USB_TYPE; // Driver type is GPD_DRV_TYPE
1905 data_corrupt = KAL_FALSE;
1906
1907 // Get handle
1908 handle = DclSerialPort_Open(device, 0);
1909
1910 // Upper Module Initialize & Driver Register callback and then Attach
1911 DataPath_Setup(handle, devtype, TTY_FLAG_NEW_TX);
1912
1913 // New Tx Path
1914 // Send Tx Data -> TxDoneCb(For free gpds)
1915 {
1916 char SendBuff[UT_TEST_SIZE];
1917 int datalen;
1918 int offset;
1919 int i;
1920
1921 // Clear Hardware Buffer
1922 Hw_ClearBuff(device);
1923
1924 // Prepare Data to Send
1925 datalen = UT_TEST_SIZE;
1926 for (i = 0; i < datalen; i++) {
1927 SendBuff[i] = i & UT_DATA_MASK;
1928 }
1929
1930 // Setup Tx Buffer Structure
1931 offset = 0;
1932
1933 // Sending Data Until Sending Complete
1934 do {
1935 // Dummy Upper Module
1936 {
1937 void *gpd_t;
1938 void *p_head;
1939 void *p_tail;
1940 tty_io_request_t *ior;
1941 int gpd_num = 2;
1942
1943 // Create gpds for ior
1944 // GPD_TYPE: QBM_TYPE_TTY_INT
1945 // GPD_LEN: QBM_TTY_XXX_DATA_LEN(1024)
1946 qbmt_alloc_q_no_tail(QBM_TYPE_TTY_INT, gpd_num, &p_head, &p_tail);
1947 ior = (tty_io_request_t *)QBM_DES_GET_SW_CTRL_FIELD(p_head);
1948 ior->first_gpd = p_head;
1949 ior->last_gpd = p_tail;
1950
1951 // Copy data to gpds (the following code only suit for QBM_TYPE_TTY_INT)
1952 list_each_gpd(gpd_t, ior->first_gpd, ior->last_gpd) {
1953 int copylen = MIN(QBM_TTY_XXX_DATA_LEN, datalen - offset);
1954
1955 kal_mem_cpy(QBM_DES_GET_DATAPTR(gpd_t), SendBuff + offset, copylen);
1956 offset += copylen;
1957
1958 QBM_DES_SET_DATALEN(gpd_t, copylen);
1959 }
1960
1961 DclSerialPort_UpModuleTransmit(handle, ior);
1962 }
1963
1964 // Dummy Driver
1965 {
1966 // Free GPD or Return Tx GPD to Upper Module
1967 Tx_Flush_Gpd(device);
1968 }
1969 } while (offset < datalen);
1970
1971 // Compare data with Hardware Buffer
1972 for (i = 0; i < datalen; i++) {
1973 if (SendBuff[i] ^ Dev_Mgmt[device].HwBuff[i]) {
1974 data_corrupt = KAL_TRUE;
1975 break;
1976 }
1977 }
1978 }
1979
1980 // Upper Module DeInit & Driver Detatch & DeRegister Callback
1981 DataPath_Close(handle);
1982
1983 // Check data no corrupt
1984 if (data_corrupt) {
1985 FAIL_MSG("[NewTxPath] Data Corrupt in Device# = %d, DevType = %d", device, devtype);
1986 return KAL_FALSE;
1987 }
1988
1989 // Check there is no assert
1990 if (ut_assert_flag) {
1991 ut_assert_flag = KAL_FALSE; // clear flag
1992 FAIL_MSG("[NewTxPath] There is a assertion in exception. It's found at Test Case end");
1993 return KAL_FALSE;
1994 }
1995 return KAL_TRUE;
1996}
1997
1998kal_bool NewTxLightPath(kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
1999{
2000 DCL_DEV device;
2001 DCL_STATUS status;
2002 DCL_HANDLE handle;
2003 SIO_TYPE_T devtype;
2004 kal_bool data_corrupt;
2005
2006 // Setup Port & Driver Type
2007 device = uart_port1;
2008 devtype = DCL_UART_USB_TYPE; // Driver type is GPD_DRV_TYPE
2009 data_corrupt = KAL_FALSE;
2010
2011 // Get handle
2012 handle = DclSerialPort_Open(device, 0);
2013
2014 // Upper Module Initialize & Driver Register callback and then Attach
2015 DataPath_Setup(handle, devtype, TTY_FLAG_NEW_TX);
2016
2017 // New Tx Path
2018 // Send Tx Data -> TxDoneCb(For free gpds)
2019 {
2020 char SendBuff[UT_TEST_SIZE];
2021 int datalen;
2022 int offset;
2023 int i;
2024
2025 // Clear Hardware Buffer
2026 Hw_ClearBuff(device);
2027
2028 // Prepare Data to Send
2029 datalen = UT_TEST_SIZE;
2030 for (i = 0; i < datalen; i++) {
2031 SendBuff[i] = i & UT_DATA_MASK;
2032 }
2033
2034 // Setup Tx Buffer Structure
2035 offset = 0;
2036
2037 // Sending Data Until Sending Complete
2038 do {
2039 // Dummy Upper Module
2040 {
2041 void *gpd_t;
2042 void *p_head;
2043 void *p_tail;
2044 tty_io_request_t *ior;
2045 int gpd_num = 2;
2046
2047 // Create gpds for ior
2048 // GPD_TYPE: QBM_TYPE_TTY_INT
2049 // GPD_LEN: QBM_TTY_XXX_DATA_LEN(1024)
2050 qbmt_alloc_q_no_tail(QBM_TYPE_TTY_INT, gpd_num, &p_head, &p_tail);
2051 ior = (tty_io_request_t *)QBM_DES_GET_SW_CTRL_FIELD(p_head);
2052 ior->first_gpd = p_head;
2053 ior->last_gpd = p_tail;
2054
2055 // Copy data to gpds (the following code only suit for QBM_TYPE_TTY_INT)
2056 list_each_gpd(gpd_t, ior->first_gpd, ior->last_gpd) {
2057 int copylen = MIN(QBM_TTY_XXX_DATA_LEN, datalen - offset);
2058
2059 kal_mem_cpy(QBM_DES_GET_DATAPTR(gpd_t), SendBuff + offset, copylen);
2060 offset += copylen;
2061
2062 QBM_DES_SET_DATALEN(gpd_t, copylen);
2063 }
2064
2065 DclSerialPort_UpModuleTransmitLight(handle, ior);
2066 }
2067
2068 // Dummy Driver
2069 {
2070 // Free GPD or Return Tx GPD to Upper Module
2071 Tx_Flush_Gpd(device);
2072 }
2073 } while (offset < datalen);
2074
2075 // Compare data with Hardware Buffer
2076 for (i = 0; i < datalen; i++) {
2077 if (SendBuff[i] ^ Dev_Mgmt[device].HwBuff[i]) {
2078 data_corrupt = KAL_TRUE;
2079 break;
2080 }
2081 }
2082 }
2083
2084 // Upper Module DeInit & Driver Detatch & DeRegister Callback
2085 DataPath_Close(handle);
2086
2087 // Check data no corrupt
2088 if (data_corrupt) {
2089 FAIL_MSG("[NewTxPath] Data Corrupt in Device# = %d, DevType = %d", device, devtype);
2090 return KAL_FALSE;
2091 }
2092
2093 // Check there is no assert
2094 if (ut_assert_flag) {
2095 ut_assert_flag = KAL_FALSE; // clear flag
2096 FAIL_MSG("[NewTxPath] There is a assertion in exception. It's found at Test Case end");
2097 return KAL_FALSE;
2098 }
2099 return KAL_TRUE;
2100}
2101
2102kal_bool NewRxPath(kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
2103{
2104 DCL_DEV device;
2105 DCL_STATUS status;
2106 DCL_HANDLE handle;
2107 SIO_TYPE_T devtype;
2108 kal_bool data_corrupt;
2109
2110 // Setup Port & Driver Type
2111 device = uart_port1;
2112 devtype = DCL_UART_USB_TYPE; // Driver type is GPD_DRV_TYPE
2113 data_corrupt = KAL_FALSE;
2114
2115 // Get handle
2116 handle = DclSerialPort_Open(device, 0);
2117
2118 // Upper Module Initialize & Driver Register callback and then Attach
2119 DataPath_Setup(handle, devtype, TTY_FLAG_NEW_RX);
2120
2121 // New Rx Path
2122 // Send Rx gpds -> RxCb
2123 {
2124 char RecvBuff[UT_TEST_SIZE];
2125 int datalen;
2126 int offset;
2127 int i;
2128
2129 // Clear Hardware Buffer
2130 Hw_ClearBuff(device);
2131
2132 // Prepare Rx Data
2133 datalen = UT_TEST_SIZE;
2134 for (i = 0; i < datalen; i++) {
2135 Dev_Mgmt[device].HwBuff[i] = i & UT_DATA_MASK;
2136 }
2137 Dev_Mgmt[device].size = datalen;
2138
2139 // Setup Rx Buffer Structure
2140 offset = 0;
2141
2142
2143
2144 // Receiving Data Until Data empty in Hardware
2145 do {
2146 // Dummy Upper Module
2147 {
2148 void *p_head;
2149 void *p_tail;
2150 tty_io_request_t *ior;
2151 int gpd_num = 2;
2152
2153 // Create gpds for ior
2154 // GPD_TYPE: QBM_TYPE_TTY_INT
2155 // GPD_LEN: QBM_TTY_XXX_DATA_LEN(1024)
2156 qbmt_alloc_q(QBM_TYPE_TTY_INT, gpd_num, &p_head, &p_tail);
2157 ior = (tty_io_request_t *)QBM_DES_GET_SW_CTRL_FIELD(p_head);
2158 ior->first_gpd = p_head;
2159 ior->last_gpd = p_tail;
2160
2161 // Send Rx_Ior to Driver
2162 DclSerialPort_UpModuleAssignRxIor(handle, ior);
2163 }
2164
2165 // Dummy Hardware Operation
2166 {
2167 // Copy Data to Driver Rx GPD in the Rx Queue
2168 Hw_PopDataToRxQue(device);
2169 }
2170
2171 // Dummy Driver
2172 {
2173 // Get Rx GPDs(Contain Received Data) by De-Q
2174 void * ior = Rx_DeQueToIor(device);
2175 // Rx callback to send ior to tty
2176 DclSerialPort_DrvRx(handle, DRV_TTY_UT, ior);
2177 }
2178
2179 // Dummy Upper Module
2180 {
2181 if (Dev_Mgmt[device].Rx_Ior) {
2182 void *gpd_t;
2183
2184 // Copy data from gpds (the following code only suit for QBM_TYPE_TTY_INT)
2185 list_each_gpd(gpd_t, Dev_Mgmt[device].Rx_Ior->first_gpd, Dev_Mgmt[device].Rx_Ior->last_gpd) {
2186 int copylen = MIN(QBM_TTY_XXX_DATA_LEN, QBM_DES_GET_DATALEN(gpd_t));
2187
2188 kal_mem_cpy(RecvBuff + offset, QBM_DES_GET_DATAPTR(gpd_t), copylen);
2189 offset += copylen;
2190 }
2191 // Free Rx Ior
2192 qbmt_dest_q(Dev_Mgmt[device].Rx_Ior->first_gpd, Dev_Mgmt[device].Rx_Ior->last_gpd);
2193 }
2194 }
2195 } while (offset < datalen);
2196
2197 // Compare data with Hardware Buffer
2198 for (i = 0; i < datalen; i++) {
2199 if (RecvBuff[i] ^ Dev_Mgmt[device].HwBuff[i]) {
2200 data_corrupt = KAL_TRUE;
2201 break;
2202 }
2203 }
2204 }
2205
2206 // Upper Module DeInit & Driver Detatch & DeRegister Callback
2207 DataPath_Close(handle);
2208
2209 // Check data no corrupt
2210 if (data_corrupt) {
2211 FAIL_MSG("[NewRxPath] Data Corrupt in Device# = %d, DevType = %d", device, devtype);
2212 return KAL_FALSE;
2213 }
2214
2215 // Check there is no assert
2216 if (ut_assert_flag) {
2217 ut_assert_flag = KAL_FALSE; // clear flag
2218 FAIL_MSG("[NewRxPath] There is a assertion in exception. It's found at Test Case end");
2219 return KAL_FALSE;
2220 }
2221 return KAL_TRUE;
2222}
2223
2224kal_bool BuffModTxPath(kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
2225{
2226 DCL_DEV device;
2227 DCL_STATUS status;
2228 DCL_HANDLE handle;
2229 SIO_TYPE_T devtype;
2230 kal_bool data_corrupt;
2231
2232 // Setup Port & Driver Type
2233 device = uart_port1;
2234 devtype = DCL_UART_CMUX_TYPE; // Driver type is BUFF_DRV_TYPE
2235 data_corrupt = KAL_FALSE;
2236
2237 // Get handle
2238 handle = DclSerialPort_Open(device, 0);
2239
2240 // Upper Module Initialize & Driver Register callback and then Attach
2241 DataPath_Setup(handle, devtype, 0);
2242
2243 // Conventional Tx Path
2244 // Send Tx Data -> TxDoneCb -> Get "Ready to Write" ilm
2245 {
2246 UART_CTRL_PUT_BYTES_T ur_ctrl_putbytes;
2247 char SendBuff[UT_TEST_SIZE];
2248 int datalen;
2249 int offset;
2250 int i;
2251
2252 // Clear Hardware Buffer
2253 Hw_ClearBuff(device);
2254
2255 // Prepare Data to Send
2256 datalen = UT_TEST_SIZE;
2257 for (i = 0; i < datalen; i++) {
2258 SendBuff[i] = i & UT_DATA_MASK;
2259 }
2260
2261
2262 // Setup Tx Buffer Structure
2263 offset = 0;
2264 ur_ctrl_putbytes.u4OwenrId = MOD_TTY_UT;
2265 ur_ctrl_putbytes.puBuffaddr = SendBuff;
2266 ur_ctrl_putbytes.u2Length = datalen;
2267
2268 // Sending Data Until Sending Complete
2269 do {
2270 // Dummy Upper Module
2271 {
2272 DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes);
2273 offset += ur_ctrl_putbytes.u2RetSize;
2274
2275 // Update Tx Buffer Structure
2276 ur_ctrl_putbytes.puBuffaddr = SendBuff + offset;
2277 ur_ctrl_putbytes.u2Length = datalen - offset;
2278 }
2279
2280 // Dummy Driver
2281 {
2282 // Using TxDoneCb to inform TTYCore
2283 DclSerialPort_DrvTxDone(handle, DRV_TTY_UT, NULL);
2284 }
2285
2286 // Dummy Upper Module
2287 {
2288 // In conventional path, _tty_tx_done_cb will send ilm to inform upper module.
2289 // when data buffer have the remaining data still haven't be sent.
2290 if (offset < datalen) {
2291 ilm_struct current_ilm;
2292
2293 msg_receive_extq(&current_ilm);
2294 if (current_ilm.msg_id != MSG_ID_UART_READY_TO_WRITE_IND) {
2295 destroy_ilm(&current_ilm);
2296 return KAL_FALSE;
2297 }
2298 destroy_ilm(&current_ilm);
2299 }
2300 }
2301 } while (offset < datalen);
2302
2303 // Compare data with Hardware Buffer
2304 for (i = 0; i < datalen; i++) {
2305 if (SendBuff[i] ^ Dev_Mgmt[device].HwBuff[i]) {
2306 data_corrupt = KAL_TRUE;
2307 break;
2308 }
2309 }
2310 }
2311
2312 // Upper Module DeInit & Driver Detatch & DeRegister Callback
2313 DataPath_Close(handle);
2314
2315 // Check data no corrupt
2316 if (data_corrupt) {
2317 FAIL_MSG("[BuffModTxPath] Data Corrupt in Device# = %d, DevType = %d", device, devtype);
2318 return KAL_FALSE;
2319 }
2320
2321 // Check there is no assert
2322 if (ut_assert_flag) {
2323 ut_assert_flag = KAL_FALSE; // clear flag
2324 FAIL_MSG("[BuffModTxPath] There is a assertion in exception. It's found at Test Case end");
2325 return KAL_FALSE;
2326 }
2327 return KAL_TRUE;
2328}
2329
2330kal_bool BuffModRxPath(kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
2331{
2332 DCL_DEV device;
2333 DCL_STATUS status;
2334 DCL_HANDLE handle;
2335 SIO_TYPE_T devtype;
2336 kal_bool data_corrupt;
2337
2338 // Setup Port & Driver Type
2339 device = uart_port1;
2340 devtype = DCL_UART_CMUX_TYPE; // Driver type is BUFF_DRV_TYPE
2341 data_corrupt = KAL_FALSE;
2342
2343 // Get handle
2344 handle = DclSerialPort_Open(device, 0);
2345
2346 // Upper Module Initialize & Driver Register callback and then Attach
2347 DataPath_Setup(handle, devtype, 0);
2348
2349 // Conventional Rx Path
2350 // Prepare Rx Data -> RxCb -> Get "Ready to Read" ilm -> Get Rx Data
2351 {
2352 UART_CTRL_GET_BYTES_T ur_ctrl_getbytes;
2353 char RecvBuff[UT_TEST_SIZE];
2354 int datalen;
2355 int offset;
2356 int i;
2357
2358 // Clear Hardware Buffer
2359 Hw_ClearBuff(device);
2360
2361 // Prepare Rx Data
2362 datalen = UT_TEST_SIZE;
2363 for (i = 0; i < datalen; i++) {
2364 Dev_Mgmt[device].HwBuff[i] = i & UT_DATA_MASK;
2365 }
2366 Dev_Mgmt[device].size = datalen;
2367
2368 // Setup Rx Buffer Structure
2369 offset = 0;
2370 ur_ctrl_getbytes.u4OwenrId = MOD_TTY_UT;
2371 ur_ctrl_getbytes.puBuffaddr = RecvBuff;
2372 ur_ctrl_getbytes.u2Length = datalen;
2373
2374
2375 // Dummy Driver
2376 {
2377 // Using RxCb to inform TTYCore
2378 DclSerialPort_DrvRx(handle, DRV_TTY_UT, NULL);
2379
2380 // It will raise the flag rx_up_mod_wait at Rx buffer mode initial
2381 // When using Rx_Cb to inform TTYCore it will send ilm at first time.
2382 {
2383 ilm_struct current_ilm;
2384
2385 msg_receive_extq(&current_ilm);
2386 if (current_ilm.msg_id != MSG_ID_UART_READY_TO_READ_IND) {
2387 destroy_ilm(&current_ilm);
2388 return KAL_FALSE;
2389 }
2390 destroy_ilm(&current_ilm);
2391 }
2392 }
2393 do {
2394 // Dummy Upper Module
2395 {
2396 // Get Data
2397 DclSerialPort_Control(handle, SIO_CMD_GET_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_getbytes);
2398 offset += ur_ctrl_getbytes.u2RetSize;
2399
2400 // Update Rx Buffer Structure
2401 ur_ctrl_getbytes.puBuffaddr = RecvBuff + offset;
2402 ur_ctrl_getbytes.u2Length = datalen - offset;
2403 }
2404
2405 ///TODO: check there is no ilm because there is sent in SIO_CMD_GET_RX_AVAIL
2406 } while (Dev_Mgmt[device].size);
2407
2408 // Compare data with Hardware Buffer
2409 for (i = 0; i < datalen; i++) {
2410 if (RecvBuff[i] ^ Dev_Mgmt[device].HwBuff[i]) {
2411 data_corrupt = KAL_TRUE;
2412 break;
2413 }
2414 }
2415 }
2416
2417 // Upper Module DeInit & Driver Detatch & DeRegister Callback
2418 DataPath_Close(handle);
2419
2420 // Check data no corrupt
2421 if (data_corrupt) {
2422 FAIL_MSG("[BuffModRxPath] Data Corrupt in Device# = %d, DevType = %d", device, devtype);
2423 return KAL_FALSE;
2424 }
2425
2426 // Check there is no assert
2427 if (ut_assert_flag) {
2428 ut_assert_flag = KAL_FALSE; // clear flag
2429 FAIL_MSG("[BuffModRxPath] There is a assertion in exception. It's found at Test Case end");
2430 return KAL_FALSE;
2431 }
2432 return KAL_TRUE;
2433}
2434
2435// Loopback Test Sub-Case
2436kal_bool NewTx_NewRx(kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
2437{
2438 DCL_DEV device;
2439 DCL_STATUS status;
2440 DCL_HANDLE handle;
2441 SIO_TYPE_T devtype;
2442 kal_bool data_corrupt;
2443
2444 // Setup Port & Driver Type
2445 device = uart_port1;
2446 devtype = DCL_UART_USB_TYPE; // Driver type is GPD_DRV_TYPE
2447 data_corrupt = KAL_FALSE;
2448
2449 // Get handle
2450 handle = DclSerialPort_Open(device, 0);
2451
2452 // Upper Module Initialize & Driver Register callback and then Attach
2453 DataPath_Setup(handle, devtype, TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX);
2454
2455 // Send Tx Data -> TxDoneCb(For free gpds) -> Send Rx gpds -> RxCb
2456 {
2457 char SendBuff[UT_TEST_SIZE];
2458 char RecvBuff[UT_TEST_SIZE];
2459 int datalen;
2460 int s_offset;
2461 int r_offset;
2462 int i;
2463
2464 // Clear Hardware Buffer
2465 Hw_ClearBuff(device);
2466
2467 // Prepare Data to Send
2468 datalen = UT_TEST_SIZE;
2469 for (i = 0; i < datalen; i++) {
2470 SendBuff[i] = i & UT_DATA_MASK;
2471 }
2472
2473 // Setup Buffer Structure
2474 s_offset = 0;
2475 r_offset = 0;
2476
2477 // Sending Data Until Sending Complete
2478 do {
2479 // Dummy Upper Module
2480 {
2481 void *gpd_t;
2482 void *p_head;
2483 void *p_tail;
2484 tty_io_request_t *ior;
2485 int gpd_num = 2;
2486
2487 // Create gpds for ior
2488 // GPD_TYPE: QBM_TYPE_TTY_INT
2489 // GPD_LEN: QBM_TTY_XXX_DATA_LEN(1024)
2490 qbmt_alloc_q_no_tail(QBM_TYPE_TTY_INT, gpd_num, &p_head, &p_tail);
2491 ior = (tty_io_request_t *)QBM_DES_GET_SW_CTRL_FIELD(p_head);
2492 ior->first_gpd = p_head;
2493 ior->last_gpd = p_tail;
2494
2495 // Copy data to gpds (the following code only suit for QBM_TYPE_TTY_INT)
2496 list_each_gpd(gpd_t, ior->first_gpd, ior->last_gpd) {
2497 int copylen = MIN(QBM_TTY_XXX_DATA_LEN, datalen - s_offset);
2498
2499 kal_mem_cpy(QBM_DES_GET_DATAPTR(gpd_t), SendBuff + s_offset, copylen);
2500 s_offset += copylen;
2501
2502 QBM_DES_SET_DATALEN(gpd_t, copylen);
2503 }
2504
2505 DclSerialPort_UpModuleTransmit(handle, ior);
2506 }
2507
2508 // Dummy Driver
2509 {
2510 // Free GPD or Return Tx GPD to Upper Module
2511 Tx_Flush_Gpd(device);
2512 }
2513 } while (s_offset < datalen);
2514
2515 // Receiving Data Until Data empty in Hardware
2516 do {
2517 // Dummy Upper Module
2518 {
2519 void *p_head;
2520 void *p_tail;
2521 tty_io_request_t *ior;
2522 int gpd_num = 2;
2523
2524 // Create gpds for ior
2525 // GPD_TYPE: QBM_TYPE_TTY_INT
2526 // GPD_LEN: QBM_TTY_XXX_DATA_LEN(1024)
2527 qbmt_alloc_q(QBM_TYPE_TTY_INT, gpd_num, &p_head, &p_tail);
2528 ior = (tty_io_request_t *)QBM_DES_GET_SW_CTRL_FIELD(p_head);
2529 ior->first_gpd = p_head;
2530 ior->last_gpd = p_tail;
2531
2532 // Send Rx_Ior to Driver
2533 DclSerialPort_UpModuleAssignRxIor(handle, ior);
2534 }
2535
2536 // Dummy Hardware Operation
2537 {
2538 // Copy Data to Driver Rx GPD in the Rx Queue
2539 Hw_PopDataToRxQue(device);
2540 }
2541
2542 // Dummy Driver
2543 {
2544 // Get Rx GPDs(Contain Received Data) by De-Q
2545 void * ior = Rx_DeQueToIor(device);
2546 // Rx callback to send ior to tty
2547 DclSerialPort_DrvRx(handle, DRV_TTY_UT, ior);
2548 }
2549
2550 // Dummy Upper Module
2551 {
2552 if (Dev_Mgmt[device].Rx_Ior) {
2553 void *gpd_t;
2554
2555 // Copy data from gpds (the following code only suit for QBM_TYPE_TTY_INT)
2556 list_each_gpd(gpd_t, Dev_Mgmt[device].Rx_Ior->first_gpd, Dev_Mgmt[device].Rx_Ior->last_gpd) {
2557 int copylen = MIN(QBM_TTY_XXX_DATA_LEN, QBM_DES_GET_DATALEN(gpd_t));
2558
2559 kal_mem_cpy(RecvBuff + r_offset, QBM_DES_GET_DATAPTR(gpd_t), copylen);
2560 r_offset += copylen;
2561 }
2562 // Free Rx Ior
2563 qbmt_dest_q(Dev_Mgmt[device].Rx_Ior->first_gpd, Dev_Mgmt[device].Rx_Ior->last_gpd);
2564 }
2565 }
2566 } while (r_offset < datalen);
2567
2568 // Compare data between Send Buffer & Receive Buffer
2569 for (i = 0; i < datalen; i++) {
2570 if (SendBuff[i] ^ RecvBuff[i]) {
2571 data_corrupt = KAL_TRUE;
2572 break;
2573 }
2574 }
2575 }
2576
2577 // Upper Module DeInit & Driver Detatch & DeRegister Callback
2578 DataPath_Close(handle);
2579
2580 // Check data no corrupt
2581 if (data_corrupt) {
2582 FAIL_MSG("Data Corrupt in Device# = %d, DevType = %d", device, devtype);
2583 return KAL_FALSE;
2584 }
2585
2586 // Check there is no assert
2587 if (ut_assert_flag) {
2588 ut_assert_flag = KAL_FALSE; // clear flag
2589 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
2590 return KAL_FALSE;
2591 }
2592 return KAL_TRUE;
2593}
2594
2595kal_bool NewTx_ConvRx(kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
2596{
2597 DCL_DEV device;
2598 DCL_STATUS status;
2599 DCL_HANDLE handle;
2600 SIO_TYPE_T devtype;
2601 kal_bool data_corrupt;
2602
2603 // Setup Port & Driver Type
2604 device = uart_port1;
2605 devtype = DCL_UART_USB_TYPE; // Driver type is GPD_DRV_TYPE
2606 data_corrupt = KAL_FALSE;
2607
2608 // Get handle
2609 handle = DclSerialPort_Open(device, 0);
2610
2611 // Upper Module Initialize & Driver Register callback and then Attach
2612 DataPath_Setup(handle, devtype, TTY_FLAG_NEW_TX);
2613
2614 // Send Tx Data -> TxDoneCb(For free gpds) -> RxCb -> Send Rx Buffer
2615 {
2616 UART_CTRL_GET_BYTES_T ur_ctrl_getbytes;
2617 char SendBuff[UT_TEST_SIZE];
2618 char RecvBuff[UT_TEST_SIZE];
2619 int datalen;
2620 int s_offset;
2621 int r_offset;
2622 int i;
2623
2624 // Clear Hardware Buffer
2625 Hw_ClearBuff(device);
2626
2627 // Prepare Data to Send
2628 datalen = UT_TEST_SIZE;
2629 for (i = 0; i < datalen; i++) {
2630 SendBuff[i] = i & UT_DATA_MASK;
2631 }
2632
2633 // Setup Tx Buffer Structure
2634 s_offset = 0;
2635 r_offset = 0;
2636 ur_ctrl_getbytes.u4OwenrId = MOD_TTY_UT;
2637 ur_ctrl_getbytes.puBuffaddr = RecvBuff;
2638 ur_ctrl_getbytes.u2Length = datalen;
2639
2640 // Sending Data Until Sending Complete
2641 do {
2642 // Dummy Upper Module
2643 {
2644 void *gpd_t;
2645 void *p_head;
2646 void *p_tail;
2647 tty_io_request_t *ior;
2648 int gpd_num = 2;
2649
2650 // Create gpds for ior
2651 // GPD_TYPE: QBM_TYPE_TTY_INT
2652 // GPD_LEN: QBM_TTY_XXX_DATA_LEN(1024)
2653 qbmt_alloc_q_no_tail(QBM_TYPE_TTY_INT, gpd_num, &p_head, &p_tail);
2654 ior = (tty_io_request_t *)QBM_DES_GET_SW_CTRL_FIELD(p_head);
2655 ior->first_gpd = p_head;
2656 ior->last_gpd = p_tail;
2657
2658 // Copy data to gpds (the following code only suit for QBM_TYPE_TTY_INT)
2659 list_each_gpd(gpd_t, ior->first_gpd, ior->last_gpd) {
2660 int copylen = MIN(QBM_TTY_XXX_DATA_LEN, datalen - s_offset);
2661
2662 kal_mem_cpy(QBM_DES_GET_DATAPTR(gpd_t), SendBuff + s_offset, copylen);
2663 s_offset += copylen;
2664
2665 QBM_DES_SET_DATALEN(gpd_t, copylen);
2666 }
2667
2668 DclSerialPort_UpModuleTransmit(handle, ior);
2669 }
2670
2671 // Dummy Driver
2672 {
2673 // Free GPD or Return Tx GPD to Upper Module
2674 Tx_Flush_Gpd(device);
2675 }
2676 } while (s_offset < datalen);
2677
2678 // Receiving Data Until Data empty in Hardware
2679 do {
2680 // Dummy Hardware Operation
2681 {
2682 // Copy Data to Driver Rx GPD in the Rx Queue
2683 Hw_PopDataToRxQue(device);
2684 }
2685
2686 // Dummy Driver
2687 {
2688 // Get Rx GPDs(Contain Received Data) by De-Q
2689 void * ior = Rx_DeQueToIor(device);
2690 // Rx callback to send ior to tty
2691 if (ior) {
2692 DclSerialPort_DrvRx(handle, DRV_TTY_UT, ior);
2693 }
2694 }
2695
2696 // Dummy Upper Module
2697 {
2698 // In conventional path, _tty_rx_cb will send ilm to inform upper module data ready to read.
2699 {
2700 ilm_struct current_ilm;
2701
2702 msg_receive_extq(&current_ilm);
2703 if (current_ilm.msg_id != MSG_ID_UART_READY_TO_READ_IND) {
2704 destroy_ilm(&current_ilm);
2705 return KAL_FALSE;
2706 }
2707 destroy_ilm(&current_ilm);
2708 }
2709
2710 // Get Data
2711 DclSerialPort_Control(handle, SIO_CMD_GET_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_getbytes);
2712 r_offset += ur_ctrl_getbytes.u2RetSize;
2713
2714 // Update Rx Buffer Structure
2715 ur_ctrl_getbytes.puBuffaddr = RecvBuff + r_offset;
2716 ur_ctrl_getbytes.u2Length = datalen - r_offset;
2717 }
2718 } while (Dev_Mgmt[device].size);
2719
2720 // Compare data between Send Buffer & Receive Buffer
2721 for (i = 0; i < datalen; i++) {
2722 if (SendBuff[i] ^ RecvBuff[i]) {
2723 data_corrupt = KAL_TRUE;
2724 break;
2725 }
2726 }
2727 }
2728
2729 // Upper Module DeInit & Driver Detatch & DeRegister Callback
2730 DataPath_Close(handle);
2731
2732 // Check data no corrupt
2733 if (data_corrupt) {
2734 FAIL_MSG("Data Corrupt in Device# = %d, DevType = %d", device, devtype);
2735 return KAL_FALSE;
2736 }
2737
2738 // Check there is no assert
2739 if (ut_assert_flag) {
2740 ut_assert_flag = KAL_FALSE; // clear flag
2741 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
2742 return KAL_FALSE;
2743 }
2744 return KAL_TRUE;
2745}
2746
2747kal_bool ConvTx_NewRx(kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
2748{
2749 DCL_DEV device;
2750 DCL_STATUS status;
2751 DCL_HANDLE handle;
2752 SIO_TYPE_T devtype;
2753 kal_bool data_corrupt;
2754
2755 // Setup Port & Driver Type
2756 device = uart_port1;
2757 devtype = DCL_UART_USB_TYPE; // Driver type is GPD_DRV_TYPE
2758 data_corrupt = KAL_FALSE;
2759
2760 // Get handle
2761 handle = DclSerialPort_Open(device, 0);
2762
2763 // Upper Module Initialize & Driver Register callback and then Attach
2764 DataPath_Setup(handle, devtype, TTY_FLAG_NEW_RX);
2765
2766 // Send Tx Data -> TxDoneCb -> Get "Ready to Write" ilm -> Send Rx gpds -> RxCb
2767 {
2768 UART_CTRL_PUT_BYTES_T ur_ctrl_putbytes;
2769 char SendBuff[UT_TEST_SIZE];
2770 char RecvBuff[UT_TEST_SIZE];
2771 int datalen;
2772 int s_offset;
2773 int r_offset;
2774 int i;
2775
2776 // Clear Hardware Buffer
2777 Hw_ClearBuff(device);
2778
2779 // Prepare Data to Send
2780 datalen = UT_TEST_SIZE;
2781 for (i = 0; i < datalen; i++) {
2782 SendBuff[i] = i & UT_DATA_MASK;
2783 }
2784
2785 // Setup Buffer Structure
2786 s_offset = 0;
2787 ur_ctrl_putbytes.u4OwenrId = MOD_TTY_UT;
2788 ur_ctrl_putbytes.puBuffaddr = SendBuff;
2789 ur_ctrl_putbytes.u2Length = datalen;
2790 r_offset = 0;
2791
2792 // Sending Data Until Sending Complete
2793 do {
2794 // Dummy Upper Module
2795 {
2796 DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes);
2797 s_offset += ur_ctrl_putbytes.u2RetSize;
2798
2799 // Update Tx Buffer Structure
2800 ur_ctrl_putbytes.puBuffaddr = SendBuff + s_offset;
2801 ur_ctrl_putbytes.u2Length = datalen - s_offset;
2802 }
2803
2804 // Dummy Driver
2805 {
2806 // Return Tx GPD to TTYCore
2807 Tx_Flush_Gpd(device);
2808 }
2809
2810 // Dummy Upper Module
2811 {
2812 // In conventional path, _tty_tx_done_cb will send ilm to inform upper module.
2813 // when data buffer have the remaining data still haven't be sent.
2814 if (s_offset < datalen) {
2815 ilm_struct current_ilm;
2816
2817 msg_receive_extq(&current_ilm);
2818 if (current_ilm.msg_id != MSG_ID_UART_READY_TO_WRITE_IND) {
2819 destroy_ilm(&current_ilm);
2820 return KAL_FALSE;
2821 }
2822 destroy_ilm(&current_ilm);
2823 }
2824 }
2825 } while (s_offset < datalen);
2826
2827 // Receiving Data Until Data empty in Hardware
2828 do {
2829 // Dummy Upper Module
2830 {
2831 void *p_head;
2832 void *p_tail;
2833 tty_io_request_t *ior;
2834 int gpd_num = 2;
2835
2836 // Create gpds for ior
2837 // GPD_TYPE: QBM_TYPE_TTY_INT
2838 // GPD_LEN: QBM_TTY_XXX_DATA_LEN(1024)
2839 qbmt_alloc_q(QBM_TYPE_TTY_INT, gpd_num, &p_head, &p_tail);
2840 ior = (tty_io_request_t *)QBM_DES_GET_SW_CTRL_FIELD(p_head);
2841 ior->first_gpd = p_head;
2842 ior->last_gpd = p_tail;
2843
2844 // Send Rx_Ior to Driver
2845 DclSerialPort_UpModuleAssignRxIor(handle, ior);
2846 }
2847
2848 // Dummy Hardware Operation
2849 {
2850 // Copy Data to Driver Rx GPD in the Rx Queue
2851 Hw_PopDataToRxQue(device);
2852 }
2853
2854 // Dummy Driver
2855 {
2856 // Get Rx GPDs(Contain Received Data) by De-Q
2857 void * ior = Rx_DeQueToIor(device);
2858 // Rx callback to send ior to tty
2859 DclSerialPort_DrvRx(handle, DRV_TTY_UT, ior);
2860 }
2861
2862 // Dummy Upper Module
2863 {
2864 if (Dev_Mgmt[device].Rx_Ior) {
2865 void *gpd_t;
2866
2867 // Copy data from gpds (the following code only suit for QBM_TYPE_TTY_INT)
2868 list_each_gpd(gpd_t, Dev_Mgmt[device].Rx_Ior->first_gpd, Dev_Mgmt[device].Rx_Ior->last_gpd) {
2869 int copylen = MIN(QBM_TTY_XXX_DATA_LEN, QBM_DES_GET_DATALEN(gpd_t));
2870
2871 kal_mem_cpy(RecvBuff + r_offset, QBM_DES_GET_DATAPTR(gpd_t), copylen);
2872 r_offset += copylen;
2873 }
2874 // Free Rx Ior
2875 qbmt_dest_q(Dev_Mgmt[device].Rx_Ior->first_gpd, Dev_Mgmt[device].Rx_Ior->last_gpd);
2876 }
2877 }
2878 } while (r_offset < datalen);
2879
2880 // Compare data between Send Buffer & Receive Buffer
2881 for (i = 0; i < datalen; i++) {
2882 if (SendBuff[i] ^ RecvBuff[i]) {
2883 data_corrupt = KAL_TRUE;
2884 break;
2885 }
2886 }
2887 }
2888
2889 // Upper Module DeInit & Driver Detatch & DeRegister Callback
2890 DataPath_Close(handle);
2891
2892 // Check data no corrupt
2893 if (data_corrupt) {
2894 FAIL_MSG("Data Corrupt in Device# = %d, DevType = %d", device, devtype);
2895 return KAL_FALSE;
2896 }
2897
2898 // Check there is no assert
2899 if (ut_assert_flag) {
2900 ut_assert_flag = KAL_FALSE; // clear flag
2901 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
2902 return KAL_FALSE;
2903 }
2904 return KAL_TRUE;
2905}
2906
2907kal_bool ConvTx_ConvRx(kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
2908{
2909 DCL_DEV device;
2910 DCL_STATUS status;
2911 DCL_HANDLE handle;
2912 SIO_TYPE_T devtype;
2913 kal_bool data_corrupt;
2914
2915 // Setup Port & Driver Type
2916 device = uart_port1;
2917 devtype = DCL_UART_USB_TYPE; // Driver type is GPD_DRV_TYPE
2918 data_corrupt = KAL_FALSE;
2919
2920 // Get handle
2921 handle = DclSerialPort_Open(device, 0);
2922
2923 // Upper Module Initialize & Driver Register callback and then Attach
2924 DataPath_Setup(handle, devtype, 0);
2925
2926 // if Upper Module is conventional & not buffer mode, driver will using ilm to inform upper module driver attach.
2927 {
2928 ilm_struct current_ilm;
2929
2930 msg_receive_extq(&current_ilm);
2931 if (current_ilm.msg_id != MSG_ID_UART_PLUGIN_IND) {
2932 destroy_ilm(&current_ilm);
2933 return KAL_FALSE;
2934 }
2935 destroy_ilm(&current_ilm);
2936 }
2937
2938 // Send Tx Data -> TxDoneCb -> Get "Ready to Write" ilm -> RxCb -> Send Rx gpds
2939 {
2940 UART_CTRL_PUT_BYTES_T ur_ctrl_putbytes;
2941 UART_CTRL_GET_BYTES_T ur_ctrl_getbytes;
2942 char SendBuff[UT_TEST_SIZE];
2943 char RecvBuff[UT_TEST_SIZE];
2944 int datalen;
2945 int s_offset;
2946 int r_offset;
2947 int i;
2948
2949 // Clear Hardware Buffer
2950 Hw_ClearBuff(device);
2951
2952 // Prepare Data to Send
2953 datalen = UT_TEST_SIZE;
2954 for (i = 0; i < datalen; i++) {
2955 SendBuff[i] = i & UT_DATA_MASK;
2956 }
2957
2958 // Setup Buffer Structure
2959 s_offset = 0;
2960 ur_ctrl_putbytes.u4OwenrId = MOD_TTY_UT;
2961 ur_ctrl_putbytes.puBuffaddr = SendBuff;
2962 ur_ctrl_putbytes.u2Length = datalen;
2963 r_offset = 0;
2964 ur_ctrl_getbytes.u4OwenrId = MOD_TTY_UT;
2965 ur_ctrl_getbytes.puBuffaddr = RecvBuff;
2966 ur_ctrl_getbytes.u2Length = datalen;
2967
2968 // Sending Data Until Sending Complete
2969 do {
2970 // Dummy Upper Module
2971 {
2972 DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes);
2973 s_offset += ur_ctrl_putbytes.u2RetSize;
2974
2975 // Update Tx Buffer Structure
2976 ur_ctrl_putbytes.puBuffaddr = SendBuff + s_offset;
2977 ur_ctrl_putbytes.u2Length = datalen - s_offset;
2978 }
2979
2980 // Dummy Driver
2981 {
2982 // Return Tx GPD to TTYCore
2983 Tx_Flush_Gpd(device);
2984 }
2985
2986 // Dummy Upper Module
2987 {
2988 // In conventional path, _tty_tx_done_cb will send ilm to inform upper module.
2989 // when data buffer have the remaining data still haven't be sent.
2990 if (s_offset < datalen) {
2991 ilm_struct current_ilm;
2992
2993 msg_receive_extq(&current_ilm);
2994 if (current_ilm.msg_id != MSG_ID_UART_READY_TO_WRITE_IND) {
2995 destroy_ilm(&current_ilm);
2996 return KAL_FALSE;
2997 }
2998 destroy_ilm(&current_ilm);
2999 }
3000 }
3001 } while (s_offset < datalen);
3002
3003 // Receiving Data Until Data empty in Hardware
3004 do {
3005 // Dummy Hardware Operation
3006 {
3007 // Copy Data to Driver Rx GPD in the Rx Queue
3008 Hw_PopDataToRxQue(device);
3009 }
3010
3011 // Dummy Driver
3012 {
3013 // Get Rx GPDs(Contain Received Data) by De-Q
3014 void * ior = Rx_DeQueToIor(device);
3015 // Rx callback to send ior to tty
3016 if (ior) {
3017 DclSerialPort_DrvRx(handle, DRV_TTY_UT, ior);
3018 }
3019 }
3020
3021 // Dummy Upper Module
3022 {
3023 // In conventional path, _tty_rx_cb will send ilm to inform upper module data ready to read.
3024 {
3025 ilm_struct current_ilm;
3026
3027 msg_receive_extq(&current_ilm);
3028 if (current_ilm.msg_id != MSG_ID_UART_READY_TO_READ_IND) {
3029 destroy_ilm(&current_ilm);
3030 return KAL_FALSE;
3031 }
3032 destroy_ilm(&current_ilm);
3033 }
3034
3035 // Get Data
3036 DclSerialPort_Control(handle, SIO_CMD_GET_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_getbytes);
3037 r_offset += ur_ctrl_getbytes.u2RetSize;
3038
3039 // Update Rx Buffer Structure
3040 ur_ctrl_getbytes.puBuffaddr = RecvBuff + r_offset;
3041 ur_ctrl_getbytes.u2Length = datalen - r_offset;
3042 }
3043 } while (Dev_Mgmt[device].size);
3044
3045 // Compare data between Send Buffer & Receive Buffer
3046 for (i = 0; i < datalen; i++) {
3047 if (SendBuff[i] ^ RecvBuff[i]) {
3048 data_corrupt = KAL_TRUE;
3049 break;
3050 }
3051 }
3052 }
3053
3054 // Upper Module DeInit & Driver Detatch & DeRegister Callback
3055 DataPath_Close(handle);
3056
3057 // Check data no corrupt
3058 if (data_corrupt) {
3059 FAIL_MSG("Data Corrupt in Device# = %d, DevType = %d", device, devtype);
3060 return KAL_FALSE;
3061 }
3062
3063 // Check there is no assert
3064 if (ut_assert_flag) {
3065 ut_assert_flag = KAL_FALSE; // clear flag
3066 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
3067 return KAL_FALSE;
3068 }
3069 return KAL_TRUE;
3070}
3071
3072kal_bool BuffMod_ConvTx_ConvRx(kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
3073{
3074 DCL_DEV device;
3075 DCL_STATUS status;
3076 DCL_HANDLE handle;
3077 SIO_TYPE_T devtype;
3078 kal_bool data_corrupt;
3079
3080 // Setup Port & Driver Type
3081 device = uart_port1;
3082 devtype = DCL_UART_CMUX_TYPE; // Driver type is BUFF_DRV_TYPE
3083 data_corrupt = KAL_FALSE;
3084
3085 // Get handle
3086 handle = DclSerialPort_Open(device, 0);
3087
3088 // Upper Module Initialize & Driver Register callback and then Attach
3089 DataPath_Setup(handle, devtype, 0);
3090
3091 // Send Tx Data -> TxDoneCb -> Get "Ready to Write" ilm -> RxCb -> Send Rx gpds
3092 {
3093 UART_CTRL_PUT_BYTES_T ur_ctrl_putbytes;
3094 UART_CTRL_GET_BYTES_T ur_ctrl_getbytes;
3095 char SendBuff[UT_TEST_SIZE];
3096 char RecvBuff[UT_TEST_SIZE];
3097 int datalen;
3098 int s_offset;
3099 int r_offset;
3100 int i;
3101
3102 // Clear Hardware Buffer
3103 Hw_ClearBuff(device);
3104
3105 // Prepare Data to Send
3106 datalen = UT_TEST_SIZE;
3107 for (i = 0; i < datalen; i++) {
3108 SendBuff[i] = i & UT_DATA_MASK;
3109 }
3110
3111 // Setup Buffer Structure
3112 s_offset = 0;
3113 ur_ctrl_putbytes.u4OwenrId = MOD_TTY_UT;
3114 ur_ctrl_putbytes.puBuffaddr = SendBuff;
3115 ur_ctrl_putbytes.u2Length = datalen;
3116 r_offset = 0;
3117 ur_ctrl_getbytes.u4OwenrId = MOD_TTY_UT;
3118 ur_ctrl_getbytes.puBuffaddr = RecvBuff;
3119 ur_ctrl_getbytes.u2Length = datalen;
3120
3121 // Sending Data Until Sending Complete
3122 do {
3123 // Dummy Upper Module
3124 {
3125 DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes);
3126 s_offset += ur_ctrl_putbytes.u2RetSize;
3127
3128 // Update Tx Buffer Structure
3129 ur_ctrl_putbytes.puBuffaddr = SendBuff + s_offset;
3130 ur_ctrl_putbytes.u2Length = datalen - s_offset;
3131 }
3132
3133 // Dummy Driver
3134 {
3135 // Using TxDoneCb to inform TTYCore
3136 DclSerialPort_DrvTxDone(handle, DRV_TTY_UT, NULL);
3137 }
3138
3139 // Dummy Upper Module
3140 {
3141 // In conventional path, _tty_tx_done_cb will send ilm to inform upper module.
3142 // when data buffer have the remaining data still haven't be sent.
3143 if (s_offset < datalen) {
3144 ilm_struct current_ilm;
3145
3146 msg_receive_extq(&current_ilm);
3147 if (current_ilm.msg_id != MSG_ID_UART_READY_TO_WRITE_IND) {
3148 destroy_ilm(&current_ilm);
3149 return KAL_FALSE;
3150 }
3151 destroy_ilm(&current_ilm);
3152 }
3153 }
3154 } while (s_offset < datalen);
3155
3156 // Dummy Driver
3157 {
3158 // Using RxCb to inform TTYCore
3159 DclSerialPort_DrvRx(handle, DRV_TTY_UT, NULL);
3160
3161 // It will raise the flag rx_up_mod_wait at Rx buffer mode initial
3162 // When using Rx_Cb to inform TTYCore it will send ilm at first time.
3163 {
3164 ilm_struct current_ilm;
3165
3166 msg_receive_extq(&current_ilm);
3167 if (current_ilm.msg_id != MSG_ID_UART_READY_TO_READ_IND) {
3168 destroy_ilm(&current_ilm);
3169 return KAL_FALSE;
3170 }
3171 destroy_ilm(&current_ilm);
3172 }
3173 }
3174 // Receiving Data Until Data empty in Hardware
3175 do {
3176 // Dummy Upper Module
3177 {
3178 // Get Data
3179 DclSerialPort_Control(handle, SIO_CMD_GET_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_getbytes);
3180 r_offset += ur_ctrl_getbytes.u2RetSize;
3181
3182 // Update Rx Buffer Structure
3183 ur_ctrl_getbytes.puBuffaddr = RecvBuff + r_offset;
3184 ur_ctrl_getbytes.u2Length = datalen - r_offset;
3185 }
3186 } while (Dev_Mgmt[device].size);
3187
3188 // Compare data between Send Buffer & Receive Buffer
3189 for (i = 0; i < datalen; i++) {
3190 if (SendBuff[i] ^ RecvBuff[i]) {
3191 data_corrupt = KAL_TRUE;
3192 break;
3193 }
3194 }
3195 }
3196
3197 // Upper Module DeInit & Driver Detatch & DeRegister Callback
3198 DataPath_Close(handle);
3199
3200 // Check data no corrupt
3201 if (data_corrupt) {
3202 FAIL_MSG("Data Corrupt in Device# = %d, DevType = %d", device, devtype);
3203 return KAL_FALSE;
3204 }
3205
3206 // Check there is no assert
3207 if (ut_assert_flag) {
3208 ut_assert_flag = KAL_FALSE; // clear flag
3209 FAIL_MSG("There is a assertion in exception. It's found at Test Case end");
3210 return KAL_FALSE;
3211 }
3212 return KAL_TRUE;
3213}
3214
3215/**************
3216 Main-Case
3217 **************/
3218kal_bool DataPath_DirectlyPath(void *p_param, kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
3219{
3220 if (IS_SUB_CASE_FAIL(ConvTxPath))
3221 return KAL_FALSE;
3222 if (IS_SUB_CASE_FAIL(ConvRxPath))
3223 return KAL_FALSE;
3224 if (IS_SUB_CASE_FAIL(NewTxPath))
3225 return KAL_FALSE;
3226 if (IS_SUB_CASE_FAIL(NewTxLightPath))
3227 return KAL_FALSE;
3228 if (IS_SUB_CASE_FAIL(NewRxPath))
3229 return KAL_FALSE;
3230 if (IS_SUB_CASE_FAIL(BuffModTxPath))
3231 return KAL_FALSE;
3232 if (IS_SUB_CASE_FAIL(BuffModRxPath))
3233 return KAL_FALSE;
3234
3235 return KAL_TRUE;
3236}
3237
3238kal_bool DataPath_LoopbackTest(void *p_param, kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
3239{
3240 if (IS_SUB_CASE_FAIL(NewTx_NewRx))
3241 return KAL_FALSE;
3242 if (IS_SUB_CASE_FAIL(NewTx_ConvRx))
3243 return KAL_FALSE;
3244 if (IS_SUB_CASE_FAIL(ConvTx_NewRx))
3245 return KAL_FALSE;
3246 if (IS_SUB_CASE_FAIL(ConvTx_ConvRx))
3247 return KAL_FALSE;
3248 if (IS_SUB_CASE_FAIL(BuffMod_ConvTx_ConvRx))
3249 return KAL_FALSE;
3250
3251 return KAL_TRUE;
3252}
3253
3254/***********************************
3255 UnitTest Begin End
3256 ***********************************/
3257kal_bool utTest_Initialize(void *p_param, kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
3258{
3259 kal_mem_set(Dev_Mgmt, 0, sizeof(UtInstance) * UART_DEV_CNT);
3260
3261 return KAL_TRUE;
3262}
3263
3264kal_bool utTest_End(void *p_param, kal_char *p_ret_err_str, kal_uint32 *p_ret_err_str_sz)
3265{
3266 return KAL_TRUE;
3267}
3268
3269/****************************************************************************
3270 TTYUT Task Init Function
3271 ***************************************************************************/
3272
3273#define UT_TEST(_func, param) { #_func, _func, param }
3274ST_TCASE_T st_tcase_g[] = {
3275 UT_TEST(utTest_Initialize, NULL),
3276
3277 // Don't take out "FuncVeri_Common" case, DclSerialPort_Initialize will make test environment clear.
3278 UT_TEST(FuncVeri_Common, NULL),
3279
3280 UT_TEST(FuncVeri_DrvRegDeRegCb, NULL),
3281 UT_TEST(FuncVeri_DrvAtDetach, NULL),
3282 UT_TEST(FuncVeri_UpInitDeinit, NULL),
3283 UT_TEST(FuncVeri_UpRegCb, NULL),
3284 UT_TEST(FuncVeri_ChangeOwner, NULL),
3285 UT_TEST(FuncVeri_Misc, NULL),
3286
3287 UT_TEST(DataPath_DirectlyPath, NULL),
3288 UT_TEST(DataPath_LoopbackTest, NULL),
3289 /// TODO: DataPath for ChangeOwner
3290
3291 UT_TEST(utTest_End, NULL)
3292};
3293kal_uint32 st_tcase_count_g = sizeof(st_tcase_g) / sizeof(ST_TCASE_T);
3294
3295kal_bool tty_ut_st_create (void)
3296{
3297 return st_reg_test(ST_MOD_NAME, /* p_mod_name */
3298 &st_tcase_g, /* p_tcase */
3299 st_tcase_count_g /* tcase_num */
3300 );
3301}
3302