4 * Tests suite for LTTng notification API
6 * Copyright (C) 2017 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
8 * SPDX-License-Identifier: MIT
20 #include <sys/types.h>
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/condition/event-rule.h>
33 #include <lttng/domain.h>
34 #include <lttng/endpoint.h>
35 #include <lttng/event-rule/kprobe.h>
36 #include <lttng/event-rule/syscall.h>
37 #include <lttng/event-rule/tracepoint.h>
38 #include <lttng/event-rule/uprobe.h>
39 #include <lttng/kernel-probe.h>
40 #include <lttng/lttng-error.h>
41 #include <lttng/lttng.h>
42 #include <lttng/notification/channel.h>
43 #include <lttng/notification/notification.h>
44 #include <lttng/condition/evaluation.h>
45 #include <lttng/trigger/trigger.h>
46 #include <lttng/userspace-probe.h>
51 int named_pipe_args_start
= 0;
53 const char *app_state_file
= NULL
;
55 static const char *get_notification_trigger_name(
56 struct lttng_notification
*notification
)
58 const char *name
= NULL
;
59 enum lttng_evaluation_status status
;
60 const struct lttng_evaluation
*evaluation
;
61 evaluation
= lttng_notification_get_evaluation(notification
);
62 if (evaluation
== NULL
) {
63 fail("lttng_notification_get_evaluation");
67 switch (lttng_evaluation_get_type(evaluation
)) {
68 case LTTNG_CONDITION_TYPE_EVENT_RULE_HIT
:
70 status
= lttng_evaluation_event_rule_get_trigger_name(
72 if (status
!= LTTNG_EVALUATION_STATUS_OK
) {
73 fail("lttng_evaluation_event_rule_get_trigger_name");
80 fail("Wrong notification evaluation type \n");
87 static int validator_notification_trigger_name(
88 struct lttng_notification
*notification
,
89 const char *trigger_name
)
98 name
= get_notification_trigger_name(notification
);
104 name_is_equal
= (strcmp(trigger_name
, name
) == 0);
105 ok(name_is_equal
, "Expected trigger name: %s got %s", trigger_name
,
108 ret
= !name_is_equal
;
115 void wait_on_file(const char *path
, bool file_exist
)
124 ret
= stat(path
, &buf
);
125 if (ret
== -1 && errno
== ENOENT
) {
128 * The file does not exist. wait a bit and
129 * continue looping until it does.
131 (void) poll(NULL
, 0, 10);
136 * File does not exist and the exit condition we want.
137 * Break from the loop and return.
146 * stat() returned 0, so the file exists. break now only if
147 * that's the exit condition we want.
156 int write_pipe(const char *path
, uint8_t data
)
161 fd
= open(path
, O_WRONLY
| O_NONBLOCK
);
163 perror("Could not open consumer control named pipe");
167 ret
= write(fd
, &data
, sizeof(data
));
169 perror("Named pipe write failed");
171 perror("Named pipe close failed");
179 perror("Name pipe closing failed");
188 int stop_consumer(const char **argv
)
192 for (i
= named_pipe_args_start
; i
< nb_args
; i
++) {
193 ret
= write_pipe(argv
[i
], 49);
199 int resume_consumer(const char **argv
)
203 for (i
= named_pipe_args_start
; i
< nb_args
; i
++) {
204 ret
= write_pipe(argv
[i
], 0);
210 int suspend_application(void)
215 if (!stat(app_state_file
, &buf
)) {
216 fail("App is already in a suspended state.");
222 * Send SIGUSR1 to application instructing it to bypass tracepoint.
226 ret
= kill(app_pid
, SIGUSR1
);
228 fail("SIGUSR1 failed. errno %d", errno
);
233 wait_on_file(app_state_file
, true);
241 int resume_application(void)
246 ret
= stat(app_state_file
, &buf
);
247 if (ret
== -1 && errno
== ENOENT
) {
248 fail("State file does not exist");
258 ret
= kill(app_pid
, SIGUSR1
);
260 fail("SIGUSR1 failed. errno %d", errno
);
265 wait_on_file(app_state_file
, false);
274 void test_triggers_buffer_usage_condition(const char *session_name
,
275 const char *channel_name
,
276 enum lttng_domain_type domain_type
,
277 enum lttng_condition_type condition_type
)
279 unsigned int test_vector_size
= 5, i
;
280 enum lttng_condition_status condition_status
;
281 struct lttng_action
*action
;
284 action
= lttng_action_notify_create();
286 fail("Setup error on action creation");
290 /* Test lttng_register_trigger with null value */
291 ok(lttng_register_trigger(NULL
) == -LTTNG_ERR_INVALID
, "Registering a NULL trigger fails as expected");
293 /* Test: register a trigger */
295 for (i
= 0; i
< pow(2,test_vector_size
); i
++) {
297 char *test_tuple_string
= NULL
;
298 unsigned int mask_position
= 0;
299 bool session_name_set
= false;
300 bool channel_name_set
= false;
301 bool threshold_ratio_set
= false;
302 bool threshold_byte_set
= false;
303 bool domain_type_set
= false;
305 struct lttng_trigger
*trigger
= NULL
;
306 struct lttng_condition
*condition
= NULL
;
308 /* Create base condition */
309 switch (condition_type
) {
310 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
311 condition
= lttng_condition_buffer_usage_low_create();
313 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
314 condition
= lttng_condition_buffer_usage_high_create();
327 /* Prepare the condition for trigger registration test */
329 /* Set session name */
330 if ((1 << mask_position
) & i
) {
331 condition_status
= lttng_condition_buffer_usage_set_session_name(
332 condition
, session_name
);
333 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
337 session_name_set
= true;
341 /* Set channel name */
342 if ((1 << mask_position
) & i
) {
343 condition_status
= lttng_condition_buffer_usage_set_channel_name(
344 condition
, channel_name
);
345 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
349 channel_name_set
= true;
353 /* Set threshold ratio */
354 if ((1 << mask_position
) & i
) {
355 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
357 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
361 threshold_ratio_set
= true;
365 /* Set threshold byte */
366 if ((1 << mask_position
) & i
) {
367 condition_status
= lttng_condition_buffer_usage_set_threshold(
369 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
373 threshold_byte_set
= true;
377 /* Set domain type */
378 if ((1 << mask_position
) & i
) {
379 condition_status
= lttng_condition_buffer_usage_set_domain_type(
380 condition
, LTTNG_DOMAIN_UST
);
381 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
385 domain_type_set
= true;
389 if (mask_position
!= test_vector_size
-1) {
390 assert("Logic error for test vector generation");
393 loop_ret
= asprintf(&test_tuple_string
, "session name %s, channel name %s, threshold ratio %s, threshold byte %s, domain type %s",
394 session_name_set
? "set" : "unset",
395 channel_name_set
? "set" : "unset",
396 threshold_ratio_set
? "set" : "unset",
397 threshold_byte_set
? "set" : "unset",
398 domain_type_set
? "set" : "unset");
399 if (!test_tuple_string
|| loop_ret
< 0) {
405 trigger
= lttng_trigger_create(condition
, action
);
411 loop_ret
= lttng_register_trigger(trigger
);
415 fail("Setup error occurred for tuple: %s", test_tuple_string
);
419 /* This combination happens three times */
420 if (session_name_set
&& channel_name_set
421 && (threshold_ratio_set
|| threshold_byte_set
)
422 && domain_type_set
) {
423 ok(loop_ret
== 0, "Trigger is registered: %s", test_tuple_string
);
426 * Test that a trigger cannot be registered
429 loop_ret
= lttng_register_trigger(trigger
);
430 ok(loop_ret
== -LTTNG_ERR_TRIGGER_EXISTS
, "Re-register trigger fails as expected: %s", test_tuple_string
);
432 /* Test that a trigger can be unregistered */
433 loop_ret
= lttng_unregister_trigger(trigger
);
434 ok(loop_ret
== 0, "Unregister trigger: %s", test_tuple_string
);
437 * Test that unregistration of a non-previously
438 * registered trigger fail.
440 loop_ret
= lttng_unregister_trigger(trigger
);
441 ok(loop_ret
== -LTTNG_ERR_TRIGGER_NOT_FOUND
, "Unregister of a non-registered trigger fails as expected: %s", test_tuple_string
);
443 ok(loop_ret
== -LTTNG_ERR_INVALID_TRIGGER
, "Trigger is invalid as expected and cannot be registered: %s", test_tuple_string
);
447 free(test_tuple_string
);
448 lttng_trigger_destroy(trigger
);
449 lttng_condition_destroy(condition
);
453 lttng_action_destroy(action
);
457 void wait_data_pending(const char *session_name
)
462 ret
= lttng_data_pending(session_name
);
468 int setup_buffer_usage_condition(struct lttng_condition
*condition
,
469 const char *condition_name
,
470 const char *session_name
,
471 const char *channel_name
,
472 const enum lttng_domain_type domain_type
)
474 enum lttng_condition_status condition_status
;
477 condition_status
= lttng_condition_buffer_usage_set_session_name(
478 condition
, session_name
);
479 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
480 fail("Failed to set session name on creation of condition `%s`",
486 condition_status
= lttng_condition_buffer_usage_set_channel_name(
487 condition
, channel_name
);
488 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
489 fail("Failed to set channel name on creation of condition `%s`",
495 condition_status
= lttng_condition_buffer_usage_set_domain_type(
496 condition
, domain_type
);
497 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
498 fail("Failed to set domain type on creation of condition `%s`",
509 void test_invalid_channel_subscription(
510 const enum lttng_domain_type domain_type
)
512 enum lttng_condition_status condition_status
;
513 enum lttng_notification_channel_status nc_status
;
514 struct lttng_condition
*dummy_condition
= NULL
;
515 struct lttng_condition
*dummy_invalid_condition
= NULL
;
516 struct lttng_notification_channel
*notification_channel
= NULL
;
519 notification_channel
= lttng_notification_channel_create(
520 lttng_session_daemon_notification_endpoint
);
521 ok(notification_channel
, "Notification channel object creation");
522 if (!notification_channel
) {
527 * Create a dummy, empty (thus invalid) condition to test error paths.
529 dummy_invalid_condition
= lttng_condition_buffer_usage_low_create();
530 if (!dummy_invalid_condition
) {
531 fail("Setup error on condition creation");
536 * Test subscription and unsubscription of an invalid condition to/from
539 nc_status
= lttng_notification_channel_subscribe(
540 notification_channel
, dummy_invalid_condition
);
541 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
542 "Subscribing to an invalid condition");
544 nc_status
= lttng_notification_channel_unsubscribe(
545 notification_channel
, dummy_invalid_condition
);
546 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
547 "Unsubscribing from an invalid condition");
549 /* Create a valid dummy condition with a ratio of 0.5 */
550 dummy_condition
= lttng_condition_buffer_usage_low_create();
551 if (!dummy_condition
) {
552 fail("Setup error on dummy_condition creation");
556 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
557 dummy_condition
, 0.5);
558 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
559 fail("Setup error on condition creation");
563 ret
= setup_buffer_usage_condition(dummy_condition
, "dummy_condition",
564 "dummy_session", "dummy_channel", domain_type
);
566 fail("Setup error on dummy condition creation");
571 * Test subscription and unsubscription to/from a channel with invalid
574 nc_status
= lttng_notification_channel_subscribe(NULL
, NULL
);
575 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
576 "Notification channel subscription is invalid: NULL, NULL");
578 nc_status
= lttng_notification_channel_subscribe(
579 notification_channel
, NULL
);
580 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
581 "Notification channel subscription is invalid: NON-NULL, NULL");
583 nc_status
= lttng_notification_channel_subscribe(NULL
, dummy_condition
);
584 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
585 "Notification channel subscription is invalid: NULL, NON-NULL");
587 nc_status
= lttng_notification_channel_unsubscribe(
588 notification_channel
, dummy_condition
);
589 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION
,
590 "Unsubscribing from a valid unknown condition");
593 lttng_notification_channel_destroy(notification_channel
);
594 lttng_condition_destroy(dummy_invalid_condition
);
595 lttng_condition_destroy(dummy_condition
);
599 enum buffer_usage_type
{
600 BUFFER_USAGE_TYPE_LOW
,
601 BUFFER_USAGE_TYPE_HIGH
,
604 static int register_buffer_usage_notify_trigger(const char *session_name
,
605 const char *channel_name
,
606 const enum lttng_domain_type domain_type
,
607 enum buffer_usage_type buffer_usage_type
,
609 struct lttng_condition
**condition
,
610 struct lttng_action
**action
,
611 struct lttng_trigger
**trigger
)
613 enum lttng_condition_status condition_status
;
614 struct lttng_action
*tmp_action
= NULL
;
615 struct lttng_condition
*tmp_condition
= NULL
;
616 struct lttng_trigger
*tmp_trigger
= NULL
;
620 tmp_action
= lttng_action_notify_create();
622 fail("Setup error on action creation");
627 if (buffer_usage_type
== BUFFER_USAGE_TYPE_LOW
) {
628 tmp_condition
= lttng_condition_buffer_usage_low_create();
630 tmp_condition
= lttng_condition_buffer_usage_high_create();
633 if (!tmp_condition
) {
634 fail("Setup error on condition creation");
639 /* Set the buffer usage threashold */
640 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
641 tmp_condition
, ratio
);
642 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
643 fail("Setup error on condition creation");
648 ret
= setup_buffer_usage_condition(tmp_condition
, "condition_name",
649 session_name
, channel_name
, domain_type
);
651 fail("Setup error on condition creation");
656 /* Register the trigger for condition. */
657 tmp_trigger
= lttng_trigger_create(tmp_condition
, tmp_action
);
659 fail("Setup error on trigger creation");
664 ret
= lttng_register_trigger(tmp_trigger
);
666 fail("Setup error on trigger registration");
671 *condition
= tmp_condition
;
672 *trigger
= tmp_trigger
;
673 *action
= tmp_action
;
677 lttng_action_destroy(tmp_action
);
678 lttng_condition_destroy(tmp_condition
);
679 lttng_trigger_destroy(tmp_trigger
);
685 static void test_subscription_twice(const char *session_name
,
686 const char *channel_name
,
687 const enum lttng_domain_type domain_type
)
690 enum lttng_notification_channel_status nc_status
;
692 struct lttng_action
*action
= NULL
;
693 struct lttng_notification_channel
*notification_channel
= NULL
;
694 struct lttng_trigger
*trigger
= NULL
;
696 struct lttng_condition
*condition
= NULL
;
698 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
699 domain_type
, BUFFER_USAGE_TYPE_LOW
, 0.99, &condition
,
702 fail("Setup error on trigger registration");
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
) {
714 /* Subscribe a valid condition. */
715 nc_status
= lttng_notification_channel_subscribe(
716 notification_channel
, condition
);
717 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
718 "Subscribe to condition");
720 /* Subscribing again should fail. */
721 nc_status
= lttng_notification_channel_subscribe(
722 notification_channel
, condition
);
723 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED
,
724 "Subscribe to a condition for which subscription was already done");
727 lttng_unregister_trigger(trigger
);
728 lttng_trigger_destroy(trigger
);
729 lttng_notification_channel_destroy(notification_channel
);
730 lttng_action_destroy(action
);
731 lttng_condition_destroy(condition
);
734 static void test_buffer_usage_notification_channel(const char *session_name
,
735 const char *channel_name
,
736 const enum lttng_domain_type domain_type
,
740 enum lttng_notification_channel_status nc_status
;
742 struct lttng_action
*low_action
= NULL
;
743 struct lttng_action
*high_action
= NULL
;
744 struct lttng_notification
*notification
= NULL
;
745 struct lttng_notification_channel
*notification_channel
= NULL
;
746 struct lttng_trigger
*low_trigger
= NULL
;
747 struct lttng_trigger
*high_trigger
= NULL
;
749 struct lttng_condition
*low_condition
= NULL
;
750 struct lttng_condition
*high_condition
= NULL
;
752 const double low_ratio
= 0.0;
753 const double high_ratio
= 0.90;
755 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
756 domain_type
, BUFFER_USAGE_TYPE_LOW
, low_ratio
,
757 &low_condition
, &low_action
, &low_trigger
);
759 fail("Setup error on low trigger registration");
763 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
764 domain_type
, BUFFER_USAGE_TYPE_HIGH
, high_ratio
,
765 &high_condition
, &high_action
, &high_trigger
);
767 fail("Setup error on high trigger registration");
772 notification_channel
= lttng_notification_channel_create(
773 lttng_session_daemon_notification_endpoint
);
774 ok(notification_channel
, "Notification channel object creation");
775 if (!notification_channel
) {
779 /* Subscribe a valid low condition */
780 nc_status
= lttng_notification_channel_subscribe(
781 notification_channel
, low_condition
);
782 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
783 "Subscribe to low condition");
785 /* Subscribe a valid high condition */
786 nc_status
= lttng_notification_channel_subscribe(
787 notification_channel
, high_condition
);
788 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
789 "Subscribe to high condition");
791 resume_application();
793 /* Wait for notification to happen */
795 lttng_start_tracing(session_name
);
797 /* Wait for high notification */
799 nc_status
= lttng_notification_channel_get_next_notification(
800 notification_channel
, ¬ification
);
801 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
802 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
803 lttng_condition_get_type(lttng_notification_get_condition(
805 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
806 "High notification received after intermediary communication");
807 lttng_notification_destroy(notification
);
810 suspend_application();
811 lttng_stop_tracing_no_wait(session_name
);
812 resume_consumer(argv
);
813 wait_data_pending(session_name
);
816 * Test that communication still work even if there is notification
817 * waiting for consumption.
820 nc_status
= lttng_notification_channel_unsubscribe(
821 notification_channel
, low_condition
);
822 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
823 "Unsubscribe with pending notification");
825 nc_status
= lttng_notification_channel_subscribe(
826 notification_channel
, low_condition
);
827 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
828 "Subscribe with pending notification");
831 nc_status
= lttng_notification_channel_get_next_notification(
832 notification_channel
, ¬ification
);
833 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
834 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
835 lttng_condition_get_type(lttng_notification_get_condition(
837 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
,
838 "Low notification received after intermediary communication");
839 lttng_notification_destroy(notification
);
842 /* Stop consumer to force a high notification */
844 resume_application();
845 lttng_start_tracing(session_name
);
848 nc_status
= lttng_notification_channel_get_next_notification(
849 notification_channel
, ¬ification
);
850 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
851 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
852 lttng_condition_get_type(lttng_notification_get_condition(
854 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
855 "High notification received after intermediary communication");
856 lttng_notification_destroy(notification
);
859 suspend_application();
860 lttng_stop_tracing_no_wait(session_name
);
861 resume_consumer(argv
);
862 wait_data_pending(session_name
);
865 nc_status
= lttng_notification_channel_get_next_notification(
866 notification_channel
, ¬ification
);
867 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
868 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
869 lttng_condition_get_type(lttng_notification_get_condition(
871 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
,
872 "Low notification received after re-subscription");
873 lttng_notification_destroy(notification
);
877 resume_application();
878 /* Stop consumer to force a high notification */
879 lttng_start_tracing(session_name
);
882 nc_status
= lttng_notification_channel_get_next_notification(
883 notification_channel
, ¬ification
);
884 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
885 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
886 lttng_condition_get_type(lttng_notification_get_condition(
888 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
889 "High notification");
890 lttng_notification_destroy(notification
);
893 suspend_application();
895 /* Resume consumer to allow event consumption */
896 lttng_stop_tracing_no_wait(session_name
);
897 resume_consumer(argv
);
898 wait_data_pending(session_name
);
900 nc_status
= lttng_notification_channel_unsubscribe(
901 notification_channel
, low_condition
);
902 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
903 "Unsubscribe low condition with pending notification");
905 nc_status
= lttng_notification_channel_unsubscribe(
906 notification_channel
, high_condition
);
907 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
908 "Unsubscribe high condition with pending notification");
911 lttng_notification_channel_destroy(notification_channel
);
912 lttng_trigger_destroy(low_trigger
);
913 lttng_trigger_destroy(high_trigger
);
914 lttng_action_destroy(low_action
);
915 lttng_action_destroy(high_action
);
916 lttng_condition_destroy(low_condition
);
917 lttng_condition_destroy(high_condition
);
920 static void create_tracepoint_event_rule_trigger(const char *event_pattern
,
921 const char *trigger_name
,
923 unsigned int exclusion_count
,
924 const char * const *exclusions
,
925 enum lttng_domain_type domain_type
,
926 struct lttng_condition
**condition
,
927 struct lttng_trigger
**trigger
)
929 enum lttng_event_rule_status event_rule_status
;
930 enum lttng_trigger_status trigger_status
;
932 struct lttng_action
*tmp_action
= NULL
;
933 struct lttng_event_rule
*event_rule
= NULL
;
934 struct lttng_condition
*tmp_condition
= NULL
;
935 struct lttng_trigger
*tmp_trigger
= NULL
;
938 assert(event_pattern
);
939 assert(trigger_name
);
943 event_rule
= lttng_event_rule_tracepoint_create(domain_type
);
944 ok(event_rule
, "Tracepoint event rule object creation");
946 event_rule_status
= lttng_event_rule_tracepoint_set_pattern(
947 event_rule
, event_pattern
);
948 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
949 "Setting tracepoint event rule pattern: '%s'",
953 event_rule_status
= lttng_event_rule_tracepoint_set_filter(
955 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
956 "Setting tracepoint event rule filter: '%s'",
964 assert(domain_type
== LTTNG_DOMAIN_UST
);
965 assert(exclusion_count
> 0);
967 for (i
= 0; i
< exclusion_count
; i
++) {
969 lttng_event_rule_tracepoint_add_exclusion(
972 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
973 fail("Setting tracepoint event rule exclusion '%s'.",
979 ok(success
, "Setting tracepoint event rule exclusions");
982 tmp_condition
= lttng_condition_event_rule_create(event_rule
);
983 ok(tmp_condition
, "Condition event rule object creation");
985 tmp_action
= lttng_action_notify_create();
986 ok(tmp_action
, "Action event rule object creation");
988 tmp_trigger
= lttng_trigger_create(tmp_condition
, tmp_action
);
989 ok(tmp_trigger
, "Trigger object creation %s", trigger_name
);
991 trigger_status
= lttng_trigger_set_name(tmp_trigger
, trigger_name
);
992 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
993 "Setting name to trigger %s", trigger_name
);
995 ret
= lttng_register_trigger(tmp_trigger
);
996 ok(ret
== 0, "Trigger registration %s", trigger_name
);
998 lttng_event_rule_destroy(event_rule
);
1000 *condition
= tmp_condition
;
1001 *trigger
= tmp_trigger
;
1006 static struct lttng_notification
*get_next_notification(
1007 struct lttng_notification_channel
*notification_channel
)
1009 struct lttng_notification
*local_notification
= NULL
;
1010 enum lttng_notification_channel_status status
;
1012 /* Receive the next notification. */
1013 status
= lttng_notification_channel_get_next_notification(
1014 notification_channel
, &local_notification
);
1017 case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
:
1019 case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED
:
1020 fail("Notifications have been dropped");
1021 local_notification
= NULL
;
1024 /* Unhandled conditions / errors. */
1025 fail("Failed to get next notification (unknown notification channel status): status = %d",
1027 local_notification
= NULL
;
1031 return local_notification
;
1034 static void test_tracepoint_event_rule_notification(
1035 enum lttng_domain_type domain_type
)
1039 const int notification_count
= 3;
1040 enum lttng_notification_channel_status nc_status
;
1041 struct lttng_action
*action
= NULL
;
1042 struct lttng_condition
*condition
= NULL
;
1043 struct lttng_notification_channel
*notification_channel
= NULL
;
1044 struct lttng_trigger
*trigger
= NULL
;
1045 const char * const trigger_name
= "my_precious";
1046 const char *pattern
;
1048 if (domain_type
== LTTNG_DOMAIN_UST
) {
1049 pattern
= "tp:tptest";
1051 pattern
= "lttng_test_filter_event";
1054 create_tracepoint_event_rule_trigger(pattern
, trigger_name
, NULL
, 0,
1055 NULL
, domain_type
, &condition
, &trigger
);
1057 notification_channel
= lttng_notification_channel_create(
1058 lttng_session_daemon_notification_endpoint
);
1059 ok(notification_channel
, "Notification channel object creation");
1061 nc_status
= lttng_notification_channel_subscribe(
1062 notification_channel
, condition
);
1063 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1064 "Subscribe to tracepoint event rule condition");
1066 resume_application();
1068 /* Get notifications. */
1069 for (i
= 0; i
< notification_count
; i
++) {
1070 struct lttng_notification
*notification
= get_next_notification(
1071 notification_channel
);
1073 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1074 notification_count
);
1077 if (notification
== NULL
) {
1081 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1082 lttng_notification_destroy(notification
);
1089 suspend_application();
1090 lttng_notification_channel_destroy(notification_channel
);
1091 lttng_unregister_trigger(trigger
);
1092 lttng_trigger_destroy(trigger
);
1093 lttng_action_destroy(action
);
1094 lttng_condition_destroy(condition
);
1098 static void test_tracepoint_event_rule_notification_filter(
1099 enum lttng_domain_type domain_type
)
1102 const int notification_count
= 3;
1103 enum lttng_notification_channel_status nc_status
;
1104 struct lttng_condition
*ctrl_condition
= NULL
, *condition
= NULL
;
1105 struct lttng_notification_channel
*notification_channel
= NULL
;
1106 struct lttng_trigger
*ctrl_trigger
= NULL
, *trigger
= NULL
;
1107 const char * const ctrl_trigger_name
= "control_trigger";
1108 const char * const trigger_name
= "trigger";
1109 const char *pattern
;
1110 int ctrl_count
= 0, count
= 0;
1112 if (domain_type
== LTTNG_DOMAIN_UST
) {
1113 pattern
= "tp:tptest";
1115 pattern
= "lttng_test_filter_event";
1118 notification_channel
= lttng_notification_channel_create(
1119 lttng_session_daemon_notification_endpoint
);
1120 ok(notification_channel
, "Notification channel object creation");
1122 create_tracepoint_event_rule_trigger(pattern
, ctrl_trigger_name
, NULL
,
1123 0, NULL
, domain_type
, &ctrl_condition
, &ctrl_trigger
);
1125 nc_status
= lttng_notification_channel_subscribe(
1126 notification_channel
, ctrl_condition
);
1127 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1128 "Subscribe to tracepoint event rule condition");
1131 * Attach a filter expression to get notification only if the
1132 * `intfield` is even.
1134 create_tracepoint_event_rule_trigger(pattern
, trigger_name
,
1135 "(intfield & 1) == 0", 0, NULL
, domain_type
, &condition
,
1138 nc_status
= lttng_notification_channel_subscribe(
1139 notification_channel
, condition
);
1140 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1141 "Subscribe to tracepoint event rule condition");
1144 * We registered 2 notifications triggers, one with a filter and one
1145 * without (control). The one with a filter will only fired when the
1146 * `intfield` is a multiple of 2. We should get two times as many
1147 * control notifications as filter notifications.
1149 resume_application();
1152 * Get 3 notifications. We should get 1 for the regular trigger (with
1153 * the filter) and 2 from the control trigger. This works whatever
1154 * the order we receive the notifications.
1156 for (i
= 0; i
< notification_count
; i
++) {
1158 struct lttng_notification
*notification
= get_next_notification(
1159 notification_channel
);
1161 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1162 notification_count
);
1165 if (notification
== NULL
) {
1169 name
= get_notification_trigger_name(notification
);
1171 lttng_notification_destroy(notification
);
1175 if (strcmp(ctrl_trigger_name
, name
) == 0) {
1177 } else if (strcmp(trigger_name
, name
) == 0) {
1181 lttng_notification_destroy(notification
);
1184 ok(ctrl_count
/ 2 == count
,
1185 "Get twice as many control notif as of regular notif");
1188 suspend_application();
1190 lttng_unregister_trigger(trigger
);
1191 lttng_unregister_trigger(ctrl_trigger
);
1192 lttng_notification_channel_destroy(notification_channel
);
1193 lttng_trigger_destroy(trigger
);
1194 lttng_trigger_destroy(ctrl_trigger
);
1195 lttng_condition_destroy(condition
);
1196 lttng_condition_destroy(ctrl_condition
);
1199 static void test_tracepoint_event_rule_notification_exclusion(
1200 enum lttng_domain_type domain_type
)
1202 enum lttng_notification_channel_status nc_status
;
1203 struct lttng_condition
*ctrl_condition
= NULL
, *condition
= NULL
;
1204 struct lttng_notification_channel
*notification_channel
= NULL
;
1205 struct lttng_trigger
*ctrl_trigger
= NULL
, *trigger
= NULL
;
1206 int ctrl_count
= 0, count
= 0, i
;
1207 const int notification_count
= 6;
1208 const char * const ctrl_trigger_name
= "control_exclusion_trigger";
1209 const char * const trigger_name
= "exclusion_trigger";
1210 const char * const pattern
= "tp:tptest*";
1211 const char * const exclusions
[] = {
1218 notification_channel
= lttng_notification_channel_create(
1219 lttng_session_daemon_notification_endpoint
);
1220 ok(notification_channel
, "Notification channel object creation");
1222 create_tracepoint_event_rule_trigger(pattern
, ctrl_trigger_name
, NULL
,
1223 0, NULL
, domain_type
, &ctrl_condition
, &ctrl_trigger
);
1225 nc_status
= lttng_notification_channel_subscribe(
1226 notification_channel
, ctrl_condition
);
1227 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1228 "Subscribe to tracepoint event rule condition");
1230 create_tracepoint_event_rule_trigger(pattern
, trigger_name
, NULL
, 4,
1231 exclusions
, domain_type
, &condition
, &trigger
);
1233 nc_status
= lttng_notification_channel_subscribe(
1234 notification_channel
, condition
);
1235 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1236 "Subscribe to tracepoint event rule condition");
1239 * We registered 2 notifications triggers, one with an exclusion and
1240 * one without (control).
1241 * - The trigger with an exclusion will fire once every iteration.
1242 * - The trigger without an exclusion will fire 5 times every
1245 * We should get 5 times as many notifications from the control
1248 resume_application();
1251 * Get 6 notifications. We should get 1 for the regular trigger (with
1252 * the exclusion) and 5 from the control trigger. This works whatever
1253 * the order we receive the notifications.
1255 for (i
= 0; i
< notification_count
; i
++) {
1257 struct lttng_notification
*notification
= get_next_notification(
1258 notification_channel
);
1260 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1261 notification_count
);
1264 if (notification
== NULL
) {
1268 name
= get_notification_trigger_name(notification
);
1270 lttng_notification_destroy(notification
);
1274 if (strcmp(ctrl_trigger_name
, name
) == 0) {
1276 } else if (strcmp(trigger_name
, name
) == 0) {
1280 lttng_notification_destroy(notification
);
1283 ok(ctrl_count
/ 5 == count
,
1284 "Got 5 times as many control notif as of regular notif");
1287 suspend_application();
1289 lttng_unregister_trigger(trigger
);
1290 lttng_unregister_trigger(ctrl_trigger
);
1291 lttng_notification_channel_destroy(notification_channel
);
1292 lttng_trigger_destroy(trigger
);
1293 lttng_trigger_destroy(ctrl_trigger
);
1294 lttng_condition_destroy(condition
);
1295 lttng_condition_destroy(ctrl_condition
);
1299 static void test_kprobe_event_rule_notification(
1300 enum lttng_domain_type domain_type
)
1303 const int notification_count
= 3;
1304 enum lttng_notification_channel_status nc_status
;
1305 enum lttng_event_rule_status event_rule_status
;
1306 enum lttng_trigger_status trigger_status
;
1307 struct lttng_notification_channel
*notification_channel
= NULL
;
1308 struct lttng_condition
*condition
= NULL
;
1309 struct lttng_kernel_probe_location
*location
= NULL
;
1310 struct lttng_event_rule
*event_rule
= NULL
;
1311 struct lttng_action
*action
= NULL
;
1312 struct lttng_trigger
*trigger
= NULL
;
1313 const char * const trigger_name
= "kprobe_trigger";
1314 const char * const symbol_name
= "lttng_test_filter_event_write";
1316 action
= lttng_action_notify_create();
1318 fail("Failed to create notify action");
1322 location
= lttng_kernel_probe_location_symbol_create(symbol_name
, 0);
1324 fail("Failed to create kernel probe location");
1328 notification_channel
= lttng_notification_channel_create(
1329 lttng_session_daemon_notification_endpoint
);
1330 ok(notification_channel
, "Notification channel object creation");
1332 event_rule
= lttng_event_rule_kprobe_create();
1333 ok(event_rule
, "kprobe event rule object creation");
1335 event_rule_status
= lttng_event_rule_kprobe_set_location(
1336 event_rule
, location
);
1337 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1338 "Setting kprobe event rule location: '%s'", symbol_name
);
1340 event_rule_status
= lttng_event_rule_kprobe_set_name(
1341 event_rule
, trigger_name
);
1342 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1343 "Setting kprobe event rule name: '%s'", trigger_name
);
1345 condition
= lttng_condition_event_rule_create(event_rule
);
1346 ok(condition
, "Condition event rule object creation");
1348 /* Register the trigger for condition. */
1349 trigger
= lttng_trigger_create(condition
, action
);
1351 fail("Failed to create trigger with kernel probe event rule condition and notify action");
1355 trigger_status
= lttng_trigger_set_name(trigger
, trigger_name
);
1356 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
1357 "Setting trigger name to '%s'", trigger_name
);
1359 ret
= lttng_register_trigger(trigger
);
1361 fail("Failed to register trigger with kernel probe event rule condition and notify action");
1365 nc_status
= lttng_notification_channel_subscribe(
1366 notification_channel
, condition
);
1367 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1368 "Subscribe to tracepoint event rule condition");
1370 resume_application();
1372 for (i
= 0; i
< notification_count
; i
++) {
1373 struct lttng_notification
*notification
= get_next_notification(
1374 notification_channel
);
1376 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1377 notification_count
);
1380 if (notification
== NULL
) {
1384 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1385 lttng_notification_destroy(notification
);
1392 suspend_application();
1393 lttng_notification_channel_destroy(notification_channel
);
1394 lttng_unregister_trigger(trigger
);
1395 lttng_trigger_destroy(trigger
);
1396 lttng_action_destroy(action
);
1397 lttng_event_rule_destroy(event_rule
);
1398 lttng_condition_destroy(condition
);
1399 lttng_kernel_probe_location_destroy(location
);
1403 static void test_uprobe_event_rule_notification(
1404 enum lttng_domain_type domain_type
,
1405 const char *testapp_path
,
1406 const char *test_symbol_name
)
1409 const int notification_count
= 3;
1410 enum lttng_notification_channel_status nc_status
;
1411 enum lttng_event_rule_status event_rule_status
;
1412 enum lttng_trigger_status trigger_status
;
1413 struct lttng_notification_channel
*notification_channel
= NULL
;
1414 struct lttng_userspace_probe_location
*probe_location
= NULL
;
1415 struct lttng_userspace_probe_location_lookup_method
*lookup_method
=
1417 struct lttng_condition
*condition
= NULL
;
1418 struct lttng_event_rule
*event_rule
= NULL
;
1419 struct lttng_action
*action
= NULL
;
1420 struct lttng_trigger
*trigger
= NULL
;
1421 const char * const trigger_name
= "uprobe_trigger";
1423 action
= lttng_action_notify_create();
1425 fail("Failed to create notify action");
1429 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1430 if (!lookup_method
) {
1431 fail("Setup error on userspace probe lookup method creation");
1435 probe_location
= lttng_userspace_probe_location_function_create(
1436 testapp_path
, test_symbol_name
, lookup_method
);
1437 if (!probe_location
) {
1438 fail("Failed to create userspace probe location");
1442 notification_channel
= lttng_notification_channel_create(
1443 lttng_session_daemon_notification_endpoint
);
1444 ok(notification_channel
, "Notification channel object creation");
1446 event_rule
= lttng_event_rule_uprobe_create();
1447 ok(event_rule
, "kprobe event rule object creation");
1449 event_rule_status
= lttng_event_rule_uprobe_set_location(
1450 event_rule
, probe_location
);
1451 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1452 "Setting uprobe event rule location");
1454 event_rule_status
= lttng_event_rule_uprobe_set_name(
1455 event_rule
, trigger_name
);
1456 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1457 "Setting uprobe event rule name: '%s'", trigger_name
);
1459 condition
= lttng_condition_event_rule_create(event_rule
);
1460 ok(condition
, "Condition event rule object creation");
1462 /* Register the trigger for condition. */
1463 trigger
= lttng_trigger_create(condition
, action
);
1465 fail("Failed to create trigger with userspace probe event rule condition and notify action");
1469 trigger_status
= lttng_trigger_set_name(trigger
, trigger_name
);
1470 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
1471 "Setting name to trigger '%s'", trigger_name
);
1473 ret
= lttng_register_trigger(trigger
);
1475 fail("Failed to register trigger with userspace probe event rule condition and notify action");
1479 nc_status
= lttng_notification_channel_subscribe(
1480 notification_channel
, condition
);
1481 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1482 "Subscribe to tracepoint event rule condition");
1484 resume_application();
1486 for (i
= 0; i
< 3; i
++) {
1487 struct lttng_notification
*notification
= get_next_notification(
1488 notification_channel
);
1490 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1491 notification_count
);
1494 if (notification
== NULL
) {
1498 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1499 lttng_notification_destroy(notification
);
1505 suspend_application();
1507 lttng_notification_channel_destroy(notification_channel
);
1508 lttng_unregister_trigger(trigger
);
1509 lttng_trigger_destroy(trigger
);
1510 lttng_action_destroy(action
);
1511 lttng_event_rule_destroy(event_rule
);
1512 lttng_condition_destroy(condition
);
1516 static void test_syscall_event_rule_notification(
1517 enum lttng_domain_type domain_type
)
1520 const int notification_count
= 3;
1521 enum lttng_notification_channel_status nc_status
;
1522 enum lttng_event_rule_status event_rule_status
;
1523 enum lttng_trigger_status trigger_status
;
1524 struct lttng_notification_channel
*notification_channel
= NULL
;
1525 struct lttng_condition
*condition
= NULL
;
1526 struct lttng_event_rule
*event_rule
= NULL
;
1527 struct lttng_action
*action
= NULL
;
1528 struct lttng_trigger
*trigger
= NULL
;
1529 const char * const trigger_name
= "syscall_trigger";
1530 const char * const syscall_name
= "openat";
1532 action
= lttng_action_notify_create();
1534 fail("Failed to create notify action");
1538 notification_channel
= lttng_notification_channel_create(
1539 lttng_session_daemon_notification_endpoint
);
1540 ok(notification_channel
, "Notification channel object creation");
1542 event_rule
= lttng_event_rule_syscall_create();
1543 ok(event_rule
, "syscall event rule object creation");
1545 event_rule_status
= lttng_event_rule_syscall_set_pattern(
1546 event_rule
, syscall_name
);
1547 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1548 "Setting syscall event rule pattern: '%s'", syscall_name
);
1550 condition
= lttng_condition_event_rule_create(event_rule
);
1551 ok(condition
, "Condition syscall event rule object creation");
1553 /* Register the trigger for condition. */
1554 trigger
= lttng_trigger_create(condition
, action
);
1556 fail("Failed to create trigger with syscall event rule condition and notify action");
1560 trigger_status
= lttng_trigger_set_name(trigger
, trigger_name
);
1561 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
1562 "Setting name to trigger '%s'", trigger_name
);
1564 ret
= lttng_register_trigger(trigger
);
1566 fail("Failed to register trigger with syscall event rule condition and notify action");
1570 nc_status
= lttng_notification_channel_subscribe(
1571 notification_channel
, condition
);
1572 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1573 "Subscribe to tracepoint event rule condition");
1575 resume_application();
1577 for (i
= 0; i
< notification_count
; i
++) {
1578 struct lttng_notification
*notification
= get_next_notification(
1579 notification_channel
);
1581 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1582 notification_count
);
1585 if (notification
== NULL
) {
1589 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1590 lttng_notification_destroy(notification
);
1596 suspend_application();
1597 lttng_notification_channel_destroy(notification_channel
);
1598 lttng_unregister_trigger(trigger
);
1599 lttng_trigger_destroy(trigger
);
1600 lttng_action_destroy(action
);
1601 lttng_condition_destroy(condition
);
1605 static void test_syscall_event_rule_notification_filter(
1606 enum lttng_domain_type domain_type
)
1609 const int notification_count
= 3;
1610 enum lttng_notification_channel_status nc_status
;
1611 enum lttng_event_rule_status event_rule_status
;
1612 enum lttng_trigger_status trigger_status
;
1613 struct lttng_notification_channel
*notification_channel
= NULL
;
1614 struct lttng_condition
*condition
= NULL
;
1615 struct lttng_event_rule
*event_rule
= NULL
;
1616 struct lttng_action
*action
= NULL
;
1617 struct lttng_trigger
*trigger
= NULL
;
1618 const char * const trigger_name
= "syscall_trigger";
1619 const char * const syscall_name
= "openat";
1620 const char * const filter_pattern
= "filename == \"/proc/cpuinfo\"";
1622 action
= lttng_action_notify_create();
1624 fail("Failed to create notify action");
1628 notification_channel
= lttng_notification_channel_create(
1629 lttng_session_daemon_notification_endpoint
);
1630 ok(notification_channel
, "Notification channel object creation");
1632 event_rule
= lttng_event_rule_syscall_create();
1633 ok(event_rule
, "syscall event rule object creation");
1635 event_rule_status
= lttng_event_rule_syscall_set_pattern(
1636 event_rule
, syscall_name
);
1637 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1638 "Setting syscall event rule pattern: '%s'", syscall_name
);
1640 event_rule_status
= lttng_event_rule_syscall_set_filter(
1641 event_rule
, filter_pattern
);
1642 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1643 "Setting filter: '%s'", filter_pattern
);
1645 condition
= lttng_condition_event_rule_create(event_rule
);
1646 ok(condition
, "Condition event rule object creation");
1648 /* Register the triggers for condition */
1649 trigger
= lttng_trigger_create(condition
, action
);
1651 fail("Failed to create trigger with syscall filtering event rule condition and notify action");
1655 trigger_status
= lttng_trigger_set_name(trigger
, trigger_name
);
1656 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
1657 "Setting name to trigger '%s'", trigger_name
);
1659 ret
= lttng_register_trigger(trigger
);
1661 fail("Failed to register trigger with syscall filtering event rule condition and notify action");
1665 nc_status
= lttng_notification_channel_subscribe(
1666 notification_channel
, condition
);
1667 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1668 "Subscribe to tracepoint event rule condition");
1670 resume_application();
1672 for (i
= 0; i
< notification_count
; i
++) {
1673 struct lttng_notification
*notification
= get_next_notification(
1674 notification_channel
);
1676 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1677 notification_count
);
1680 if (notification
== NULL
) {
1684 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1685 lttng_notification_destroy(notification
);
1692 suspend_application();
1694 lttng_unregister_trigger(trigger
);
1695 lttng_notification_channel_destroy(notification_channel
);
1696 lttng_trigger_destroy(trigger
);
1697 lttng_event_rule_destroy(event_rule
);
1698 lttng_condition_destroy(condition
);
1702 int main(int argc
, const char *argv
[])
1705 const char *domain_type_string
= NULL
;
1706 enum lttng_domain_type domain_type
= LTTNG_DOMAIN_NONE
;
1709 fail("Missing test scenario, domain type, pid, or application state file argument(s)");
1713 test_scenario
= atoi(argv
[1]);
1714 domain_type_string
= argv
[2];
1715 app_pid
= (pid_t
) atoi(argv
[3]);
1716 app_state_file
= argv
[4];
1718 if (!strcmp("LTTNG_DOMAIN_UST", domain_type_string
)) {
1719 domain_type
= LTTNG_DOMAIN_UST
;
1721 if (!strcmp("LTTNG_DOMAIN_KERNEL", domain_type_string
)) {
1722 domain_type
= LTTNG_DOMAIN_KERNEL
;
1724 if (domain_type
== LTTNG_DOMAIN_NONE
) {
1725 fail("Unknown domain type");
1730 * Test cases are responsible for resuming the app when needed
1731 * and making sure it's suspended when returning.
1733 suspend_application();
1735 switch (test_scenario
) {
1740 /* Test cases that need gen-ust-event testapp. */
1741 diag("Test basic notification error paths for %s domain",
1742 domain_type_string
);
1743 test_invalid_channel_subscription(domain_type
);
1745 diag("Test tracepoint event rule notifications for domain %s",
1746 domain_type_string
);
1747 test_tracepoint_event_rule_notification(domain_type
);
1749 diag("Test tracepoint event rule notifications with filter for domain %s",
1750 domain_type_string
);
1751 test_tracepoint_event_rule_notification_filter(domain_type
);
1756 const char *session_name
, *channel_name
;
1758 /* Test cases that need a tracing session enabled. */
1762 * Argument 7 and upward are named pipe location for consumerd
1765 named_pipe_args_start
= 7;
1768 fail("Missing parameter for tests to run %d", argc
);
1774 session_name
= argv
[5];
1775 channel_name
= argv
[6];
1777 test_subscription_twice(session_name
, channel_name
,
1780 diag("Test trigger for domain %s with buffer_usage_low condition",
1781 domain_type_string
);
1782 test_triggers_buffer_usage_condition(session_name
, channel_name
,
1784 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
);
1786 diag("Test trigger for domain %s with buffer_usage_high condition",
1787 domain_type_string
);
1788 test_triggers_buffer_usage_condition(session_name
, channel_name
,
1790 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
);
1792 diag("Test buffer usage notification channel api for domain %s",
1793 domain_type_string
);
1794 test_buffer_usage_notification_channel(session_name
, channel_name
,
1801 * Test cases that need a test app with more than one event
1807 * At the moment, the only test case of this scenario is
1808 * exclusion which is only supported by UST.
1810 assert(domain_type
== LTTNG_DOMAIN_UST
);
1811 diag("Test tracepoint event rule notifications with exclusion for domain %s",
1812 domain_type_string
);
1813 test_tracepoint_event_rule_notification_exclusion(domain_type
);
1820 /* Test cases that need the kernel tracer. */
1821 assert(domain_type
== LTTNG_DOMAIN_KERNEL
);
1823 diag("Test kprobe event rule notifications for domain %s",
1824 domain_type_string
);
1826 test_kprobe_event_rule_notification(domain_type
);
1833 /* Test cases that need the kernel tracer. */
1834 assert(domain_type
== LTTNG_DOMAIN_KERNEL
);
1836 diag("Test syscall event rule notifications for domain %s",
1837 domain_type_string
);
1839 test_syscall_event_rule_notification(domain_type
);
1841 diag("Test syscall filtering event rule notifications for domain %s",
1842 domain_type_string
);
1844 test_syscall_event_rule_notification_filter(domain_type
);
1850 const char *testapp_path
, *test_symbol_name
;
1855 fail("Missing parameter for tests to run %d", argc
);
1859 testapp_path
= argv
[5];
1860 test_symbol_name
= argv
[6];
1861 /* Test cases that need the kernel tracer. */
1862 assert(domain_type
== LTTNG_DOMAIN_KERNEL
);
1864 diag("Test userspace-probe event rule notifications for domain %s",
1865 domain_type_string
);
1867 test_uprobe_event_rule_notification(
1868 domain_type
, testapp_path
, test_symbol_name
);
1877 return exit_status();