Prepare for '-Wmissing-field-initializers'
[lttng-tools.git] / tests / regression / tools / trigger / hidden / hidden_trigger.cpp
CommitLineData
1cc00241
JG
1/*
2 * trigger_name.c
3 *
4 * Test that hidden triggers are not visible to liblttng-ctl.
5 *
6 * Copyright (C) 2021 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * SPDX-License-Identifier: MIT
9 *
10 */
11
1cc00241
JG
12#include <stdint.h>
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16#include <unistd.h>
17
18#include <tap/tap.h>
19
20#include <common/macros.h>
21#include <lttng/lttng.h>
22
23#define TEST_COUNT 1
24
25#define TEST_SESSION_NAME "test_session"
26#define TEST_CHANNEL_NAME "test_channel"
27
28static
29int get_registered_triggers_count(void)
30{
31 int ret;
32 enum lttng_error_code ret_code;
33 enum lttng_trigger_status trigger_status;
34 struct lttng_triggers *triggers = NULL;
35 unsigned int trigger_count;
36
37 ret_code = lttng_list_triggers(&triggers);
38 if (ret_code != LTTNG_OK) {
39 fail("Failed to list triggers");
40 ret = -1;
41 goto end;
42 }
43
44 trigger_status = lttng_triggers_get_count(triggers, &trigger_count);
45 if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
46 fail("Failed to get count of triggers returned by listing");
47 ret = -1;
48 goto end;
49 }
50
51 ret = (int) trigger_count;
52
53end:
54 lttng_triggers_destroy(triggers);
55 return ret;
56}
57
58static
59int setup_session_with_size_rotation_schedule(const char *session_output_path)
60{
61 int ret;
62 struct lttng_session_descriptor *session_desriptor = NULL;
63 enum lttng_error_code ret_code;
64 struct lttng_handle ust_channel_handle = {
729c1fec
SM
65 TEST_SESSION_NAME,
66 {
67 .type = LTTNG_DOMAIN_UST,
68 .buf_type = LTTNG_BUFFER_PER_UID,
1c9a0b0e
MJ
69 .padding = {},
70 .attr = {},
71 },
72 {}
1cc00241 73 };
729c1fec
SM
74
75 lttng_channel channel_cfg {};
76 strcpy(channel_cfg.name, TEST_CHANNEL_NAME);
77 channel_cfg.enabled = 1;
78 channel_cfg.attr.overwrite = -1;
79 channel_cfg.attr.subbuf_size = (uint64_t) sysconf(_SC_PAGE_SIZE) * 8;
80 channel_cfg.attr.num_subbuf = 8;
81 channel_cfg.attr.output = LTTNG_EVENT_MMAP;
82
1cc00241
JG
83 enum lttng_rotation_status rotation_status;
84 struct lttng_rotation_schedule *rotation_schedule = NULL;
85
86 session_desriptor = lttng_session_descriptor_local_create(
87 TEST_SESSION_NAME, session_output_path);
88 if (!session_desriptor) {
89 fail("Failed to create session descriptor for session `%s`",
90 TEST_SESSION_NAME);
91 ret = -1;
92 goto end;
93 }
94
95 ret_code = lttng_create_session_ext(session_desriptor);
96 if (ret_code != LTTNG_OK) {
97 fail("Failed to create session `%s`: %s", TEST_SESSION_NAME,
98 lttng_strerror(-ret_code));
99 ret = -1;
100 goto end;
101 }
102
103 ret = lttng_enable_channel(&ust_channel_handle, &channel_cfg);
104 if (ret) {
105 fail("Failed to enable channel `%s`: %s", TEST_CHANNEL_NAME,
106 lttng_strerror(ret));
107 ret = -1;
108 goto end;
109 }
110
111 ret = lttng_start_tracing(TEST_SESSION_NAME);
112 if (ret) {
113 fail("Failed to start session `%s`: %s", TEST_SESSION_NAME,
114 lttng_strerror(ret));
115 ret = -1;
116 goto end;
117 }
118
119 rotation_schedule = lttng_rotation_schedule_size_threshold_create();
120 if (!rotation_schedule) {
121 fail("Failed to create rotation schedule descriptor");
122 ret = -1;
123 goto end;
124 }
125
126 /*
127 * The rotation schedule size threshold doesn't matter; no event rules
128 * were specified so the session consumed size should not grow over
129 * time.
130 */
131 rotation_status = lttng_rotation_schedule_size_threshold_set_threshold(
81663f07 132 rotation_schedule, sysconf(_SC_PAGE_SIZE) * 4096);
1cc00241
JG
133 if (rotation_status != LTTNG_ROTATION_STATUS_OK) {
134 fail("Failed to set size threshold of session rotation schedule");
135 ret = -1;
136 goto end;
137 }
138
139 rotation_status = lttng_session_add_rotation_schedule(
140 TEST_SESSION_NAME, rotation_schedule);
141 if (rotation_status != LTTNG_ROTATION_STATUS_OK) {
142 fail("Failed to set size-based rotation schedule on session `%s`",
143 TEST_SESSION_NAME);
144 ret = -1;
145 goto end;
146 }
147
148 ret = 0;
149end:
150 lttng_session_descriptor_destroy(session_desriptor);
151 lttng_rotation_schedule_destroy(rotation_schedule);
152 return ret;
153}
154
155int main(int argc, const char **argv)
156{
157 int ret;
158
159 if (argc != 2) {
160 fail("Missing trace path");
161 goto end;
162 }
163
164 plan_tests(TEST_COUNT);
165
166 if (get_registered_triggers_count() != 0) {
167 fail("Session daemon already has registered triggers, bailing out");
168 goto end;
169 }
170
171 ret = setup_session_with_size_rotation_schedule(argv[1]);
172 if (ret) {
173 goto end;
174 }
175
176 ok(get_registered_triggers_count() == 0,
177 "No triggers visible while session has an enabled size-based rotation schedule");
178
179 ret = lttng_destroy_session(TEST_SESSION_NAME);
180 if (ret) {
181 fail("Failed to destroy session `%s`", TEST_SESSION_NAME);
182 goto end;
183 }
184end:
185 return exit_status();
186}
This page took 0.032207 seconds and 4 git commands to generate.