Commit | Line | Data |
---|---|---|
434f8068 JR |
1 | /* |
2 | * notification.c | |
3 | * | |
4 | * Tests suite for LTTng notification API | |
5 | * | |
6 | * Copyright (C) 2017 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> | |
7 | * | |
9d16b343 | 8 | * SPDX-License-Identifier: MIT |
434f8068 | 9 | * |
434f8068 JR |
10 | */ |
11 | ||
12 | #include <assert.h> | |
13 | #include <math.h> | |
14 | #include <stdbool.h> | |
15 | #include <stdio.h> | |
16 | #include <stdlib.h> | |
17 | #include <string.h> | |
18 | #include <unistd.h> | |
19 | #include <inttypes.h> | |
20 | #include <sys/types.h> | |
21 | #include <sys/stat.h> | |
22 | #include <fcntl.h> | |
854382b8 JR |
23 | #include <signal.h> |
24 | #include <errno.h> | |
25 | #include <poll.h> | |
434f8068 JR |
26 | |
27 | #include <lttng/action/action.h> | |
28 | #include <lttng/action/notify.h> | |
29 | #include <lttng/condition/buffer-usage.h> | |
30 | #include <lttng/condition/condition.h> | |
31 | #include <lttng/condition/evaluation.h> | |
32 | #include <lttng/domain.h> | |
33 | #include <lttng/endpoint.h> | |
34 | #include <lttng/lttng-error.h> | |
35 | #include <lttng/notification/channel.h> | |
36 | #include <lttng/notification/notification.h> | |
37 | #include <lttng/trigger/trigger.h> | |
25040abc | 38 | #include <lttng/lttng.h> |
434f8068 JR |
39 | |
40 | #include <tap/tap.h> | |
41 | ||
42 | #define NUM_TESTS 104 | |
854382b8 | 43 | |
434f8068 JR |
44 | int nb_args = 0; |
45 | int named_pipe_args_start = 0; | |
854382b8 JR |
46 | pid_t app_pid = -1; |
47 | const char *app_state_file = NULL; | |
48 | ||
49 | static | |
50 | void wait_on_file(const char *path, bool file_exist) | |
51 | { | |
52 | if (!path) { | |
53 | return; | |
54 | } | |
55 | for (;;) { | |
56 | int ret; | |
57 | struct stat buf; | |
58 | ||
59 | ret = stat(path, &buf); | |
60 | if (ret == -1 && errno == ENOENT) { | |
61 | if (file_exist) { | |
62 | (void) poll(NULL, 0, 10); /* 10 ms delay */ | |
63 | continue; /* retry */ | |
64 | } | |
65 | break; /* File does not exist */ | |
66 | } | |
67 | if (ret) { | |
68 | perror("stat"); | |
69 | exit(EXIT_FAILURE); | |
70 | } | |
71 | break; /* found */ | |
72 | } | |
73 | } | |
434f8068 JR |
74 | |
75 | int write_pipe(const char *path, uint8_t data) | |
76 | { | |
77 | int ret = 0; | |
78 | int fd = 0; | |
79 | ||
80 | fd = open(path, O_WRONLY | O_NONBLOCK); | |
81 | if (fd < 0) { | |
82 | perror("Could not open consumer control named pipe"); | |
83 | goto end; | |
84 | } | |
85 | ||
86 | ret = write(fd, &data , sizeof(data)); | |
87 | if (ret < 1) { | |
88 | perror("Named pipe write failed"); | |
eff748d0 JR |
89 | if (close(fd)) { |
90 | perror("Named pipe close failed"); | |
91 | } | |
434f8068 JR |
92 | ret = -1; |
93 | goto end; | |
94 | } | |
95 | ||
96 | ret = close(fd); | |
97 | if (ret < 0) { | |
98 | perror("Name pipe closing failed"); | |
99 | ret = -1; | |
100 | goto end; | |
101 | } | |
102 | end: | |
103 | return ret; | |
104 | } | |
105 | ||
106 | int stop_consumer(const char **argv) | |
107 | { | |
108 | int ret = 0; | |
109 | for (int i = named_pipe_args_start; i < nb_args; i++) { | |
110 | ret = write_pipe(argv[i], 49); | |
111 | } | |
112 | return ret; | |
113 | } | |
114 | ||
115 | int resume_consumer(const char **argv) | |
116 | { | |
117 | int ret = 0; | |
118 | for (int i = named_pipe_args_start; i < nb_args; i++) { | |
119 | ret = write_pipe(argv[i], 0); | |
120 | } | |
121 | return ret; | |
122 | } | |
123 | ||
854382b8 JR |
124 | int suspend_application() |
125 | { | |
126 | int ret; | |
127 | struct stat buf; | |
128 | ||
129 | if (!stat(app_state_file, &buf)) { | |
130 | fail("App is already in a suspended state."); | |
131 | ret = -1; | |
132 | goto error; | |
133 | } | |
134 | ||
135 | /* | |
136 | * Send SIGUSR1 to application instructing it to bypass tracepoint. | |
137 | */ | |
138 | ret = kill(app_pid, SIGUSR1); | |
139 | if (ret) { | |
140 | fail("SIGUSR1 failed. errno %d", errno); | |
141 | ret = -1; | |
142 | goto error; | |
143 | } | |
144 | ||
145 | wait_on_file(app_state_file, true); | |
146 | ||
147 | error: | |
148 | return ret; | |
149 | ||
150 | } | |
151 | ||
152 | int resume_application() | |
153 | { | |
154 | int ret; | |
155 | struct stat buf; | |
156 | ||
157 | ret = stat(app_state_file, &buf); | |
158 | if (ret == -1 && errno == ENOENT) { | |
159 | fail("State file does not exist"); | |
160 | goto error; | |
161 | } | |
162 | if (ret) { | |
163 | perror("stat"); | |
164 | goto error; | |
165 | } | |
166 | ||
167 | ret = kill(app_pid, SIGUSR1); | |
168 | if (ret) { | |
169 | fail("SIGUSR1 failed. errno %d", errno); | |
170 | ret = -1; | |
171 | goto error; | |
172 | } | |
173 | ||
174 | wait_on_file(app_state_file, false); | |
175 | ||
176 | error: | |
177 | return ret; | |
178 | ||
179 | } | |
180 | ||
181 | ||
434f8068 JR |
182 | void test_triggers_buffer_usage_condition(const char *session_name, |
183 | const char *channel_name, | |
184 | enum lttng_domain_type domain_type, | |
185 | enum lttng_condition_type condition_type) | |
186 | { | |
187 | enum lttng_condition_status condition_status; | |
188 | struct lttng_action *action; | |
189 | ||
190 | /* Set-up */ | |
191 | action = lttng_action_notify_create(); | |
192 | if (!action) { | |
193 | fail("Setup error on action creation"); | |
194 | goto end; | |
195 | } | |
196 | ||
197 | /* Test lttng_register_trigger with null value */ | |
198 | ok(lttng_register_trigger(NULL) == -LTTNG_ERR_INVALID, "Registering a NULL trigger fails as expected"); | |
199 | ||
200 | /* Test: register a trigger */ | |
201 | unsigned int test_vector_size = 5; | |
202 | for (unsigned int i = 0; i < pow(2,test_vector_size); i++) { | |
203 | int loop_ret = 0; | |
204 | char *test_tuple_string = NULL; | |
205 | unsigned int mask_position = 0; | |
206 | bool session_name_set = false; | |
207 | bool channel_name_set = false; | |
208 | bool threshold_ratio_set = false; | |
209 | bool threshold_byte_set = false; | |
210 | bool domain_type_set = false; | |
211 | ||
212 | struct lttng_trigger *trigger = NULL; | |
213 | struct lttng_condition *condition = NULL; | |
214 | ||
215 | /* Create base condition */ | |
216 | switch (condition_type) { | |
217 | case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW: | |
218 | condition = lttng_condition_buffer_usage_low_create(); | |
219 | break; | |
220 | case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH: | |
221 | condition = lttng_condition_buffer_usage_high_create(); | |
222 | break; | |
223 | default: | |
224 | loop_ret = 1; | |
225 | goto loop_end; | |
226 | } | |
227 | ||
228 | if (!condition) { | |
229 | loop_ret = 1; | |
230 | goto loop_end; | |
231 | ||
232 | } | |
233 | ||
234 | /* Prepare the condition for trigger registration test */ | |
235 | ||
236 | /* Set session name */ | |
237 | if ((1 << mask_position) & i) { | |
238 | condition_status = lttng_condition_buffer_usage_set_session_name( | |
239 | condition, session_name); | |
240 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
241 | loop_ret = 1; | |
242 | goto loop_end; | |
243 | } | |
244 | session_name_set = true; | |
245 | } | |
246 | mask_position++; | |
247 | ||
248 | /* Set channel name */ | |
249 | if ((1 << mask_position) & i) { | |
250 | condition_status = lttng_condition_buffer_usage_set_channel_name( | |
251 | condition, channel_name); | |
252 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
253 | loop_ret = 1; | |
254 | goto loop_end; | |
255 | } | |
256 | channel_name_set = true; | |
257 | } | |
258 | mask_position++; | |
259 | ||
260 | /* Set threshold ratio */ | |
261 | if ((1 << mask_position) & i) { | |
262 | condition_status = lttng_condition_buffer_usage_set_threshold_ratio( | |
263 | condition, 0.0); | |
264 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
265 | loop_ret = 1; | |
266 | goto loop_end; | |
267 | } | |
268 | threshold_ratio_set = true; | |
269 | } | |
270 | mask_position++; | |
271 | ||
272 | /* Set threshold byte */ | |
273 | if ((1 << mask_position) & i) { | |
274 | condition_status = lttng_condition_buffer_usage_set_threshold( | |
275 | condition, 0); | |
276 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
277 | loop_ret = 1; | |
278 | goto loop_end; | |
279 | } | |
280 | threshold_byte_set = true; | |
281 | } | |
282 | mask_position++; | |
283 | ||
284 | /* Set domain type */ | |
285 | if ((1 << mask_position) & i) { | |
286 | condition_status = lttng_condition_buffer_usage_set_domain_type( | |
287 | condition, LTTNG_DOMAIN_UST); | |
288 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
289 | loop_ret = 1; | |
290 | goto loop_end; | |
291 | } | |
292 | domain_type_set = true; | |
293 | } | |
294 | ||
295 | /* Safety check */ | |
296 | if (mask_position != test_vector_size -1) { | |
297 | assert("Logic error for test vector generation"); | |
298 | } | |
299 | ||
300 | loop_ret = asprintf(&test_tuple_string, "session name %s, channel name %s, threshold ratio %s, threshold byte %s, domain type %s", | |
301 | session_name_set ? "set" : "unset", | |
302 | channel_name_set ? "set" : "unset", | |
303 | threshold_ratio_set ? "set" : "unset", | |
304 | threshold_byte_set ? "set" : "unset", | |
305 | domain_type_set? "set" : "unset"); | |
306 | if (!test_tuple_string || loop_ret < 0) { | |
307 | loop_ret = 1; | |
308 | goto loop_end; | |
309 | } | |
310 | ||
311 | /* Create trigger */ | |
312 | trigger = lttng_trigger_create(condition, action); | |
313 | if (!trigger) { | |
314 | loop_ret = 1; | |
315 | goto loop_end; | |
316 | } | |
317 | ||
318 | loop_ret = lttng_register_trigger(trigger); | |
319 | ||
320 | loop_end: | |
321 | if (loop_ret == 1) { | |
322 | fail("Setup error occurred for tuple: %s", test_tuple_string); | |
323 | goto loop_cleanup; | |
324 | } | |
325 | ||
326 | /* This combination happens three times */ | |
327 | if (session_name_set && channel_name_set | |
328 | && (threshold_ratio_set || threshold_byte_set) | |
329 | && domain_type_set) { | |
330 | ok(loop_ret == 0, "Trigger is registered: %s", test_tuple_string); | |
331 | ||
332 | /* | |
333 | * Test that a trigger cannot be registered | |
334 | * multiple time. | |
335 | */ | |
336 | loop_ret = lttng_register_trigger(trigger); | |
337 | ok(loop_ret == -LTTNG_ERR_TRIGGER_EXISTS, "Re-register trigger fails as expected: %s", test_tuple_string); | |
338 | ||
339 | /* Test that a trigger can be unregistered */ | |
340 | loop_ret = lttng_unregister_trigger(trigger); | |
341 | ok(loop_ret == 0, "Unregister trigger: %s", test_tuple_string); | |
342 | ||
343 | /* | |
344 | * Test that unregistration of a non-previously | |
345 | * registered trigger fail. | |
346 | */ | |
347 | loop_ret = lttng_unregister_trigger(trigger); | |
348 | ok(loop_ret == -LTTNG_ERR_TRIGGER_NOT_FOUND, "Unregister of a non-registerd trigger fails as expected: %s", test_tuple_string); | |
349 | } else { | |
350 | ok(loop_ret == -LTTNG_ERR_INVALID_TRIGGER, "Trigger is invalid as expected and cannot be registered: %s", test_tuple_string); | |
351 | } | |
352 | ||
353 | loop_cleanup: | |
354 | free(test_tuple_string); | |
355 | lttng_trigger_destroy(trigger); | |
356 | lttng_condition_destroy(condition); | |
357 | } | |
358 | ||
359 | end: | |
360 | lttng_action_destroy(action); | |
361 | } | |
362 | ||
ff2b03c8 JG |
363 | static |
364 | void wait_data_pending(const char *session_name) | |
365 | { | |
366 | int ret; | |
367 | ||
368 | do { | |
369 | ret = lttng_data_pending(session_name); | |
370 | assert(ret >= 0); | |
371 | } while (ret != 0); | |
372 | } | |
373 | ||
854382b8 | 374 | void test_notification_channel(const char *session_name, const char *channel_name, const enum lttng_domain_type domain_type, const char **argv) |
434f8068 JR |
375 | { |
376 | int ret = 0; | |
377 | enum lttng_condition_status condition_status; | |
378 | enum lttng_notification_channel_status nc_status; | |
379 | ||
380 | struct lttng_action *action = NULL; | |
381 | struct lttng_notification *notification = NULL; | |
382 | struct lttng_notification_channel *notification_channel = NULL; | |
383 | struct lttng_trigger *trigger = NULL; | |
384 | ||
385 | struct lttng_condition *low_condition = NULL; | |
386 | struct lttng_condition *high_condition = NULL; | |
387 | struct lttng_condition *dummy_invalid_condition = NULL; | |
388 | struct lttng_condition *dummy_condition = NULL; | |
389 | ||
390 | double low_ratio = 0.0; | |
391 | double high_ratio = 0.99; | |
392 | ||
393 | /* Set-up */ | |
394 | action = lttng_action_notify_create(); | |
395 | if (!action) { | |
396 | fail("Setup error on action creation"); | |
397 | goto end; | |
398 | } | |
399 | ||
400 | /* Create a dummy, empty condition for later test */ | |
401 | dummy_invalid_condition = lttng_condition_buffer_usage_low_create(); | |
402 | if (!dummy_invalid_condition) { | |
403 | fail("Setup error on condition creation"); | |
404 | goto end; | |
405 | } | |
406 | ||
407 | /* Create a valid dummy condition with a ratio of 0.5 */ | |
408 | dummy_condition = lttng_condition_buffer_usage_low_create(); | |
409 | if (!dummy_condition) { | |
410 | fail("Setup error on dummy_condition creation"); | |
411 | goto end; | |
412 | ||
413 | } | |
414 | condition_status = lttng_condition_buffer_usage_set_threshold_ratio( | |
415 | dummy_condition, 0.5); | |
416 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
417 | fail("Setup error on condition creation"); | |
418 | goto end; | |
419 | } | |
420 | ||
421 | condition_status = lttng_condition_buffer_usage_set_session_name( | |
422 | dummy_condition, session_name); | |
423 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
424 | fail("Setup error on dummy_condition creation"); | |
425 | goto end; | |
426 | } | |
427 | condition_status = lttng_condition_buffer_usage_set_channel_name( | |
428 | dummy_condition, channel_name); | |
429 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
430 | fail("Setup error on dummy_condition creation"); | |
431 | goto end; | |
432 | } | |
433 | condition_status = lttng_condition_buffer_usage_set_domain_type( | |
434 | dummy_condition, domain_type); | |
435 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
436 | fail("Setup error on dummy_condition creation"); | |
437 | goto end; | |
438 | } | |
439 | ||
440 | /* Register a low condition with a ratio */ | |
441 | low_condition = lttng_condition_buffer_usage_low_create(); | |
442 | if (!low_condition) { | |
443 | fail("Setup error on low_condition creation"); | |
444 | goto end; | |
445 | } | |
446 | condition_status = lttng_condition_buffer_usage_set_threshold_ratio( | |
447 | low_condition, low_ratio); | |
448 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
449 | fail("Setup error on low_condition creation"); | |
450 | goto end; | |
451 | } | |
452 | ||
453 | condition_status = lttng_condition_buffer_usage_set_session_name( | |
454 | low_condition, session_name); | |
455 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
456 | fail("Setup error on low_condition creation"); | |
457 | goto end; | |
458 | } | |
459 | condition_status = lttng_condition_buffer_usage_set_channel_name( | |
460 | low_condition, channel_name); | |
461 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
462 | fail("Setup error on low_condition creation"); | |
463 | goto end; | |
464 | } | |
465 | condition_status = lttng_condition_buffer_usage_set_domain_type( | |
466 | low_condition, domain_type); | |
467 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
468 | fail("Setup error on low_condition creation"); | |
469 | goto end; | |
470 | ||
471 | } | |
472 | ||
473 | /* Register a high condition with a ratio */ | |
474 | high_condition = lttng_condition_buffer_usage_high_create(); | |
475 | if (!high_condition) { | |
476 | fail("Setup error on high_condition creation"); | |
477 | goto end; | |
478 | } | |
479 | ||
480 | condition_status = lttng_condition_buffer_usage_set_threshold_ratio( | |
481 | high_condition, high_ratio); | |
482 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
483 | fail("Setup error on high_condition creation"); | |
484 | goto end; | |
485 | } | |
486 | ||
487 | condition_status = lttng_condition_buffer_usage_set_session_name( | |
488 | high_condition, session_name); | |
489 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
490 | fail("Setup error on high_condition creation"); | |
491 | goto end; | |
492 | } | |
493 | condition_status = lttng_condition_buffer_usage_set_channel_name( | |
494 | high_condition, channel_name); | |
495 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
496 | fail("Setup error on high_condition creation"); | |
497 | goto end; | |
498 | } | |
499 | condition_status = lttng_condition_buffer_usage_set_domain_type( | |
500 | high_condition, domain_type); | |
501 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
502 | fail("Setup error on high_condition creation"); | |
503 | goto end; | |
504 | } | |
505 | ||
506 | /* Register the triggers for low and high condition */ | |
507 | trigger = lttng_trigger_create(low_condition, action); | |
508 | if (!trigger) { | |
509 | fail("Setup error on low trigger creation"); | |
510 | goto end; | |
511 | } | |
512 | ||
513 | ret = lttng_register_trigger(trigger); | |
514 | if (ret) { | |
515 | fail("Setup error on low trigger registration"); | |
516 | goto end; | |
517 | } | |
518 | ||
519 | lttng_trigger_destroy(trigger); | |
520 | trigger = NULL; | |
521 | ||
522 | trigger = lttng_trigger_create(high_condition, action); | |
523 | if (!trigger) { | |
524 | fail("Setup error on high trigger creation"); | |
525 | goto end; | |
526 | } | |
527 | ||
528 | ret = lttng_register_trigger(trigger); | |
529 | if (ret) { | |
530 | fail("Setup error on high trigger registration"); | |
531 | goto end; | |
532 | } | |
533 | ||
534 | /* Begin testing */ | |
535 | notification_channel = lttng_notification_channel_create(lttng_session_daemon_notification_endpoint); | |
536 | ok(notification_channel, "Notification channel object creation"); | |
537 | if (!notification_channel) { | |
538 | goto end; | |
539 | } | |
540 | ||
541 | /* Basic error path check */ | |
542 | nc_status = lttng_notification_channel_subscribe(NULL, NULL); | |
543 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID, "Notification channel subscription is invalid: NULL, NULL"); | |
544 | ||
545 | nc_status = lttng_notification_channel_subscribe(notification_channel, NULL); | |
546 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID, "Notification channel subscription is invalid: NON-NULL, NULL"); | |
547 | ||
548 | nc_status = lttng_notification_channel_subscribe(NULL, low_condition); | |
549 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID, "Notification channel subscription is invalid: NULL, NON-NULL"); | |
550 | ||
551 | nc_status = lttng_notification_channel_subscribe(notification_channel, dummy_invalid_condition); | |
552 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID, "Subscribing to an invalid condition"); | |
553 | ||
554 | nc_status = lttng_notification_channel_unsubscribe(notification_channel, dummy_invalid_condition); | |
a5fcfec4 | 555 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID, "Unsubscribing from an invalid condition"); |
434f8068 JR |
556 | |
557 | nc_status = lttng_notification_channel_unsubscribe(notification_channel, dummy_condition); | |
a5fcfec4 | 558 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION, "Unsubscribing from a valid unknown condition"); |
434f8068 JR |
559 | |
560 | /* Subscribe a valid low condition */ | |
561 | nc_status = lttng_notification_channel_subscribe(notification_channel, low_condition); | |
562 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, "Subscribe to condition"); | |
563 | ||
564 | /* Subscribe a valid high condition */ | |
565 | nc_status = lttng_notification_channel_subscribe(notification_channel, high_condition); | |
566 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, "Subscribe to condition"); | |
567 | ||
568 | nc_status = lttng_notification_channel_subscribe(notification_channel, low_condition); | |
569 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED, "Subscribe to a condition for which subscription was already done"); | |
570 | ||
571 | nc_status = lttng_notification_channel_subscribe(notification_channel, high_condition); | |
572 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED, "Subscribe to a condition for which subscription was already done"); | |
573 | ||
574 | /* Wait for notification to happen */ | |
434f8068 | 575 | stop_consumer(argv); |
ff2b03c8 | 576 | lttng_start_tracing(session_name); |
434f8068 JR |
577 | |
578 | /* Wait for high notification */ | |
579 | nc_status = lttng_notification_channel_get_next_notification(notification_channel, ¬ification); | |
580 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK | |
581 | && notification | |
582 | && lttng_condition_get_type(lttng_notification_get_condition(notification)) == LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH, | |
583 | "High notification received after intermediary communication"); | |
584 | lttng_notification_destroy(notification); | |
585 | notification = NULL; | |
586 | ||
854382b8 | 587 | suspend_application(); |
ff2b03c8 | 588 | lttng_stop_tracing_no_wait(session_name); |
434f8068 | 589 | resume_consumer(argv); |
ff2b03c8 | 590 | wait_data_pending(session_name); |
434f8068 JR |
591 | |
592 | /* | |
593 | * Test that communication still work even if there is notification | |
594 | * waiting for consumption. | |
595 | */ | |
596 | ||
597 | nc_status = lttng_notification_channel_unsubscribe(notification_channel, low_condition); | |
598 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, "Unsubscribe with pending notification"); | |
599 | ||
600 | nc_status = lttng_notification_channel_subscribe(notification_channel, low_condition); | |
601 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, "subscribe with pending notification"); | |
602 | ||
603 | nc_status = lttng_notification_channel_get_next_notification(notification_channel, ¬ification); | |
604 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK | |
605 | && notification | |
606 | && lttng_condition_get_type(lttng_notification_get_condition(notification)) == LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW, | |
607 | "Low notification received after intermediary communication"); | |
608 | lttng_notification_destroy(notification); | |
609 | notification = NULL; | |
610 | ||
611 | /* Stop consumer to force a high notification */ | |
ff2b03c8 | 612 | stop_consumer(argv); |
854382b8 | 613 | resume_application(); |
434f8068 | 614 | lttng_start_tracing(session_name); |
434f8068 JR |
615 | |
616 | nc_status = lttng_notification_channel_get_next_notification(notification_channel, ¬ification); | |
617 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK && notification && | |
618 | lttng_condition_get_type(lttng_notification_get_condition(notification)) == LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH, | |
619 | "High notification received after intermediary communication"); | |
620 | lttng_notification_destroy(notification); | |
621 | notification = NULL; | |
622 | ||
854382b8 | 623 | suspend_application(); |
ff2b03c8 | 624 | lttng_stop_tracing_no_wait(session_name); |
434f8068 | 625 | resume_consumer(argv); |
ff2b03c8 | 626 | wait_data_pending(session_name); |
434f8068 JR |
627 | |
628 | nc_status = lttng_notification_channel_get_next_notification(notification_channel, ¬ification); | |
629 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK && notification && | |
630 | lttng_condition_get_type(lttng_notification_get_condition(notification)) == LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW, | |
631 | "Low notification received after re-subscription"); | |
632 | lttng_notification_destroy(notification); | |
633 | notification = NULL; | |
634 | ||
ff2b03c8 | 635 | stop_consumer(argv); |
854382b8 | 636 | resume_application(); |
434f8068 JR |
637 | /* Stop consumer to force a high notification */ |
638 | lttng_start_tracing(session_name); | |
434f8068 JR |
639 | |
640 | nc_status = lttng_notification_channel_get_next_notification(notification_channel, ¬ification); | |
641 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK && notification && | |
642 | lttng_condition_get_type(lttng_notification_get_condition(notification)) == LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH, | |
643 | "High notification"); | |
644 | lttng_notification_destroy(notification); | |
645 | notification = NULL; | |
646 | ||
647 | /* Resume consumer to allow event consumption */ | |
ff2b03c8 JG |
648 | suspend_application(); |
649 | lttng_stop_tracing_no_wait(session_name); | |
434f8068 | 650 | resume_consumer(argv); |
ff2b03c8 | 651 | wait_data_pending(session_name); |
434f8068 JR |
652 | |
653 | nc_status = lttng_notification_channel_unsubscribe(notification_channel, low_condition); | |
654 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, "Unsubscribe low condition with pending notification"); | |
655 | nc_status = lttng_notification_channel_unsubscribe(notification_channel, high_condition); | |
656 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, "Unsubscribe high condition with pending notification"); | |
657 | ||
658 | end: | |
659 | lttng_notification_channel_destroy(notification_channel); | |
660 | lttng_trigger_destroy(trigger); | |
661 | lttng_action_destroy(action); | |
662 | lttng_condition_destroy(low_condition); | |
eff748d0 | 663 | lttng_condition_destroy(high_condition); |
434f8068 JR |
664 | lttng_condition_destroy(dummy_invalid_condition); |
665 | lttng_condition_destroy(dummy_condition); | |
666 | } | |
667 | ||
668 | int main(int argc, const char *argv[]) | |
669 | { | |
670 | const char *session_name = NULL; | |
671 | const char *channel_name = NULL; | |
672 | const char *domain_type_string = NULL; | |
673 | enum lttng_domain_type domain_type = LTTNG_DOMAIN_NONE; | |
674 | ||
675 | plan_tests(NUM_TESTS); | |
676 | ||
854382b8 JR |
677 | /* Argument 6 and upward are named pipe location for consumerd control */ |
678 | named_pipe_args_start = 6; | |
434f8068 | 679 | |
854382b8 | 680 | if (argc < 7) { |
434f8068 JR |
681 | fail("Missing parameter for tests to run %d", argc); |
682 | goto error; | |
683 | } | |
684 | ||
685 | nb_args = argc; | |
686 | ||
854382b8 JR |
687 | domain_type_string = argv[1]; |
688 | session_name = argv[2]; | |
689 | channel_name = argv[3]; | |
690 | app_pid = (pid_t) atoi(argv[4]); | |
691 | app_state_file = argv[5]; | |
434f8068 JR |
692 | |
693 | if (!strcmp("LTTNG_DOMAIN_UST", domain_type_string)) { | |
694 | domain_type = LTTNG_DOMAIN_UST; | |
695 | } | |
696 | if (!strcmp("LTTNG_DOMAIN_KERNEL", domain_type_string)) { | |
697 | domain_type = LTTNG_DOMAIN_KERNEL; | |
698 | } | |
699 | if (domain_type == LTTNG_DOMAIN_NONE) { | |
700 | fail("Unknown domain type"); | |
701 | goto error; | |
702 | } | |
703 | ||
704 | diag("Test trigger for domain %s with buffer_usage_low condition", domain_type_string); | |
705 | test_triggers_buffer_usage_condition(session_name, channel_name, domain_type, LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW); | |
706 | diag("Test trigger for domain %s with buffer_usage_high condition", domain_type_string); | |
707 | test_triggers_buffer_usage_condition(session_name, channel_name, domain_type, LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH); | |
708 | ||
709 | diag("Test notification channel api for domain %s", domain_type_string); | |
710 | test_notification_channel(session_name, channel_name, domain_type, argv); | |
711 | error: | |
712 | return exit_status(); | |
713 | } | |
714 |