2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "tskm_port_subsys.h"
23 #include <native_service/cl_monitor.h>
24 #include <system_service/ss_sm_client_if.h>
25 #include <system_service/resm.h>
26 //#include <stub/ss_diag.h>
29 #include "agl_thread.h"
31 #include "tskm_main.h"
32 #include "tskm_debug.h"
33 #include "tskm_util.h"
34 #include "tskm_port_pf.h"
38 #define oops_name2pid(processname) syscall(OOPSTRACE_SYSCALL, 17, processname)
43 CL_MonitorSearch_t clMonSearch;
44 uint32_t resmId; // Session ID of RESM
47 static SUB_SYS_CTX_t g_sub;
49 /******************************************************************
50 * Subsystem initialization
51 ******************************************************************/
52 int tskm_sub_init(void) {
54 SUB_SYS_CTX_t* p_ctx = &g_sub;
56 clRet = CL_MonitorSearchInit(&p_ctx->clMonSearch);
57 if (clRet != 0) { // LCOV_EXCL_BR_LINE 6: For processing intializing process
58 // LCOV_EXCL_START 6:For processing initializing process
59 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
62 // LCOV_EXCL_STOP 6: For processing initializing process
66 // LCOV_EXCL_START 6:For processing initializing process
68 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
73 /******************************************************************
74 * Subsystem termination
75 ******************************************************************/
76 int tskm_sub_term(void) {
78 SUB_SYS_CTX_t* p_ctx = &g_sub;
80 ret = CL_MonitorSearchDestroy(&p_ctx->clMonSearch);
87 /*********************************************************
89 *********************************************************/
90 void tskm_sub_reboot(const TSKM_ERROR_REBOOT_t* p_info) {
91 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
95 l_eStatus = SendCpuResetRequestToSystemManager(
96 e_SS_SM_CPU_RESET_REASON_GENERIC_ERR, p_info->log.messageStr);
97 if (eFrameworkunifiedStatusOK != l_eStatus) {
102 /*********************************************************
104 *********************************************************/
105 void tskm_sub_reboot_normal(void) {
106 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
108 l_eStatus = SendCpuResetRequestToSystemManager(
109 e_SS_SM_CPU_RESET_REASON_NORMAL);
110 if (l_eStatus != eFrameworkunifiedStatusOK) {
115 /*********************************************************
117 *********************************************************/
118 void tskm_sub_logging(const TSKM_LOGGING_INFO_t* p_info) {
119 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
120 eSMUserLogType l_eType;
122 switch (p_info->type) {
123 case TSKM_LOGGING_TYPE_GRP_RELAUNCH:
124 l_eType = e_SS_SM_CAPTURE_GROUP_RELAUNCH;
126 case TSKM_LOGGING_TYPE_MODULE_LOGS:
128 l_eType = e_SS_SM_CAPTURE_MODULE_LOGS;
132 l_eStatus = SendUserInvokedLoggingRequestToSystemManager(l_eType,
134 if (eFrameworkunifiedStatusOK != l_eStatus) {
139 /*********************************************************
141 *********************************************************/
142 void tskm_sub_debugDumpRes(BOOL bIsNeedSvcName, const char *p_dumpMsg) {
143 if (bIsNeedSvcName) { // LCOV_EXCL_BR_LINE 8: As the bIsNeedSvcName is set to FALSE only
144 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
145 SSDEBUGDUMP("%s", p_dumpMsg); // LCOV_EXCL_LINE 8: As the bIsNeedSvcName is set to FALSE only
147 SSDEBUGDUMP_RAW("%s", p_dumpMsg);
151 /*********************************************************
153 *********************************************************/
154 int tskm_sub_getExtBootInfo(T_SS_SM_START_ExtDataStructType *p_info) {
155 EFrameworkunifiedStatus l_eStatus;
156 T_SS_SM_START_ExtDataStructType extStartupInfo;
158 l_eStatus = GetInterfaceunifiedOnStartExtInfo(extStartupInfo);
159 if (l_eStatus != eFrameworkunifiedStatusOK) {
164 memcpy(p_info, &extStartupInfo, sizeof(extStartupInfo));
170 /*********************************************************
171 * Service Error Monitoring Check
172 *********************************************************/
174 tskm_sub_searchHungSvcs() {
176 TSKM_HUNG_INFO_t *p_hungList = NULL;
177 SUB_SYS_CTX_t* p_ctx = &g_sub;
179 ret = CL_MonitorSearchTimeout(&p_ctx->clMonSearch);
181 TSKM_ASSERT_ERRNO(0);
185 if (0 < p_ctx->clMonSearch.entry_num) {
188 TSKM_PRINTF(TSKM_LOG_DEBUG, "TimeoutSvcNum = %d",
189 p_ctx->clMonSearch.entry_num);
191 if (NULL == p_ctx->clMonSearch.entry_list) {
196 p_hungList = (TSKM_HUNG_INFO_t *) malloc( // NOLINT (readability/casting)
197 sizeof(TSKM_HUNG_INFO_t) * (p_ctx->clMonSearch.entry_num + 1));
198 if (p_hungList == NULL) { // LCOV_EXCL_BR_LINE 5: malloc's error case.
199 // LCOV_EXCL_START 5: Checked in Death testing, but it is not reflected in the coverage and excluded
200 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
201 TSKM_ASSERT_ERRNO(0);
206 for (ii = 0; ii < p_ctx->clMonSearch.entry_num; ii++) {
207 p_hungList[ii].pid = p_ctx->clMonSearch.entry_list[ii].pid;
208 p_hungList[ii].type = p_ctx->clMonSearch.entry_list[ii].type;
210 // set "-1" to pid at the end of list.
211 p_hungList[p_ctx->clMonSearch.entry_num].pid = -1;
214 ERROR: return p_hungList;
217 /*********************************************************
218 * RESM Initialization
219 *********************************************************/
220 int tskm_sub_resmInit(void) { // LCOV_EXCL_START 6: Because the condition cannot be set
221 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
223 SUB_SYS_CTX_t* p_ctx = &g_sub;
224 RESM_ERR_t resmRet = RESM_E_OK;
229 resmRet = RESM_Open(NULL, &(p_ctx->resmId));
230 if (RESM_E_OK != resmRet) {
233 #warning RESM backtrace disabled, because 'print_backtrace_pid' not support.
235 // Backtrace outoutput of the RESM
236 pid = oops_name2pid(MN_SS_RESOURCEMGR);
238 TSKM_ASSERT(-1 != print_backtrace_pid(pid));
240 TSKM_PRINTF(TSKM_LOG_ERROR, "ERR : oops_name2pid %d , err:%d, msg:%s",
241 pid, errno, strerror(errno));
248 resmRet = RESM_GetEventFd(p_ctx->resmId, &redmFd);
249 if (RESM_E_OK != resmRet) {
254 ev.reqEvent = RESM_EV_MEM;
255 ev.prm.restMemThresh = 512; // Threshold(BYTE)
257 resmRet = RESM_ReqEvent(p_ctx->resmId, &ev);
258 if (RESM_E_OK != resmRet) {
267 /*********************************************************
269 *********************************************************/
270 int tskm_sub_resmRcv(TSKM_EVENT_INFO_t* p_ev) {
271 SUB_SYS_CTX_t* p_ctx = &g_sub;
272 RESM_ERR_t resmRet = RESM_E_OK;
275 resmRet = RESM_GetEvent(p_ctx->resmId, &evFlag);
276 if (RESM_E_OK != resmRet) {
281 if (RESM_EV_MEM != evFlag) {
286 TSKM_PRINTF(TSKM_LOG_ERROR, "Detect LowMem");
288 p_ev->event = TSKM_EV_LCL_REP_LOWMEM;
294 int tskm_sub_setWakeupOrder(const char* p_order) {
295 // Under consideration
297 } // LCOV_EXCL_BR_LINE 10: Gcov constraints (last row)