|
31 | 31 | * Ranjani Sridharan <ranjani.sridharan@linux.intel.com> |
32 | 32 | */ |
33 | 33 |
|
34 | | -#include <sof/preproc.h> |
35 | 34 | #include <stdint.h> |
36 | | -#include <stdio.h> |
37 | | -#include <string.h> |
38 | 35 | #include "host/common_test.h" |
39 | 36 | #include "host/trace.h" |
40 | 37 |
|
41 | | -#define MAX_TRACE_CLASSES 255 |
42 | | -/* testbench trace definition */ |
43 | | - |
44 | 38 | /* enable trace by default in testbench */ |
45 | | -static int test_bench_trace = 1; |
46 | | -int num_trace_classes; |
47 | | - |
48 | | -/* set up trace class identifier table based on SOF trace header file */ |
49 | | -int setup_trace_table(void) |
50 | | -{ |
51 | | - char buffer[2048]; |
52 | | - char *trace = "uapi/logging.h"; |
53 | | - char *trace_filename = malloc(strlen(SOF_INC) + strlen(trace) + 2); |
54 | | - char *token; |
55 | | - int ret, i = 0; |
56 | | - size_t size; |
57 | | - FILE *fp; |
58 | | - |
59 | | - /* set up trace file name using include directory prefix */ |
60 | | - sprintf(trace_filename, "%s/%s", SOF_INC, trace); |
61 | | - |
62 | | - fp = fopen(trace_filename, "r"); |
63 | | - if (!fp) { |
64 | | - fprintf(stderr, "error: opening trace include file %s\n", |
65 | | - trace_filename); |
66 | | - return -EINVAL; |
67 | | - } |
68 | | - |
69 | | - /* find number of trace classes defined */ |
70 | | - while (fgets(buffer, sizeof(buffer), fp)) { |
71 | | - char identifier[1024]; |
72 | | - int value = 0, shift = 0; |
73 | | - |
74 | | - ret = sscanf(buffer, "#define %s (%d << %d)", identifier, |
75 | | - &value, &shift); |
76 | | - if (ret == 3) { |
77 | | - /* if TRACE_CLASS definition */ |
78 | | - if (strstr(identifier, "TRACE_CLASS")) |
79 | | - i++; |
80 | | - } |
81 | | - } |
82 | | - |
83 | | - num_trace_classes = i; |
84 | | - |
85 | | - /* allocate memory for trace table */ |
86 | | - size = sizeof(struct trace_class_table); |
87 | | - trace_table = (struct trace_class_table *)malloc(size * |
88 | | - num_trace_classes); |
| 39 | +int test_bench_trace = 1; |
89 | 40 |
|
90 | | - /* rewind file pointer */ |
91 | | - fseek(fp, 0, SEEK_SET); |
92 | | - |
93 | | - i = 0; |
94 | | - |
95 | | - /* read lines from header */ |
96 | | - while (fgets(buffer, sizeof(buffer), fp)) { |
97 | | - char identifier[1024]; |
98 | | - int value = 0, shift = 0; |
99 | | - |
100 | | - ret = sscanf(buffer, "#define %s (%d << %d)", identifier, |
101 | | - &value, &shift); |
102 | | - if (ret == 3) { |
103 | | - /* if TRACE_CLASS definition */ |
104 | | - if (strstr(identifier, "TRACE_CLASS")) { |
105 | | - /* extract subsystem name */ |
106 | | - token = strtok(identifier, "_"); |
107 | | - token = strtok(NULL, "_"); |
108 | | - token = strtok(NULL, "_"); |
109 | | - |
110 | | - /* add trace class entry */ |
111 | | - trace_table[i].trace_class = value; |
112 | | - trace_table[i].class_name = strdup(token); |
113 | | - i++; |
114 | | - } |
115 | | - } |
116 | | - } |
117 | | - fclose(fp); |
118 | | - free(trace_filename); |
119 | | - return 0; |
120 | | -} |
121 | | - |
122 | | -void free_trace_table(void) |
123 | | -{ |
124 | | - int i; |
125 | | - |
126 | | - for (i = 0; i < num_trace_classes; i++) |
127 | | - free(trace_table[i].class_name); |
128 | | - |
129 | | - free(trace_table); |
130 | | -} |
| 41 | +#define CASE(x) case TRACE_CLASS_##x: return #x |
131 | 42 |
|
132 | 43 | /* look up subsystem class name from table */ |
133 | | -static char *get_trace_class(uint32_t trace_class) |
| 44 | +char *get_trace_class(uint32_t trace_class) |
134 | 45 | { |
135 | | - int i; |
136 | | - |
137 | | - /* look up trace class table and return subsystem name */ |
138 | | - for (i = 0; i < num_trace_classes; i++) { |
139 | | - if (trace_table[i].trace_class == trace_class) |
140 | | - return trace_table[i].class_name; |
| 46 | + switch (trace_class) { |
| 47 | + CASE(IRQ); |
| 48 | + CASE(IPC); |
| 49 | + CASE(PIPE); |
| 50 | + CASE(HOST); |
| 51 | + CASE(DAI); |
| 52 | + CASE(DMA); |
| 53 | + CASE(SSP); |
| 54 | + CASE(COMP); |
| 55 | + CASE(WAIT); |
| 56 | + CASE(LOCK); |
| 57 | + CASE(MEM); |
| 58 | + CASE(MIXER); |
| 59 | + CASE(BUFFER); |
| 60 | + CASE(VOLUME); |
| 61 | + CASE(SWITCH); |
| 62 | + CASE(MUX); |
| 63 | + CASE(SRC); |
| 64 | + CASE(TONE); |
| 65 | + CASE(EQ_FIR); |
| 66 | + CASE(EQ_IIR); |
| 67 | + CASE(SA); |
| 68 | + CASE(DMIC); |
| 69 | + CASE(POWER); |
| 70 | + default: return "unknown"; |
141 | 71 | } |
142 | | - |
143 | | - return "value"; |
144 | | -} |
145 | | - |
146 | | -#define META_SEQ_STEP_param_procU(i, _) META_CONCAT(param, i) %u |
147 | | - |
148 | | -#define HOST_TRACE_EVENT_NTH_PARAMS(id_count, param_count) \ |
149 | | - uintptr_t event \ |
150 | | - META_SEQ_FROM_0_TO(id_count , META_SEQ_STEP_id_uint32_t) \ |
151 | | - META_SEQ_FROM_0_TO(param_count, META_SEQ_STEP_param_uint32_t) |
152 | | - |
153 | | -#define HOST_TRACE_EVENT_NTH(postfix, param_count) \ |
154 | | - META_FUNC_WITH_VARARGS( \ |
155 | | - _trace_event, META_CONCAT(postfix, param_count), \ |
156 | | - void, HOST_TRACE_EVENT_NTH_PARAMS(2, param_count) \ |
157 | | - ) |
158 | | - |
159 | | -/* print trace event */ |
160 | | -#define HOST_TRACE_EVENT_NTH_IMPL(arg_count) \ |
161 | | -HOST_TRACE_EVENT_NTH(, arg_count) \ |
162 | | -{ \ |
163 | | - char a, b, c; \ |
164 | | - \ |
165 | | - if (test_bench_trace > 0) { \ |
166 | | - /* look up subsystem from trace class table */ \ |
167 | | - char *trace_class = strdup(get_trace_class(event >> 24));\ |
168 | | - \ |
169 | | - a = event & 0xff; \ |
170 | | - b = (event >> 8) & 0xff; \ |
171 | | - c = (event >> 16) & 0xff; \ |
172 | | - \ |
173 | | - /* print trace event stderr*/ \ |
174 | | - if (!strcmp(trace_class, "value")) \ |
175 | | - fprintf(stderr, \ |
176 | | - "Trace value %lu, "META_QUOTE( \ |
177 | | - META_SEQ_FROM_0_TO(arg_count, \ |
178 | | - META_SEQ_STEP_param_procU \ |
179 | | - ))"\n" \ |
180 | | - , event META_SEQ_FROM_0_TO(arg_count, \ |
181 | | - META_SEQ_STEP_param)); \ |
182 | | - else \ |
183 | | - fprintf(stderr, \ |
184 | | - "Trace %s %c%c%c\n" \ |
185 | | - , trace_class, c, b, a); \ |
186 | | - if (trace_class) \ |
187 | | - free(trace_class); \ |
188 | | - } \ |
189 | | -} \ |
190 | | -HOST_TRACE_EVENT_NTH(_mbox_atomic, arg_count) \ |
191 | | -{ \ |
192 | | - META_CONCAT(_trace_event, arg_count) \ |
193 | | - (event META_SEQ_FROM_0_TO(2, META_SEQ_STEP_id) \ |
194 | | - META_SEQ_FROM_0_TO(arg_count, META_SEQ_STEP_param)); \ |
195 | 72 | } |
196 | 73 |
|
197 | | -/* Implementation of |
198 | | - * void _trace_event0( uint32_t log_entry, uint32_t params...) {...} |
199 | | - * void _trace_event_mbox_atomic0(uint32_t log_entry, uint32_t params...) {...} |
200 | | - */ |
201 | | -HOST_TRACE_EVENT_NTH_IMPL(0); |
202 | | - |
203 | | -/* Implementation of |
204 | | - * void _trace_event1( uint32_t log_entry, uint32_t params...) {...} |
205 | | - * void _trace_event_mbox_atomic1(uint32_t log_entry, uint32_t params...) {...} |
206 | | - */ |
207 | | -HOST_TRACE_EVENT_NTH_IMPL(1); |
208 | | - |
209 | | -/* Implementation of |
210 | | - * void _trace_event2( uint32_t log_entry, uint32_t params...) {...} |
211 | | - * void _trace_event_mbox_atomic2(uint32_t log_entry, uint32_t params...) {...} |
212 | | - */ |
213 | | -HOST_TRACE_EVENT_NTH_IMPL(2); |
214 | | - |
215 | | -/* Implementation of |
216 | | - * void _trace_event3( uint32_t log_entry, uint32_t params...) {...} |
217 | | - * void _trace_event_mbox_atomic3(uint32_t log_entry, uint32_t params...) {...} |
218 | | - */ |
219 | | -HOST_TRACE_EVENT_NTH_IMPL(3); |
220 | | - |
221 | | -/* Implementation of |
222 | | - * void _trace_event4( uint32_t log_entry, uint32_t params...) {...} |
223 | | - * void _trace_event_mbox_atomic4(uint32_t log_entry, uint32_t params...) {...} |
224 | | - */ |
225 | | -HOST_TRACE_EVENT_NTH_IMPL(4); |
226 | | - |
227 | | -/* Implementation of |
228 | | - * void _trace_event5( uint32_t log_entry, uint32_t params...) {...} |
229 | | - * void _trace_event_mbox_atomic5(uint32_t log_entry, uint32_t params...) {...} |
230 | | - */ |
231 | | -HOST_TRACE_EVENT_NTH_IMPL(5); |
232 | | - |
233 | 74 | /* enable trace in testbench */ |
234 | 75 | void tb_enable_trace(bool enable) |
235 | 76 | { |
|
0 commit comments