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