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