Prepare for '-Wunused-parameter'
[lttng-tools.git] / tests / unit / test_event_rule.cpp
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
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>
20 #include <lttng/event-rule/jul-logging-internal.h>
21 #include <lttng/event-rule/jul-logging.h>
22 #include <lttng/event-rule/kernel-kprobe-internal.h>
23 #include <lttng/event-rule/kernel-kprobe.h>
24 #include <lttng/event-rule/kernel-syscall-internal.h>
25 #include <lttng/event-rule/kernel-syscall.h>
26 #include <lttng/event-rule/python-logging-internal.h>
27 #include <lttng/event-rule/python-logging.h>
28 #include <lttng/event-rule/kernel-tracepoint-internal.h>
29 #include <lttng/event-rule/kernel-tracepoint.h>
30 #include <lttng/event-rule/kernel-uprobe-internal.h>
31 #include <lttng/event-rule/kernel-uprobe.h>
32 #include <lttng/event-rule/user-tracepoint-internal.h>
33 #include <lttng/event-rule/user-tracepoint.h>
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>
39 #include "bin/lttng/loglevel.h"
40
41 /* For error.h. */
42 int lttng_opt_quiet = 1;
43 int lttng_opt_verbose;
44 int lttng_opt_mi;
45
46 #define NUM_TESTS 212
47
48 struct tracepoint_test {
49 enum lttng_domain_type type;
50 bool support_name_pattern_exclusion;
51 };
52
53 typedef const char *(*log_level_name_getter)(int log_level);
54
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
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
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);
130 LTTNG_ASSERT(log_level_rule);
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
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
217 syscall = lttng_event_rule_kernel_syscall_create(LTTNG_EVENT_RULE_KERNEL_SYSCALL_EMISSION_SITE_ENTRY);
218 ok(syscall, "syscall object.");
219
220 status = lttng_event_rule_kernel_syscall_set_name_pattern(syscall, pattern);
221 ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern.");
222 status = lttng_event_rule_kernel_syscall_get_name_pattern(syscall, &tmp);
223 ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern.");
224 ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal.");
225
226 status = lttng_event_rule_kernel_syscall_set_filter(syscall, filter);
227 ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter.");
228 status = lttng_event_rule_kernel_syscall_get_filter(syscall, &tmp);
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
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);
270 LTTNG_ASSERT(log_level_rule);
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
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);
335 LTTNG_ASSERT(log_level_rule);
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
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);
400 LTTNG_ASSERT(log_level_rule);
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
447 static void test_event_rule_userspace_probe(void)
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.");
462
463 lookup_method = lttng_userspace_probe_location_lookup_method_function_elf_create();
464 if (!lookup_method) {
465 fail("Setup error on userspace probe lookup method creation.");
466 goto end;
467 }
468
469 probe_location = lttng_userspace_probe_location_function_create(
470 "/proc/self/exe",
471 "lttng_userspace_probe_location_tracepoint_create",
472 lookup_method);
473 if (!probe_location) {
474 fail("Setup error on userspace probe location creation.");
475 goto end;
476 }
477
478 /* Ownership transferred to the probe location function object. */
479 lookup_method = NULL;
480
481 lttng_payload_init(&payload);
482
483 uprobe = lttng_event_rule_kernel_uprobe_create(probe_location);
484 ok(uprobe, "uprobe event rule object creation.");
485
486 status = lttng_event_rule_kernel_uprobe_get_location(
487 uprobe, &probe_location_tmp);
488 ok(status == LTTNG_EVENT_RULE_STATUS_OK,
489 "Getting uprobe event rule location.");
490 ok(lttng_userspace_probe_location_is_equal(
491 probe_location, probe_location_tmp),
492 "Location is equal.");
493
494 status = lttng_event_rule_kernel_uprobe_set_event_name(uprobe, probe_name);
495 ok(status == LTTNG_EVENT_RULE_STATUS_OK,
496 "Setting uprobe event rule name: %s.", probe_name);
497 status = lttng_event_rule_kernel_uprobe_get_event_name(uprobe, &tmp);
498 ok(status == LTTNG_EVENT_RULE_STATUS_OK, "Getting uprobe name.");
499 ok(!strcmp(probe_name, tmp), "Uprobe name are equal.");
500
501 ok(lttng_event_rule_serialize(uprobe, &payload) == 0, "Serializing.");
502
503 {
504 struct lttng_payload_view view =
505 lttng_payload_view_from_payload(
506 &payload, 0, -1);
507
508 ok(lttng_event_rule_create_from_payload(
509 &view, &uprobe_from_buffer) > 0,
510 "Deserializing.");
511 }
512
513 ok(lttng_event_rule_is_equal(uprobe, uprobe_from_buffer),
514 "serialized and from buffer are equal.");
515
516 end:
517 lttng_payload_reset(&payload);
518 lttng_event_rule_destroy(uprobe);
519 lttng_event_rule_destroy(uprobe_from_buffer);
520 lttng_userspace_probe_location_destroy(probe_location);
521 lttng_userspace_probe_location_lookup_method_destroy(lookup_method);
522 }
523
524 static void test_event_rule_kernel_probe_by_location(
525 const struct lttng_kernel_probe_location *location)
526 {
527 struct lttng_event_rule *kprobe = NULL;
528 struct lttng_event_rule *kprobe_from_buffer = NULL;
529 enum lttng_event_rule_status status;
530 const struct lttng_kernel_probe_location *_location;
531
532 const char *probe_name = "my_probe";
533 const char *tmp;
534 struct lttng_payload payload;
535
536 diag("Event rule kprobe for location type %d.",
537 lttng_kernel_probe_location_get_type(location));
538
539 lttng_payload_init(&payload);
540
541 kprobe = lttng_event_rule_kernel_kprobe_create(location);
542 ok(kprobe, "kprobe event rule object creation.");
543
544 status = lttng_event_rule_kernel_kprobe_get_location(kprobe, &_location);
545 ok(status == LTTNG_EVENT_RULE_STATUS_OK,
546 "Getting kprobe event rule location.");
547 ok(lttng_kernel_probe_location_is_equal(location, _location), "Locations are equal.");
548
549 status = lttng_event_rule_kernel_kprobe_set_event_name(kprobe, probe_name);
550 ok(status == LTTNG_EVENT_RULE_STATUS_OK,
551 "Setting kprobe event rule name: %s.", probe_name);
552 status = lttng_event_rule_kernel_kprobe_get_event_name(kprobe, &tmp);
553 ok(status == LTTNG_EVENT_RULE_STATUS_OK, "Getting kprobe name.");
554 ok(!strcmp(probe_name, tmp), "kprobe name are equal.");
555
556 ok(lttng_event_rule_serialize(kprobe, &payload) == 0, "Serializing.");
557
558 {
559 struct lttng_payload_view view =
560 lttng_payload_view_from_payload(
561 &payload, 0, -1);
562
563 ok(lttng_event_rule_create_from_payload(
564 &view, &kprobe_from_buffer) > 0,
565 "Deserializing.");
566 }
567
568 ok(lttng_event_rule_is_equal(kprobe, kprobe_from_buffer),
569 "serialized and from buffer are equal.");
570
571 lttng_payload_reset(&payload);
572 lttng_event_rule_destroy(kprobe);
573 lttng_event_rule_destroy(kprobe_from_buffer);
574 }
575
576 static void test_event_rule_kernel_probe(void)
577 {
578 struct lttng_kernel_probe_location *address_location = NULL;
579 struct lttng_kernel_probe_location *symbol_location = NULL;
580
581 address_location = lttng_kernel_probe_location_address_create(50);
582 symbol_location = lttng_kernel_probe_location_symbol_create("une_bonne", 50);
583 LTTNG_ASSERT(address_location);
584 LTTNG_ASSERT(symbol_location);
585
586 test_event_rule_kernel_probe_by_location(address_location);
587 test_event_rule_kernel_probe_by_location(symbol_location);
588
589 lttng_kernel_probe_location_destroy(address_location);
590 lttng_kernel_probe_location_destroy(symbol_location);
591 }
592
593 static void test_set_event_rule_log_level_rules(
594 struct lttng_event_rule *event_rule,
595 event_rule_set_log_level set_log_level,
596 int log_level,
597 enum lttng_event_rule_status *exactly_status,
598 enum lttng_event_rule_status *as_severe_status)
599 {
600 struct lttng_log_level_rule *log_level_rule;
601
602 log_level_rule = lttng_log_level_rule_at_least_as_severe_as_create(
603 log_level);
604 LTTNG_ASSERT(log_level_rule);
605
606 *as_severe_status = set_log_level(
607 event_rule, log_level_rule);
608 lttng_log_level_rule_destroy(log_level_rule);
609
610 log_level_rule = lttng_log_level_rule_exactly_create(log_level);
611 LTTNG_ASSERT(log_level_rule);
612
613 *exactly_status = set_log_level(
614 event_rule, log_level_rule);
615 lttng_log_level_rule_destroy(log_level_rule);
616 }
617
618 static void test_event_rule_log_level_generic(enum lttng_event_rule_type event_rule_type,
619 log_level_name_getter get_log_level_name,
620 event_rule_create create_event_rule,
621 event_rule_set_log_level set_log_level,
622 const int tagged_log_level_values[],
623 size_t tagged_log_level_values_count,
624 const int valid_log_level_values[],
625 size_t valid_log_level_values_count,
626 const int invalid_log_level_values[],
627 size_t invalid_log_level_values_count)
628 {
629 size_t i;
630 struct lttng_event_rule *rule;
631 enum lttng_event_rule_status er_exactly_status, er_as_severe_status;
632 const char *event_rule_type_str = lttng_event_rule_type_str(event_rule_type);
633
634
635 diag("Test %s event rule + log level rule", event_rule_type_str);
636
637 rule = create_event_rule();
638 LTTNG_ASSERT(rule);
639
640 for (i = 0; i < tagged_log_level_values_count; i++) {
641 const int tagged_log_level_value = tagged_log_level_values[i];
642
643 test_set_event_rule_log_level_rules(rule, set_log_level,
644 tagged_log_level_value,
645 &er_exactly_status, &er_as_severe_status);
646 ok(er_exactly_status == LTTNG_EVENT_RULE_STATUS_OK,
647 "Log level rule \"exactly\" accepted by %s event rule: level = %s",
648 event_rule_type_str,
649 get_log_level_name(
650 tagged_log_level_value));
651 ok(er_as_severe_status == LTTNG_EVENT_RULE_STATUS_OK,
652 "Log level rule \"as least as severe as\" accepted by %s event rule: level = %s",
653 event_rule_type_str,
654 get_log_level_name(
655 tagged_log_level_value));
656 }
657
658 for (i = 0; i < valid_log_level_values_count; i++) {
659 const int valid_log_level_value = valid_log_level_values[i];
660
661 test_set_event_rule_log_level_rules(rule, set_log_level,
662 valid_log_level_value,
663 &er_exactly_status, &er_as_severe_status);
664 ok(er_exactly_status == LTTNG_EVENT_RULE_STATUS_OK,
665 "Log level rule \"exactly\" accepted by %s event rule: level = %d",
666 event_rule_type_str,
667 valid_log_level_value);
668 ok(er_as_severe_status == LTTNG_EVENT_RULE_STATUS_OK,
669 "Log level rule \"as least as severe as\" accepted by %s event rule: level = %d",
670 event_rule_type_str,
671 valid_log_level_value);
672 }
673
674 for (i = 0; i < invalid_log_level_values_count; i++) {
675 const int invalid_log_level_value = invalid_log_level_values[i];
676
677 test_set_event_rule_log_level_rules(rule, set_log_level,
678 invalid_log_level_value,
679 &er_exactly_status, &er_as_severe_status);
680 ok(er_exactly_status == LTTNG_EVENT_RULE_STATUS_INVALID,
681 "Log level rule \"exactly\" rejected by %s event rule: level = %d",
682 event_rule_type_str,
683 invalid_log_level_value);
684 ok(er_as_severe_status == LTTNG_EVENT_RULE_STATUS_INVALID,
685 "Log level rule \"as least as severe as\" rejected by %s event rule: level = %d",
686 event_rule_type_str,
687 invalid_log_level_value);
688 }
689
690 lttng_event_rule_destroy(rule);
691 }
692
693 static void test_event_rule_log_level_ust(void)
694 {
695 const int tagged_log_level_values[] = {
696 LTTNG_LOGLEVEL_EMERG,
697 LTTNG_LOGLEVEL_ALERT,
698 LTTNG_LOGLEVEL_CRIT,
699 LTTNG_LOGLEVEL_ERR,
700 LTTNG_LOGLEVEL_WARNING,
701 LTTNG_LOGLEVEL_NOTICE,
702 LTTNG_LOGLEVEL_INFO,
703 LTTNG_LOGLEVEL_DEBUG_SYSTEM,
704 LTTNG_LOGLEVEL_DEBUG_PROGRAM,
705 LTTNG_LOGLEVEL_DEBUG_PROCESS,
706 LTTNG_LOGLEVEL_DEBUG_MODULE,
707 LTTNG_LOGLEVEL_DEBUG_UNIT,
708 LTTNG_LOGLEVEL_DEBUG_FUNCTION,
709 LTTNG_LOGLEVEL_DEBUG_LINE,
710 LTTNG_LOGLEVEL_DEBUG,
711 };
712 const int invalid_log_level_values[] = {
713 -1980,
714 1995,
715 LTTNG_LOGLEVEL_DEBUG + 1,
716 LTTNG_LOGLEVEL_EMERG - 1,
717 };
718
719 test_event_rule_log_level_generic(LTTNG_EVENT_RULE_TYPE_USER_TRACEPOINT,
720 loglevel_value_to_name,
721 lttng_event_rule_user_tracepoint_create,
722 lttng_event_rule_user_tracepoint_set_log_level_rule,
723 tagged_log_level_values,
724 ARRAY_SIZE(tagged_log_level_values), NULL, 0,
725 invalid_log_level_values,
726 ARRAY_SIZE(invalid_log_level_values));
727 }
728
729 static void test_event_rule_log_level_jul(void)
730 {
731 const int tagged_log_level_values[] = {
732 LTTNG_LOGLEVEL_JUL_OFF,
733 LTTNG_LOGLEVEL_JUL_SEVERE,
734 LTTNG_LOGLEVEL_JUL_WARNING,
735 LTTNG_LOGLEVEL_JUL_INFO,
736 LTTNG_LOGLEVEL_JUL_CONFIG,
737 LTTNG_LOGLEVEL_JUL_FINE,
738 LTTNG_LOGLEVEL_JUL_FINER,
739 LTTNG_LOGLEVEL_JUL_FINEST,
740 LTTNG_LOGLEVEL_JUL_ALL,
741 };
742 const int valid_log_level_values[] = {
743 0,
744 -1980,
745 1995
746 };
747
748 test_event_rule_log_level_generic(LTTNG_EVENT_RULE_TYPE_JUL_LOGGING,
749 loglevel_jul_value_to_name,
750 lttng_event_rule_jul_logging_create,
751 lttng_event_rule_jul_logging_set_log_level_rule,
752 tagged_log_level_values,
753 ARRAY_SIZE(tagged_log_level_values),
754 valid_log_level_values,
755 ARRAY_SIZE(valid_log_level_values), NULL, 0);
756 }
757
758 static void test_event_rule_log_level_log4j(void)
759 {
760 const int tagged_log_level_values[] = {
761 LTTNG_LOGLEVEL_LOG4J_OFF,
762 LTTNG_LOGLEVEL_LOG4J_FATAL,
763 LTTNG_LOGLEVEL_LOG4J_ERROR,
764 LTTNG_LOGLEVEL_LOG4J_WARN,
765 LTTNG_LOGLEVEL_LOG4J_INFO,
766 LTTNG_LOGLEVEL_LOG4J_DEBUG,
767 LTTNG_LOGLEVEL_LOG4J_TRACE,
768 LTTNG_LOGLEVEL_LOG4J_ALL,
769 };
770 const int valid_log_level_values[] = {
771 0
772 -1980,
773 1995
774 };
775
776 test_event_rule_log_level_generic(LTTNG_EVENT_RULE_TYPE_LOG4J_LOGGING,
777 loglevel_log4j_value_to_name,
778 lttng_event_rule_log4j_logging_create,
779 lttng_event_rule_log4j_logging_set_log_level_rule,
780 tagged_log_level_values,
781 ARRAY_SIZE(tagged_log_level_values),
782 valid_log_level_values,
783 ARRAY_SIZE(valid_log_level_values), NULL, 0);
784 }
785
786 static void test_event_rule_log_level_python(void)
787 {
788 const int tagged_log_level_values[] = {
789 LTTNG_LOGLEVEL_PYTHON_CRITICAL,
790 LTTNG_LOGLEVEL_PYTHON_ERROR,
791 LTTNG_LOGLEVEL_PYTHON_WARNING,
792 LTTNG_LOGLEVEL_PYTHON_INFO,
793 LTTNG_LOGLEVEL_PYTHON_DEBUG,
794 LTTNG_LOGLEVEL_PYTHON_NOTSET,
795 };
796 const int valid_log_level_values[] = {
797 45,
798 35,
799 0,
800 -657,
801 };
802
803 test_event_rule_log_level_generic(LTTNG_EVENT_RULE_TYPE_PYTHON_LOGGING,
804 loglevel_python_value_to_name,
805 lttng_event_rule_python_logging_create,
806 lttng_event_rule_python_logging_set_log_level_rule,
807 tagged_log_level_values,
808 ARRAY_SIZE(tagged_log_level_values),
809 valid_log_level_values,
810 ARRAY_SIZE(valid_log_level_values),
811 NULL, 0);
812 }
813
814 int main(void)
815 {
816 plan_tests(NUM_TESTS);
817 test_event_rule_kernel_tracepoint();
818 test_event_rule_user_tracepoint();
819 test_event_rule_syscall();
820 test_event_rule_userspace_probe();
821 test_event_rule_kernel_probe();
822 test_event_rule_log4j_logging();
823 test_event_rule_jul_logging();
824 test_event_rule_python_logging();
825 test_event_rule_log_level_ust();
826 test_event_rule_log_level_jul();
827 test_event_rule_log_level_log4j();
828 test_event_rule_log_level_python();
829 return exit_status();
830 }
This page took 0.046993 seconds and 5 git commands to generate.