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.");
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.");
469 probe_location
= lttng_userspace_probe_location_function_create(
471 "lttng_userspace_probe_location_tracepoint_create",
473 if (!probe_location
) {
474 fail("Setup error on userspace probe location creation.");
478 /* Ownership transferred to the probe location function object. */
479 lookup_method
= NULL
;
481 lttng_payload_init(&payload
);
483 uprobe
= lttng_event_rule_kernel_uprobe_create(probe_location
);
484 ok(uprobe
, "uprobe event rule object creation.");
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.");
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.");
501 ok(lttng_event_rule_serialize(uprobe
, &payload
) == 0, "Serializing.");
504 struct lttng_payload_view view
=
505 lttng_payload_view_from_payload(
508 ok(lttng_event_rule_create_from_payload(
509 &view
, &uprobe_from_buffer
) > 0,
513 ok(lttng_event_rule_is_equal(uprobe
, uprobe_from_buffer
),
514 "serialized and from buffer are equal.");
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
);
524 static void test_event_rule_kernel_probe_by_location(
525 const struct lttng_kernel_probe_location
*location
)
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
;
532 const char *probe_name
= "my_probe";
534 struct lttng_payload payload
;
536 diag("Event rule kprobe for location type %d.",
537 lttng_kernel_probe_location_get_type(location
));
539 lttng_payload_init(&payload
);
541 kprobe
= lttng_event_rule_kernel_kprobe_create(location
);
542 ok(kprobe
, "kprobe event rule object creation.");
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.");
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.");
556 ok(lttng_event_rule_serialize(kprobe
, &payload
) == 0, "Serializing.");
559 struct lttng_payload_view view
=
560 lttng_payload_view_from_payload(
563 ok(lttng_event_rule_create_from_payload(
564 &view
, &kprobe_from_buffer
) > 0,
568 ok(lttng_event_rule_is_equal(kprobe
, kprobe_from_buffer
),
569 "serialized and from buffer are equal.");
571 lttng_payload_reset(&payload
);
572 lttng_event_rule_destroy(kprobe
);
573 lttng_event_rule_destroy(kprobe_from_buffer
);
576 static void test_event_rule_kernel_probe(void)
578 struct lttng_kernel_probe_location
*address_location
= NULL
;
579 struct lttng_kernel_probe_location
*symbol_location
= NULL
;
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
);
586 test_event_rule_kernel_probe_by_location(address_location
);
587 test_event_rule_kernel_probe_by_location(symbol_location
);
589 lttng_kernel_probe_location_destroy(address_location
);
590 lttng_kernel_probe_location_destroy(symbol_location
);
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
,
597 enum lttng_event_rule_status
*exactly_status
,
598 enum lttng_event_rule_status
*as_severe_status
)
600 struct lttng_log_level_rule
*log_level_rule
;
602 log_level_rule
= lttng_log_level_rule_at_least_as_severe_as_create(
604 LTTNG_ASSERT(log_level_rule
);
606 *as_severe_status
= set_log_level(
607 event_rule
, log_level_rule
);
608 lttng_log_level_rule_destroy(log_level_rule
);
610 log_level_rule
= lttng_log_level_rule_exactly_create(log_level
);
611 LTTNG_ASSERT(log_level_rule
);
613 *exactly_status
= set_log_level(
614 event_rule
, log_level_rule
);
615 lttng_log_level_rule_destroy(log_level_rule
);
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
)
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
);
635 diag("Test %s event rule + log level rule", event_rule_type_str
);
637 rule
= create_event_rule();
640 for (i
= 0; i
< tagged_log_level_values_count
; i
++) {
641 const int tagged_log_level_value
= tagged_log_level_values
[i
];
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",
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",
655 tagged_log_level_value
));
658 for (i
= 0; i
< valid_log_level_values_count
; i
++) {
659 const int valid_log_level_value
= valid_log_level_values
[i
];
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",
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",
671 valid_log_level_value
);
674 for (i
= 0; i
< invalid_log_level_values_count
; i
++) {
675 const int invalid_log_level_value
= invalid_log_level_values
[i
];
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",
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",
687 invalid_log_level_value
);
690 lttng_event_rule_destroy(rule
);
693 static void test_event_rule_log_level_ust(void)
695 const int tagged_log_level_values
[] = {
696 LTTNG_LOGLEVEL_EMERG
,
697 LTTNG_LOGLEVEL_ALERT
,
700 LTTNG_LOGLEVEL_WARNING
,
701 LTTNG_LOGLEVEL_NOTICE
,
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
,
712 const int invalid_log_level_values
[] = {
715 LTTNG_LOGLEVEL_DEBUG
+ 1,
716 LTTNG_LOGLEVEL_EMERG
- 1,
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
));
729 static void test_event_rule_log_level_jul(void)
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
,
742 const int valid_log_level_values
[] = {
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);
758 static void test_event_rule_log_level_log4j(void)
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
,
770 const int valid_log_level_values
[] = {
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);
786 static void test_event_rule_log_level_python(void)
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
,
796 const int valid_log_level_values
[] = {
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
),
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();