Force usage of assert() condition when NDEBUG is defined
[lttng-tools.git] / tests / regression / tools / notification / sessiond_testpoints.c
CommitLineData
38eb8a68
FD
1/*
2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9#include <common/compat/getenv.h>
10#include <common/consumer/consumer.h>
11#include <common/pipe.h>
12#include <common/error.h>
13#include <unistd.h>
14#include <stdbool.h>
15#include <lttng/constant.h>
16#include <fcntl.h>
17#include <dlfcn.h>
38eb8a68
FD
18#include <stdio.h>
19
20static char *pause_pipe_path;
21static struct lttng_pipe *pause_pipe;
22static int *notifier_notif_consumption_state;;
23
24int lttng_opt_verbose;
25int lttng_opt_mi;
26int lttng_opt_quiet;
27
28static
29void __attribute__((destructor)) pause_pipe_fini(void)
30{
31 int ret;
32
33 if (pause_pipe_path) {
34 ret = unlink(pause_pipe_path);
35 if (ret) {
36 PERROR("Failed to unlink pause pipe: path = %s",
37 pause_pipe_path);
38 }
39 }
40
41 free(pause_pipe_path);
42 lttng_pipe_destroy(pause_pipe);
43}
44
45int __testpoint_sessiond_thread_notification(void);
46int __testpoint_sessiond_thread_notification(void)
47{
48 int ret = 0;
49 const char *pause_pipe_path_prefix;
50
51 pause_pipe_path_prefix = lttng_secure_getenv(
52 "NOTIFIER_PAUSE_PIPE_PATH");
53 if (!pause_pipe_path_prefix) {
54 ret = -1;
55 goto end;
56 }
57
58 notifier_notif_consumption_state = dlsym(NULL, "notifier_consumption_paused");
a0377dfe 59 LTTNG_ASSERT(notifier_notif_consumption_state);
38eb8a68
FD
60
61 ret = asprintf(&pause_pipe_path, "%s", pause_pipe_path_prefix);
62 if (ret < 1) {
63 ERR("Failed to allocate pause pipe path");
64 goto end;
65 }
66
67 DBG("Creating pause pipe at %s", pause_pipe_path);
68 pause_pipe = lttng_pipe_named_open(pause_pipe_path,
69 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, O_NONBLOCK);
70 if (!pause_pipe) {
71 ERR("Failed to create pause pipe at %s", pause_pipe_path);
72 ret = -1;
73 goto end;
74 }
75
76 /* Only the read end of the pipe is useful to us. */
77 ret = lttng_pipe_write_close(pause_pipe);
78end:
79 return ret;
80}
81
82int __testpoint_sessiond_handle_notifier_event_pipe(void);
83int __testpoint_sessiond_handle_notifier_event_pipe(void)
84{
85 int ret = 0;
86 uint8_t value;
87 bool value_read = false;
88
89 if (!pause_pipe) {
90 ret = -1;
91 goto end;
92 }
93
94 /* Purge pipe and only consider the freshest value. */
95 do {
96 ret = lttng_pipe_read(pause_pipe, &value, sizeof(value));
97 if (ret == sizeof(value)) {
98 value_read = true;
99 }
100 } while (ret == sizeof(value));
101
102 ret = (errno == EAGAIN) ? 0 : -errno;
103
104 if (value_read) {
105 *notifier_notif_consumption_state = !!value;
106 DBG("Message received on pause pipe: %s data consumption",
107 *notifier_notif_consumption_state ? "paused" : "resumed");
108 }
109end:
110 return ret;
111}
This page took 0.027065 seconds and 4 git commands to generate.