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
,
51 struct capture_base_field_tuple
{
52 const char *field_name
;
53 enum field_type field_type
;
54 /* Do we expect a userspace capture? */
56 /* Do we expect a kernel capture? */
58 validate_cb validate_ust
;
59 validate_cb validate_kernel
;
63 const char *field_value_type_to_str(enum lttng_event_field_value_type type
)
66 case LTTNG_EVENT_FIELD_VALUE_TYPE_UNKNOWN
:
68 case LTTNG_EVENT_FIELD_VALUE_TYPE_INVALID
:
70 case LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT
:
71 return "UNSIGNED INT";
72 case LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_INT
:
74 case LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM
:
75 return "UNSIGNED ENUM";
76 case LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM
:
78 case LTTNG_EVENT_FIELD_VALUE_TYPE_REAL
:
80 case LTTNG_EVENT_FIELD_VALUE_TYPE_STRING
:
82 case LTTNG_EVENT_FIELD_VALUE_TYPE_ARRAY
:
89 static int validate_type(const struct lttng_event_field_value
*event_field
,
90 enum lttng_event_field_value_type expect
)
93 enum lttng_event_field_value_type value
;
95 value
= lttng_event_field_value_get_type(event_field
);
96 if (value
== LTTNG_EVENT_FIELD_VALUE_TYPE_INVALID
) {
101 ok(expect
== value
, "Expected field type %s, got %s",
102 field_value_type_to_str(expect
),
103 field_value_type_to_str(value
));
105 ret
= expect
!= value
;
112 * Validate unsigned captured field against the iteration number.
114 static int validate_unsigned_int_field(
115 const struct lttng_event_field_value
*event_field
,
116 unsigned int expected_value
)
120 enum lttng_event_field_value_status status
;
123 event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT
);
128 status
= lttng_event_field_value_unsigned_int_get_value(
129 event_field
, &value
);
130 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
131 fail("lttng_event_field_value_unsigned_int_get_value returned an error: status = %d",
137 ok(value
== (uint64_t) expected_value
,
138 "Expected unsigned integer value %u, got %" PRIu64
,
139 expected_value
, value
);
141 ret
= value
!= (uint64_t) expected_value
;
148 * Validate signed captured field.
150 static int validate_signed_int_field(
151 const struct lttng_event_field_value
*event_field
,
152 unsigned int iteration
)
155 const int64_t expected
= -1;
157 enum lttng_event_field_value_status status
;
163 event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_INT
);
168 status
= lttng_event_field_value_signed_int_get_value(
169 event_field
, &value
);
170 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
171 fail("lttng_event_field_value_signed_int_get_value returned an error: status = %d",
177 ok(value
== expected
,
178 "Expected signed integer value %" PRId64
182 ret
= value
!= expected
;
190 * Validate array of unsigned int.
192 static int validate_array_unsigned_int_field(
193 const struct lttng_event_field_value
*event_field
,
194 unsigned int iteration
)
197 enum lttng_event_field_value_status status
;
198 const unsigned int expected
= 3;
199 unsigned int i
, count
;
204 ret
= validate_type(event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_ARRAY
);
209 status
= lttng_event_field_value_array_get_length(event_field
, &count
);
210 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
211 fail("lttng_event_field_value_array_get_length");
216 ok(count
== expected
, "Expected %d subelements, got %d", expected
,
218 if (count
!= expected
) {
223 for (i
= 1; i
< count
+ 1; i
++) {
224 const struct lttng_event_field_value
*value
;
226 status
= lttng_event_field_value_array_get_element_at_index(
227 event_field
, i
- 1, &value
);
228 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
229 fail("lttng_event_field_value_array_get_element_at_index returned an error: status = %d",
235 ret
= validate_unsigned_int_field(value
, i
);
247 static int validate_array_unsigned_int_field_at_index(
248 const struct lttng_event_field_value
*event_field
,
249 unsigned int iteration
)
252 const uint64_t expected_value
= 2;
253 enum lttng_event_field_value_status status
;
260 event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT
);
265 status
= lttng_event_field_value_unsigned_int_get_value(
266 event_field
, &value
);
267 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
268 fail("lttng_event_field_value_unsigned_int_get_value returned an error: status = %d",
274 ok(value
== expected_value
,
275 "Expected unsigned integer value %" PRIu64
", got %" PRIu64
,
276 expected_value
, value
);
284 * Validate sequence for a string (seqfield1):
286 * Value: "test" encoded in UTF-8: [116, 101, 115, 116]
288 static int validate_seqfield1(const struct lttng_event_field_value
*event_field
,
289 unsigned int iteration
)
292 enum lttng_event_field_value_status status
;
293 unsigned int i
, count
;
294 const unsigned int expect
[] = {116, 101, 115, 116};
295 const size_t array_count
= sizeof(expect
) / sizeof(*expect
);
300 ret
= validate_type(event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_ARRAY
);
305 status
= lttng_event_field_value_array_get_length(event_field
, &count
);
306 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
307 fail("lttng_event_field_value_array_get_length returned an error: status = %d",
313 ok(count
== array_count
, "Expected %zu array sub-elements, got %d",
315 if (count
!= array_count
) {
320 for (i
= 0; i
< count
; i
++) {
321 const struct lttng_event_field_value
*value
;
323 status
= lttng_event_field_value_array_get_element_at_index(
324 event_field
, i
, &value
);
325 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
326 fail("lttng_event_field_value_array_get_element_at_index returned an error: status = %d",
332 ret
= validate_unsigned_int_field(value
, expect
[i
]);
343 static int validate_string(
344 const struct lttng_event_field_value
*event_field
,
348 const char *value
= NULL
;
349 enum lttng_event_field_value_status status
;
351 ret
= validate_type(event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_STRING
);
356 status
= lttng_event_field_value_string_get_value(event_field
, &value
);
358 fail("lttng_event_field_value_array_get_length returned an error: status = %d",
364 ok(!strcmp(value
, expect
), "Expected string value \"%s\", got \"%s\"",
374 * Validate string. Expected value is "test".
376 static int validate_string_test(
377 const struct lttng_event_field_value
*event_field
,
378 unsigned int iteration
)
380 const char * const expect
= "test";
385 return validate_string(event_field
, expect
);
389 * Validate escaped string. Expected value is "\*".
391 static int validate_string_escaped(
392 const struct lttng_event_field_value
*event_field
,
393 unsigned int iteration
)
395 const char * const expect
= "\\*";
400 return validate_string(event_field
, expect
);
404 * Validate real field.
406 static int validate_real(
407 const struct lttng_event_field_value
*event_field
,
412 enum lttng_event_field_value_status status
;
414 ret
= validate_type(event_field
, LTTNG_EVENT_FIELD_VALUE_TYPE_REAL
);
419 status
= lttng_event_field_value_real_get_value(event_field
, &value
);
420 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
421 fail("lttng_event_field_value_real_get_value returned an error: status = %d",
427 ok(value
== expect
, "Expected real value %f, got %f", expect
, value
);
428 ret
= value
!= expect
;
434 * Validate floatfield.
436 static int validate_floatfield(
437 const struct lttng_event_field_value
*event_field
,
438 unsigned int iteration
)
440 const double expect
= 2222.0;
445 return validate_real(event_field
, expect
);
449 * Validate doublefield.
451 static int validate_doublefield(
452 const struct lttng_event_field_value
*event_field
,
453 unsigned int iteration
)
455 const double expect
= 2.0;
460 return validate_real(event_field
, expect
);
464 * Validate enum0: enum0 = ( "AUTO: EXPECT 0" : container = 0 )
466 static int validate_enum0(const struct lttng_event_field_value
*event_field
,
467 unsigned int iteration
)
470 enum lttng_event_field_value_status status
;
472 const uint64_t expected_value
= 0;
477 ret
= validate_type(event_field
,
478 LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM
);
483 status
= lttng_event_field_value_unsigned_int_get_value(
484 event_field
, &value
);
485 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
486 fail("lttng_event_field_value_unsigned_int_get_value returned an error: status = %d",
492 ok(value
== expected_value
,
493 "Expected enum value %" PRIu64
", got %" PRIu64
,
494 expected_value
, value
);
501 * Validate enumnegative: enumnegative = ( "AUTO: EXPECT 0" : container = 0 )
503 * We expect 2 labels here.
505 static int validate_enumnegative(
506 const struct lttng_event_field_value
*event_field
,
507 unsigned int iteration
)
510 enum lttng_event_field_value_status status
;
512 const int64_t expected_value
= -1;
517 ret
= validate_type(event_field
,
518 LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM
);
523 status
= lttng_event_field_value_signed_int_get_value(
524 event_field
, &value
);
525 if (status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
526 fail("lttng_event_field_value_unsigned_int_get_value");
531 ok(value
== expected_value
,
532 "Expected enum value %" PRId64
", got %" PRId64
,
533 expected_value
, value
);
539 static int validate_context_procname_ust(
540 const struct lttng_event_field_value
*event_field
,
541 unsigned int iteration
)
545 return validate_string(event_field
, "gen-ust-events");
548 static int validate_context_procname_kernel(
549 const struct lttng_event_field_value
*event_field
,
550 unsigned int iteration
)
554 return validate_string(event_field
, "echo");
557 struct capture_base_field_tuple test_capture_base_fields
[] = {
558 { "DOESNOTEXIST", FIELD_TYPE_PAYLOAD
, false, false, NULL
, NULL
},
559 { "intfield", FIELD_TYPE_PAYLOAD
, true, true, validate_unsigned_int_field
, validate_unsigned_int_field
},
560 { "longfield", FIELD_TYPE_PAYLOAD
, true, true, validate_unsigned_int_field
, validate_unsigned_int_field
},
561 { "signedfield", FIELD_TYPE_PAYLOAD
, true, true, validate_signed_int_field
, validate_signed_int_field
},
562 { "arrfield1", FIELD_TYPE_PAYLOAD
, true, true, validate_array_unsigned_int_field
, validate_array_unsigned_int_field
},
563 { "arrfield2", FIELD_TYPE_PAYLOAD
, true, true, validate_string_test
, validate_string_test
},
564 { "arrfield3", FIELD_TYPE_PAYLOAD
, true, true, validate_array_unsigned_int_field
, validate_array_unsigned_int_field
},
565 { "seqfield1", FIELD_TYPE_PAYLOAD
, true, true, validate_seqfield1
, validate_seqfield1
},
566 { "seqfield2", FIELD_TYPE_PAYLOAD
, true, true, validate_string_test
, validate_string_test
},
567 { "seqfield3", FIELD_TYPE_PAYLOAD
, true, true, validate_array_unsigned_int_field
, validate_array_unsigned_int_field
},
568 { "seqfield4", FIELD_TYPE_PAYLOAD
, true, true, validate_array_unsigned_int_field
, validate_array_unsigned_int_field
},
569 { "arrfield1[1]", FIELD_TYPE_ARRAY_FIELD
, true, true, validate_array_unsigned_int_field_at_index
, validate_array_unsigned_int_field_at_index
},
570 { "stringfield", FIELD_TYPE_PAYLOAD
, true, true, validate_string_test
, validate_string_test
},
571 { "stringfield2", FIELD_TYPE_PAYLOAD
, true, true, validate_string_escaped
, validate_string_escaped
},
572 { "floatfield", FIELD_TYPE_PAYLOAD
, true, false, validate_floatfield
, validate_floatfield
},
573 { "doublefield", FIELD_TYPE_PAYLOAD
, true, false, validate_doublefield
, validate_doublefield
},
574 { "enum0", FIELD_TYPE_PAYLOAD
, true, true, validate_enum0
, validate_enum0
},
575 { "enumnegative", FIELD_TYPE_PAYLOAD
, true, true, validate_enumnegative
, validate_enumnegative
},
576 { "$ctx.procname", FIELD_TYPE_CONTEXT
, true, true, validate_context_procname_ust
, validate_context_procname_kernel
},
579 static const char *get_notification_trigger_name(
580 struct lttng_notification
*notification
)
582 const char *trigger_name
= NULL
;
583 enum lttng_trigger_status trigger_status
;
584 const struct lttng_trigger
*trigger
;
586 trigger
= lttng_notification_get_trigger(notification
);
588 fail("Failed to get trigger from notification");
592 trigger_status
= lttng_trigger_get_name(trigger
, &trigger_name
);
593 switch (trigger_status
) {
594 case LTTNG_TRIGGER_STATUS_OK
:
596 case LTTNG_TRIGGER_STATUS_UNSET
:
597 trigger_name
= "(anonymous)";
600 fail("Failed to get name from notification's trigger");
608 static int validator_notification_trigger_name(
609 struct lttng_notification
*notification
,
610 const char *trigger_name
)
616 LTTNG_ASSERT(notification
);
617 LTTNG_ASSERT(trigger_name
);
619 name
= get_notification_trigger_name(notification
);
625 name_is_equal
= (strcmp(trigger_name
, name
) == 0);
626 ok(name_is_equal
, "Expected trigger name: %s got %s", trigger_name
,
629 ret
= !name_is_equal
;
636 void wait_on_file(const char *path
, bool file_exist
)
645 ret
= stat(path
, &buf
);
646 if (ret
== -1 && errno
== ENOENT
) {
649 * The file does not exist. wait a bit and
650 * continue looping until it does.
652 (void) poll(NULL
, 0, 10);
657 * File does not exist and the exit condition we want.
658 * Break from the loop and return.
667 * stat() returned 0, so the file exists. break now only if
668 * that's the exit condition we want.
677 int write_pipe(const char *path
, uint8_t data
)
682 fd
= open(path
, O_WRONLY
| O_NONBLOCK
);
684 perror("Could not open consumer control named pipe");
688 ret
= write(fd
, &data
, sizeof(data
));
690 perror("Named pipe write failed");
692 perror("Named pipe close failed");
700 perror("Name pipe closing failed");
709 int stop_consumer(const char **argv
)
713 for (i
= named_pipe_args_start
; i
< nb_args
; i
++) {
714 ret
= write_pipe(argv
[i
], 49);
720 int resume_consumer(const char **argv
)
724 for (i
= named_pipe_args_start
; i
< nb_args
; i
++) {
725 ret
= write_pipe(argv
[i
], 0);
731 int suspend_application(void)
736 if (!stat(app_state_file
, &buf
)) {
737 fail("App is already in a suspended state.");
743 * Send SIGUSR1 to application instructing it to bypass tracepoint.
745 LTTNG_ASSERT(app_pid
> 1);
747 ret
= kill(app_pid
, SIGUSR1
);
749 fail("SIGUSR1 failed. errno %d", errno
);
754 wait_on_file(app_state_file
, true);
762 int resume_application(void)
767 ret
= stat(app_state_file
, &buf
);
768 if (ret
== -1 && errno
== ENOENT
) {
769 fail("State file does not exist");
777 LTTNG_ASSERT(app_pid
> 1);
779 ret
= kill(app_pid
, SIGUSR1
);
781 fail("SIGUSR1 failed. errno %d", errno
);
786 wait_on_file(app_state_file
, false);
795 void test_triggers_buffer_usage_condition(const char *session_name
,
796 const char *channel_name
,
797 enum lttng_condition_type condition_type
)
799 unsigned int test_vector_size
= 5, i
;
800 enum lttng_condition_status condition_status
;
801 struct lttng_action
*action
;
804 action
= lttng_action_notify_create();
806 fail("Setup error on action creation");
810 /* Test lttng_register_trigger with null value */
811 ok(lttng_register_trigger(NULL
) == -LTTNG_ERR_INVALID
, "Registering a NULL trigger fails as expected");
813 /* Test: register a trigger */
815 for (i
= 0; i
< pow(2,test_vector_size
); i
++) {
817 char *test_tuple_string
= NULL
;
818 unsigned int mask_position
= 0;
819 bool session_name_set
= false;
820 bool channel_name_set
= false;
821 bool threshold_ratio_set
= false;
822 bool threshold_byte_set
= false;
823 bool domain_type_set
= false;
825 struct lttng_trigger
*trigger
= NULL
;
826 struct lttng_condition
*condition
= NULL
;
828 /* Create base condition */
829 switch (condition_type
) {
830 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
831 condition
= lttng_condition_buffer_usage_low_create();
833 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
834 condition
= lttng_condition_buffer_usage_high_create();
847 /* Prepare the condition for trigger registration test */
849 /* Set session name */
850 if ((1 << mask_position
) & i
) {
851 condition_status
= lttng_condition_buffer_usage_set_session_name(
852 condition
, session_name
);
853 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
857 session_name_set
= true;
861 /* Set channel name */
862 if ((1 << mask_position
) & i
) {
863 condition_status
= lttng_condition_buffer_usage_set_channel_name(
864 condition
, channel_name
);
865 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
869 channel_name_set
= true;
873 /* Set threshold ratio */
874 if ((1 << mask_position
) & i
) {
875 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
877 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
881 threshold_ratio_set
= true;
885 /* Set threshold byte */
886 if ((1 << mask_position
) & i
) {
887 condition_status
= lttng_condition_buffer_usage_set_threshold(
889 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
893 threshold_byte_set
= true;
897 /* Set domain type */
898 if ((1 << mask_position
) & i
) {
899 condition_status
= lttng_condition_buffer_usage_set_domain_type(
900 condition
, LTTNG_DOMAIN_UST
);
901 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
905 domain_type_set
= true;
909 if (mask_position
!= test_vector_size
-1) {
910 LTTNG_ASSERT("Logic error for test vector generation");
913 loop_ret
= asprintf(&test_tuple_string
, "session name %s, channel name %s, threshold ratio %s, threshold byte %s, domain type %s",
914 session_name_set
? "set" : "unset",
915 channel_name_set
? "set" : "unset",
916 threshold_ratio_set
? "set" : "unset",
917 threshold_byte_set
? "set" : "unset",
918 domain_type_set
? "set" : "unset");
919 if (!test_tuple_string
|| loop_ret
< 0) {
925 trigger
= lttng_trigger_create(condition
, action
);
931 loop_ret
= lttng_register_trigger(trigger
);
935 fail("Setup error occurred for tuple: %s", test_tuple_string
);
939 /* This combination happens three times */
940 if (session_name_set
&& channel_name_set
941 && (threshold_ratio_set
|| threshold_byte_set
)
942 && domain_type_set
) {
943 ok(loop_ret
== 0, "Trigger is registered: %s", test_tuple_string
);
946 * Test that a trigger cannot be registered
949 loop_ret
= lttng_register_trigger(trigger
);
950 ok(loop_ret
== -LTTNG_ERR_TRIGGER_EXISTS
, "Re-register trigger fails as expected: %s", test_tuple_string
);
952 /* Test that a trigger can be unregistered */
953 loop_ret
= lttng_unregister_trigger(trigger
);
954 ok(loop_ret
== 0, "Unregister trigger: %s", test_tuple_string
);
957 * Test that unregistration of a non-previously
958 * registered trigger fail.
960 loop_ret
= lttng_unregister_trigger(trigger
);
961 ok(loop_ret
== -LTTNG_ERR_TRIGGER_NOT_FOUND
, "Unregister of a non-registered trigger fails as expected: %s", test_tuple_string
);
963 ok(loop_ret
== -LTTNG_ERR_INVALID_TRIGGER
, "Trigger is invalid as expected and cannot be registered: %s", test_tuple_string
);
967 free(test_tuple_string
);
968 lttng_trigger_destroy(trigger
);
969 lttng_condition_destroy(condition
);
973 lttng_action_destroy(action
);
977 void wait_data_pending(const char *session_name
)
982 ret
= lttng_data_pending(session_name
);
983 LTTNG_ASSERT(ret
>= 0);
988 int setup_buffer_usage_condition(struct lttng_condition
*condition
,
989 const char *condition_name
,
990 const char *session_name
,
991 const char *channel_name
,
992 const enum lttng_domain_type domain_type
)
994 enum lttng_condition_status condition_status
;
997 condition_status
= lttng_condition_buffer_usage_set_session_name(
998 condition
, session_name
);
999 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1000 fail("Failed to set session name on creation of condition `%s`",
1006 condition_status
= lttng_condition_buffer_usage_set_channel_name(
1007 condition
, channel_name
);
1008 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1009 fail("Failed to set channel name on creation of condition `%s`",
1015 condition_status
= lttng_condition_buffer_usage_set_domain_type(
1016 condition
, domain_type
);
1017 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1018 fail("Failed to set domain type on creation of condition `%s`",
1029 void test_invalid_channel_subscription(
1030 const enum lttng_domain_type domain_type
)
1032 enum lttng_condition_status condition_status
;
1033 enum lttng_notification_channel_status nc_status
;
1034 struct lttng_condition
*dummy_condition
= NULL
;
1035 struct lttng_condition
*dummy_invalid_condition
= NULL
;
1036 struct lttng_notification_channel
*notification_channel
= NULL
;
1039 notification_channel
= lttng_notification_channel_create(
1040 lttng_session_daemon_notification_endpoint
);
1041 ok(notification_channel
, "Notification channel object creation");
1042 if (!notification_channel
) {
1047 * Create a dummy, empty (thus invalid) condition to test error paths.
1049 dummy_invalid_condition
= lttng_condition_buffer_usage_low_create();
1050 if (!dummy_invalid_condition
) {
1051 fail("Setup error on condition creation");
1056 * Test subscription and unsubscription of an invalid condition to/from
1059 nc_status
= lttng_notification_channel_subscribe(
1060 notification_channel
, dummy_invalid_condition
);
1061 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
1062 "Subscribing to an invalid condition");
1064 nc_status
= lttng_notification_channel_unsubscribe(
1065 notification_channel
, dummy_invalid_condition
);
1066 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
1067 "Unsubscribing from an invalid condition");
1069 /* Create a valid dummy condition with a ratio of 0.5 */
1070 dummy_condition
= lttng_condition_buffer_usage_low_create();
1071 if (!dummy_condition
) {
1072 fail("Setup error on dummy_condition creation");
1076 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
1077 dummy_condition
, 0.5);
1078 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1079 fail("Setup error on condition creation");
1083 ret
= setup_buffer_usage_condition(dummy_condition
, "dummy_condition",
1084 "dummy_session", "dummy_channel", domain_type
);
1086 fail("Setup error on dummy condition creation");
1091 * Test subscription and unsubscription to/from a channel with invalid
1094 nc_status
= lttng_notification_channel_subscribe(NULL
, NULL
);
1095 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
1096 "Notification channel subscription is invalid: NULL, NULL");
1098 nc_status
= lttng_notification_channel_subscribe(
1099 notification_channel
, NULL
);
1100 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
1101 "Notification channel subscription is invalid: NON-NULL, NULL");
1103 nc_status
= lttng_notification_channel_subscribe(NULL
, dummy_condition
);
1104 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID
,
1105 "Notification channel subscription is invalid: NULL, NON-NULL");
1107 nc_status
= lttng_notification_channel_unsubscribe(
1108 notification_channel
, dummy_condition
);
1109 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION
,
1110 "Unsubscribing from a valid unknown condition");
1113 lttng_notification_channel_destroy(notification_channel
);
1114 lttng_condition_destroy(dummy_invalid_condition
);
1115 lttng_condition_destroy(dummy_condition
);
1119 enum buffer_usage_type
{
1120 BUFFER_USAGE_TYPE_LOW
,
1121 BUFFER_USAGE_TYPE_HIGH
,
1124 static int register_buffer_usage_notify_trigger(const char *session_name
,
1125 const char *channel_name
,
1126 const enum lttng_domain_type domain_type
,
1127 enum buffer_usage_type buffer_usage_type
,
1129 struct lttng_condition
**condition
,
1130 struct lttng_action
**action
,
1131 struct lttng_trigger
**trigger
)
1133 enum lttng_condition_status condition_status
;
1134 struct lttng_action
*tmp_action
= NULL
;
1135 struct lttng_condition
*tmp_condition
= NULL
;
1136 struct lttng_trigger
*tmp_trigger
= NULL
;
1140 tmp_action
= lttng_action_notify_create();
1142 fail("Setup error on action creation");
1147 if (buffer_usage_type
== BUFFER_USAGE_TYPE_LOW
) {
1148 tmp_condition
= lttng_condition_buffer_usage_low_create();
1150 tmp_condition
= lttng_condition_buffer_usage_high_create();
1153 if (!tmp_condition
) {
1154 fail("Setup error on condition creation");
1159 /* Set the buffer usage threashold */
1160 condition_status
= lttng_condition_buffer_usage_set_threshold_ratio(
1161 tmp_condition
, ratio
);
1162 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
1163 fail("Setup error on condition creation");
1168 ret
= setup_buffer_usage_condition(tmp_condition
, "condition_name",
1169 session_name
, channel_name
, domain_type
);
1171 fail("Setup error on condition creation");
1176 /* Register the trigger for condition. */
1177 tmp_trigger
= lttng_trigger_create(tmp_condition
, tmp_action
);
1179 fail("Setup error on trigger creation");
1184 ret
= lttng_register_trigger(tmp_trigger
);
1186 fail("Setup error on trigger registration");
1191 *condition
= tmp_condition
;
1192 *trigger
= tmp_trigger
;
1193 *action
= tmp_action
;
1197 lttng_action_destroy(tmp_action
);
1198 lttng_condition_destroy(tmp_condition
);
1199 lttng_trigger_destroy(tmp_trigger
);
1205 static void test_subscription_twice(const char *session_name
,
1206 const char *channel_name
,
1207 const enum lttng_domain_type domain_type
)
1210 enum lttng_notification_channel_status nc_status
;
1212 struct lttng_action
*action
= NULL
;
1213 struct lttng_notification_channel
*notification_channel
= NULL
;
1214 struct lttng_trigger
*trigger
= NULL
;
1216 struct lttng_condition
*condition
= NULL
;
1218 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
1219 domain_type
, BUFFER_USAGE_TYPE_LOW
, 0.99, &condition
,
1222 fail("Setup error on trigger registration in %s()",
1227 /* Begin testing. */
1228 notification_channel
= lttng_notification_channel_create(
1229 lttng_session_daemon_notification_endpoint
);
1230 ok(notification_channel
, "Notification channel object creation");
1231 if (!notification_channel
) {
1235 /* Subscribe a valid condition. */
1236 nc_status
= lttng_notification_channel_subscribe(
1237 notification_channel
, condition
);
1238 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1239 "Subscribe to condition");
1241 /* Subscribing again should fail. */
1242 nc_status
= lttng_notification_channel_subscribe(
1243 notification_channel
, condition
);
1244 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED
,
1245 "Subscribe to a condition for which subscription was already done");
1248 ret
= lttng_unregister_trigger(trigger
);
1250 fail("Failed to unregister trigger in %s()", __FUNCTION__
);
1253 lttng_trigger_destroy(trigger
);
1254 lttng_notification_channel_destroy(notification_channel
);
1255 lttng_action_destroy(action
);
1256 lttng_condition_destroy(condition
);
1259 static void test_buffer_usage_notification_channel(const char *session_name
,
1260 const char *channel_name
,
1261 const enum lttng_domain_type domain_type
,
1265 enum lttng_notification_channel_status nc_status
;
1267 struct lttng_action
*low_action
= NULL
;
1268 struct lttng_action
*high_action
= NULL
;
1269 struct lttng_notification
*notification
= NULL
;
1270 struct lttng_notification_channel
*notification_channel
= NULL
;
1271 struct lttng_trigger
*low_trigger
= NULL
;
1272 struct lttng_trigger
*high_trigger
= NULL
;
1274 struct lttng_condition
*low_condition
= NULL
;
1275 struct lttng_condition
*high_condition
= NULL
;
1277 const double low_ratio
= 0.0;
1278 const double high_ratio
= 0.90;
1280 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
1281 domain_type
, BUFFER_USAGE_TYPE_LOW
, low_ratio
,
1282 &low_condition
, &low_action
, &low_trigger
);
1284 fail("Setup error on low trigger registration");
1288 ret
= register_buffer_usage_notify_trigger(session_name
, channel_name
,
1289 domain_type
, BUFFER_USAGE_TYPE_HIGH
, high_ratio
,
1290 &high_condition
, &high_action
, &high_trigger
);
1292 fail("Setup error on high trigger registration");
1297 notification_channel
= lttng_notification_channel_create(
1298 lttng_session_daemon_notification_endpoint
);
1299 ok(notification_channel
, "Notification channel object creation");
1300 if (!notification_channel
) {
1304 /* Subscribe a valid low condition */
1305 nc_status
= lttng_notification_channel_subscribe(
1306 notification_channel
, low_condition
);
1307 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1308 "Subscribe to low condition");
1310 /* Subscribe a valid high condition */
1311 nc_status
= lttng_notification_channel_subscribe(
1312 notification_channel
, high_condition
);
1313 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1314 "Subscribe to high condition");
1316 resume_application();
1318 /* Wait for notification to happen */
1319 stop_consumer(argv
);
1320 lttng_start_tracing(session_name
);
1322 /* Wait for high notification */
1324 nc_status
= lttng_notification_channel_get_next_notification(
1325 notification_channel
, ¬ification
);
1326 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
1327 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
1328 lttng_condition_get_type(lttng_notification_get_condition(
1330 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
1331 "High notification received after intermediary communication");
1332 lttng_notification_destroy(notification
);
1333 notification
= NULL
;
1335 suspend_application();
1336 lttng_stop_tracing_no_wait(session_name
);
1337 resume_consumer(argv
);
1338 wait_data_pending(session_name
);
1341 * Test that communication still work even if there is notification
1342 * waiting for consumption.
1345 nc_status
= lttng_notification_channel_unsubscribe(
1346 notification_channel
, low_condition
);
1347 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1348 "Unsubscribe with pending notification");
1350 nc_status
= lttng_notification_channel_subscribe(
1351 notification_channel
, low_condition
);
1352 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1353 "Subscribe with pending notification");
1356 nc_status
= lttng_notification_channel_get_next_notification(
1357 notification_channel
, ¬ification
);
1358 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
1359 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
1360 lttng_condition_get_type(lttng_notification_get_condition(
1362 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
,
1363 "Low notification received after intermediary communication");
1364 lttng_notification_destroy(notification
);
1365 notification
= NULL
;
1367 /* Stop consumer to force a high notification */
1368 stop_consumer(argv
);
1369 resume_application();
1370 lttng_start_tracing(session_name
);
1373 nc_status
= lttng_notification_channel_get_next_notification(
1374 notification_channel
, ¬ification
);
1375 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
1376 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
1377 lttng_condition_get_type(lttng_notification_get_condition(
1379 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
1380 "High notification received after intermediary communication");
1381 lttng_notification_destroy(notification
);
1382 notification
= NULL
;
1384 suspend_application();
1385 lttng_stop_tracing_no_wait(session_name
);
1386 resume_consumer(argv
);
1387 wait_data_pending(session_name
);
1390 nc_status
= lttng_notification_channel_get_next_notification(
1391 notification_channel
, ¬ification
);
1392 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
1393 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
1394 lttng_condition_get_type(lttng_notification_get_condition(
1396 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
,
1397 "Low notification received after re-subscription");
1398 lttng_notification_destroy(notification
);
1399 notification
= NULL
;
1401 stop_consumer(argv
);
1402 resume_application();
1403 /* Stop consumer to force a high notification */
1404 lttng_start_tracing(session_name
);
1407 nc_status
= lttng_notification_channel_get_next_notification(
1408 notification_channel
, ¬ification
);
1409 } while (nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED
);
1410 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
&& notification
&&
1411 lttng_condition_get_type(lttng_notification_get_condition(
1413 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
,
1414 "High notification");
1415 lttng_notification_destroy(notification
);
1416 notification
= NULL
;
1418 suspend_application();
1420 /* Resume consumer to allow event consumption */
1421 lttng_stop_tracing_no_wait(session_name
);
1422 resume_consumer(argv
);
1423 wait_data_pending(session_name
);
1425 nc_status
= lttng_notification_channel_unsubscribe(
1426 notification_channel
, low_condition
);
1427 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1428 "Unsubscribe low condition with pending notification");
1430 nc_status
= lttng_notification_channel_unsubscribe(
1431 notification_channel
, high_condition
);
1432 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1433 "Unsubscribe high condition with pending notification");
1436 lttng_notification_channel_destroy(notification_channel
);
1437 lttng_trigger_destroy(low_trigger
);
1438 lttng_trigger_destroy(high_trigger
);
1439 lttng_action_destroy(low_action
);
1440 lttng_action_destroy(high_action
);
1441 lttng_condition_destroy(low_condition
);
1442 lttng_condition_destroy(high_condition
);
1445 static void create_tracepoint_event_rule_trigger(const char *event_pattern
,
1446 const char *trigger_name
,
1448 unsigned int exclusion_count
,
1449 const char * const *exclusions
,
1450 enum lttng_domain_type domain_type
,
1451 condition_capture_desc_cb capture_desc_cb
,
1452 struct lttng_condition
**condition
,
1453 struct lttng_trigger
**trigger
)
1455 typedef struct lttng_event_rule
*(*event_rule_create
)(void);
1456 typedef enum lttng_event_rule_status (
1457 *event_rule_set_name_pattern
)(
1458 struct lttng_event_rule
*rule
,
1459 const char *pattern
);
1460 typedef enum lttng_event_rule_status (*event_rule_set_filter
)(
1461 struct lttng_event_rule
*rule
,
1462 const char *expression
);
1463 typedef enum lttng_event_rule_status (
1464 *event_rule_add_name_pattern_exclusion
)(
1465 struct lttng_event_rule
* rule
, const char *exclusion
);
1467 enum lttng_event_rule_status event_rule_status
;
1468 struct lttng_action
*tmp_action
= NULL
;
1469 struct lttng_event_rule
*event_rule
= NULL
;
1470 struct lttng_condition
*tmp_condition
= NULL
;
1471 struct lttng_trigger
*tmp_trigger
= NULL
;
1473 enum lttng_error_code ret_code
;
1474 event_rule_create create
;
1475 event_rule_set_name_pattern set_name_pattern
;
1476 event_rule_set_filter set_filter
;
1477 event_rule_add_name_pattern_exclusion add_name_pattern_exclusion
;
1479 LTTNG_ASSERT(event_pattern
);
1480 LTTNG_ASSERT(trigger_name
);
1481 LTTNG_ASSERT(condition
);
1482 LTTNG_ASSERT(trigger
);
1484 /* Set the function pointers based on the domain type. */
1485 switch (domain_type
) {
1486 case LTTNG_DOMAIN_UST
:
1487 create
= lttng_event_rule_user_tracepoint_create
;
1488 set_name_pattern
= lttng_event_rule_user_tracepoint_set_name_pattern
;
1489 set_filter
= lttng_event_rule_user_tracepoint_set_filter
;
1490 add_name_pattern_exclusion
= lttng_event_rule_user_tracepoint_add_name_pattern_exclusion
;
1492 case LTTNG_DOMAIN_KERNEL
:
1493 create
= lttng_event_rule_kernel_tracepoint_create
;
1494 set_name_pattern
= lttng_event_rule_kernel_tracepoint_set_name_pattern
;
1495 set_filter
= lttng_event_rule_kernel_tracepoint_set_filter
;
1496 add_name_pattern_exclusion
= NULL
;
1503 event_rule
= create();
1504 ok(event_rule
, "Tracepoint event rule object creation");
1506 event_rule_status
= set_name_pattern(event_rule
, event_pattern
);
1507 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1508 "Setting tracepoint event rule pattern: '%s'",
1512 event_rule_status
= set_filter(event_rule
, filter
);
1513 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1514 "Setting tracepoint event rule filter: '%s'",
1520 bool success
= true;
1522 LTTNG_ASSERT(domain_type
== LTTNG_DOMAIN_UST
);
1523 LTTNG_ASSERT(add_name_pattern_exclusion
!= NULL
);
1524 LTTNG_ASSERT(exclusion_count
> 0);
1526 for (i
= 0; i
< exclusion_count
; i
++) {
1527 event_rule_status
= add_name_pattern_exclusion(
1528 event_rule
, exclusions
[i
]);
1529 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
1530 fail("Setting tracepoint event rule exclusion '%s'.",
1536 ok(success
, "Setting tracepoint event rule exclusions");
1539 tmp_condition
= lttng_condition_event_rule_matches_create(event_rule
);
1540 ok(tmp_condition
, "Condition event rule object creation");
1542 if (capture_desc_cb
) {
1543 ret
= capture_desc_cb(tmp_condition
);
1545 fail("Failed to generate the condition capture descriptor");
1550 tmp_action
= lttng_action_notify_create();
1551 ok(tmp_action
, "Action event rule object creation");
1553 tmp_trigger
= lttng_trigger_create(tmp_condition
, tmp_action
);
1554 ok(tmp_trigger
, "Trigger object creation %s", trigger_name
);
1556 ret_code
= lttng_register_trigger_with_name(tmp_trigger
, trigger_name
);
1557 ok(ret_code
== LTTNG_OK
, "Trigger registration %s", trigger_name
);
1559 lttng_event_rule_destroy(event_rule
);
1561 *condition
= tmp_condition
;
1562 *trigger
= tmp_trigger
;
1567 static struct lttng_notification
*get_next_notification(
1568 struct lttng_notification_channel
*notification_channel
)
1570 struct lttng_notification
*local_notification
= NULL
;
1571 enum lttng_notification_channel_status status
;
1573 /* Receive the next notification. */
1574 status
= lttng_notification_channel_get_next_notification(
1575 notification_channel
, &local_notification
);
1578 case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
:
1580 case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED
:
1581 fail("Notifications have been dropped");
1582 local_notification
= NULL
;
1585 /* Unhandled conditions / errors. */
1586 fail("Failed to get next notification (unknown notification channel status): status = %d",
1588 local_notification
= NULL
;
1592 return local_notification
;
1595 static void test_tracepoint_event_rule_notification(
1596 enum lttng_domain_type domain_type
)
1600 const int notification_count
= 3;
1601 enum lttng_notification_channel_status nc_status
;
1602 struct lttng_action
*action
= NULL
;
1603 struct lttng_condition
*condition
= NULL
;
1604 struct lttng_notification_channel
*notification_channel
= NULL
;
1605 struct lttng_trigger
*trigger
= NULL
;
1606 const char * const trigger_name
= "my_precious";
1607 const char *pattern
;
1609 if (domain_type
== LTTNG_DOMAIN_UST
) {
1610 pattern
= "tp:tptest";
1612 pattern
= "lttng_test_filter_event";
1615 create_tracepoint_event_rule_trigger(pattern
, trigger_name
, NULL
, 0,
1616 NULL
, domain_type
, NULL
, &condition
, &trigger
);
1618 notification_channel
= lttng_notification_channel_create(
1619 lttng_session_daemon_notification_endpoint
);
1620 ok(notification_channel
, "Notification channel object creation");
1622 nc_status
= lttng_notification_channel_subscribe(
1623 notification_channel
, condition
);
1624 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1625 "Subscribe to tracepoint event rule condition");
1627 resume_application();
1629 /* Get notifications. */
1630 for (i
= 0; i
< notification_count
; i
++) {
1631 struct lttng_notification
*notification
= get_next_notification(
1632 notification_channel
);
1634 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1635 notification_count
);
1638 if (notification
== NULL
) {
1642 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1643 lttng_notification_destroy(notification
);
1650 suspend_application();
1651 lttng_notification_channel_destroy(notification_channel
);
1652 lttng_unregister_trigger(trigger
);
1653 lttng_trigger_destroy(trigger
);
1654 lttng_action_destroy(action
);
1655 lttng_condition_destroy(condition
);
1659 static void test_tracepoint_event_rule_notification_filter(
1660 enum lttng_domain_type domain_type
)
1663 const int notification_count
= 3;
1664 enum lttng_notification_channel_status nc_status
;
1665 struct lttng_condition
*ctrl_condition
= NULL
, *condition
= NULL
;
1666 struct lttng_notification_channel
*notification_channel
= NULL
;
1667 struct lttng_trigger
*ctrl_trigger
= NULL
, *trigger
= NULL
;
1668 const char * const ctrl_trigger_name
= "control_trigger";
1669 const char * const trigger_name
= "trigger";
1670 const char *pattern
;
1671 int ctrl_count
= 0, count
= 0;
1673 if (domain_type
== LTTNG_DOMAIN_UST
) {
1674 pattern
= "tp:tptest";
1676 pattern
= "lttng_test_filter_event";
1679 notification_channel
= lttng_notification_channel_create(
1680 lttng_session_daemon_notification_endpoint
);
1681 ok(notification_channel
, "Notification channel object creation");
1683 create_tracepoint_event_rule_trigger(pattern
, ctrl_trigger_name
, NULL
,
1684 0, NULL
, domain_type
, NULL
, &ctrl_condition
, &ctrl_trigger
);
1686 nc_status
= lttng_notification_channel_subscribe(
1687 notification_channel
, ctrl_condition
);
1688 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1689 "Subscribe to tracepoint event rule condition");
1692 * Attach a filter expression to get notification only if the
1693 * `intfield` is even.
1695 create_tracepoint_event_rule_trigger(pattern
, trigger_name
,
1696 "(intfield & 1) == 0", 0, NULL
, domain_type
, NULL
, &condition
,
1699 nc_status
= lttng_notification_channel_subscribe(
1700 notification_channel
, condition
);
1701 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1702 "Subscribe to tracepoint event rule condition");
1705 * We registered 2 notifications triggers, one with a filter and one
1706 * without (control). The one with a filter will only fired when the
1707 * `intfield` is a multiple of 2. We should get two times as many
1708 * control notifications as filter notifications.
1710 resume_application();
1713 * Get 3 notifications. We should get 1 for the regular trigger (with
1714 * the filter) and 2 from the control trigger. This works whatever
1715 * the order we receive the notifications.
1717 for (i
= 0; i
< notification_count
; i
++) {
1719 struct lttng_notification
*notification
= get_next_notification(
1720 notification_channel
);
1722 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1723 notification_count
);
1726 if (notification
== NULL
) {
1730 name
= get_notification_trigger_name(notification
);
1732 lttng_notification_destroy(notification
);
1736 if (strcmp(ctrl_trigger_name
, name
) == 0) {
1738 } else if (strcmp(trigger_name
, name
) == 0) {
1742 lttng_notification_destroy(notification
);
1745 ok(ctrl_count
/ 2 == count
,
1746 "Get twice as many control notif as of regular notif");
1749 suspend_application();
1751 lttng_unregister_trigger(trigger
);
1752 lttng_unregister_trigger(ctrl_trigger
);
1753 lttng_notification_channel_destroy(notification_channel
);
1754 lttng_trigger_destroy(trigger
);
1755 lttng_trigger_destroy(ctrl_trigger
);
1756 lttng_condition_destroy(condition
);
1757 lttng_condition_destroy(ctrl_condition
);
1760 static void test_tracepoint_event_rule_notification_exclusion(
1761 enum lttng_domain_type domain_type
)
1763 enum lttng_notification_channel_status nc_status
;
1764 struct lttng_condition
*ctrl_condition
= NULL
, *condition
= NULL
;
1765 struct lttng_notification_channel
*notification_channel
= NULL
;
1766 struct lttng_trigger
*ctrl_trigger
= NULL
, *trigger
= NULL
;
1767 int ctrl_count
= 0, count
= 0, i
;
1768 const int notification_count
= 6;
1769 const char * const ctrl_trigger_name
= "control_exclusion_trigger";
1770 const char * const trigger_name
= "exclusion_trigger";
1771 const char * const pattern
= "tp:tptest*";
1772 const char * const exclusions
[] = {
1779 notification_channel
= lttng_notification_channel_create(
1780 lttng_session_daemon_notification_endpoint
);
1781 ok(notification_channel
, "Notification channel object creation");
1783 create_tracepoint_event_rule_trigger(pattern
, ctrl_trigger_name
, NULL
,
1784 0, NULL
, domain_type
, NULL
, &ctrl_condition
,
1787 nc_status
= lttng_notification_channel_subscribe(
1788 notification_channel
, ctrl_condition
);
1789 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1790 "Subscribe to tracepoint event rule condition");
1792 create_tracepoint_event_rule_trigger(pattern
, trigger_name
, NULL
, 4,
1793 exclusions
, domain_type
, NULL
, &condition
,
1796 nc_status
= lttng_notification_channel_subscribe(
1797 notification_channel
, condition
);
1798 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1799 "Subscribe to tracepoint event rule condition");
1802 * We registered 2 notifications triggers, one with an exclusion and
1803 * one without (control).
1804 * - The trigger with an exclusion will fire once every iteration.
1805 * - The trigger without an exclusion will fire 5 times every
1808 * We should get 5 times as many notifications from the control
1811 resume_application();
1814 * Get 6 notifications. We should get 1 for the regular trigger (with
1815 * the exclusion) and 5 from the control trigger. This works whatever
1816 * the order we receive the notifications.
1818 for (i
= 0; i
< notification_count
; i
++) {
1820 struct lttng_notification
*notification
= get_next_notification(
1821 notification_channel
);
1823 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1824 notification_count
);
1827 if (notification
== NULL
) {
1831 name
= get_notification_trigger_name(notification
);
1833 lttng_notification_destroy(notification
);
1837 if (strcmp(ctrl_trigger_name
, name
) == 0) {
1839 } else if (strcmp(trigger_name
, name
) == 0) {
1843 lttng_notification_destroy(notification
);
1846 ok(ctrl_count
/ 5 == count
,
1847 "Got 5 times as many control notif as of regular notif");
1850 suspend_application();
1852 lttng_unregister_trigger(trigger
);
1853 lttng_unregister_trigger(ctrl_trigger
);
1854 lttng_notification_channel_destroy(notification_channel
);
1855 lttng_trigger_destroy(trigger
);
1856 lttng_trigger_destroy(ctrl_trigger
);
1857 lttng_condition_destroy(condition
);
1858 lttng_condition_destroy(ctrl_condition
);
1862 static void test_kprobe_event_rule_notification(void)
1865 enum lttng_error_code ret_code
;
1866 const int notification_count
= 3;
1867 enum lttng_notification_channel_status nc_status
;
1868 enum lttng_event_rule_status event_rule_status
;
1869 struct lttng_notification_channel
*notification_channel
= NULL
;
1870 struct lttng_condition
*condition
= NULL
;
1871 struct lttng_kernel_probe_location
*location
= NULL
;
1872 struct lttng_event_rule
*event_rule
= NULL
;
1873 struct lttng_action
*action
= NULL
;
1874 struct lttng_trigger
*trigger
= NULL
;
1875 const char * const trigger_name
= "kprobe_trigger";
1876 const char * const symbol_name
= "lttng_test_filter_event_write";
1878 action
= lttng_action_notify_create();
1880 fail("Failed to create notify action");
1884 location
= lttng_kernel_probe_location_symbol_create(symbol_name
, 0);
1886 fail("Failed to create kernel probe location");
1890 notification_channel
= lttng_notification_channel_create(
1891 lttng_session_daemon_notification_endpoint
);
1892 ok(notification_channel
, "Notification channel object creation");
1894 event_rule
= lttng_event_rule_kernel_kprobe_create(location
);
1895 ok(event_rule
, "kprobe event rule object creation");
1897 event_rule_status
= lttng_event_rule_kernel_kprobe_set_event_name(
1898 event_rule
, trigger_name
);
1899 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
1900 "Setting kprobe event rule name: '%s'", trigger_name
);
1902 condition
= lttng_condition_event_rule_matches_create(event_rule
);
1903 ok(condition
, "Condition event rule object creation");
1905 /* Register the trigger for condition. */
1906 trigger
= lttng_trigger_create(condition
, action
);
1908 fail("Failed to create trigger with kernel probe event rule condition and notify action");
1912 ret_code
= lttng_register_trigger_with_name(trigger
, trigger_name
);
1913 if (ret_code
!= LTTNG_OK
) {
1914 fail("Failed to register trigger with kernel probe event rule condition and notify action");
1918 nc_status
= lttng_notification_channel_subscribe(
1919 notification_channel
, condition
);
1920 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
1921 "Subscribe to tracepoint event rule condition");
1923 resume_application();
1925 for (i
= 0; i
< notification_count
; i
++) {
1926 struct lttng_notification
*notification
= get_next_notification(
1927 notification_channel
);
1929 ok(notification
, "Received notification (%d/%d)", i
+ 1,
1930 notification_count
);
1933 if (notification
== NULL
) {
1937 ret
= validator_notification_trigger_name(notification
, trigger_name
);
1938 lttng_notification_destroy(notification
);
1945 suspend_application();
1946 lttng_notification_channel_destroy(notification_channel
);
1947 lttng_unregister_trigger(trigger
);
1948 lttng_trigger_destroy(trigger
);
1949 lttng_action_destroy(action
);
1950 lttng_event_rule_destroy(event_rule
);
1951 lttng_condition_destroy(condition
);
1952 lttng_kernel_probe_location_destroy(location
);
1956 static void test_uprobe_event_rule_notification(
1957 const char *testapp_path
,
1958 const char *test_symbol_name
)
1961 enum lttng_error_code ret_code
;
1962 const int notification_count
= 3;
1963 enum lttng_notification_channel_status nc_status
;
1964 enum lttng_event_rule_status event_rule_status
;
1965 struct lttng_notification_channel
*notification_channel
= NULL
;
1966 struct lttng_userspace_probe_location
*probe_location
= NULL
;
1967 struct lttng_userspace_probe_location_lookup_method
*lookup_method
=
1969 struct lttng_condition
*condition
= NULL
;
1970 struct lttng_event_rule
*event_rule
= NULL
;
1971 struct lttng_action
*action
= NULL
;
1972 struct lttng_trigger
*trigger
= NULL
;
1973 const char * const trigger_name
= "uprobe_trigger";
1975 action
= lttng_action_notify_create();
1977 fail("Failed to create notify action");
1981 lookup_method
= lttng_userspace_probe_location_lookup_method_function_elf_create();
1982 if (!lookup_method
) {
1983 fail("Setup error on userspace probe lookup method creation");
1987 probe_location
= lttng_userspace_probe_location_function_create(
1988 testapp_path
, test_symbol_name
, lookup_method
);
1989 if (!probe_location
) {
1990 fail("Failed to create userspace probe location");
1994 notification_channel
= lttng_notification_channel_create(
1995 lttng_session_daemon_notification_endpoint
);
1996 ok(notification_channel
, "Notification channel object creation");
1998 event_rule
= lttng_event_rule_kernel_uprobe_create(probe_location
);
1999 ok(event_rule
, "kprobe event rule object creation");
2001 event_rule_status
= lttng_event_rule_kernel_uprobe_set_event_name(
2002 event_rule
, trigger_name
);
2003 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
2004 "Setting uprobe event rule name: '%s'", trigger_name
);
2006 condition
= lttng_condition_event_rule_matches_create(event_rule
);
2007 ok(condition
, "Condition event rule object creation");
2009 /* Register the trigger for condition. */
2010 trigger
= lttng_trigger_create(condition
, action
);
2012 fail("Failed to create trigger with userspace probe event rule condition and notify action");
2016 ret_code
= lttng_register_trigger_with_name(trigger
, trigger_name
);
2017 if (ret_code
!= LTTNG_OK
) {
2018 fail("Failed to register trigger with userspace probe event rule condition and notify action");
2022 nc_status
= lttng_notification_channel_subscribe(
2023 notification_channel
, condition
);
2024 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
2025 "Subscribe to tracepoint event rule condition");
2027 resume_application();
2029 for (i
= 0; i
< 3; i
++) {
2030 struct lttng_notification
*notification
= get_next_notification(
2031 notification_channel
);
2033 ok(notification
, "Received notification (%d/%d)", i
+ 1,
2034 notification_count
);
2037 if (notification
== NULL
) {
2041 ret
= validator_notification_trigger_name(notification
, trigger_name
);
2042 lttng_notification_destroy(notification
);
2048 suspend_application();
2050 lttng_notification_channel_destroy(notification_channel
);
2051 lttng_unregister_trigger(trigger
);
2052 lttng_trigger_destroy(trigger
);
2053 lttng_action_destroy(action
);
2054 lttng_userspace_probe_location_destroy(probe_location
);
2055 lttng_event_rule_destroy(event_rule
);
2056 lttng_condition_destroy(condition
);
2060 static void test_syscall_event_rule_notification(void)
2063 enum lttng_error_code ret_code
;
2064 const int notification_count
= 3;
2065 enum lttng_notification_channel_status nc_status
;
2066 enum lttng_event_rule_status event_rule_status
;
2067 struct lttng_notification_channel
*notification_channel
= NULL
;
2068 struct lttng_condition
*condition
= NULL
;
2069 struct lttng_event_rule
*event_rule
= NULL
;
2070 struct lttng_action
*action
= NULL
;
2071 struct lttng_trigger
*trigger
= NULL
;
2072 const char * const trigger_name
= "syscall_trigger";
2073 const char * const syscall_name
= "openat";
2075 action
= lttng_action_notify_create();
2077 fail("Failed to create notify action");
2081 notification_channel
= lttng_notification_channel_create(
2082 lttng_session_daemon_notification_endpoint
);
2083 ok(notification_channel
, "Notification channel object creation");
2085 event_rule
= lttng_event_rule_kernel_syscall_create(LTTNG_EVENT_RULE_KERNEL_SYSCALL_EMISSION_SITE_ENTRY
);
2086 ok(event_rule
, "syscall event rule object creation");
2088 event_rule_status
= lttng_event_rule_kernel_syscall_set_name_pattern(
2089 event_rule
, syscall_name
);
2090 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
2091 "Setting syscall event rule pattern: '%s'", syscall_name
);
2093 condition
= lttng_condition_event_rule_matches_create(event_rule
);
2094 ok(condition
, "Condition syscall event rule object creation");
2096 /* Register the trigger for condition. */
2097 trigger
= lttng_trigger_create(condition
, action
);
2099 fail("Failed to create trigger with syscall event rule condition and notify action");
2103 ret_code
= lttng_register_trigger_with_name(trigger
, trigger_name
);
2104 if (ret_code
!= LTTNG_OK
) {
2105 fail("Failed to register trigger with syscall event rule condition and notify action");
2109 nc_status
= lttng_notification_channel_subscribe(
2110 notification_channel
, condition
);
2111 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
2112 "Subscribe to tracepoint event rule condition");
2114 resume_application();
2116 for (i
= 0; i
< notification_count
; i
++) {
2117 struct lttng_notification
*notification
= get_next_notification(
2118 notification_channel
);
2120 ok(notification
, "Received notification (%d/%d)", i
+ 1,
2121 notification_count
);
2124 if (notification
== NULL
) {
2128 ret
= validator_notification_trigger_name(notification
, trigger_name
);
2129 lttng_notification_destroy(notification
);
2135 suspend_application();
2136 lttng_notification_channel_destroy(notification_channel
);
2137 lttng_unregister_trigger(trigger
);
2138 lttng_trigger_destroy(trigger
);
2139 lttng_action_destroy(action
);
2140 lttng_condition_destroy(condition
);
2144 static void test_syscall_event_rule_notification_filter(void)
2147 enum lttng_error_code ret_code
;
2148 const int notification_count
= 3;
2149 enum lttng_notification_channel_status nc_status
;
2150 enum lttng_event_rule_status event_rule_status
;
2151 struct lttng_notification_channel
*notification_channel
= NULL
;
2152 struct lttng_condition
*condition
= NULL
;
2153 struct lttng_event_rule
*event_rule
= NULL
;
2154 struct lttng_action
*action
= NULL
;
2155 struct lttng_trigger
*trigger
= NULL
;
2156 const char * const trigger_name
= "syscall_trigger";
2157 const char * const syscall_name
= "openat";
2158 const char * const filter_pattern
= "filename == \"/proc/cpuinfo\"";
2160 action
= lttng_action_notify_create();
2162 fail("Failed to create notify action");
2166 notification_channel
= lttng_notification_channel_create(
2167 lttng_session_daemon_notification_endpoint
);
2168 ok(notification_channel
, "Notification channel object creation");
2170 event_rule
= lttng_event_rule_kernel_syscall_create(LTTNG_EVENT_RULE_KERNEL_SYSCALL_EMISSION_SITE_ENTRY
);
2171 ok(event_rule
, "syscall event rule object creation");
2173 event_rule_status
= lttng_event_rule_kernel_syscall_set_name_pattern(
2174 event_rule
, syscall_name
);
2175 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
2176 "Setting syscall event rule pattern: '%s'", syscall_name
);
2178 event_rule_status
= lttng_event_rule_kernel_syscall_set_filter(
2179 event_rule
, filter_pattern
);
2180 ok(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
,
2181 "Setting filter: '%s'", filter_pattern
);
2183 condition
= lttng_condition_event_rule_matches_create(event_rule
);
2184 ok(condition
, "Condition event rule object creation");
2186 /* Register the triggers for condition */
2187 trigger
= lttng_trigger_create(condition
, action
);
2189 fail("Failed to create trigger with syscall filtering event rule condition and notify action");
2193 ret_code
= lttng_register_trigger_with_name(trigger
, trigger_name
);
2194 if (ret_code
!= LTTNG_OK
) {
2195 fail("Failed to register trigger with syscall filtering event rule condition and notify action");
2199 nc_status
= lttng_notification_channel_subscribe(
2200 notification_channel
, condition
);
2201 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
2202 "Subscribe to tracepoint event rule condition");
2204 resume_application();
2206 for (i
= 0; i
< notification_count
; i
++) {
2207 struct lttng_notification
*notification
= get_next_notification(
2208 notification_channel
);
2210 ok(notification
, "Received notification (%d/%d)", i
+ 1,
2211 notification_count
);
2214 if (notification
== NULL
) {
2218 ret
= validator_notification_trigger_name(notification
, trigger_name
);
2219 lttng_notification_destroy(notification
);
2226 suspend_application();
2228 lttng_unregister_trigger(trigger
);
2229 lttng_notification_channel_destroy(notification_channel
);
2230 lttng_trigger_destroy(trigger
);
2231 lttng_event_rule_destroy(event_rule
);
2232 lttng_condition_destroy(condition
);
2236 static int generate_capture_descr(struct lttng_condition
*condition
)
2239 struct lttng_event_expr
*expr
= NULL
;
2240 const unsigned int basic_field_count
= sizeof(test_capture_base_fields
) /
2241 sizeof(*test_capture_base_fields
);
2242 enum lttng_condition_status cond_status
;
2244 for (i
= 0; i
< basic_field_count
; i
++) {
2245 diag("Adding capture descriptor '%s'",
2246 test_capture_base_fields
[i
].field_name
);
2248 switch (test_capture_base_fields
[i
].field_type
) {
2249 case FIELD_TYPE_PAYLOAD
:
2250 expr
= lttng_event_expr_event_payload_field_create(
2251 test_capture_base_fields
[i
].field_name
);
2253 case FIELD_TYPE_CONTEXT
:
2254 expr
= lttng_event_expr_channel_context_field_create(
2255 test_capture_base_fields
[i
].field_name
);
2257 case FIELD_TYPE_ARRAY_FIELD
:
2261 char field_name
[FIELD_NAME_MAX_LEN
];
2262 struct lttng_event_expr
*array_expr
= NULL
;
2264 nb_matches
= sscanf(test_capture_base_fields
[i
].field_name
,
2265 "%[^[][%u]", field_name
, &index
);
2266 if (nb_matches
!= 2) {
2267 fail("Unexpected array field name format: field name = '%s'",
2268 test_capture_base_fields
[i
].field_name
);
2273 array_expr
= lttng_event_expr_event_payload_field_create(
2276 expr
= lttng_event_expr_array_field_element_create(
2280 case FIELD_TYPE_APP_CONTEXT
:
2281 fail("Application context tests are not implemented yet.");
2289 fail("Failed to create capture expression");
2294 cond_status
= lttng_condition_event_rule_matches_append_capture_descriptor(
2296 if (cond_status
!= LTTNG_CONDITION_STATUS_OK
) {
2297 fail("Failed to append capture descriptor");
2299 lttng_event_expr_destroy(expr
);
2310 static int validator_notification_trigger_capture(
2311 enum lttng_domain_type domain
,
2312 struct lttng_notification
*notification
,
2313 const int iteration
)
2316 unsigned int capture_count
, i
;
2317 enum lttng_evaluation_event_rule_matches_status
2318 event_rule_matches_evaluation_status
;
2319 enum lttng_event_field_value_status event_field_value_status
;
2320 const struct lttng_evaluation
*evaluation
;
2321 const struct lttng_event_field_value
*captured_fields
;
2322 bool at_least_one_error
= false;
2324 evaluation
= lttng_notification_get_evaluation(notification
);
2325 if (evaluation
== NULL
) {
2326 fail("Failed to get evaluation from notification during trigger capture test");
2331 event_rule_matches_evaluation_status
=
2332 lttng_evaluation_event_rule_matches_get_captured_values(
2333 evaluation
, &captured_fields
);
2334 if (event_rule_matches_evaluation_status
!=
2335 LTTNG_EVALUATION_EVENT_RULE_MATCHES_STATUS_OK
) {
2336 diag("Failed to get event rule evaluation captured values: status = %d",
2337 (int) event_rule_matches_evaluation_status
);
2342 event_field_value_status
=
2343 lttng_event_field_value_array_get_length(captured_fields
,
2345 if (event_field_value_status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
2346 fail("Failed to get count of captured value field array");
2351 for (i
= 0; i
< capture_count
; i
++) {
2352 const struct lttng_event_field_value
*captured_field
= NULL
;
2353 validate_cb validate
;
2356 diag("Validating capture of field '%s'",
2357 test_capture_base_fields
[i
].field_name
);
2358 event_field_value_status
=
2359 lttng_event_field_value_array_get_element_at_index(
2364 case LTTNG_DOMAIN_UST
:
2365 expected
= test_capture_base_fields
[i
].expected_ust
;
2367 case LTTNG_DOMAIN_KERNEL
:
2368 expected
= test_capture_base_fields
[i
].expected_kernel
;
2371 fail("Unexpected domain encountered: domain = %d",
2377 if (domain
== LTTNG_DOMAIN_UST
) {
2378 validate
= test_capture_base_fields
[i
].validate_ust
;
2380 validate
= test_capture_base_fields
[i
].validate_kernel
;
2384 ok(event_field_value_status
== LTTNG_EVENT_FIELD_VALUE_STATUS_UNAVAILABLE
,
2385 "No payload captured");
2389 if (event_field_value_status
!= LTTNG_EVENT_FIELD_VALUE_STATUS_OK
) {
2390 if (event_field_value_status
==
2391 LTTNG_EVENT_FIELD_VALUE_STATUS_UNAVAILABLE
) {
2392 fail("Expected a capture but it is unavailable");
2394 fail("lttng_event_field_value_array_get_element_at_index returned an error: status = %d",
2395 (int) event_field_value_status
);
2402 diag("Captured field of type %s",
2403 field_value_type_to_str(
2404 lttng_event_field_value_get_type(captured_field
)));
2406 LTTNG_ASSERT(validate
);
2407 ret
= validate(captured_field
, iteration
);
2409 at_least_one_error
= true;
2413 ret
= at_least_one_error
;
2419 static void test_tracepoint_event_rule_notification_capture(
2420 enum lttng_domain_type domain_type
)
2422 enum lttng_notification_channel_status nc_status
;
2425 struct lttng_condition
*condition
= NULL
;
2426 struct lttng_notification_channel
*notification_channel
= NULL
;
2427 struct lttng_trigger
*trigger
= NULL
;
2428 const char *trigger_name
= "my_precious";
2429 const char *pattern
;
2431 if (domain_type
== LTTNG_DOMAIN_UST
) {
2432 pattern
= "tp:tptest";
2434 pattern
= "lttng_test_filter_event";
2437 create_tracepoint_event_rule_trigger(pattern
, trigger_name
, NULL
, 0,
2438 NULL
, domain_type
, generate_capture_descr
, &condition
,
2441 notification_channel
= lttng_notification_channel_create(
2442 lttng_session_daemon_notification_endpoint
);
2443 ok(notification_channel
, "Notification channel object creation");
2445 nc_status
= lttng_notification_channel_subscribe(
2446 notification_channel
, condition
);
2447 ok(nc_status
== LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
,
2448 "Subscribe to tracepoint event rule condition");
2450 resume_application();
2452 /* Get 3 notifications */
2453 for (i
= 0; i
< 3; i
++) {
2454 struct lttng_notification
*notification
= get_next_notification(
2455 notification_channel
);
2456 ok(notification
, "Received notification");
2459 if (notification
== NULL
) {
2463 ret
= validator_notification_trigger_name(notification
, trigger_name
);
2465 lttng_notification_destroy(notification
);
2469 ret
= validator_notification_trigger_capture(domain_type
, notification
, i
);
2471 lttng_notification_destroy(notification
);
2475 lttng_notification_destroy(notification
);
2479 suspend_application();
2480 lttng_notification_channel_destroy(notification_channel
);
2481 lttng_unregister_trigger(trigger
);
2482 lttng_trigger_destroy(trigger
);
2483 lttng_condition_destroy(condition
);
2487 int main(int argc
, const char *argv
[])
2490 const char *domain_type_string
= NULL
;
2491 enum lttng_domain_type domain_type
= LTTNG_DOMAIN_NONE
;
2494 fail("Missing test scenario, domain type, pid, or application state file argument(s)");
2498 test_scenario
= atoi(argv
[1]);
2499 domain_type_string
= argv
[2];
2500 app_pid
= (pid_t
) atoi(argv
[3]);
2501 app_state_file
= argv
[4];
2503 if (!strcmp("LTTNG_DOMAIN_UST", domain_type_string
)) {
2504 domain_type
= LTTNG_DOMAIN_UST
;
2506 if (!strcmp("LTTNG_DOMAIN_KERNEL", domain_type_string
)) {
2507 domain_type
= LTTNG_DOMAIN_KERNEL
;
2509 if (domain_type
== LTTNG_DOMAIN_NONE
) {
2510 fail("Unknown domain type");
2515 * Test cases are responsible for resuming the app when needed
2516 * and making sure it's suspended when returning.
2518 suspend_application();
2520 switch (test_scenario
) {
2525 /* Test cases that need gen-ust-event testapp. */
2526 diag("Test basic notification error paths for %s domain",
2527 domain_type_string
);
2528 test_invalid_channel_subscription(domain_type
);
2530 diag("Test tracepoint event rule notifications for domain %s",
2531 domain_type_string
);
2532 test_tracepoint_event_rule_notification(domain_type
);
2534 diag("Test tracepoint event rule notifications with filter for domain %s",
2535 domain_type_string
);
2536 test_tracepoint_event_rule_notification_filter(domain_type
);
2541 const char *session_name
, *channel_name
;
2543 /* Test cases that need a tracing session enabled. */
2547 * Argument 7 and upward are named pipe location for consumerd
2550 named_pipe_args_start
= 7;
2553 fail("Missing parameter for tests to run %d", argc
);
2559 session_name
= argv
[5];
2560 channel_name
= argv
[6];
2562 test_subscription_twice(session_name
, channel_name
,
2565 diag("Test trigger for domain %s with buffer_usage_low condition",
2566 domain_type_string
);
2567 test_triggers_buffer_usage_condition(session_name
, channel_name
,
2568 LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
);
2570 diag("Test trigger for domain %s with buffer_usage_high condition",
2571 domain_type_string
);
2572 test_triggers_buffer_usage_condition(session_name
, channel_name
,
2573 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
);
2575 diag("Test buffer usage notification channel api for domain %s",
2576 domain_type_string
);
2577 test_buffer_usage_notification_channel(session_name
, channel_name
,
2584 * Test cases that need a test app with more than one event
2590 * At the moment, the only test case of this scenario is
2591 * exclusion which is only supported by UST.
2593 LTTNG_ASSERT(domain_type
== LTTNG_DOMAIN_UST
);
2594 diag("Test tracepoint event rule notifications with exclusion for domain %s",
2595 domain_type_string
);
2596 test_tracepoint_event_rule_notification_exclusion(domain_type
);
2603 /* Test cases that need the kernel tracer. */
2604 LTTNG_ASSERT(domain_type
== LTTNG_DOMAIN_KERNEL
);
2606 diag("Test kprobe event rule notifications for domain %s",
2607 domain_type_string
);
2609 test_kprobe_event_rule_notification();
2616 /* Test cases that need the kernel tracer. */
2617 LTTNG_ASSERT(domain_type
== LTTNG_DOMAIN_KERNEL
);
2619 diag("Test syscall event rule notifications for domain %s",
2620 domain_type_string
);
2622 test_syscall_event_rule_notification();
2624 diag("Test syscall filtering event rule notifications for domain %s",
2625 domain_type_string
);
2627 test_syscall_event_rule_notification_filter();
2633 const char *testapp_path
, *test_symbol_name
;
2638 fail("Missing parameter for tests to run %d", argc
);
2642 testapp_path
= argv
[5];
2643 test_symbol_name
= argv
[6];
2644 /* Test cases that need the kernel tracer. */
2645 LTTNG_ASSERT(domain_type
== LTTNG_DOMAIN_KERNEL
);
2647 diag("Test userspace-probe event rule notifications for domain %s",
2648 domain_type_string
);
2650 test_uprobe_event_rule_notification(
2651 testapp_path
, test_symbol_name
);
2657 switch(domain_type
) {
2658 case LTTNG_DOMAIN_UST
:
2661 case LTTNG_DOMAIN_KERNEL
:
2668 diag("Test tracepoint event rule notification captures for domain %s",
2669 domain_type_string
);
2670 test_tracepoint_event_rule_notification_capture(domain_type
);
2680 return exit_status();