Test: session rotation schedule API
[lttng-tools.git] / tests / regression / tools / rotation / schedule_api.c
... / ...
CommitLineData
1/*
2 * schedule_api.c
3 *
4 * Unit tests for the session rotation schedule API
5 *
6 * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@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 <stddef.h>
28#include <stdbool.h>
29#include <tap/tap.h>
30
31#include <lttng/lttng.h>
32
33#define NUM_TESTS 26
34
35#define SIZE_THRESHOLD_BYTES 1024
36#define PERIODIC_TIME_US 1000000
37
38const char *session_name;
39
40bool schedules_equal(const struct lttng_rotation_schedule *a,
41 const struct lttng_rotation_schedule *b)
42{
43 bool equal = false;
44 enum lttng_rotation_schedule_type a_type, b_type;
45 uint64_t a_value, b_value;
46 enum lttng_rotation_status status;
47
48 a_type = lttng_rotation_schedule_get_type(a);
49 b_type = lttng_rotation_schedule_get_type(b);
50 if (a_type != b_type) {
51 diag("Schedules are not of the same type (%i != %i)",
52 a_type, b_type);
53 goto end;
54 }
55
56 switch (a_type) {
57 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD:
58 {
59 status = lttng_rotation_schedule_size_threshold_get_threshold(a,
60 &a_value);
61 if (status != LTTNG_ROTATION_STATUS_OK) {
62 diag("Failed to retrieve size threshold of schedule 'a'");
63 goto end;
64 }
65 status = lttng_rotation_schedule_size_threshold_get_threshold(b,
66 &b_value);
67 if (status != LTTNG_ROTATION_STATUS_OK) {
68 diag("Failed to retrieve size threshold of schedule 'b'");
69 goto end;
70 }
71 break;
72 }
73 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC:
74 {
75 status = lttng_rotation_schedule_periodic_get_period(a,
76 &a_value);
77 if (status != LTTNG_ROTATION_STATUS_OK) {
78 diag("Failed to retrieve period of schedule 'a'");
79 goto end;
80 }
81 status = lttng_rotation_schedule_periodic_get_period(b,
82 &b_value);
83 if (status != LTTNG_ROTATION_STATUS_OK) {
84 diag("Failed to retrieve period of schedule 'b'");
85 goto end;
86 }
87 break;
88 }
89 default:
90 diag("Unexpected schedule type: %i", a_type);
91 goto end;
92 }
93
94 equal = a_value == b_value;
95 if (!equal) {
96 diag("Schedules have different values");
97 }
98end:
99 return equal;
100}
101
102void test_add_null_session(void)
103{
104 enum lttng_rotation_status status;
105 struct lttng_rotation_schedule *size_schedule = NULL;
106
107 size_schedule = lttng_rotation_schedule_size_threshold_create();
108
109 status = lttng_session_add_rotation_schedule(NULL, size_schedule);
110 ok(status == LTTNG_ROTATION_STATUS_INVALID,
111 "NULL session name rejected by lttng_session_add_rotation_schedule()");
112}
113
114void test_add_null_schedule(void)
115{
116 enum lttng_rotation_status status;
117
118 status = lttng_session_add_rotation_schedule(session_name, NULL);
119 ok(status == LTTNG_ROTATION_STATUS_INVALID,
120 "NULL schedule rejected by lttng_session_add_rotation_schedule()");
121}
122
123void test_add_uninitialized_schedule(void)
124{
125 enum lttng_rotation_status status;
126 struct lttng_rotation_schedule *size_schedule = NULL,
127 *periodic_schedule = NULL;
128
129 size_schedule = lttng_rotation_schedule_size_threshold_create();
130 ok(size_schedule, "Created a size threshold session rotation schedule");
131
132 status = lttng_session_add_rotation_schedule(session_name,
133 size_schedule);
134 ok(status == LTTNG_ROTATION_STATUS_INVALID,
135 "Uninitialized size schedule rejected by lttng_session_add_rotation_schedule()");
136
137 periodic_schedule = lttng_rotation_schedule_periodic_create();
138 ok(periodic_schedule, "Created a periodic session rotation schedule");
139
140 status = lttng_session_add_rotation_schedule(session_name,
141 periodic_schedule);
142 ok(status == LTTNG_ROTATION_STATUS_INVALID,
143 "Uninitialized periodic schedule rejected by lttng_session_add_rotation_schedule()");
144
145 lttng_rotation_schedule_destroy(size_schedule);
146 lttng_rotation_schedule_destroy(periodic_schedule);
147}
148
149void test_remove_null_session(void)
150{
151 enum lttng_rotation_status status;
152 struct lttng_rotation_schedule *size_schedule = NULL;
153
154 size_schedule = lttng_rotation_schedule_size_threshold_create();
155
156 status = lttng_session_remove_rotation_schedule(NULL, size_schedule);
157 ok(status == LTTNG_ROTATION_STATUS_INVALID,
158 "NULL session name rejected by lttng_session_remove_rotation_schedule()");
159}
160
161void test_remove_null_schedule(void)
162{
163 enum lttng_rotation_status status;
164
165 status = lttng_session_remove_rotation_schedule(session_name, NULL);
166 ok(status == LTTNG_ROTATION_STATUS_INVALID,
167 "NULL schedule rejected by lttng_session_remove_rotation_schedule()");
168}
169
170void test_remove_uninitialized_schedule(void)
171{
172 enum lttng_rotation_status status;
173 struct lttng_rotation_schedule *size_schedule = NULL,
174 *periodic_schedule = NULL;
175
176 size_schedule = lttng_rotation_schedule_size_threshold_create();
177 status = lttng_session_remove_rotation_schedule(session_name,
178 size_schedule);
179 ok(status == LTTNG_ROTATION_STATUS_INVALID,
180 "Uninitialized size schedule rejected by lttng_session_remove_rotation_schedule()");
181
182 periodic_schedule = lttng_rotation_schedule_periodic_create();
183 status = lttng_session_remove_rotation_schedule(session_name,
184 periodic_schedule);
185 ok(status == LTTNG_ROTATION_STATUS_INVALID,
186 "Uninitialized periodic schedule rejected by lttng_session_remove_rotation_schedule()");
187
188 lttng_rotation_schedule_destroy(size_schedule);
189 lttng_rotation_schedule_destroy(periodic_schedule);
190}
191
192void test_uninitialized_schedule_get(void)
193{
194 uint64_t value;
195 enum lttng_rotation_status status;
196 struct lttng_rotation_schedule *size_schedule = NULL,
197 *periodic_schedule = NULL;
198
199 size_schedule = lttng_rotation_schedule_size_threshold_create();
200 periodic_schedule = lttng_rotation_schedule_periodic_create();
201
202 status = lttng_rotation_schedule_size_threshold_get_threshold(
203 size_schedule, &value);
204 ok(status == LTTNG_ROTATION_STATUS_UNAVAILABLE,
205 "Getter on size threshold rotation schedule returns LTTNG_ROTATION_STATUS_UNAVAILABLE by default");
206 status = lttng_rotation_schedule_periodic_get_period(periodic_schedule,
207 &value);
208 ok(status == LTTNG_ROTATION_STATUS_UNAVAILABLE,
209 "Getter on periodic rotation schedule returns LTTNG_ROTATION_STATUS_UNAVAILABLE by default");
210
211 lttng_rotation_schedule_destroy(size_schedule);
212 lttng_rotation_schedule_destroy(periodic_schedule);
213
214}
215
216void test_add_list_remove_schedule(
217 const struct lttng_rotation_schedule *original_schedule)
218{
219 int ret;
220 unsigned int schedules_count = 0;
221 enum lttng_rotation_status status;
222 const struct lttng_rotation_schedule *list_schedule;
223 struct lttng_rotation_schedules *list_schedules;
224
225 status = lttng_session_add_rotation_schedule(session_name,
226 original_schedule);
227 ok(status == LTTNG_ROTATION_STATUS_OK,
228 "Add a rotation schedule to session \'%s\'",
229 session_name);
230
231 ret = lttng_session_list_rotation_schedules(session_name,
232 &list_schedules);
233 ok(ret == LTTNG_OK && list_schedules,
234 "List rotation schedules of session \'%s\'",
235 session_name);
236
237 status = lttng_rotation_schedules_get_count(list_schedules,
238 &schedules_count);
239 ok(status == LTTNG_ROTATION_STATUS_OK && schedules_count == 1,
240 "Listing returned 1 rotation schedule");
241
242 list_schedule = lttng_rotation_schedules_get_at_index(list_schedules,
243 0);
244 ok(list_schedule,
245 "Obtain the first schedule of a schedules list");
246
247 ok(schedules_equal(original_schedule, list_schedule),
248 "Schedule returned by the listing is equal to the reference schedule that was added");
249
250 status = lttng_session_remove_rotation_schedule(session_name,
251 list_schedule);
252 ok(status == LTTNG_ROTATION_STATUS_OK,
253 "Remove rotation schedule returned by the schedules listing");
254 lttng_rotation_schedules_destroy(list_schedules);
255
256 (void) lttng_session_list_rotation_schedules(session_name,
257 &list_schedules);
258 status = lttng_rotation_schedules_get_count(list_schedules,
259 &schedules_count);
260 ok(status == LTTNG_ROTATION_STATUS_OK && schedules_count == 0,
261 "Listing returned 0 rotation schedules after removal");
262
263}
264
265void test_add_list_remove_size_schedule(void)
266{
267 struct lttng_rotation_schedule *size_schedule;
268
269 diag("Add, list, and remove a size threshold rotation schedule");
270 size_schedule = lttng_rotation_schedule_size_threshold_create();
271 (void) lttng_rotation_schedule_size_threshold_set_threshold(
272 size_schedule, SIZE_THRESHOLD_BYTES);
273 test_add_list_remove_schedule(size_schedule);
274 lttng_rotation_schedule_destroy(size_schedule);
275}
276
277void test_add_list_remove_periodic_schedule(void)
278{
279 struct lttng_rotation_schedule *periodic_schedule;
280
281 diag("Add, list, and remove a periodic rotation schedule");
282 periodic_schedule = lttng_rotation_schedule_periodic_create();
283 (void) lttng_rotation_schedule_periodic_set_period(
284 periodic_schedule, PERIODIC_TIME_US);
285 test_add_list_remove_schedule(periodic_schedule);
286 lttng_rotation_schedule_destroy(periodic_schedule);
287}
288
289int main(int argc, char **argv)
290{
291 plan_tests(NUM_TESTS);
292
293 if (argc < 2) {
294 diag("Usage: schedule_api SESSION_NAME");
295 goto end;
296 }
297
298 session_name = argv[1];
299
300 diag("Argument validation");
301 test_add_null_session();
302 test_add_null_schedule();
303 test_add_uninitialized_schedule();
304 test_remove_null_session();
305 test_remove_null_schedule();
306 test_remove_uninitialized_schedule();
307 test_uninitialized_schedule_get();
308
309 test_add_list_remove_size_schedule();
310 test_add_list_remove_periodic_schedule();
311end:
312 return exit_status();
313}
This page took 0.024249 seconds and 5 git commands to generate.