4 * Lib BabelTrace - Seeks test program
6 * Copyright 2012 - Yannick Brosseau <yannick.brosseau@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; under version 2 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <babeltrace/context.h>
23 #include <babeltrace/iterator.h>
24 #include <babeltrace/ctf/iterator.h>
25 #include <babeltrace/ctf/events-internal.h>
26 #include <babeltrace/babeltrace-internal.h> /* For symbol side-effects */
31 #include <babeltrace/compat/limits.h>
38 void run_seek_begin(char *path
, uint64_t expected_begin
)
40 struct bt_context
*ctx
;
41 struct bt_ctf_iter
*iter
;
42 struct bt_ctf_event
*event
;
43 struct bt_iter_pos newpos
;
45 int64_t timestamp_begin
;
46 int64_t timestamp_seek_begin
;
49 ctx
= create_context_with_path(path
);
51 diag("Cannot create valid context");
55 /* Create iterator with null begin and end */
56 iter
= bt_ctf_iter_create(ctx
, NULL
, NULL
);
58 diag("Cannot create valid iterator");
62 event
= bt_ctf_iter_read_event(iter
);
64 ok(event
, "Event valid");
66 /* Validate that the first timestamp is right */
67 ok1(bt_ctf_get_timestamp(event
, ×tamp_begin
) == 0);
69 ok1(timestamp_begin
== expected_begin
);
71 /* Validate that we get the same value after a seek begin */
72 newpos
.type
= BT_SEEK_BEGIN
;
73 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
75 ok(ret
== 0, "Seek begin retval %d", ret
);
77 event
= bt_ctf_iter_read_event(iter
);
79 ok(event
, "Event valid");
81 ok1(bt_ctf_get_timestamp(event
, ×tamp_seek_begin
) == 0);
83 ok1(timestamp_begin
== timestamp_seek_begin
);
89 void run_seek_last(char *path
, uint64_t expected_last
)
91 struct bt_context
*ctx
;
92 struct bt_ctf_iter
*iter
;
93 struct bt_ctf_event
*event
;
94 struct bt_iter_pos newpos
;
96 int64_t timestamp_last
;
99 ctx
= create_context_with_path(path
);
101 diag("Cannot create valid context");
105 /* Create iterator with null last and end */
106 iter
= bt_ctf_iter_create(ctx
, NULL
, NULL
);
108 diag("Cannot create valid iterator");
112 event
= bt_ctf_iter_read_event(iter
);
114 ok(event
, "Event valid at beginning");
117 newpos
.type
= BT_SEEK_LAST
;
118 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
120 ok(ret
== 0, "Seek last retval %d", ret
);
122 event
= bt_ctf_iter_read_event(iter
);
124 ok(event
, "Event valid at last position");
126 ok1(bt_ctf_get_timestamp(event
, ×tamp_last
) == 0);
128 ok1(timestamp_last
== expected_last
);
130 /* Try to read next event */
131 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
133 ok(ret
== 0, "iter next should return an error");
135 event
= bt_ctf_iter_read_event(iter
);
137 ok(event
== 0, "Event after last should be invalid");
142 void run_seek_time_at_last(char *path
, uint64_t expected_last
)
144 struct bt_context
*ctx
;
145 struct bt_ctf_iter
*iter
;
146 struct bt_ctf_event
*event
;
147 struct bt_iter_pos newpos
;
149 int64_t timestamp_last
;
152 ctx
= create_context_with_path(path
);
154 diag("Cannot create valid context");
158 /* Create iterator with null last and end */
159 iter
= bt_ctf_iter_create(ctx
, NULL
, NULL
);
161 diag("Cannot create valid iterator");
165 event
= bt_ctf_iter_read_event(iter
);
167 ok(event
, "Event valid at beginning");
170 newpos
.type
= BT_SEEK_TIME
;
171 newpos
.u
.seek_time
= expected_last
;
172 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
174 ok(ret
== 0, "Seek time at last retval %d", ret
);
176 event
= bt_ctf_iter_read_event(iter
);
178 ok(event
, "Event valid at last position");
180 ok1(bt_ctf_get_timestamp(event
, ×tamp_last
) == 0);
182 ok1(timestamp_last
== expected_last
);
184 /* Try to read next event */
185 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
187 ok(ret
== 0, "iter next should return an error");
189 event
= bt_ctf_iter_read_event(iter
);
191 ok(event
== 0, "Event after last should be invalid");
196 void run_seek_cycles(char *path
,
197 uint64_t expected_begin
,
198 uint64_t expected_last
)
200 struct bt_context
*ctx
;
201 struct bt_ctf_iter
*iter
;
202 struct bt_ctf_event
*event
;
203 struct bt_iter_pos newpos
;
208 ctx
= create_context_with_path(path
);
210 diag("Cannot create valid context");
214 /* Create iterator with null last and end */
215 iter
= bt_ctf_iter_create(ctx
, NULL
, NULL
);
217 diag("Cannot create valid iterator");
221 event
= bt_ctf_iter_read_event(iter
);
223 ok(event
, "Event valid at beginning");
226 newpos
.type
= BT_SEEK_LAST
;
227 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
229 ok(ret
== 0, "Seek last retval %d", ret
);
231 event
= bt_ctf_iter_read_event(iter
);
233 ok(event
, "Event valid at last position");
235 ok1(bt_ctf_get_timestamp(event
, ×tamp
) == 0);
237 ok1(timestamp
== expected_last
);
239 /* Try to read next event */
240 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
242 ok(ret
== 0, "iter next should return an error");
244 event
= bt_ctf_iter_read_event(iter
);
246 ok(event
== 0, "Event after last should be invalid");
249 newpos
.type
= BT_SEEK_BEGIN
;
250 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
252 ok(ret
== 0, "Seek begin retval %d", ret
);
254 event
= bt_ctf_iter_read_event(iter
);
256 ok(event
, "Event valid at first position");
258 ok1(bt_ctf_get_timestamp(event
, ×tamp
) == 0);
260 ok1(timestamp
== expected_begin
);
262 /* Seek last again */
263 newpos
.type
= BT_SEEK_LAST
;
264 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
266 ok(ret
== 0, "Seek last retval %d", ret
);
268 event
= bt_ctf_iter_read_event(iter
);
270 ok(event
, "Event valid at last position");
272 ok1(bt_ctf_get_timestamp(event
, ×tamp
) == 0);
274 ok1(timestamp
== expected_last
);
279 int main(int argc
, char **argv
)
282 uint64_t expected_begin
;
283 uint64_t expected_last
;
286 * Side-effects ensuring libs are not optimized away by static
289 babeltrace_debug
= 0; /* libbabeltrace.la */
290 opt_clock_offset
= 0; /* libbabeltrace-ctf.la */
292 plan_tests(NR_TESTS
);
295 diag("Invalid arguments: need a trace path and the start and last timestamp");
299 /* Parse arguments (Trace, begin timestamp) */
302 expected_begin
= strtoull(argv
[2], NULL
, 0);
303 if (ULLONG_MAX
== expected_begin
&& errno
== ERANGE
) {
304 diag("Invalid value for begin timestamp");
308 expected_last
= strtoull(argv
[3], NULL
, 0);
309 if (ULLONG_MAX
== expected_last
&& errno
== ERANGE
) {
310 diag("Invalid value for last timestamp");
314 run_seek_begin(path
, expected_begin
);
315 run_seek_time_at_last(path
, expected_last
);
316 run_seek_last(path
, expected_last
);
317 run_seek_cycles(path
, expected_begin
, expected_last
);
319 return exit_status();
This page took 0.035228 seconds and 4 git commands to generate.