• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  * conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  * of conditions and the following disclaimer in the documentation and/or other materials
13  * provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  * to endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "It_smp_hwi.h"
33 
34 #ifdef __cplusplus
35 #if __cplusplus
36 extern "C" {
37 #endif /* __cpluscplus */
38 #endif /* __cpluscplus */
39 extern EVENT_CB_S g_event;
40 #ifndef LOSCFG_NO_SHARED_IRQ
41 
42 static HwiIrqParam g_dev[LOSCFG_KERNEL_CORE_NUM];
43 
HwiF01(void)44 static VOID HwiF01(void)
45 {
46     LOS_AtomicInc(&g_testCount);
47 }
48 
TaskF02(VOID)49 static VOID TaskF02(VOID)
50 {
51     TestHwiTrigger(HWI_NUM_TEST);
52     LOS_EventWrite(&g_event, 0x1 << LOSCFG_KERNEL_CORE_NUM);
53     TestDumpCpuid();
54     return;
55 }
56 
TaskF01(UINTPTR devIndex)57 static VOID TaskF01(UINTPTR devIndex)
58 {
59     UINT32 ret;
60     // 3, Set the interrupt priority
61     ret = LOS_HwiCreate(HWI_NUM_TEST, 3, IRQF_SHARED, (HWI_PROC_FUNC)HwiF01, &(g_dev[devIndex]));
62     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
63 
64     ret = LOS_EventWrite(&g_event, 0x1 << devIndex);
65     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
66 
67     TestDumpCpuid();
68     return;
69 }
70 
Testcase(void)71 static UINT32 Testcase(void)
72 {
73     TSK_INIT_PARAM_S testTask;
74     UINT32 ret, testid, currCpuid;
75     UINT32 i;
76 
77     g_testCount = 0;
78     LOS_EventInit(&g_event);
79 
80     for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
81         g_dev[i].pDevId = (void *)(i + 1);
82         g_dev[i].swIrq = HWI_NUM_TEST;
83     }
84 
85     for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
86         TEST_TASK_PARAM_INIT(testTask, "it_hwi_share_task", TaskF01,
87             TASK_PRIO_TEST + 1); // not set cpuaffi
88         testTask.auwArgs[0] = i;
89         ret = LOS_TaskCreate(&testid, &testTask);
90         ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
91     }
92 
93     ret = LOS_EventRead(&g_event, (0x1 << LOSCFG_KERNEL_CORE_NUM) - 1, LOS_WAITMODE_AND, LOS_WAIT_FOREVER);
94     ICUNIT_GOTO_EQUAL(ret, (0x1 << LOSCFG_KERNEL_CORE_NUM) - 1, ret, EXIT);
95 
96     TEST_TASK_PARAM_INIT(testTask, "it_hwi_share_task", TaskF02,
97         TASK_PRIO_TEST + 1); // not set cpuaffi
98     ret = LOS_TaskCreate(&testid, &testTask);
99     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
100 
101     ret = LOS_EventRead(&g_event, (0x1 << (LOSCFG_KERNEL_CORE_NUM + 1)) - 1, LOS_WAITMODE_AND, LOS_WAIT_FOREVER);
102     ICUNIT_GOTO_EQUAL(ret, (0x1 << (LOSCFG_KERNEL_CORE_NUM + 1)) - 1, ret, EXIT);
103 
104     LOS_TaskDelay(2); // 2, set delay time
105 
106     ICUNIT_GOTO_EQUAL(g_testCount, LOSCFG_KERNEL_CORE_NUM, g_testCount, EXIT);
107 EXIT:
108     for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
109         LOS_HwiDelete(HWI_NUM_TEST, &(g_dev[i]));
110     }
111     LOS_EventDestroy(&g_event);
112     return LOS_OK;
113 }
114 
ItSmpLosHwiShare007(VOID)115 VOID ItSmpLosHwiShare007(VOID)
116 {
117     TEST_ADD_CASE("ItSmpLosHwiShare007", Testcase, TEST_LOS, TEST_HWI, TEST_LEVEL1, TEST_FUNCTION);
118 }
119 #endif
120 #ifdef __cplusplus
121 #if __cplusplus
122 }
123 #endif /* __cpluscplus */
124 #endif /* __cpluscplus */
125