Tests: Cleanup: notification: `assert()` that `app_pid` is set
[lttng-tools.git] / tests / regression / tools / notification / notification.c
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 *
8 * SPDX-License-Identifier: MIT
9 *
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>
23 #include <signal.h>
24 #include <poll.h>
25
26 #include <common/compat/errno.h>
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>
38 #include <lttng/lttng.h>
39
40 #include <tap/tap.h>
41
42 #define NUM_TESTS 104
43
44 int nb_args = 0;
45 int named_pipe_args_start = 0;
46 pid_t app_pid = 0;
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 /*
63 * The file does not exist. wait a bit and
64 * continue looping until it does.
65 */
66 (void) poll(NULL, 0, 10);
67 continue;
68 }
69
70 /*
71 * File does not exist and the exit condition we want.
72 * Break from the loop and return.
73 */
74 break;
75 }
76 if (ret) {
77 perror("stat");
78 exit(EXIT_FAILURE);
79 }
80 /*
81 * stat() returned 0, so the file exists. break now only if
82 * that's the exit condition we want.
83 */
84 if (file_exist) {
85 break;
86 }
87 }
88 }
89
90 static
91 int write_pipe(const char *path, uint8_t data)
92 {
93 int ret = 0;
94 int fd = 0;
95
96 fd = open(path, O_WRONLY | O_NONBLOCK);
97 if (fd < 0) {
98 perror("Could not open consumer control named pipe");
99 goto end;
100 }
101
102 ret = write(fd, &data , sizeof(data));
103 if (ret < 1) {
104 perror("Named pipe write failed");
105 if (close(fd)) {
106 perror("Named pipe close failed");
107 }
108 ret = -1;
109 goto end;
110 }
111
112 ret = close(fd);
113 if (ret < 0) {
114 perror("Name pipe closing failed");
115 ret = -1;
116 goto end;
117 }
118 end:
119 return ret;
120 }
121
122 static
123 int stop_consumer(const char **argv)
124 {
125 int ret = 0, i;
126
127 for (i = named_pipe_args_start; i < nb_args; i++) {
128 ret = write_pipe(argv[i], 49);
129 }
130 return ret;
131 }
132
133 static
134 int resume_consumer(const char **argv)
135 {
136 int ret = 0, i;
137
138 for (i = named_pipe_args_start; i < nb_args; i++) {
139 ret = write_pipe(argv[i], 0);
140 }
141 return ret;
142 }
143
144 static
145 int suspend_application(void)
146 {
147 int ret;
148 struct stat buf;
149
150 if (!stat(app_state_file, &buf)) {
151 fail("App is already in a suspended state.");
152 ret = -1;
153 goto error;
154 }
155
156 /*
157 * Send SIGUSR1 to application instructing it to bypass tracepoint.
158 */
159 assert(app_pid > 1);
160
161 ret = kill(app_pid, SIGUSR1);
162 if (ret) {
163 fail("SIGUSR1 failed. errno %d", errno);
164 ret = -1;
165 goto error;
166 }
167
168 wait_on_file(app_state_file, true);
169
170 error:
171 return ret;
172
173 }
174
175 static
176 int resume_application(void)
177 {
178 int ret;
179 struct stat buf;
180
181 ret = stat(app_state_file, &buf);
182 if (ret == -1 && errno == ENOENT) {
183 fail("State file does not exist");
184 goto error;
185 }
186 if (ret) {
187 perror("stat");
188 goto error;
189 }
190
191 assert(app_pid > 1);
192
193 ret = kill(app_pid, SIGUSR1);
194 if (ret) {
195 fail("SIGUSR1 failed. errno %d", errno);
196 ret = -1;
197 goto error;
198 }
199
200 wait_on_file(app_state_file, false);
201
202 error:
203 return ret;
204
205 }
206
207
208 static
209 void test_triggers_buffer_usage_condition(const char *session_name,
210 const char *channel_name,
211 enum lttng_domain_type domain_type,
212 enum lttng_condition_type condition_type)
213 {
214 unsigned int test_vector_size = 5, i;
215 enum lttng_condition_status condition_status;
216 struct lttng_action *action;
217
218 /* Set-up */
219 action = lttng_action_notify_create();
220 if (!action) {
221 fail("Setup error on action creation");
222 goto end;
223 }
224
225 /* Test lttng_register_trigger with null value */
226 ok(lttng_register_trigger(NULL) == -LTTNG_ERR_INVALID, "Registering a NULL trigger fails as expected");
227
228 /* Test: register a trigger */
229
230 for (i = 0; i < pow(2,test_vector_size); i++) {
231 int loop_ret = 0;
232 char *test_tuple_string = NULL;
233 unsigned int mask_position = 0;
234 bool session_name_set = false;
235 bool channel_name_set = false;
236 bool threshold_ratio_set = false;
237 bool threshold_byte_set = false;
238 bool domain_type_set = false;
239
240 struct lttng_trigger *trigger = NULL;
241 struct lttng_condition *condition = NULL;
242
243 /* Create base condition */
244 switch (condition_type) {
245 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
246 condition = lttng_condition_buffer_usage_low_create();
247 break;
248 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
249 condition = lttng_condition_buffer_usage_high_create();
250 break;
251 default:
252 loop_ret = 1;
253 goto loop_end;
254 }
255
256 if (!condition) {
257 loop_ret = 1;
258 goto loop_end;
259
260 }
261
262 /* Prepare the condition for trigger registration test */
263
264 /* Set session name */
265 if ((1 << mask_position) & i) {
266 condition_status = lttng_condition_buffer_usage_set_session_name(
267 condition, session_name);
268 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
269 loop_ret = 1;
270 goto loop_end;
271 }
272 session_name_set = true;
273 }
274 mask_position++;
275
276 /* Set channel name */
277 if ((1 << mask_position) & i) {
278 condition_status = lttng_condition_buffer_usage_set_channel_name(
279 condition, channel_name);
280 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
281 loop_ret = 1;
282 goto loop_end;
283 }
284 channel_name_set = true;
285 }
286 mask_position++;
287
288 /* Set threshold ratio */
289 if ((1 << mask_position) & i) {
290 condition_status = lttng_condition_buffer_usage_set_threshold_ratio(
291 condition, 0.0);
292 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
293 loop_ret = 1;
294 goto loop_end;
295 }
296 threshold_ratio_set = true;
297 }
298 mask_position++;
299
300 /* Set threshold byte */
301 if ((1 << mask_position) & i) {
302 condition_status = lttng_condition_buffer_usage_set_threshold(
303 condition, 0);
304 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
305 loop_ret = 1;
306 goto loop_end;
307 }
308 threshold_byte_set = true;
309 }
310 mask_position++;
311
312 /* Set domain type */
313 if ((1 << mask_position) & i) {
314 condition_status = lttng_condition_buffer_usage_set_domain_type(
315 condition, LTTNG_DOMAIN_UST);
316 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
317 loop_ret = 1;
318 goto loop_end;
319 }
320 domain_type_set = true;
321 }
322
323 /* Safety check */
324 if (mask_position != test_vector_size -1) {
325 assert("Logic error for test vector generation");
326 }
327
328 loop_ret = asprintf(&test_tuple_string, "session name %s, channel name %s, threshold ratio %s, threshold byte %s, domain type %s",
329 session_name_set ? "set" : "unset",
330 channel_name_set ? "set" : "unset",
331 threshold_ratio_set ? "set" : "unset",
332 threshold_byte_set ? "set" : "unset",
333 domain_type_set? "set" : "unset");
334 if (!test_tuple_string || loop_ret < 0) {
335 loop_ret = 1;
336 goto loop_end;
337 }
338
339 /* Create trigger */
340 trigger = lttng_trigger_create(condition, action);
341 if (!trigger) {
342 loop_ret = 1;
343 goto loop_end;
344 }
345
346 loop_ret = lttng_register_trigger(trigger);
347
348 loop_end:
349 if (loop_ret == 1) {
350 fail("Setup error occurred for tuple: %s", test_tuple_string);
351 goto loop_cleanup;
352 }
353
354 /* This combination happens three times */
355 if (session_name_set && channel_name_set
356 && (threshold_ratio_set || threshold_byte_set)
357 && domain_type_set) {
358 ok(loop_ret == 0, "Trigger is registered: %s", test_tuple_string);
359
360 /*
361 * Test that a trigger cannot be registered
362 * multiple time.
363 */
364 loop_ret = lttng_register_trigger(trigger);
365 ok(loop_ret == -LTTNG_ERR_TRIGGER_EXISTS, "Re-register trigger fails as expected: %s", test_tuple_string);
366
367 /* Test that a trigger can be unregistered */
368 loop_ret = lttng_unregister_trigger(trigger);
369 ok(loop_ret == 0, "Unregister trigger: %s", test_tuple_string);
370
371 /*
372 * Test that unregistration of a non-previously
373 * registered trigger fail.
374 */
375 loop_ret = lttng_unregister_trigger(trigger);
376 ok(loop_ret == -LTTNG_ERR_TRIGGER_NOT_FOUND, "Unregister of a non-registered trigger fails as expected: %s", test_tuple_string);
377 } else {
378 ok(loop_ret == -LTTNG_ERR_INVALID_TRIGGER, "Trigger is invalid as expected and cannot be registered: %s", test_tuple_string);
379 }
380
381 loop_cleanup:
382 free(test_tuple_string);
383 lttng_trigger_destroy(trigger);
384 lttng_condition_destroy(condition);
385 }
386
387 end:
388 lttng_action_destroy(action);
389 }
390
391 static
392 void wait_data_pending(const char *session_name)
393 {
394 int ret;
395
396 do {
397 ret = lttng_data_pending(session_name);
398 assert(ret >= 0);
399 } while (ret != 0);
400 }
401
402 static
403 int setup_buffer_usage_condition(struct lttng_condition *condition,
404 const char *condition_name,
405 const char *session_name,
406 const char *channel_name,
407 const enum lttng_domain_type domain_type)
408 {
409 enum lttng_condition_status condition_status;
410 int ret = 0;
411
412 condition_status = lttng_condition_buffer_usage_set_session_name(
413 condition, session_name);
414 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
415 fail("Failed to set session name on creation of condition `%s`",
416 condition_name);
417 ret = -1;
418 goto end;
419 }
420
421 condition_status = lttng_condition_buffer_usage_set_channel_name(
422 condition, channel_name);
423 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
424 fail("Failed to set channel name on creation of condition `%s`",
425 condition_name);
426 ret = -1;
427 goto end;
428 }
429
430 condition_status = lttng_condition_buffer_usage_set_domain_type(
431 condition, domain_type);
432 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
433 fail("Failed to set domain type on creation of condition `%s`",
434 condition_name);
435 ret = -1;
436 goto end;
437 }
438
439 end:
440 return ret;
441 }
442
443 static
444 void test_invalid_channel_subscription(
445 const enum lttng_domain_type domain_type)
446 {
447 enum lttng_condition_status condition_status;
448 enum lttng_notification_channel_status nc_status;
449 struct lttng_condition *dummy_condition = NULL;
450 struct lttng_condition *dummy_invalid_condition = NULL;
451 struct lttng_notification_channel *notification_channel = NULL;
452 int ret = 0;
453
454 notification_channel = lttng_notification_channel_create(
455 lttng_session_daemon_notification_endpoint);
456 ok(notification_channel, "Notification channel object creation");
457 if (!notification_channel) {
458 goto end;
459 }
460
461 /*
462 * Create a dummy, empty (thus invalid) condition to test error paths.
463 */
464 dummy_invalid_condition = lttng_condition_buffer_usage_low_create();
465 if (!dummy_invalid_condition) {
466 fail("Setup error on condition creation");
467 goto end;
468 }
469
470 /*
471 * Test subscription and unsubscription of an invalid condition to/from
472 * a channel.
473 */
474 nc_status = lttng_notification_channel_subscribe(
475 notification_channel, dummy_invalid_condition);
476 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID,
477 "Subscribing to an invalid condition");
478
479 nc_status = lttng_notification_channel_unsubscribe(
480 notification_channel, dummy_invalid_condition);
481 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID,
482 "Unsubscribing from an invalid condition");
483
484 /* Create a valid dummy condition with a ratio of 0.5 */
485 dummy_condition = lttng_condition_buffer_usage_low_create();
486 if (!dummy_condition) {
487 fail("Setup error on dummy_condition creation");
488 goto end;
489 }
490
491 condition_status = lttng_condition_buffer_usage_set_threshold_ratio(
492 dummy_condition, 0.5);
493 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
494 fail("Setup error on condition creation");
495 goto end;
496 }
497
498 ret = setup_buffer_usage_condition(dummy_condition, "dummy_condition",
499 "dummy_session", "dummy_channel", domain_type);
500 if (ret) {
501 fail("Setup error on dummy condition creation");
502 goto end;
503 }
504
505 /*
506 * Test subscription and unsubscription to/from a channel with invalid
507 * parameters.
508 */
509 nc_status = lttng_notification_channel_subscribe(NULL, NULL);
510 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID,
511 "Notification channel subscription is invalid: NULL, NULL");
512
513 nc_status = lttng_notification_channel_subscribe(
514 notification_channel, NULL);
515 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID,
516 "Notification channel subscription is invalid: NON-NULL, NULL");
517
518 nc_status = lttng_notification_channel_subscribe(NULL, dummy_condition);
519 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID,
520 "Notification channel subscription is invalid: NULL, NON-NULL");
521
522 nc_status = lttng_notification_channel_unsubscribe(
523 notification_channel, dummy_condition);
524 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION,
525 "Unsubscribing from a valid unknown condition");
526
527 end:
528 lttng_notification_channel_destroy(notification_channel);
529 lttng_condition_destroy(dummy_invalid_condition);
530 lttng_condition_destroy(dummy_condition);
531 return;
532 }
533
534 enum buffer_usage_type {
535 BUFFER_USAGE_TYPE_LOW,
536 BUFFER_USAGE_TYPE_HIGH,
537 };
538
539 static int register_buffer_usage_notify_trigger(const char *session_name,
540 const char *channel_name,
541 const enum lttng_domain_type domain_type,
542 enum buffer_usage_type buffer_usage_type,
543 double ratio,
544 struct lttng_condition **condition,
545 struct lttng_action **action,
546 struct lttng_trigger **trigger)
547 {
548 enum lttng_condition_status condition_status;
549 struct lttng_action *tmp_action = NULL;
550 struct lttng_condition *tmp_condition = NULL;
551 struct lttng_trigger *tmp_trigger = NULL;
552 int ret = 0;
553
554 /* Set-up */
555 tmp_action = lttng_action_notify_create();
556 if (!action) {
557 fail("Setup error on action creation");
558 ret = -1;
559 goto error;
560 }
561
562 if (buffer_usage_type == BUFFER_USAGE_TYPE_LOW) {
563 tmp_condition = lttng_condition_buffer_usage_low_create();
564 } else {
565 tmp_condition = lttng_condition_buffer_usage_high_create();
566 }
567
568 if (!tmp_condition) {
569 fail("Setup error on condition creation");
570 ret = -1;
571 goto error;
572 }
573
574 /* Set the buffer usage threashold */
575 condition_status = lttng_condition_buffer_usage_set_threshold_ratio(
576 tmp_condition, ratio);
577 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
578 fail("Setup error on condition creation");
579 ret = -1;
580 goto error;
581 }
582
583 ret = setup_buffer_usage_condition(tmp_condition, "condition_name",
584 session_name, channel_name, domain_type);
585 if (ret) {
586 fail("Setup error on condition creation");
587 ret = -1;
588 goto error;
589 }
590
591 /* Register the trigger for condition. */
592 tmp_trigger = lttng_trigger_create(tmp_condition, tmp_action);
593 if (!tmp_trigger) {
594 fail("Setup error on trigger creation");
595 ret = -1;
596 goto error;
597 }
598
599 ret = lttng_register_trigger(tmp_trigger);
600 if (ret) {
601 fail("Setup error on trigger registration");
602 ret = -1;
603 goto error;
604 }
605
606 *condition = tmp_condition;
607 *trigger = tmp_trigger;
608 *action = tmp_action;
609 goto end;
610
611 error:
612 lttng_action_destroy(tmp_action);
613 lttng_condition_destroy(tmp_condition);
614 lttng_trigger_destroy(tmp_trigger);
615
616 end:
617 return ret;
618 }
619
620 static void test_subscription_twice(const char *session_name,
621 const char *channel_name,
622 const enum lttng_domain_type domain_type)
623 {
624 int ret = 0;
625 enum lttng_notification_channel_status nc_status;
626
627 struct lttng_action *action = NULL;
628 struct lttng_notification_channel *notification_channel = NULL;
629 struct lttng_trigger *trigger = NULL;
630
631 struct lttng_condition *condition = NULL;
632
633 ret = register_buffer_usage_notify_trigger(session_name, channel_name,
634 domain_type, BUFFER_USAGE_TYPE_LOW, 0.99, &condition,
635 &action, &trigger);
636 if (ret) {
637 fail("Setup error on trigger registration");
638 goto end;
639 }
640
641 /* Begin testing. */
642 notification_channel = lttng_notification_channel_create(
643 lttng_session_daemon_notification_endpoint);
644 ok(notification_channel, "Notification channel object creation");
645 if (!notification_channel) {
646 goto end;
647 }
648
649 /* Subscribe a valid condition. */
650 nc_status = lttng_notification_channel_subscribe(
651 notification_channel, condition);
652 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK,
653 "Subscribe to condition");
654
655 /* Subscribing again should fail. */
656 nc_status = lttng_notification_channel_subscribe(
657 notification_channel, condition);
658 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED,
659 "Subscribe to a condition for which subscription was already done");
660
661 end:
662 lttng_unregister_trigger(trigger);
663 lttng_trigger_destroy(trigger);
664 lttng_notification_channel_destroy(notification_channel);
665 lttng_action_destroy(action);
666 lttng_condition_destroy(condition);
667 }
668
669 static void test_buffer_usage_notification_channel(const char *session_name,
670 const char *channel_name,
671 const enum lttng_domain_type domain_type,
672 const char **argv)
673 {
674 int ret = 0;
675 enum lttng_notification_channel_status nc_status;
676
677 struct lttng_action *low_action = NULL;
678 struct lttng_action *high_action = NULL;
679 struct lttng_notification *notification = NULL;
680 struct lttng_notification_channel *notification_channel = NULL;
681 struct lttng_trigger *low_trigger = NULL;
682 struct lttng_trigger *high_trigger = NULL;
683
684 struct lttng_condition *low_condition = NULL;
685 struct lttng_condition *high_condition = NULL;
686
687 const double low_ratio = 0.0;
688 const double high_ratio = 0.90;
689
690 ret = register_buffer_usage_notify_trigger(session_name, channel_name,
691 domain_type, BUFFER_USAGE_TYPE_LOW, low_ratio,
692 &low_condition, &low_action, &low_trigger);
693 if (ret) {
694 fail("Setup error on low trigger registration");
695 goto end;
696 }
697
698 ret = register_buffer_usage_notify_trigger(session_name, channel_name,
699 domain_type, BUFFER_USAGE_TYPE_HIGH, high_ratio,
700 &high_condition, &high_action, &high_trigger);
701 if (ret) {
702 fail("Setup error on high trigger registration");
703 goto end;
704 }
705
706 /* Begin testing */
707 notification_channel = lttng_notification_channel_create(
708 lttng_session_daemon_notification_endpoint);
709 ok(notification_channel, "Notification channel object creation");
710 if (!notification_channel) {
711 goto end;
712 }
713
714 /* Subscribe a valid low condition */
715 nc_status = lttng_notification_channel_subscribe(
716 notification_channel, low_condition);
717 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK,
718 "Subscribe to low condition");
719
720 /* Subscribe a valid high condition */
721 nc_status = lttng_notification_channel_subscribe(
722 notification_channel, high_condition);
723 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK,
724 "Subscribe to high condition");
725
726 resume_application();
727
728 /* Wait for notification to happen */
729 stop_consumer(argv);
730 lttng_start_tracing(session_name);
731
732 /* Wait for high notification */
733 do {
734 nc_status = lttng_notification_channel_get_next_notification(
735 notification_channel, &notification);
736 } while (nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED);
737 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK && notification &&
738 lttng_condition_get_type(lttng_notification_get_condition(
739 notification)) ==
740 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH,
741 "High notification received after intermediary communication");
742 lttng_notification_destroy(notification);
743 notification = NULL;
744
745 suspend_application();
746 lttng_stop_tracing_no_wait(session_name);
747 resume_consumer(argv);
748 wait_data_pending(session_name);
749
750 /*
751 * Test that communication still work even if there is notification
752 * waiting for consumption.
753 */
754
755 nc_status = lttng_notification_channel_unsubscribe(
756 notification_channel, low_condition);
757 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK,
758 "Unsubscribe with pending notification");
759
760 nc_status = lttng_notification_channel_subscribe(
761 notification_channel, low_condition);
762 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK,
763 "Subscribe with pending notification");
764
765 do {
766 nc_status = lttng_notification_channel_get_next_notification(
767 notification_channel, &notification);
768 } while (nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED);
769 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK && notification &&
770 lttng_condition_get_type(lttng_notification_get_condition(
771 notification)) ==
772 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW,
773 "Low notification received after intermediary communication");
774 lttng_notification_destroy(notification);
775 notification = NULL;
776
777 /* Stop consumer to force a high notification */
778 stop_consumer(argv);
779 resume_application();
780 lttng_start_tracing(session_name);
781
782 do {
783 nc_status = lttng_notification_channel_get_next_notification(
784 notification_channel, &notification);
785 } while (nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED);
786 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK && notification &&
787 lttng_condition_get_type(lttng_notification_get_condition(
788 notification)) ==
789 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH,
790 "High notification received after intermediary communication");
791 lttng_notification_destroy(notification);
792 notification = NULL;
793
794 suspend_application();
795 lttng_stop_tracing_no_wait(session_name);
796 resume_consumer(argv);
797 wait_data_pending(session_name);
798
799 do {
800 nc_status = lttng_notification_channel_get_next_notification(
801 notification_channel, &notification);
802 } while (nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED);
803 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK && notification &&
804 lttng_condition_get_type(lttng_notification_get_condition(
805 notification)) ==
806 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW,
807 "Low notification received after re-subscription");
808 lttng_notification_destroy(notification);
809 notification = NULL;
810
811 stop_consumer(argv);
812 resume_application();
813 /* Stop consumer to force a high notification */
814 lttng_start_tracing(session_name);
815
816 do {
817 nc_status = lttng_notification_channel_get_next_notification(
818 notification_channel, &notification);
819 } while (nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED);
820 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK && notification &&
821 lttng_condition_get_type(lttng_notification_get_condition(
822 notification)) ==
823 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH,
824 "High notification");
825 lttng_notification_destroy(notification);
826 notification = NULL;
827
828 suspend_application();
829
830 /* Resume consumer to allow event consumption */
831 lttng_stop_tracing_no_wait(session_name);
832 resume_consumer(argv);
833 wait_data_pending(session_name);
834
835 nc_status = lttng_notification_channel_unsubscribe(
836 notification_channel, low_condition);
837 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK,
838 "Unsubscribe low condition with pending notification");
839
840 nc_status = lttng_notification_channel_unsubscribe(
841 notification_channel, high_condition);
842 ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK,
843 "Unsubscribe high condition with pending notification");
844
845 end:
846 lttng_notification_channel_destroy(notification_channel);
847 lttng_trigger_destroy(low_trigger);
848 lttng_trigger_destroy(high_trigger);
849 lttng_action_destroy(low_action);
850 lttng_action_destroy(high_action);
851 lttng_condition_destroy(low_condition);
852 lttng_condition_destroy(high_condition);
853 }
854
855 int main(int argc, const char *argv[])
856 {
857 const char *session_name = NULL;
858 const char *channel_name = NULL;
859 const char *domain_type_string = NULL;
860 enum lttng_domain_type domain_type = LTTNG_DOMAIN_NONE;
861
862 plan_tests(NUM_TESTS);
863
864 /* Argument 6 and upward are named pipe location for consumerd control */
865 named_pipe_args_start = 6;
866
867 if (argc < 7) {
868 fail("Missing parameter for tests to run %d", argc);
869 goto error;
870 }
871
872 nb_args = argc;
873
874 domain_type_string = argv[1];
875 session_name = argv[2];
876 channel_name = argv[3];
877 app_pid = (pid_t) atoi(argv[4]);
878 app_state_file = argv[5];
879
880 if (!strcmp("LTTNG_DOMAIN_UST", domain_type_string)) {
881 domain_type = LTTNG_DOMAIN_UST;
882 }
883 if (!strcmp("LTTNG_DOMAIN_KERNEL", domain_type_string)) {
884 domain_type = LTTNG_DOMAIN_KERNEL;
885 }
886 if (domain_type == LTTNG_DOMAIN_NONE) {
887 fail("Unknown domain type");
888 goto error;
889 }
890
891 /*
892 * Test cases are responsible for resuming the app when needed and
893 * making sure it's suspended when returning.
894 */
895 suspend_application();
896
897 diag("Test trigger for domain %s with buffer_usage_low condition", domain_type_string);
898 test_triggers_buffer_usage_condition(session_name, channel_name, domain_type, LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW);
899 diag("Test trigger for domain %s with buffer_usage_high condition", domain_type_string);
900 test_triggers_buffer_usage_condition(session_name, channel_name, domain_type, LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH);
901
902 /* Basic error path check. */
903 test_invalid_channel_subscription(domain_type);
904 test_subscription_twice(session_name, channel_name, domain_type);
905
906 diag("Test buffer usage notification channel api for domain %s", domain_type_string);
907 test_buffer_usage_notification_channel(session_name, channel_name, domain_type, argv);
908 error:
909 return exit_status();
910 }
911
This page took 0.048032 seconds and 5 git commands to generate.