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
HwiF01(VOID)19 static VOID HwiF01(VOID)
20 {
21 UINT32 ret;
22 CHAR buff1[QUEUE_SHORT_BUFFER_LENGTH] = "UniDSP";
23 CHAR buff2[QUEUE_SHORT_BUFFER_LENGTH] = "DOPRA";
24 CHAR buff3[QUEUE_SHORT_BUFFER_LENGTH] = "TEST";
25
26 ret = LOS_QueueWriteHeadCopyIsr(g_testQueueID01, buff1, QUEUE_BASE_MSGSIZE);
27 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
28
29 ret = LOS_QueueWriteHeadCopyIsr(g_testQueueID01, buff2, QUEUE_BASE_MSGSIZE);
30 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
31
32 ret = LOS_QueueWriteHeadCopyIsr(g_testQueueID01, buff3, QUEUE_BASE_MSGSIZE);
33 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
34 }
35
TaskF01(VOID)36 static VOID TaskF01(VOID)
37 {
38 UINT32 ret;
39 UINT32 msgSize = (UINT32)QUEUE_BASE_MSGSIZE;
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[QUEUE_SHORT_BUFFER_LENGTH] = " ";
44
45 ret = LOS_QueueReadCopy(g_testQueueID01, buff, &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_QueueReadCopy(g_testQueueID01, buff, &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_QueueReadCopy(g_testQueueID01, buff, &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 HwiIrqParam irqParam;
76
77 ret = LOS_QueueCreate("Q1", QUEUE_BASE_NUM, &g_testQueueID01, 0, QUEUE_BASE_MSGSIZE);
78 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
79
80 (VOID)memset_s(&irqParam, sizeof(HwiIrqParam), 0, sizeof(HwiIrqParam));
81 irqParam.pDevId = 0;
82 ret = LOS_HwiCreate(HWI_NUM_TEST, hwiPrio, mode, (HWI_PROC_FUNC)HwiF01, &irqParam);
83 ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
84
85 TSK_INIT_PARAM_S task1 = { 0 };
86 task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01;
87 task1.uwStackSize = TASK_STACK_SIZE_TEST;
88 task1.pcName = "Tsk001A";
89 task1.usTaskPrio = TASK_PRIO_TEST - 1;
90 task1.uwResved = LOS_TASK_STATUS_DETACHED;
91 g_testCount = 0;
92 ret = LOS_TaskCreate(&g_testTaskID01, &task1);
93 ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
94
95 TestHwiTrigger(HWI_NUM_TEST);
96
97 EXIT:
98 TestHwiDelete(HWI_NUM_TEST);
99 ret = LOS_QueueDelete(g_testQueueID01);
100 ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
101 return LOS_OK;
102 }
103
ItLosQueueIsr016(VOID)104 VOID ItLosQueueIsr016(VOID)
105 {
106 TEST_ADD_CASE("ItLosQueueIsr016", Testcase, TEST_LOS, TEST_QUE, TEST_LEVEL1, TEST_FUNCTION);
107 }
108
109