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> | |
a3c51653 JR |
21 | #include <lttng/event-rule/kernel-probe-internal.h> |
22 | #include <lttng/event-rule/kernel-probe.h> | |
dbc20d3c JR |
23 | #include <lttng/event-rule/syscall-internal.h> |
24 | #include <lttng/event-rule/syscall.h> | |
25 | #include <lttng/event-rule/tracepoint-internal.h> | |
26 | #include <lttng/event-rule/tracepoint.h> | |
e957bf98 JR |
27 | #include <lttng/event-rule/userspace-probe-internal.h> |
28 | #include <lttng/event-rule/userspace-probe.h> | |
dbc20d3c JR |
29 | #include <lttng/event.h> |
30 | #include <lttng/kernel-probe-internal.h> | |
31 | #include <lttng/kernel-probe.h> | |
32 | #include <lttng/userspace-probe-internal.h> | |
33 | #include <lttng/userspace-probe.h> | |
2b4c142d | 34 | #include "bin/lttng/loglevel.h" |
dbc20d3c JR |
35 | |
36 | /* For error.h. */ | |
37 | int lttng_opt_quiet = 1; | |
38 | int lttng_opt_verbose; | |
39 | int lttng_opt_mi; | |
40 | ||
2b4c142d | 41 | #define NUM_TESTS 246 |
dbc20d3c JR |
42 | |
43 | struct tracepoint_test { | |
44 | enum lttng_domain_type type; | |
975d26c5 | 45 | bool support_name_pattern_exclusion; |
dbc20d3c JR |
46 | }; |
47 | ||
2b4c142d JG |
48 | typedef const char *(*log_level_name_getter)(int log_level); |
49 | ||
dbc20d3c JR |
50 | static |
51 | void test_event_rule_tracepoint_by_domain(const struct tracepoint_test *test) | |
52 | { | |
dbc20d3c JR |
53 | unsigned int count; |
54 | struct lttng_event_rule *tracepoint = NULL; | |
55 | struct lttng_event_rule *tracepoint_from_buffer = NULL; | |
56 | enum lttng_event_rule_status status; | |
57 | enum lttng_domain_type domain_type, type; | |
dbc20d3c JR |
58 | const char *pattern="my_event_*"; |
59 | const char *filter="msg_id == 23 && size >= 2048"; | |
60 | const char *tmp; | |
975d26c5 | 61 | const char *name_pattern_exclusions[] = {"my_event_test1", "my_event_test2" ,"my_event_test3"}; |
85b05318 JR |
62 | struct lttng_log_level_rule *log_level_rule = NULL; |
63 | const struct lttng_log_level_rule *log_level_rule_return = NULL; | |
dbc20d3c JR |
64 | struct lttng_payload payload; |
65 | ||
66 | type = test->type; | |
67 | diag("Testing domain %d.", type); | |
68 | ||
69 | lttng_payload_init(&payload); | |
70 | ||
85b05318 JR |
71 | log_level_rule = lttng_log_level_rule_exactly_create(LTTNG_LOGLEVEL_INFO); |
72 | assert(log_level_rule); | |
73 | ||
dbc20d3c JR |
74 | tracepoint = lttng_event_rule_tracepoint_create(type); |
75 | ok(tracepoint, "tracepoint object."); | |
76 | ||
77 | status = lttng_event_rule_tracepoint_get_domain_type(tracepoint, &domain_type); | |
78 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "get tracepoint domain."); | |
79 | ok(domain_type == type, "domain type got %d expected %d.", domain_type, type); | |
80 | ||
8bc73626 | 81 | status = lttng_event_rule_tracepoint_set_name_pattern(tracepoint, pattern); |
dbc20d3c | 82 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); |
8bc73626 | 83 | status = lttng_event_rule_tracepoint_get_name_pattern(tracepoint, &tmp); |
dbc20d3c JR |
84 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); |
85 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
86 | ||
87 | status = lttng_event_rule_tracepoint_set_filter(tracepoint, filter); | |
88 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); | |
89 | status = lttng_event_rule_tracepoint_get_filter(tracepoint, &tmp); | |
90 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); | |
91 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
92 | ||
85b05318 JR |
93 | status = lttng_event_rule_tracepoint_get_log_level_rule(tracepoint, &log_level_rule_return); |
94 | ok(status == LTTNG_EVENT_RULE_STATUS_UNSET, "get unset log level rule."); | |
95 | ||
2b4c142d JG |
96 | if (type != LTTNG_DOMAIN_KERNEL) { |
97 | status = lttng_event_rule_tracepoint_set_log_level_rule(tracepoint, log_level_rule); | |
98 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting log level rule."); | |
99 | status = lttng_event_rule_tracepoint_get_log_level_rule(tracepoint, &log_level_rule_return); | |
100 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "get log level rule."); | |
101 | } | |
dbc20d3c | 102 | |
975d26c5 | 103 | if (test->support_name_pattern_exclusion) { |
dbc20d3c JR |
104 | int i; |
105 | ||
106 | for (i = 0; i < 3; i++) { | |
975d26c5 JR |
107 | status = lttng_event_rule_tracepoint_add_name_pattern_exclusion(tracepoint, name_pattern_exclusions[i]); |
108 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting name pattern exclusions \"%s\"", name_pattern_exclusions[i]); | |
dbc20d3c JR |
109 | } |
110 | ||
975d26c5 JR |
111 | status = lttng_event_rule_tracepoint_get_name_pattern_exclusion_count(tracepoint, &count); |
112 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting name pattern exclusion count."); | |
dbc20d3c JR |
113 | ok(count == 3, "count is %d/3", count); |
114 | ||
115 | for (i = 0; i < count; i++) { | |
975d26c5 JR |
116 | status = lttng_event_rule_tracepoint_get_name_pattern_exclusion_at_index(tracepoint, i, &tmp); |
117 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting name pattern exclusion at index %d.", i); | |
118 | ok(!strncmp(name_pattern_exclusions[i], tmp, strlen(name_pattern_exclusions[i])), "%s == %s.", tmp, name_pattern_exclusions[i]); | |
dbc20d3c JR |
119 | } |
120 | } else { | |
121 | int i; | |
122 | ||
123 | for (i = 0; i < 3; i++) { | |
975d26c5 JR |
124 | status = lttng_event_rule_tracepoint_add_name_pattern_exclusion(tracepoint, name_pattern_exclusions[i]); |
125 | ok(status == LTTNG_EVENT_RULE_STATUS_UNSUPPORTED, "setting name pattern exclusions unsupported \"%s\".", name_pattern_exclusions[i]); | |
dbc20d3c JR |
126 | } |
127 | ||
975d26c5 JR |
128 | status = lttng_event_rule_tracepoint_get_name_pattern_exclusion_count(tracepoint, &count); |
129 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting name pattern exclusion count."); | |
dbc20d3c JR |
130 | ok(count == 0, "count is %d/0", count); |
131 | } | |
132 | ||
133 | ok(lttng_event_rule_serialize(tracepoint, &payload) == 0, "Serializing."); | |
134 | ||
135 | { | |
136 | struct lttng_payload_view view = | |
137 | lttng_payload_view_from_payload( | |
138 | &payload, 0, -1); | |
139 | ||
140 | ok(lttng_event_rule_create_from_payload( | |
141 | &view, &tracepoint_from_buffer) > 0, | |
142 | "Deserializing."); | |
143 | } | |
144 | ||
145 | ok(lttng_event_rule_is_equal(tracepoint, tracepoint_from_buffer), "serialized and from buffer are equal."); | |
146 | ||
147 | lttng_payload_reset(&payload); | |
148 | lttng_event_rule_destroy(tracepoint); | |
149 | lttng_event_rule_destroy(tracepoint_from_buffer); | |
85b05318 | 150 | lttng_log_level_rule_destroy(log_level_rule); |
dbc20d3c JR |
151 | } |
152 | ||
153 | static | |
154 | void test_event_rule_tracepoint(void) | |
155 | { | |
156 | int i; | |
157 | struct lttng_event_rule *tracepoint = NULL; | |
158 | struct tracepoint_test tests[] = {{LTTNG_DOMAIN_JUL, false}, | |
159 | {LTTNG_DOMAIN_KERNEL, false}, | |
160 | {LTTNG_DOMAIN_LOG4J, false}, | |
161 | {LTTNG_DOMAIN_PYTHON, false}, | |
162 | {LTTNG_DOMAIN_UST, true}}; | |
163 | ||
164 | diag("Testing lttng_event_rule_tracepoint."); | |
165 | tracepoint = lttng_event_rule_tracepoint_create(LTTNG_DOMAIN_NONE); | |
166 | ok(!tracepoint, "Domain type restriction on create."); | |
167 | ||
168 | for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) { | |
169 | test_event_rule_tracepoint_by_domain(&tests[i]); | |
170 | } | |
171 | } | |
172 | ||
173 | static void test_event_rule_syscall(void) | |
174 | { | |
175 | struct lttng_event_rule *syscall = NULL; | |
176 | struct lttng_event_rule *syscall_from_buffer = NULL; | |
177 | enum lttng_event_rule_status status; | |
178 | const char *pattern = "my_event_*"; | |
179 | const char *filter = "msg_id == 23 && size >= 2048"; | |
180 | const char *tmp; | |
181 | struct lttng_payload payload; | |
182 | ||
183 | diag("Event rule syscall."); | |
184 | ||
185 | lttng_payload_init(&payload); | |
186 | ||
57739a6b | 187 | syscall = lttng_event_rule_syscall_create(LTTNG_EVENT_RULE_SYSCALL_EMISSION_SITE_ENTRY); |
dbc20d3c JR |
188 | ok(syscall, "syscall object."); |
189 | ||
b2eeb0d5 | 190 | status = lttng_event_rule_syscall_set_name_pattern(syscall, pattern); |
dbc20d3c | 191 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern."); |
b2eeb0d5 | 192 | status = lttng_event_rule_syscall_get_name_pattern(syscall, &tmp); |
dbc20d3c JR |
193 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting pattern."); |
194 | ok(!strncmp(pattern, tmp, strlen(pattern)), "pattern is equal."); | |
195 | ||
196 | status = lttng_event_rule_syscall_set_filter(syscall, filter); | |
197 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter."); | |
198 | status = lttng_event_rule_syscall_get_filter(syscall, &tmp); | |
199 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "getting filter."); | |
200 | ok(!strncmp(filter, tmp, strlen(filter)), "filter is equal."); | |
201 | ||
202 | ok(lttng_event_rule_serialize(syscall, &payload) == 0, "Serializing."); | |
203 | ||
204 | { | |
205 | struct lttng_payload_view view = | |
206 | lttng_payload_view_from_payload( | |
207 | &payload, 0, -1); | |
208 | ||
209 | ok(lttng_event_rule_create_from_payload( | |
210 | &view, &syscall_from_buffer) > 0, | |
211 | "Deserializing."); | |
212 | } | |
213 | ||
214 | ok(lttng_event_rule_is_equal(syscall, syscall_from_buffer), | |
215 | "serialized and from buffer are equal."); | |
216 | ||
217 | lttng_payload_reset(&payload); | |
218 | lttng_event_rule_destroy(syscall); | |
219 | lttng_event_rule_destroy(syscall_from_buffer); | |
220 | } | |
221 | ||
1f1567a5 | 222 | static void test_event_rule_userspace_probe(void) |
dbc20d3c JR |
223 | { |
224 | struct lttng_event_rule *uprobe = NULL; | |
225 | struct lttng_event_rule *uprobe_from_buffer = NULL; | |
226 | struct lttng_userspace_probe_location_lookup_method *lookup_method = | |
227 | NULL; | |
228 | struct lttng_userspace_probe_location *probe_location = NULL; | |
229 | const struct lttng_userspace_probe_location *probe_location_tmp = NULL; | |
230 | enum lttng_event_rule_status status; | |
231 | ||
232 | const char *probe_name = "my_probe."; | |
233 | const char *tmp; | |
234 | struct lttng_payload payload; | |
235 | ||
236 | diag("Event rule uprobe."); | |
237 | ||
238 | lookup_method = lttng_userspace_probe_location_lookup_method_function_elf_create(); | |
239 | if (!lookup_method) { | |
240 | fail("Setup error on userspace probe lookup method creation."); | |
241 | goto end; | |
242 | } | |
243 | ||
244 | probe_location = lttng_userspace_probe_location_function_create( | |
245 | "/proc/self/exe", | |
246 | "lttng_userspace_probe_location_tracepoint_create", | |
247 | lookup_method); | |
248 | if (!probe_location) { | |
249 | fail("Setup error on userspace probe location creation."); | |
250 | goto end; | |
251 | } | |
252 | ||
253 | /* Ownership transferred to the probe location function object. */ | |
254 | lookup_method = NULL; | |
255 | ||
256 | lttng_payload_init(&payload); | |
257 | ||
10685de6 | 258 | uprobe = lttng_event_rule_userspace_probe_create(probe_location); |
dbc20d3c JR |
259 | ok(uprobe, "uprobe event rule object creation."); |
260 | ||
1f1567a5 | 261 | status = lttng_event_rule_userspace_probe_get_location( |
dbc20d3c JR |
262 | uprobe, &probe_location_tmp); |
263 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, | |
264 | "Getting uprobe event rule location."); | |
265 | ok(lttng_userspace_probe_location_is_equal( | |
266 | probe_location, probe_location_tmp), | |
267 | "Location is equal."); | |
268 | ||
405f9e7d | 269 | status = lttng_event_rule_userspace_probe_set_event_name(uprobe, probe_name); |
dbc20d3c JR |
270 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, |
271 | "Setting uprobe event rule name: %s.", probe_name); | |
405f9e7d | 272 | status = lttng_event_rule_userspace_probe_get_event_name(uprobe, &tmp); |
dbc20d3c JR |
273 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "Getting uprobe name."); |
274 | ok(!strcmp(probe_name, tmp), "Uprobe name are equal."); | |
275 | ||
276 | ok(lttng_event_rule_serialize(uprobe, &payload) == 0, "Serializing."); | |
277 | ||
278 | { | |
279 | struct lttng_payload_view view = | |
280 | lttng_payload_view_from_payload( | |
281 | &payload, 0, -1); | |
282 | ||
283 | ok(lttng_event_rule_create_from_payload( | |
284 | &view, &uprobe_from_buffer) > 0, | |
285 | "Deserializing."); | |
286 | } | |
287 | ||
288 | ok(lttng_event_rule_is_equal(uprobe, uprobe_from_buffer), | |
289 | "serialized and from buffer are equal."); | |
290 | ||
291 | end: | |
292 | lttng_payload_reset(&payload); | |
293 | lttng_event_rule_destroy(uprobe); | |
294 | lttng_event_rule_destroy(uprobe_from_buffer); | |
295 | lttng_userspace_probe_location_destroy(probe_location); | |
296 | lttng_userspace_probe_location_lookup_method_destroy(lookup_method); | |
297 | } | |
298 | ||
f2791161 | 299 | static void test_event_rule_kernel_probe_by_location( |
dbc20d3c JR |
300 | const struct lttng_kernel_probe_location *location) |
301 | { | |
302 | struct lttng_event_rule *kprobe = NULL; | |
303 | struct lttng_event_rule *kprobe_from_buffer = NULL; | |
304 | enum lttng_event_rule_status status; | |
305 | const struct lttng_kernel_probe_location *_location; | |
306 | ||
307 | const char *probe_name = "my_probe"; | |
308 | const char *tmp; | |
309 | struct lttng_payload payload; | |
310 | ||
311 | diag("Event rule kprobe for location type %d.", | |
312 | lttng_kernel_probe_location_get_type(location)); | |
313 | ||
314 | lttng_payload_init(&payload); | |
315 | ||
602a6d40 | 316 | kprobe = lttng_event_rule_kernel_probe_create(location); |
dbc20d3c JR |
317 | ok(kprobe, "kprobe event rule object creation."); |
318 | ||
f2791161 | 319 | status = lttng_event_rule_kernel_probe_get_location(kprobe, &_location); |
dbc20d3c JR |
320 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, |
321 | "Getting kprobe event rule location."); | |
322 | ok(lttng_kernel_probe_location_is_equal(location, _location), "Locations are equal."); | |
323 | ||
d891bb52 | 324 | status = lttng_event_rule_kernel_probe_set_event_name(kprobe, probe_name); |
dbc20d3c JR |
325 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, |
326 | "Setting kprobe event rule name: %s.", probe_name); | |
d891bb52 | 327 | status = lttng_event_rule_kernel_probe_get_event_name(kprobe, &tmp); |
dbc20d3c JR |
328 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "Getting kprobe name."); |
329 | ok(!strcmp(probe_name, tmp), "kprobe name are equal."); | |
330 | ||
331 | ok(lttng_event_rule_serialize(kprobe, &payload) == 0, "Serializing."); | |
332 | ||
333 | { | |
334 | struct lttng_payload_view view = | |
335 | lttng_payload_view_from_payload( | |
336 | &payload, 0, -1); | |
337 | ||
338 | ok(lttng_event_rule_create_from_payload( | |
339 | &view, &kprobe_from_buffer) > 0, | |
340 | "Deserializing."); | |
341 | } | |
342 | ||
343 | ok(lttng_event_rule_is_equal(kprobe, kprobe_from_buffer), | |
344 | "serialized and from buffer are equal."); | |
345 | ||
346 | lttng_payload_reset(&payload); | |
347 | lttng_event_rule_destroy(kprobe); | |
348 | lttng_event_rule_destroy(kprobe_from_buffer); | |
349 | } | |
350 | ||
f2791161 | 351 | static void test_event_rule_kernel_probe(void) |
dbc20d3c JR |
352 | { |
353 | struct lttng_kernel_probe_location *address_location = NULL; | |
354 | struct lttng_kernel_probe_location *symbol_location = NULL; | |
355 | ||
356 | address_location = lttng_kernel_probe_location_address_create(50); | |
357 | symbol_location = lttng_kernel_probe_location_symbol_create("une_bonne", 50); | |
358 | assert(address_location); | |
359 | assert(symbol_location); | |
360 | ||
f2791161 JR |
361 | test_event_rule_kernel_probe_by_location(address_location); |
362 | test_event_rule_kernel_probe_by_location(symbol_location); | |
dbc20d3c JR |
363 | |
364 | lttng_kernel_probe_location_destroy(address_location); | |
365 | lttng_kernel_probe_location_destroy(symbol_location); | |
366 | } | |
367 | ||
2b4c142d JG |
368 | static void test_set_event_rule_log_level_rules( |
369 | struct lttng_event_rule *event_rule, | |
370 | int log_level, | |
371 | enum lttng_event_rule_status *exactly_status, | |
372 | enum lttng_event_rule_status *as_severe_status) | |
373 | { | |
374 | struct lttng_log_level_rule *log_level_rule; | |
375 | ||
376 | log_level_rule = lttng_log_level_rule_at_least_as_severe_as_create( | |
377 | log_level); | |
378 | assert(log_level_rule); | |
379 | ||
380 | *as_severe_status = lttng_event_rule_tracepoint_set_log_level_rule( | |
381 | event_rule, log_level_rule); | |
382 | lttng_log_level_rule_destroy(log_level_rule); | |
383 | ||
384 | log_level_rule = lttng_log_level_rule_exactly_create(log_level); | |
385 | assert(log_level_rule); | |
386 | ||
387 | *exactly_status = lttng_event_rule_tracepoint_set_log_level_rule( | |
388 | event_rule, log_level_rule); | |
389 | lttng_log_level_rule_destroy(log_level_rule); | |
390 | } | |
391 | ||
392 | static void test_event_rule_log_level_kernel(void) | |
393 | { | |
394 | struct lttng_event_rule *kernel_tracepoint_rule; | |
395 | enum lttng_event_rule_status er_exactly_status, er_as_severe_status; | |
396 | ||
397 | diag("Test kernel event rule + log level rule"); | |
398 | kernel_tracepoint_rule = | |
399 | lttng_event_rule_tracepoint_create(LTTNG_DOMAIN_KERNEL); | |
400 | assert(kernel_tracepoint_rule); | |
401 | ||
402 | test_set_event_rule_log_level_rules(kernel_tracepoint_rule, 0, &er_exactly_status, &er_as_severe_status); | |
403 | ok(er_exactly_status == LTTNG_EVENT_RULE_STATUS_UNSUPPORTED, | |
404 | "Log level rule \"exactly\" rejected by kernel tracepoint event rule (unsupported)"); | |
405 | ok(er_as_severe_status == LTTNG_EVENT_RULE_STATUS_UNSUPPORTED, | |
406 | "Log level rule \"at least as severe as\" rejected by kernel tracepoint event rule (unsupported)"); | |
407 | ||
408 | lttng_event_rule_destroy(kernel_tracepoint_rule); | |
409 | } | |
410 | ||
411 | static void test_event_rule_log_level_generic(const char *domain_name, | |
412 | enum lttng_domain_type domain, | |
413 | log_level_name_getter get_log_level_name, | |
414 | const int tagged_log_level_values[], | |
415 | size_t tagged_log_level_values_count, | |
416 | const int valid_log_level_values[], | |
417 | size_t valid_log_level_values_count, | |
418 | const int invalid_log_level_values[], | |
419 | size_t invalid_log_level_values_count) | |
420 | { | |
421 | size_t i; | |
422 | struct lttng_event_rule *tracepoint_rule; | |
423 | enum lttng_event_rule_status er_exactly_status, er_as_severe_status; | |
424 | ||
425 | diag("Test %s event rule + log level rule", domain_name); | |
426 | tracepoint_rule = lttng_event_rule_tracepoint_create(domain); | |
427 | assert(tracepoint_rule); | |
428 | ||
429 | for (i = 0; i < tagged_log_level_values_count; i++) { | |
430 | const int tagged_log_level_value = tagged_log_level_values[i]; | |
431 | ||
432 | test_set_event_rule_log_level_rules(tracepoint_rule, | |
433 | tagged_log_level_value, | |
434 | &er_exactly_status, &er_as_severe_status); | |
435 | ok(er_exactly_status == LTTNG_EVENT_RULE_STATUS_OK, | |
436 | "Log level rule \"exactly\" accepted by %s tracepoint event rule: level = %s", | |
437 | domain_name, | |
438 | get_log_level_name( | |
439 | tagged_log_level_value)); | |
440 | ok(er_as_severe_status == LTTNG_EVENT_RULE_STATUS_OK, | |
441 | "Log level rule \"as least as severe as\" accepted by %s tracepoint event rule: level = %s", | |
442 | domain_name, | |
443 | get_log_level_name( | |
444 | tagged_log_level_value)); | |
445 | } | |
446 | ||
447 | for (i = 0; i < valid_log_level_values_count; i++) { | |
448 | const int valid_log_level_value = valid_log_level_values[i]; | |
449 | ||
450 | test_set_event_rule_log_level_rules(tracepoint_rule, | |
451 | valid_log_level_value, | |
452 | &er_exactly_status, &er_as_severe_status); | |
453 | ok(er_exactly_status == LTTNG_EVENT_RULE_STATUS_OK, | |
454 | "Log level rule \"exactly\" accepted by %s tracepoint event rule: level = %d", | |
455 | domain_name, | |
456 | valid_log_level_value); | |
457 | ok(er_as_severe_status == LTTNG_EVENT_RULE_STATUS_OK, | |
458 | "Log level rule \"as least as severe as\" accepted by %s tracepoint event rule: level = %d", | |
459 | domain_name, | |
460 | valid_log_level_value); | |
461 | } | |
462 | ||
463 | for (i = 0; i < invalid_log_level_values_count; i++) { | |
464 | const int invalid_log_level_value = invalid_log_level_values[i]; | |
465 | ||
466 | test_set_event_rule_log_level_rules(tracepoint_rule, | |
467 | invalid_log_level_value, | |
468 | &er_exactly_status, &er_as_severe_status); | |
469 | ok(er_exactly_status == LTTNG_EVENT_RULE_STATUS_INVALID, | |
470 | "Log level rule \"exactly\" rejected by %s tracepoint event rule: level = %d", | |
471 | domain_name, | |
472 | invalid_log_level_value); | |
473 | ok(er_as_severe_status == LTTNG_EVENT_RULE_STATUS_INVALID, | |
474 | "Log level rule \"as least as severe as\" rejected by %s tracepoint event rule: level = %d", | |
475 | domain_name, | |
476 | invalid_log_level_value); | |
477 | } | |
478 | ||
479 | lttng_event_rule_destroy(tracepoint_rule); | |
480 | } | |
481 | ||
482 | static void test_event_rule_log_level_ust(void) | |
483 | { | |
484 | const int tagged_log_level_values[] = { | |
485 | LTTNG_LOGLEVEL_EMERG, | |
486 | LTTNG_LOGLEVEL_ALERT, | |
487 | LTTNG_LOGLEVEL_CRIT, | |
488 | LTTNG_LOGLEVEL_ERR, | |
489 | LTTNG_LOGLEVEL_WARNING, | |
490 | LTTNG_LOGLEVEL_NOTICE, | |
491 | LTTNG_LOGLEVEL_INFO, | |
492 | LTTNG_LOGLEVEL_DEBUG_SYSTEM, | |
493 | LTTNG_LOGLEVEL_DEBUG_PROGRAM, | |
494 | LTTNG_LOGLEVEL_DEBUG_PROCESS, | |
495 | LTTNG_LOGLEVEL_DEBUG_MODULE, | |
496 | LTTNG_LOGLEVEL_DEBUG_UNIT, | |
497 | LTTNG_LOGLEVEL_DEBUG_FUNCTION, | |
498 | LTTNG_LOGLEVEL_DEBUG_LINE, | |
499 | LTTNG_LOGLEVEL_DEBUG, | |
500 | }; | |
501 | const int invalid_log_level_values[] = { | |
502 | -1980, | |
503 | 1995, | |
504 | LTTNG_LOGLEVEL_DEBUG + 1, | |
505 | LTTNG_LOGLEVEL_EMERG - 1, | |
506 | }; | |
507 | ||
508 | test_event_rule_log_level_generic("user space", LTTNG_DOMAIN_UST, | |
509 | loglevel_value_to_name, tagged_log_level_values, | |
510 | ARRAY_SIZE(tagged_log_level_values), | |
511 | NULL, 0, | |
512 | invalid_log_level_values, | |
513 | ARRAY_SIZE(invalid_log_level_values)); | |
514 | } | |
515 | ||
516 | static void test_event_rule_log_level_jul(void) | |
517 | { | |
518 | const int tagged_log_level_values[] = { | |
519 | LTTNG_LOGLEVEL_JUL_OFF, | |
520 | LTTNG_LOGLEVEL_JUL_SEVERE, | |
521 | LTTNG_LOGLEVEL_JUL_WARNING, | |
522 | LTTNG_LOGLEVEL_JUL_INFO, | |
523 | LTTNG_LOGLEVEL_JUL_CONFIG, | |
524 | LTTNG_LOGLEVEL_JUL_FINE, | |
525 | LTTNG_LOGLEVEL_JUL_FINER, | |
526 | LTTNG_LOGLEVEL_JUL_FINEST, | |
527 | LTTNG_LOGLEVEL_JUL_ALL, | |
528 | }; | |
529 | const int valid_log_level_values[] = { | |
530 | 0, | |
531 | -1980, | |
532 | 1995 | |
533 | }; | |
534 | ||
535 | test_event_rule_log_level_generic("Java Util Logging", LTTNG_DOMAIN_JUL, | |
536 | loglevel_jul_value_to_name, tagged_log_level_values, | |
537 | ARRAY_SIZE(tagged_log_level_values), | |
538 | valid_log_level_values, | |
539 | ARRAY_SIZE(valid_log_level_values), NULL, 0); | |
540 | } | |
541 | ||
542 | static void test_event_rule_log_level_log4j(void) | |
543 | { | |
544 | const int tagged_log_level_values[] = { | |
545 | LTTNG_LOGLEVEL_LOG4J_OFF, | |
546 | LTTNG_LOGLEVEL_LOG4J_FATAL, | |
547 | LTTNG_LOGLEVEL_LOG4J_ERROR, | |
548 | LTTNG_LOGLEVEL_LOG4J_WARN, | |
549 | LTTNG_LOGLEVEL_LOG4J_INFO, | |
550 | LTTNG_LOGLEVEL_LOG4J_DEBUG, | |
551 | LTTNG_LOGLEVEL_LOG4J_TRACE, | |
552 | LTTNG_LOGLEVEL_LOG4J_ALL, | |
553 | }; | |
554 | const int valid_log_level_values[] = { | |
555 | 0 | |
556 | -1980, | |
557 | 1995 | |
558 | }; | |
559 | ||
560 | test_event_rule_log_level_generic("Log4j", LTTNG_DOMAIN_LOG4J, | |
561 | loglevel_log4j_value_to_name, tagged_log_level_values, | |
562 | ARRAY_SIZE(tagged_log_level_values), | |
563 | valid_log_level_values, | |
564 | ARRAY_SIZE(valid_log_level_values), NULL, 0); | |
565 | } | |
566 | ||
567 | static void test_event_rule_log_level_python(void) | |
568 | { | |
569 | const int tagged_log_level_values[] = { | |
570 | LTTNG_LOGLEVEL_PYTHON_CRITICAL, | |
571 | LTTNG_LOGLEVEL_PYTHON_ERROR, | |
572 | LTTNG_LOGLEVEL_PYTHON_WARNING, | |
573 | LTTNG_LOGLEVEL_PYTHON_INFO, | |
574 | LTTNG_LOGLEVEL_PYTHON_DEBUG, | |
575 | LTTNG_LOGLEVEL_PYTHON_NOTSET, | |
576 | }; | |
577 | const int valid_log_level_values[] = { | |
578 | 45, | |
579 | 35, | |
580 | 0, | |
581 | -657, | |
582 | }; | |
583 | ||
584 | test_event_rule_log_level_generic("Python", LTTNG_DOMAIN_PYTHON, | |
585 | loglevel_python_value_to_name, tagged_log_level_values, | |
586 | ARRAY_SIZE(tagged_log_level_values), | |
587 | valid_log_level_values, | |
588 | ARRAY_SIZE(valid_log_level_values), | |
589 | NULL, 0); | |
590 | } | |
591 | ||
dbc20d3c JR |
592 | int main(int argc, const char *argv[]) |
593 | { | |
594 | plan_tests(NUM_TESTS); | |
595 | test_event_rule_tracepoint(); | |
596 | test_event_rule_syscall(); | |
1f1567a5 | 597 | test_event_rule_userspace_probe(); |
f2791161 | 598 | test_event_rule_kernel_probe(); |
2b4c142d JG |
599 | test_event_rule_log_level_kernel(); |
600 | test_event_rule_log_level_ust(); | |
601 | test_event_rule_log_level_jul(); | |
602 | test_event_rule_log_level_log4j(); | |
603 | test_event_rule_log_level_python(); | |
dbc20d3c JR |
604 | return exit_status(); |
605 | } |