Commit | Line | Data |
---|---|---|
dbc20d3c JR |
1 | /* |
2 | * Unit tests for the notification API. | |
3 | * | |
4 | * Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> | |
5 | * | |
6 | * SPDX-License-Identifier: LGPL-2.1-only | |
7 | * | |
8 | */ | |
9 | ||
dbc20d3c JR |
10 | #include <inttypes.h> |
11 | #include <stdio.h> | |
12 | #include <string.h> | |
13 | #include <unistd.h> | |
14 | ||
15 | #include <tap/tap.h> | |
16 | ||
17 | #include <common/payload-view.h> | |
18 | #include <common/payload.h> | |
19 | #include <lttng/domain.h> | |
b47b01d8 JR |
20 | #include <lttng/event-rule/jul-logging-internal.h> |
21 | #include <lttng/event-rule/jul-logging.h> | |
85522de5 JR |
22 | #include <lttng/event-rule/kernel-kprobe-internal.h> |
23 | #include <lttng/event-rule/kernel-kprobe.h> | |
4f7da553 JR |
24 | #include <lttng/event-rule/kernel-syscall-internal.h> |
25 | #include <lttng/event-rule/kernel-syscall.h> | |
6530ec7d JR |
26 | #include <lttng/event-rule/python-logging-internal.h> |
27 | #include <lttng/event-rule/python-logging.h> | |
af0818ef JR |
28 | #include <lttng/event-rule/kernel-tracepoint-internal.h> |
29 | #include <lttng/event-rule/kernel-tracepoint.h> | |
46fd07ac JR |
30 | #include <lttng/event-rule/kernel-uprobe-internal.h> |
31 | #include <lttng/event-rule/kernel-uprobe.h> | |
0a23a07d JR |
32 | #include <lttng/event-rule/user-tracepoint-internal.h> |
33 | #include <lttng/event-rule/user-tracepoint.h> | |
dbc20d3c JR |
34 | #include <lttng/event.h> |
35 | #include <lttng/kernel-probe-internal.h> | |
36 | #include <lttng/kernel-probe.h> | |
37 | #include <lttng/userspace-probe-internal.h> | |
38 | #include <lttng/userspace-probe.h> | |
2b4c142d | 39 | #include "bin/lttng/loglevel.h" |
dbc20d3c JR |
40 | |
41 | /* For error.h. */ | |
42 | int lttng_opt_quiet = 1; | |
43 | int lttng_opt_verbose; | |
44 | int lttng_opt_mi; | |
45 | ||
695f7044 | 46 | #define NUM_TESTS 212 |
dbc20d3c JR |
47 | |
48 | struct tracepoint_test { | |
49 | enum lttng_domain_type type; | |
975d26c5 | 50 | bool support_name_pattern_exclusion; |
dbc20d3c JR |
51 | }; |
52 | ||
2b4c142d JG |
53 | typedef const char *(*log_level_name_getter)(int log_level); |
54 | ||
cade690d JR |
55 | typedef struct lttng_event_rule *(*event_rule_create)(void); |
56 | typedef enum lttng_event_rule_status (*event_rule_set_log_level)( | |
57 | struct lttng_event_rule *rule, | |
58 | const struct lttng_log_level_rule *log_level_rule); | |
59 | ||
af0818ef JR |
60 | static |
61 | void test_event_rule_kernel_tracepoint(void) | |
62 | { | |
63 | struct lttng_event_rule *tracepoint = NULL; | |
64 | struct lttng_event_rule *tracepoint_from_buffer = NULL; | |
65 | enum lttng_event_rule_status status; | |
66 | const char *pattern="my_event_*"; | |
67 | const char *filter="msg_id == 23 && size >= 2048"; | |
68 | const char *tmp; | |
69 | struct lttng_payload payload; | |
70 | ||
71 | diag("Testing lttng_event_rule_kernel_tracepoint."); | |
72 | ||
73 | lttng_payload_init(&payload); | |
74 | ||
75 | tracepoint = lttng_event_rule_kernel_tracepoint_create(); | |
76 | ok(tracepoint, "tracepoint object."); | |
77 | ||
78 | status = lttng_event_rule_kernel_tracepoint_set_name_pattern(tracepoint, pattern); | |
79 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); | |
80 | status = lttng_event_rule_kernel_tracepoint_get_name_pattern(tracepoint, &tmp); | |
81 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); | |
82 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
83 | ||
84 | status = lttng_event_rule_kernel_tracepoint_set_filter(tracepoint, filter); | |
85 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); | |
86 | status = lttng_event_rule_kernel_tracepoint_get_filter(tracepoint, &tmp); | |
87 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); | |
88 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
89 | ||
90 | ok(lttng_event_rule_serialize(tracepoint, &payload) == 0, "Serializing."); | |
91 | ||
92 | { | |
93 | struct lttng_payload_view view = | |
94 | lttng_payload_view_from_payload( | |
95 | &payload, 0, -1); | |
96 | ||
97 | ok(lttng_event_rule_create_from_payload( | |
98 | &view, &tracepoint_from_buffer) > 0, | |
99 | "Deserializing."); | |
100 | } | |
101 | ||
102 | ok(lttng_event_rule_is_equal(tracepoint, tracepoint_from_buffer), "serialized and from buffer are equal."); | |
103 | ||
104 | lttng_payload_reset(&payload); | |
105 | lttng_event_rule_destroy(tracepoint); | |
106 | lttng_event_rule_destroy(tracepoint_from_buffer); | |
107 | } | |
108 | ||
0a23a07d JR |
109 | static |
110 | void test_event_rule_user_tracepoint(void) | |
111 | { | |
112 | int i; | |
113 | unsigned int count; | |
114 | struct lttng_event_rule *tracepoint = NULL; | |
115 | struct lttng_event_rule *tracepoint_from_buffer = NULL; | |
116 | enum lttng_event_rule_status status; | |
117 | const char *pattern="my_event_*"; | |
118 | const char *filter="msg_id == 23 && size >= 2048"; | |
119 | const char *tmp; | |
120 | const char *name_pattern_exclusions[] = {"my_event_test1", "my_event_test2" ,"my_event_test3"}; | |
121 | struct lttng_log_level_rule *log_level_rule = NULL; | |
122 | const struct lttng_log_level_rule *log_level_rule_return = NULL; | |
123 | struct lttng_payload payload; | |
124 | ||
125 | diag("Testing lttng_event_rule_user_tracepoint."); | |
126 | ||
127 | lttng_payload_init(&payload); | |
128 | ||
129 | log_level_rule = lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO); | |
a0377dfe | 130 | LTTNG_ASSERT(log_level_rule); |
0a23a07d JR |
131 | |
132 | tracepoint = lttng_event_rule_user_tracepoint_create(); | |
133 | ok(tracepoint, "user tracepoint object."); | |
134 | ||
135 | status = lttng_event_rule_user_tracepoint_set_name_pattern(tracepoint, pattern); | |
136 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); | |
137 | status = lttng_event_rule_user_tracepoint_get_name_pattern(tracepoint, &tmp); | |
138 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); | |
139 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
140 | ||
141 | status = lttng_event_rule_user_tracepoint_set_filter(tracepoint, filter); | |
142 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); | |
143 | status = lttng_event_rule_user_tracepoint_get_filter(tracepoint, &tmp); | |
144 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); | |
145 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
146 | ||
147 | status = lttng_event_rule_user_tracepoint_get_log_level_rule(tracepoint, &log_level_rule_return); | |
148 | ok(status == LTTNG_EVENT_RULE_STATUS_UNSET, "get unset log level rule."); | |
149 | ||
150 | status = lttng_event_rule_user_tracepoint_set_log_level_rule( | |
151 | tracepoint, log_level_rule); | |
152 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting log level rule."); | |
153 | status = lttng_event_rule_user_tracepoint_get_log_level_rule( | |
154 | tracepoint, &log_level_rule_return); | |
155 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "get log level rule."); | |
156 | ||
157 | /* Name pattern exclusions */ | |
158 | for (i = 0; i < 3; i++) { | |
159 | status = lttng_event_rule_user_tracepoint_add_name_pattern_exclusion( | |
160 | tracepoint, name_pattern_exclusions[i]); | |
161 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, | |
162 | "setting name pattern exclusions \"%s\"", | |
163 | name_pattern_exclusions[i]); | |
164 | } | |
165 | ||
166 | status = lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_count( | |
167 | tracepoint, &count); | |
168 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, | |
169 | "getting name pattern exclusion count."); | |
170 | ok(count == 3, "count is %d/3", count); | |
171 | ||
172 | for (i = 0; i < count; i++) { | |
173 | status = lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_at_index( | |
174 | tracepoint, i, &tmp); | |
175 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, | |
176 | "getting name pattern exclusion at index %d.", | |
177 | i); | |
178 | ok(!strncmp(name_pattern_exclusions[i], tmp, | |
179 | strlen(name_pattern_exclusions[i])), | |
180 | "%s == %s.", tmp, name_pattern_exclusions[i]); | |
181 | } | |
182 | ||
183 | ok(lttng_event_rule_serialize(tracepoint, &payload) == 0, "Serializing."); | |
184 | ||
185 | { | |
186 | struct lttng_payload_view view = | |
187 | lttng_payload_view_from_payload( | |
188 | &payload, 0, -1); | |
189 | ||
190 | ok(lttng_event_rule_create_from_payload( | |
191 | &view, &tracepoint_from_buffer) > 0, | |
192 | "Deserializing."); | |
193 | } | |
194 | ||
195 | ok(lttng_event_rule_is_equal(tracepoint, tracepoint_from_buffer), "serialized and from buffer are equal."); | |
196 | ||
197 | lttng_payload_reset(&payload); | |
198 | lttng_event_rule_destroy(tracepoint); | |
199 | lttng_event_rule_destroy(tracepoint_from_buffer); | |
200 | lttng_log_level_rule_destroy(log_level_rule); | |
201 | } | |
202 | ||
dbc20d3c JR |
203 | static void test_event_rule_syscall(void) |
204 | { | |
205 | struct lttng_event_rule *syscall = NULL; | |
206 | struct lttng_event_rule *syscall_from_buffer = NULL; | |
207 | enum lttng_event_rule_status status; | |
208 | const char *pattern = "my_event_*"; | |
209 | const char *filter = "msg_id == 23 && size >= 2048"; | |
210 | const char *tmp; | |
211 | struct lttng_payload payload; | |
212 | ||
213 | diag("Event rule syscall."); | |
214 | ||
215 | lttng_payload_init(&payload); | |
216 | ||
4f7da553 | 217 | syscall = lttng_event_rule_kernel_syscall_create(LTTNG_EVENT_RULE_KERNEL_SYSCALL_EMISSION_SITE_ENTRY); |
dbc20d3c JR |
218 | ok(syscall, "syscall object."); |
219 | ||
4f7da553 | 220 | status = lttng_event_rule_kernel_syscall_set_name_pattern(syscall, pattern); |
dbc20d3c | 221 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); |
4f7da553 | 222 | status = lttng_event_rule_kernel_syscall_get_name_pattern(syscall, &tmp); |
dbc20d3c JR |
223 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); |
224 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
225 | ||
4f7da553 | 226 | status = lttng_event_rule_kernel_syscall_set_filter(syscall, filter); |
dbc20d3c | 227 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); |
4f7da553 | 228 | status = lttng_event_rule_kernel_syscall_get_filter(syscall, &tmp); |
dbc20d3c JR |
229 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); |
230 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
231 | ||
232 | ok(lttng_event_rule_serialize(syscall, &payload) == 0, "Serializing."); | |
233 | ||
234 | { | |
235 | struct lttng_payload_view view = | |
236 | lttng_payload_view_from_payload( | |
237 | &payload, 0, -1); | |
238 | ||
239 | ok(lttng_event_rule_create_from_payload( | |
240 | &view, &syscall_from_buffer) > 0, | |
241 | "Deserializing."); | |
242 | } | |
243 | ||
244 | ok(lttng_event_rule_is_equal(syscall, syscall_from_buffer), | |
245 | "serialized and from buffer are equal."); | |
246 | ||
247 | lttng_payload_reset(&payload); | |
248 | lttng_event_rule_destroy(syscall); | |
249 | lttng_event_rule_destroy(syscall_from_buffer); | |
250 | } | |
251 | ||
b47b01d8 JR |
252 | static |
253 | void test_event_rule_jul_logging(void) | |
254 | { | |
255 | struct lttng_event_rule *jul_logging = NULL; | |
256 | struct lttng_event_rule *jul_logging_from_buffer = NULL; | |
257 | enum lttng_event_rule_status status; | |
258 | const char *pattern="my_event_*"; | |
259 | const char *filter="msg_id == 23 && size >= 2048"; | |
260 | const char *tmp; | |
261 | struct lttng_log_level_rule *log_level_rule = NULL; | |
262 | const struct lttng_log_level_rule *log_level_rule_return = NULL; | |
263 | struct lttng_payload payload; | |
264 | ||
265 | diag("Testing lttng_event_rule_user_jul_logging."); | |
266 | ||
267 | lttng_payload_init(&payload); | |
268 | ||
269 | log_level_rule = lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO); | |
a0377dfe | 270 | LTTNG_ASSERT(log_level_rule); |
b47b01d8 JR |
271 | |
272 | jul_logging = lttng_event_rule_jul_logging_create(); | |
273 | ok(jul_logging, "jul_logging object."); | |
274 | ||
275 | status = lttng_event_rule_jul_logging_set_name_pattern(jul_logging, pattern); | |
276 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); | |
277 | status = lttng_event_rule_jul_logging_get_name_pattern(jul_logging, &tmp); | |
278 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); | |
279 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
280 | ||
281 | status = lttng_event_rule_jul_logging_set_filter(jul_logging, filter); | |
282 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); | |
283 | status = lttng_event_rule_jul_logging_get_filter(jul_logging, &tmp); | |
284 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); | |
285 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
286 | ||
287 | status = lttng_event_rule_jul_logging_get_log_level_rule(jul_logging, &log_level_rule_return); | |
288 | ok(status == LTTNG_EVENT_RULE_STATUS_UNSET, "get unset log level rule."); | |
289 | ||
290 | status = lttng_event_rule_jul_logging_set_log_level_rule( | |
291 | jul_logging, log_level_rule); | |
292 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting log level rule."); | |
293 | status = lttng_event_rule_jul_logging_get_log_level_rule( | |
294 | jul_logging, &log_level_rule_return); | |
295 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "get log level rule."); | |
296 | ||
297 | ok(lttng_event_rule_serialize(jul_logging, &payload) == 0, "Serializing."); | |
298 | ||
299 | { | |
300 | struct lttng_payload_view view = | |
301 | lttng_payload_view_from_payload( | |
302 | &payload, 0, -1); | |
303 | ||
304 | ok(lttng_event_rule_create_from_payload( | |
305 | &view, &jul_logging_from_buffer) > 0, | |
306 | "Deserializing."); | |
307 | } | |
308 | ||
309 | ok(lttng_event_rule_is_equal(jul_logging, jul_logging_from_buffer), "serialized and from buffer are equal."); | |
310 | ||
311 | lttng_payload_reset(&payload); | |
312 | lttng_event_rule_destroy(jul_logging); | |
313 | lttng_event_rule_destroy(jul_logging_from_buffer); | |
314 | lttng_log_level_rule_destroy(log_level_rule); | |
315 | } | |
316 | ||
138d6838 JR |
317 | static |
318 | void test_event_rule_log4j_logging(void) | |
319 | { | |
320 | struct lttng_event_rule *log4j_logging = NULL; | |
321 | struct lttng_event_rule *log4j_logging_from_buffer = NULL; | |
322 | enum lttng_event_rule_status status; | |
323 | const char *pattern="my_event_*"; | |
324 | const char *filter="msg_id == 23 && size >= 2048"; | |
325 | const char *tmp; | |
326 | struct lttng_log_level_rule *log_level_rule = NULL; | |
327 | const struct lttng_log_level_rule *log_level_rule_return = NULL; | |
328 | struct lttng_payload payload; | |
329 | ||
330 | diag("Testing lttng_event_rule_user_log4j_logging."); | |
331 | ||
332 | lttng_payload_init(&payload); | |
333 | ||
334 | log_level_rule = lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO); | |
a0377dfe | 335 | LTTNG_ASSERT(log_level_rule); |
138d6838 JR |
336 | |
337 | log4j_logging = lttng_event_rule_log4j_logging_create(); | |
338 | ok(log4j_logging, "log4j_logging object."); | |
339 | ||
340 | status = lttng_event_rule_log4j_logging_set_name_pattern(log4j_logging, pattern); | |
341 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); | |
342 | status = lttng_event_rule_log4j_logging_get_name_pattern(log4j_logging, &tmp); | |
343 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); | |
344 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
345 | ||
346 | status = lttng_event_rule_log4j_logging_set_filter(log4j_logging, filter); | |
347 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); | |
348 | status = lttng_event_rule_log4j_logging_get_filter(log4j_logging, &tmp); | |
349 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); | |
350 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
351 | ||
352 | status = lttng_event_rule_log4j_logging_get_log_level_rule(log4j_logging, &log_level_rule_return); | |
353 | ok(status == LTTNG_EVENT_RULE_STATUS_UNSET, "get unset log level rule."); | |
354 | ||
355 | status = lttng_event_rule_log4j_logging_set_log_level_rule( | |
356 | log4j_logging, log_level_rule); | |
357 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting log level rule."); | |
358 | status = lttng_event_rule_log4j_logging_get_log_level_rule( | |
359 | log4j_logging, &log_level_rule_return); | |
360 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "get log level rule."); | |
361 | ||
362 | ok(lttng_event_rule_serialize(log4j_logging, &payload) == 0, "Serializing."); | |
363 | ||
364 | { | |
365 | struct lttng_payload_view view = | |
366 | lttng_payload_view_from_payload( | |
367 | &payload, 0, -1); | |
368 | ||
369 | ok(lttng_event_rule_create_from_payload( | |
370 | &view, &log4j_logging_from_buffer) > 0, | |
371 | "Deserializing."); | |
372 | } | |
373 | ||
374 | ok(lttng_event_rule_is_equal(log4j_logging, log4j_logging_from_buffer), "serialized and from buffer are equal."); | |
375 | ||
376 | lttng_payload_reset(&payload); | |
377 | lttng_event_rule_destroy(log4j_logging); | |
378 | lttng_event_rule_destroy(log4j_logging_from_buffer); | |
379 | lttng_log_level_rule_destroy(log_level_rule); | |
380 | } | |
381 | ||
6530ec7d JR |
382 | static |
383 | void test_event_rule_python_logging(void) | |
384 | { | |
385 | struct lttng_event_rule *python_logging = NULL; | |
386 | struct lttng_event_rule *python_logging_from_buffer = NULL; | |
387 | enum lttng_event_rule_status status; | |
388 | const char *pattern="my_event_*"; | |
389 | const char *filter="msg_id == 23 && size >= 2048"; | |
390 | const char *tmp; | |
391 | struct lttng_log_level_rule *log_level_rule = NULL; | |
392 | const struct lttng_log_level_rule *log_level_rule_return = NULL; | |
393 | struct lttng_payload payload; | |
394 | ||
395 | diag("Testing lttng_event_rule_user_python_logging."); | |
396 | ||
397 | lttng_payload_init(&payload); | |
398 | ||
399 | log_level_rule = lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO); | |
a0377dfe | 400 | LTTNG_ASSERT(log_level_rule); |
6530ec7d JR |
401 | |
402 | python_logging = lttng_event_rule_python_logging_create(); | |
403 | ok(python_logging, "python_logging object."); | |
404 | ||
405 | status = lttng_event_rule_python_logging_set_name_pattern(python_logging, pattern); | |
406 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); | |
407 | status = lttng_event_rule_python_logging_get_name_pattern(python_logging, &tmp); | |
408 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); | |
409 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
410 | ||
411 | status = lttng_event_rule_python_logging_set_filter(python_logging, filter); | |
412 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); | |
413 | status = lttng_event_rule_python_logging_get_filter(python_logging, &tmp); | |
414 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); | |
415 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
416 | ||
417 | status = lttng_event_rule_python_logging_get_log_level_rule(python_logging, &log_level_rule_return); | |
418 | ok(status == LTTNG_EVENT_RULE_STATUS_UNSET, "get unset log level rule."); | |
419 | ||
420 | status = lttng_event_rule_python_logging_set_log_level_rule( | |
421 | python_logging, log_level_rule); | |
422 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting log level rule."); | |
423 | status = lttng_event_rule_python_logging_get_log_level_rule( | |
424 | python_logging, &log_level_rule_return); | |
425 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "get log level rule."); | |
426 | ||
427 | ok(lttng_event_rule_serialize(python_logging, &payload) == 0, "Serializing."); | |
428 | ||
429 | { | |
430 | struct lttng_payload_view view = | |
431 | lttng_payload_view_from_payload( | |
432 | &payload, 0, -1); | |
433 | ||
434 | ok(lttng_event_rule_create_from_payload( | |
435 | &view, &python_logging_from_buffer) > 0, | |
436 | "Deserializing."); | |
437 | } | |
438 | ||
439 | ok(lttng_event_rule_is_equal(python_logging, python_logging_from_buffer), "serialized and from buffer are equal."); | |
440 | ||
441 | lttng_payload_reset(&payload); | |
442 | lttng_event_rule_destroy(python_logging); | |
443 | lttng_event_rule_destroy(python_logging_from_buffer); | |
444 | lttng_log_level_rule_destroy(log_level_rule); | |
445 | } | |
446 | ||
1f1567a5 | 447 | static void test_event_rule_userspace_probe(void) |
dbc20d3c JR |
448 | { |
449 | struct lttng_event_rule *uprobe = NULL; | |
450 | struct lttng_event_rule *uprobe_from_buffer = NULL; | |
451 | struct lttng_userspace_probe_location_lookup_method *lookup_method = | |
452 | NULL; | |
453 | struct lttng_userspace_probe_location *probe_location = NULL; | |
454 | const struct lttng_userspace_probe_location *probe_location_tmp = NULL; | |
455 | enum lttng_event_rule_status status; | |
456 | ||
457 | const char *probe_name = "my_probe."; | |
458 | const char *tmp; | |
459 | struct lttng_payload payload; | |
460 | ||
461 | diag("Event rule uprobe."); | |
6610d7be | 462 | lttng_payload_init(&payload); |
dbc20d3c JR |
463 | |
464 | lookup_method = lttng_userspace_probe_location_lookup_method_function_elf_create(); | |
465 | if (!lookup_method) { | |
466 | fail("Setup error on userspace probe lookup method creation."); | |
467 | goto end; | |
468 | } | |
469 | ||
470 | probe_location = lttng_userspace_probe_location_function_create( | |
471 | "/proc/self/exe", | |
472 | "lttng_userspace_probe_location_tracepoint_create", | |
473 | lookup_method); | |
474 | if (!probe_location) { | |
475 | fail("Setup error on userspace probe location creation."); | |
476 | goto end; | |
477 | } | |
478 | ||
479 | /* Ownership transferred to the probe location function object. */ | |
480 | lookup_method = NULL; | |
481 | ||
482 | lttng_payload_init(&payload); | |
483 | ||
46fd07ac | 484 | uprobe = lttng_event_rule_kernel_uprobe_create(probe_location); |
dbc20d3c JR |
485 | ok(uprobe, "uprobe event rule object creation."); |
486 | ||
46fd07ac | 487 | status = lttng_event_rule_kernel_uprobe_get_location( |
dbc20d3c JR |
488 | uprobe, &probe_location_tmp); |
489 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, | |
490 | "Getting uprobe event rule location."); | |
491 | ok(lttng_userspace_probe_location_is_equal( | |
492 | probe_location, probe_location_tmp), | |
493 | "Location is equal."); | |
494 | ||
46fd07ac | 495 | status = lttng_event_rule_kernel_uprobe_set_event_name(uprobe, probe_name); |
dbc20d3c JR |
496 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, |
497 | "Setting uprobe event rule name: %s.", probe_name); | |
46fd07ac | 498 | status = lttng_event_rule_kernel_uprobe_get_event_name(uprobe, &tmp); |
dbc20d3c JR |
499 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "Getting uprobe name."); |
500 | ok(!strcmp(probe_name, tmp), "Uprobe name are equal."); | |
501 | ||
502 | ok(lttng_event_rule_serialize(uprobe, &payload) == 0, "Serializing."); | |
503 | ||
504 | { | |
505 | struct lttng_payload_view view = | |
506 | lttng_payload_view_from_payload( | |
507 | &payload, 0, -1); | |
508 | ||
509 | ok(lttng_event_rule_create_from_payload( | |
510 | &view, &uprobe_from_buffer) > 0, | |
511 | "Deserializing."); | |
512 | } | |
513 | ||
514 | ok(lttng_event_rule_is_equal(uprobe, uprobe_from_buffer), | |
515 | "serialized and from buffer are equal."); | |
516 | ||
517 | end: | |
518 | lttng_payload_reset(&payload); | |
519 | lttng_event_rule_destroy(uprobe); | |
520 | lttng_event_rule_destroy(uprobe_from_buffer); | |
521 | lttng_userspace_probe_location_destroy(probe_location); | |
522 | lttng_userspace_probe_location_lookup_method_destroy(lookup_method); | |
523 | } | |
524 | ||
f2791161 | 525 | static void test_event_rule_kernel_probe_by_location( |
dbc20d3c JR |
526 | const struct lttng_kernel_probe_location *location) |
527 | { | |
528 | struct lttng_event_rule *kprobe = NULL; | |
529 | struct lttng_event_rule *kprobe_from_buffer = NULL; | |
530 | enum lttng_event_rule_status status; | |
531 | const struct lttng_kernel_probe_location *_location; | |
532 | ||
533 | const char *probe_name = "my_probe"; | |
534 | const char *tmp; | |
535 | struct lttng_payload payload; | |
536 | ||
537 | diag("Event rule kprobe for location type %d.", | |
538 | lttng_kernel_probe_location_get_type(location)); | |
539 | ||
540 | lttng_payload_init(&payload); | |
541 | ||
85522de5 | 542 | kprobe = lttng_event_rule_kernel_kprobe_create(location); |
dbc20d3c JR |
543 | ok(kprobe, "kprobe event rule object creation."); |
544 | ||
85522de5 | 545 | status = lttng_event_rule_kernel_kprobe_get_location(kprobe, &_location); |
dbc20d3c JR |
546 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, |
547 | "Getting kprobe event rule location."); | |
548 | ok(lttng_kernel_probe_location_is_equal(location, _location), "Locations are equal."); | |
549 | ||
85522de5 | 550 | status = lttng_event_rule_kernel_kprobe_set_event_name(kprobe, probe_name); |
dbc20d3c JR |
551 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, |
552 | "Setting kprobe event rule name: %s.", probe_name); | |
85522de5 | 553 | status = lttng_event_rule_kernel_kprobe_get_event_name(kprobe, &tmp); |
dbc20d3c JR |
554 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "Getting kprobe name."); |
555 | ok(!strcmp(probe_name, tmp), "kprobe name are equal."); | |
556 | ||
557 | ok(lttng_event_rule_serialize(kprobe, &payload) == 0, "Serializing."); | |
558 | ||
559 | { | |
560 | struct lttng_payload_view view = | |
561 | lttng_payload_view_from_payload( | |
562 | &payload, 0, -1); | |
563 | ||
564 | ok(lttng_event_rule_create_from_payload( | |
565 | &view, &kprobe_from_buffer) > 0, | |
566 | "Deserializing."); | |
567 | } | |
568 | ||
569 | ok(lttng_event_rule_is_equal(kprobe, kprobe_from_buffer), | |
570 | "serialized and from buffer are equal."); | |
571 | ||
572 | lttng_payload_reset(&payload); | |
573 | lttng_event_rule_destroy(kprobe); | |
574 | lttng_event_rule_destroy(kprobe_from_buffer); | |
575 | } | |
576 | ||
f2791161 | 577 | static void test_event_rule_kernel_probe(void) |
dbc20d3c JR |
578 | { |
579 | struct lttng_kernel_probe_location *address_location = NULL; | |
580 | struct lttng_kernel_probe_location *symbol_location = NULL; | |
581 | ||
582 | address_location = lttng_kernel_probe_location_address_create(50); | |
583 | symbol_location = lttng_kernel_probe_location_symbol_create("une_bonne", 50); | |
a0377dfe FD |
584 | LTTNG_ASSERT(address_location); |
585 | LTTNG_ASSERT(symbol_location); | |
dbc20d3c | 586 | |
f2791161 JR |
587 | test_event_rule_kernel_probe_by_location(address_location); |
588 | test_event_rule_kernel_probe_by_location(symbol_location); | |
dbc20d3c JR |
589 | |
590 | lttng_kernel_probe_location_destroy(address_location); | |
591 | lttng_kernel_probe_location_destroy(symbol_location); | |
592 | } | |
593 | ||
2b4c142d JG |
594 | static void test_set_event_rule_log_level_rules( |
595 | struct lttng_event_rule *event_rule, | |
cade690d | 596 | event_rule_set_log_level set_log_level, |
2b4c142d JG |
597 | int log_level, |
598 | enum lttng_event_rule_status *exactly_status, | |
599 | enum lttng_event_rule_status *as_severe_status) | |
600 | { | |
601 | struct lttng_log_level_rule *log_level_rule; | |
602 | ||
603 | log_level_rule = lttng_log_level_rule_at_least_as_severe_as_create( | |
604 | log_level); | |
a0377dfe | 605 | LTTNG_ASSERT(log_level_rule); |
2b4c142d | 606 | |
cade690d | 607 | *as_severe_status = set_log_level( |
2b4c142d JG |
608 | event_rule, log_level_rule); |
609 | lttng_log_level_rule_destroy(log_level_rule); | |
610 | ||
611 | log_level_rule = lttng_log_level_rule_exactly_create(log_level); | |
a0377dfe | 612 | LTTNG_ASSERT(log_level_rule); |
2b4c142d | 613 | |
cade690d | 614 | *exactly_status = set_log_level( |
2b4c142d JG |
615 | event_rule, log_level_rule); |
616 | lttng_log_level_rule_destroy(log_level_rule); | |
617 | } | |
618 | ||
cade690d | 619 | static void test_event_rule_log_level_generic(enum lttng_event_rule_type event_rule_type, |
2b4c142d | 620 | log_level_name_getter get_log_level_name, |
cade690d JR |
621 | event_rule_create create_event_rule, |
622 | event_rule_set_log_level set_log_level, | |
2b4c142d JG |
623 | const int tagged_log_level_values[], |
624 | size_t tagged_log_level_values_count, | |
625 | const int valid_log_level_values[], | |
626 | size_t valid_log_level_values_count, | |
627 | const int invalid_log_level_values[], | |
628 | size_t invalid_log_level_values_count) | |
629 | { | |
630 | size_t i; | |
cade690d | 631 | struct lttng_event_rule *rule; |
2b4c142d | 632 | enum lttng_event_rule_status er_exactly_status, er_as_severe_status; |
cade690d JR |
633 | const char *event_rule_type_str = lttng_event_rule_type_str(event_rule_type); |
634 | ||
2b4c142d | 635 | |
cade690d JR |
636 | diag("Test %s event rule + log level rule", event_rule_type_str); |
637 | ||
638 | rule = create_event_rule(); | |
a0377dfe | 639 | LTTNG_ASSERT(rule); |
2b4c142d JG |
640 | |
641 | for (i = 0; i < tagged_log_level_values_count; i++) { | |
642 | const int tagged_log_level_value = tagged_log_level_values[i]; | |
643 | ||
cade690d | 644 | test_set_event_rule_log_level_rules(rule, set_log_level, |
2b4c142d JG |
645 | tagged_log_level_value, |
646 | &er_exactly_status, &er_as_severe_status); | |
647 | ok(er_exactly_status == LTTNG_EVENT_RULE_STATUS_OK, | |
cade690d JR |
648 | "Log level rule \"exactly\" accepted by %s event rule: level = %s", |
649 | event_rule_type_str, | |
2b4c142d JG |
650 | get_log_level_name( |
651 | tagged_log_level_value)); | |
652 | ok(er_as_severe_status == LTTNG_EVENT_RULE_STATUS_OK, | |
cade690d JR |
653 | "Log level rule \"as least as severe as\" accepted by %s event rule: level = %s", |
654 | event_rule_type_str, | |
2b4c142d JG |
655 | get_log_level_name( |
656 | tagged_log_level_value)); | |
657 | } | |
658 | ||
659 | for (i = 0; i < valid_log_level_values_count; i++) { | |
660 | const int valid_log_level_value = valid_log_level_values[i]; | |
661 | ||
cade690d | 662 | test_set_event_rule_log_level_rules(rule, set_log_level, |
2b4c142d JG |
663 | valid_log_level_value, |
664 | &er_exactly_status, &er_as_severe_status); | |
665 | ok(er_exactly_status == LTTNG_EVENT_RULE_STATUS_OK, | |
cade690d JR |
666 | "Log level rule \"exactly\" accepted by %s event rule: level = %d", |
667 | event_rule_type_str, | |
2b4c142d JG |
668 | valid_log_level_value); |
669 | ok(er_as_severe_status == LTTNG_EVENT_RULE_STATUS_OK, | |
cade690d JR |
670 | "Log level rule \"as least as severe as\" accepted by %s event rule: level = %d", |
671 | event_rule_type_str, | |
2b4c142d JG |
672 | valid_log_level_value); |
673 | } | |
674 | ||
675 | for (i = 0; i < invalid_log_level_values_count; i++) { | |
676 | const int invalid_log_level_value = invalid_log_level_values[i]; | |
677 | ||
cade690d | 678 | test_set_event_rule_log_level_rules(rule, set_log_level, |
2b4c142d JG |
679 | invalid_log_level_value, |
680 | &er_exactly_status, &er_as_severe_status); | |
681 | ok(er_exactly_status == LTTNG_EVENT_RULE_STATUS_INVALID, | |
cade690d JR |
682 | "Log level rule \"exactly\" rejected by %s event rule: level = %d", |
683 | event_rule_type_str, | |
2b4c142d JG |
684 | invalid_log_level_value); |
685 | ok(er_as_severe_status == LTTNG_EVENT_RULE_STATUS_INVALID, | |
cade690d JR |
686 | "Log level rule \"as least as severe as\" rejected by %s event rule: level = %d", |
687 | event_rule_type_str, | |
2b4c142d JG |
688 | invalid_log_level_value); |
689 | } | |
690 | ||
cade690d | 691 | lttng_event_rule_destroy(rule); |
2b4c142d JG |
692 | } |
693 | ||
694 | static void test_event_rule_log_level_ust(void) | |
695 | { | |
696 | const int tagged_log_level_values[] = { | |
697 | LTTNG_LOGLEVEL_EMERG, | |
698 | LTTNG_LOGLEVEL_ALERT, | |
699 | LTTNG_LOGLEVEL_CRIT, | |
700 | LTTNG_LOGLEVEL_ERR, | |
701 | LTTNG_LOGLEVEL_WARNING, | |
702 | LTTNG_LOGLEVEL_NOTICE, | |
703 | LTTNG_LOGLEVEL_INFO, | |
704 | LTTNG_LOGLEVEL_DEBUG_SYSTEM, | |
705 | LTTNG_LOGLEVEL_DEBUG_PROGRAM, | |
706 | LTTNG_LOGLEVEL_DEBUG_PROCESS, | |
707 | LTTNG_LOGLEVEL_DEBUG_MODULE, | |
708 | LTTNG_LOGLEVEL_DEBUG_UNIT, | |
709 | LTTNG_LOGLEVEL_DEBUG_FUNCTION, | |
710 | LTTNG_LOGLEVEL_DEBUG_LINE, | |
711 | LTTNG_LOGLEVEL_DEBUG, | |
712 | }; | |
713 | const int invalid_log_level_values[] = { | |
714 | -1980, | |
715 | 1995, | |
716 | LTTNG_LOGLEVEL_DEBUG + 1, | |
717 | LTTNG_LOGLEVEL_EMERG - 1, | |
718 | }; | |
719 | ||
cade690d JR |
720 | test_event_rule_log_level_generic(LTTNG_EVENT_RULE_TYPE_USER_TRACEPOINT, |
721 | loglevel_value_to_name, | |
722 | lttng_event_rule_user_tracepoint_create, | |
723 | lttng_event_rule_user_tracepoint_set_log_level_rule, | |
724 | tagged_log_level_values, | |
725 | ARRAY_SIZE(tagged_log_level_values), NULL, 0, | |
2b4c142d JG |
726 | invalid_log_level_values, |
727 | ARRAY_SIZE(invalid_log_level_values)); | |
728 | } | |
729 | ||
730 | static void test_event_rule_log_level_jul(void) | |
731 | { | |
732 | const int tagged_log_level_values[] = { | |
733 | LTTNG_LOGLEVEL_JUL_OFF, | |
734 | LTTNG_LOGLEVEL_JUL_SEVERE, | |
735 | LTTNG_LOGLEVEL_JUL_WARNING, | |
736 | LTTNG_LOGLEVEL_JUL_INFO, | |
737 | LTTNG_LOGLEVEL_JUL_CONFIG, | |
738 | LTTNG_LOGLEVEL_JUL_FINE, | |
739 | LTTNG_LOGLEVEL_JUL_FINER, | |
740 | LTTNG_LOGLEVEL_JUL_FINEST, | |
741 | LTTNG_LOGLEVEL_JUL_ALL, | |
742 | }; | |
743 | const int valid_log_level_values[] = { | |
744 | 0, | |
745 | -1980, | |
746 | 1995 | |
747 | }; | |
748 | ||
cade690d JR |
749 | test_event_rule_log_level_generic(LTTNG_EVENT_RULE_TYPE_JUL_LOGGING, |
750 | loglevel_jul_value_to_name, | |
751 | lttng_event_rule_jul_logging_create, | |
752 | lttng_event_rule_jul_logging_set_log_level_rule, | |
753 | tagged_log_level_values, | |
2b4c142d JG |
754 | ARRAY_SIZE(tagged_log_level_values), |
755 | valid_log_level_values, | |
756 | ARRAY_SIZE(valid_log_level_values), NULL, 0); | |
757 | } | |
758 | ||
759 | static void test_event_rule_log_level_log4j(void) | |
760 | { | |
761 | const int tagged_log_level_values[] = { | |
762 | LTTNG_LOGLEVEL_LOG4J_OFF, | |
763 | LTTNG_LOGLEVEL_LOG4J_FATAL, | |
764 | LTTNG_LOGLEVEL_LOG4J_ERROR, | |
765 | LTTNG_LOGLEVEL_LOG4J_WARN, | |
766 | LTTNG_LOGLEVEL_LOG4J_INFO, | |
767 | LTTNG_LOGLEVEL_LOG4J_DEBUG, | |
768 | LTTNG_LOGLEVEL_LOG4J_TRACE, | |
769 | LTTNG_LOGLEVEL_LOG4J_ALL, | |
770 | }; | |
771 | const int valid_log_level_values[] = { | |
772 | 0 | |
773 | -1980, | |
774 | 1995 | |
775 | }; | |
776 | ||
cade690d JR |
777 | test_event_rule_log_level_generic(LTTNG_EVENT_RULE_TYPE_LOG4J_LOGGING, |
778 | loglevel_log4j_value_to_name, | |
779 | lttng_event_rule_log4j_logging_create, | |
780 | lttng_event_rule_log4j_logging_set_log_level_rule, | |
781 | tagged_log_level_values, | |
2b4c142d JG |
782 | ARRAY_SIZE(tagged_log_level_values), |
783 | valid_log_level_values, | |
784 | ARRAY_SIZE(valid_log_level_values), NULL, 0); | |
785 | } | |
786 | ||
787 | static void test_event_rule_log_level_python(void) | |
788 | { | |
789 | const int tagged_log_level_values[] = { | |
790 | LTTNG_LOGLEVEL_PYTHON_CRITICAL, | |
791 | LTTNG_LOGLEVEL_PYTHON_ERROR, | |
792 | LTTNG_LOGLEVEL_PYTHON_WARNING, | |
793 | LTTNG_LOGLEVEL_PYTHON_INFO, | |
794 | LTTNG_LOGLEVEL_PYTHON_DEBUG, | |
795 | LTTNG_LOGLEVEL_PYTHON_NOTSET, | |
796 | }; | |
797 | const int valid_log_level_values[] = { | |
798 | 45, | |
799 | 35, | |
800 | 0, | |
801 | -657, | |
802 | }; | |
803 | ||
cade690d JR |
804 | test_event_rule_log_level_generic(LTTNG_EVENT_RULE_TYPE_PYTHON_LOGGING, |
805 | loglevel_python_value_to_name, | |
806 | lttng_event_rule_python_logging_create, | |
807 | lttng_event_rule_python_logging_set_log_level_rule, | |
808 | tagged_log_level_values, | |
2b4c142d JG |
809 | ARRAY_SIZE(tagged_log_level_values), |
810 | valid_log_level_values, | |
811 | ARRAY_SIZE(valid_log_level_values), | |
812 | NULL, 0); | |
813 | } | |
814 | ||
f46376a1 | 815 | int main(void) |
dbc20d3c JR |
816 | { |
817 | plan_tests(NUM_TESTS); | |
af0818ef | 818 | test_event_rule_kernel_tracepoint(); |
0a23a07d | 819 | test_event_rule_user_tracepoint(); |
dbc20d3c | 820 | test_event_rule_syscall(); |
1f1567a5 | 821 | test_event_rule_userspace_probe(); |
f2791161 | 822 | test_event_rule_kernel_probe(); |
138d6838 | 823 | test_event_rule_log4j_logging(); |
b47b01d8 | 824 | test_event_rule_jul_logging(); |
6530ec7d | 825 | test_event_rule_python_logging(); |
2b4c142d JG |
826 | test_event_rule_log_level_ust(); |
827 | test_event_rule_log_level_jul(); | |
828 | test_event_rule_log_level_log4j(); | |
829 | test_event_rule_log_level_python(); | |
dbc20d3c JR |
830 | return exit_status(); |
831 | } |