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