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>
37 void run_seek_begin(char *path
, uint64_t expected_begin
)
39 struct bt_context
*ctx
;
40 struct bt_ctf_iter
*iter
;
41 struct bt_ctf_event
*event
;
42 struct bt_iter_pos newpos
;
44 uint64_t timestamp_begin
;
45 uint64_t timestamp_seek_begin
;
48 ctx
= create_context_with_path(path
);
50 plan_skip_all("Cannot create valid context");
53 /* Create iterator with null begin and end */
54 iter
= bt_ctf_iter_create(ctx
, NULL
, NULL
);
56 plan_skip_all("Cannot create valid iterator");
59 event
= bt_ctf_iter_read_event(iter
);
61 ok(event
, "Event valid");
63 /* Validate that the first timestamp is right */
64 timestamp_begin
= bt_ctf_get_timestamp(event
);
66 ok1(timestamp_begin
== expected_begin
);
68 /* Validate that we get the same value after a seek begin */
69 newpos
.type
= BT_SEEK_BEGIN
;
70 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
72 ok(ret
== 0, "Seek begin retval %d", ret
);
74 event
= bt_ctf_iter_read_event(iter
);
76 ok(event
, "Event valid");
78 timestamp_seek_begin
= bt_ctf_get_timestamp(event
);
80 ok1(timestamp_begin
== timestamp_seek_begin
);
86 void run_seek_last(char *path
, uint64_t expected_last
)
88 struct bt_context
*ctx
;
89 struct bt_ctf_iter
*iter
;
90 struct bt_ctf_event
*event
;
91 struct bt_iter_pos newpos
;
93 uint64_t timestamp_last
;
96 ctx
= create_context_with_path(path
);
98 plan_skip_all("Cannot create valid context");
101 /* Create iterator with null last and end */
102 iter
= bt_ctf_iter_create(ctx
, NULL
, NULL
);
104 plan_skip_all("Cannot create valid iterator");
107 event
= bt_ctf_iter_read_event(iter
);
109 ok(event
, "Event valid at beginning");
112 newpos
.type
= BT_SEEK_LAST
;
113 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
115 ok(ret
== 0, "Seek last retval %d", ret
);
117 event
= bt_ctf_iter_read_event(iter
);
119 ok(event
, "Event valid at last position");
121 timestamp_last
= bt_ctf_get_timestamp(event
);
123 ok1(timestamp_last
== expected_last
);
125 /* Try to read next event */
126 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
128 ok(ret
== 0, "iter next should return an error");
130 event
= bt_ctf_iter_read_event(iter
);
132 ok(event
== 0, "Event after last should be invalid");
137 void run_seek_time_at_last(char *path
, uint64_t expected_last
)
139 struct bt_context
*ctx
;
140 struct bt_ctf_iter
*iter
;
141 struct bt_ctf_event
*event
;
142 struct bt_iter_pos newpos
;
144 uint64_t timestamp_last
;
147 ctx
= create_context_with_path(path
);
149 plan_skip_all("Cannot create valid context");
152 /* Create iterator with null last and end */
153 iter
= bt_ctf_iter_create(ctx
, NULL
, NULL
);
155 plan_skip_all("Cannot create valid iterator");
158 event
= bt_ctf_iter_read_event(iter
);
160 ok(event
, "Event valid at beginning");
163 newpos
.type
= BT_SEEK_TIME
;
164 newpos
.u
.seek_time
= expected_last
;
165 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
167 ok(ret
== 0, "Seek time at last retval %d", ret
);
169 event
= bt_ctf_iter_read_event(iter
);
171 ok(event
, "Event valid at last position");
173 timestamp_last
= bt_ctf_get_timestamp(event
);
175 ok1(timestamp_last
== expected_last
);
177 /* Try to read next event */
178 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
180 ok(ret
== 0, "iter next should return an error");
182 event
= bt_ctf_iter_read_event(iter
);
184 ok(event
== 0, "Event after last should be invalid");
189 void run_seek_cycles(char *path
,
190 uint64_t expected_begin
,
191 uint64_t expected_last
)
193 struct bt_context
*ctx
;
194 struct bt_ctf_iter
*iter
;
195 struct bt_ctf_event
*event
;
196 struct bt_iter_pos newpos
;
201 ctx
= create_context_with_path(path
);
203 plan_skip_all("Cannot create valid context");
206 /* Create iterator with null last and end */
207 iter
= bt_ctf_iter_create(ctx
, NULL
, NULL
);
209 plan_skip_all("Cannot create valid iterator");
212 event
= bt_ctf_iter_read_event(iter
);
214 ok(event
, "Event valid at beginning");
217 newpos
.type
= BT_SEEK_LAST
;
218 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
220 ok(ret
== 0, "Seek last retval %d", ret
);
222 event
= bt_ctf_iter_read_event(iter
);
224 ok(event
, "Event valid at last position");
226 timestamp
= bt_ctf_get_timestamp(event
);
228 ok1(timestamp
== expected_last
);
230 /* Try to read next event */
231 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
233 ok(ret
== 0, "iter next should return an error");
235 event
= bt_ctf_iter_read_event(iter
);
237 ok(event
== 0, "Event after last should be invalid");
240 newpos
.type
= BT_SEEK_BEGIN
;
241 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
243 ok(ret
== 0, "Seek begin retval %d", ret
);
245 event
= bt_ctf_iter_read_event(iter
);
247 ok(event
, "Event valid at first position");
249 timestamp
= bt_ctf_get_timestamp(event
);
251 ok1(timestamp
== expected_begin
);
253 /* Seek last again */
254 newpos
.type
= BT_SEEK_LAST
;
255 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
257 ok(ret
== 0, "Seek last retval %d", ret
);
259 event
= bt_ctf_iter_read_event(iter
);
261 ok(event
, "Event valid at last position");
263 timestamp
= bt_ctf_get_timestamp(event
);
265 ok1(timestamp
== expected_last
);
270 int main(int argc
, char **argv
)
273 uint64_t expected_begin
;
274 uint64_t expected_last
;
276 plan_tests(NR_TESTS
);
279 plan_skip_all("Invalid arguments: need a trace path and the start and last timestamp");
283 /* Parse arguments (Trace, begin timestamp) */
286 expected_begin
= strtoull(argv
[2], NULL
, 0);
287 if (ULLONG_MAX
== expected_begin
&& errno
== ERANGE
) {
288 plan_skip_all("Invalid value for begin timestamp");
291 expected_last
= strtoull(argv
[3], NULL
, 0);
292 if (ULLONG_MAX
== expected_last
&& errno
== ERANGE
) {
293 plan_skip_all("Invalid value for last timestamp");
296 run_seek_begin(path
, expected_begin
);
297 run_seek_time_at_last(path
, expected_last
);
298 run_seek_last(path
, expected_last
);
299 run_seek_cycles(path
, expected_begin
, expected_last
);
301 return exit_status();
This page took 0.036012 seconds and 4 git commands to generate.