• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2022 Huawei Device 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 "example.h"
17 #include <stdint.h>
18 #include <feature.h>
19 #include <securec.h>
20 #include <ohos_init.h>
21 #include <samgr_lite.h>
22 #include <cmsis_os.h>
23 #include "time_adapter.h"
24 
25 typedef struct BootTestExample {
26     Service service;
27     Feature feature;
28 } BootTestExample;
29 
30 static const char *GetName(Service *service);
31 static BOOL Initialize(Service *service, Identity identity);
32 static BOOL MessageHandle(Service *service, Request *msg);
33 static TaskConfig GetTaskConfig(Service *service);
34 static const char *FEATURE_GetName(Feature *feature);
35 static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity);
36 static void FEATURE_OnStop(Feature *feature, Identity identity);
37 static BOOL FEATURE_OnMessage(Feature *feature, Request *request);
38 static BootTestExample g_example[] = {
39     {
40         .service = {GetName, Initialize, MessageHandle, GetTaskConfig},
41         .feature = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage}
42     }, {
43         .service = {GetName, Initialize, MessageHandle, GetTaskConfig},
44         .feature = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage}
45     }, {
46         .service = {GetName, Initialize, MessageHandle, GetTaskConfig},
47         .feature = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage}
48     }, {
49         .service = {GetName, Initialize, MessageHandle, GetTaskConfig},
50         .feature = {FEATURE_GetName, FEATURE_OnInitialize, FEATURE_OnStop, FEATURE_OnMessage}
51     }
52 };
53 
54 static uint32_t g_initIndex = 0;
55 
FEATURE_GetName(Feature * feature)56 static const char *FEATURE_GetName(Feature *feature)
57 {
58     // test cases service 0
59     if (feature == &g_example[0].feature) {
60         return BOOT_SYS_FEATURE1;
61     }
62     // test cases service 1
63     if (feature == &g_example[1].feature) {
64         return BOOT_SYS_FEATURE2;
65     }
66     // test cases service 2
67     if (feature == &g_example[2].feature) {
68         return BOOT_SYSEX_FEATURE1;
69     }
70     // test cases service 3
71     if (feature == &g_example[3].feature) {
72         return BOOT_SYSEX_FEATURE2;
73     }
74     return NULL;
75 }
76 
FEATURE_OnInitialize(Feature * feature,Service * parent,Identity identity)77 static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity)
78 {
79     (void)identity;
80     printf("[Boot Test][TaskID:%u][Step:%u][Reg Finish S:%s, F:%s]Time: %llu!\n",
81            (int)osThreadGetId(), g_initIndex++, parent->GetName(parent), feature->GetName(feature),
82            SAMGR_GetProcessTime());
83 }
84 
FEATURE_OnStop(Feature * feature,Identity identity)85 static void FEATURE_OnStop(Feature *feature, Identity identity)
86 {
87     (void)feature;
88     (void)identity;
89 }
90 
FEATURE_OnMessage(Feature * feature,Request * request)91 static BOOL FEATURE_OnMessage(Feature *feature, Request *request)
92 {
93     printf("[Boot Test][TaskID:%u][Step:%u][F:%s] msgId<%d> \n",
94            (int)osThreadGetId(), g_initIndex++, feature->GetName(feature), request->msgId);
95     return FALSE;
96 }
97 
GetName(Service * service)98 static const char *GetName(Service *service)
99 {
100     // test cases service 0
101     if (service == &g_example[0].service) {
102         return BOOT_SYS_SERVICE1;
103     }
104     // test cases service 1
105     if (service == &g_example[1].service) {
106         return BOOT_SYS_SERVICE2;
107     }
108     // test cases service 2
109     if (service == &g_example[2].service) {
110         return BOOT_SYSEX_SERVICE1;
111     }
112     // test cases service 3
113     if (service == &g_example[3].service) {
114         return BOOT_SYSEX_SERVICE2;
115     }
116     return NULL;
117 }
118 
Initialize(Service * service,Identity identity)119 static BOOL Initialize(Service *service, Identity identity)
120 {
121     (void)identity;
122     printf("[Boot Test][TaskID:%u][Step:%u][Reg Finish S:%s]Time: %llu!\n",
123            (int)osThreadGetId(), g_initIndex++, service->GetName(service), SAMGR_GetProcessTime());
124     return TRUE;
125 }
126 
MessageHandle(Service * service,Request * msg)127 static BOOL MessageHandle(Service *service, Request *msg)
128 {
129     printf("[Boot Test][TaskID:%u][Step:%u][S:%s] msgId<%d> \n",
130            (int)osThreadGetId(), g_initIndex++, service->GetName(service), msg->msgId);
131     return FALSE;
132 }
133 
GetTaskConfig(Service * service)134 static TaskConfig GetTaskConfig(Service *service)
135 {
136     (void)service;
137     TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL,
138                          0x400, 2, SHARED_TASK};
139     return config;
140 }
141 
MInit(void)142 static void MInit(void)
143 {
144     printf("[Boot Test][TaskID:%u][Step:%u][CORE INIT]Time: %llu!\n",
145            (int)osThreadGetId(), g_initIndex++, SAMGR_GetProcessTime());
146 }
MRun(void)147 static void MRun(void)
148 {
149     printf("[Boot Test][TaskID:%u][Step:%u][SYS RUN]Time: %llu!\n",
150            (int)osThreadGetId(), g_initIndex++, SAMGR_GetProcessTime());
151 }
152 
SInit(BootTestExample * demo)153 static void SInit(BootTestExample *demo)
154 {
155     SAMGR_GetInstance()->RegisterService(&demo->service);
156 
157     // test cases service 2
158     printf((demo < &g_example[2]) ?
159            "[Boot Test][TaskID:%u][Step:%u][SYS Reg S:%s]Time: %llu!\n" :
160            "[Boot Test][TaskID:%u][Step:%u][SYSEX Reg S:%s]Time: %llu!\n",
161            (int)osThreadGetId(), g_initIndex++, demo->service.GetName(&demo->service), SAMGR_GetProcessTime());
162 }
163 
FInit(BootTestExample * demo)164 static void FInit(BootTestExample *demo)
165 {
166     SAMGR_GetInstance()->RegisterFeature(demo->service.GetName(&demo->service), &demo->feature);
167 
168     // test cases service 2
169     printf((demo < &g_example[2]) ?
170            "[Boot Test][TaskID:%u][Step:%u][SYS Reg S:%s, F:%s]Time: %llu!\n" :
171            "[Boot Test][TaskID:%u][Step:%u][SYSEX Reg S:%s, F:%s]Time: %llu!\n",
172            (int)osThreadGetId(), g_initIndex++, demo->service.GetName(&demo->service),
173            demo->feature.GetName(&demo->feature), SAMGR_GetProcessTime());
174 }
175 
S1Init(void)176 static void S1Init(void)
177 {
178     // test cases service 0
179     SInit(&g_example[0]);
180 }
181 
S2Init(void)182 static void S2Init(void)
183 {
184     // test cases service 1
185     SInit(&g_example[1]);
186 }
187 
F1Init(void)188 static void F1Init(void)
189 {
190     // test cases feature 0
191     FInit(&g_example[0]);
192 }
193 
F2Init(void)194 static void F2Init(void)
195 {
196     // test cases feature 1
197     FInit(&g_example[1]);
198 }
199 
S3Init(void)200 static void S3Init(void)
201 {
202     // test cases service 2
203     SInit(&g_example[2]);
204 }
205 
S4Init(void)206 static void S4Init(void)
207 {
208     // test cases service 3
209     SInit(&g_example[3]);
210 }
211 
F3Init(void)212 static void F3Init(void)
213 {
214     // test cases feature 2
215     FInit(&g_example[2]);
216 }
217 
F4Init(void)218 static void F4Init(void)
219 {
220     // test cases feature 3
221     FInit(&g_example[3]);
222 }
223 
224 CORE_INIT(MInit);
225 SYS_RUN(MRun);
226 // init pri first
227 SYS_SERVICE_INIT_PRI(S1Init, 0);
228 // init pri second
229 SYS_SERVICE_INIT_PRI(S2Init, 1);
230 // init pri first
231 SYS_FEATURE_INIT_PRI(F1Init, 0);
232 // init pri second
233 SYS_FEATURE_INIT_PRI(F2Init, 1);
234 // init pri first
235 SYSEX_SERVICE_INIT_PRI(S3Init, 0);
236 // init pri second
237 SYSEX_SERVICE_INIT_PRI(S4Init, 1);
238 // init pri first
239 SYSEX_FEATURE_INIT_PRI(F3Init, 0);
240 // init pri second
241 SYSEX_FEATURE_INIT_PRI(F4Init, 1);
242