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
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"
42 int lttng_opt_quiet
= 1;
43 int lttng_opt_verbose
;
48 struct tracepoint_test
{
49 enum lttng_domain_type type
;
50 bool support_name_pattern_exclusion
;
53 typedef const char *(*log_level_name_getter
)(int log_level
);
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
);
61 void test_event_rule_kernel_tracepoint(void)
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";
69 struct lttng_payload payload
;
71 diag("Testing lttng_event_rule_kernel_tracepoint.");
73 lttng_payload_init(&payload
);
75 tracepoint
= lttng_event_rule_kernel_tracepoint_create();
76 ok(tracepoint
, "tracepoint object.");
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.");
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.");
90 ok(lttng_event_rule_serialize(tracepoint
, &payload
) == 0, "Serializing.");
93 struct lttng_payload_view view
=
94 lttng_payload_view_from_payload(
97 ok(lttng_event_rule_create_from_payload(
98 &view
, &tracepoint_from_buffer
) > 0,
102 ok(lttng_event_rule_is_equal(tracepoint
, tracepoint_from_buffer
), "serialized and from buffer are equal.");
104 lttng_payload_reset(&payload
);
105 lttng_event_rule_destroy(tracepoint
);
106 lttng_event_rule_destroy(tracepoint_from_buffer
);
110 void test_event_rule_user_tracepoint(void)
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";
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
;
125 diag("Testing lttng_event_rule_user_tracepoint.");
127 lttng_payload_init(&payload
);
129 log_level_rule
= lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO
);
130 LTTNG_ASSERT(log_level_rule
);
132 tracepoint
= lttng_event_rule_user_tracepoint_create();
133 ok(tracepoint
, "user tracepoint object.");
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.");
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.");
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.");
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.");
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
]);
166 status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_count(
168 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
,
169 "getting name pattern exclusion count.");
170 ok(count
== 3, "count is %d/3", count
);
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.",
178 ok(!strncmp(name_pattern_exclusions
[i
], tmp
,
179 strlen(name_pattern_exclusions
[i
])),
180 "%s == %s.", tmp
, name_pattern_exclusions
[i
]);
183 ok(lttng_event_rule_serialize(tracepoint
, &payload
) == 0, "Serializing.");
186 struct lttng_payload_view view
=
187 lttng_payload_view_from_payload(
190 ok(lttng_event_rule_create_from_payload(
191 &view
, &tracepoint_from_buffer
) > 0,
195 ok(lttng_event_rule_is_equal(tracepoint
, tracepoint_from_buffer
), "serialized and from buffer are equal.");
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
);
203 static void test_event_rule_syscall(void)
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";
211 struct lttng_payload payload
;
213 diag("Event rule syscall.");
215 lttng_payload_init(&payload
);
217 syscall
= lttng_event_rule_kernel_syscall_create(LTTNG_EVENT_RULE_KERNEL_SYSCALL_EMISSION_SITE_ENTRY
);
218 ok(syscall
, "syscall object.");
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.");
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.");
232 ok(lttng_event_rule_serialize(syscall
, &payload
) == 0, "Serializing.");
235 struct lttng_payload_view view
=
236 lttng_payload_view_from_payload(
239 ok(lttng_event_rule_create_from_payload(
240 &view
, &syscall_from_buffer
) > 0,
244 ok(lttng_event_rule_is_equal(syscall
, syscall_from_buffer
),
245 "serialized and from buffer are equal.");
247 lttng_payload_reset(&payload
);
248 lttng_event_rule_destroy(syscall
);
249 lttng_event_rule_destroy(syscall_from_buffer
);
253 void test_event_rule_jul_logging(void)
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";
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
;
265 diag("Testing lttng_event_rule_user_jul_logging.");
267 lttng_payload_init(&payload
);
269 log_level_rule
= lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO
);
270 LTTNG_ASSERT(log_level_rule
);
272 jul_logging
= lttng_event_rule_jul_logging_create();
273 ok(jul_logging
, "jul_logging object.");
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.");
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.");
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.");
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.");
297 ok(lttng_event_rule_serialize(jul_logging
, &payload
) == 0, "Serializing.");
300 struct lttng_payload_view view
=
301 lttng_payload_view_from_payload(
304 ok(lttng_event_rule_create_from_payload(
305 &view
, &jul_logging_from_buffer
) > 0,
309 ok(lttng_event_rule_is_equal(jul_logging
, jul_logging_from_buffer
), "serialized and from buffer are equal.");
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
);
318 void test_event_rule_log4j_logging(void)
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";
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
;
330 diag("Testing lttng_event_rule_user_log4j_logging.");
332 lttng_payload_init(&payload
);
334 log_level_rule
= lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO
);
335 LTTNG_ASSERT(log_level_rule
);
337 log4j_logging
= lttng_event_rule_log4j_logging_create();
338 ok(log4j_logging
, "log4j_logging object.");
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.");
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.");
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.");
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.");
362 ok(lttng_event_rule_serialize(log4j_logging
, &payload
) == 0, "Serializing.");
365 struct lttng_payload_view view
=
366 lttng_payload_view_from_payload(
369 ok(lttng_event_rule_create_from_payload(
370 &view
, &log4j_logging_from_buffer
) > 0,
374 ok(lttng_event_rule_is_equal(log4j_logging
, log4j_logging_from_buffer
), "serialized and from buffer are equal.");
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
);
383 void test_event_rule_python_logging(void)
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";
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
;
395 diag("Testing lttng_event_rule_user_python_logging.");
397 lttng_payload_init(&payload
);
399 log_level_rule
= lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO
);
400 LTTNG_ASSERT(log_level_rule
);
402 python_logging
= lttng_event_rule_python_logging_create();
403 ok(python_logging
, "python_logging object.");
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.");
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.");
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.");
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.");
427 ok(lttng_event_rule_serialize(python_logging
, &payload
) == 0, "Serializing.");
430 struct lttng_payload_view view
=
431 lttng_payload_view_from_payload(
434 ok(lttng_event_rule_create_from_payload(
435 &view
, &python_logging_from_buffer
) > 0,
439 ok(lttng_event_rule_is_equal(python_logging
, python_logging_from_buffer
), "serialized and from buffer are equal.");
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
);
447 static void test_event_rule_userspace_probe(void)
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
=
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
;
457 const char *probe_name
= "my_probe.";
459 struct lttng_payload payload
;
461 diag("Event rule uprobe.");
462 lttng_payload_init(&payload
);
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.");
470 probe_location
= lttng_userspace_probe_location_function_create(
472 "lttng_userspace_probe_location_tracepoint_create",
474 if (!probe_location
) {
475 fail("Setup error on userspace probe location creation.");
479 /* Ownership transferred to the probe location function object. */
480 lookup_method
= NULL
;
482 lttng_payload_init(&payload
);
484 uprobe
= lttng_event_rule_kernel_uprobe_create(probe_location
);
485 ok(uprobe
, "uprobe event rule object creation.");
487 status
= lttng_event_rule_kernel_uprobe_get_location(
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.");
495 status
= lttng_event_rule_kernel_uprobe_set_event_name(uprobe
, probe_name
);
496 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
,
497 "Setting uprobe event rule name: %s.", probe_name
);
498 status
= lttng_event_rule_kernel_uprobe_get_event_name(uprobe
, &tmp
);
499 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "Getting uprobe name.");
500 ok(!strcmp(probe_name
, tmp
), "Uprobe name are equal.");
502 ok(lttng_event_rule_serialize(uprobe
, &payload
) == 0, "Serializing.");
505 struct lttng_payload_view view
=
506 lttng_payload_view_from_payload(
509 ok(lttng_event_rule_create_from_payload(
510 &view
, &uprobe_from_buffer
) > 0,
514 ok(lttng_event_rule_is_equal(uprobe
, uprobe_from_buffer
),
515 "serialized and from buffer are equal.");
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
);
525 static void test_event_rule_kernel_probe_by_location(
526 const struct lttng_kernel_probe_location
*location
)
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
;
533 const char *probe_name
= "my_probe";
535 struct lttng_payload payload
;
537 diag("Event rule kprobe for location type %d.",
538 lttng_kernel_probe_location_get_type(location
));
540 lttng_payload_init(&payload
);
542 kprobe
= lttng_event_rule_kernel_kprobe_create(location
);
543 ok(kprobe
, "kprobe event rule object creation.");
545 status
= lttng_event_rule_kernel_kprobe_get_location(kprobe
, &_location
);
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.");
550 status
= lttng_event_rule_kernel_kprobe_set_event_name(kprobe
, probe_name
);
551 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
,
552 "Setting kprobe event rule name: %s.", probe_name
);
553 status
= lttng_event_rule_kernel_kprobe_get_event_name(kprobe
, &tmp
);
554 ok(status
== LTTNG_EVENT_RULE_STATUS_OK
, "Getting kprobe name.");
555 ok(!strcmp(probe_name
, tmp
), "kprobe name are equal.");
557 ok(lttng_event_rule_serialize(kprobe
, &payload
) == 0, "Serializing.");
560 struct lttng_payload_view view
=
561 lttng_payload_view_from_payload(
564 ok(lttng_event_rule_create_from_payload(
565 &view
, &kprobe_from_buffer
) > 0,
569 ok(lttng_event_rule_is_equal(kprobe
, kprobe_from_buffer
),
570 "serialized and from buffer are equal.");
572 lttng_payload_reset(&payload
);
573 lttng_event_rule_destroy(kprobe
);
574 lttng_event_rule_destroy(kprobe_from_buffer
);
577 static void test_event_rule_kernel_probe(void)
579 struct lttng_kernel_probe_location
*address_location
= NULL
;
580 struct lttng_kernel_probe_location
*symbol_location
= NULL
;
582 address_location
= lttng_kernel_probe_location_address_create(50);
583 symbol_location
= lttng_kernel_probe_location_symbol_create("une_bonne", 50);
584 LTTNG_ASSERT(address_location
);
585 LTTNG_ASSERT(symbol_location
);
587 test_event_rule_kernel_probe_by_location(address_location
);
588 test_event_rule_kernel_probe_by_location(symbol_location
);
590 lttng_kernel_probe_location_destroy(address_location
);
591 lttng_kernel_probe_location_destroy(symbol_location
);
594 static void test_set_event_rule_log_level_rules(
595 struct lttng_event_rule
*event_rule
,
596 event_rule_set_log_level set_log_level
,
598 enum lttng_event_rule_status
*exactly_status
,
599 enum lttng_event_rule_status
*as_severe_status
)
601 struct lttng_log_level_rule
*log_level_rule
;
603 log_level_rule
= lttng_log_level_rule_at_least_as_severe_as_create(
605 LTTNG_ASSERT(log_level_rule
);
607 *as_severe_status
= set_log_level(
608 event_rule
, log_level_rule
);
609 lttng_log_level_rule_destroy(log_level_rule
);
611 log_level_rule
= lttng_log_level_rule_exactly_create(log_level
);
612 LTTNG_ASSERT(log_level_rule
);
614 *exactly_status
= set_log_level(
615 event_rule
, log_level_rule
);
616 lttng_log_level_rule_destroy(log_level_rule
);
619 static void test_event_rule_log_level_generic(enum lttng_event_rule_type event_rule_type
,
620 log_level_name_getter get_log_level_name
,
621 event_rule_create create_event_rule
,
622 event_rule_set_log_level set_log_level
,
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
)
631 struct lttng_event_rule
*rule
;
632 enum lttng_event_rule_status er_exactly_status
, er_as_severe_status
;
633 const char *event_rule_type_str
= lttng_event_rule_type_str(event_rule_type
);
636 diag("Test %s event rule + log level rule", event_rule_type_str
);
638 rule
= create_event_rule();
641 for (i
= 0; i
< tagged_log_level_values_count
; i
++) {
642 const int tagged_log_level_value
= tagged_log_level_values
[i
];
644 test_set_event_rule_log_level_rules(rule
, set_log_level
,
645 tagged_log_level_value
,
646 &er_exactly_status
, &er_as_severe_status
);
647 ok(er_exactly_status
== LTTNG_EVENT_RULE_STATUS_OK
,
648 "Log level rule \"exactly\" accepted by %s event rule: level = %s",
651 tagged_log_level_value
));
652 ok(er_as_severe_status
== LTTNG_EVENT_RULE_STATUS_OK
,
653 "Log level rule \"as least as severe as\" accepted by %s event rule: level = %s",
656 tagged_log_level_value
));
659 for (i
= 0; i
< valid_log_level_values_count
; i
++) {
660 const int valid_log_level_value
= valid_log_level_values
[i
];
662 test_set_event_rule_log_level_rules(rule
, set_log_level
,
663 valid_log_level_value
,
664 &er_exactly_status
, &er_as_severe_status
);
665 ok(er_exactly_status
== LTTNG_EVENT_RULE_STATUS_OK
,
666 "Log level rule \"exactly\" accepted by %s event rule: level = %d",
668 valid_log_level_value
);
669 ok(er_as_severe_status
== LTTNG_EVENT_RULE_STATUS_OK
,
670 "Log level rule \"as least as severe as\" accepted by %s event rule: level = %d",
672 valid_log_level_value
);
675 for (i
= 0; i
< invalid_log_level_values_count
; i
++) {
676 const int invalid_log_level_value
= invalid_log_level_values
[i
];
678 test_set_event_rule_log_level_rules(rule
, set_log_level
,
679 invalid_log_level_value
,
680 &er_exactly_status
, &er_as_severe_status
);
681 ok(er_exactly_status
== LTTNG_EVENT_RULE_STATUS_INVALID
,
682 "Log level rule \"exactly\" rejected by %s event rule: level = %d",
684 invalid_log_level_value
);
685 ok(er_as_severe_status
== LTTNG_EVENT_RULE_STATUS_INVALID
,
686 "Log level rule \"as least as severe as\" rejected by %s event rule: level = %d",
688 invalid_log_level_value
);
691 lttng_event_rule_destroy(rule
);
694 static void test_event_rule_log_level_ust(void)
696 const int tagged_log_level_values
[] = {
697 LTTNG_LOGLEVEL_EMERG
,
698 LTTNG_LOGLEVEL_ALERT
,
701 LTTNG_LOGLEVEL_WARNING
,
702 LTTNG_LOGLEVEL_NOTICE
,
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
,
713 const int invalid_log_level_values
[] = {
716 LTTNG_LOGLEVEL_DEBUG
+ 1,
717 LTTNG_LOGLEVEL_EMERG
- 1,
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,
726 invalid_log_level_values
,
727 ARRAY_SIZE(invalid_log_level_values
));
730 static void test_event_rule_log_level_jul(void)
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
,
743 const int valid_log_level_values
[] = {
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
,
754 ARRAY_SIZE(tagged_log_level_values
),
755 valid_log_level_values
,
756 ARRAY_SIZE(valid_log_level_values
), NULL
, 0);
759 static void test_event_rule_log_level_log4j(void)
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
,
771 const int valid_log_level_values
[] = {
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
,
782 ARRAY_SIZE(tagged_log_level_values
),
783 valid_log_level_values
,
784 ARRAY_SIZE(valid_log_level_values
), NULL
, 0);
787 static void test_event_rule_log_level_python(void)
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
,
797 const int valid_log_level_values
[] = {
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
,
809 ARRAY_SIZE(tagged_log_level_values
),
810 valid_log_level_values
,
811 ARRAY_SIZE(valid_log_level_values
),
817 plan_tests(NUM_TESTS
);
818 test_event_rule_kernel_tracepoint();
819 test_event_rule_user_tracepoint();
820 test_event_rule_syscall();
821 test_event_rule_userspace_probe();
822 test_event_rule_kernel_probe();
823 test_event_rule_log4j_logging();
824 test_event_rule_jul_logging();
825 test_event_rule_python_logging();
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();
830 return exit_status();