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 #ifndef TASK_MANAGER_SERVER_INCLUDE_TSKM_DEBUG_H_
18 #define TASK_MANAGER_SERVER_INCLUDE_TSKM_DEBUG_H_
21 #include <sys/types.h>
23 #include <native_service/ns_logger_if.h>
24 #include "system_service/tskm_svc.h"
26 #include "system_service/tskm_local_type.h"
28 #define TSKM_STATIC static
30 // for frameworkunifiedlog
31 #define ZONE_INIT ZONEMASK(10) // Reserved for lib
32 #define ZONE_FUNC ZONEMASK(11) // Reserved for lib
33 #define ZONE_MEM ZONEMASK(12) // Reserved for lib
34 #define ZONE_OUT ZONEMASK(13)
35 #define ZONE_STATE ZONEMASK(14) // Basic state change
36 #define ZONE_15 ZONEMASK(15)
37 #define ZONE_16 ZONEMASK(16)
38 #define ZONE_17 ZONEMASK(17)
39 #define ZONE_18 ZONEMASK(18)
40 #define ZONE_19 ZONEMASK(19)
41 #define ZONE_20 ZONEMASK(20)
42 #define ZONE_21 ZONEMASK(21)
43 #define ZONE_22 ZONEMASK(22)
44 #define ZONE_23 ZONEMASK(23)
45 #define ZONE_24 ZONEMASK(24)
46 #define ZONE_25 ZONEMASK(25)
47 #define ZONE_26 ZONEMASK(26)
48 #define ZONE_27 ZONEMASK(27)
49 #define ZONE_28 ZONEMASK(28)
50 #define ZONE_INFO ZONEMASK(29) // Reserved for lib
51 #define ZONE_WARN ZONEMASK(30) // Reserved for lib
52 #define ZONE_ERR ZONEMASK(31) // Reserved for lib
54 #define ZONE_TEXT_10 "Init"
55 #define ZONE_TEXT_11 "Function"
56 #define ZONE_TEXT_12 "Memory"
57 #define ZONE_TEXT_13 ""
58 #define ZONE_TEXT_14 ""
59 #define ZONE_TEXT_15 ""
60 #define ZONE_TEXT_16 ""
61 #define ZONE_TEXT_17 ""
62 #define ZONE_TEXT_18 ""
63 #define ZONE_TEXT_19 ""
64 #define ZONE_TEXT_20 ""
65 #define ZONE_TEXT_21 ""
66 #define ZONE_TEXT_22 ""
67 #define ZONE_TEXT_23 ""
68 #define ZONE_TEXT_24 ""
69 #define ZONE_TEXT_25 ""
70 #define ZONE_TEXT_26 ""
71 #define ZONE_TEXT_27 ""
72 #define ZONE_TEXT_28 ""
73 #define ZONE_TEXT_29 "Info"
74 #define ZONE_TEXT_30 "Warning"
75 #define ZONE_TEXT_31 "Error"
77 #ifndef FRAMEWORKUNIFIEDLOGOPTIONS
78 #define FRAMEWORKUNIFIEDLOGOPTIONS (LPRINT|LMSGQ) // LPRINT , LMSGQ, LSLOGGER
81 #ifndef FRAMEWORKUNIFIEDLOGAPPZONES
82 #define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_OUT, ZONE_WARN, ZONE_ERR, ZONE_STATE, ZONE_PERFORMANCE, ZONE_SYSTEMDATA
98 #define TSKM_LOG_ERROR 0x00000001U
99 #define TSKM_LOG_STATE 0x00000002U
100 #define TSKM_LOG_DEBUG 0x00000004U
101 #define TSKM_LOG_API 0x00000008U
102 #define TSKM_LOG_PORTPF 0x00000010U
103 #define TSKM_LOG_FUNC 0x00000020U
104 #define TSKM_LOG_MSG 0x00000040U
105 #define TSKM_LOG_WARN 0x00000080U
106 #define TSKM_LOG_SVCSTATE 0x00000100U
107 #define TSKM_LOG_SYSTEMDATA 0x00000200U
110 #define TSKM_LOG_CUSTUM (0 \
124 #define TSKM_DEFAULT_PRINTF(flag, fmt, ...) { \
126 case TSKM_LOG_SYSTEMDATA: \
127 FRAMEWORKUNIFIEDLOG(ZONE_SYSTEMDATA, __FUNCTION__, fmt, ##__VA_ARGS__); \
130 case TSKM_LOG_STATE: \
131 FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, fmt, ##__VA_ARGS__); \
133 case TSKM_LOG_ERROR: \
134 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, fmt, ##__VA_ARGS__); \
136 case TSKM_LOG_WARN: \
137 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, fmt, ##__VA_ARGS__); \
139 case TSKM_LOG_DEBUG: \
140 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, fmt, ##__VA_ARGS__); \
143 case TSKM_LOG_FUNC: \
144 case TSKM_LOG_PORTPF: \
146 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, fmt, ##__VA_ARGS__); \
151 #define TSKM_PRINTF(flag, fmt, ...) { \
152 if (TSKM_LOG_SVCSTATE == flag) { \
153 /* Logs at startup and termination */ \
154 FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, fmt, ## __VA_ARGS__); \
155 } else if (TSKM_LOG_CUSTUM & flag) { \
156 /* Logging by STATE when CUSTUM is specified */ \
157 FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, fmt, ## __VA_ARGS__); \
159 TSKM_DEFAULT_PRINTF(flag, fmt, ## __VA_ARGS__); \
163 #define TSKM_ASSERT(x) \
165 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TSKM_ASSERT"); \
168 #define TSKM_ASSERT_ERRNO(x) \
170 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TSKM_ASSERT %d:%s", errno, strerror(errno)); \
173 #define TSKM_ASSERT_PRINT(x, fmt, ...) \
175 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TSKM_ASSERT:" fmt, ## __VA_ARGS__); \
178 #define TSKM_STATIC_ASSERT(expr) \
180 char STATIC_ASSERTION_FAILED[(expr) ? 1 : -1]; \
181 (void)STATIC_ASSERTION_FAILED; \
184 #define TSKM_DUMP(addr, size) { \
185 char* buf = (char*)addr; /* NOLINT (readability/casting) */ \
187 printf("[DUMP] %s:%d addr:%p size:%d", __FUNCTION__, __LINE__, addr, size); \
188 for (ii=0 ; ii < size ; ii++) { \
189 if (ii%16 == 0) printf(" "); \
190 if (ii%32 == 0) printf("\n"); \
191 printf("%02x", buf[ii]); \
196 #define TSKM_FUNC_IN() TSKM_PRINTF(TSKM_LOG_FUNC, "%s:IN", __FUNCTION__)
198 #define TSKM_FUNC_OUT() TSKM_PRINTF(TSKM_LOG_FUNC, "%s:OUT", __FUNCTION__)
200 const char* tskm_convState2Str(TSKM_STATE_t state);
201 const char* tskm_convLocalStep2Str(TSKM_LOCAL_STEP_t localStep);
202 const char* tskm_convEvent2Str(TSKM_EVENT_t event);
203 const char* tskm_convInitCompId2Str(uint64_t compId);
204 const char* tskm_convTermCompId2Str(uint64_t compId);
205 const char* tskm_convSvcState2Str(TSKM_SVC_STATE_t state);
206 void tskm_svcsDump(TSKM_SVCS_CTX_t* p_svcs);
208 #endif // TASK_MANAGER_SERVER_INCLUDE_TSKM_DEBUG_H_