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/trigger/trigger.h>
45 #include <lttng/userspace-probe.h>
50 int named_pipe_args_start
= 0;
52 const char *app_state_file
= NULL
;
55 void wait_on_file(const char *path
, bool file_exist
)
64 ret
= stat(path
, &buf
);
65 if (ret
== -1 && errno
== ENOENT
) {
68 * The file does not exist. wait a bit and
69 * continue looping until it does.
71 (void) poll(NULL
, 0, 10);
76 * File does not exist and the exit condition we want.
77 * Break from the loop and return.
86 * stat() returned 0, so the file exists. break now only if
87 * that's the exit condition we want.
96 int write_pipe(const char *path
, uint8_t data
)
101 fd
= open(path
, O_WRONLY
| O_NONBLOCK
);
103 perror("Could not open consumer control named pipe");
107 ret
= write(fd
, &data
, sizeof(data
));
109 perror("Named pipe write failed");
111 perror("Named pipe close failed");
119 perror("Name pipe closing failed");
128 int stop_consumer(const char **argv
)
132 for (i
= named_pipe_args_start
; i
< nb_args
; i
++) {
133 ret
= write_pipe(argv
[i
], 49);
139 int resume_consumer(const char **argv
)
143 for (i
= named_pipe_args_start
; i
< nb_args
; i
++) {
144 ret
= write_pipe(argv
[i
], 0);
150 int suspend_application(void)
155 if (!stat(app_state_file
, &buf
)) {
156 fail("App is already in a suspended state.");
162 * Send SIGUSR1 to application instructing it to bypass tracepoint.
166 ret
= kill(app_pid
, SIGUSR1
);
168 fail("SIGUSR1 failed. errno %d", errno
);
173 wait_on_file(app_state_file
, true);
181 int resume_application(void)
186 ret
= stat(app_state_file
, &buf
);
187 if (ret
== -1 && errno
== ENOENT
) {
188 fail("State file does not exist");
198 ret
= kill(app_pid
, SIGUSR1
);
200 fail("SIGUSR1 failed. errno %d", errno
);
205 wait_on_file(app_state_file
, false);
214 void test_triggers_buffer_usage_condition(const char *session_name
,
215 const char *channel_name
,
216 enum lttng_domain_type domain_type
,
217 enum lttng_condition_type condition_type
)
219 unsigned int test_vector_size
= 5, i
;
220 enum lttng_condition_status condition_status
;
221 struct lttng_action
*action
;
224 action
= lttng_action_notify_create();
226 fail("Setup error on action creation");
230 /* Test lttng_register_trigger with null value */
231 ok(lttng_register_trigger(NULL
) == -LTTNG_ERR_INVALID
, "Registering a NULL trigger fails as expected");
233 /* Test: register a trigger */
235 for (i
= 0; i
< pow(2,test_vector_size
); i
++) {
237 char *test_tuple_string
= NULL
;
238 unsigned int mask_position
= 0;
239 bool session_name_set
= false;
240 bool channel_name_set
= false;
241 bool threshold_ratio_set
= false;
242 bool threshold_byte_set
= false;
243 bool domain_type_set
= false;
245 struct lttng_trigger
*trigger
= NULL
;
246 struct lttng_condition
*condition
= NULL
;
248 /* Create base condition */
249 switch (condition_type
) {
250 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
251 condition
= lttng_condition_buffer_usage_low_create();
253 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
254 condition
= lttng_condition_buffer_usage_high_create();
267 /* Prepare the condition for trigger registration test */
269 /* Set session name */
270 if ((1 << mask_position
) & i
) {
271 condition_status
= lttng_condition_buffer_usage_set_session_name(
272 condition
, session_name
);
273 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
277 session_name_set
= true;
281 /* Set channel name */
282 if ((1 << mask_position
) & i
) {
283 condition_status
= lttng_condition_buffer_usage_set_channel_name(
284 condition
, channel_name
);
285 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
289 channel_name_set
= true;
293 /* Set threshold ratio */
294 if ((1 << mask_position
) & i
) {
295 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
297 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
301 threshold_ratio_set
= true;
305 /* Set threshold byte */
306 if ((1 << mask_position
) & i
) {
307 condition_status
= lttng_condition_buffer_usage_set_threshold(
309 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
313 threshold_byte_set
= true;
317 /* Set domain type */
318 if ((1 << mask_position
) & i
) {
319 condition_status
= lttng_condition_buffer_usage_set_domain_type(
320 condition
, LTTNG_DOMAIN_UST
);
321 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
325 domain_type_set
= true;
329 if (mask_position
!= test_vector_size
-1) {
330 assert("Logic error for test vector generation");
333 loop_ret
= asprintf(&test_tuple_string
, "session name %s, channel name %s, threshold ratio %s, threshold byte %s, domain type %s",
334 session_name_set
? "set" : "unset",
335 channel_name_set
? "set" : "unset",
336 threshold_ratio_set
? "set" : "unset",
337 threshold_byte_set
? "set" : "unset",
338 domain_type_set
? "set" : "unset");
339 if (!test_tuple_string
|| loop_ret
< 0) {
345 trigger
= lttng_trigger_create(condition
, action
);
351 loop_ret
= lttng_register_trigger(trigger
);
355 fail("Setup error occurred for tuple: %s", test_tuple_string
);
359 /* This combination happens three times */
360 if (session_name_set
&& channel_name_set
361 && (threshold_ratio_set
|| threshold_byte_set
)
362 && domain_type_set
) {
363 ok(loop_ret
== 0, "Trigger is registered: %s", test_tuple_string
);
366 * Test that a trigger cannot be registered
369 loop_ret
= lttng_register_trigger(trigger
);
370 ok(loop_ret
== -LTTNG_ERR_TRIGGER_EXISTS
, "Re-register trigger fails as expected: %s", test_tuple_string
);
372 /* Test that a trigger can be unregistered */
373 loop_ret
= lttng_unregister_trigger(trigger
);
374 ok(loop_ret
== 0, "Unregister trigger: %s", test_tuple_string
);
377 * Test that unregistration of a non-previously
378 * registered trigger fail.
380 loop_ret
= lttng_unregister_trigger(trigger
);
381 ok(loop_ret
== -LTTNG_ERR_TRIGGER_NOT_FOUND
, "Unregister of a non-registered trigger fails as expected: %s", test_tuple_string
);
383 ok(loop_ret
== -LTTNG_ERR_INVALID_TRIGGER
, "Trigger is invalid as expected and cannot be registered: %s", test_tuple_string
);
387 free(test_tuple_string
);
388 lttng_trigger_destroy(trigger
);
389 lttng_condition_destroy(condition
);
393 lttng_action_destroy(action
);
397 void wait_data_pending(const char *session_name
)
402 ret
= lttng_data_pending(session_name
);
408 int setup_buffer_usage_condition(struct lttng_condition
*condition
,
409 const char *condition_name
,
410 const char *session_name
,
411 const char *channel_name
,
412 const enum lttng_domain_type domain_type
)
414 enum lttng_condition_status condition_status
;
417 condition_status
= lttng_condition_buffer_usage_set_session_name(
418 condition
, session_name
);
419 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
420 fail("Failed to set session name on creation of condition `%s`",
426 condition_status
= lttng_condition_buffer_usage_set_channel_name(
427 condition
, channel_name
);
428 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
429 fail("Failed to set channel name on creation of condition `%s`",
435 condition_status
= lttng_condition_buffer_usage_set_domain_type(
436 condition
, domain_type
);
437 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
438 fail("Failed to set domain type on creation of condition `%s`",
449 void test_invalid_channel_subscription(
450 const enum lttng_domain_type domain_type
)
452 enum lttng_condition_status condition_status
;
453 enum lttng_notification_channel_status nc_status
;
454 struct lttng_condition
*dummy_condition
= NULL
;
455 struct lttng_condition
*dummy_invalid_condition
= NULL
;
456 struct lttng_notification_channel
*notification_channel
= NULL
;
459 notification_channel
= lttng_notification_channel_create(
460 lttng_session_daemon_notification_endpoint
);
461 ok(notification_channel
, "Notification channel object creation");
462 if (!notification_channel
) {
467 * Create a dummy, empty (thus invalid) condition to test error paths.
469 dummy_invalid_condition
= lttng_condition_buffer_usage_low_create();
470 if (!dummy_invalid_condition
) {
471 fail("Setup error on condition creation");
476 * Test subscription and unsubscription of an invalid condition to/from
479 nc_status
= lttng_notification_channel_subscribe(
480 notification_channel
, dummy_invalid_condition
);
481 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
482 "Subscribing to an invalid condition");
484 nc_status
= lttng_notification_channel_unsubscribe(
485 notification_channel
, dummy_invalid_condition
);
486 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
487 "Unsubscribing from an invalid condition");
489 /* Create a valid dummy condition with a ratio of 0.5 */
490 dummy_condition
= lttng_condition_buffer_usage_low_create();
491 if (!dummy_condition
) {
492 fail("Setup error on dummy_condition creation");
496 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
497 dummy_condition
, 0.5);
498 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
499 fail("Setup error on condition creation");
503 ret
= setup_buffer_usage_condition(dummy_condition
, "dummy_condition",
504 "dummy_session", "dummy_channel", domain_type
);
506 fail("Setup error on dummy condition creation");
511 * Test subscription and unsubscription to/from a channel with invalid
514 nc_status
= lttng_notification_channel_subscribe(NULL
, NULL
);
515 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
516 "Notification channel subscription is invalid: NULL, NULL");
518 nc_status
= lttng_notification_channel_subscribe(
519 notification_channel
, NULL
);
520 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
521 "Notification channel subscription is invalid: NON-NULL, NULL");
523 nc_status
= lttng_notification_channel_subscribe(NULL
, dummy_condition
);
524 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
525 "Notification channel subscription is invalid: NULL, NON-NULL");
527 nc_status
= lttng_notification_channel_unsubscribe(
528 notification_channel
, dummy_condition
);
529 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION
,
530 "Unsubscribing from a valid unknown condition");
533 lttng_notification_channel_destroy(notification_channel
);
534 lttng_condition_destroy(dummy_invalid_condition
);
535 lttng_condition_destroy(dummy_condition
);
539 enum buffer_usage_type
{
540 BUFFER_USAGE_TYPE_LOW
,
541 BUFFER_USAGE_TYPE_HIGH
,
544 static int register_buffer_usage_notify_trigger(const char *session_name
,
545 const char *channel_name
,
546 const enum lttng_domain_type domain_type
,
547 enum buffer_usage_type buffer_usage_type
,
549 struct lttng_condition
**condition
,
550 struct lttng_action
**action
,
551 struct lttng_trigger
**trigger
)
553 enum lttng_condition_status condition_status
;
554 struct lttng_action
*tmp_action
= NULL
;
555 struct lttng_condition
*tmp_condition
= NULL
;
556 struct lttng_trigger
*tmp_trigger
= NULL
;
560 tmp_action
= lttng_action_notify_create();
562 fail("Setup error on action creation");
567 if (buffer_usage_type
== BUFFER_USAGE_TYPE_LOW
) {
568 tmp_condition
= lttng_condition_buffer_usage_low_create();
570 tmp_condition
= lttng_condition_buffer_usage_high_create();
573 if (!tmp_condition
) {
574 fail("Setup error on condition creation");
579 /* Set the buffer usage threashold */
580 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
581 tmp_condition
, ratio
);
582 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
583 fail("Setup error on condition creation");
588 ret
= setup_buffer_usage_condition(tmp_condition
, "condition_name",
589 session_name
, channel_name
, domain_type
);
591 fail("Setup error on condition creation");
596 /* Register the trigger for condition. */
597 tmp_trigger
= lttng_trigger_create(tmp_condition
, tmp_action
);
599 fail("Setup error on trigger creation");
604 ret
= lttng_register_trigger(tmp_trigger
);
606 fail("Setup error on trigger registration");
611 *condition
= tmp_condition
;
612 *trigger
= tmp_trigger
;
613 *action
= tmp_action
;
617 lttng_action_destroy(tmp_action
);
618 lttng_condition_destroy(tmp_condition
);
619 lttng_trigger_destroy(tmp_trigger
);
625 static void test_subscription_twice(const char *session_name
,
626 const char *channel_name
,
627 const enum lttng_domain_type domain_type
)
630 enum lttng_notification_channel_status nc_status
;
632 struct lttng_action
*action
= NULL
;
633 struct lttng_notification_channel
*notification_channel
= NULL
;
634 struct lttng_trigger
*trigger
= NULL
;
636 struct lttng_condition
*condition
= NULL
;
638 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
639 domain_type
, BUFFER_USAGE_TYPE_LOW
, 0.99, &condition
,
642 fail("Setup error on trigger registration");
647 notification_channel
= lttng_notification_channel_create(
648 lttng_session_daemon_notification_endpoint
);
649 ok(notification_channel
, "Notification channel object creation");
650 if (!notification_channel
) {
654 /* Subscribe a valid condition. */
655 nc_status
= lttng_notification_channel_subscribe(
656 notification_channel
, condition
);
657 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
658 "Subscribe to condition");
660 /* Subscribing again should fail. */
661 nc_status
= lttng_notification_channel_subscribe(
662 notification_channel
, condition
);
663 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED
,
664 "Subscribe to a condition for which subscription was already done");
667 lttng_unregister_trigger(trigger
);
668 lttng_trigger_destroy(trigger
);
669 lttng_notification_channel_destroy(notification_channel
);
670 lttng_action_destroy(action
);
671 lttng_condition_destroy(condition
);
674 static void test_buffer_usage_notification_channel(const char *session_name
,
675 const char *channel_name
,
676 const enum lttng_domain_type domain_type
,
680 enum lttng_notification_channel_status nc_status
;
682 struct lttng_action
*low_action
= NULL
;
683 struct lttng_action
*high_action
= NULL
;
684 struct lttng_notification
*notification
= NULL
;
685 struct lttng_notification_channel
*notification_channel
= NULL
;
686 struct lttng_trigger
*low_trigger
= NULL
;
687 struct lttng_trigger
*high_trigger
= NULL
;
689 struct lttng_condition
*low_condition
= NULL
;
690 struct lttng_condition
*high_condition
= NULL
;
692 const double low_ratio
= 0.0;
693 const double high_ratio
= 0.90;
695 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
696 domain_type
, BUFFER_USAGE_TYPE_LOW
, low_ratio
,
697 &low_condition
, &low_action
, &low_trigger
);
699 fail("Setup error on low trigger registration");
703 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
704 domain_type
, BUFFER_USAGE_TYPE_HIGH
, high_ratio
,
705 &high_condition
, &high_action
, &high_trigger
);
707 fail("Setup error on high trigger registration");
712 notification_channel
= lttng_notification_channel_create(
713 lttng_session_daemon_notification_endpoint
);
714 ok(notification_channel
, "Notification channel object creation");
715 if (!notification_channel
) {
719 /* Subscribe a valid low condition */
720 nc_status
= lttng_notification_channel_subscribe(
721 notification_channel
, low_condition
);
722 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
723 "Subscribe to low condition");
725 /* Subscribe a valid high condition */
726 nc_status
= lttng_notification_channel_subscribe(
727 notification_channel
, high_condition
);
728 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
729 "Subscribe to high condition");
731 resume_application();
733 /* Wait for notification to happen */
735 lttng_start_tracing(session_name
);
737 /* Wait for high notification */
739 nc_status
= lttng_notification_channel_get_next_notification(
740 notification_channel
, ¬ification
);
741 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
742 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
743 lttng_condition_get_type(lttng_notification_get_condition(
745 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
746 "High notification received after intermediary communication");
747 lttng_notification_destroy(notification
);
750 suspend_application();
751 lttng_stop_tracing_no_wait(session_name
);
752 resume_consumer(argv
);
753 wait_data_pending(session_name
);
756 * Test that communication still work even if there is notification
757 * waiting for consumption.
760 nc_status
= lttng_notification_channel_unsubscribe(
761 notification_channel
, low_condition
);
762 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
763 "Unsubscribe with pending notification");
765 nc_status
= lttng_notification_channel_subscribe(
766 notification_channel
, low_condition
);
767 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
768 "Subscribe with pending notification");
771 nc_status
= lttng_notification_channel_get_next_notification(
772 notification_channel
, ¬ification
);
773 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
774 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
775 lttng_condition_get_type(lttng_notification_get_condition(
777 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
,
778 "Low notification received after intermediary communication");
779 lttng_notification_destroy(notification
);
782 /* Stop consumer to force a high notification */
784 resume_application();
785 lttng_start_tracing(session_name
);
788 nc_status
= lttng_notification_channel_get_next_notification(
789 notification_channel
, ¬ification
);
790 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
791 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
792 lttng_condition_get_type(lttng_notification_get_condition(
794 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
795 "High notification received after intermediary communication");
796 lttng_notification_destroy(notification
);
799 suspend_application();
800 lttng_stop_tracing_no_wait(session_name
);
801 resume_consumer(argv
);
802 wait_data_pending(session_name
);
805 nc_status
= lttng_notification_channel_get_next_notification(
806 notification_channel
, ¬ification
);
807 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
808 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
809 lttng_condition_get_type(lttng_notification_get_condition(
811 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
,
812 "Low notification received after re-subscription");
813 lttng_notification_destroy(notification
);
817 resume_application();
818 /* Stop consumer to force a high notification */
819 lttng_start_tracing(session_name
);
822 nc_status
= lttng_notification_channel_get_next_notification(
823 notification_channel
, ¬ification
);
824 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
825 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
826 lttng_condition_get_type(lttng_notification_get_condition(
828 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
829 "High notification");
830 lttng_notification_destroy(notification
);
833 suspend_application();
835 /* Resume consumer to allow event consumption */
836 lttng_stop_tracing_no_wait(session_name
);
837 resume_consumer(argv
);
838 wait_data_pending(session_name
);
840 nc_status
= lttng_notification_channel_unsubscribe(
841 notification_channel
, low_condition
);
842 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
843 "Unsubscribe low condition with pending notification");
845 nc_status
= lttng_notification_channel_unsubscribe(
846 notification_channel
, high_condition
);
847 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
848 "Unsubscribe high condition with pending notification");
851 lttng_notification_channel_destroy(notification_channel
);
852 lttng_trigger_destroy(low_trigger
);
853 lttng_trigger_destroy(high_trigger
);
854 lttng_action_destroy(low_action
);
855 lttng_action_destroy(high_action
);
856 lttng_condition_destroy(low_condition
);
857 lttng_condition_destroy(high_condition
);
860 static void create_tracepoint_event_rule_trigger(const char *event_pattern
,
861 const char *trigger_name
,
863 unsigned int exclusion_count
,
864 const char * const *exclusions
,
865 enum lttng_domain_type domain_type
,
866 struct lttng_condition
**condition
,
867 struct lttng_trigger
**trigger
)
869 enum lttng_event_rule_status event_rule_status
;
870 enum lttng_trigger_status trigger_status
;
872 struct lttng_action
*tmp_action
= NULL
;
873 struct lttng_event_rule
*event_rule
= NULL
;
874 struct lttng_condition
*tmp_condition
= NULL
;
875 struct lttng_trigger
*tmp_trigger
= NULL
;
878 assert(event_pattern
);
879 assert(trigger_name
);
883 event_rule
= lttng_event_rule_tracepoint_create(domain_type
);
884 ok(event_rule
, "Tracepoint event rule object creation");
886 event_rule_status
= lttng_event_rule_tracepoint_set_pattern(
887 event_rule
, event_pattern
);
888 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
889 "Setting tracepoint event rule pattern: '%s'",
893 event_rule_status
= lttng_event_rule_tracepoint_set_filter(
895 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
896 "Setting tracepoint event rule filter: '%s'",
904 assert(domain_type
== LTTNG_DOMAIN_UST
);
905 assert(exclusion_count
> 0);
907 for (i
= 0; i
< exclusion_count
; i
++) {
909 lttng_event_rule_tracepoint_add_exclusion(
912 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
913 fail("Setting tracepoint event rule exclusion '%s'.",
919 ok(success
, "Setting tracepoint event rule exclusions");
922 tmp_condition
= lttng_condition_event_rule_create(event_rule
);
923 ok(tmp_condition
, "Condition event rule object creation");
925 tmp_action
= lttng_action_notify_create();
926 ok(tmp_action
, "Action event rule object creation");
928 tmp_trigger
= lttng_trigger_create(tmp_condition
, tmp_action
);
929 ok(tmp_trigger
, "Trigger object creation %s", trigger_name
);
931 trigger_status
= lttng_trigger_set_name(tmp_trigger
, trigger_name
);
932 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
933 "Setting name to trigger %s", trigger_name
);
935 ret
= lttng_register_trigger(tmp_trigger
);
936 ok(ret
== 0, "Trigger registration %s", trigger_name
);
938 lttng_event_rule_destroy(event_rule
);
940 *condition
= tmp_condition
;
941 *trigger
= tmp_trigger
;
946 static char *get_next_notification_trigger_name(
947 struct lttng_notification_channel
*notification_channel
)
949 struct lttng_notification
*notification
;
950 enum lttng_notification_channel_status status
;
951 const struct lttng_evaluation
*notification_evaluation
;
952 char *trigger_name
= NULL
;
954 enum lttng_condition_type notification_evaluation_type
;
956 /* Receive the next notification. */
957 status
= lttng_notification_channel_get_next_notification(
958 notification_channel
, ¬ification
);
961 case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
:
964 /* Unhandled conditions / errors. */
965 fail("Failed to get next notification channel notification: status = %d",
970 notification_evaluation
=
971 lttng_notification_get_evaluation(notification
);
973 notification_evaluation_type
=
974 lttng_evaluation_get_type(notification_evaluation
);
975 switch (notification_evaluation_type
) {
976 case LTTNG_CONDITION_TYPE_EVENT_RULE_HIT
:
977 lttng_evaluation_event_rule_get_trigger_name(
978 notification_evaluation
, &name
);
980 trigger_name
= strdup(name
);
983 fail("Unexpected notification evaluation type: notification type = %d",
984 notification_evaluation_type
);
988 lttng_notification_destroy(notification
);
994 static void test_tracepoint_event_rule_notification(
995 enum lttng_domain_type domain_type
)
998 const int notification_count
= 3;
999 enum lttng_notification_channel_status nc_status
;
1000 struct lttng_action
*action
= NULL
;
1001 struct lttng_condition
*condition
= NULL
;
1002 struct lttng_notification_channel
*notification_channel
= NULL
;
1003 struct lttng_trigger
*trigger
= NULL
;
1004 const char * const trigger_name
= "my_precious";
1005 const char *pattern
;
1007 if (domain_type
== LTTNG_DOMAIN_UST
) {
1008 pattern
= "tp:tptest";
1010 pattern
= "lttng_test_filter_event";
1013 create_tracepoint_event_rule_trigger(pattern
, trigger_name
, NULL
, 0,
1014 NULL
, domain_type
, &condition
, &trigger
);
1016 notification_channel
= lttng_notification_channel_create(
1017 lttng_session_daemon_notification_endpoint
);
1018 ok(notification_channel
, "Notification channel object creation");
1020 nc_status
= lttng_notification_channel_subscribe(
1021 notification_channel
, condition
);
1022 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1023 "Subscribe to tracepoint event rule condition");
1025 resume_application();
1027 /* Get 3 notifications. */
1028 for (i
= 0; i
< notification_count
; i
++) {
1029 char *name
= get_next_notification_trigger_name(
1030 notification_channel
);
1032 ok(strcmp(trigger_name
, name
) == 0,
1033 "Received notification for the expected trigger name: '%s' (%d/%d)",
1034 trigger_name
, i
+ 1, notification_count
);
1038 suspend_application();
1039 lttng_notification_channel_destroy(notification_channel
);
1040 lttng_unregister_trigger(trigger
);
1041 lttng_trigger_destroy(trigger
);
1042 lttng_action_destroy(action
);
1043 lttng_condition_destroy(condition
);
1047 static void test_tracepoint_event_rule_notification_filter(
1048 enum lttng_domain_type domain_type
)
1051 enum lttng_notification_channel_status nc_status
;
1053 struct lttng_condition
*ctrl_condition
= NULL
, *condition
= NULL
;
1054 struct lttng_notification_channel
*notification_channel
= NULL
;
1055 struct lttng_trigger
*ctrl_trigger
= NULL
, *trigger
= NULL
;
1056 const char * const ctrl_trigger_name
= "control_trigger";
1057 const char * const trigger_name
= "trigger";
1058 const char *pattern
;
1059 int ctrl_count
= 0, count
= 0;
1061 if (domain_type
== LTTNG_DOMAIN_UST
) {
1062 pattern
= "tp:tptest";
1064 pattern
= "lttng_test_filter_event";
1067 notification_channel
= lttng_notification_channel_create(
1068 lttng_session_daemon_notification_endpoint
);
1069 ok(notification_channel
, "Notification channel object creation");
1071 create_tracepoint_event_rule_trigger(pattern
, ctrl_trigger_name
, NULL
,
1072 0, NULL
, domain_type
, &ctrl_condition
, &ctrl_trigger
);
1074 nc_status
= lttng_notification_channel_subscribe(
1075 notification_channel
, ctrl_condition
);
1076 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1077 "Subscribe to tracepoint event rule condition");
1080 * Attach a filter expression to get notification only if the
1081 * `intfield` is even.
1083 create_tracepoint_event_rule_trigger(pattern
, trigger_name
,
1084 "(intfield & 1) == 0", 0, NULL
, domain_type
, &condition
,
1087 nc_status
= lttng_notification_channel_subscribe(
1088 notification_channel
, condition
);
1089 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1090 "Subscribe to tracepoint event rule condition");
1093 * We registered 2 notifications triggers, one with a filter and one
1094 * without (control). The one with a filter will only fired when the
1095 * `intfield` is a multiple of 2. We should get two times as many
1096 * control notifications as filter notifications.
1098 resume_application();
1101 * Get 3 notifications. We should get 1 for the regular trigger (with
1102 * the filter) and 2 from the control trigger. This works whatever
1103 * the order we receive the notifications.
1105 for (i
= 0; i
< 3; i
++) {
1106 char *name
= get_next_notification_trigger_name(
1107 notification_channel
);
1109 if (strcmp(ctrl_trigger_name
, name
) == 0) {
1111 } else if (strcmp(trigger_name
, name
) == 0) {
1118 ok(ctrl_count
/ 2 == count
,
1119 "Get twice as many control notif as of regular notif");
1121 suspend_application();
1123 lttng_unregister_trigger(trigger
);
1124 lttng_unregister_trigger(ctrl_trigger
);
1125 lttng_notification_channel_destroy(notification_channel
);
1126 lttng_trigger_destroy(trigger
);
1127 lttng_trigger_destroy(ctrl_trigger
);
1128 lttng_condition_destroy(condition
);
1129 lttng_condition_destroy(ctrl_condition
);
1132 static void test_tracepoint_event_rule_notification_exclusion(
1133 enum lttng_domain_type domain_type
)
1135 enum lttng_notification_channel_status nc_status
;
1136 struct lttng_condition
*ctrl_condition
= NULL
, *condition
= NULL
;
1137 struct lttng_notification_channel
*notification_channel
= NULL
;
1138 struct lttng_trigger
*ctrl_trigger
= NULL
, *trigger
= NULL
;
1139 int ctrl_count
= 0, count
= 0, i
;
1140 const char * const ctrl_trigger_name
= "control_exclusion_trigger";
1141 const char * const trigger_name
= "exclusion_trigger";
1142 const char * const pattern
= "tp:tptest*";
1143 const char * const exclusions
[] = {
1150 notification_channel
= lttng_notification_channel_create(
1151 lttng_session_daemon_notification_endpoint
);
1152 ok(notification_channel
, "Notification channel object creation");
1154 create_tracepoint_event_rule_trigger(pattern
, ctrl_trigger_name
, NULL
,
1155 0, NULL
, domain_type
, &ctrl_condition
, &ctrl_trigger
);
1157 nc_status
= lttng_notification_channel_subscribe(
1158 notification_channel
, ctrl_condition
);
1159 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1160 "Subscribe to tracepoint event rule condition");
1162 create_tracepoint_event_rule_trigger(pattern
, trigger_name
, NULL
, 4,
1163 exclusions
, domain_type
, &condition
, &trigger
);
1165 nc_status
= lttng_notification_channel_subscribe(
1166 notification_channel
, condition
);
1167 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1168 "Subscribe to tracepoint event rule condition");
1171 * We registered 2 notifications triggers, one with an exclusion and
1172 * one without (control).
1173 * - The trigger with an exclusion will fire once every iteration.
1174 * - The trigger without an exclusion will fire 5 times every
1177 * We should get 5 times as many notifications from the control
1180 resume_application();
1183 * Get 6 notifications. We should get 1 for the regular trigger (with
1184 * the exclusion) and 5 from the control trigger. This works whatever
1185 * the order we receive the notifications.
1187 for (i
= 0; i
< 6; i
++) {
1188 char *name
= get_next_notification_trigger_name(
1189 notification_channel
);
1191 if (strcmp(ctrl_trigger_name
, name
) == 0) {
1193 } else if (strcmp(trigger_name
, name
) == 0) {
1200 ok(ctrl_count
/ 5 == count
,
1201 "Got 5 times as many control notif as of regular notif");
1203 suspend_application();
1205 lttng_unregister_trigger(trigger
);
1206 lttng_unregister_trigger(ctrl_trigger
);
1207 lttng_notification_channel_destroy(notification_channel
);
1208 lttng_trigger_destroy(trigger
);
1209 lttng_trigger_destroy(ctrl_trigger
);
1210 lttng_condition_destroy(condition
);
1211 lttng_condition_destroy(ctrl_condition
);
1215 static void test_kprobe_event_rule_notification(
1216 enum lttng_domain_type domain_type
)
1219 const int notification_count
= 3;
1220 enum lttng_notification_channel_status nc_status
;
1221 enum lttng_event_rule_status event_rule_status
;
1222 enum lttng_trigger_status trigger_status
;
1223 struct lttng_notification_channel
*notification_channel
= NULL
;
1224 struct lttng_condition
*condition
= NULL
;
1225 struct lttng_kernel_probe_location
*location
= NULL
;
1226 struct lttng_event_rule
*event_rule
= NULL
;
1227 struct lttng_action
*action
= NULL
;
1228 struct lttng_trigger
*trigger
= NULL
;
1229 const char * const trigger_name
= "kprobe_trigger";
1230 const char * const symbol_name
= "lttng_test_filter_event_write";
1232 action
= lttng_action_notify_create();
1234 fail("Failed to create notify action");
1238 location
= lttng_kernel_probe_location_symbol_create(symbol_name
, 0);
1240 fail("Failed to create kernel probe location");
1244 notification_channel
= lttng_notification_channel_create(
1245 lttng_session_daemon_notification_endpoint
);
1246 ok(notification_channel
, "Notification channel object creation");
1248 event_rule
= lttng_event_rule_kprobe_create();
1249 ok(event_rule
, "kprobe event rule object creation");
1251 event_rule_status
= lttng_event_rule_kprobe_set_location(
1252 event_rule
, location
);
1253 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1254 "Setting kprobe event rule location: '%s'", symbol_name
);
1256 event_rule_status
= lttng_event_rule_kprobe_set_name(
1257 event_rule
, trigger_name
);
1258 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1259 "Setting kprobe event rule name: '%s'", trigger_name
);
1261 condition
= lttng_condition_event_rule_create(event_rule
);
1262 ok(condition
, "Condition event rule object creation");
1264 /* Register the trigger for condition. */
1265 trigger
= lttng_trigger_create(condition
, action
);
1267 fail("Failed to create trigger with kernel probe event rule condition and notify action");
1271 trigger_status
= lttng_trigger_set_name(trigger
, trigger_name
);
1272 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
1273 "Setting trigger name to '%s'", trigger_name
);
1275 ret
= lttng_register_trigger(trigger
);
1277 fail("Failed to register trigger with kernel probe event rule condition and notify action");
1281 nc_status
= lttng_notification_channel_subscribe(
1282 notification_channel
, condition
);
1283 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1284 "Subscribe to tracepoint event rule condition");
1286 resume_application();
1288 for (i
= 0; i
< notification_count
; i
++) {
1289 char *name
= get_next_notification_trigger_name(
1290 notification_channel
);
1292 ok(strcmp(trigger_name
, name
) == 0,
1293 "Received notification for the expected trigger name: '%s' (%d/%d)",
1294 trigger_name
, i
+ 1, notification_count
);
1299 suspend_application();
1300 lttng_notification_channel_destroy(notification_channel
);
1301 lttng_unregister_trigger(trigger
);
1302 lttng_trigger_destroy(trigger
);
1303 lttng_action_destroy(action
);
1304 lttng_event_rule_destroy(event_rule
);
1305 lttng_condition_destroy(condition
);
1306 lttng_kernel_probe_location_destroy(location
);
1310 static void test_uprobe_event_rule_notification(
1311 enum lttng_domain_type domain_type
,
1312 const char *testapp_path
,
1313 const char *test_symbol_name
)
1316 const int notification_count
= 3;
1317 enum lttng_notification_channel_status nc_status
;
1318 enum lttng_event_rule_status event_rule_status
;
1319 enum lttng_trigger_status trigger_status
;
1320 struct lttng_notification_channel
*notification_channel
= NULL
;
1321 struct lttng_userspace_probe_location
*probe_location
= NULL
;
1322 struct lttng_userspace_probe_location_lookup_method
*lookup_method
=
1324 struct lttng_condition
*condition
= NULL
;
1325 struct lttng_event_rule
*event_rule
= NULL
;
1326 struct lttng_action
*action
= NULL
;
1327 struct lttng_trigger
*trigger
= NULL
;
1328 const char * const trigger_name
= "uprobe_trigger";
1330 action
= lttng_action_notify_create();
1332 fail("Failed to create notify action");
1336 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1337 if (!lookup_method
) {
1338 fail("Setup error on userspace probe lookup method creation");
1342 probe_location
= lttng_userspace_probe_location_function_create(
1343 testapp_path
, test_symbol_name
, lookup_method
);
1344 if (!probe_location
) {
1345 fail("Failed to create userspace probe location");
1349 notification_channel
= lttng_notification_channel_create(
1350 lttng_session_daemon_notification_endpoint
);
1351 ok(notification_channel
, "Notification channel object creation");
1353 event_rule
= lttng_event_rule_uprobe_create();
1354 ok(event_rule
, "kprobe event rule object creation");
1356 event_rule_status
= lttng_event_rule_uprobe_set_location(
1357 event_rule
, probe_location
);
1358 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1359 "Setting uprobe event rule location");
1361 event_rule_status
= lttng_event_rule_uprobe_set_name(
1362 event_rule
, trigger_name
);
1363 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1364 "Setting uprobe event rule name: '%s'", trigger_name
);
1366 condition
= lttng_condition_event_rule_create(event_rule
);
1367 ok(condition
, "Condition event rule object creation");
1369 /* Register the trigger for condition. */
1370 trigger
= lttng_trigger_create(condition
, action
);
1372 fail("Failed to create trigger with userspace probe event rule condition and notify action");
1376 trigger_status
= lttng_trigger_set_name(trigger
, trigger_name
);
1377 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
1378 "Setting name to trigger '%s'", trigger_name
);
1380 ret
= lttng_register_trigger(trigger
);
1382 fail("Failed to register trigger with userspace probe event rule condition and notify action");
1386 nc_status
= lttng_notification_channel_subscribe(
1387 notification_channel
, condition
);
1388 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1389 "Subscribe to tracepoint event rule condition");
1391 resume_application();
1393 for (i
= 0; i
< notification_count
; i
++) {
1394 char *name
= get_next_notification_trigger_name(
1395 notification_channel
);
1397 ok(strcmp(trigger_name
, name
) == 0,
1398 "Received notification for the expected trigger name: '%s' (%d/%d)",
1399 trigger_name
, i
+ 1, notification_count
);
1403 suspend_application();
1405 lttng_notification_channel_destroy(notification_channel
);
1406 lttng_unregister_trigger(trigger
);
1407 lttng_trigger_destroy(trigger
);
1408 lttng_action_destroy(action
);
1409 lttng_event_rule_destroy(event_rule
);
1410 lttng_condition_destroy(condition
);
1414 static void test_syscall_event_rule_notification(
1415 enum lttng_domain_type domain_type
)
1418 const int notification_count
= 3;
1419 enum lttng_notification_channel_status nc_status
;
1420 enum lttng_event_rule_status event_rule_status
;
1421 enum lttng_trigger_status trigger_status
;
1422 struct lttng_notification_channel
*notification_channel
= NULL
;
1423 struct lttng_condition
*condition
= NULL
;
1424 struct lttng_event_rule
*event_rule
= NULL
;
1425 struct lttng_action
*action
= NULL
;
1426 struct lttng_trigger
*trigger
= NULL
;
1427 const char * const trigger_name
= "syscall_trigger";
1428 const char * const syscall_name
= "openat";
1430 action
= lttng_action_notify_create();
1432 fail("Failed to create notify action");
1436 notification_channel
= lttng_notification_channel_create(
1437 lttng_session_daemon_notification_endpoint
);
1438 ok(notification_channel
, "Notification channel object creation");
1440 event_rule
= lttng_event_rule_syscall_create();
1441 ok(event_rule
, "syscall event rule object creation");
1443 event_rule_status
= lttng_event_rule_syscall_set_pattern(
1444 event_rule
, syscall_name
);
1445 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1446 "Setting syscall event rule pattern: '%s'", syscall_name
);
1448 condition
= lttng_condition_event_rule_create(event_rule
);
1449 ok(condition
, "Condition syscall event rule object creation");
1451 /* Register the trigger for condition. */
1452 trigger
= lttng_trigger_create(condition
, action
);
1454 fail("Failed to create trigger with syscall event rule condition and notify action");
1458 trigger_status
= lttng_trigger_set_name(trigger
, trigger_name
);
1459 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
1460 "Setting name to trigger '%s'", trigger_name
);
1462 ret
= lttng_register_trigger(trigger
);
1464 fail("Failed to register trigger with syscall event rule condition and notify action");
1468 nc_status
= lttng_notification_channel_subscribe(
1469 notification_channel
, condition
);
1470 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1471 "Subscribe to tracepoint event rule condition");
1473 resume_application();
1475 for (i
= 0; i
< notification_count
; i
++) {
1476 char *name
= get_next_notification_trigger_name(
1477 notification_channel
);
1479 ok(strcmp(trigger_name
, name
) == 0,
1480 "Received notification for the expected trigger name: '%s' (%d/%d)",
1481 trigger_name
, i
+ 1, notification_count
);
1485 suspend_application();
1486 lttng_notification_channel_destroy(notification_channel
);
1487 lttng_unregister_trigger(trigger
);
1488 lttng_trigger_destroy(trigger
);
1489 lttng_action_destroy(action
);
1490 lttng_condition_destroy(condition
);
1494 static void test_syscall_event_rule_notification_filter(
1495 enum lttng_domain_type domain_type
)
1498 const int notification_count
= 3;
1499 enum lttng_notification_channel_status nc_status
;
1500 enum lttng_event_rule_status event_rule_status
;
1501 enum lttng_trigger_status trigger_status
;
1502 struct lttng_notification_channel
*notification_channel
= NULL
;
1503 struct lttng_condition
*condition
= NULL
;
1504 struct lttng_event_rule
*event_rule
= NULL
;
1505 struct lttng_action
*action
= NULL
;
1506 struct lttng_trigger
*trigger
= NULL
;
1507 const char * const trigger_name
= "syscall_trigger";
1508 const char * const syscall_name
= "openat";
1509 const char * const filter_pattern
= "filename == \"/proc/cpuinfo\"";
1511 action
= lttng_action_notify_create();
1513 fail("Failed to create notify action");
1517 notification_channel
= lttng_notification_channel_create(
1518 lttng_session_daemon_notification_endpoint
);
1519 ok(notification_channel
, "Notification channel object creation");
1521 event_rule
= lttng_event_rule_syscall_create();
1522 ok(event_rule
, "syscall event rule object creation");
1524 event_rule_status
= lttng_event_rule_syscall_set_pattern(
1525 event_rule
, syscall_name
);
1526 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1527 "Setting syscall event rule pattern: '%s'", syscall_name
);
1529 event_rule_status
= lttng_event_rule_syscall_set_filter(
1530 event_rule
, filter_pattern
);
1531 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1532 "Setting filter: '%s'", filter_pattern
);
1534 condition
= lttng_condition_event_rule_create(event_rule
);
1535 ok(condition
, "Condition event rule object creation");
1537 /* Register the triggers for condition */
1538 trigger
= lttng_trigger_create(condition
, action
);
1540 fail("Failed to create trigger with syscall filtering event rule condition and notify action");
1544 trigger_status
= lttng_trigger_set_name(trigger
, trigger_name
);
1545 ok(trigger_status
== LTTNG_TRIGGER_STATUS_OK
,
1546 "Setting name to trigger '%s'", trigger_name
);
1548 ret
= lttng_register_trigger(trigger
);
1550 fail("Failed to register trigger with syscall filtering event rule condition and notify action");
1554 nc_status
= lttng_notification_channel_subscribe(
1555 notification_channel
, condition
);
1556 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1557 "Subscribe to tracepoint event rule condition");
1559 resume_application();
1561 for (i
= 0; i
< 3; i
++) {
1562 char *name
= get_next_notification_trigger_name(
1563 notification_channel
);
1565 ok(strcmp(trigger_name
, name
) == 0,
1566 "Received notification for the expected trigger name: '%s' (%d/%d)",
1567 trigger_name
, i
+ 1, notification_count
);
1572 suspend_application();
1574 lttng_unregister_trigger(trigger
);
1575 lttng_notification_channel_destroy(notification_channel
);
1576 lttng_trigger_destroy(trigger
);
1577 lttng_event_rule_destroy(event_rule
);
1578 lttng_condition_destroy(condition
);
1582 int main(int argc
, const char *argv
[])
1585 const char *domain_type_string
= NULL
;
1586 enum lttng_domain_type domain_type
= LTTNG_DOMAIN_NONE
;
1589 fail("Missing test scenario, domain type, pid, or application state file argument(s)");
1593 test_scenario
= atoi(argv
[1]);
1594 domain_type_string
= argv
[2];
1595 app_pid
= (pid_t
) atoi(argv
[3]);
1596 app_state_file
= argv
[4];
1598 if (!strcmp("LTTNG_DOMAIN_UST", domain_type_string
)) {
1599 domain_type
= LTTNG_DOMAIN_UST
;
1601 if (!strcmp("LTTNG_DOMAIN_KERNEL", domain_type_string
)) {
1602 domain_type
= LTTNG_DOMAIN_KERNEL
;
1604 if (domain_type
== LTTNG_DOMAIN_NONE
) {
1605 fail("Unknown domain type");
1610 * Test cases are responsible for resuming the app when needed
1611 * and making sure it's suspended when returning.
1613 suspend_application();
1615 switch (test_scenario
) {
1620 /* Test cases that need gen-ust-event testapp. */
1621 diag("Test basic notification error paths for %s domain",
1622 domain_type_string
);
1623 test_invalid_channel_subscription(domain_type
);
1625 diag("Test tracepoint event rule notifications for domain %s",
1626 domain_type_string
);
1627 test_tracepoint_event_rule_notification(domain_type
);
1629 diag("Test tracepoint event rule notifications with filter for domain %s",
1630 domain_type_string
);
1631 test_tracepoint_event_rule_notification_filter(domain_type
);
1636 const char *session_name
, *channel_name
;
1637 /* Test cases that need a tracing session enabled. */
1641 * Argument 7 and upward are named pipe location for consumerd
1644 named_pipe_args_start
= 7;
1647 fail("Missing parameter for tests to run %d", argc
);
1653 session_name
= argv
[5];
1654 channel_name
= argv
[6];
1656 test_subscription_twice(session_name
, channel_name
,
1659 diag("Test trigger for domain %s with buffer_usage_low condition",
1660 domain_type_string
);
1661 test_triggers_buffer_usage_condition(session_name
, channel_name
,
1663 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
);
1665 diag("Test trigger for domain %s with buffer_usage_high condition",
1666 domain_type_string
);
1667 test_triggers_buffer_usage_condition(session_name
, channel_name
,
1669 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
);
1671 diag("Test buffer usage notification channel api for domain %s",
1672 domain_type_string
);
1673 test_buffer_usage_notification_channel(session_name
, channel_name
,
1680 * Test cases that need a test app with more than one event
1686 * At the moment, the only test case of this scenario is
1687 * exclusion which is only supported by UST.
1689 assert(domain_type
== LTTNG_DOMAIN_UST
);
1690 diag("Test tracepoint event rule notifications with exclusion for domain %s",
1691 domain_type_string
);
1692 test_tracepoint_event_rule_notification_exclusion(domain_type
);
1700 /* Test cases that need the kernel tracer. */
1701 assert(domain_type
== LTTNG_DOMAIN_KERNEL
);
1703 diag("Test kprobe event rule notifications for domain %s",
1704 domain_type_string
);
1706 test_kprobe_event_rule_notification(domain_type
);
1713 /* Test cases that need the kernel tracer. */
1714 assert(domain_type
== LTTNG_DOMAIN_KERNEL
);
1716 diag("Test syscall event rule notifications for domain %s",
1717 domain_type_string
);
1719 test_syscall_event_rule_notification(domain_type
);
1721 diag("Test syscall filtering event rule notifications for domain %s",
1722 domain_type_string
);
1724 test_syscall_event_rule_notification_filter(domain_type
);
1730 const char *testapp_path
, *test_symbol_name
;
1735 fail("Missing parameter for tests to run %d", argc
);
1739 testapp_path
= argv
[5];
1740 test_symbol_name
= argv
[6];
1741 /* Test cases that need the kernel tracer. */
1742 assert(domain_type
== LTTNG_DOMAIN_KERNEL
);
1744 diag("Test userspace-probe event rule notifications for domain %s",
1745 domain_type_string
);
1747 test_uprobe_event_rule_notification(
1748 domain_type
, testapp_path
, test_symbol_name
);
1757 return exit_status();