Fix: tests: uninitialized lttng_payload
[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 lttng_payload_init(&payload);
463
464 lookup_method = lttng_userspace_probe_location_lookup_method_function_elf_create();
465 if (!lookup_method) {
466 fail("Setup error on userspace probe lookup method creation.");
467 goto end;
468 }
469
470 probe_location = lttng_userspace_probe_location_function_create(
471 "/proc/self/exe",
472 "lttng_userspace_probe_location_tracepoint_create",
473 lookup_method);
474 if (!probe_location) {
475 fail("Setup error on userspace probe location creation.");
476 goto end;
477 }
478
479 /* Ownership transferred to the probe location function object. */
480 lookup_method = NULL;
481
482 lttng_payload_init(&payload);
483
484 uprobe = lttng_event_rule_kernel_uprobe_create(probe_location);
485 ok(uprobe, "uprobe event rule object creation.");
486
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.");
494
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.");
501
502 ok(lttng_event_rule_serialize(uprobe, &payload) == 0, "Serializing.");
503
504 {
505 struct lttng_payload_view view =
506 lttng_payload_view_from_payload(
507 &payload, 0, -1);
508
509 ok(lttng_event_rule_create_from_payload(
510 &view, &uprobe_from_buffer) > 0,
511 "Deserializing.");
512 }
513
514 ok(lttng_event_rule_is_equal(uprobe, uprobe_from_buffer),
515 "serialized and from buffer are equal.");
516
517 end:
518 lttng_payload_reset(&payload);
519 lttng_event_rule_destroy(uprobe);
520 lttng_event_rule_destroy(uprobe_from_buffer);
521 lttng_userspace_probe_location_destroy(probe_location);
522 lttng_userspace_probe_location_lookup_method_destroy(lookup_method);
523 }
524
525 static void test_event_rule_kernel_probe_by_location(
526 const struct lttng_kernel_probe_location *location)
527 {
528 struct lttng_event_rule *kprobe = NULL;
529 struct lttng_event_rule *kprobe_from_buffer = NULL;
530 enum lttng_event_rule_status status;
531 const struct lttng_kernel_probe_location *_location;
532
533 const char *probe_name = "my_probe";
534 const char *tmp;
535 struct lttng_payload payload;
536
537 diag("Event rule kprobe for location type %d.",
538 lttng_kernel_probe_location_get_type(location));
539
540 lttng_payload_init(&payload);
541
542 kprobe = lttng_event_rule_kernel_kprobe_create(location);
543 ok(kprobe, "kprobe event rule object creation.");
544
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.");
549
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.");
556
557 ok(lttng_event_rule_serialize(kprobe, &payload) == 0, "Serializing.");
558
559 {
560 struct lttng_payload_view view =
561 lttng_payload_view_from_payload(
562 &payload, 0, -1);
563
564 ok(lttng_event_rule_create_from_payload(
565 &view, &kprobe_from_buffer) > 0,
566 "Deserializing.");
567 }
568
569 ok(lttng_event_rule_is_equal(kprobe, kprobe_from_buffer),
570 "serialized and from buffer are equal.");
571
572 lttng_payload_reset(&payload);
573 lttng_event_rule_destroy(kprobe);
574 lttng_event_rule_destroy(kprobe_from_buffer);
575 }
576
577 static void test_event_rule_kernel_probe(void)
578 {
579 struct lttng_kernel_probe_location *address_location = NULL;
580 struct lttng_kernel_probe_location *symbol_location = NULL;
581
582 address_location = lttng_kernel_probe_location_address_create(50);
583 symbol_location = lttng_kernel_probe_location_symbol_create("une_bonne", 50);
584 LTTNG_ASSERT(address_location);
585 LTTNG_ASSERT(symbol_location);
586
587 test_event_rule_kernel_probe_by_location(address_location);
588 test_event_rule_kernel_probe_by_location(symbol_location);
589
590 lttng_kernel_probe_location_destroy(address_location);
591 lttng_kernel_probe_location_destroy(symbol_location);
592 }
593
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,
597 int log_level,
598 enum lttng_event_rule_status *exactly_status,
599 enum lttng_event_rule_status *as_severe_status)
600 {
601 struct lttng_log_level_rule *log_level_rule;
602
603 log_level_rule = lttng_log_level_rule_at_least_as_severe_as_create(
604 log_level);
605 LTTNG_ASSERT(log_level_rule);
606
607 *as_severe_status = set_log_level(
608 event_rule, log_level_rule);
609 lttng_log_level_rule_destroy(log_level_rule);
610
611 log_level_rule = lttng_log_level_rule_exactly_create(log_level);
612 LTTNG_ASSERT(log_level_rule);
613
614 *exactly_status = set_log_level(
615 event_rule, log_level_rule);
616 lttng_log_level_rule_destroy(log_level_rule);
617 }
618
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)
629 {
630 size_t i;
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);
634
635
636 diag("Test %s event rule + log level rule", event_rule_type_str);
637
638 rule = create_event_rule();
639 LTTNG_ASSERT(rule);
640
641 for (i = 0; i < tagged_log_level_values_count; i++) {
642 const int tagged_log_level_value = tagged_log_level_values[i];
643
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",
649 event_rule_type_str,
650 get_log_level_name(
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",
654 event_rule_type_str,
655 get_log_level_name(
656 tagged_log_level_value));
657 }
658
659 for (i = 0; i < valid_log_level_values_count; i++) {
660 const int valid_log_level_value = valid_log_level_values[i];
661
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",
667 event_rule_type_str,
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",
671 event_rule_type_str,
672 valid_log_level_value);
673 }
674
675 for (i = 0; i < invalid_log_level_values_count; i++) {
676 const int invalid_log_level_value = invalid_log_level_values[i];
677
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",
683 event_rule_type_str,
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",
687 event_rule_type_str,
688 invalid_log_level_value);
689 }
690
691 lttng_event_rule_destroy(rule);
692 }
693
694 static void test_event_rule_log_level_ust(void)
695 {
696 const int tagged_log_level_values[] = {
697 LTTNG_LOGLEVEL_EMERG,
698 LTTNG_LOGLEVEL_ALERT,
699 LTTNG_LOGLEVEL_CRIT,
700 LTTNG_LOGLEVEL_ERR,
701 LTTNG_LOGLEVEL_WARNING,
702 LTTNG_LOGLEVEL_NOTICE,
703 LTTNG_LOGLEVEL_INFO,
704 LTTNG_LOGLEVEL_DEBUG_SYSTEM,
705 LTTNG_LOGLEVEL_DEBUG_PROGRAM,
706 LTTNG_LOGLEVEL_DEBUG_PROCESS,
707 LTTNG_LOGLEVEL_DEBUG_MODULE,
708 LTTNG_LOGLEVEL_DEBUG_UNIT,
709 LTTNG_LOGLEVEL_DEBUG_FUNCTION,
710 LTTNG_LOGLEVEL_DEBUG_LINE,
711 LTTNG_LOGLEVEL_DEBUG,
712 };
713 const int invalid_log_level_values[] = {
714 -1980,
715 1995,
716 LTTNG_LOGLEVEL_DEBUG + 1,
717 LTTNG_LOGLEVEL_EMERG - 1,
718 };
719
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));
728 }
729
730 static void test_event_rule_log_level_jul(void)
731 {
732 const int tagged_log_level_values[] = {
733 LTTNG_LOGLEVEL_JUL_OFF,
734 LTTNG_LOGLEVEL_JUL_SEVERE,
735 LTTNG_LOGLEVEL_JUL_WARNING,
736 LTTNG_LOGLEVEL_JUL_INFO,
737 LTTNG_LOGLEVEL_JUL_CONFIG,
738 LTTNG_LOGLEVEL_JUL_FINE,
739 LTTNG_LOGLEVEL_JUL_FINER,
740 LTTNG_LOGLEVEL_JUL_FINEST,
741 LTTNG_LOGLEVEL_JUL_ALL,
742 };
743 const int valid_log_level_values[] = {
744 0,
745 -1980,
746 1995
747 };
748
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);
757 }
758
759 static void test_event_rule_log_level_log4j(void)
760 {
761 const int tagged_log_level_values[] = {
762 LTTNG_LOGLEVEL_LOG4J_OFF,
763 LTTNG_LOGLEVEL_LOG4J_FATAL,
764 LTTNG_LOGLEVEL_LOG4J_ERROR,
765 LTTNG_LOGLEVEL_LOG4J_WARN,
766 LTTNG_LOGLEVEL_LOG4J_INFO,
767 LTTNG_LOGLEVEL_LOG4J_DEBUG,
768 LTTNG_LOGLEVEL_LOG4J_TRACE,
769 LTTNG_LOGLEVEL_LOG4J_ALL,
770 };
771 const int valid_log_level_values[] = {
772 0
773 -1980,
774 1995
775 };
776
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);
785 }
786
787 static void test_event_rule_log_level_python(void)
788 {
789 const int tagged_log_level_values[] = {
790 LTTNG_LOGLEVEL_PYTHON_CRITICAL,
791 LTTNG_LOGLEVEL_PYTHON_ERROR,
792 LTTNG_LOGLEVEL_PYTHON_WARNING,
793 LTTNG_LOGLEVEL_PYTHON_INFO,
794 LTTNG_LOGLEVEL_PYTHON_DEBUG,
795 LTTNG_LOGLEVEL_PYTHON_NOTSET,
796 };
797 const int valid_log_level_values[] = {
798 45,
799 35,
800 0,
801 -657,
802 };
803
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),
812 NULL, 0);
813 }
814
815 int main(void)
816 {
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();
831 }
This page took 0.05923 seconds and 5 git commands to generate.