4 * Tests suite for LTTng notification API
6 * Copyright (C) 2017 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
8 * SPDX-License-Identifier: MIT
19 #include <sys/types.h>
25 #include <common/compat/errno.hpp>
26 #include <common/macros.hpp>
27 #include <lttng/lttng.h>
31 #define FIELD_NAME_MAX_LEN 256
33 /* A callback to populate the condition capture descriptor. */
34 typedef int (*condition_capture_desc_cb
)(struct lttng_condition
*condition
);
36 /* A callback for captured field validation. */
37 typedef int (*validate_cb
)(const struct lttng_event_field_value
*event_field
, unsigned iteration
);
40 int named_pipe_args_start
= 0;
42 const char *app_state_file
= NULL
;
47 FIELD_TYPE_APP_CONTEXT
,
48 FIELD_TYPE_ARRAY_FIELD
,
52 struct capture_base_field_tuple
{
53 const char *field_name
;
54 enum field_type field_type
;
55 /* Do we expect a userspace capture? */
57 /* Do we expect a kernel capture? */
59 validate_cb validate_ust
;
60 validate_cb validate_kernel
;
65 const char *field_value_type_to_str(enum lttng_event_field_value_type type
)
68 case LTTNG_EVENT_FIELD_VALUE_TYPE_UNKNOWN
:
70 case LTTNG_EVENT_FIELD_VALUE_TYPE_INVALID
:
72 case LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT
:
73 return "UNSIGNED INT";
74 case LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_INT
:
76 case LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM
:
77 return "UNSIGNED ENUM";
78 case LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM
:
80 case LTTNG_EVENT_FIELD_VALUE_TYPE_REAL
:
82 case LTTNG_EVENT_FIELD_VALUE_TYPE_STRING
:
84 case LTTNG_EVENT_FIELD_VALUE_TYPE_ARRAY
:
91 static int validate_type(const struct lttng_event_field_value
*event_field
,
92 enum lttng_event_field_value_type expect
)
95 enum lttng_event_field_value_type value
;
97 value
= lttng_event_field_value_get_type(event_field
);
98 if (value
== LTTNG_EVENT_FIELD_VALUE_TYPE_INVALID
) {
103 ok(expect
== value
, "Expected field type %s, got %s",
104 field_value_type_to_str(expect
),
105 field_value_type_to_str(value
));
107 ret
= expect
!= value
;
114 * Validate unsigned captured field against the iteration number.
116 static int validate_unsigned_int_field(
117 const struct lttng_event_field_value
*event_field
,
118 unsigned int expected_value
)
122 enum lttng_event_field_value_status status
;
125 event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT
);
130 status
= lttng_event_field_value_unsigned_int_get_value(
131 event_field
, &value
);
132 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
133 fail("lttng_event_field_value_unsigned_int_get_value returned an error: status = %d",
139 ok(value
== (uint64_t) expected_value
,
140 "Expected unsigned integer value %u, got %" PRIu64
,
141 expected_value
, value
);
143 ret
= value
!= (uint64_t) expected_value
;
150 * Validate signed captured field.
152 static int validate_signed_int_field(
153 const struct lttng_event_field_value
*event_field
,
154 unsigned int iteration
)
157 const int64_t expected
= -1;
159 enum lttng_event_field_value_status status
;
165 event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_INT
);
170 status
= lttng_event_field_value_signed_int_get_value(
171 event_field
, &value
);
172 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
173 fail("lttng_event_field_value_signed_int_get_value returned an error: status = %d",
179 ok(value
== expected
,
180 "Expected signed integer value %" PRId64
184 ret
= value
!= expected
;
192 * Validate array of unsigned int.
194 static int validate_array_unsigned_int_field(
195 const struct lttng_event_field_value
*event_field
,
196 unsigned int iteration
)
199 enum lttng_event_field_value_status status
;
200 const unsigned int expected
= 3;
201 unsigned int i
, count
;
206 ret
= validate_type(event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_ARRAY
);
211 status
= lttng_event_field_value_array_get_length(event_field
, &count
);
212 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
213 fail("lttng_event_field_value_array_get_length");
218 ok(count
== expected
, "Expected %d subelements, got %d", expected
,
220 if (count
!= expected
) {
225 for (i
= 1; i
< count
+ 1; i
++) {
226 const struct lttng_event_field_value
*value
;
228 status
= lttng_event_field_value_array_get_element_at_index(
229 event_field
, i
- 1, &value
);
230 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
231 fail("lttng_event_field_value_array_get_element_at_index returned an error: status = %d",
237 ret
= validate_unsigned_int_field(value
, i
);
249 static int validate_array_unsigned_int_field_at_index(
250 const struct lttng_event_field_value
*event_field
,
251 unsigned int iteration
)
254 const uint64_t expected_value
= 2;
255 enum lttng_event_field_value_status status
;
262 event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT
);
267 status
= lttng_event_field_value_unsigned_int_get_value(
268 event_field
, &value
);
269 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
270 fail("lttng_event_field_value_unsigned_int_get_value returned an error: status = %d",
276 ok(value
== expected_value
,
277 "Expected unsigned integer value %" PRIu64
", got %" PRIu64
,
278 expected_value
, value
);
286 * Validate sequence for a string (seqfield1):
288 * Value: "test" encoded in UTF-8: [116, 101, 115, 116]
290 static int validate_seqfield1(const struct lttng_event_field_value
*event_field
,
291 unsigned int iteration
)
294 enum lttng_event_field_value_status status
;
295 unsigned int i
, count
;
296 const unsigned int expect
[] = {116, 101, 115, 116};
297 const size_t array_count
= sizeof(expect
) / sizeof(*expect
);
302 ret
= validate_type(event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_ARRAY
);
307 status
= lttng_event_field_value_array_get_length(event_field
, &count
);
308 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
309 fail("lttng_event_field_value_array_get_length returned an error: status = %d",
315 ok(count
== array_count
, "Expected %zu array sub-elements, got %d",
317 if (count
!= array_count
) {
322 for (i
= 0; i
< count
; i
++) {
323 const struct lttng_event_field_value
*value
;
325 status
= lttng_event_field_value_array_get_element_at_index(
326 event_field
, i
, &value
);
327 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
328 fail("lttng_event_field_value_array_get_element_at_index returned an error: status = %d",
334 ret
= validate_unsigned_int_field(value
, expect
[i
]);
345 static int validate_string(
346 const struct lttng_event_field_value
*event_field
,
350 const char *value
= NULL
;
351 enum lttng_event_field_value_status status
;
353 ret
= validate_type(event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_STRING
);
358 status
= lttng_event_field_value_string_get_value(event_field
, &value
);
360 fail("lttng_event_field_value_array_get_length returned an error: status = %d",
366 ok(!strcmp(value
, expect
), "Expected string value \"%s\", got \"%s\"",
376 * Validate string. Expected value is "test".
378 static int validate_string_test(
379 const struct lttng_event_field_value
*event_field
,
380 unsigned int iteration
)
382 const char * const expect
= "test";
387 return validate_string(event_field
, expect
);
391 * Validate escaped string. Expected value is "\*".
393 static int validate_string_escaped(
394 const struct lttng_event_field_value
*event_field
,
395 unsigned int iteration
)
397 const char * const expect
= "\\*";
402 return validate_string(event_field
, expect
);
406 * Validate real field.
408 static int validate_real(
409 const struct lttng_event_field_value
*event_field
,
414 enum lttng_event_field_value_status status
;
416 ret
= validate_type(event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_REAL
);
421 status
= lttng_event_field_value_real_get_value(event_field
, &value
);
422 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
423 fail("lttng_event_field_value_real_get_value returned an error: status = %d",
429 ok(value
== expect
, "Expected real value %f, got %f", expect
, value
);
430 ret
= value
!= expect
;
436 * Validate floatfield.
438 static int validate_floatfield(
439 const struct lttng_event_field_value
*event_field
,
440 unsigned int iteration
)
442 const double expect
= 2222.0;
447 return validate_real(event_field
, expect
);
451 * Validate doublefield.
453 static int validate_doublefield(
454 const struct lttng_event_field_value
*event_field
,
455 unsigned int iteration
)
457 const double expect
= 2.0;
462 return validate_real(event_field
, expect
);
466 * Validate enum0: enum0 = ( "AUTO: EXPECT 0" : container = 0 )
468 static int validate_enum0(const struct lttng_event_field_value
*event_field
,
469 unsigned int iteration
)
472 enum lttng_event_field_value_status status
;
474 const uint64_t expected_value
= 0;
479 ret
= validate_type(event_field
,
480 LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM
);
485 status
= lttng_event_field_value_unsigned_int_get_value(
486 event_field
, &value
);
487 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
488 fail("lttng_event_field_value_unsigned_int_get_value returned an error: status = %d",
494 ok(value
== expected_value
,
495 "Expected enum value %" PRIu64
", got %" PRIu64
,
496 expected_value
, value
);
503 * Validate enumnegative: enumnegative = ( "AUTO: EXPECT 0" : container = 0 )
505 * We expect 2 labels here.
507 static int validate_enumnegative(
508 const struct lttng_event_field_value
*event_field
,
509 unsigned int iteration
)
512 enum lttng_event_field_value_status status
;
514 const int64_t expected_value
= -1;
519 ret
= validate_type(event_field
,
520 LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM
);
525 status
= lttng_event_field_value_signed_int_get_value(
526 event_field
, &value
);
527 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
528 fail("lttng_event_field_value_unsigned_int_get_value");
533 ok(value
== expected_value
,
534 "Expected enum value %" PRId64
", got %" PRId64
,
535 expected_value
, value
);
541 static int validate_context_procname_ust(
542 const struct lttng_event_field_value
*event_field
,
543 unsigned int iteration
)
547 return validate_string(event_field
, "gen-ust-events");
550 static int validate_context_procname_kernel(
551 const struct lttng_event_field_value
*event_field
,
552 unsigned int iteration
)
556 return validate_string(event_field
, "echo");
559 struct capture_base_field_tuple test_capture_base_fields
[] = {
560 { "DOESNOTEXIST", FIELD_TYPE_PAYLOAD
, false, false, NULL
, NULL
},
561 { "intfield", FIELD_TYPE_PAYLOAD
, true, true, validate_unsigned_int_field
, validate_unsigned_int_field
},
562 { "longfield", FIELD_TYPE_PAYLOAD
, true, true, validate_unsigned_int_field
, validate_unsigned_int_field
},
563 { "signedfield", FIELD_TYPE_PAYLOAD
, true, true, validate_signed_int_field
, validate_signed_int_field
},
564 { "arrfield1", FIELD_TYPE_PAYLOAD
, true, true, validate_array_unsigned_int_field
, validate_array_unsigned_int_field
},
565 { "arrfield2", FIELD_TYPE_PAYLOAD
, true, true, validate_string_test
, validate_string_test
},
566 { "arrfield3", FIELD_TYPE_PAYLOAD
, true, true, validate_array_unsigned_int_field
, validate_array_unsigned_int_field
},
567 { "seqfield1", FIELD_TYPE_PAYLOAD
, true, true, validate_seqfield1
, validate_seqfield1
},
568 { "seqfield2", FIELD_TYPE_PAYLOAD
, true, true, validate_string_test
, validate_string_test
},
569 { "seqfield3", FIELD_TYPE_PAYLOAD
, true, true, validate_array_unsigned_int_field
, validate_array_unsigned_int_field
},
570 { "seqfield4", FIELD_TYPE_PAYLOAD
, true, true, validate_array_unsigned_int_field
, validate_array_unsigned_int_field
},
571 { "arrfield1[1]", FIELD_TYPE_ARRAY_FIELD
, true, true, validate_array_unsigned_int_field_at_index
, validate_array_unsigned_int_field_at_index
},
572 { "stringfield", FIELD_TYPE_PAYLOAD
, true, true, validate_string_test
, validate_string_test
},
573 { "stringfield2", FIELD_TYPE_PAYLOAD
, true, true, validate_string_escaped
, validate_string_escaped
},
574 { "floatfield", FIELD_TYPE_PAYLOAD
, true, false, validate_floatfield
, validate_floatfield
},
575 { "doublefield", FIELD_TYPE_PAYLOAD
, true, false, validate_doublefield
, validate_doublefield
},
576 { "enum0", FIELD_TYPE_PAYLOAD
, true, true, validate_enum0
, validate_enum0
},
577 { "enumnegative", FIELD_TYPE_PAYLOAD
, true, true, validate_enumnegative
, validate_enumnegative
},
578 { "$ctx.procname", FIELD_TYPE_CONTEXT
, true, true, validate_context_procname_ust
, validate_context_procname_kernel
},
581 static const char *get_notification_trigger_name(
582 struct lttng_notification
*notification
)
584 const char *trigger_name
= NULL
;
585 enum lttng_trigger_status trigger_status
;
586 const struct lttng_trigger
*trigger
;
588 trigger
= lttng_notification_get_trigger(notification
);
590 fail("Failed to get trigger from notification");
594 trigger_status
= lttng_trigger_get_name(trigger
, &trigger_name
);
595 switch (trigger_status
) {
596 case LTTNG_TRIGGER_STATUS_OK
:
598 case LTTNG_TRIGGER_STATUS_UNSET
:
599 trigger_name
= "(anonymous)";
602 fail("Failed to get name from notification's trigger");
610 static int validator_notification_trigger_name(
611 struct lttng_notification
*notification
,
612 const char *trigger_name
)
618 LTTNG_ASSERT(notification
);
619 LTTNG_ASSERT(trigger_name
);
621 name
= get_notification_trigger_name(notification
);
627 name_is_equal
= (strcmp(trigger_name
, name
) == 0);
628 ok(name_is_equal
, "Expected trigger name: %s got %s", trigger_name
,
631 ret
= !name_is_equal
;
638 void wait_on_file(const char *path
, bool file_exist
)
647 ret
= stat(path
, &buf
);
648 if (ret
== -1 && errno
== ENOENT
) {
651 * The file does not exist. wait a bit and
652 * continue looping until it does.
654 (void) poll(NULL
, 0, 10);
659 * File does not exist and the exit condition we want.
660 * Break from the loop and return.
669 * stat() returned 0, so the file exists. break now only if
670 * that's the exit condition we want.
679 int write_pipe(const char *path
, uint8_t data
)
684 fd
= open(path
, O_WRONLY
| O_NONBLOCK
);
686 perror("Could not open consumer control named pipe");
690 ret
= write(fd
, &data
, sizeof(data
));
692 perror("Named pipe write failed");
694 perror("Named pipe close failed");
702 perror("Name pipe closing failed");
711 int stop_consumer(const char **argv
)
715 for (i
= named_pipe_args_start
; i
< nb_args
; i
++) {
716 ret
= write_pipe(argv
[i
], 49);
722 int resume_consumer(const char **argv
)
726 for (i
= named_pipe_args_start
; i
< nb_args
; i
++) {
727 ret
= write_pipe(argv
[i
], 0);
733 int suspend_application(void)
738 if (!stat(app_state_file
, &buf
)) {
739 fail("App is already in a suspended state.");
745 * Send SIGUSR1 to application instructing it to bypass tracepoint.
747 LTTNG_ASSERT(app_pid
> 1);
749 ret
= kill(app_pid
, SIGUSR1
);
751 fail("SIGUSR1 failed. errno %d", errno
);
756 wait_on_file(app_state_file
, true);
764 int resume_application(void)
769 ret
= stat(app_state_file
, &buf
);
770 if (ret
== -1 && errno
== ENOENT
) {
771 fail("State file does not exist");
779 LTTNG_ASSERT(app_pid
> 1);
781 ret
= kill(app_pid
, SIGUSR1
);
783 fail("SIGUSR1 failed. errno %d", errno
);
788 wait_on_file(app_state_file
, false);
797 void test_triggers_buffer_usage_condition(const char *session_name
,
798 const char *channel_name
,
799 enum lttng_condition_type condition_type
)
801 unsigned int test_vector_size
= 5, i
;
802 enum lttng_condition_status condition_status
;
803 struct lttng_action
*action
;
806 action
= lttng_action_notify_create();
808 fail("Setup error on action creation");
812 /* Test lttng_register_trigger with null value */
813 ok(lttng_register_trigger(NULL
) == -LTTNG_ERR_INVALID
, "Registering a NULL trigger fails as expected");
815 /* Test: register a trigger */
817 for (i
= 0; i
< pow(2,test_vector_size
); i
++) {
819 char *test_tuple_string
= NULL
;
820 unsigned int mask_position
= 0;
821 bool session_name_set
= false;
822 bool channel_name_set
= false;
823 bool threshold_ratio_set
= false;
824 bool threshold_byte_set
= false;
825 bool domain_type_set
= false;
827 struct lttng_trigger
*trigger
= NULL
;
828 struct lttng_condition
*condition
= NULL
;
830 /* Create base condition */
831 switch (condition_type
) {
832 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
833 condition
= lttng_condition_buffer_usage_low_create();
835 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
836 condition
= lttng_condition_buffer_usage_high_create();
849 /* Prepare the condition for trigger registration test */
851 /* Set session name */
852 if ((1 << mask_position
) & i
) {
853 condition_status
= lttng_condition_buffer_usage_set_session_name(
854 condition
, session_name
);
855 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
859 session_name_set
= true;
863 /* Set channel name */
864 if ((1 << mask_position
) & i
) {
865 condition_status
= lttng_condition_buffer_usage_set_channel_name(
866 condition
, channel_name
);
867 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
871 channel_name_set
= true;
875 /* Set threshold ratio */
876 if ((1 << mask_position
) & i
) {
877 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
879 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
883 threshold_ratio_set
= true;
887 /* Set threshold byte */
888 if ((1 << mask_position
) & i
) {
889 condition_status
= lttng_condition_buffer_usage_set_threshold(
891 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
895 threshold_byte_set
= true;
899 /* Set domain type */
900 if ((1 << mask_position
) & i
) {
901 condition_status
= lttng_condition_buffer_usage_set_domain_type(
902 condition
, LTTNG_DOMAIN_UST
);
903 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
907 domain_type_set
= true;
911 if (mask_position
!= test_vector_size
-1) {
912 LTTNG_ASSERT("Logic error for test vector generation");
915 loop_ret
= asprintf(&test_tuple_string
, "session name %s, channel name %s, threshold ratio %s, threshold byte %s, domain type %s",
916 session_name_set
? "set" : "unset",
917 channel_name_set
? "set" : "unset",
918 threshold_ratio_set
? "set" : "unset",
919 threshold_byte_set
? "set" : "unset",
920 domain_type_set
? "set" : "unset");
921 if (!test_tuple_string
|| loop_ret
< 0) {
927 trigger
= lttng_trigger_create(condition
, action
);
933 loop_ret
= lttng_register_trigger(trigger
);
937 fail("Setup error occurred for tuple: %s", test_tuple_string
);
941 /* This combination happens three times */
942 if (session_name_set
&& channel_name_set
943 && (threshold_ratio_set
|| threshold_byte_set
)
944 && domain_type_set
) {
945 ok(loop_ret
== 0, "Trigger is registered: %s", test_tuple_string
);
948 * Test that a trigger cannot be registered
951 loop_ret
= lttng_register_trigger(trigger
);
952 ok(loop_ret
== -LTTNG_ERR_TRIGGER_EXISTS
, "Re-register trigger fails as expected: %s", test_tuple_string
);
954 /* Test that a trigger can be unregistered */
955 loop_ret
= lttng_unregister_trigger(trigger
);
956 ok(loop_ret
== 0, "Unregister trigger: %s", test_tuple_string
);
959 * Test that unregistration of a non-previously
960 * registered trigger fail.
962 loop_ret
= lttng_unregister_trigger(trigger
);
963 ok(loop_ret
== -LTTNG_ERR_TRIGGER_NOT_FOUND
, "Unregister of a non-registered trigger fails as expected: %s", test_tuple_string
);
965 ok(loop_ret
== -LTTNG_ERR_INVALID_TRIGGER
, "Trigger is invalid as expected and cannot be registered: %s", test_tuple_string
);
969 free(test_tuple_string
);
970 lttng_trigger_destroy(trigger
);
971 lttng_condition_destroy(condition
);
975 lttng_action_destroy(action
);
979 void wait_data_pending(const char *session_name
)
984 ret
= lttng_data_pending(session_name
);
985 LTTNG_ASSERT(ret
>= 0);
990 int setup_buffer_usage_condition(struct lttng_condition
*condition
,
991 const char *condition_name
,
992 const char *session_name
,
993 const char *channel_name
,
994 const enum lttng_domain_type domain_type
)
996 enum lttng_condition_status condition_status
;
999 condition_status
= lttng_condition_buffer_usage_set_session_name(
1000 condition
, session_name
);
1001 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1002 fail("Failed to set session name on creation of condition `%s`",
1008 condition_status
= lttng_condition_buffer_usage_set_channel_name(
1009 condition
, channel_name
);
1010 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1011 fail("Failed to set channel name on creation of condition `%s`",
1017 condition_status
= lttng_condition_buffer_usage_set_domain_type(
1018 condition
, domain_type
);
1019 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1020 fail("Failed to set domain type on creation of condition `%s`",
1031 void test_invalid_channel_subscription(
1032 const enum lttng_domain_type domain_type
)
1034 enum lttng_condition_status condition_status
;
1035 enum lttng_notification_channel_status nc_status
;
1036 struct lttng_condition
*dummy_condition
= NULL
;
1037 struct lttng_condition
*dummy_invalid_condition
= NULL
;
1038 struct lttng_notification_channel
*notification_channel
= NULL
;
1041 notification_channel
= lttng_notification_channel_create(
1042 lttng_session_daemon_notification_endpoint
);
1043 ok(notification_channel
, "Notification channel object creation");
1044 if (!notification_channel
) {
1049 * Create a dummy, empty (thus invalid) condition to test error paths.
1051 dummy_invalid_condition
= lttng_condition_buffer_usage_low_create();
1052 if (!dummy_invalid_condition
) {
1053 fail("Setup error on condition creation");
1058 * Test subscription and unsubscription of an invalid condition to/from
1061 nc_status
= lttng_notification_channel_subscribe(
1062 notification_channel
, dummy_invalid_condition
);
1063 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
1064 "Subscribing to an invalid condition");
1066 nc_status
= lttng_notification_channel_unsubscribe(
1067 notification_channel
, dummy_invalid_condition
);
1068 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
1069 "Unsubscribing from an invalid condition");
1071 /* Create a valid dummy condition with a ratio of 0.5 */
1072 dummy_condition
= lttng_condition_buffer_usage_low_create();
1073 if (!dummy_condition
) {
1074 fail("Setup error on dummy_condition creation");
1078 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
1079 dummy_condition
, 0.5);
1080 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1081 fail("Setup error on condition creation");
1085 ret
= setup_buffer_usage_condition(dummy_condition
, "dummy_condition",
1086 "dummy_session", "dummy_channel", domain_type
);
1088 fail("Setup error on dummy condition creation");
1093 * Test subscription and unsubscription to/from a channel with invalid
1096 nc_status
= lttng_notification_channel_subscribe(NULL
, NULL
);
1097 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
1098 "Notification channel subscription is invalid: NULL, NULL");
1100 nc_status
= lttng_notification_channel_subscribe(
1101 notification_channel
, NULL
);
1102 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
1103 "Notification channel subscription is invalid: NON-NULL, NULL");
1105 nc_status
= lttng_notification_channel_subscribe(NULL
, dummy_condition
);
1106 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
1107 "Notification channel subscription is invalid: NULL, NON-NULL");
1109 nc_status
= lttng_notification_channel_unsubscribe(
1110 notification_channel
, dummy_condition
);
1111 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION
,
1112 "Unsubscribing from a valid unknown condition");
1115 lttng_notification_channel_destroy(notification_channel
);
1116 lttng_condition_destroy(dummy_invalid_condition
);
1117 lttng_condition_destroy(dummy_condition
);
1121 enum buffer_usage_type
{
1122 BUFFER_USAGE_TYPE_LOW
,
1123 BUFFER_USAGE_TYPE_HIGH
,
1126 static int register_buffer_usage_notify_trigger(const char *session_name
,
1127 const char *channel_name
,
1128 const enum lttng_domain_type domain_type
,
1129 enum buffer_usage_type buffer_usage_type
,
1131 struct lttng_condition
**condition
,
1132 struct lttng_action
**action
,
1133 struct lttng_trigger
**trigger
)
1135 enum lttng_condition_status condition_status
;
1136 struct lttng_action
*tmp_action
= NULL
;
1137 struct lttng_condition
*tmp_condition
= NULL
;
1138 struct lttng_trigger
*tmp_trigger
= NULL
;
1142 tmp_action
= lttng_action_notify_create();
1144 fail("Setup error on action creation");
1149 if (buffer_usage_type
== BUFFER_USAGE_TYPE_LOW
) {
1150 tmp_condition
= lttng_condition_buffer_usage_low_create();
1152 tmp_condition
= lttng_condition_buffer_usage_high_create();
1155 if (!tmp_condition
) {
1156 fail("Setup error on condition creation");
1161 /* Set the buffer usage threashold */
1162 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
1163 tmp_condition
, ratio
);
1164 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1165 fail("Setup error on condition creation");
1170 ret
= setup_buffer_usage_condition(tmp_condition
, "condition_name",
1171 session_name
, channel_name
, domain_type
);
1173 fail("Setup error on condition creation");
1178 /* Register the trigger for condition. */
1179 tmp_trigger
= lttng_trigger_create(tmp_condition
, tmp_action
);
1181 fail("Setup error on trigger creation");
1186 ret
= lttng_register_trigger(tmp_trigger
);
1188 fail("Setup error on trigger registration");
1193 *condition
= tmp_condition
;
1194 *trigger
= tmp_trigger
;
1195 *action
= tmp_action
;
1199 lttng_action_destroy(tmp_action
);
1200 lttng_condition_destroy(tmp_condition
);
1201 lttng_trigger_destroy(tmp_trigger
);
1207 static void test_subscription_twice(const char *session_name
,
1208 const char *channel_name
,
1209 const enum lttng_domain_type domain_type
)
1212 enum lttng_notification_channel_status nc_status
;
1214 struct lttng_action
*action
= NULL
;
1215 struct lttng_notification_channel
*notification_channel
= NULL
;
1216 struct lttng_trigger
*trigger
= NULL
;
1218 struct lttng_condition
*condition
= NULL
;
1220 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
1221 domain_type
, BUFFER_USAGE_TYPE_LOW
, 0.99, &condition
,
1224 fail("Setup error on trigger registration in %s()",
1229 /* Begin testing. */
1230 notification_channel
= lttng_notification_channel_create(
1231 lttng_session_daemon_notification_endpoint
);
1232 ok(notification_channel
, "Notification channel object creation");
1233 if (!notification_channel
) {
1237 /* Subscribe a valid condition. */
1238 nc_status
= lttng_notification_channel_subscribe(
1239 notification_channel
, condition
);
1240 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1241 "Subscribe to condition");
1243 /* Subscribing again should fail. */
1244 nc_status
= lttng_notification_channel_subscribe(
1245 notification_channel
, condition
);
1246 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED
,
1247 "Subscribe to a condition for which subscription was already done");
1250 ret
= lttng_unregister_trigger(trigger
);
1252 fail("Failed to unregister trigger in %s()", __FUNCTION__
);
1255 lttng_trigger_destroy(trigger
);
1256 lttng_notification_channel_destroy(notification_channel
);
1257 lttng_action_destroy(action
);
1258 lttng_condition_destroy(condition
);
1261 static void test_buffer_usage_notification_channel(const char *session_name
,
1262 const char *channel_name
,
1263 const enum lttng_domain_type domain_type
,
1267 enum lttng_notification_channel_status nc_status
;
1269 struct lttng_action
*low_action
= NULL
;
1270 struct lttng_action
*high_action
= NULL
;
1271 struct lttng_notification
*notification
= NULL
;
1272 struct lttng_notification_channel
*notification_channel
= NULL
;
1273 struct lttng_trigger
*low_trigger
= NULL
;
1274 struct lttng_trigger
*high_trigger
= NULL
;
1276 struct lttng_condition
*low_condition
= NULL
;
1277 struct lttng_condition
*high_condition
= NULL
;
1279 const double low_ratio
= 0.0;
1280 const double high_ratio
= 0.90;
1282 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
1283 domain_type
, BUFFER_USAGE_TYPE_LOW
, low_ratio
,
1284 &low_condition
, &low_action
, &low_trigger
);
1286 fail("Setup error on low trigger registration");
1290 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
1291 domain_type
, BUFFER_USAGE_TYPE_HIGH
, high_ratio
,
1292 &high_condition
, &high_action
, &high_trigger
);
1294 fail("Setup error on high trigger registration");
1299 notification_channel
= lttng_notification_channel_create(
1300 lttng_session_daemon_notification_endpoint
);
1301 ok(notification_channel
, "Notification channel object creation");
1302 if (!notification_channel
) {
1306 /* Subscribe a valid low condition */
1307 nc_status
= lttng_notification_channel_subscribe(
1308 notification_channel
, low_condition
);
1309 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1310 "Subscribe to low condition");
1312 /* Subscribe a valid high condition */
1313 nc_status
= lttng_notification_channel_subscribe(
1314 notification_channel
, high_condition
);
1315 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1316 "Subscribe to high condition");
1318 resume_application();
1320 /* Wait for notification to happen */
1321 stop_consumer(argv
);
1322 lttng_start_tracing(session_name
);
1324 /* Wait for high notification */
1326 nc_status
= lttng_notification_channel_get_next_notification(
1327 notification_channel
, ¬ification
);
1328 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
1329 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
1330 lttng_condition_get_type(lttng_notification_get_condition(
1332 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
1333 "High notification received after intermediary communication");
1334 lttng_notification_destroy(notification
);
1335 notification
= NULL
;
1337 suspend_application();
1338 lttng_stop_tracing_no_wait(session_name
);
1339 resume_consumer(argv
);
1340 wait_data_pending(session_name
);
1343 * Test that communication still work even if there is notification
1344 * waiting for consumption.
1347 nc_status
= lttng_notification_channel_unsubscribe(
1348 notification_channel
, low_condition
);
1349 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1350 "Unsubscribe with pending notification");
1352 nc_status
= lttng_notification_channel_subscribe(
1353 notification_channel
, low_condition
);
1354 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1355 "Subscribe with pending notification");
1358 nc_status
= lttng_notification_channel_get_next_notification(
1359 notification_channel
, ¬ification
);
1360 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
1361 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
1362 lttng_condition_get_type(lttng_notification_get_condition(
1364 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
,
1365 "Low notification received after intermediary communication");
1366 lttng_notification_destroy(notification
);
1367 notification
= NULL
;
1369 /* Stop consumer to force a high notification */
1370 stop_consumer(argv
);
1371 resume_application();
1372 lttng_start_tracing(session_name
);
1375 nc_status
= lttng_notification_channel_get_next_notification(
1376 notification_channel
, ¬ification
);
1377 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
1378 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
1379 lttng_condition_get_type(lttng_notification_get_condition(
1381 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
1382 "High notification received after intermediary communication");
1383 lttng_notification_destroy(notification
);
1384 notification
= NULL
;
1386 suspend_application();
1387 lttng_stop_tracing_no_wait(session_name
);
1388 resume_consumer(argv
);
1389 wait_data_pending(session_name
);
1392 nc_status
= lttng_notification_channel_get_next_notification(
1393 notification_channel
, ¬ification
);
1394 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
1395 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
1396 lttng_condition_get_type(lttng_notification_get_condition(
1398 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
,
1399 "Low notification received after re-subscription");
1400 lttng_notification_destroy(notification
);
1401 notification
= NULL
;
1403 stop_consumer(argv
);
1404 resume_application();
1405 /* Stop consumer to force a high notification */
1406 lttng_start_tracing(session_name
);
1409 nc_status
= lttng_notification_channel_get_next_notification(
1410 notification_channel
, ¬ification
);
1411 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
1412 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
1413 lttng_condition_get_type(lttng_notification_get_condition(
1415 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
1416 "High notification");
1417 lttng_notification_destroy(notification
);
1418 notification
= NULL
;
1420 suspend_application();
1422 /* Resume consumer to allow event consumption */
1423 lttng_stop_tracing_no_wait(session_name
);
1424 resume_consumer(argv
);
1425 wait_data_pending(session_name
);
1427 nc_status
= lttng_notification_channel_unsubscribe(
1428 notification_channel
, low_condition
);
1429 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1430 "Unsubscribe low condition with pending notification");
1432 nc_status
= lttng_notification_channel_unsubscribe(
1433 notification_channel
, high_condition
);
1434 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1435 "Unsubscribe high condition with pending notification");
1438 lttng_notification_channel_destroy(notification_channel
);
1439 lttng_trigger_destroy(low_trigger
);
1440 lttng_trigger_destroy(high_trigger
);
1441 lttng_action_destroy(low_action
);
1442 lttng_action_destroy(high_action
);
1443 lttng_condition_destroy(low_condition
);
1444 lttng_condition_destroy(high_condition
);
1447 static void create_tracepoint_event_rule_trigger(const char *event_pattern
,
1448 const char *trigger_name
,
1450 unsigned int exclusion_count
,
1451 const char * const *exclusions
,
1452 enum lttng_domain_type domain_type
,
1453 condition_capture_desc_cb capture_desc_cb
,
1454 struct lttng_condition
**condition
,
1455 struct lttng_trigger
**trigger
)
1457 typedef struct lttng_event_rule
*(*event_rule_create
)(void);
1458 typedef enum lttng_event_rule_status (
1459 *event_rule_set_name_pattern
)(
1460 struct lttng_event_rule
*rule
,
1461 const char *pattern
);
1462 typedef enum lttng_event_rule_status (*event_rule_set_filter
)(
1463 struct lttng_event_rule
*rule
,
1464 const char *expression
);
1465 typedef enum lttng_event_rule_status (
1466 *event_rule_add_name_pattern_exclusion
)(
1467 struct lttng_event_rule
* rule
, const char *exclusion
);
1469 enum lttng_event_rule_status event_rule_status
;
1470 struct lttng_action
*tmp_action
= NULL
;
1471 struct lttng_event_rule
*event_rule
= NULL
;
1472 struct lttng_condition
*tmp_condition
= NULL
;
1473 struct lttng_trigger
*tmp_trigger
= NULL
;
1475 enum lttng_error_code ret_code
;
1476 event_rule_create create
;
1477 event_rule_set_name_pattern set_name_pattern
;
1478 event_rule_set_filter set_filter
;
1479 event_rule_add_name_pattern_exclusion add_name_pattern_exclusion
;
1481 LTTNG_ASSERT(event_pattern
);
1482 LTTNG_ASSERT(trigger_name
);
1483 LTTNG_ASSERT(condition
);
1484 LTTNG_ASSERT(trigger
);
1486 /* Set the function pointers based on the domain type. */
1487 switch (domain_type
) {
1488 case LTTNG_DOMAIN_UST
:
1489 create
= lttng_event_rule_user_tracepoint_create
;
1490 set_name_pattern
= lttng_event_rule_user_tracepoint_set_name_pattern
;
1491 set_filter
= lttng_event_rule_user_tracepoint_set_filter
;
1492 add_name_pattern_exclusion
= lttng_event_rule_user_tracepoint_add_name_pattern_exclusion
;
1494 case LTTNG_DOMAIN_KERNEL
:
1495 create
= lttng_event_rule_kernel_tracepoint_create
;
1496 set_name_pattern
= lttng_event_rule_kernel_tracepoint_set_name_pattern
;
1497 set_filter
= lttng_event_rule_kernel_tracepoint_set_filter
;
1498 add_name_pattern_exclusion
= NULL
;
1505 event_rule
= create();
1506 ok(event_rule
, "Tracepoint event rule object creation");
1508 event_rule_status
= set_name_pattern(event_rule
, event_pattern
);
1509 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1510 "Setting tracepoint event rule pattern: '%s'",
1514 event_rule_status
= set_filter(event_rule
, filter
);
1515 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1516 "Setting tracepoint event rule filter: '%s'",
1522 bool success
= true;
1524 LTTNG_ASSERT(domain_type
== LTTNG_DOMAIN_UST
);
1525 LTTNG_ASSERT(add_name_pattern_exclusion
!= NULL
);
1526 LTTNG_ASSERT(exclusion_count
> 0);
1528 for (i
= 0; i
< exclusion_count
; i
++) {
1529 event_rule_status
= add_name_pattern_exclusion(
1530 event_rule
, exclusions
[i
]);
1531 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1532 fail("Setting tracepoint event rule exclusion '%s'.",
1538 ok(success
, "Setting tracepoint event rule exclusions");
1541 tmp_condition
= lttng_condition_event_rule_matches_create(event_rule
);
1542 ok(tmp_condition
, "Condition event rule object creation");
1544 if (capture_desc_cb
) {
1545 ret
= capture_desc_cb(tmp_condition
);
1547 fail("Failed to generate the condition capture descriptor");
1552 tmp_action
= lttng_action_notify_create();
1553 ok(tmp_action
, "Action event rule object creation");
1555 tmp_trigger
= lttng_trigger_create(tmp_condition
, tmp_action
);
1556 ok(tmp_trigger
, "Trigger object creation %s", trigger_name
);
1558 ret_code
= lttng_register_trigger_with_name(tmp_trigger
, trigger_name
);
1559 ok(ret_code
== LTTNG_OK
, "Trigger registration %s", trigger_name
);
1561 lttng_event_rule_destroy(event_rule
);
1563 *condition
= tmp_condition
;
1564 *trigger
= tmp_trigger
;
1569 static struct lttng_notification
*get_next_notification(
1570 struct lttng_notification_channel
*notification_channel
)
1572 struct lttng_notification
*local_notification
= NULL
;
1573 enum lttng_notification_channel_status status
;
1575 /* Receive the next notification. */
1576 status
= lttng_notification_channel_get_next_notification(
1577 notification_channel
, &local_notification
);
1580 case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
:
1582 case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED
:
1583 fail("Notifications have been dropped");
1584 local_notification
= NULL
;
1587 /* Unhandled conditions / errors. */
1588 fail("Failed to get next notification (unknown notification channel status): status = %d",
1590 local_notification
= NULL
;
1594 return local_notification
;
1597 static void test_tracepoint_event_rule_notification(
1598 enum lttng_domain_type domain_type
)
1602 const int notification_count
= 3;
1603 enum lttng_notification_channel_status nc_status
;
1604 struct lttng_action
*action
= NULL
;
1605 struct lttng_condition
*condition
= NULL
;
1606 struct lttng_notification_channel
*notification_channel
= NULL
;
1607 struct lttng_trigger
*trigger
= NULL
;
1608 const char * const trigger_name
= "my_precious";
1609 const char *pattern
;
1611 if (domain_type
== LTTNG_DOMAIN_UST
) {
1612 pattern
= "tp:tptest";
1614 pattern
= "lttng_test_filter_event";
1617 create_tracepoint_event_rule_trigger(pattern
, trigger_name
, NULL
, 0,
1618 NULL
, domain_type
, NULL
, &condition
, &trigger
);
1620 notification_channel
= lttng_notification_channel_create(
1621 lttng_session_daemon_notification_endpoint
);
1622 ok(notification_channel
, "Notification channel object creation");
1624 nc_status
= lttng_notification_channel_subscribe(
1625 notification_channel
, condition
);
1626 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1627 "Subscribe to tracepoint event rule condition");
1629 resume_application();
1631 /* Get notifications. */
1632 for (i
= 0; i
< notification_count
; i
++) {
1633 struct lttng_notification
*notification
= get_next_notification(
1634 notification_channel
);
1636 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1637 notification_count
);
1640 if (notification
== NULL
) {
1644 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1645 lttng_notification_destroy(notification
);
1652 suspend_application();
1653 lttng_notification_channel_destroy(notification_channel
);
1654 lttng_unregister_trigger(trigger
);
1655 lttng_trigger_destroy(trigger
);
1656 lttng_action_destroy(action
);
1657 lttng_condition_destroy(condition
);
1661 static void test_tracepoint_event_rule_notification_filter(
1662 enum lttng_domain_type domain_type
)
1665 const int notification_count
= 3;
1666 enum lttng_notification_channel_status nc_status
;
1667 struct lttng_condition
*ctrl_condition
= NULL
, *condition
= NULL
;
1668 struct lttng_notification_channel
*notification_channel
= NULL
;
1669 struct lttng_trigger
*ctrl_trigger
= NULL
, *trigger
= NULL
;
1670 const char * const ctrl_trigger_name
= "control_trigger";
1671 const char * const trigger_name
= "trigger";
1672 const char *pattern
;
1673 int ctrl_count
= 0, count
= 0;
1675 if (domain_type
== LTTNG_DOMAIN_UST
) {
1676 pattern
= "tp:tptest";
1678 pattern
= "lttng_test_filter_event";
1681 notification_channel
= lttng_notification_channel_create(
1682 lttng_session_daemon_notification_endpoint
);
1683 ok(notification_channel
, "Notification channel object creation");
1685 create_tracepoint_event_rule_trigger(pattern
, ctrl_trigger_name
, NULL
,
1686 0, NULL
, domain_type
, NULL
, &ctrl_condition
, &ctrl_trigger
);
1688 nc_status
= lttng_notification_channel_subscribe(
1689 notification_channel
, ctrl_condition
);
1690 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1691 "Subscribe to tracepoint event rule condition");
1694 * Attach a filter expression to get notification only if the
1695 * `intfield` is even.
1697 create_tracepoint_event_rule_trigger(pattern
, trigger_name
,
1698 "(intfield & 1) == 0", 0, NULL
, domain_type
, NULL
, &condition
,
1701 nc_status
= lttng_notification_channel_subscribe(
1702 notification_channel
, condition
);
1703 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1704 "Subscribe to tracepoint event rule condition");
1707 * We registered 2 notifications triggers, one with a filter and one
1708 * without (control). The one with a filter will only fired when the
1709 * `intfield` is a multiple of 2. We should get two times as many
1710 * control notifications as filter notifications.
1712 resume_application();
1715 * Get 3 notifications. We should get 1 for the regular trigger (with
1716 * the filter) and 2 from the control trigger. This works whatever
1717 * the order we receive the notifications.
1719 for (i
= 0; i
< notification_count
; i
++) {
1721 struct lttng_notification
*notification
= get_next_notification(
1722 notification_channel
);
1724 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1725 notification_count
);
1728 if (notification
== NULL
) {
1732 name
= get_notification_trigger_name(notification
);
1734 lttng_notification_destroy(notification
);
1738 if (strcmp(ctrl_trigger_name
, name
) == 0) {
1740 } else if (strcmp(trigger_name
, name
) == 0) {
1744 lttng_notification_destroy(notification
);
1747 ok(ctrl_count
/ 2 == count
,
1748 "Get twice as many control notif as of regular notif");
1751 suspend_application();
1753 lttng_unregister_trigger(trigger
);
1754 lttng_unregister_trigger(ctrl_trigger
);
1755 lttng_notification_channel_destroy(notification_channel
);
1756 lttng_trigger_destroy(trigger
);
1757 lttng_trigger_destroy(ctrl_trigger
);
1758 lttng_condition_destroy(condition
);
1759 lttng_condition_destroy(ctrl_condition
);
1762 static void test_tracepoint_event_rule_notification_exclusion(
1763 enum lttng_domain_type domain_type
)
1765 enum lttng_notification_channel_status nc_status
;
1766 struct lttng_condition
*ctrl_condition
= NULL
, *condition
= NULL
;
1767 struct lttng_notification_channel
*notification_channel
= NULL
;
1768 struct lttng_trigger
*ctrl_trigger
= NULL
, *trigger
= NULL
;
1769 int ctrl_count
= 0, count
= 0, i
;
1770 const int notification_count
= 6;
1771 const char * const ctrl_trigger_name
= "control_exclusion_trigger";
1772 const char * const trigger_name
= "exclusion_trigger";
1773 const char * const pattern
= "tp:tptest*";
1774 const char * const exclusions
[] = {
1781 notification_channel
= lttng_notification_channel_create(
1782 lttng_session_daemon_notification_endpoint
);
1783 ok(notification_channel
, "Notification channel object creation");
1785 create_tracepoint_event_rule_trigger(pattern
, ctrl_trigger_name
, NULL
,
1786 0, NULL
, domain_type
, NULL
, &ctrl_condition
,
1789 nc_status
= lttng_notification_channel_subscribe(
1790 notification_channel
, ctrl_condition
);
1791 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1792 "Subscribe to tracepoint event rule condition");
1794 create_tracepoint_event_rule_trigger(pattern
, trigger_name
, NULL
, 4,
1795 exclusions
, domain_type
, NULL
, &condition
,
1798 nc_status
= lttng_notification_channel_subscribe(
1799 notification_channel
, condition
);
1800 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1801 "Subscribe to tracepoint event rule condition");
1804 * We registered 2 notifications triggers, one with an exclusion and
1805 * one without (control).
1806 * - The trigger with an exclusion will fire once every iteration.
1807 * - The trigger without an exclusion will fire 5 times every
1810 * We should get 5 times as many notifications from the control
1813 resume_application();
1816 * Get 6 notifications. We should get 1 for the regular trigger (with
1817 * the exclusion) and 5 from the control trigger. This works whatever
1818 * the order we receive the notifications.
1820 for (i
= 0; i
< notification_count
; i
++) {
1822 struct lttng_notification
*notification
= get_next_notification(
1823 notification_channel
);
1825 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1826 notification_count
);
1829 if (notification
== NULL
) {
1833 name
= get_notification_trigger_name(notification
);
1835 lttng_notification_destroy(notification
);
1839 if (strcmp(ctrl_trigger_name
, name
) == 0) {
1841 } else if (strcmp(trigger_name
, name
) == 0) {
1845 lttng_notification_destroy(notification
);
1848 ok(ctrl_count
/ 5 == count
,
1849 "Got 5 times as many control notif as of regular notif");
1852 suspend_application();
1854 lttng_unregister_trigger(trigger
);
1855 lttng_unregister_trigger(ctrl_trigger
);
1856 lttng_notification_channel_destroy(notification_channel
);
1857 lttng_trigger_destroy(trigger
);
1858 lttng_trigger_destroy(ctrl_trigger
);
1859 lttng_condition_destroy(condition
);
1860 lttng_condition_destroy(ctrl_condition
);
1864 static void test_kprobe_event_rule_notification(void)
1867 enum lttng_error_code ret_code
;
1868 const int notification_count
= 3;
1869 enum lttng_notification_channel_status nc_status
;
1870 enum lttng_event_rule_status event_rule_status
;
1871 struct lttng_notification_channel
*notification_channel
= NULL
;
1872 struct lttng_condition
*condition
= NULL
;
1873 struct lttng_kernel_probe_location
*location
= NULL
;
1874 struct lttng_event_rule
*event_rule
= NULL
;
1875 struct lttng_action
*action
= NULL
;
1876 struct lttng_trigger
*trigger
= NULL
;
1877 const char * const trigger_name
= "kprobe_trigger";
1878 const char * const symbol_name
= "lttng_test_filter_event_write";
1880 action
= lttng_action_notify_create();
1882 fail("Failed to create notify action");
1886 location
= lttng_kernel_probe_location_symbol_create(symbol_name
, 0);
1888 fail("Failed to create kernel probe location");
1892 notification_channel
= lttng_notification_channel_create(
1893 lttng_session_daemon_notification_endpoint
);
1894 ok(notification_channel
, "Notification channel object creation");
1896 event_rule
= lttng_event_rule_kernel_kprobe_create(location
);
1897 ok(event_rule
, "kprobe event rule object creation");
1899 event_rule_status
= lttng_event_rule_kernel_kprobe_set_event_name(
1900 event_rule
, trigger_name
);
1901 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1902 "Setting kprobe event rule name: '%s'", trigger_name
);
1904 condition
= lttng_condition_event_rule_matches_create(event_rule
);
1905 ok(condition
, "Condition event rule object creation");
1907 /* Register the trigger for condition. */
1908 trigger
= lttng_trigger_create(condition
, action
);
1910 fail("Failed to create trigger with kernel probe event rule condition and notify action");
1914 ret_code
= lttng_register_trigger_with_name(trigger
, trigger_name
);
1915 if (ret_code
!= LTTNG_OK
) {
1916 fail("Failed to register trigger with kernel probe event rule condition and notify action");
1920 nc_status
= lttng_notification_channel_subscribe(
1921 notification_channel
, condition
);
1922 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1923 "Subscribe to tracepoint event rule condition");
1925 resume_application();
1927 for (i
= 0; i
< notification_count
; i
++) {
1928 struct lttng_notification
*notification
= get_next_notification(
1929 notification_channel
);
1931 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1932 notification_count
);
1935 if (notification
== NULL
) {
1939 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1940 lttng_notification_destroy(notification
);
1947 suspend_application();
1948 lttng_notification_channel_destroy(notification_channel
);
1949 lttng_unregister_trigger(trigger
);
1950 lttng_trigger_destroy(trigger
);
1951 lttng_action_destroy(action
);
1952 lttng_event_rule_destroy(event_rule
);
1953 lttng_condition_destroy(condition
);
1954 lttng_kernel_probe_location_destroy(location
);
1958 static void test_uprobe_event_rule_notification(
1959 const char *testapp_path
,
1960 const char *test_symbol_name
)
1963 enum lttng_error_code ret_code
;
1964 const int notification_count
= 3;
1965 enum lttng_notification_channel_status nc_status
;
1966 enum lttng_event_rule_status event_rule_status
;
1967 struct lttng_notification_channel
*notification_channel
= NULL
;
1968 struct lttng_userspace_probe_location
*probe_location
= NULL
;
1969 struct lttng_userspace_probe_location_lookup_method
*lookup_method
=
1971 struct lttng_condition
*condition
= NULL
;
1972 struct lttng_event_rule
*event_rule
= NULL
;
1973 struct lttng_action
*action
= NULL
;
1974 struct lttng_trigger
*trigger
= NULL
;
1975 const char * const trigger_name
= "uprobe_trigger";
1977 action
= lttng_action_notify_create();
1979 fail("Failed to create notify action");
1983 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1984 if (!lookup_method
) {
1985 fail("Setup error on userspace probe lookup method creation");
1989 probe_location
= lttng_userspace_probe_location_function_create(
1990 testapp_path
, test_symbol_name
, lookup_method
);
1991 if (!probe_location
) {
1992 fail("Failed to create userspace probe location");
1996 notification_channel
= lttng_notification_channel_create(
1997 lttng_session_daemon_notification_endpoint
);
1998 ok(notification_channel
, "Notification channel object creation");
2000 event_rule
= lttng_event_rule_kernel_uprobe_create(probe_location
);
2001 ok(event_rule
, "uprobe event rule object creation");
2003 event_rule_status
= lttng_event_rule_kernel_uprobe_set_event_name(
2004 event_rule
, trigger_name
);
2005 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
2006 "Setting uprobe event rule name: '%s'", trigger_name
);
2008 condition
= lttng_condition_event_rule_matches_create(event_rule
);
2009 ok(condition
, "Condition event rule object creation");
2011 /* Register the trigger for condition. */
2012 trigger
= lttng_trigger_create(condition
, action
);
2014 fail("Failed to create trigger with userspace probe event rule condition and notify action");
2018 ret_code
= lttng_register_trigger_with_name(trigger
, trigger_name
);
2019 if (ret_code
!= LTTNG_OK
) {
2020 fail("Failed to register trigger with userspace probe event rule condition and notify action");
2024 nc_status
= lttng_notification_channel_subscribe(
2025 notification_channel
, condition
);
2026 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
2027 "Subscribe to tracepoint event rule condition");
2029 resume_application();
2031 for (i
= 0; i
< 3; i
++) {
2032 struct lttng_notification
*notification
= get_next_notification(
2033 notification_channel
);
2035 ok(notification
, "Received notification (%d/%d)", i
+ 1,
2036 notification_count
);
2039 if (notification
== NULL
) {
2043 ret
= validator_notification_trigger_name(notification
, trigger_name
);
2044 lttng_notification_destroy(notification
);
2050 suspend_application();
2052 lttng_notification_channel_destroy(notification_channel
);
2053 lttng_unregister_trigger(trigger
);
2054 lttng_trigger_destroy(trigger
);
2055 lttng_action_destroy(action
);
2056 lttng_userspace_probe_location_destroy(probe_location
);
2057 lttng_event_rule_destroy(event_rule
);
2058 lttng_condition_destroy(condition
);
2062 static void test_syscall_event_rule_notification(void)
2065 enum lttng_error_code ret_code
;
2066 const int notification_count
= 3;
2067 enum lttng_notification_channel_status nc_status
;
2068 enum lttng_event_rule_status event_rule_status
;
2069 struct lttng_notification_channel
*notification_channel
= NULL
;
2070 struct lttng_condition
*condition
= NULL
;
2071 struct lttng_event_rule
*event_rule
= NULL
;
2072 struct lttng_action
*action
= NULL
;
2073 struct lttng_trigger
*trigger
= NULL
;
2074 const char * const trigger_name
= "syscall_trigger";
2075 const char * const syscall_name
= "openat";
2077 action
= lttng_action_notify_create();
2079 fail("Failed to create notify action");
2083 notification_channel
= lttng_notification_channel_create(
2084 lttng_session_daemon_notification_endpoint
);
2085 ok(notification_channel
, "Notification channel object creation");
2087 event_rule
= lttng_event_rule_kernel_syscall_create(LTTNG_EVENT_RULE_KERNEL_SYSCALL_EMISSION_SITE_ENTRY
);
2088 ok(event_rule
, "syscall event rule object creation");
2090 event_rule_status
= lttng_event_rule_kernel_syscall_set_name_pattern(
2091 event_rule
, syscall_name
);
2092 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
2093 "Setting syscall event rule pattern: '%s'", syscall_name
);
2095 condition
= lttng_condition_event_rule_matches_create(event_rule
);
2096 ok(condition
, "Condition syscall event rule object creation");
2098 /* Register the trigger for condition. */
2099 trigger
= lttng_trigger_create(condition
, action
);
2101 fail("Failed to create trigger with syscall event rule condition and notify action");
2105 ret_code
= lttng_register_trigger_with_name(trigger
, trigger_name
);
2106 if (ret_code
!= LTTNG_OK
) {
2107 fail("Failed to register trigger with syscall event rule condition and notify action");
2111 nc_status
= lttng_notification_channel_subscribe(
2112 notification_channel
, condition
);
2113 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
2114 "Subscribe to tracepoint event rule condition");
2116 resume_application();
2118 for (i
= 0; i
< notification_count
; i
++) {
2119 struct lttng_notification
*notification
= get_next_notification(
2120 notification_channel
);
2122 ok(notification
, "Received notification (%d/%d)", i
+ 1,
2123 notification_count
);
2126 if (notification
== NULL
) {
2130 ret
= validator_notification_trigger_name(notification
, trigger_name
);
2131 lttng_notification_destroy(notification
);
2137 suspend_application();
2138 lttng_notification_channel_destroy(notification_channel
);
2139 lttng_unregister_trigger(trigger
);
2140 lttng_trigger_destroy(trigger
);
2141 lttng_action_destroy(action
);
2142 lttng_condition_destroy(condition
);
2146 static void test_syscall_event_rule_notification_filter(void)
2149 enum lttng_error_code ret_code
;
2150 const int notification_count
= 3;
2151 enum lttng_notification_channel_status nc_status
;
2152 enum lttng_event_rule_status event_rule_status
;
2153 struct lttng_notification_channel
*notification_channel
= NULL
;
2154 struct lttng_condition
*condition
= NULL
;
2155 struct lttng_event_rule
*event_rule
= NULL
;
2156 struct lttng_action
*action
= NULL
;
2157 struct lttng_trigger
*trigger
= NULL
;
2158 const char * const trigger_name
= "syscall_trigger";
2159 const char * const syscall_name
= "openat";
2160 const char * const filter_pattern
= "filename == \"/proc/cpuinfo\"";
2162 action
= lttng_action_notify_create();
2164 fail("Failed to create notify action");
2168 notification_channel
= lttng_notification_channel_create(
2169 lttng_session_daemon_notification_endpoint
);
2170 ok(notification_channel
, "Notification channel object creation");
2172 event_rule
= lttng_event_rule_kernel_syscall_create(LTTNG_EVENT_RULE_KERNEL_SYSCALL_EMISSION_SITE_ENTRY
);
2173 ok(event_rule
, "syscall event rule object creation");
2175 event_rule_status
= lttng_event_rule_kernel_syscall_set_name_pattern(
2176 event_rule
, syscall_name
);
2177 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
2178 "Setting syscall event rule pattern: '%s'", syscall_name
);
2180 event_rule_status
= lttng_event_rule_kernel_syscall_set_filter(
2181 event_rule
, filter_pattern
);
2182 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
2183 "Setting filter: '%s'", filter_pattern
);
2185 condition
= lttng_condition_event_rule_matches_create(event_rule
);
2186 ok(condition
, "Condition event rule object creation");
2188 /* Register the triggers for condition */
2189 trigger
= lttng_trigger_create(condition
, action
);
2191 fail("Failed to create trigger with syscall filtering event rule condition and notify action");
2195 ret_code
= lttng_register_trigger_with_name(trigger
, trigger_name
);
2196 if (ret_code
!= LTTNG_OK
) {
2197 fail("Failed to register trigger with syscall filtering event rule condition and notify action");
2201 nc_status
= lttng_notification_channel_subscribe(
2202 notification_channel
, condition
);
2203 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
2204 "Subscribe to tracepoint event rule condition");
2206 resume_application();
2208 for (i
= 0; i
< notification_count
; i
++) {
2209 struct lttng_notification
*notification
= get_next_notification(
2210 notification_channel
);
2212 ok(notification
, "Received notification (%d/%d)", i
+ 1,
2213 notification_count
);
2216 if (notification
== NULL
) {
2220 ret
= validator_notification_trigger_name(notification
, trigger_name
);
2221 lttng_notification_destroy(notification
);
2228 suspend_application();
2230 lttng_unregister_trigger(trigger
);
2231 lttng_notification_channel_destroy(notification_channel
);
2232 lttng_trigger_destroy(trigger
);
2233 lttng_event_rule_destroy(event_rule
);
2234 lttng_condition_destroy(condition
);
2238 static int generate_capture_descr(struct lttng_condition
*condition
)
2241 struct lttng_event_expr
*expr
= NULL
;
2242 const unsigned int basic_field_count
= sizeof(test_capture_base_fields
) /
2243 sizeof(*test_capture_base_fields
);
2244 enum lttng_condition_status cond_status
;
2246 for (i
= 0; i
< basic_field_count
; i
++) {
2247 diag("Adding capture descriptor '%s'",
2248 test_capture_base_fields
[i
].field_name
);
2250 switch (test_capture_base_fields
[i
].field_type
) {
2251 case FIELD_TYPE_PAYLOAD
:
2252 expr
= lttng_event_expr_event_payload_field_create(
2253 test_capture_base_fields
[i
].field_name
);
2255 case FIELD_TYPE_CONTEXT
:
2256 expr
= lttng_event_expr_channel_context_field_create(
2257 test_capture_base_fields
[i
].field_name
);
2259 case FIELD_TYPE_ARRAY_FIELD
:
2263 char field_name
[FIELD_NAME_MAX_LEN
];
2264 struct lttng_event_expr
*array_expr
= NULL
;
2266 nb_matches
= sscanf(test_capture_base_fields
[i
].field_name
,
2267 "%[^[][%u]", field_name
, &index
);
2268 if (nb_matches
!= 2) {
2269 fail("Unexpected array field name format: field name = '%s'",
2270 test_capture_base_fields
[i
].field_name
);
2275 array_expr
= lttng_event_expr_event_payload_field_create(
2278 expr
= lttng_event_expr_array_field_element_create(
2282 case FIELD_TYPE_APP_CONTEXT
:
2283 fail("Application context tests are not implemented yet.");
2291 fail("Failed to create capture expression");
2296 cond_status
= lttng_condition_event_rule_matches_append_capture_descriptor(
2298 if (cond_status
!= LTTNG_CONDITION_STATUS_OK
) {
2299 fail("Failed to append capture descriptor");
2301 lttng_event_expr_destroy(expr
);
2312 static int validator_notification_trigger_capture(
2313 enum lttng_domain_type domain
,
2314 struct lttng_notification
*notification
,
2315 const int iteration
)
2318 unsigned int capture_count
, i
;
2319 enum lttng_evaluation_event_rule_matches_status
2320 event_rule_matches_evaluation_status
;
2321 enum lttng_event_field_value_status event_field_value_status
;
2322 const struct lttng_evaluation
*evaluation
;
2323 const struct lttng_event_field_value
*captured_fields
;
2324 bool at_least_one_error
= false;
2326 evaluation
= lttng_notification_get_evaluation(notification
);
2327 if (evaluation
== NULL
) {
2328 fail("Failed to get evaluation from notification during trigger capture test");
2333 event_rule_matches_evaluation_status
=
2334 lttng_evaluation_event_rule_matches_get_captured_values(
2335 evaluation
, &captured_fields
);
2336 if (event_rule_matches_evaluation_status
!=
2337 LTTNG_EVALUATION_EVENT_RULE_MATCHES_STATUS_OK
) {
2338 diag("Failed to get event rule evaluation captured values: status = %d",
2339 (int) event_rule_matches_evaluation_status
);
2344 event_field_value_status
=
2345 lttng_event_field_value_array_get_length(captured_fields
,
2347 if (event_field_value_status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
2348 fail("Failed to get count of captured value field array");
2353 for (i
= 0; i
< capture_count
; i
++) {
2354 const struct lttng_event_field_value
*captured_field
= NULL
;
2355 validate_cb validate
;
2358 diag("Validating capture of field '%s'",
2359 test_capture_base_fields
[i
].field_name
);
2360 event_field_value_status
=
2361 lttng_event_field_value_array_get_element_at_index(
2366 case LTTNG_DOMAIN_UST
:
2367 expected
= test_capture_base_fields
[i
].expected_ust
;
2369 case LTTNG_DOMAIN_KERNEL
:
2370 expected
= test_capture_base_fields
[i
].expected_kernel
;
2373 fail("Unexpected domain encountered: domain = %d",
2379 if (domain
== LTTNG_DOMAIN_UST
) {
2380 validate
= test_capture_base_fields
[i
].validate_ust
;
2382 validate
= test_capture_base_fields
[i
].validate_kernel
;
2386 ok(event_field_value_status
== LTTNG_EVENT_FIELD_VALUE_STATUS_UNAVAILABLE
,
2387 "No payload captured");
2391 if (event_field_value_status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
2392 if (event_field_value_status
==
2393 LTTNG_EVENT_FIELD_VALUE_STATUS_UNAVAILABLE
) {
2394 fail("Expected a capture but it is unavailable");
2396 fail("lttng_event_field_value_array_get_element_at_index returned an error: status = %d",
2397 (int) event_field_value_status
);
2404 diag("Captured field of type %s",
2405 field_value_type_to_str(
2406 lttng_event_field_value_get_type(captured_field
)));
2408 LTTNG_ASSERT(validate
);
2409 ret
= validate(captured_field
, iteration
);
2411 at_least_one_error
= true;
2415 ret
= at_least_one_error
;
2421 static void test_tracepoint_event_rule_notification_capture(
2422 enum lttng_domain_type domain_type
)
2424 enum lttng_notification_channel_status nc_status
;
2427 struct lttng_condition
*condition
= NULL
;
2428 struct lttng_notification_channel
*notification_channel
= NULL
;
2429 struct lttng_trigger
*trigger
= NULL
;
2430 const char *trigger_name
= "my_precious";
2431 const char *pattern
;
2433 if (domain_type
== LTTNG_DOMAIN_UST
) {
2434 pattern
= "tp:tptest";
2436 pattern
= "lttng_test_filter_event";
2439 create_tracepoint_event_rule_trigger(pattern
, trigger_name
, NULL
, 0,
2440 NULL
, domain_type
, generate_capture_descr
, &condition
,
2443 notification_channel
= lttng_notification_channel_create(
2444 lttng_session_daemon_notification_endpoint
);
2445 ok(notification_channel
, "Notification channel object creation");
2447 nc_status
= lttng_notification_channel_subscribe(
2448 notification_channel
, condition
);
2449 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
2450 "Subscribe to tracepoint event rule condition");
2452 resume_application();
2454 /* Get 3 notifications */
2455 for (i
= 0; i
< 3; i
++) {
2456 struct lttng_notification
*notification
= get_next_notification(
2457 notification_channel
);
2458 ok(notification
, "Received notification");
2461 if (notification
== NULL
) {
2465 ret
= validator_notification_trigger_name(notification
, trigger_name
);
2467 lttng_notification_destroy(notification
);
2471 ret
= validator_notification_trigger_capture(domain_type
, notification
, i
);
2473 lttng_notification_destroy(notification
);
2477 lttng_notification_destroy(notification
);
2481 suspend_application();
2482 lttng_notification_channel_destroy(notification_channel
);
2483 lttng_unregister_trigger(trigger
);
2484 lttng_trigger_destroy(trigger
);
2485 lttng_condition_destroy(condition
);
2489 int main(int argc
, const char *argv
[])
2492 const char *domain_type_string
= NULL
;
2493 enum lttng_domain_type domain_type
= LTTNG_DOMAIN_NONE
;
2496 fail("Missing test scenario, domain type, pid, or application state file argument(s)");
2500 test_scenario
= atoi(argv
[1]);
2501 domain_type_string
= argv
[2];
2502 app_pid
= (pid_t
) atoi(argv
[3]);
2503 app_state_file
= argv
[4];
2505 if (!strcmp("LTTNG_DOMAIN_UST", domain_type_string
)) {
2506 domain_type
= LTTNG_DOMAIN_UST
;
2508 if (!strcmp("LTTNG_DOMAIN_KERNEL", domain_type_string
)) {
2509 domain_type
= LTTNG_DOMAIN_KERNEL
;
2511 if (domain_type
== LTTNG_DOMAIN_NONE
) {
2512 fail("Unknown domain type");
2517 * Test cases are responsible for resuming the app when needed
2518 * and making sure it's suspended when returning.
2520 suspend_application();
2522 switch (test_scenario
) {
2527 /* Test cases that need gen-ust-event testapp. */
2528 diag("Test basic notification error paths for %s domain",
2529 domain_type_string
);
2530 test_invalid_channel_subscription(domain_type
);
2532 diag("Test tracepoint event rule notifications for domain %s",
2533 domain_type_string
);
2534 test_tracepoint_event_rule_notification(domain_type
);
2536 diag("Test tracepoint event rule notifications with filter for domain %s",
2537 domain_type_string
);
2538 test_tracepoint_event_rule_notification_filter(domain_type
);
2543 const char *session_name
, *channel_name
;
2545 /* Test cases that need a tracing session enabled. */
2549 * Argument 7 and upward are named pipe location for consumerd
2552 named_pipe_args_start
= 7;
2555 fail("Missing parameter for tests to run %d", argc
);
2561 session_name
= argv
[5];
2562 channel_name
= argv
[6];
2564 test_subscription_twice(session_name
, channel_name
,
2567 diag("Test trigger for domain %s with buffer_usage_low condition",
2568 domain_type_string
);
2569 test_triggers_buffer_usage_condition(session_name
, channel_name
,
2570 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
);
2572 diag("Test trigger for domain %s with buffer_usage_high condition",
2573 domain_type_string
);
2574 test_triggers_buffer_usage_condition(session_name
, channel_name
,
2575 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
);
2577 diag("Test buffer usage notification channel api for domain %s",
2578 domain_type_string
);
2579 test_buffer_usage_notification_channel(session_name
, channel_name
,
2586 * Test cases that need a test app with more than one event
2592 * At the moment, the only test case of this scenario is
2593 * exclusion which is only supported by UST.
2595 LTTNG_ASSERT(domain_type
== LTTNG_DOMAIN_UST
);
2596 diag("Test tracepoint event rule notifications with exclusion for domain %s",
2597 domain_type_string
);
2598 test_tracepoint_event_rule_notification_exclusion(domain_type
);
2605 /* Test cases that need the kernel tracer. */
2606 LTTNG_ASSERT(domain_type
== LTTNG_DOMAIN_KERNEL
);
2608 diag("Test kprobe event rule notifications for domain %s",
2609 domain_type_string
);
2611 test_kprobe_event_rule_notification();
2618 /* Test cases that need the kernel tracer. */
2619 LTTNG_ASSERT(domain_type
== LTTNG_DOMAIN_KERNEL
);
2621 diag("Test syscall event rule notifications for domain %s",
2622 domain_type_string
);
2624 test_syscall_event_rule_notification();
2626 diag("Test syscall filtering event rule notifications for domain %s",
2627 domain_type_string
);
2629 test_syscall_event_rule_notification_filter();
2635 const char *testapp_path
, *test_symbol_name
;
2640 fail("Missing parameter for tests to run %d", argc
);
2644 testapp_path
= argv
[5];
2645 test_symbol_name
= argv
[6];
2646 /* Test cases that need the kernel tracer. */
2647 LTTNG_ASSERT(domain_type
== LTTNG_DOMAIN_KERNEL
);
2649 diag("Test userspace-probe event rule notifications for domain %s",
2650 domain_type_string
);
2652 test_uprobe_event_rule_notification(
2653 testapp_path
, test_symbol_name
);
2659 switch(domain_type
) {
2660 case LTTNG_DOMAIN_UST
:
2663 case LTTNG_DOMAIN_KERNEL
:
2670 diag("Test tracepoint event rule notification captures for domain %s",
2671 domain_type_string
);
2672 test_tracepoint_event_rule_notification_capture(domain_type
);
2682 return exit_status();