Add gitlab issue/merge request templates
[staging/basesystem.git] / service / system / task_manager / server / include / tskm_debug.h
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef TASK_MANAGER_SERVER_INCLUDE_TSKM_DEBUG_H_
18 #define TASK_MANAGER_SERVER_INCLUDE_TSKM_DEBUG_H_
19
20 #include <stdio.h>
21 #include <sys/types.h>
22 #include <unistd.h>
23 #include <native_service/ns_logger_if.h>
24 #include "system_service/tskm_svc.h"
25
26 #include "system_service/tskm_local_type.h"
27
28 #define TSKM_STATIC static
29
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
53
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"
76
77 #ifndef  FRAMEWORKUNIFIEDLOGOPTIONS
78 #define FRAMEWORKUNIFIEDLOGOPTIONS (LPRINT|LMSGQ)  // LPRINT , LMSGQ, LSLOGGER
79 #endif
80
81 #ifndef FRAMEWORKUNIFIEDLOGAPPZONES
82 #define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_OUT, ZONE_WARN, ZONE_ERR, ZONE_STATE, ZONE_PERFORMANCE, ZONE_SYSTEMDATA
83 /*
84  ZONE_NS_FUNC,\
85   ZONE_NS_DIS,\
86   ZONE_NS__CWORD77_,\
87   ZONE_NS_IMP_INFO,\
88   ZONE_NS_SM_DEV_INFO,\
89   ZONE_NS_SM_USR_INFO,\
90   ZONE_NS_INFO,\
91   ZONE_NS_DEBUG_DUMP,\
92   ZONE_NS_WAR       ,\
93   ZONE_NS_ERR       ,\
94   ZONE_DEBUG_DUMP
95  */
96 #endif
97
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
108
109 // For debugging
110 #define TSKM_LOG_CUSTUM  (0 \
111                         )
112 /*
113  |TSKM_LOG_MSG    \
114                          |TSKM_LOG_DEBUG  \
115                          |TSKM_LOG_FUNC   \
116                          |TSKM_LOG_PORTPF \
117  */
118
119 typedef enum {
120   TSKM_LOG_TYPE_TEXT,
121   TSKM_LOG_TYPE_PLACE,
122 } TSKM_LOG_TYPE_t;
123
124 #define TSKM_DEFAULT_PRINTF(flag, fmt, ...) { \
125     switch (flag) { \
126         case TSKM_LOG_SYSTEMDATA: \
127             FRAMEWORKUNIFIEDLOG(ZONE_SYSTEMDATA, __FUNCTION__, fmt, ##__VA_ARGS__); \
128             break; \
129         case TSKM_LOG_API: \
130         case TSKM_LOG_STATE: \
131             FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, fmt, ##__VA_ARGS__); \
132             break; \
133         case TSKM_LOG_ERROR: \
134             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, fmt, ##__VA_ARGS__); \
135             break; \
136         case TSKM_LOG_WARN: \
137             FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, fmt, ##__VA_ARGS__); \
138             break; \
139         case TSKM_LOG_DEBUG: \
140             FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, fmt, ##__VA_ARGS__); \
141             break; \
142         case TSKM_LOG_MSG: \
143         case TSKM_LOG_FUNC: \
144         case TSKM_LOG_PORTPF: \
145         default: \
146             FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, fmt, ##__VA_ARGS__); \
147             break; \
148     } \
149   }
150
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__); \
158     } else { \
159       TSKM_DEFAULT_PRINTF(flag, fmt, ## __VA_ARGS__); \
160     } \
161   }
162
163 #define TSKM_ASSERT(x)  \
164           if (!(x)) { \
165             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TSKM_ASSERT"); \
166           }
167
168 #define TSKM_ASSERT_ERRNO(x)  \
169           if (!(x)) { \
170              FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TSKM_ASSERT %d:%s", errno, strerror(errno)); \
171           }
172
173 #define TSKM_ASSERT_PRINT(x, fmt, ...) \
174           if (!(x)) { \
175             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "TSKM_ASSERT:" fmt, ## __VA_ARGS__); \
176           }
177
178 #define TSKM_STATIC_ASSERT(expr) \
179   { \
180     char STATIC_ASSERTION_FAILED[(expr) ? 1 : -1]; \
181     (void)STATIC_ASSERTION_FAILED; \
182   }
183
184 #define TSKM_DUMP(addr, size) { \
185     char* buf = (char*)addr;  /* NOLINT (readability/casting) */  \
186     int ii; \
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]);  \
192     } \
193     printf("\n"); \
194   }
195
196 #define TSKM_FUNC_IN() TSKM_PRINTF(TSKM_LOG_FUNC, "%s:IN", __FUNCTION__)
197
198 #define TSKM_FUNC_OUT() TSKM_PRINTF(TSKM_LOG_FUNC, "%s:OUT", __FUNCTION__)
199
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);
207
208 #endif  // TASK_MANAGER_SERVER_INCLUDE_TSKM_DEBUG_H_