• 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 <los_base.h>
17 #include <securec.h>
18 #include <ohos_init.h>
19 #include <cmsis_os.h>
20 #include "service.h"
21 #include "samgr_lite.h"
22 
23 #define TIME_UNLIMITED_CASE 0
24 #define WAIT_BOOT_PROC ((1000) * (11))
25 #define TEST_SYS_SERVICE1 "tst_sys1"
26 #define TEST_SYS_SERVICE2 "tst_sys2"
27 #define TEST_APP_SERVICE1 "tst_app1"
28 #define TEST_APP_SERVICE2 "tst_app2"
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 Service g_testSys1 = {GetName, Initialize, MessageHandle, GetTaskConfig};
35 static Service g_testSys2 = {GetName, Initialize, MessageHandle, GetTaskConfig};
36 static Service g_testApp1 = {GetName, Initialize, MessageHandle, GetTaskConfig};
37 static Service g_testApp2 = {GetName, Initialize, MessageHandle, GetTaskConfig};
38 
GetName(Service * service)39 static const char *GetName(Service *service)
40 {
41     if (service == &g_testSys1) {
42         return TEST_SYS_SERVICE1;
43     }
44     if (service == &g_testSys2) {
45         return TEST_SYS_SERVICE2;
46     }
47     if (service == &g_testApp1) {
48         return TEST_APP_SERVICE1;
49     }
50     if (service == &g_testApp2) {
51         return TEST_APP_SERVICE2;
52     }
53     return NULL;
54 }
55 
Initialize(Service * service,Identity identity)56 static BOOL Initialize(Service *service, Identity identity)
57 {
58     (void)identity;
59     if (service == &g_testSys1 || service == &g_testApp1) {
60         printf("[Recovery Test][Initialize]Time Out Case Running\n");
61         LOS_Msleep(WAIT_BOOT_PROC);
62         return TRUE;
63     }
64 #if TIME_UNLIMITED_CASE
65     if (service == &g_testSys2 || service == &g_testApp2) {
66         printf("[Recovery Test][Initialize]Time Unlimited Case Running\n\n");
67         while (1) {
68             (void)identity;
69         }
70         return TRUE;
71     }
72 #endif
73     return TRUE;
74 }
75 
MessageHandle(Service * service,Request * msg)76 static BOOL MessageHandle(Service *service, Request *msg)
77 {
78     (void)service;
79     (void)msg;
80     return FALSE;
81 }
82 
GetTaskConfig(Service * service)83 static TaskConfig GetTaskConfig(Service *service)
84 {
85     (void)service;
86     TaskConfig config = {LEVEL_HIGH, PRI_NORMAL,
87                          0x400, 16, SHARED_TASK};
88     return config;
89 }
90 
SInit(Service * demo)91 static void SInit(Service *demo)
92 {
93     SAMGR_GetInstance()->RegisterService(demo);
94 }
95 
SS1Init(void)96 static void SS1Init(void)
97 {
98     SInit(&g_testSys1);
99 }
100 
SS2Init(void)101 static void SS2Init(void)
102 {
103     SInit(&g_testSys2);
104 }
105 
AS1Init(void)106 static void AS1Init(void)
107 {
108     SInit(&g_testApp1);
109 }
110 
AS2Init(void)111 static void AS2Init(void)
112 {
113     SInit(&g_testApp2);
114 }
115 
116 SYS_SERVICE_INIT(SS1Init);
117 SYS_SERVICE_INIT(SS2Init);
118 SYSEX_SERVICE_INIT(AS1Init);
119 SYSEX_SERVICE_INIT(AS2Init);
120