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/lttng.h>
32 int named_pipe_args_start
= 0;
34 const char *app_state_file
= NULL
;
36 static const char *get_notification_trigger_name(
37 struct lttng_notification
*notification
)
39 const char *name
= NULL
;
40 enum lttng_evaluation_status status
;
41 const struct lttng_evaluation
*evaluation
;
42 evaluation
= lttng_notification_get_evaluation(notification
);
43 if (evaluation
== NULL
) {
44 fail("lttng_notification_get_evaluation");
48 switch (lttng_evaluation_get_type(evaluation
)) {
49 case LTTNG_CONDITION_TYPE_EVENT_RULE_HIT
:
51 status
= lttng_evaluation_event_rule_get_trigger_name(
53 if (status
!= LTTNG_EVALUATION_STATUS_OK
) {
54 fail("lttng_evaluation_event_rule_get_trigger_name");
61 fail("Wrong notification evaluation type \n");
68 static int validator_notification_trigger_name(
69 struct lttng_notification
*notification
,
70 const char *trigger_name
)
79 name
= get_notification_trigger_name(notification
);
85 name_is_equal
= (strcmp(trigger_name
, name
) == 0);
86 ok(name_is_equal
, "Expected trigger name: %s got %s", trigger_name
,
96 void wait_on_file(const char *path
, bool file_exist
)
105 ret
= stat(path
, &buf
);
106 if (ret
== -1 && errno
== ENOENT
) {
109 * The file does not exist. wait a bit and
110 * continue looping until it does.
112 (void) poll(NULL
, 0, 10);
117 * File does not exist and the exit condition we want.
118 * Break from the loop and return.
127 * stat() returned 0, so the file exists. break now only if
128 * that's the exit condition we want.
137 int write_pipe(const char *path
, uint8_t data
)
142 fd
= open(path
, O_WRONLY
| O_NONBLOCK
);
144 perror("Could not open consumer control named pipe");
148 ret
= write(fd
, &data
, sizeof(data
));
150 perror("Named pipe write failed");
152 perror("Named pipe close failed");
160 perror("Name pipe closing failed");
169 int stop_consumer(const char **argv
)
173 for (i
= named_pipe_args_start
; i
< nb_args
; i
++) {
174 ret
= write_pipe(argv
[i
], 49);
180 int resume_consumer(const char **argv
)
184 for (i
= named_pipe_args_start
; i
< nb_args
; i
++) {
185 ret
= write_pipe(argv
[i
], 0);
191 int suspend_application(void)
196 if (!stat(app_state_file
, &buf
)) {
197 fail("App is already in a suspended state.");
203 * Send SIGUSR1 to application instructing it to bypass tracepoint.
207 ret
= kill(app_pid
, SIGUSR1
);
209 fail("SIGUSR1 failed. errno %d", errno
);
214 wait_on_file(app_state_file
, true);
222 int resume_application(void)
227 ret
= stat(app_state_file
, &buf
);
228 if (ret
== -1 && errno
== ENOENT
) {
229 fail("State file does not exist");
239 ret
= kill(app_pid
, SIGUSR1
);
241 fail("SIGUSR1 failed. errno %d", errno
);
246 wait_on_file(app_state_file
, false);
255 void test_triggers_buffer_usage_condition(const char *session_name
,
256 const char *channel_name
,
257 enum lttng_domain_type domain_type
,
258 enum lttng_condition_type condition_type
)
260 unsigned int test_vector_size
= 5, i
;
261 enum lttng_condition_status condition_status
;
262 struct lttng_action
*action
;
265 action
= lttng_action_notify_create();
267 fail("Setup error on action creation");
271 /* Test lttng_register_trigger with null value */
272 ok(lttng_register_trigger(NULL
) == -LTTNG_ERR_INVALID
, "Registering a NULL trigger fails as expected");
274 /* Test: register a trigger */
276 for (i
= 0; i
< pow(2,test_vector_size
); i
++) {
278 char *test_tuple_string
= NULL
;
279 unsigned int mask_position
= 0;
280 bool session_name_set
= false;
281 bool channel_name_set
= false;
282 bool threshold_ratio_set
= false;
283 bool threshold_byte_set
= false;
284 bool domain_type_set
= false;
286 struct lttng_trigger
*trigger
= NULL
;
287 struct lttng_condition
*condition
= NULL
;
289 /* Create base condition */
290 switch (condition_type
) {
291 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
292 condition
= lttng_condition_buffer_usage_low_create();
294 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
295 condition
= lttng_condition_buffer_usage_high_create();
308 /* Prepare the condition for trigger registration test */
310 /* Set session name */
311 if ((1 << mask_position
) & i
) {
312 condition_status
= lttng_condition_buffer_usage_set_session_name(
313 condition
, session_name
);
314 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
318 session_name_set
= true;
322 /* Set channel name */
323 if ((1 << mask_position
) & i
) {
324 condition_status
= lttng_condition_buffer_usage_set_channel_name(
325 condition
, channel_name
);
326 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
330 channel_name_set
= true;
334 /* Set threshold ratio */
335 if ((1 << mask_position
) & i
) {
336 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
338 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
342 threshold_ratio_set
= true;
346 /* Set threshold byte */
347 if ((1 << mask_position
) & i
) {
348 condition_status
= lttng_condition_buffer_usage_set_threshold(
350 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
354 threshold_byte_set
= true;
358 /* Set domain type */
359 if ((1 << mask_position
) & i
) {
360 condition_status
= lttng_condition_buffer_usage_set_domain_type(
361 condition
, LTTNG_DOMAIN_UST
);
362 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
366 domain_type_set
= true;
370 if (mask_position
!= test_vector_size
-1) {
371 assert("Logic error for test vector generation");
374 loop_ret
= asprintf(&test_tuple_string
, "session name %s, channel name %s, threshold ratio %s, threshold byte %s, domain type %s",
375 session_name_set
? "set" : "unset",
376 channel_name_set
? "set" : "unset",
377 threshold_ratio_set
? "set" : "unset",
378 threshold_byte_set
? "set" : "unset",
379 domain_type_set
? "set" : "unset");
380 if (!test_tuple_string
|| loop_ret
< 0) {
386 trigger
= lttng_trigger_create(condition
, action
);
392 loop_ret
= lttng_register_trigger(trigger
);
396 fail("Setup error occurred for tuple: %s", test_tuple_string
);
400 /* This combination happens three times */
401 if (session_name_set
&& channel_name_set
402 && (threshold_ratio_set
|| threshold_byte_set
)
403 && domain_type_set
) {
404 ok(loop_ret
== 0, "Trigger is registered: %s", test_tuple_string
);
407 * Test that a trigger cannot be registered
410 loop_ret
= lttng_register_trigger(trigger
);
411 ok(loop_ret
== -LTTNG_ERR_TRIGGER_EXISTS
, "Re-register trigger fails as expected: %s", test_tuple_string
);
413 /* Test that a trigger can be unregistered */
414 loop_ret
= lttng_unregister_trigger(trigger
);
415 ok(loop_ret
== 0, "Unregister trigger: %s", test_tuple_string
);
418 * Test that unregistration of a non-previously
419 * registered trigger fail.
421 loop_ret
= lttng_unregister_trigger(trigger
);
422 ok(loop_ret
== -LTTNG_ERR_TRIGGER_NOT_FOUND
, "Unregister of a non-registered trigger fails as expected: %s", test_tuple_string
);
424 ok(loop_ret
== -LTTNG_ERR_INVALID_TRIGGER
, "Trigger is invalid as expected and cannot be registered: %s", test_tuple_string
);
428 free(test_tuple_string
);
429 lttng_trigger_destroy(trigger
);
430 lttng_condition_destroy(condition
);
434 lttng_action_destroy(action
);
438 void wait_data_pending(const char *session_name
)
443 ret
= lttng_data_pending(session_name
);
449 int setup_buffer_usage_condition(struct lttng_condition
*condition
,
450 const char *condition_name
,
451 const char *session_name
,
452 const char *channel_name
,
453 const enum lttng_domain_type domain_type
)
455 enum lttng_condition_status condition_status
;
458 condition_status
= lttng_condition_buffer_usage_set_session_name(
459 condition
, session_name
);
460 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
461 fail("Failed to set session name on creation of condition `%s`",
467 condition_status
= lttng_condition_buffer_usage_set_channel_name(
468 condition
, channel_name
);
469 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
470 fail("Failed to set channel name on creation of condition `%s`",
476 condition_status
= lttng_condition_buffer_usage_set_domain_type(
477 condition
, domain_type
);
478 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
479 fail("Failed to set domain type on creation of condition `%s`",
490 void test_invalid_channel_subscription(
491 const enum lttng_domain_type domain_type
)
493 enum lttng_condition_status condition_status
;
494 enum lttng_notification_channel_status nc_status
;
495 struct lttng_condition
*dummy_condition
= NULL
;
496 struct lttng_condition
*dummy_invalid_condition
= NULL
;
497 struct lttng_notification_channel
*notification_channel
= NULL
;
500 notification_channel
= lttng_notification_channel_create(
501 lttng_session_daemon_notification_endpoint
);
502 ok(notification_channel
, "Notification channel object creation");
503 if (!notification_channel
) {
508 * Create a dummy, empty (thus invalid) condition to test error paths.
510 dummy_invalid_condition
= lttng_condition_buffer_usage_low_create();
511 if (!dummy_invalid_condition
) {
512 fail("Setup error on condition creation");
517 * Test subscription and unsubscription of an invalid condition to/from
520 nc_status
= lttng_notification_channel_subscribe(
521 notification_channel
, dummy_invalid_condition
);
522 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
523 "Subscribing to an invalid condition");
525 nc_status
= lttng_notification_channel_unsubscribe(
526 notification_channel
, dummy_invalid_condition
);
527 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
528 "Unsubscribing from an invalid condition");
530 /* Create a valid dummy condition with a ratio of 0.5 */
531 dummy_condition
= lttng_condition_buffer_usage_low_create();
532 if (!dummy_condition
) {
533 fail("Setup error on dummy_condition creation");
537 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
538 dummy_condition
, 0.5);
539 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
540 fail("Setup error on condition creation");
544 ret
= setup_buffer_usage_condition(dummy_condition
, "dummy_condition",
545 "dummy_session", "dummy_channel", domain_type
);
547 fail("Setup error on dummy condition creation");
552 * Test subscription and unsubscription to/from a channel with invalid
555 nc_status
= lttng_notification_channel_subscribe(NULL
, NULL
);
556 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
557 "Notification channel subscription is invalid: NULL, NULL");
559 nc_status
= lttng_notification_channel_subscribe(
560 notification_channel
, NULL
);
561 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
562 "Notification channel subscription is invalid: NON-NULL, NULL");
564 nc_status
= lttng_notification_channel_subscribe(NULL
, dummy_condition
);
565 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
566 "Notification channel subscription is invalid: NULL, NON-NULL");
568 nc_status
= lttng_notification_channel_unsubscribe(
569 notification_channel
, dummy_condition
);
570 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION
,
571 "Unsubscribing from a valid unknown condition");
574 lttng_notification_channel_destroy(notification_channel
);
575 lttng_condition_destroy(dummy_invalid_condition
);
576 lttng_condition_destroy(dummy_condition
);
580 enum buffer_usage_type
{
581 BUFFER_USAGE_TYPE_LOW
,
582 BUFFER_USAGE_TYPE_HIGH
,
585 static int register_buffer_usage_notify_trigger(const char *session_name
,
586 const char *channel_name
,
587 const enum lttng_domain_type domain_type
,
588 enum buffer_usage_type buffer_usage_type
,
590 struct lttng_condition
**condition
,
591 struct lttng_action
**action
,
592 struct lttng_trigger
**trigger
)
594 enum lttng_condition_status condition_status
;
595 struct lttng_action
*tmp_action
= NULL
;
596 struct lttng_condition
*tmp_condition
= NULL
;
597 struct lttng_trigger
*tmp_trigger
= NULL
;
601 tmp_action
= lttng_action_notify_create();
603 fail("Setup error on action creation");
608 if (buffer_usage_type
== BUFFER_USAGE_TYPE_LOW
) {
609 tmp_condition
= lttng_condition_buffer_usage_low_create();
611 tmp_condition
= lttng_condition_buffer_usage_high_create();
614 if (!tmp_condition
) {
615 fail("Setup error on condition creation");
620 /* Set the buffer usage threashold */
621 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
622 tmp_condition
, ratio
);
623 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
624 fail("Setup error on condition creation");
629 ret
= setup_buffer_usage_condition(tmp_condition
, "condition_name",
630 session_name
, channel_name
, domain_type
);
632 fail("Setup error on condition creation");
637 /* Register the trigger for condition. */
638 tmp_trigger
= lttng_trigger_create(tmp_condition
, tmp_action
);
640 fail("Setup error on trigger creation");
645 ret
= lttng_register_trigger(tmp_trigger
);
647 fail("Setup error on trigger registration");
652 *condition
= tmp_condition
;
653 *trigger
= tmp_trigger
;
654 *action
= tmp_action
;
658 lttng_action_destroy(tmp_action
);
659 lttng_condition_destroy(tmp_condition
);
660 lttng_trigger_destroy(tmp_trigger
);
666 static void test_subscription_twice(const char *session_name
,
667 const char *channel_name
,
668 const enum lttng_domain_type domain_type
)
671 enum lttng_notification_channel_status nc_status
;
673 struct lttng_action
*action
= NULL
;
674 struct lttng_notification_channel
*notification_channel
= NULL
;
675 struct lttng_trigger
*trigger
= NULL
;
677 struct lttng_condition
*condition
= NULL
;
679 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
680 domain_type
, BUFFER_USAGE_TYPE_LOW
, 0.99, &condition
,
683 fail("Setup error on trigger registration");
688 notification_channel
= lttng_notification_channel_create(
689 lttng_session_daemon_notification_endpoint
);
690 ok(notification_channel
, "Notification channel object creation");
691 if (!notification_channel
) {
695 /* Subscribe a valid condition. */
696 nc_status
= lttng_notification_channel_subscribe(
697 notification_channel
, condition
);
698 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
699 "Subscribe to condition");
701 /* Subscribing again should fail. */
702 nc_status
= lttng_notification_channel_subscribe(
703 notification_channel
, condition
);
704 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED
,
705 "Subscribe to a condition for which subscription was already done");
708 lttng_unregister_trigger(trigger
);
709 lttng_trigger_destroy(trigger
);
710 lttng_notification_channel_destroy(notification_channel
);
711 lttng_action_destroy(action
);
712 lttng_condition_destroy(condition
);
715 static void test_buffer_usage_notification_channel(const char *session_name
,
716 const char *channel_name
,
717 const enum lttng_domain_type domain_type
,
721 enum lttng_notification_channel_status nc_status
;
723 struct lttng_action
*low_action
= NULL
;
724 struct lttng_action
*high_action
= NULL
;
725 struct lttng_notification
*notification
= NULL
;
726 struct lttng_notification_channel
*notification_channel
= NULL
;
727 struct lttng_trigger
*low_trigger
= NULL
;
728 struct lttng_trigger
*high_trigger
= NULL
;
730 struct lttng_condition
*low_condition
= NULL
;
731 struct lttng_condition
*high_condition
= NULL
;
733 const double low_ratio
= 0.0;
734 const double high_ratio
= 0.90;
736 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
737 domain_type
, BUFFER_USAGE_TYPE_LOW
, low_ratio
,
738 &low_condition
, &low_action
, &low_trigger
);
740 fail("Setup error on low trigger registration");
744 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
745 domain_type
, BUFFER_USAGE_TYPE_HIGH
, high_ratio
,
746 &high_condition
, &high_action
, &high_trigger
);
748 fail("Setup error on high trigger registration");
753 notification_channel
= lttng_notification_channel_create(
754 lttng_session_daemon_notification_endpoint
);
755 ok(notification_channel
, "Notification channel object creation");
756 if (!notification_channel
) {
760 /* Subscribe a valid low condition */
761 nc_status
= lttng_notification_channel_subscribe(
762 notification_channel
, low_condition
);
763 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
764 "Subscribe to low condition");
766 /* Subscribe a valid high condition */
767 nc_status
= lttng_notification_channel_subscribe(
768 notification_channel
, high_condition
);
769 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
770 "Subscribe to high condition");
772 resume_application();
774 /* Wait for notification to happen */
776 lttng_start_tracing(session_name
);
778 /* Wait for high notification */
780 nc_status
= lttng_notification_channel_get_next_notification(
781 notification_channel
, ¬ification
);
782 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
783 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
784 lttng_condition_get_type(lttng_notification_get_condition(
786 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
787 "High notification received after intermediary communication");
788 lttng_notification_destroy(notification
);
791 suspend_application();
792 lttng_stop_tracing_no_wait(session_name
);
793 resume_consumer(argv
);
794 wait_data_pending(session_name
);
797 * Test that communication still work even if there is notification
798 * waiting for consumption.
801 nc_status
= lttng_notification_channel_unsubscribe(
802 notification_channel
, low_condition
);
803 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
804 "Unsubscribe with pending notification");
806 nc_status
= lttng_notification_channel_subscribe(
807 notification_channel
, low_condition
);
808 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
809 "Subscribe with pending notification");
812 nc_status
= lttng_notification_channel_get_next_notification(
813 notification_channel
, ¬ification
);
814 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
815 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
816 lttng_condition_get_type(lttng_notification_get_condition(
818 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
,
819 "Low notification received after intermediary communication");
820 lttng_notification_destroy(notification
);
823 /* Stop consumer to force a high notification */
825 resume_application();
826 lttng_start_tracing(session_name
);
829 nc_status
= lttng_notification_channel_get_next_notification(
830 notification_channel
, ¬ification
);
831 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
832 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
833 lttng_condition_get_type(lttng_notification_get_condition(
835 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
836 "High notification received after intermediary communication");
837 lttng_notification_destroy(notification
);
840 suspend_application();
841 lttng_stop_tracing_no_wait(session_name
);
842 resume_consumer(argv
);
843 wait_data_pending(session_name
);
846 nc_status
= lttng_notification_channel_get_next_notification(
847 notification_channel
, ¬ification
);
848 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
849 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
850 lttng_condition_get_type(lttng_notification_get_condition(
852 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
,
853 "Low notification received after re-subscription");
854 lttng_notification_destroy(notification
);
858 resume_application();
859 /* Stop consumer to force a high notification */
860 lttng_start_tracing(session_name
);
863 nc_status
= lttng_notification_channel_get_next_notification(
864 notification_channel
, ¬ification
);
865 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
866 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
867 lttng_condition_get_type(lttng_notification_get_condition(
869 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
870 "High notification");
871 lttng_notification_destroy(notification
);
874 suspend_application();
876 /* Resume consumer to allow event consumption */
877 lttng_stop_tracing_no_wait(session_name
);
878 resume_consumer(argv
);
879 wait_data_pending(session_name
);
881 nc_status
= lttng_notification_channel_unsubscribe(
882 notification_channel
, low_condition
);
883 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
884 "Unsubscribe low condition with pending notification");
886 nc_status
= lttng_notification_channel_unsubscribe(
887 notification_channel
, high_condition
);
888 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
889 "Unsubscribe high condition with pending notification");
892 lttng_notification_channel_destroy(notification_channel
);
893 lttng_trigger_destroy(low_trigger
);
894 lttng_trigger_destroy(high_trigger
);
895 lttng_action_destroy(low_action
);
896 lttng_action_destroy(high_action
);
897 lttng_condition_destroy(low_condition
);
898 lttng_condition_destroy(high_condition
);
901 static void create_tracepoint_event_rule_trigger(const char *event_pattern
,
902 const char *trigger_name
,
904 unsigned int exclusion_count
,
905 const char * const *exclusions
,
906 enum lttng_domain_type domain_type
,
907 struct lttng_condition
**condition
,
908 struct lttng_trigger
**trigger
)
910 enum lttng_event_rule_status event_rule_status
;
911 enum lttng_trigger_status trigger_status
;
913 struct lttng_action
*tmp_action
= NULL
;
914 struct lttng_event_rule
*event_rule
= NULL
;
915 struct lttng_condition
*tmp_condition
= NULL
;
916 struct lttng_trigger
*tmp_trigger
= NULL
;
919 assert(event_pattern
);
920 assert(trigger_name
);
924 event_rule
= lttng_event_rule_tracepoint_create(domain_type
);
925 ok(event_rule
, "Tracepoint event rule object creation");
927 event_rule_status
= lttng_event_rule_tracepoint_set_pattern(
928 event_rule
, event_pattern
);
929 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
930 "Setting tracepoint event rule pattern: '%s'",
934 event_rule_status
= lttng_event_rule_tracepoint_set_filter(
936 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
937 "Setting tracepoint event rule filter: '%s'",
945 assert(domain_type
== LTTNG_DOMAIN_UST
);
946 assert(exclusion_count
> 0);
948 for (i
= 0; i
< exclusion_count
; i
++) {
950 lttng_event_rule_tracepoint_add_exclusion(
953 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
954 fail("Setting tracepoint event rule exclusion '%s'.",
960 ok(success
, "Setting tracepoint event rule exclusions");
963 tmp_condition
= lttng_condition_event_rule_create(event_rule
);
964 ok(tmp_condition
, "Condition event rule object creation");
966 tmp_action
= lttng_action_notify_create();
967 ok(tmp_action
, "Action event rule object creation");
969 tmp_trigger
= lttng_trigger_create(tmp_condition
, tmp_action
);
970 ok(tmp_trigger
, "Trigger object creation %s", trigger_name
);
972 trigger_status
= lttng_trigger_set_name(tmp_trigger
, trigger_name
);
973 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
974 "Setting name to trigger %s", trigger_name
);
976 ret
= lttng_register_trigger(tmp_trigger
);
977 ok(ret
== 0, "Trigger registration %s", trigger_name
);
979 lttng_event_rule_destroy(event_rule
);
981 *condition
= tmp_condition
;
982 *trigger
= tmp_trigger
;
987 static struct lttng_notification
*get_next_notification(
988 struct lttng_notification_channel
*notification_channel
)
990 struct lttng_notification
*local_notification
= NULL
;
991 enum lttng_notification_channel_status status
;
993 /* Receive the next notification. */
994 status
= lttng_notification_channel_get_next_notification(
995 notification_channel
, &local_notification
);
998 case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
:
1000 case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED
:
1001 fail("Notifications have been dropped");
1002 local_notification
= NULL
;
1005 /* Unhandled conditions / errors. */
1006 fail("Failed to get next notification (unknown notification channel status): status = %d",
1008 local_notification
= NULL
;
1012 return local_notification
;
1015 static void test_tracepoint_event_rule_notification(
1016 enum lttng_domain_type domain_type
)
1020 const int notification_count
= 3;
1021 enum lttng_notification_channel_status nc_status
;
1022 struct lttng_action
*action
= NULL
;
1023 struct lttng_condition
*condition
= NULL
;
1024 struct lttng_notification_channel
*notification_channel
= NULL
;
1025 struct lttng_trigger
*trigger
= NULL
;
1026 const char * const trigger_name
= "my_precious";
1027 const char *pattern
;
1029 if (domain_type
== LTTNG_DOMAIN_UST
) {
1030 pattern
= "tp:tptest";
1032 pattern
= "lttng_test_filter_event";
1035 create_tracepoint_event_rule_trigger(pattern
, trigger_name
, NULL
, 0,
1036 NULL
, domain_type
, &condition
, &trigger
);
1038 notification_channel
= lttng_notification_channel_create(
1039 lttng_session_daemon_notification_endpoint
);
1040 ok(notification_channel
, "Notification channel object creation");
1042 nc_status
= lttng_notification_channel_subscribe(
1043 notification_channel
, condition
);
1044 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1045 "Subscribe to tracepoint event rule condition");
1047 resume_application();
1049 /* Get notifications. */
1050 for (i
= 0; i
< notification_count
; i
++) {
1051 struct lttng_notification
*notification
= get_next_notification(
1052 notification_channel
);
1054 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1055 notification_count
);
1058 if (notification
== NULL
) {
1062 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1063 lttng_notification_destroy(notification
);
1070 suspend_application();
1071 lttng_notification_channel_destroy(notification_channel
);
1072 lttng_unregister_trigger(trigger
);
1073 lttng_trigger_destroy(trigger
);
1074 lttng_action_destroy(action
);
1075 lttng_condition_destroy(condition
);
1079 static void test_tracepoint_event_rule_notification_filter(
1080 enum lttng_domain_type domain_type
)
1083 const int notification_count
= 3;
1084 enum lttng_notification_channel_status nc_status
;
1085 struct lttng_condition
*ctrl_condition
= NULL
, *condition
= NULL
;
1086 struct lttng_notification_channel
*notification_channel
= NULL
;
1087 struct lttng_trigger
*ctrl_trigger
= NULL
, *trigger
= NULL
;
1088 const char * const ctrl_trigger_name
= "control_trigger";
1089 const char * const trigger_name
= "trigger";
1090 const char *pattern
;
1091 int ctrl_count
= 0, count
= 0;
1093 if (domain_type
== LTTNG_DOMAIN_UST
) {
1094 pattern
= "tp:tptest";
1096 pattern
= "lttng_test_filter_event";
1099 notification_channel
= lttng_notification_channel_create(
1100 lttng_session_daemon_notification_endpoint
);
1101 ok(notification_channel
, "Notification channel object creation");
1103 create_tracepoint_event_rule_trigger(pattern
, ctrl_trigger_name
, NULL
,
1104 0, NULL
, domain_type
, &ctrl_condition
, &ctrl_trigger
);
1106 nc_status
= lttng_notification_channel_subscribe(
1107 notification_channel
, ctrl_condition
);
1108 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1109 "Subscribe to tracepoint event rule condition");
1112 * Attach a filter expression to get notification only if the
1113 * `intfield` is even.
1115 create_tracepoint_event_rule_trigger(pattern
, trigger_name
,
1116 "(intfield & 1) == 0", 0, NULL
, domain_type
, &condition
,
1119 nc_status
= lttng_notification_channel_subscribe(
1120 notification_channel
, condition
);
1121 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1122 "Subscribe to tracepoint event rule condition");
1125 * We registered 2 notifications triggers, one with a filter and one
1126 * without (control). The one with a filter will only fired when the
1127 * `intfield` is a multiple of 2. We should get two times as many
1128 * control notifications as filter notifications.
1130 resume_application();
1133 * Get 3 notifications. We should get 1 for the regular trigger (with
1134 * the filter) and 2 from the control trigger. This works whatever
1135 * the order we receive the notifications.
1137 for (i
= 0; i
< notification_count
; i
++) {
1139 struct lttng_notification
*notification
= get_next_notification(
1140 notification_channel
);
1142 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1143 notification_count
);
1146 if (notification
== NULL
) {
1150 name
= get_notification_trigger_name(notification
);
1152 lttng_notification_destroy(notification
);
1156 if (strcmp(ctrl_trigger_name
, name
) == 0) {
1158 } else if (strcmp(trigger_name
, name
) == 0) {
1162 lttng_notification_destroy(notification
);
1165 ok(ctrl_count
/ 2 == count
,
1166 "Get twice as many control notif as of regular notif");
1169 suspend_application();
1171 lttng_unregister_trigger(trigger
);
1172 lttng_unregister_trigger(ctrl_trigger
);
1173 lttng_notification_channel_destroy(notification_channel
);
1174 lttng_trigger_destroy(trigger
);
1175 lttng_trigger_destroy(ctrl_trigger
);
1176 lttng_condition_destroy(condition
);
1177 lttng_condition_destroy(ctrl_condition
);
1180 static void test_tracepoint_event_rule_notification_exclusion(
1181 enum lttng_domain_type domain_type
)
1183 enum lttng_notification_channel_status nc_status
;
1184 struct lttng_condition
*ctrl_condition
= NULL
, *condition
= NULL
;
1185 struct lttng_notification_channel
*notification_channel
= NULL
;
1186 struct lttng_trigger
*ctrl_trigger
= NULL
, *trigger
= NULL
;
1187 int ctrl_count
= 0, count
= 0, i
;
1188 const int notification_count
= 6;
1189 const char * const ctrl_trigger_name
= "control_exclusion_trigger";
1190 const char * const trigger_name
= "exclusion_trigger";
1191 const char * const pattern
= "tp:tptest*";
1192 const char * const exclusions
[] = {
1199 notification_channel
= lttng_notification_channel_create(
1200 lttng_session_daemon_notification_endpoint
);
1201 ok(notification_channel
, "Notification channel object creation");
1203 create_tracepoint_event_rule_trigger(pattern
, ctrl_trigger_name
, NULL
,
1204 0, NULL
, domain_type
, &ctrl_condition
, &ctrl_trigger
);
1206 nc_status
= lttng_notification_channel_subscribe(
1207 notification_channel
, ctrl_condition
);
1208 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1209 "Subscribe to tracepoint event rule condition");
1211 create_tracepoint_event_rule_trigger(pattern
, trigger_name
, NULL
, 4,
1212 exclusions
, domain_type
, &condition
, &trigger
);
1214 nc_status
= lttng_notification_channel_subscribe(
1215 notification_channel
, condition
);
1216 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1217 "Subscribe to tracepoint event rule condition");
1220 * We registered 2 notifications triggers, one with an exclusion and
1221 * one without (control).
1222 * - The trigger with an exclusion will fire once every iteration.
1223 * - The trigger without an exclusion will fire 5 times every
1226 * We should get 5 times as many notifications from the control
1229 resume_application();
1232 * Get 6 notifications. We should get 1 for the regular trigger (with
1233 * the exclusion) and 5 from the control trigger. This works whatever
1234 * the order we receive the notifications.
1236 for (i
= 0; i
< notification_count
; i
++) {
1238 struct lttng_notification
*notification
= get_next_notification(
1239 notification_channel
);
1241 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1242 notification_count
);
1245 if (notification
== NULL
) {
1249 name
= get_notification_trigger_name(notification
);
1251 lttng_notification_destroy(notification
);
1255 if (strcmp(ctrl_trigger_name
, name
) == 0) {
1257 } else if (strcmp(trigger_name
, name
) == 0) {
1261 lttng_notification_destroy(notification
);
1264 ok(ctrl_count
/ 5 == count
,
1265 "Got 5 times as many control notif as of regular notif");
1268 suspend_application();
1270 lttng_unregister_trigger(trigger
);
1271 lttng_unregister_trigger(ctrl_trigger
);
1272 lttng_notification_channel_destroy(notification_channel
);
1273 lttng_trigger_destroy(trigger
);
1274 lttng_trigger_destroy(ctrl_trigger
);
1275 lttng_condition_destroy(condition
);
1276 lttng_condition_destroy(ctrl_condition
);
1280 static void test_kprobe_event_rule_notification(
1281 enum lttng_domain_type domain_type
)
1284 const int notification_count
= 3;
1285 enum lttng_notification_channel_status nc_status
;
1286 enum lttng_event_rule_status event_rule_status
;
1287 enum lttng_trigger_status trigger_status
;
1288 struct lttng_notification_channel
*notification_channel
= NULL
;
1289 struct lttng_condition
*condition
= NULL
;
1290 struct lttng_kernel_probe_location
*location
= NULL
;
1291 struct lttng_event_rule
*event_rule
= NULL
;
1292 struct lttng_action
*action
= NULL
;
1293 struct lttng_trigger
*trigger
= NULL
;
1294 const char * const trigger_name
= "kprobe_trigger";
1295 const char * const symbol_name
= "lttng_test_filter_event_write";
1297 action
= lttng_action_notify_create();
1299 fail("Failed to create notify action");
1303 location
= lttng_kernel_probe_location_symbol_create(symbol_name
, 0);
1305 fail("Failed to create kernel probe location");
1309 notification_channel
= lttng_notification_channel_create(
1310 lttng_session_daemon_notification_endpoint
);
1311 ok(notification_channel
, "Notification channel object creation");
1313 event_rule
= lttng_event_rule_kprobe_create();
1314 ok(event_rule
, "kprobe event rule object creation");
1316 event_rule_status
= lttng_event_rule_kprobe_set_location(
1317 event_rule
, location
);
1318 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1319 "Setting kprobe event rule location: '%s'", symbol_name
);
1321 event_rule_status
= lttng_event_rule_kprobe_set_name(
1322 event_rule
, trigger_name
);
1323 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1324 "Setting kprobe event rule name: '%s'", trigger_name
);
1326 condition
= lttng_condition_event_rule_create(event_rule
);
1327 ok(condition
, "Condition event rule object creation");
1329 /* Register the trigger for condition. */
1330 trigger
= lttng_trigger_create(condition
, action
);
1332 fail("Failed to create trigger with kernel probe event rule condition and notify action");
1336 trigger_status
= lttng_trigger_set_name(trigger
, trigger_name
);
1337 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
1338 "Setting trigger name to '%s'", trigger_name
);
1340 ret
= lttng_register_trigger(trigger
);
1342 fail("Failed to register trigger with kernel probe event rule condition and notify action");
1346 nc_status
= lttng_notification_channel_subscribe(
1347 notification_channel
, condition
);
1348 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1349 "Subscribe to tracepoint event rule condition");
1351 resume_application();
1353 for (i
= 0; i
< notification_count
; i
++) {
1354 struct lttng_notification
*notification
= get_next_notification(
1355 notification_channel
);
1357 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1358 notification_count
);
1361 if (notification
== NULL
) {
1365 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1366 lttng_notification_destroy(notification
);
1373 suspend_application();
1374 lttng_notification_channel_destroy(notification_channel
);
1375 lttng_unregister_trigger(trigger
);
1376 lttng_trigger_destroy(trigger
);
1377 lttng_action_destroy(action
);
1378 lttng_event_rule_destroy(event_rule
);
1379 lttng_condition_destroy(condition
);
1380 lttng_kernel_probe_location_destroy(location
);
1384 static void test_uprobe_event_rule_notification(
1385 enum lttng_domain_type domain_type
,
1386 const char *testapp_path
,
1387 const char *test_symbol_name
)
1390 const int notification_count
= 3;
1391 enum lttng_notification_channel_status nc_status
;
1392 enum lttng_event_rule_status event_rule_status
;
1393 enum lttng_trigger_status trigger_status
;
1394 struct lttng_notification_channel
*notification_channel
= NULL
;
1395 struct lttng_userspace_probe_location
*probe_location
= NULL
;
1396 struct lttng_userspace_probe_location_lookup_method
*lookup_method
=
1398 struct lttng_condition
*condition
= NULL
;
1399 struct lttng_event_rule
*event_rule
= NULL
;
1400 struct lttng_action
*action
= NULL
;
1401 struct lttng_trigger
*trigger
= NULL
;
1402 const char * const trigger_name
= "uprobe_trigger";
1404 action
= lttng_action_notify_create();
1406 fail("Failed to create notify action");
1410 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1411 if (!lookup_method
) {
1412 fail("Setup error on userspace probe lookup method creation");
1416 probe_location
= lttng_userspace_probe_location_function_create(
1417 testapp_path
, test_symbol_name
, lookup_method
);
1418 if (!probe_location
) {
1419 fail("Failed to create userspace probe location");
1423 notification_channel
= lttng_notification_channel_create(
1424 lttng_session_daemon_notification_endpoint
);
1425 ok(notification_channel
, "Notification channel object creation");
1427 event_rule
= lttng_event_rule_uprobe_create();
1428 ok(event_rule
, "kprobe event rule object creation");
1430 event_rule_status
= lttng_event_rule_uprobe_set_location(
1431 event_rule
, probe_location
);
1432 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1433 "Setting uprobe event rule location");
1435 event_rule_status
= lttng_event_rule_uprobe_set_name(
1436 event_rule
, trigger_name
);
1437 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1438 "Setting uprobe event rule name: '%s'", trigger_name
);
1440 condition
= lttng_condition_event_rule_create(event_rule
);
1441 ok(condition
, "Condition event rule object creation");
1443 /* Register the trigger for condition. */
1444 trigger
= lttng_trigger_create(condition
, action
);
1446 fail("Failed to create trigger with userspace probe event rule condition and notify action");
1450 trigger_status
= lttng_trigger_set_name(trigger
, trigger_name
);
1451 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
1452 "Setting name to trigger '%s'", trigger_name
);
1454 ret
= lttng_register_trigger(trigger
);
1456 fail("Failed to register trigger with userspace probe event rule condition and notify action");
1460 nc_status
= lttng_notification_channel_subscribe(
1461 notification_channel
, condition
);
1462 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1463 "Subscribe to tracepoint event rule condition");
1465 resume_application();
1467 for (i
= 0; i
< 3; i
++) {
1468 struct lttng_notification
*notification
= get_next_notification(
1469 notification_channel
);
1471 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1472 notification_count
);
1475 if (notification
== NULL
) {
1479 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1480 lttng_notification_destroy(notification
);
1486 suspend_application();
1488 lttng_notification_channel_destroy(notification_channel
);
1489 lttng_unregister_trigger(trigger
);
1490 lttng_trigger_destroy(trigger
);
1491 lttng_action_destroy(action
);
1492 lttng_userspace_probe_location_destroy(probe_location
);
1493 lttng_event_rule_destroy(event_rule
);
1494 lttng_condition_destroy(condition
);
1498 static void test_syscall_event_rule_notification(
1499 enum lttng_domain_type domain_type
)
1502 const int notification_count
= 3;
1503 enum lttng_notification_channel_status nc_status
;
1504 enum lttng_event_rule_status event_rule_status
;
1505 enum lttng_trigger_status trigger_status
;
1506 struct lttng_notification_channel
*notification_channel
= NULL
;
1507 struct lttng_condition
*condition
= NULL
;
1508 struct lttng_event_rule
*event_rule
= NULL
;
1509 struct lttng_action
*action
= NULL
;
1510 struct lttng_trigger
*trigger
= NULL
;
1511 const char * const trigger_name
= "syscall_trigger";
1512 const char * const syscall_name
= "openat";
1514 action
= lttng_action_notify_create();
1516 fail("Failed to create notify action");
1520 notification_channel
= lttng_notification_channel_create(
1521 lttng_session_daemon_notification_endpoint
);
1522 ok(notification_channel
, "Notification channel object creation");
1524 event_rule
= lttng_event_rule_syscall_create();
1525 ok(event_rule
, "syscall event rule object creation");
1527 event_rule_status
= lttng_event_rule_syscall_set_pattern(
1528 event_rule
, syscall_name
);
1529 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1530 "Setting syscall event rule pattern: '%s'", syscall_name
);
1532 condition
= lttng_condition_event_rule_create(event_rule
);
1533 ok(condition
, "Condition syscall event rule object creation");
1535 /* Register the trigger for condition. */
1536 trigger
= lttng_trigger_create(condition
, action
);
1538 fail("Failed to create trigger with syscall event rule condition and notify action");
1542 trigger_status
= lttng_trigger_set_name(trigger
, trigger_name
);
1543 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
1544 "Setting name to trigger '%s'", trigger_name
);
1546 ret
= lttng_register_trigger(trigger
);
1548 fail("Failed to register trigger with syscall event rule condition and notify action");
1552 nc_status
= lttng_notification_channel_subscribe(
1553 notification_channel
, condition
);
1554 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1555 "Subscribe to tracepoint event rule condition");
1557 resume_application();
1559 for (i
= 0; i
< notification_count
; i
++) {
1560 struct lttng_notification
*notification
= get_next_notification(
1561 notification_channel
);
1563 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1564 notification_count
);
1567 if (notification
== NULL
) {
1571 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1572 lttng_notification_destroy(notification
);
1578 suspend_application();
1579 lttng_notification_channel_destroy(notification_channel
);
1580 lttng_unregister_trigger(trigger
);
1581 lttng_trigger_destroy(trigger
);
1582 lttng_action_destroy(action
);
1583 lttng_condition_destroy(condition
);
1587 static void test_syscall_event_rule_notification_filter(
1588 enum lttng_domain_type domain_type
)
1591 const int notification_count
= 3;
1592 enum lttng_notification_channel_status nc_status
;
1593 enum lttng_event_rule_status event_rule_status
;
1594 enum lttng_trigger_status trigger_status
;
1595 struct lttng_notification_channel
*notification_channel
= NULL
;
1596 struct lttng_condition
*condition
= NULL
;
1597 struct lttng_event_rule
*event_rule
= NULL
;
1598 struct lttng_action
*action
= NULL
;
1599 struct lttng_trigger
*trigger
= NULL
;
1600 const char * const trigger_name
= "syscall_trigger";
1601 const char * const syscall_name
= "openat";
1602 const char * const filter_pattern
= "filename == \"/proc/cpuinfo\"";
1604 action
= lttng_action_notify_create();
1606 fail("Failed to create notify action");
1610 notification_channel
= lttng_notification_channel_create(
1611 lttng_session_daemon_notification_endpoint
);
1612 ok(notification_channel
, "Notification channel object creation");
1614 event_rule
= lttng_event_rule_syscall_create();
1615 ok(event_rule
, "syscall event rule object creation");
1617 event_rule_status
= lttng_event_rule_syscall_set_pattern(
1618 event_rule
, syscall_name
);
1619 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1620 "Setting syscall event rule pattern: '%s'", syscall_name
);
1622 event_rule_status
= lttng_event_rule_syscall_set_filter(
1623 event_rule
, filter_pattern
);
1624 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1625 "Setting filter: '%s'", filter_pattern
);
1627 condition
= lttng_condition_event_rule_create(event_rule
);
1628 ok(condition
, "Condition event rule object creation");
1630 /* Register the triggers for condition */
1631 trigger
= lttng_trigger_create(condition
, action
);
1633 fail("Failed to create trigger with syscall filtering event rule condition and notify action");
1637 trigger_status
= lttng_trigger_set_name(trigger
, trigger_name
);
1638 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
1639 "Setting name to trigger '%s'", trigger_name
);
1641 ret
= lttng_register_trigger(trigger
);
1643 fail("Failed to register trigger with syscall filtering event rule condition and notify action");
1647 nc_status
= lttng_notification_channel_subscribe(
1648 notification_channel
, condition
);
1649 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1650 "Subscribe to tracepoint event rule condition");
1652 resume_application();
1654 for (i
= 0; i
< notification_count
; i
++) {
1655 struct lttng_notification
*notification
= get_next_notification(
1656 notification_channel
);
1658 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1659 notification_count
);
1662 if (notification
== NULL
) {
1666 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1667 lttng_notification_destroy(notification
);
1674 suspend_application();
1676 lttng_unregister_trigger(trigger
);
1677 lttng_notification_channel_destroy(notification_channel
);
1678 lttng_trigger_destroy(trigger
);
1679 lttng_event_rule_destroy(event_rule
);
1680 lttng_condition_destroy(condition
);
1684 int main(int argc
, const char *argv
[])
1687 const char *domain_type_string
= NULL
;
1688 enum lttng_domain_type domain_type
= LTTNG_DOMAIN_NONE
;
1691 fail("Missing test scenario, domain type, pid, or application state file argument(s)");
1695 test_scenario
= atoi(argv
[1]);
1696 domain_type_string
= argv
[2];
1697 app_pid
= (pid_t
) atoi(argv
[3]);
1698 app_state_file
= argv
[4];
1700 if (!strcmp("LTTNG_DOMAIN_UST", domain_type_string
)) {
1701 domain_type
= LTTNG_DOMAIN_UST
;
1703 if (!strcmp("LTTNG_DOMAIN_KERNEL", domain_type_string
)) {
1704 domain_type
= LTTNG_DOMAIN_KERNEL
;
1706 if (domain_type
== LTTNG_DOMAIN_NONE
) {
1707 fail("Unknown domain type");
1712 * Test cases are responsible for resuming the app when needed
1713 * and making sure it's suspended when returning.
1715 suspend_application();
1717 switch (test_scenario
) {
1722 /* Test cases that need gen-ust-event testapp. */
1723 diag("Test basic notification error paths for %s domain",
1724 domain_type_string
);
1725 test_invalid_channel_subscription(domain_type
);
1727 diag("Test tracepoint event rule notifications for domain %s",
1728 domain_type_string
);
1729 test_tracepoint_event_rule_notification(domain_type
);
1731 diag("Test tracepoint event rule notifications with filter for domain %s",
1732 domain_type_string
);
1733 test_tracepoint_event_rule_notification_filter(domain_type
);
1738 const char *session_name
, *channel_name
;
1740 /* Test cases that need a tracing session enabled. */
1744 * Argument 7 and upward are named pipe location for consumerd
1747 named_pipe_args_start
= 7;
1750 fail("Missing parameter for tests to run %d", argc
);
1756 session_name
= argv
[5];
1757 channel_name
= argv
[6];
1759 test_subscription_twice(session_name
, channel_name
,
1762 diag("Test trigger for domain %s with buffer_usage_low condition",
1763 domain_type_string
);
1764 test_triggers_buffer_usage_condition(session_name
, channel_name
,
1766 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
);
1768 diag("Test trigger for domain %s with buffer_usage_high condition",
1769 domain_type_string
);
1770 test_triggers_buffer_usage_condition(session_name
, channel_name
,
1772 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
);
1774 diag("Test buffer usage notification channel api for domain %s",
1775 domain_type_string
);
1776 test_buffer_usage_notification_channel(session_name
, channel_name
,
1783 * Test cases that need a test app with more than one event
1789 * At the moment, the only test case of this scenario is
1790 * exclusion which is only supported by UST.
1792 assert(domain_type
== LTTNG_DOMAIN_UST
);
1793 diag("Test tracepoint event rule notifications with exclusion for domain %s",
1794 domain_type_string
);
1795 test_tracepoint_event_rule_notification_exclusion(domain_type
);
1802 /* Test cases that need the kernel tracer. */
1803 assert(domain_type
== LTTNG_DOMAIN_KERNEL
);
1805 diag("Test kprobe event rule notifications for domain %s",
1806 domain_type_string
);
1808 test_kprobe_event_rule_notification(domain_type
);
1815 /* Test cases that need the kernel tracer. */
1816 assert(domain_type
== LTTNG_DOMAIN_KERNEL
);
1818 diag("Test syscall event rule notifications for domain %s",
1819 domain_type_string
);
1821 test_syscall_event_rule_notification(domain_type
);
1823 diag("Test syscall filtering event rule notifications for domain %s",
1824 domain_type_string
);
1826 test_syscall_event_rule_notification_filter(domain_type
);
1832 const char *testapp_path
, *test_symbol_name
;
1837 fail("Missing parameter for tests to run %d", argc
);
1841 testapp_path
= argv
[5];
1842 test_symbol_name
= argv
[6];
1843 /* Test cases that need the kernel tracer. */
1844 assert(domain_type
== LTTNG_DOMAIN_KERNEL
);
1846 diag("Test userspace-probe event rule notifications for domain %s",
1847 domain_type_string
);
1849 test_uprobe_event_rule_notification(
1850 domain_type
, testapp_path
, test_symbol_name
);
1859 return exit_status();