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.h>
26 #include <babeltrace/babeltrace-internal.h> /* For symbol side-effects */
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 uint64_t timestamp_begin
;
46 uint64_t timestamp_seek_begin
;
49 ctx
= create_context_with_path(path
);
51 plan_skip_all("Cannot create valid context");
54 /* Create iterator with null begin and end */
55 iter
= bt_ctf_iter_create(ctx
, NULL
, NULL
);
57 plan_skip_all("Cannot create valid iterator");
60 event
= bt_ctf_iter_read_event(iter
);
62 ok(event
, "Event valid");
64 /* Validate that the first timestamp is right */
65 timestamp_begin
= bt_ctf_get_timestamp(event
);
67 ok1(timestamp_begin
== expected_begin
);
69 /* Validate that we get the same value after a seek begin */
70 newpos
.type
= BT_SEEK_BEGIN
;
71 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
73 ok(ret
== 0, "Seek begin retval %d", ret
);
75 event
= bt_ctf_iter_read_event(iter
);
77 ok(event
, "Event valid");
79 timestamp_seek_begin
= bt_ctf_get_timestamp(event
);
81 ok1(timestamp_begin
== timestamp_seek_begin
);
87 void run_seek_last(char *path
, uint64_t expected_last
)
89 struct bt_context
*ctx
;
90 struct bt_ctf_iter
*iter
;
91 struct bt_ctf_event
*event
;
92 struct bt_iter_pos newpos
;
94 uint64_t timestamp_last
;
97 ctx
= create_context_with_path(path
);
99 plan_skip_all("Cannot create valid context");
102 /* Create iterator with null last and end */
103 iter
= bt_ctf_iter_create(ctx
, NULL
, NULL
);
105 plan_skip_all("Cannot create valid iterator");
108 event
= bt_ctf_iter_read_event(iter
);
110 ok(event
, "Event valid at beginning");
113 newpos
.type
= BT_SEEK_LAST
;
114 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
116 ok(ret
== 0, "Seek last retval %d", ret
);
118 event
= bt_ctf_iter_read_event(iter
);
120 ok(event
, "Event valid at last position");
122 timestamp_last
= bt_ctf_get_timestamp(event
);
124 ok1(timestamp_last
== expected_last
);
126 /* Try to read next event */
127 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
129 ok(ret
== 0, "iter next should return an error");
131 event
= bt_ctf_iter_read_event(iter
);
133 ok(event
== 0, "Event after last should be invalid");
138 void run_seek_time_at_last(char *path
, uint64_t expected_last
)
140 struct bt_context
*ctx
;
141 struct bt_ctf_iter
*iter
;
142 struct bt_ctf_event
*event
;
143 struct bt_iter_pos newpos
;
145 uint64_t timestamp_last
;
148 ctx
= create_context_with_path(path
);
150 plan_skip_all("Cannot create valid context");
153 /* Create iterator with null last and end */
154 iter
= bt_ctf_iter_create(ctx
, NULL
, NULL
);
156 plan_skip_all("Cannot create valid iterator");
159 event
= bt_ctf_iter_read_event(iter
);
161 ok(event
, "Event valid at beginning");
164 newpos
.type
= BT_SEEK_TIME
;
165 newpos
.u
.seek_time
= expected_last
;
166 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
168 ok(ret
== 0, "Seek time at last retval %d", ret
);
170 event
= bt_ctf_iter_read_event(iter
);
172 ok(event
, "Event valid at last position");
174 timestamp_last
= bt_ctf_get_timestamp(event
);
176 ok1(timestamp_last
== expected_last
);
178 /* Try to read next event */
179 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
181 ok(ret
== 0, "iter next should return an error");
183 event
= bt_ctf_iter_read_event(iter
);
185 ok(event
== 0, "Event after last should be invalid");
190 void run_seek_cycles(char *path
,
191 uint64_t expected_begin
,
192 uint64_t expected_last
)
194 struct bt_context
*ctx
;
195 struct bt_ctf_iter
*iter
;
196 struct bt_ctf_event
*event
;
197 struct bt_iter_pos newpos
;
202 ctx
= create_context_with_path(path
);
204 plan_skip_all("Cannot create valid context");
207 /* Create iterator with null last and end */
208 iter
= bt_ctf_iter_create(ctx
, NULL
, NULL
);
210 plan_skip_all("Cannot create valid iterator");
213 event
= bt_ctf_iter_read_event(iter
);
215 ok(event
, "Event valid at beginning");
218 newpos
.type
= BT_SEEK_LAST
;
219 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
221 ok(ret
== 0, "Seek last retval %d", ret
);
223 event
= bt_ctf_iter_read_event(iter
);
225 ok(event
, "Event valid at last position");
227 timestamp
= bt_ctf_get_timestamp(event
);
229 ok1(timestamp
== expected_last
);
231 /* Try to read next event */
232 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
234 ok(ret
== 0, "iter next should return an error");
236 event
= bt_ctf_iter_read_event(iter
);
238 ok(event
== 0, "Event after last should be invalid");
241 newpos
.type
= BT_SEEK_BEGIN
;
242 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
244 ok(ret
== 0, "Seek begin retval %d", ret
);
246 event
= bt_ctf_iter_read_event(iter
);
248 ok(event
, "Event valid at first position");
250 timestamp
= bt_ctf_get_timestamp(event
);
252 ok1(timestamp
== expected_begin
);
254 /* Seek last again */
255 newpos
.type
= BT_SEEK_LAST
;
256 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
258 ok(ret
== 0, "Seek last retval %d", ret
);
260 event
= bt_ctf_iter_read_event(iter
);
262 ok(event
, "Event valid at last position");
264 timestamp
= bt_ctf_get_timestamp(event
);
266 ok1(timestamp
== expected_last
);
271 int main(int argc
, char **argv
)
274 uint64_t expected_begin
;
275 uint64_t expected_last
;
278 * Side-effects ensuring libs are not optimized away by static
281 babeltrace_debug
= 0; /* libbabeltrace.la */
282 opt_clock_offset
= 0; /* libbabeltrace-ctf.la */
284 plan_tests(NR_TESTS
);
287 plan_skip_all("Invalid arguments: need a trace path and the start and last timestamp");
291 /* Parse arguments (Trace, begin timestamp) */
294 expected_begin
= strtoull(argv
[2], NULL
, 0);
295 if (ULLONG_MAX
== expected_begin
&& errno
== ERANGE
) {
296 plan_skip_all("Invalid value for begin timestamp");
299 expected_last
= strtoull(argv
[3], NULL
, 0);
300 if (ULLONG_MAX
== expected_last
&& errno
== ERANGE
) {
301 plan_skip_all("Invalid value for last timestamp");
304 run_seek_begin(path
, expected_begin
);
305 run_seek_time_at_last(path
, expected_last
);
306 run_seek_last(path
, expected_last
);
307 run_seek_cycles(path
, expected_begin
, expected_last
);
309 return exit_status();
This page took 0.037448 seconds and 4 git commands to generate.