Commit | Line | Data |
---|---|---|
dbc20d3c JR |
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 <assert.h> | |
11 | #include <inttypes.h> | |
12 | #include <stdio.h> | |
13 | #include <string.h> | |
14 | #include <unistd.h> | |
15 | ||
16 | #include <tap/tap.h> | |
17 | ||
18 | #include <common/payload-view.h> | |
19 | #include <common/payload.h> | |
20 | #include <lttng/domain.h> | |
b47b01d8 JR |
21 | #include <lttng/event-rule/jul-logging-internal.h> |
22 | #include <lttng/event-rule/jul-logging.h> | |
85522de5 JR |
23 | #include <lttng/event-rule/kernel-kprobe-internal.h> |
24 | #include <lttng/event-rule/kernel-kprobe.h> | |
4f7da553 JR |
25 | #include <lttng/event-rule/kernel-syscall-internal.h> |
26 | #include <lttng/event-rule/kernel-syscall.h> | |
6530ec7d JR |
27 | #include <lttng/event-rule/python-logging-internal.h> |
28 | #include <lttng/event-rule/python-logging.h> | |
af0818ef JR |
29 | #include <lttng/event-rule/kernel-tracepoint-internal.h> |
30 | #include <lttng/event-rule/kernel-tracepoint.h> | |
46fd07ac JR |
31 | #include <lttng/event-rule/kernel-uprobe-internal.h> |
32 | #include <lttng/event-rule/kernel-uprobe.h> | |
0a23a07d JR |
33 | #include <lttng/event-rule/user-tracepoint-internal.h> |
34 | #include <lttng/event-rule/user-tracepoint.h> | |
dbc20d3c JR |
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> | |
2b4c142d | 40 | #include "bin/lttng/loglevel.h" |
dbc20d3c JR |
41 | |
42 | /* For error.h. */ | |
43 | int lttng_opt_quiet = 1; | |
44 | int lttng_opt_verbose; | |
45 | int lttng_opt_mi; | |
46 | ||
695f7044 | 47 | #define NUM_TESTS 212 |
dbc20d3c JR |
48 | |
49 | struct tracepoint_test { | |
50 | enum lttng_domain_type type; | |
975d26c5 | 51 | bool support_name_pattern_exclusion; |
dbc20d3c JR |
52 | }; |
53 | ||
2b4c142d JG |
54 | typedef const char *(*log_level_name_getter)(int log_level); |
55 | ||
cade690d JR |
56 | typedef struct lttng_event_rule *(*event_rule_create)(void); |
57 | typedef enum lttng_event_rule_status (*event_rule_set_log_level)( | |
58 | struct lttng_event_rule *rule, | |
59 | const struct lttng_log_level_rule *log_level_rule); | |
60 | ||
af0818ef JR |
61 | static |
62 | void test_event_rule_kernel_tracepoint(void) | |
63 | { | |
64 | struct lttng_event_rule *tracepoint = NULL; | |
65 | struct lttng_event_rule *tracepoint_from_buffer = NULL; | |
66 | enum lttng_event_rule_status status; | |
67 | const char *pattern="my_event_*"; | |
68 | const char *filter="msg_id == 23 && size >= 2048"; | |
69 | const char *tmp; | |
70 | struct lttng_payload payload; | |
71 | ||
72 | diag("Testing lttng_event_rule_kernel_tracepoint."); | |
73 | ||
74 | lttng_payload_init(&payload); | |
75 | ||
76 | tracepoint = lttng_event_rule_kernel_tracepoint_create(); | |
77 | ok(tracepoint, "tracepoint object."); | |
78 | ||
79 | status = lttng_event_rule_kernel_tracepoint_set_name_pattern(tracepoint, pattern); | |
80 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); | |
81 | status = lttng_event_rule_kernel_tracepoint_get_name_pattern(tracepoint, &tmp); | |
82 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); | |
83 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
84 | ||
85 | status = lttng_event_rule_kernel_tracepoint_set_filter(tracepoint, filter); | |
86 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); | |
87 | status = lttng_event_rule_kernel_tracepoint_get_filter(tracepoint, &tmp); | |
88 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); | |
89 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
90 | ||
91 | ok(lttng_event_rule_serialize(tracepoint, &payload) == 0, "Serializing."); | |
92 | ||
93 | { | |
94 | struct lttng_payload_view view = | |
95 | lttng_payload_view_from_payload( | |
96 | &payload, 0, -1); | |
97 | ||
98 | ok(lttng_event_rule_create_from_payload( | |
99 | &view, &tracepoint_from_buffer) > 0, | |
100 | "Deserializing."); | |
101 | } | |
102 | ||
103 | ok(lttng_event_rule_is_equal(tracepoint, tracepoint_from_buffer), "serialized and from buffer are equal."); | |
104 | ||
105 | lttng_payload_reset(&payload); | |
106 | lttng_event_rule_destroy(tracepoint); | |
107 | lttng_event_rule_destroy(tracepoint_from_buffer); | |
108 | } | |
109 | ||
0a23a07d JR |
110 | static |
111 | void test_event_rule_user_tracepoint(void) | |
112 | { | |
113 | int i; | |
114 | unsigned int count; | |
115 | struct lttng_event_rule *tracepoint = NULL; | |
116 | struct lttng_event_rule *tracepoint_from_buffer = NULL; | |
117 | enum lttng_event_rule_status status; | |
118 | const char *pattern="my_event_*"; | |
119 | const char *filter="msg_id == 23 && size >= 2048"; | |
120 | const char *tmp; | |
121 | const char *name_pattern_exclusions[] = {"my_event_test1", "my_event_test2" ,"my_event_test3"}; | |
122 | struct lttng_log_level_rule *log_level_rule = NULL; | |
123 | const struct lttng_log_level_rule *log_level_rule_return = NULL; | |
124 | struct lttng_payload payload; | |
125 | ||
126 | diag("Testing lttng_event_rule_user_tracepoint."); | |
127 | ||
128 | lttng_payload_init(&payload); | |
129 | ||
130 | log_level_rule = lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO); | |
131 | assert(log_level_rule); | |
132 | ||
133 | tracepoint = lttng_event_rule_user_tracepoint_create(); | |
134 | ok(tracepoint, "user tracepoint object."); | |
135 | ||
136 | status = lttng_event_rule_user_tracepoint_set_name_pattern(tracepoint, pattern); | |
137 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); | |
138 | status = lttng_event_rule_user_tracepoint_get_name_pattern(tracepoint, &tmp); | |
139 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); | |
140 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
141 | ||
142 | status = lttng_event_rule_user_tracepoint_set_filter(tracepoint, filter); | |
143 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); | |
144 | status = lttng_event_rule_user_tracepoint_get_filter(tracepoint, &tmp); | |
145 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); | |
146 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
147 | ||
148 | status = lttng_event_rule_user_tracepoint_get_log_level_rule(tracepoint, &log_level_rule_return); | |
149 | ok(status == LTTNG_EVENT_RULE_STATUS_UNSET, "get unset log level rule."); | |
150 | ||
151 | status = lttng_event_rule_user_tracepoint_set_log_level_rule( | |
152 | tracepoint, log_level_rule); | |
153 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting log level rule."); | |
154 | status = lttng_event_rule_user_tracepoint_get_log_level_rule( | |
155 | tracepoint, &log_level_rule_return); | |
156 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "get log level rule."); | |
157 | ||
158 | /* Name pattern exclusions */ | |
159 | for (i = 0; i < 3; i++) { | |
160 | status = lttng_event_rule_user_tracepoint_add_name_pattern_exclusion( | |
161 | tracepoint, name_pattern_exclusions[i]); | |
162 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, | |
163 | "setting name pattern exclusions \"%s\"", | |
164 | name_pattern_exclusions[i]); | |
165 | } | |
166 | ||
167 | status = lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_count( | |
168 | tracepoint, &count); | |
169 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, | |
170 | "getting name pattern exclusion count."); | |
171 | ok(count == 3, "count is %d/3", count); | |
172 | ||
173 | for (i = 0; i < count; i++) { | |
174 | status = lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_at_index( | |
175 | tracepoint, i, &tmp); | |
176 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, | |
177 | "getting name pattern exclusion at index %d.", | |
178 | i); | |
179 | ok(!strncmp(name_pattern_exclusions[i], tmp, | |
180 | strlen(name_pattern_exclusions[i])), | |
181 | "%s == %s.", tmp, name_pattern_exclusions[i]); | |
182 | } | |
183 | ||
184 | ok(lttng_event_rule_serialize(tracepoint, &payload) == 0, "Serializing."); | |
185 | ||
186 | { | |
187 | struct lttng_payload_view view = | |
188 | lttng_payload_view_from_payload( | |
189 | &payload, 0, -1); | |
190 | ||
191 | ok(lttng_event_rule_create_from_payload( | |
192 | &view, &tracepoint_from_buffer) > 0, | |
193 | "Deserializing."); | |
194 | } | |
195 | ||
196 | ok(lttng_event_rule_is_equal(tracepoint, tracepoint_from_buffer), "serialized and from buffer are equal."); | |
197 | ||
198 | lttng_payload_reset(&payload); | |
199 | lttng_event_rule_destroy(tracepoint); | |
200 | lttng_event_rule_destroy(tracepoint_from_buffer); | |
201 | lttng_log_level_rule_destroy(log_level_rule); | |
202 | } | |
203 | ||
dbc20d3c JR |
204 | static void test_event_rule_syscall(void) |
205 | { | |
206 | struct lttng_event_rule *syscall = NULL; | |
207 | struct lttng_event_rule *syscall_from_buffer = NULL; | |
208 | enum lttng_event_rule_status status; | |
209 | const char *pattern = "my_event_*"; | |
210 | const char *filter = "msg_id == 23 && size >= 2048"; | |
211 | const char *tmp; | |
212 | struct lttng_payload payload; | |
213 | ||
214 | diag("Event rule syscall."); | |
215 | ||
216 | lttng_payload_init(&payload); | |
217 | ||
4f7da553 | 218 | syscall = lttng_event_rule_kernel_syscall_create(LTTNG_EVENT_RULE_KERNEL_SYSCALL_EMISSION_SITE_ENTRY); |
dbc20d3c JR |
219 | ok(syscall, "syscall object."); |
220 | ||
4f7da553 | 221 | status = lttng_event_rule_kernel_syscall_set_name_pattern(syscall, pattern); |
dbc20d3c | 222 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); |
4f7da553 | 223 | status = lttng_event_rule_kernel_syscall_get_name_pattern(syscall, &tmp); |
dbc20d3c JR |
224 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); |
225 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
226 | ||
4f7da553 | 227 | status = lttng_event_rule_kernel_syscall_set_filter(syscall, filter); |
dbc20d3c | 228 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); |
4f7da553 | 229 | status = lttng_event_rule_kernel_syscall_get_filter(syscall, &tmp); |
dbc20d3c JR |
230 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); |
231 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
232 | ||
233 | ok(lttng_event_rule_serialize(syscall, &payload) == 0, "Serializing."); | |
234 | ||
235 | { | |
236 | struct lttng_payload_view view = | |
237 | lttng_payload_view_from_payload( | |
238 | &payload, 0, -1); | |
239 | ||
240 | ok(lttng_event_rule_create_from_payload( | |
241 | &view, &syscall_from_buffer) > 0, | |
242 | "Deserializing."); | |
243 | } | |
244 | ||
245 | ok(lttng_event_rule_is_equal(syscall, syscall_from_buffer), | |
246 | "serialized and from buffer are equal."); | |
247 | ||
248 | lttng_payload_reset(&payload); | |
249 | lttng_event_rule_destroy(syscall); | |
250 | lttng_event_rule_destroy(syscall_from_buffer); | |
251 | } | |
252 | ||
b47b01d8 JR |
253 | static |
254 | void test_event_rule_jul_logging(void) | |
255 | { | |
256 | struct lttng_event_rule *jul_logging = NULL; | |
257 | struct lttng_event_rule *jul_logging_from_buffer = NULL; | |
258 | enum lttng_event_rule_status status; | |
259 | const char *pattern="my_event_*"; | |
260 | const char *filter="msg_id == 23 && size >= 2048"; | |
261 | const char *tmp; | |
262 | struct lttng_log_level_rule *log_level_rule = NULL; | |
263 | const struct lttng_log_level_rule *log_level_rule_return = NULL; | |
264 | struct lttng_payload payload; | |
265 | ||
266 | diag("Testing lttng_event_rule_user_jul_logging."); | |
267 | ||
268 | lttng_payload_init(&payload); | |
269 | ||
270 | log_level_rule = lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO); | |
271 | assert(log_level_rule); | |
272 | ||
273 | jul_logging = lttng_event_rule_jul_logging_create(); | |
274 | ok(jul_logging, "jul_logging object."); | |
275 | ||
276 | status = lttng_event_rule_jul_logging_set_name_pattern(jul_logging, pattern); | |
277 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); | |
278 | status = lttng_event_rule_jul_logging_get_name_pattern(jul_logging, &tmp); | |
279 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); | |
280 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
281 | ||
282 | status = lttng_event_rule_jul_logging_set_filter(jul_logging, filter); | |
283 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); | |
284 | status = lttng_event_rule_jul_logging_get_filter(jul_logging, &tmp); | |
285 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); | |
286 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
287 | ||
288 | status = lttng_event_rule_jul_logging_get_log_level_rule(jul_logging, &log_level_rule_return); | |
289 | ok(status == LTTNG_EVENT_RULE_STATUS_UNSET, "get unset log level rule."); | |
290 | ||
291 | status = lttng_event_rule_jul_logging_set_log_level_rule( | |
292 | jul_logging, log_level_rule); | |
293 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting log level rule."); | |
294 | status = lttng_event_rule_jul_logging_get_log_level_rule( | |
295 | jul_logging, &log_level_rule_return); | |
296 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "get log level rule."); | |
297 | ||
298 | ok(lttng_event_rule_serialize(jul_logging, &payload) == 0, "Serializing."); | |
299 | ||
300 | { | |
301 | struct lttng_payload_view view = | |
302 | lttng_payload_view_from_payload( | |
303 | &payload, 0, -1); | |
304 | ||
305 | ok(lttng_event_rule_create_from_payload( | |
306 | &view, &jul_logging_from_buffer) > 0, | |
307 | "Deserializing."); | |
308 | } | |
309 | ||
310 | ok(lttng_event_rule_is_equal(jul_logging, jul_logging_from_buffer), "serialized and from buffer are equal."); | |
311 | ||
312 | lttng_payload_reset(&payload); | |
313 | lttng_event_rule_destroy(jul_logging); | |
314 | lttng_event_rule_destroy(jul_logging_from_buffer); | |
315 | lttng_log_level_rule_destroy(log_level_rule); | |
316 | } | |
317 | ||
138d6838 JR |
318 | static |
319 | void test_event_rule_log4j_logging(void) | |
320 | { | |
321 | struct lttng_event_rule *log4j_logging = NULL; | |
322 | struct lttng_event_rule *log4j_logging_from_buffer = NULL; | |
323 | enum lttng_event_rule_status status; | |
324 | const char *pattern="my_event_*"; | |
325 | const char *filter="msg_id == 23 && size >= 2048"; | |
326 | const char *tmp; | |
327 | struct lttng_log_level_rule *log_level_rule = NULL; | |
328 | const struct lttng_log_level_rule *log_level_rule_return = NULL; | |
329 | struct lttng_payload payload; | |
330 | ||
331 | diag("Testing lttng_event_rule_user_log4j_logging."); | |
332 | ||
333 | lttng_payload_init(&payload); | |
334 | ||
335 | log_level_rule = lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO); | |
336 | assert(log_level_rule); | |
337 | ||
338 | log4j_logging = lttng_event_rule_log4j_logging_create(); | |
339 | ok(log4j_logging, "log4j_logging object."); | |
340 | ||
341 | status = lttng_event_rule_log4j_logging_set_name_pattern(log4j_logging, pattern); | |
342 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); | |
343 | status = lttng_event_rule_log4j_logging_get_name_pattern(log4j_logging, &tmp); | |
344 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); | |
345 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
346 | ||
347 | status = lttng_event_rule_log4j_logging_set_filter(log4j_logging, filter); | |
348 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); | |
349 | status = lttng_event_rule_log4j_logging_get_filter(log4j_logging, &tmp); | |
350 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); | |
351 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
352 | ||
353 | status = lttng_event_rule_log4j_logging_get_log_level_rule(log4j_logging, &log_level_rule_return); | |
354 | ok(status == LTTNG_EVENT_RULE_STATUS_UNSET, "get unset log level rule."); | |
355 | ||
356 | status = lttng_event_rule_log4j_logging_set_log_level_rule( | |
357 | log4j_logging, log_level_rule); | |
358 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting log level rule."); | |
359 | status = lttng_event_rule_log4j_logging_get_log_level_rule( | |
360 | log4j_logging, &log_level_rule_return); | |
361 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "get log level rule."); | |
362 | ||
363 | ok(lttng_event_rule_serialize(log4j_logging, &payload) == 0, "Serializing."); | |
364 | ||
365 | { | |
366 | struct lttng_payload_view view = | |
367 | lttng_payload_view_from_payload( | |
368 | &payload, 0, -1); | |
369 | ||
370 | ok(lttng_event_rule_create_from_payload( | |
371 | &view, &log4j_logging_from_buffer) > 0, | |
372 | "Deserializing."); | |
373 | } | |
374 | ||
375 | ok(lttng_event_rule_is_equal(log4j_logging, log4j_logging_from_buffer), "serialized and from buffer are equal."); | |
376 | ||
377 | lttng_payload_reset(&payload); | |
378 | lttng_event_rule_destroy(log4j_logging); | |
379 | lttng_event_rule_destroy(log4j_logging_from_buffer); | |
380 | lttng_log_level_rule_destroy(log_level_rule); | |
381 | } | |
382 | ||
6530ec7d JR |
383 | static |
384 | void test_event_rule_python_logging(void) | |
385 | { | |
386 | struct lttng_event_rule *python_logging = NULL; | |
387 | struct lttng_event_rule *python_logging_from_buffer = NULL; | |
388 | enum lttng_event_rule_status status; | |
389 | const char *pattern="my_event_*"; | |
390 | const char *filter="msg_id == 23 && size >= 2048"; | |
391 | const char *tmp; | |
392 | struct lttng_log_level_rule *log_level_rule = NULL; | |
393 | const struct lttng_log_level_rule *log_level_rule_return = NULL; | |
394 | struct lttng_payload payload; | |
395 | ||
396 | diag("Testing lttng_event_rule_user_python_logging."); | |
397 | ||
398 | lttng_payload_init(&payload); | |
399 | ||
400 | log_level_rule = lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO); | |
401 | assert(log_level_rule); | |
402 | ||
403 | python_logging = lttng_event_rule_python_logging_create(); | |
404 | ok(python_logging, "python_logging object."); | |
405 | ||
406 | status = lttng_event_rule_python_logging_set_name_pattern(python_logging, pattern); | |
407 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); | |
408 | status = lttng_event_rule_python_logging_get_name_pattern(python_logging, &tmp); | |
409 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); | |
410 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
411 | ||
412 | status = lttng_event_rule_python_logging_set_filter(python_logging, filter); | |
413 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); | |
414 | status = lttng_event_rule_python_logging_get_filter(python_logging, &tmp); | |
415 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); | |
416 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
417 | ||
418 | status = lttng_event_rule_python_logging_get_log_level_rule(python_logging, &log_level_rule_return); | |
419 | ok(status == LTTNG_EVENT_RULE_STATUS_UNSET, "get unset log level rule."); | |
420 | ||
421 | status = lttng_event_rule_python_logging_set_log_level_rule( | |
422 | python_logging, log_level_rule); | |
423 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting log level rule."); | |
424 | status = lttng_event_rule_python_logging_get_log_level_rule( | |
425 | python_logging, &log_level_rule_return); | |
426 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "get log level rule."); | |
427 | ||
428 | ok(lttng_event_rule_serialize(python_logging, &payload) == 0, "Serializing."); | |
429 | ||
430 | { | |
431 | struct lttng_payload_view view = | |
432 | lttng_payload_view_from_payload( | |
433 | &payload, 0, -1); | |
434 | ||
435 | ok(lttng_event_rule_create_from_payload( | |
436 | &view, &python_logging_from_buffer) > 0, | |
437 | "Deserializing."); | |
438 | } | |
439 | ||
440 | ok(lttng_event_rule_is_equal(python_logging, python_logging_from_buffer), "serialized and from buffer are equal."); | |
441 | ||
442 | lttng_payload_reset(&payload); | |
443 | lttng_event_rule_destroy(python_logging); | |
444 | lttng_event_rule_destroy(python_logging_from_buffer); | |
445 | lttng_log_level_rule_destroy(log_level_rule); | |
446 | } | |
447 | ||
1f1567a5 | 448 | static void test_event_rule_userspace_probe(void) |
dbc20d3c JR |
449 | { |
450 | struct lttng_event_rule *uprobe = NULL; | |
451 | struct lttng_event_rule *uprobe_from_buffer = NULL; | |
452 | struct lttng_userspace_probe_location_lookup_method *lookup_method = | |
453 | NULL; | |
454 | struct lttng_userspace_probe_location *probe_location = NULL; | |
455 | const struct lttng_userspace_probe_location *probe_location_tmp = NULL; | |
456 | enum lttng_event_rule_status status; | |
457 | ||
458 | const char *probe_name = "my_probe."; | |
459 | const char *tmp; | |
460 | struct lttng_payload payload; | |
461 | ||
462 | diag("Event rule uprobe."); | |
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 | ||
46fd07ac | 484 | uprobe = lttng_event_rule_kernel_uprobe_create(probe_location); |
dbc20d3c JR |
485 | ok(uprobe, "uprobe event rule object creation."); |
486 | ||
46fd07ac | 487 | status = lttng_event_rule_kernel_uprobe_get_location( |
dbc20d3c JR |
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 | ||
46fd07ac | 495 | status = lttng_event_rule_kernel_uprobe_set_event_name(uprobe, probe_name); |
dbc20d3c JR |
496 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, |
497 | "Setting uprobe event rule name: %s.", probe_name); | |
46fd07ac | 498 | status = lttng_event_rule_kernel_uprobe_get_event_name(uprobe, &tmp); |
dbc20d3c JR |
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 | ||
f2791161 | 525 | static void test_event_rule_kernel_probe_by_location( |
dbc20d3c JR |
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 | ||
85522de5 | 542 | kprobe = lttng_event_rule_kernel_kprobe_create(location); |
dbc20d3c JR |
543 | ok(kprobe, "kprobe event rule object creation."); |
544 | ||
85522de5 | 545 | status = lttng_event_rule_kernel_kprobe_get_location(kprobe, &_location); |
dbc20d3c JR |
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 | ||
85522de5 | 550 | status = lttng_event_rule_kernel_kprobe_set_event_name(kprobe, probe_name); |
dbc20d3c JR |
551 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, |
552 | "Setting kprobe event rule name: %s.", probe_name); | |
85522de5 | 553 | status = lttng_event_rule_kernel_kprobe_get_event_name(kprobe, &tmp); |
dbc20d3c JR |
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 | ||
f2791161 | 577 | static void test_event_rule_kernel_probe(void) |
dbc20d3c JR |
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 | assert(address_location); | |
585 | assert(symbol_location); | |
586 | ||
f2791161 JR |
587 | test_event_rule_kernel_probe_by_location(address_location); |
588 | test_event_rule_kernel_probe_by_location(symbol_location); | |
dbc20d3c JR |
589 | |
590 | lttng_kernel_probe_location_destroy(address_location); | |
591 | lttng_kernel_probe_location_destroy(symbol_location); | |
592 | } | |
593 | ||
2b4c142d JG |
594 | static void test_set_event_rule_log_level_rules( |
595 | struct lttng_event_rule *event_rule, | |
cade690d | 596 | event_rule_set_log_level set_log_level, |
2b4c142d JG |
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 | assert(log_level_rule); | |
606 | ||
cade690d | 607 | *as_severe_status = set_log_level( |
2b4c142d JG |
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 | assert(log_level_rule); | |
613 | ||
cade690d | 614 | *exactly_status = set_log_level( |
2b4c142d JG |
615 | event_rule, log_level_rule); |
616 | lttng_log_level_rule_destroy(log_level_rule); | |
617 | } | |
618 | ||
cade690d | 619 | static void test_event_rule_log_level_generic(enum lttng_event_rule_type event_rule_type, |
2b4c142d | 620 | log_level_name_getter get_log_level_name, |
cade690d JR |
621 | event_rule_create create_event_rule, |
622 | event_rule_set_log_level set_log_level, | |
2b4c142d JG |
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; | |
cade690d | 631 | struct lttng_event_rule *rule; |
2b4c142d | 632 | enum lttng_event_rule_status er_exactly_status, er_as_severe_status; |
cade690d JR |
633 | const char *event_rule_type_str = lttng_event_rule_type_str(event_rule_type); |
634 | ||
2b4c142d | 635 | |
cade690d JR |
636 | diag("Test %s event rule + log level rule", event_rule_type_str); |
637 | ||
638 | rule = create_event_rule(); | |
639 | assert(rule); | |
2b4c142d JG |
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 | ||
cade690d | 644 | test_set_event_rule_log_level_rules(rule, set_log_level, |
2b4c142d JG |
645 | tagged_log_level_value, |
646 | &er_exactly_status, &er_as_severe_status); | |
647 | ok(er_exactly_status == LTTNG_EVENT_RULE_STATUS_OK, | |
cade690d JR |
648 | "Log level rule \"exactly\" accepted by %s event rule: level = %s", |
649 | event_rule_type_str, | |
2b4c142d JG |
650 | get_log_level_name( |
651 | tagged_log_level_value)); | |
652 | ok(er_as_severe_status == LTTNG_EVENT_RULE_STATUS_OK, | |
cade690d JR |
653 | "Log level rule \"as least as severe as\" accepted by %s event rule: level = %s", |
654 | event_rule_type_str, | |
2b4c142d JG |
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 | ||
cade690d | 662 | test_set_event_rule_log_level_rules(rule, set_log_level, |
2b4c142d JG |
663 | valid_log_level_value, |
664 | &er_exactly_status, &er_as_severe_status); | |
665 | ok(er_exactly_status == LTTNG_EVENT_RULE_STATUS_OK, | |
cade690d JR |
666 | "Log level rule \"exactly\" accepted by %s event rule: level = %d", |
667 | event_rule_type_str, | |
2b4c142d JG |
668 | valid_log_level_value); |
669 | ok(er_as_severe_status == LTTNG_EVENT_RULE_STATUS_OK, | |
cade690d JR |
670 | "Log level rule \"as least as severe as\" accepted by %s event rule: level = %d", |
671 | event_rule_type_str, | |
2b4c142d JG |
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 | ||
cade690d | 678 | test_set_event_rule_log_level_rules(rule, set_log_level, |
2b4c142d JG |
679 | invalid_log_level_value, |
680 | &er_exactly_status, &er_as_severe_status); | |
681 | ok(er_exactly_status == LTTNG_EVENT_RULE_STATUS_INVALID, | |
cade690d JR |
682 | "Log level rule \"exactly\" rejected by %s event rule: level = %d", |
683 | event_rule_type_str, | |
2b4c142d JG |
684 | invalid_log_level_value); |
685 | ok(er_as_severe_status == LTTNG_EVENT_RULE_STATUS_INVALID, | |
cade690d JR |
686 | "Log level rule \"as least as severe as\" rejected by %s event rule: level = %d", |
687 | event_rule_type_str, | |
2b4c142d JG |
688 | invalid_log_level_value); |
689 | } | |
690 | ||
cade690d | 691 | lttng_event_rule_destroy(rule); |
2b4c142d JG |
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 | ||
cade690d JR |
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, | |
2b4c142d JG |
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 | ||
cade690d JR |
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, | |
2b4c142d JG |
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 | ||
cade690d JR |
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, | |
2b4c142d JG |
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 | ||
cade690d JR |
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, | |
2b4c142d JG |
809 | ARRAY_SIZE(tagged_log_level_values), |
810 | valid_log_level_values, | |
811 | ARRAY_SIZE(valid_log_level_values), | |
812 | NULL, 0); | |
813 | } | |
814 | ||
dbc20d3c JR |
815 | int main(int argc, const char *argv[]) |
816 | { | |
817 | plan_tests(NUM_TESTS); | |
af0818ef | 818 | test_event_rule_kernel_tracepoint(); |
0a23a07d | 819 | test_event_rule_user_tracepoint(); |
dbc20d3c | 820 | test_event_rule_syscall(); |
1f1567a5 | 821 | test_event_rule_userspace_probe(); |
f2791161 | 822 | test_event_rule_kernel_probe(); |
138d6838 | 823 | test_event_rule_log4j_logging(); |
b47b01d8 | 824 | test_event_rule_jul_logging(); |
6530ec7d | 825 | test_event_rule_python_logging(); |
2b4c142d JG |
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(); | |
dbc20d3c JR |
830 | return exit_status(); |
831 | } |