2 * Unit tests for the notification API.
4 * Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
6 * SPDX-License-Identifier: LGPL-2.1-only
18 #include <common/payload-view.h>
19 #include <common/payload.h>
20 #include <lttng/domain.h>
21 #include <lttng/event-rule/jul-logging-internal.h>
22 #include <lttng/event-rule/jul-logging.h>
23 #include <lttng/event-rule/kernel-kprobe-internal.h>
24 #include <lttng/event-rule/kernel-kprobe.h>
25 #include <lttng/event-rule/kernel-syscall-internal.h>
26 #include <lttng/event-rule/kernel-syscall.h>
27 #include <lttng/event-rule/tracepoint-internal.h>
28 #include <lttng/event-rule/tracepoint.h>
29 #include <lttng/event-rule/kernel-tracepoint-internal.h>
30 #include <lttng/event-rule/kernel-tracepoint.h>
31 #include <lttng/event-rule/kernel-uprobe-internal.h>
32 #include <lttng/event-rule/kernel-uprobe.h>
33 #include <lttng/event-rule/user-tracepoint-internal.h>
34 #include <lttng/event-rule/user-tracepoint.h>
35 #include <lttng/event.h>
36 #include <lttng/kernel-probe-internal.h>
37 #include <lttng/kernel-probe.h>
38 #include <lttng/userspace-probe-internal.h>
39 #include <lttng/userspace-probe.h>
40 #include "bin/lttng/loglevel.h"
43 int lttng_opt_quiet
= 1;
44 int lttng_opt_verbose
;
49 struct tracepoint_test
{
50 enum lttng_domain_type type
;
51 bool support_name_pattern_exclusion
;
54 typedef const char *(*log_level_name_getter
)(int log_level
);
57 void test_event_rule_tracepoint_by_domain(const struct tracepoint_test
*test
)
60 struct lttng_event_rule
*tracepoint
= NULL
;
61 struct lttng_event_rule
*tracepoint_from_buffer
= NULL
;
62 enum lttng_event_rule_status status
;
63 enum lttng_domain_type domain_type
, type
;
64 const char *pattern
="my_event_*";
65 const char *filter
="msg_id == 23 && size >= 2048";
67 const char *name_pattern_exclusions
[] = {"my_event_test1", "my_event_test2" ,"my_event_test3"};
68 struct lttng_log_level_rule
*log_level_rule
= NULL
;
69 const struct lttng_log_level_rule
*log_level_rule_return
= NULL
;
70 struct lttng_payload payload
;
73 diag("Testing domain %d.", type
);
75 lttng_payload_init(&payload
);
77 log_level_rule
= lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO
);
78 assert(log_level_rule
);
80 tracepoint
= lttng_event_rule_tracepoint_create(type
);
81 ok(tracepoint
, "tracepoint object.");
83 status
= lttng_event_rule_tracepoint_get_domain_type(tracepoint
, &domain_type
);
84 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "get tracepoint domain.");
85 ok(domain_type
== type
, "domain type got %d expected %d.", domain_type
, type
);
87 status
= lttng_event_rule_tracepoint_set_name_pattern(tracepoint
, pattern
);
88 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting pattern.");
89 status
= lttng_event_rule_tracepoint_get_name_pattern(tracepoint
, &tmp
);
90 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting pattern.");
91 ok(!strncmp(pattern
, tmp
, strlen(pattern
)), "pattern is equal.");
93 status
= lttng_event_rule_tracepoint_set_filter(tracepoint
, filter
);
94 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting filter.");
95 status
= lttng_event_rule_tracepoint_get_filter(tracepoint
, &tmp
);
96 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting filter.");
97 ok(!strncmp(filter
, tmp
, strlen(filter
)), "filter is equal.");
99 status
= lttng_event_rule_tracepoint_get_log_level_rule(tracepoint
, &log_level_rule_return
);
100 ok(status
== LTTNG_EVENT_RULE_STATUS_UNSET
, "get unset log level rule.");
102 if (type
!= LTTNG_DOMAIN_KERNEL
) {
103 status
= lttng_event_rule_tracepoint_set_log_level_rule(tracepoint
, log_level_rule
);
104 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting log level rule.");
105 status
= lttng_event_rule_tracepoint_get_log_level_rule(tracepoint
, &log_level_rule_return
);
106 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "get log level rule.");
109 if (test
->support_name_pattern_exclusion
) {
112 for (i
= 0; i
< 3; i
++) {
113 status
= lttng_event_rule_tracepoint_add_name_pattern_exclusion(tracepoint
, name_pattern_exclusions
[i
]);
114 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting name pattern exclusions \"%s\"", name_pattern_exclusions
[i
]);
117 status
= lttng_event_rule_tracepoint_get_name_pattern_exclusion_count(tracepoint
, &count
);
118 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting name pattern exclusion count.");
119 ok(count
== 3, "count is %d/3", count
);
121 for (i
= 0; i
< count
; i
++) {
122 status
= lttng_event_rule_tracepoint_get_name_pattern_exclusion_at_index(tracepoint
, i
, &tmp
);
123 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting name pattern exclusion at index %d.", i
);
124 ok(!strncmp(name_pattern_exclusions
[i
], tmp
, strlen(name_pattern_exclusions
[i
])), "%s == %s.", tmp
, name_pattern_exclusions
[i
]);
129 for (i
= 0; i
< 3; i
++) {
130 status
= lttng_event_rule_tracepoint_add_name_pattern_exclusion(tracepoint
, name_pattern_exclusions
[i
]);
131 ok(status
== LTTNG_EVENT_RULE_STATUS_UNSUPPORTED
, "setting name pattern exclusions unsupported \"%s\".", name_pattern_exclusions
[i
]);
134 status
= lttng_event_rule_tracepoint_get_name_pattern_exclusion_count(tracepoint
, &count
);
135 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting name pattern exclusion count.");
136 ok(count
== 0, "count is %d/0", count
);
139 ok(lttng_event_rule_serialize(tracepoint
, &payload
) == 0, "Serializing.");
142 struct lttng_payload_view view
=
143 lttng_payload_view_from_payload(
146 ok(lttng_event_rule_create_from_payload(
147 &view
, &tracepoint_from_buffer
) > 0,
151 ok(lttng_event_rule_is_equal(tracepoint
, tracepoint_from_buffer
), "serialized and from buffer are equal.");
153 lttng_payload_reset(&payload
);
154 lttng_event_rule_destroy(tracepoint
);
155 lttng_event_rule_destroy(tracepoint_from_buffer
);
156 lttng_log_level_rule_destroy(log_level_rule
);
160 void test_event_rule_tracepoint(void)
163 struct lttng_event_rule
*tracepoint
= NULL
;
164 struct tracepoint_test tests
[] = {{LTTNG_DOMAIN_JUL
, false},
165 {LTTNG_DOMAIN_KERNEL
, false},
166 {LTTNG_DOMAIN_LOG4J
, false},
167 {LTTNG_DOMAIN_PYTHON
, false},
168 {LTTNG_DOMAIN_UST
, true}};
170 diag("Testing lttng_event_rule_tracepoint.");
171 tracepoint
= lttng_event_rule_tracepoint_create(LTTNG_DOMAIN_NONE
);
172 ok(!tracepoint
, "Domain type restriction on create.");
174 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++) {
175 test_event_rule_tracepoint_by_domain(&tests
[i
]);
180 void test_event_rule_kernel_tracepoint(void)
182 struct lttng_event_rule
*tracepoint
= NULL
;
183 struct lttng_event_rule
*tracepoint_from_buffer
= NULL
;
184 enum lttng_event_rule_status status
;
185 const char *pattern
="my_event_*";
186 const char *filter
="msg_id == 23 && size >= 2048";
188 struct lttng_payload payload
;
190 diag("Testing lttng_event_rule_kernel_tracepoint.");
192 lttng_payload_init(&payload
);
194 tracepoint
= lttng_event_rule_kernel_tracepoint_create();
195 ok(tracepoint
, "tracepoint object.");
197 status
= lttng_event_rule_kernel_tracepoint_set_name_pattern(tracepoint
, pattern
);
198 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting pattern.");
199 status
= lttng_event_rule_kernel_tracepoint_get_name_pattern(tracepoint
, &tmp
);
200 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting pattern.");
201 ok(!strncmp(pattern
, tmp
, strlen(pattern
)), "pattern is equal.");
203 status
= lttng_event_rule_kernel_tracepoint_set_filter(tracepoint
, filter
);
204 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting filter.");
205 status
= lttng_event_rule_kernel_tracepoint_get_filter(tracepoint
, &tmp
);
206 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting filter.");
207 ok(!strncmp(filter
, tmp
, strlen(filter
)), "filter is equal.");
209 ok(lttng_event_rule_serialize(tracepoint
, &payload
) == 0, "Serializing.");
212 struct lttng_payload_view view
=
213 lttng_payload_view_from_payload(
216 ok(lttng_event_rule_create_from_payload(
217 &view
, &tracepoint_from_buffer
) > 0,
221 ok(lttng_event_rule_is_equal(tracepoint
, tracepoint_from_buffer
), "serialized and from buffer are equal.");
223 lttng_payload_reset(&payload
);
224 lttng_event_rule_destroy(tracepoint
);
225 lttng_event_rule_destroy(tracepoint_from_buffer
);
229 void test_event_rule_user_tracepoint(void)
233 struct lttng_event_rule
*tracepoint
= NULL
;
234 struct lttng_event_rule
*tracepoint_from_buffer
= NULL
;
235 enum lttng_event_rule_status status
;
236 const char *pattern
="my_event_*";
237 const char *filter
="msg_id == 23 && size >= 2048";
239 const char *name_pattern_exclusions
[] = {"my_event_test1", "my_event_test2" ,"my_event_test3"};
240 struct lttng_log_level_rule
*log_level_rule
= NULL
;
241 const struct lttng_log_level_rule
*log_level_rule_return
= NULL
;
242 struct lttng_payload payload
;
244 diag("Testing lttng_event_rule_user_tracepoint.");
246 lttng_payload_init(&payload
);
248 log_level_rule
= lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO
);
249 assert(log_level_rule
);
251 tracepoint
= lttng_event_rule_user_tracepoint_create();
252 ok(tracepoint
, "user tracepoint object.");
254 status
= lttng_event_rule_user_tracepoint_set_name_pattern(tracepoint
, pattern
);
255 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting pattern.");
256 status
= lttng_event_rule_user_tracepoint_get_name_pattern(tracepoint
, &tmp
);
257 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting pattern.");
258 ok(!strncmp(pattern
, tmp
, strlen(pattern
)), "pattern is equal.");
260 status
= lttng_event_rule_user_tracepoint_set_filter(tracepoint
, filter
);
261 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting filter.");
262 status
= lttng_event_rule_user_tracepoint_get_filter(tracepoint
, &tmp
);
263 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting filter.");
264 ok(!strncmp(filter
, tmp
, strlen(filter
)), "filter is equal.");
266 status
= lttng_event_rule_user_tracepoint_get_log_level_rule(tracepoint
, &log_level_rule_return
);
267 ok(status
== LTTNG_EVENT_RULE_STATUS_UNSET
, "get unset log level rule.");
269 status
= lttng_event_rule_user_tracepoint_set_log_level_rule(
270 tracepoint
, log_level_rule
);
271 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting log level rule.");
272 status
= lttng_event_rule_user_tracepoint_get_log_level_rule(
273 tracepoint
, &log_level_rule_return
);
274 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "get log level rule.");
276 /* Name pattern exclusions */
277 for (i
= 0; i
< 3; i
++) {
278 status
= lttng_event_rule_user_tracepoint_add_name_pattern_exclusion(
279 tracepoint
, name_pattern_exclusions
[i
]);
280 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
,
281 "setting name pattern exclusions \"%s\"",
282 name_pattern_exclusions
[i
]);
285 status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_count(
287 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
,
288 "getting name pattern exclusion count.");
289 ok(count
== 3, "count is %d/3", count
);
291 for (i
= 0; i
< count
; i
++) {
292 status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_at_index(
293 tracepoint
, i
, &tmp
);
294 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
,
295 "getting name pattern exclusion at index %d.",
297 ok(!strncmp(name_pattern_exclusions
[i
], tmp
,
298 strlen(name_pattern_exclusions
[i
])),
299 "%s == %s.", tmp
, name_pattern_exclusions
[i
]);
302 ok(lttng_event_rule_serialize(tracepoint
, &payload
) == 0, "Serializing.");
305 struct lttng_payload_view view
=
306 lttng_payload_view_from_payload(
309 ok(lttng_event_rule_create_from_payload(
310 &view
, &tracepoint_from_buffer
) > 0,
314 ok(lttng_event_rule_is_equal(tracepoint
, tracepoint_from_buffer
), "serialized and from buffer are equal.");
316 lttng_payload_reset(&payload
);
317 lttng_event_rule_destroy(tracepoint
);
318 lttng_event_rule_destroy(tracepoint_from_buffer
);
319 lttng_log_level_rule_destroy(log_level_rule
);
322 static void test_event_rule_syscall(void)
324 struct lttng_event_rule
*syscall
= NULL
;
325 struct lttng_event_rule
*syscall_from_buffer
= NULL
;
326 enum lttng_event_rule_status status
;
327 const char *pattern
= "my_event_*";
328 const char *filter
= "msg_id == 23 && size >= 2048";
330 struct lttng_payload payload
;
332 diag("Event rule syscall.");
334 lttng_payload_init(&payload
);
336 syscall
= lttng_event_rule_kernel_syscall_create(LTTNG_EVENT_RULE_KERNEL_SYSCALL_EMISSION_SITE_ENTRY
);
337 ok(syscall
, "syscall object.");
339 status
= lttng_event_rule_kernel_syscall_set_name_pattern(syscall
, pattern
);
340 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting pattern.");
341 status
= lttng_event_rule_kernel_syscall_get_name_pattern(syscall
, &tmp
);
342 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting pattern.");
343 ok(!strncmp(pattern
, tmp
, strlen(pattern
)), "pattern is equal.");
345 status
= lttng_event_rule_kernel_syscall_set_filter(syscall
, filter
);
346 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting filter.");
347 status
= lttng_event_rule_kernel_syscall_get_filter(syscall
, &tmp
);
348 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting filter.");
349 ok(!strncmp(filter
, tmp
, strlen(filter
)), "filter is equal.");
351 ok(lttng_event_rule_serialize(syscall
, &payload
) == 0, "Serializing.");
354 struct lttng_payload_view view
=
355 lttng_payload_view_from_payload(
358 ok(lttng_event_rule_create_from_payload(
359 &view
, &syscall_from_buffer
) > 0,
363 ok(lttng_event_rule_is_equal(syscall
, syscall_from_buffer
),
364 "serialized and from buffer are equal.");
366 lttng_payload_reset(&payload
);
367 lttng_event_rule_destroy(syscall
);
368 lttng_event_rule_destroy(syscall_from_buffer
);
372 void test_event_rule_jul_logging(void)
374 struct lttng_event_rule
*jul_logging
= NULL
;
375 struct lttng_event_rule
*jul_logging_from_buffer
= NULL
;
376 enum lttng_event_rule_status status
;
377 const char *pattern
="my_event_*";
378 const char *filter
="msg_id == 23 && size >= 2048";
380 struct lttng_log_level_rule
*log_level_rule
= NULL
;
381 const struct lttng_log_level_rule
*log_level_rule_return
= NULL
;
382 struct lttng_payload payload
;
384 diag("Testing lttng_event_rule_user_jul_logging.");
386 lttng_payload_init(&payload
);
388 log_level_rule
= lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO
);
389 assert(log_level_rule
);
391 jul_logging
= lttng_event_rule_jul_logging_create();
392 ok(jul_logging
, "jul_logging object.");
394 status
= lttng_event_rule_jul_logging_set_name_pattern(jul_logging
, pattern
);
395 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting pattern.");
396 status
= lttng_event_rule_jul_logging_get_name_pattern(jul_logging
, &tmp
);
397 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting pattern.");
398 ok(!strncmp(pattern
, tmp
, strlen(pattern
)), "pattern is equal.");
400 status
= lttng_event_rule_jul_logging_set_filter(jul_logging
, filter
);
401 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting filter.");
402 status
= lttng_event_rule_jul_logging_get_filter(jul_logging
, &tmp
);
403 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting filter.");
404 ok(!strncmp(filter
, tmp
, strlen(filter
)), "filter is equal.");
406 status
= lttng_event_rule_jul_logging_get_log_level_rule(jul_logging
, &log_level_rule_return
);
407 ok(status
== LTTNG_EVENT_RULE_STATUS_UNSET
, "get unset log level rule.");
409 status
= lttng_event_rule_jul_logging_set_log_level_rule(
410 jul_logging
, log_level_rule
);
411 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting log level rule.");
412 status
= lttng_event_rule_jul_logging_get_log_level_rule(
413 jul_logging
, &log_level_rule_return
);
414 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "get log level rule.");
416 ok(lttng_event_rule_serialize(jul_logging
, &payload
) == 0, "Serializing.");
419 struct lttng_payload_view view
=
420 lttng_payload_view_from_payload(
423 ok(lttng_event_rule_create_from_payload(
424 &view
, &jul_logging_from_buffer
) > 0,
428 ok(lttng_event_rule_is_equal(jul_logging
, jul_logging_from_buffer
), "serialized and from buffer are equal.");
430 lttng_payload_reset(&payload
);
431 lttng_event_rule_destroy(jul_logging
);
432 lttng_event_rule_destroy(jul_logging_from_buffer
);
433 lttng_log_level_rule_destroy(log_level_rule
);
437 void test_event_rule_log4j_logging(void)
439 struct lttng_event_rule
*log4j_logging
= NULL
;
440 struct lttng_event_rule
*log4j_logging_from_buffer
= NULL
;
441 enum lttng_event_rule_status status
;
442 const char *pattern
="my_event_*";
443 const char *filter
="msg_id == 23 && size >= 2048";
445 struct lttng_log_level_rule
*log_level_rule
= NULL
;
446 const struct lttng_log_level_rule
*log_level_rule_return
= NULL
;
447 struct lttng_payload payload
;
449 diag("Testing lttng_event_rule_user_log4j_logging.");
451 lttng_payload_init(&payload
);
453 log_level_rule
= lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO
);
454 assert(log_level_rule
);
456 log4j_logging
= lttng_event_rule_log4j_logging_create();
457 ok(log4j_logging
, "log4j_logging object.");
459 status
= lttng_event_rule_log4j_logging_set_name_pattern(log4j_logging
, pattern
);
460 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting pattern.");
461 status
= lttng_event_rule_log4j_logging_get_name_pattern(log4j_logging
, &tmp
);
462 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting pattern.");
463 ok(!strncmp(pattern
, tmp
, strlen(pattern
)), "pattern is equal.");
465 status
= lttng_event_rule_log4j_logging_set_filter(log4j_logging
, filter
);
466 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting filter.");
467 status
= lttng_event_rule_log4j_logging_get_filter(log4j_logging
, &tmp
);
468 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "getting filter.");
469 ok(!strncmp(filter
, tmp
, strlen(filter
)), "filter is equal.");
471 status
= lttng_event_rule_log4j_logging_get_log_level_rule(log4j_logging
, &log_level_rule_return
);
472 ok(status
== LTTNG_EVENT_RULE_STATUS_UNSET
, "get unset log level rule.");
474 status
= lttng_event_rule_log4j_logging_set_log_level_rule(
475 log4j_logging
, log_level_rule
);
476 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "setting log level rule.");
477 status
= lttng_event_rule_log4j_logging_get_log_level_rule(
478 log4j_logging
, &log_level_rule_return
);
479 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "get log level rule.");
481 ok(lttng_event_rule_serialize(log4j_logging
, &payload
) == 0, "Serializing.");
484 struct lttng_payload_view view
=
485 lttng_payload_view_from_payload(
488 ok(lttng_event_rule_create_from_payload(
489 &view
, &log4j_logging_from_buffer
) > 0,
493 ok(lttng_event_rule_is_equal(log4j_logging
, log4j_logging_from_buffer
), "serialized and from buffer are equal.");
495 lttng_payload_reset(&payload
);
496 lttng_event_rule_destroy(log4j_logging
);
497 lttng_event_rule_destroy(log4j_logging_from_buffer
);
498 lttng_log_level_rule_destroy(log_level_rule
);
501 static void test_event_rule_userspace_probe(void)
503 struct lttng_event_rule
*uprobe
= NULL
;
504 struct lttng_event_rule
*uprobe_from_buffer
= NULL
;
505 struct lttng_userspace_probe_location_lookup_method
*lookup_method
=
507 struct lttng_userspace_probe_location
*probe_location
= NULL
;
508 const struct lttng_userspace_probe_location
*probe_location_tmp
= NULL
;
509 enum lttng_event_rule_status status
;
511 const char *probe_name
= "my_probe.";
513 struct lttng_payload payload
;
515 diag("Event rule uprobe.");
517 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
518 if (!lookup_method
) {
519 fail("Setup error on userspace probe lookup method creation.");
523 probe_location
= lttng_userspace_probe_location_function_create(
525 "lttng_userspace_probe_location_tracepoint_create",
527 if (!probe_location
) {
528 fail("Setup error on userspace probe location creation.");
532 /* Ownership transferred to the probe location function object. */
533 lookup_method
= NULL
;
535 lttng_payload_init(&payload
);
537 uprobe
= lttng_event_rule_kernel_uprobe_create(probe_location
);
538 ok(uprobe
, "uprobe event rule object creation.");
540 status
= lttng_event_rule_kernel_uprobe_get_location(
541 uprobe
, &probe_location_tmp
);
542 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
,
543 "Getting uprobe event rule location.");
544 ok(lttng_userspace_probe_location_is_equal(
545 probe_location
, probe_location_tmp
),
546 "Location is equal.");
548 status
= lttng_event_rule_kernel_uprobe_set_event_name(uprobe
, probe_name
);
549 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
,
550 "Setting uprobe event rule name: %s.", probe_name
);
551 status
= lttng_event_rule_kernel_uprobe_get_event_name(uprobe
, &tmp
);
552 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "Getting uprobe name.");
553 ok(!strcmp(probe_name
, tmp
), "Uprobe name are equal.");
555 ok(lttng_event_rule_serialize(uprobe
, &payload
) == 0, "Serializing.");
558 struct lttng_payload_view view
=
559 lttng_payload_view_from_payload(
562 ok(lttng_event_rule_create_from_payload(
563 &view
, &uprobe_from_buffer
) > 0,
567 ok(lttng_event_rule_is_equal(uprobe
, uprobe_from_buffer
),
568 "serialized and from buffer are equal.");
571 lttng_payload_reset(&payload
);
572 lttng_event_rule_destroy(uprobe
);
573 lttng_event_rule_destroy(uprobe_from_buffer
);
574 lttng_userspace_probe_location_destroy(probe_location
);
575 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
578 static void test_event_rule_kernel_probe_by_location(
579 const struct lttng_kernel_probe_location
*location
)
581 struct lttng_event_rule
*kprobe
= NULL
;
582 struct lttng_event_rule
*kprobe_from_buffer
= NULL
;
583 enum lttng_event_rule_status status
;
584 const struct lttng_kernel_probe_location
*_location
;
586 const char *probe_name
= "my_probe";
588 struct lttng_payload payload
;
590 diag("Event rule kprobe for location type %d.",
591 lttng_kernel_probe_location_get_type(location
));
593 lttng_payload_init(&payload
);
595 kprobe
= lttng_event_rule_kernel_kprobe_create(location
);
596 ok(kprobe
, "kprobe event rule object creation.");
598 status
= lttng_event_rule_kernel_kprobe_get_location(kprobe
, &_location
);
599 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
,
600 "Getting kprobe event rule location.");
601 ok(lttng_kernel_probe_location_is_equal(location
, _location
), "Locations are equal.");
603 status
= lttng_event_rule_kernel_kprobe_set_event_name(kprobe
, probe_name
);
604 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
,
605 "Setting kprobe event rule name: %s.", probe_name
);
606 status
= lttng_event_rule_kernel_kprobe_get_event_name(kprobe
, &tmp
);
607 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "Getting kprobe name.");
608 ok(!strcmp(probe_name
, tmp
), "kprobe name are equal.");
610 ok(lttng_event_rule_serialize(kprobe
, &payload
) == 0, "Serializing.");
613 struct lttng_payload_view view
=
614 lttng_payload_view_from_payload(
617 ok(lttng_event_rule_create_from_payload(
618 &view
, &kprobe_from_buffer
) > 0,
622 ok(lttng_event_rule_is_equal(kprobe
, kprobe_from_buffer
),
623 "serialized and from buffer are equal.");
625 lttng_payload_reset(&payload
);
626 lttng_event_rule_destroy(kprobe
);
627 lttng_event_rule_destroy(kprobe_from_buffer
);
630 static void test_event_rule_kernel_probe(void)
632 struct lttng_kernel_probe_location
*address_location
= NULL
;
633 struct lttng_kernel_probe_location
*symbol_location
= NULL
;
635 address_location
= lttng_kernel_probe_location_address_create(50);
636 symbol_location
= lttng_kernel_probe_location_symbol_create("une_bonne", 50);
637 assert(address_location
);
638 assert(symbol_location
);
640 test_event_rule_kernel_probe_by_location(address_location
);
641 test_event_rule_kernel_probe_by_location(symbol_location
);
643 lttng_kernel_probe_location_destroy(address_location
);
644 lttng_kernel_probe_location_destroy(symbol_location
);
647 static void test_set_event_rule_log_level_rules(
648 struct lttng_event_rule
*event_rule
,
650 enum lttng_event_rule_status
*exactly_status
,
651 enum lttng_event_rule_status
*as_severe_status
)
653 struct lttng_log_level_rule
*log_level_rule
;
655 log_level_rule
= lttng_log_level_rule_at_least_as_severe_as_create(
657 assert(log_level_rule
);
659 *as_severe_status
= lttng_event_rule_tracepoint_set_log_level_rule(
660 event_rule
, log_level_rule
);
661 lttng_log_level_rule_destroy(log_level_rule
);
663 log_level_rule
= lttng_log_level_rule_exactly_create(log_level
);
664 assert(log_level_rule
);
666 *exactly_status
= lttng_event_rule_tracepoint_set_log_level_rule(
667 event_rule
, log_level_rule
);
668 lttng_log_level_rule_destroy(log_level_rule
);
671 static void test_event_rule_log_level_generic(const char *domain_name
,
672 enum lttng_domain_type domain
,
673 log_level_name_getter get_log_level_name
,
674 const int tagged_log_level_values
[],
675 size_t tagged_log_level_values_count
,
676 const int valid_log_level_values
[],
677 size_t valid_log_level_values_count
,
678 const int invalid_log_level_values
[],
679 size_t invalid_log_level_values_count
)
682 struct lttng_event_rule
*tracepoint_rule
;
683 enum lttng_event_rule_status er_exactly_status
, er_as_severe_status
;
685 diag("Test %s event rule + log level rule", domain_name
);
686 tracepoint_rule
= lttng_event_rule_tracepoint_create(domain
);
687 assert(tracepoint_rule
);
689 for (i
= 0; i
< tagged_log_level_values_count
; i
++) {
690 const int tagged_log_level_value
= tagged_log_level_values
[i
];
692 test_set_event_rule_log_level_rules(tracepoint_rule
,
693 tagged_log_level_value
,
694 &er_exactly_status
, &er_as_severe_status
);
695 ok(er_exactly_status
== LTTNG_EVENT_RULE_STATUS_OK
,
696 "Log level rule \"exactly\" accepted by %s tracepoint event rule: level = %s",
699 tagged_log_level_value
));
700 ok(er_as_severe_status
== LTTNG_EVENT_RULE_STATUS_OK
,
701 "Log level rule \"as least as severe as\" accepted by %s tracepoint event rule: level = %s",
704 tagged_log_level_value
));
707 for (i
= 0; i
< valid_log_level_values_count
; i
++) {
708 const int valid_log_level_value
= valid_log_level_values
[i
];
710 test_set_event_rule_log_level_rules(tracepoint_rule
,
711 valid_log_level_value
,
712 &er_exactly_status
, &er_as_severe_status
);
713 ok(er_exactly_status
== LTTNG_EVENT_RULE_STATUS_OK
,
714 "Log level rule \"exactly\" accepted by %s tracepoint event rule: level = %d",
716 valid_log_level_value
);
717 ok(er_as_severe_status
== LTTNG_EVENT_RULE_STATUS_OK
,
718 "Log level rule \"as least as severe as\" accepted by %s tracepoint event rule: level = %d",
720 valid_log_level_value
);
723 for (i
= 0; i
< invalid_log_level_values_count
; i
++) {
724 const int invalid_log_level_value
= invalid_log_level_values
[i
];
726 test_set_event_rule_log_level_rules(tracepoint_rule
,
727 invalid_log_level_value
,
728 &er_exactly_status
, &er_as_severe_status
);
729 ok(er_exactly_status
== LTTNG_EVENT_RULE_STATUS_INVALID
,
730 "Log level rule \"exactly\" rejected by %s tracepoint event rule: level = %d",
732 invalid_log_level_value
);
733 ok(er_as_severe_status
== LTTNG_EVENT_RULE_STATUS_INVALID
,
734 "Log level rule \"as least as severe as\" rejected by %s tracepoint event rule: level = %d",
736 invalid_log_level_value
);
739 lttng_event_rule_destroy(tracepoint_rule
);
742 static void test_event_rule_log_level_ust(void)
744 const int tagged_log_level_values
[] = {
745 LTTNG_LOGLEVEL_EMERG
,
746 LTTNG_LOGLEVEL_ALERT
,
749 LTTNG_LOGLEVEL_WARNING
,
750 LTTNG_LOGLEVEL_NOTICE
,
752 LTTNG_LOGLEVEL_DEBUG_SYSTEM
,
753 LTTNG_LOGLEVEL_DEBUG_PROGRAM
,
754 LTTNG_LOGLEVEL_DEBUG_PROCESS
,
755 LTTNG_LOGLEVEL_DEBUG_MODULE
,
756 LTTNG_LOGLEVEL_DEBUG_UNIT
,
757 LTTNG_LOGLEVEL_DEBUG_FUNCTION
,
758 LTTNG_LOGLEVEL_DEBUG_LINE
,
759 LTTNG_LOGLEVEL_DEBUG
,
761 const int invalid_log_level_values
[] = {
764 LTTNG_LOGLEVEL_DEBUG
+ 1,
765 LTTNG_LOGLEVEL_EMERG
- 1,
768 test_event_rule_log_level_generic("user space", LTTNG_DOMAIN_UST
,
769 loglevel_value_to_name
, tagged_log_level_values
,
770 ARRAY_SIZE(tagged_log_level_values
),
772 invalid_log_level_values
,
773 ARRAY_SIZE(invalid_log_level_values
));
776 static void test_event_rule_log_level_jul(void)
778 const int tagged_log_level_values
[] = {
779 LTTNG_LOGLEVEL_JUL_OFF
,
780 LTTNG_LOGLEVEL_JUL_SEVERE
,
781 LTTNG_LOGLEVEL_JUL_WARNING
,
782 LTTNG_LOGLEVEL_JUL_INFO
,
783 LTTNG_LOGLEVEL_JUL_CONFIG
,
784 LTTNG_LOGLEVEL_JUL_FINE
,
785 LTTNG_LOGLEVEL_JUL_FINER
,
786 LTTNG_LOGLEVEL_JUL_FINEST
,
787 LTTNG_LOGLEVEL_JUL_ALL
,
789 const int valid_log_level_values
[] = {
795 test_event_rule_log_level_generic("Java Util Logging", LTTNG_DOMAIN_JUL
,
796 loglevel_jul_value_to_name
, tagged_log_level_values
,
797 ARRAY_SIZE(tagged_log_level_values
),
798 valid_log_level_values
,
799 ARRAY_SIZE(valid_log_level_values
), NULL
, 0);
802 static void test_event_rule_log_level_log4j(void)
804 const int tagged_log_level_values
[] = {
805 LTTNG_LOGLEVEL_LOG4J_OFF
,
806 LTTNG_LOGLEVEL_LOG4J_FATAL
,
807 LTTNG_LOGLEVEL_LOG4J_ERROR
,
808 LTTNG_LOGLEVEL_LOG4J_WARN
,
809 LTTNG_LOGLEVEL_LOG4J_INFO
,
810 LTTNG_LOGLEVEL_LOG4J_DEBUG
,
811 LTTNG_LOGLEVEL_LOG4J_TRACE
,
812 LTTNG_LOGLEVEL_LOG4J_ALL
,
814 const int valid_log_level_values
[] = {
820 test_event_rule_log_level_generic("Log4j", LTTNG_DOMAIN_LOG4J
,
821 loglevel_log4j_value_to_name
, tagged_log_level_values
,
822 ARRAY_SIZE(tagged_log_level_values
),
823 valid_log_level_values
,
824 ARRAY_SIZE(valid_log_level_values
), NULL
, 0);
827 static void test_event_rule_log_level_python(void)
829 const int tagged_log_level_values
[] = {
830 LTTNG_LOGLEVEL_PYTHON_CRITICAL
,
831 LTTNG_LOGLEVEL_PYTHON_ERROR
,
832 LTTNG_LOGLEVEL_PYTHON_WARNING
,
833 LTTNG_LOGLEVEL_PYTHON_INFO
,
834 LTTNG_LOGLEVEL_PYTHON_DEBUG
,
835 LTTNG_LOGLEVEL_PYTHON_NOTSET
,
837 const int valid_log_level_values
[] = {
844 test_event_rule_log_level_generic("Python", LTTNG_DOMAIN_PYTHON
,
845 loglevel_python_value_to_name
, tagged_log_level_values
,
846 ARRAY_SIZE(tagged_log_level_values
),
847 valid_log_level_values
,
848 ARRAY_SIZE(valid_log_level_values
),
852 int main(int argc
, const char *argv
[])
854 plan_tests(NUM_TESTS
);
855 test_event_rule_tracepoint();
856 test_event_rule_kernel_tracepoint();
857 test_event_rule_user_tracepoint();
858 test_event_rule_syscall();
859 test_event_rule_userspace_probe();
860 test_event_rule_kernel_probe();
861 test_event_rule_log4j_logging();
862 test_event_rule_jul_logging();
863 test_event_rule_log_level_ust();
864 test_event_rule_log_level_jul();
865 test_event_rule_log_level_log4j();
866 test_event_rule_log_level_python();
867 return exit_status();