• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "It_los_queue.h"
17 
18 
19 static CHAR g_buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP";
20 static CHAR g_buff2[QUEUE_SHORT_BUFFER_LENGTH] = "DOPRA";
21 static CHAR g_buff3[QUEUE_SHORT_BUFFER_LENGTH] = "TEST";
22 
HwiF01(VOID)23 static VOID HwiF01(VOID)
24 {
25     UINT32 ret;
26 
27     ret = LOS_QueueWriteHeadIsr(g_testQueueID01, &g_buff1, QUEUE_BASE_MSGSIZE);
28     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
29 
30     ret = LOS_QueueWriteHeadIsr(g_testQueueID01, &g_buff2, QUEUE_BASE_MSGSIZE);
31     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
32 
33     ret = LOS_QueueWriteHeadIsr(g_testQueueID01, &g_buff3, QUEUE_BASE_MSGSIZE);
34     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
35 }
36 
TaskF01(VOID)37 static VOID TaskF01(VOID)
38 {
39     UINT32 ret;
40     CHAR buffA[QUEUE_SHORT_BUFFER_LENGTH] = "TEST";
41     CHAR buffB[QUEUE_SHORT_BUFFER_LENGTH] = "DOPRA";
42     CHAR buffC[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP";
43     CHAR *buff = NULL;
44 
45     ret = LOS_QueueRead(g_testQueueID01, &buff, QUEUE_BASE_MSGSIZE, LOS_WAIT_FOREVER);
46     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
47     for (UINT8 index = 0; index < QUEUE_BASE_MSGSIZE - 1; index++) { // 7, QUEUE_BASE_MSGSIZE - 1
48         ICUNIT_GOTO_EQUAL(*((CHAR *)(intptr_t)buff + index), buffA[index],
49             *((CHAR *)(intptr_t)buff + index), EXIT);
50     }
51 
52     ret = LOS_QueueRead(g_testQueueID01, &buff, QUEUE_BASE_MSGSIZE, LOS_WAIT_FOREVER);
53     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
54     for (UINT8 index = 0; index < QUEUE_BASE_MSGSIZE - 1; index++) { // 7, QUEUE_BASE_MSGSIZE - 1
55         ICUNIT_GOTO_EQUAL(*((CHAR *)(intptr_t)buff + index), buffB[index],
56             *((CHAR *)(intptr_t)buff + index), EXIT);
57     }
58 
59     ret = LOS_QueueRead(g_testQueueID01, &buff, QUEUE_BASE_MSGSIZE, LOS_WAIT_FOREVER);
60     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
61     for (UINT8 index = 0; index < QUEUE_BASE_MSGSIZE - 1; index++) { // 7, QUEUE_BASE_MSGSIZE - 1
62         ICUNIT_GOTO_EQUAL(*((CHAR *)(intptr_t)buff + index), buffC[index],
63             *((CHAR *)(intptr_t)buff + index), EXIT);
64     }
65 
66 EXIT:
67     return;
68 }
69 
Testcase(VOID)70 static UINT32 Testcase(VOID)
71 {
72     UINT32 ret;
73     HWI_PRIOR_T hwiPrio = 3;
74     HWI_MODE_T mode = 0;
75 
76     HwiIrqParam irqParam;
77 
78     ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE);
79     ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
80 
81     (VOID)memset_s(&irqParam, sizeof(HwiIrqParam), 0, sizeof(HwiIrqParam));
82     irqParam.pDevId = 0;
83     ret = LOS_HwiCreate(HWI_NUM_TEST, hwiPrio, mode, (HWI_PROC_FUNC)HwiF01, &irqParam);
84     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
85 
86     TSK_INIT_PARAM_S task1 = { 0 };
87     task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01;
88     task1.uwStackSize = TASK_STACK_SIZE_TEST;
89     task1.pcName = "Tsk001A";
90     task1.usTaskPrio = TASK_PRIO_TEST - 1;
91     task1.uwResved = LOS_TASK_STATUS_DETACHED;
92     g_testCount = 0;
93     ret = LOS_TaskCreate(&g_testTaskID01, &task1);
94     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
95 
96     TestHwiTrigger(HWI_NUM_TEST);
97 
98 EXIT:
99     TestHwiDelete(HWI_NUM_TEST);
100     ret = LOS_QueueDelete(g_testQueueID01);
101     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
102     return LOS_OK;
103 }
104 
ItLosQueueIsr015(VOID)105 VOID ItLosQueueIsr015(VOID)
106 {
107     TEST_ADD_CASE("ItLosQueueIsr015", Testcase, TEST_LOS, TEST_QUE, TEST_LEVEL1, TEST_FUNCTION);
108 }
109 
110