Commit | Line | Data |
---|---|---|
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 | ||
28 | static | |
29 | int 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 | ||
53 | end: | |
54 | lttng_triggers_destroy(triggers); | |
55 | return ret; | |
56 | } | |
57 | ||
58 | static | |
59 | int 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, | |
69 | } | |
1cc00241 | 70 | }; |
729c1fec SM |
71 | |
72 | lttng_channel channel_cfg {}; | |
73 | strcpy(channel_cfg.name, TEST_CHANNEL_NAME); | |
74 | channel_cfg.enabled = 1; | |
75 | channel_cfg.attr.overwrite = -1; | |
76 | channel_cfg.attr.subbuf_size = (uint64_t) sysconf(_SC_PAGE_SIZE) * 8; | |
77 | channel_cfg.attr.num_subbuf = 8; | |
78 | channel_cfg.attr.output = LTTNG_EVENT_MMAP; | |
79 | ||
1cc00241 JG |
80 | enum lttng_rotation_status rotation_status; |
81 | struct lttng_rotation_schedule *rotation_schedule = NULL; | |
82 | ||
83 | session_desriptor = lttng_session_descriptor_local_create( | |
84 | TEST_SESSION_NAME, session_output_path); | |
85 | if (!session_desriptor) { | |
86 | fail("Failed to create session descriptor for session `%s`", | |
87 | TEST_SESSION_NAME); | |
88 | ret = -1; | |
89 | goto end; | |
90 | } | |
91 | ||
92 | ret_code = lttng_create_session_ext(session_desriptor); | |
93 | if (ret_code != LTTNG_OK) { | |
94 | fail("Failed to create session `%s`: %s", TEST_SESSION_NAME, | |
95 | lttng_strerror(-ret_code)); | |
96 | ret = -1; | |
97 | goto end; | |
98 | } | |
99 | ||
100 | ret = lttng_enable_channel(&ust_channel_handle, &channel_cfg); | |
101 | if (ret) { | |
102 | fail("Failed to enable channel `%s`: %s", TEST_CHANNEL_NAME, | |
103 | lttng_strerror(ret)); | |
104 | ret = -1; | |
105 | goto end; | |
106 | } | |
107 | ||
108 | ret = lttng_start_tracing(TEST_SESSION_NAME); | |
109 | if (ret) { | |
110 | fail("Failed to start session `%s`: %s", TEST_SESSION_NAME, | |
111 | lttng_strerror(ret)); | |
112 | ret = -1; | |
113 | goto end; | |
114 | } | |
115 | ||
116 | rotation_schedule = lttng_rotation_schedule_size_threshold_create(); | |
117 | if (!rotation_schedule) { | |
118 | fail("Failed to create rotation schedule descriptor"); | |
119 | ret = -1; | |
120 | goto end; | |
121 | } | |
122 | ||
123 | /* | |
124 | * The rotation schedule size threshold doesn't matter; no event rules | |
125 | * were specified so the session consumed size should not grow over | |
126 | * time. | |
127 | */ | |
128 | rotation_status = lttng_rotation_schedule_size_threshold_set_threshold( | |
81663f07 | 129 | rotation_schedule, sysconf(_SC_PAGE_SIZE) * 4096); |
1cc00241 JG |
130 | if (rotation_status != LTTNG_ROTATION_STATUS_OK) { |
131 | fail("Failed to set size threshold of session rotation schedule"); | |
132 | ret = -1; | |
133 | goto end; | |
134 | } | |
135 | ||
136 | rotation_status = lttng_session_add_rotation_schedule( | |
137 | TEST_SESSION_NAME, rotation_schedule); | |
138 | if (rotation_status != LTTNG_ROTATION_STATUS_OK) { | |
139 | fail("Failed to set size-based rotation schedule on session `%s`", | |
140 | TEST_SESSION_NAME); | |
141 | ret = -1; | |
142 | goto end; | |
143 | } | |
144 | ||
145 | ret = 0; | |
146 | end: | |
147 | lttng_session_descriptor_destroy(session_desriptor); | |
148 | lttng_rotation_schedule_destroy(rotation_schedule); | |
149 | return ret; | |
150 | } | |
151 | ||
152 | int main(int argc, const char **argv) | |
153 | { | |
154 | int ret; | |
155 | ||
156 | if (argc != 2) { | |
157 | fail("Missing trace path"); | |
158 | goto end; | |
159 | } | |
160 | ||
161 | plan_tests(TEST_COUNT); | |
162 | ||
163 | if (get_registered_triggers_count() != 0) { | |
164 | fail("Session daemon already has registered triggers, bailing out"); | |
165 | goto end; | |
166 | } | |
167 | ||
168 | ret = setup_session_with_size_rotation_schedule(argv[1]); | |
169 | if (ret) { | |
170 | goto end; | |
171 | } | |
172 | ||
173 | ok(get_registered_triggers_count() == 0, | |
174 | "No triggers visible while session has an enabled size-based rotation schedule"); | |
175 | ||
176 | ret = lttng_destroy_session(TEST_SESSION_NAME); | |
177 | if (ret) { | |
178 | fail("Failed to destroy session `%s`", TEST_SESSION_NAME); | |
179 | goto end; | |
180 | } | |
181 | end: | |
182 | return exit_status(); | |
183 | } |