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_cycles(char *path
,
138 uint64_t expected_begin
,
139 uint64_t expected_last
)
141 struct bt_context
*ctx
;
142 struct bt_ctf_iter
*iter
;
143 struct bt_ctf_event
*event
;
144 struct bt_iter_pos newpos
;
149 ctx
= create_context_with_path(path
);
151 plan_skip_all("Cannot create valid context");
154 /* Create iterator with null last and end */
155 iter
= bt_ctf_iter_create(ctx
, NULL
, NULL
);
157 plan_skip_all("Cannot create valid iterator");
160 event
= bt_ctf_iter_read_event(iter
);
162 ok(event
, "Event valid at beginning");
165 newpos
.type
= BT_SEEK_LAST
;
166 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
168 ok(ret
== 0, "Seek last retval %d", ret
);
170 event
= bt_ctf_iter_read_event(iter
);
172 ok(event
, "Event valid at last position");
174 timestamp
= bt_ctf_get_timestamp(event
);
176 ok1(timestamp
== 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");
188 newpos
.type
= BT_SEEK_BEGIN
;
189 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
191 ok(ret
== 0, "Seek begin retval %d", ret
);
193 event
= bt_ctf_iter_read_event(iter
);
195 ok(event
, "Event valid at first position");
197 timestamp
= bt_ctf_get_timestamp(event
);
199 ok1(timestamp
== expected_begin
);
201 /* Seek last again */
202 newpos
.type
= BT_SEEK_LAST
;
203 ret
= bt_iter_set_pos(bt_ctf_get_iter(iter
), &newpos
);
205 ok(ret
== 0, "Seek last retval %d", ret
);
207 event
= bt_ctf_iter_read_event(iter
);
209 ok(event
, "Event valid at last position");
211 timestamp
= bt_ctf_get_timestamp(event
);
213 ok1(timestamp
== expected_last
);
218 int main(int argc
, char **argv
)
221 uint64_t expected_begin
;
222 uint64_t expected_last
;
224 plan_tests(NR_TESTS
);
227 plan_skip_all("Invalid arguments: need a trace path and the start and last timestamp");
231 /* Parse arguments (Trace, begin timestamp) */
234 expected_begin
= strtoull(argv
[2], NULL
, 0);
235 if (ULLONG_MAX
== expected_begin
&& errno
== ERANGE
) {
236 plan_skip_all("Invalid value for begin timestamp");
239 expected_last
= strtoull(argv
[3], NULL
, 0);
240 if (ULLONG_MAX
== expected_last
&& errno
== ERANGE
) {
241 plan_skip_all("Invalid value for last timestamp");
244 run_seek_begin(path
, expected_begin
);
245 run_seek_last(path
, expected_last
);
246 run_seek_cycles(path
, expected_begin
, expected_last
);
248 return exit_status();
This page took 0.035586 seconds and 5 git commands to generate.