Commit | Line | Data |
---|---|---|
434f8068 JR |
1 | /* |
2 | * notification.c | |
3 | * | |
4 | * Tests suite for LTTng notification API | |
5 | * | |
6 | * Copyright (C) 2017 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> | |
7 | * | |
9d16b343 | 8 | * SPDX-License-Identifier: MIT |
434f8068 | 9 | * |
434f8068 JR |
10 | */ |
11 | ||
12 | #include <assert.h> | |
13 | #include <math.h> | |
14 | #include <stdbool.h> | |
15 | #include <stdio.h> | |
16 | #include <stdlib.h> | |
17 | #include <string.h> | |
18 | #include <unistd.h> | |
19 | #include <inttypes.h> | |
20 | #include <sys/types.h> | |
21 | #include <sys/stat.h> | |
22 | #include <fcntl.h> | |
854382b8 JR |
23 | #include <signal.h> |
24 | #include <errno.h> | |
25 | #include <poll.h> | |
434f8068 JR |
26 | |
27 | #include <lttng/action/action.h> | |
28 | #include <lttng/action/notify.h> | |
29 | #include <lttng/condition/buffer-usage.h> | |
30 | #include <lttng/condition/condition.h> | |
31 | #include <lttng/condition/evaluation.h> | |
32 | #include <lttng/domain.h> | |
33 | #include <lttng/endpoint.h> | |
34 | #include <lttng/lttng-error.h> | |
35 | #include <lttng/notification/channel.h> | |
36 | #include <lttng/notification/notification.h> | |
37 | #include <lttng/trigger/trigger.h> | |
25040abc | 38 | #include <lttng/lttng.h> |
434f8068 JR |
39 | |
40 | #include <tap/tap.h> | |
41 | ||
42 | #define NUM_TESTS 104 | |
854382b8 | 43 | |
434f8068 JR |
44 | int nb_args = 0; |
45 | int named_pipe_args_start = 0; | |
854382b8 JR |
46 | pid_t app_pid = -1; |
47 | const char *app_state_file = NULL; | |
48 | ||
49 | static | |
50 | void wait_on_file(const char *path, bool file_exist) | |
51 | { | |
52 | if (!path) { | |
53 | return; | |
54 | } | |
55 | for (;;) { | |
56 | int ret; | |
57 | struct stat buf; | |
58 | ||
59 | ret = stat(path, &buf); | |
60 | if (ret == -1 && errno == ENOENT) { | |
61 | if (file_exist) { | |
b201dc0c FD |
62 | /* |
63 | * The file does not exist. wait a bit and | |
64 | * continue looping until it does. | |
65 | */ | |
66 | (void) poll(NULL, 0, 10); | |
67 | continue; | |
854382b8 | 68 | } |
b201dc0c FD |
69 | |
70 | /* | |
71 | * File does not exist and the exit condition we want. | |
72 | * Break from the loop and return. | |
73 | */ | |
74 | break; | |
854382b8 JR |
75 | } |
76 | if (ret) { | |
77 | perror("stat"); | |
78 | exit(EXIT_FAILURE); | |
79 | } | |
b201dc0c FD |
80 | /* |
81 | * stat() returned 0, so the file exists. break now only if | |
82 | * that's the exit condition we want. | |
83 | */ | |
84 | if (file_exist) { | |
85 | break; | |
86 | } | |
854382b8 JR |
87 | } |
88 | } | |
434f8068 | 89 | |
ceafd18e | 90 | static |
434f8068 JR |
91 | int write_pipe(const char *path, uint8_t data) |
92 | { | |
93 | int ret = 0; | |
94 | int fd = 0; | |
95 | ||
96 | fd = open(path, O_WRONLY | O_NONBLOCK); | |
97 | if (fd < 0) { | |
98 | perror("Could not open consumer control named pipe"); | |
99 | goto end; | |
100 | } | |
101 | ||
102 | ret = write(fd, &data , sizeof(data)); | |
103 | if (ret < 1) { | |
104 | perror("Named pipe write failed"); | |
eff748d0 JR |
105 | if (close(fd)) { |
106 | perror("Named pipe close failed"); | |
107 | } | |
434f8068 JR |
108 | ret = -1; |
109 | goto end; | |
110 | } | |
111 | ||
112 | ret = close(fd); | |
113 | if (ret < 0) { | |
114 | perror("Name pipe closing failed"); | |
115 | ret = -1; | |
116 | goto end; | |
117 | } | |
118 | end: | |
119 | return ret; | |
120 | } | |
121 | ||
ceafd18e | 122 | static |
434f8068 JR |
123 | int stop_consumer(const char **argv) |
124 | { | |
9df6c82a JG |
125 | int ret = 0, i; |
126 | ||
127 | for (i = named_pipe_args_start; i < nb_args; i++) { | |
434f8068 JR |
128 | ret = write_pipe(argv[i], 49); |
129 | } | |
130 | return ret; | |
131 | } | |
132 | ||
ceafd18e | 133 | static |
434f8068 JR |
134 | int resume_consumer(const char **argv) |
135 | { | |
9df6c82a JG |
136 | int ret = 0, i; |
137 | ||
138 | for (i = named_pipe_args_start; i < nb_args; i++) { | |
434f8068 JR |
139 | ret = write_pipe(argv[i], 0); |
140 | } | |
141 | return ret; | |
142 | } | |
143 | ||
ceafd18e SM |
144 | static |
145 | int suspend_application(void) | |
854382b8 JR |
146 | { |
147 | int ret; | |
148 | struct stat buf; | |
149 | ||
150 | if (!stat(app_state_file, &buf)) { | |
151 | fail("App is already in a suspended state."); | |
152 | ret = -1; | |
153 | goto error; | |
154 | } | |
155 | ||
156 | /* | |
157 | * Send SIGUSR1 to application instructing it to bypass tracepoint. | |
158 | */ | |
159 | ret = kill(app_pid, SIGUSR1); | |
160 | if (ret) { | |
161 | fail("SIGUSR1 failed. errno %d", errno); | |
162 | ret = -1; | |
163 | goto error; | |
164 | } | |
165 | ||
166 | wait_on_file(app_state_file, true); | |
167 | ||
168 | error: | |
169 | return ret; | |
170 | ||
171 | } | |
172 | ||
ceafd18e | 173 | static |
854382b8 JR |
174 | int resume_application() |
175 | { | |
176 | int ret; | |
177 | struct stat buf; | |
178 | ||
179 | ret = stat(app_state_file, &buf); | |
180 | if (ret == -1 && errno == ENOENT) { | |
181 | fail("State file does not exist"); | |
182 | goto error; | |
183 | } | |
184 | if (ret) { | |
185 | perror("stat"); | |
186 | goto error; | |
187 | } | |
188 | ||
189 | ret = kill(app_pid, SIGUSR1); | |
190 | if (ret) { | |
191 | fail("SIGUSR1 failed. errno %d", errno); | |
192 | ret = -1; | |
193 | goto error; | |
194 | } | |
195 | ||
196 | wait_on_file(app_state_file, false); | |
197 | ||
198 | error: | |
199 | return ret; | |
200 | ||
201 | } | |
202 | ||
203 | ||
ceafd18e | 204 | static |
434f8068 JR |
205 | void test_triggers_buffer_usage_condition(const char *session_name, |
206 | const char *channel_name, | |
207 | enum lttng_domain_type domain_type, | |
208 | enum lttng_condition_type condition_type) | |
209 | { | |
9df6c82a | 210 | unsigned int test_vector_size = 5, i; |
434f8068 JR |
211 | enum lttng_condition_status condition_status; |
212 | struct lttng_action *action; | |
213 | ||
214 | /* Set-up */ | |
215 | action = lttng_action_notify_create(); | |
216 | if (!action) { | |
217 | fail("Setup error on action creation"); | |
218 | goto end; | |
219 | } | |
220 | ||
221 | /* Test lttng_register_trigger with null value */ | |
222 | ok(lttng_register_trigger(NULL) == -LTTNG_ERR_INVALID, "Registering a NULL trigger fails as expected"); | |
223 | ||
224 | /* Test: register a trigger */ | |
9df6c82a JG |
225 | |
226 | for (i = 0; i < pow(2,test_vector_size); i++) { | |
434f8068 JR |
227 | int loop_ret = 0; |
228 | char *test_tuple_string = NULL; | |
229 | unsigned int mask_position = 0; | |
230 | bool session_name_set = false; | |
231 | bool channel_name_set = false; | |
232 | bool threshold_ratio_set = false; | |
233 | bool threshold_byte_set = false; | |
234 | bool domain_type_set = false; | |
235 | ||
236 | struct lttng_trigger *trigger = NULL; | |
237 | struct lttng_condition *condition = NULL; | |
238 | ||
239 | /* Create base condition */ | |
240 | switch (condition_type) { | |
241 | case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW: | |
242 | condition = lttng_condition_buffer_usage_low_create(); | |
243 | break; | |
244 | case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH: | |
245 | condition = lttng_condition_buffer_usage_high_create(); | |
246 | break; | |
247 | default: | |
248 | loop_ret = 1; | |
249 | goto loop_end; | |
250 | } | |
251 | ||
252 | if (!condition) { | |
253 | loop_ret = 1; | |
254 | goto loop_end; | |
255 | ||
256 | } | |
257 | ||
258 | /* Prepare the condition for trigger registration test */ | |
259 | ||
260 | /* Set session name */ | |
261 | if ((1 << mask_position) & i) { | |
262 | condition_status = lttng_condition_buffer_usage_set_session_name( | |
263 | condition, session_name); | |
264 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
265 | loop_ret = 1; | |
266 | goto loop_end; | |
267 | } | |
268 | session_name_set = true; | |
269 | } | |
270 | mask_position++; | |
271 | ||
272 | /* Set channel name */ | |
273 | if ((1 << mask_position) & i) { | |
274 | condition_status = lttng_condition_buffer_usage_set_channel_name( | |
275 | condition, channel_name); | |
276 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
277 | loop_ret = 1; | |
278 | goto loop_end; | |
279 | } | |
280 | channel_name_set = true; | |
281 | } | |
282 | mask_position++; | |
283 | ||
284 | /* Set threshold ratio */ | |
285 | if ((1 << mask_position) & i) { | |
286 | condition_status = lttng_condition_buffer_usage_set_threshold_ratio( | |
287 | condition, 0.0); | |
288 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
289 | loop_ret = 1; | |
290 | goto loop_end; | |
291 | } | |
292 | threshold_ratio_set = true; | |
293 | } | |
294 | mask_position++; | |
295 | ||
296 | /* Set threshold byte */ | |
297 | if ((1 << mask_position) & i) { | |
298 | condition_status = lttng_condition_buffer_usage_set_threshold( | |
299 | condition, 0); | |
300 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
301 | loop_ret = 1; | |
302 | goto loop_end; | |
303 | } | |
304 | threshold_byte_set = true; | |
305 | } | |
306 | mask_position++; | |
307 | ||
308 | /* Set domain type */ | |
309 | if ((1 << mask_position) & i) { | |
310 | condition_status = lttng_condition_buffer_usage_set_domain_type( | |
311 | condition, LTTNG_DOMAIN_UST); | |
312 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
313 | loop_ret = 1; | |
314 | goto loop_end; | |
315 | } | |
316 | domain_type_set = true; | |
317 | } | |
318 | ||
319 | /* Safety check */ | |
320 | if (mask_position != test_vector_size -1) { | |
321 | assert("Logic error for test vector generation"); | |
322 | } | |
323 | ||
4fdd1e3a | 324 | loop_ret = asprintf(&test_tuple_string, "session name %s, channel name %s, threshold ratio %s, threshold byte %s, domain type %s", |
434f8068 JR |
325 | session_name_set ? "set" : "unset", |
326 | channel_name_set ? "set" : "unset", | |
327 | threshold_ratio_set ? "set" : "unset", | |
328 | threshold_byte_set ? "set" : "unset", | |
329 | domain_type_set? "set" : "unset"); | |
330 | if (!test_tuple_string || loop_ret < 0) { | |
331 | loop_ret = 1; | |
332 | goto loop_end; | |
333 | } | |
334 | ||
335 | /* Create trigger */ | |
336 | trigger = lttng_trigger_create(condition, action); | |
337 | if (!trigger) { | |
338 | loop_ret = 1; | |
339 | goto loop_end; | |
340 | } | |
341 | ||
342 | loop_ret = lttng_register_trigger(trigger); | |
343 | ||
344 | loop_end: | |
345 | if (loop_ret == 1) { | |
346 | fail("Setup error occurred for tuple: %s", test_tuple_string); | |
347 | goto loop_cleanup; | |
348 | } | |
349 | ||
350 | /* This combination happens three times */ | |
351 | if (session_name_set && channel_name_set | |
352 | && (threshold_ratio_set || threshold_byte_set) | |
353 | && domain_type_set) { | |
354 | ok(loop_ret == 0, "Trigger is registered: %s", test_tuple_string); | |
355 | ||
356 | /* | |
357 | * Test that a trigger cannot be registered | |
358 | * multiple time. | |
359 | */ | |
360 | loop_ret = lttng_register_trigger(trigger); | |
361 | ok(loop_ret == -LTTNG_ERR_TRIGGER_EXISTS, "Re-register trigger fails as expected: %s", test_tuple_string); | |
362 | ||
363 | /* Test that a trigger can be unregistered */ | |
364 | loop_ret = lttng_unregister_trigger(trigger); | |
365 | ok(loop_ret == 0, "Unregister trigger: %s", test_tuple_string); | |
366 | ||
367 | /* | |
368 | * Test that unregistration of a non-previously | |
369 | * registered trigger fail. | |
370 | */ | |
371 | loop_ret = lttng_unregister_trigger(trigger); | |
d9a7a1ec | 372 | ok(loop_ret == -LTTNG_ERR_TRIGGER_NOT_FOUND, "Unregister of a non-registered trigger fails as expected: %s", test_tuple_string); |
434f8068 JR |
373 | } else { |
374 | ok(loop_ret == -LTTNG_ERR_INVALID_TRIGGER, "Trigger is invalid as expected and cannot be registered: %s", test_tuple_string); | |
375 | } | |
376 | ||
377 | loop_cleanup: | |
378 | free(test_tuple_string); | |
379 | lttng_trigger_destroy(trigger); | |
380 | lttng_condition_destroy(condition); | |
381 | } | |
382 | ||
383 | end: | |
384 | lttng_action_destroy(action); | |
385 | } | |
386 | ||
ff2b03c8 JG |
387 | static |
388 | void wait_data_pending(const char *session_name) | |
389 | { | |
390 | int ret; | |
391 | ||
392 | do { | |
393 | ret = lttng_data_pending(session_name); | |
394 | assert(ret >= 0); | |
395 | } while (ret != 0); | |
396 | } | |
397 | ||
ceafd18e | 398 | static |
854382b8 | 399 | void test_notification_channel(const char *session_name, const char *channel_name, const enum lttng_domain_type domain_type, const char **argv) |
434f8068 JR |
400 | { |
401 | int ret = 0; | |
402 | enum lttng_condition_status condition_status; | |
403 | enum lttng_notification_channel_status nc_status; | |
404 | ||
405 | struct lttng_action *action = NULL; | |
406 | struct lttng_notification *notification = NULL; | |
407 | struct lttng_notification_channel *notification_channel = NULL; | |
408 | struct lttng_trigger *trigger = NULL; | |
409 | ||
410 | struct lttng_condition *low_condition = NULL; | |
411 | struct lttng_condition *high_condition = NULL; | |
412 | struct lttng_condition *dummy_invalid_condition = NULL; | |
413 | struct lttng_condition *dummy_condition = NULL; | |
414 | ||
415 | double low_ratio = 0.0; | |
416 | double high_ratio = 0.99; | |
417 | ||
418 | /* Set-up */ | |
419 | action = lttng_action_notify_create(); | |
420 | if (!action) { | |
421 | fail("Setup error on action creation"); | |
422 | goto end; | |
423 | } | |
424 | ||
425 | /* Create a dummy, empty condition for later test */ | |
426 | dummy_invalid_condition = lttng_condition_buffer_usage_low_create(); | |
427 | if (!dummy_invalid_condition) { | |
428 | fail("Setup error on condition creation"); | |
429 | goto end; | |
430 | } | |
431 | ||
432 | /* Create a valid dummy condition with a ratio of 0.5 */ | |
433 | dummy_condition = lttng_condition_buffer_usage_low_create(); | |
434 | if (!dummy_condition) { | |
435 | fail("Setup error on dummy_condition creation"); | |
436 | goto end; | |
437 | ||
438 | } | |
439 | condition_status = lttng_condition_buffer_usage_set_threshold_ratio( | |
440 | dummy_condition, 0.5); | |
441 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
442 | fail("Setup error on condition creation"); | |
443 | goto end; | |
444 | } | |
445 | ||
446 | condition_status = lttng_condition_buffer_usage_set_session_name( | |
447 | dummy_condition, session_name); | |
448 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
449 | fail("Setup error on dummy_condition creation"); | |
450 | goto end; | |
451 | } | |
452 | condition_status = lttng_condition_buffer_usage_set_channel_name( | |
453 | dummy_condition, channel_name); | |
454 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
455 | fail("Setup error on dummy_condition creation"); | |
456 | goto end; | |
457 | } | |
458 | condition_status = lttng_condition_buffer_usage_set_domain_type( | |
459 | dummy_condition, domain_type); | |
460 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
461 | fail("Setup error on dummy_condition creation"); | |
462 | goto end; | |
463 | } | |
464 | ||
465 | /* Register a low condition with a ratio */ | |
466 | low_condition = lttng_condition_buffer_usage_low_create(); | |
467 | if (!low_condition) { | |
468 | fail("Setup error on low_condition creation"); | |
469 | goto end; | |
470 | } | |
471 | condition_status = lttng_condition_buffer_usage_set_threshold_ratio( | |
472 | low_condition, low_ratio); | |
473 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
474 | fail("Setup error on low_condition creation"); | |
475 | goto end; | |
476 | } | |
477 | ||
478 | condition_status = lttng_condition_buffer_usage_set_session_name( | |
479 | low_condition, session_name); | |
480 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
481 | fail("Setup error on low_condition creation"); | |
482 | goto end; | |
483 | } | |
484 | condition_status = lttng_condition_buffer_usage_set_channel_name( | |
485 | low_condition, channel_name); | |
486 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
487 | fail("Setup error on low_condition creation"); | |
488 | goto end; | |
489 | } | |
490 | condition_status = lttng_condition_buffer_usage_set_domain_type( | |
491 | low_condition, domain_type); | |
492 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
493 | fail("Setup error on low_condition creation"); | |
494 | goto end; | |
495 | ||
496 | } | |
497 | ||
498 | /* Register a high condition with a ratio */ | |
499 | high_condition = lttng_condition_buffer_usage_high_create(); | |
500 | if (!high_condition) { | |
501 | fail("Setup error on high_condition creation"); | |
502 | goto end; | |
503 | } | |
504 | ||
505 | condition_status = lttng_condition_buffer_usage_set_threshold_ratio( | |
506 | high_condition, high_ratio); | |
507 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
508 | fail("Setup error on high_condition creation"); | |
509 | goto end; | |
510 | } | |
511 | ||
512 | condition_status = lttng_condition_buffer_usage_set_session_name( | |
513 | high_condition, session_name); | |
514 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
515 | fail("Setup error on high_condition creation"); | |
516 | goto end; | |
517 | } | |
518 | condition_status = lttng_condition_buffer_usage_set_channel_name( | |
519 | high_condition, channel_name); | |
520 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
521 | fail("Setup error on high_condition creation"); | |
522 | goto end; | |
523 | } | |
524 | condition_status = lttng_condition_buffer_usage_set_domain_type( | |
525 | high_condition, domain_type); | |
526 | if (condition_status != LTTNG_CONDITION_STATUS_OK) { | |
527 | fail("Setup error on high_condition creation"); | |
528 | goto end; | |
529 | } | |
530 | ||
531 | /* Register the triggers for low and high condition */ | |
532 | trigger = lttng_trigger_create(low_condition, action); | |
533 | if (!trigger) { | |
534 | fail("Setup error on low trigger creation"); | |
535 | goto end; | |
536 | } | |
537 | ||
538 | ret = lttng_register_trigger(trigger); | |
539 | if (ret) { | |
540 | fail("Setup error on low trigger registration"); | |
541 | goto end; | |
542 | } | |
543 | ||
544 | lttng_trigger_destroy(trigger); | |
545 | trigger = NULL; | |
546 | ||
547 | trigger = lttng_trigger_create(high_condition, action); | |
548 | if (!trigger) { | |
549 | fail("Setup error on high trigger creation"); | |
550 | goto end; | |
551 | } | |
552 | ||
553 | ret = lttng_register_trigger(trigger); | |
554 | if (ret) { | |
555 | fail("Setup error on high trigger registration"); | |
556 | goto end; | |
557 | } | |
558 | ||
559 | /* Begin testing */ | |
560 | notification_channel = lttng_notification_channel_create(lttng_session_daemon_notification_endpoint); | |
561 | ok(notification_channel, "Notification channel object creation"); | |
562 | if (!notification_channel) { | |
563 | goto end; | |
564 | } | |
565 | ||
566 | /* Basic error path check */ | |
567 | nc_status = lttng_notification_channel_subscribe(NULL, NULL); | |
568 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID, "Notification channel subscription is invalid: NULL, NULL"); | |
569 | ||
570 | nc_status = lttng_notification_channel_subscribe(notification_channel, NULL); | |
571 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID, "Notification channel subscription is invalid: NON-NULL, NULL"); | |
572 | ||
573 | nc_status = lttng_notification_channel_subscribe(NULL, low_condition); | |
574 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID, "Notification channel subscription is invalid: NULL, NON-NULL"); | |
575 | ||
576 | nc_status = lttng_notification_channel_subscribe(notification_channel, dummy_invalid_condition); | |
577 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID, "Subscribing to an invalid condition"); | |
578 | ||
579 | nc_status = lttng_notification_channel_unsubscribe(notification_channel, dummy_invalid_condition); | |
a5fcfec4 | 580 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_INVALID, "Unsubscribing from an invalid condition"); |
434f8068 JR |
581 | |
582 | nc_status = lttng_notification_channel_unsubscribe(notification_channel, dummy_condition); | |
a5fcfec4 | 583 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_UNKNOWN_CONDITION, "Unsubscribing from a valid unknown condition"); |
434f8068 JR |
584 | |
585 | /* Subscribe a valid low condition */ | |
586 | nc_status = lttng_notification_channel_subscribe(notification_channel, low_condition); | |
587 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, "Subscribe to condition"); | |
588 | ||
589 | /* Subscribe a valid high condition */ | |
590 | nc_status = lttng_notification_channel_subscribe(notification_channel, high_condition); | |
591 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, "Subscribe to condition"); | |
592 | ||
593 | nc_status = lttng_notification_channel_subscribe(notification_channel, low_condition); | |
594 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED, "Subscribe to a condition for which subscription was already done"); | |
595 | ||
596 | nc_status = lttng_notification_channel_subscribe(notification_channel, high_condition); | |
597 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_ALREADY_SUBSCRIBED, "Subscribe to a condition for which subscription was already done"); | |
598 | ||
599 | /* Wait for notification to happen */ | |
434f8068 | 600 | stop_consumer(argv); |
ff2b03c8 | 601 | lttng_start_tracing(session_name); |
434f8068 JR |
602 | |
603 | /* Wait for high notification */ | |
604 | nc_status = lttng_notification_channel_get_next_notification(notification_channel, ¬ification); | |
605 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK | |
606 | && notification | |
607 | && lttng_condition_get_type(lttng_notification_get_condition(notification)) == LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH, | |
608 | "High notification received after intermediary communication"); | |
609 | lttng_notification_destroy(notification); | |
610 | notification = NULL; | |
611 | ||
854382b8 | 612 | suspend_application(); |
ff2b03c8 | 613 | lttng_stop_tracing_no_wait(session_name); |
434f8068 | 614 | resume_consumer(argv); |
ff2b03c8 | 615 | wait_data_pending(session_name); |
434f8068 JR |
616 | |
617 | /* | |
618 | * Test that communication still work even if there is notification | |
619 | * waiting for consumption. | |
620 | */ | |
621 | ||
622 | nc_status = lttng_notification_channel_unsubscribe(notification_channel, low_condition); | |
623 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, "Unsubscribe with pending notification"); | |
624 | ||
625 | nc_status = lttng_notification_channel_subscribe(notification_channel, low_condition); | |
626 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, "subscribe with pending notification"); | |
627 | ||
628 | nc_status = lttng_notification_channel_get_next_notification(notification_channel, ¬ification); | |
629 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK | |
630 | && notification | |
631 | && lttng_condition_get_type(lttng_notification_get_condition(notification)) == LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW, | |
632 | "Low notification received after intermediary communication"); | |
633 | lttng_notification_destroy(notification); | |
634 | notification = NULL; | |
635 | ||
636 | /* Stop consumer to force a high notification */ | |
ff2b03c8 | 637 | stop_consumer(argv); |
854382b8 | 638 | resume_application(); |
434f8068 | 639 | lttng_start_tracing(session_name); |
434f8068 JR |
640 | |
641 | nc_status = lttng_notification_channel_get_next_notification(notification_channel, ¬ification); | |
642 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK && notification && | |
643 | lttng_condition_get_type(lttng_notification_get_condition(notification)) == LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH, | |
644 | "High notification received after intermediary communication"); | |
645 | lttng_notification_destroy(notification); | |
646 | notification = NULL; | |
647 | ||
854382b8 | 648 | suspend_application(); |
ff2b03c8 | 649 | lttng_stop_tracing_no_wait(session_name); |
434f8068 | 650 | resume_consumer(argv); |
ff2b03c8 | 651 | wait_data_pending(session_name); |
434f8068 JR |
652 | |
653 | nc_status = lttng_notification_channel_get_next_notification(notification_channel, ¬ification); | |
654 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK && notification && | |
655 | lttng_condition_get_type(lttng_notification_get_condition(notification)) == LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW, | |
656 | "Low notification received after re-subscription"); | |
657 | lttng_notification_destroy(notification); | |
658 | notification = NULL; | |
659 | ||
ff2b03c8 | 660 | stop_consumer(argv); |
854382b8 | 661 | resume_application(); |
434f8068 JR |
662 | /* Stop consumer to force a high notification */ |
663 | lttng_start_tracing(session_name); | |
434f8068 JR |
664 | |
665 | nc_status = lttng_notification_channel_get_next_notification(notification_channel, ¬ification); | |
666 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK && notification && | |
667 | lttng_condition_get_type(lttng_notification_get_condition(notification)) == LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH, | |
668 | "High notification"); | |
669 | lttng_notification_destroy(notification); | |
670 | notification = NULL; | |
671 | ||
672 | /* Resume consumer to allow event consumption */ | |
ff2b03c8 JG |
673 | suspend_application(); |
674 | lttng_stop_tracing_no_wait(session_name); | |
434f8068 | 675 | resume_consumer(argv); |
ff2b03c8 | 676 | wait_data_pending(session_name); |
434f8068 JR |
677 | |
678 | nc_status = lttng_notification_channel_unsubscribe(notification_channel, low_condition); | |
679 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, "Unsubscribe low condition with pending notification"); | |
680 | nc_status = lttng_notification_channel_unsubscribe(notification_channel, high_condition); | |
681 | ok(nc_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, "Unsubscribe high condition with pending notification"); | |
682 | ||
683 | end: | |
684 | lttng_notification_channel_destroy(notification_channel); | |
685 | lttng_trigger_destroy(trigger); | |
686 | lttng_action_destroy(action); | |
687 | lttng_condition_destroy(low_condition); | |
eff748d0 | 688 | lttng_condition_destroy(high_condition); |
434f8068 JR |
689 | lttng_condition_destroy(dummy_invalid_condition); |
690 | lttng_condition_destroy(dummy_condition); | |
691 | } | |
692 | ||
693 | int main(int argc, const char *argv[]) | |
694 | { | |
695 | const char *session_name = NULL; | |
696 | const char *channel_name = NULL; | |
697 | const char *domain_type_string = NULL; | |
698 | enum lttng_domain_type domain_type = LTTNG_DOMAIN_NONE; | |
699 | ||
700 | plan_tests(NUM_TESTS); | |
701 | ||
854382b8 JR |
702 | /* Argument 6 and upward are named pipe location for consumerd control */ |
703 | named_pipe_args_start = 6; | |
434f8068 | 704 | |
854382b8 | 705 | if (argc < 7) { |
434f8068 JR |
706 | fail("Missing parameter for tests to run %d", argc); |
707 | goto error; | |
708 | } | |
709 | ||
710 | nb_args = argc; | |
711 | ||
854382b8 JR |
712 | domain_type_string = argv[1]; |
713 | session_name = argv[2]; | |
714 | channel_name = argv[3]; | |
715 | app_pid = (pid_t) atoi(argv[4]); | |
716 | app_state_file = argv[5]; | |
434f8068 JR |
717 | |
718 | if (!strcmp("LTTNG_DOMAIN_UST", domain_type_string)) { | |
719 | domain_type = LTTNG_DOMAIN_UST; | |
720 | } | |
721 | if (!strcmp("LTTNG_DOMAIN_KERNEL", domain_type_string)) { | |
722 | domain_type = LTTNG_DOMAIN_KERNEL; | |
723 | } | |
724 | if (domain_type == LTTNG_DOMAIN_NONE) { | |
725 | fail("Unknown domain type"); | |
726 | goto error; | |
727 | } | |
728 | ||
729 | diag("Test trigger for domain %s with buffer_usage_low condition", domain_type_string); | |
730 | test_triggers_buffer_usage_condition(session_name, channel_name, domain_type, LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW); | |
731 | diag("Test trigger for domain %s with buffer_usage_high condition", domain_type_string); | |
732 | test_triggers_buffer_usage_condition(session_name, channel_name, domain_type, LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH); | |
733 | ||
734 | diag("Test notification channel api for domain %s", domain_type_string); | |
735 | test_notification_channel(session_name, channel_name, domain_type, argv); | |
736 | error: | |
737 | return exit_status(); | |
738 | } | |
739 |