Adding a test which do a sequence of seek BEGIN, LAST, BEGIN, LAST
authorYannick Brosseau <yannick.brosseau@gmail.com>
Sat, 17 Nov 2012 16:22:01 +0000 (11:22 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 17 Nov 2012 16:22:01 +0000 (11:22 -0500)
Signed-off-by: Yannick Brosseau <yannick.brosseau@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/lib/test-seeks.c

index c6abf2c1f2bbf85b4f2597671b95d3ffe4b04add..47bb42e216cbb1287c0c2ec9e4c5a9e017c6472f 100644 (file)
@@ -32,7 +32,7 @@
 #include "common.h"
 #include "tap.h"
 
-#define NR_TESTS       11
+#define NR_TESTS       23
 
 void run_seek_begin(char *path, uint64_t expected_begin)
 {
@@ -134,6 +134,87 @@ void run_seek_last(char *path, uint64_t expected_last)
        bt_context_put(ctx);
 }
 
+void run_seek_cycles(char *path,
+               uint64_t expected_begin,
+               uint64_t expected_last)
+{
+       struct bt_context *ctx;
+       struct bt_ctf_iter *iter;
+       struct bt_ctf_event *event;
+       struct bt_iter_pos newpos;
+       int ret;
+       uint64_t timestamp;
+
+       /* Open the trace */
+       ctx = create_context_with_path(path);
+       if (!ctx) {
+               plan_skip_all("Cannot create valid context");
+       }
+
+       /* Create iterator with null last and end */
+       iter = bt_ctf_iter_create(ctx, NULL, NULL);
+       if (!iter) {
+               plan_skip_all("Cannot create valid iterator");
+       }
+
+       event = bt_ctf_iter_read_event(iter);
+
+       ok(event, "Event valid at beginning");
+
+       /* Seek to last */
+       newpos.type = BT_SEEK_LAST;
+       ret = bt_iter_set_pos(bt_ctf_get_iter(iter), &newpos);
+
+       ok(ret == 0, "Seek last retval %d", ret);
+
+       event = bt_ctf_iter_read_event(iter);
+
+       ok(event, "Event valid at last position");
+
+       timestamp = bt_ctf_get_timestamp(event);
+
+       ok1(timestamp == expected_last);
+
+       /* Try to read next event */
+       ret = bt_iter_next(bt_ctf_get_iter(iter));
+
+       ok(ret == 0, "iter next should return an error");
+
+       event = bt_ctf_iter_read_event(iter);
+
+       ok(event == 0, "Event after last should be invalid");
+
+       /* Seek to BEGIN */
+       newpos.type = BT_SEEK_BEGIN;
+       ret = bt_iter_set_pos(bt_ctf_get_iter(iter), &newpos);
+
+       ok(ret == 0, "Seek begin retval %d", ret);
+
+       event = bt_ctf_iter_read_event(iter);
+
+       ok(event, "Event valid at first position");
+
+       timestamp = bt_ctf_get_timestamp(event);
+
+       ok1(timestamp == expected_begin);
+
+       /* Seek last again */
+       newpos.type = BT_SEEK_LAST;
+       ret = bt_iter_set_pos(bt_ctf_get_iter(iter), &newpos);
+
+       ok(ret == 0, "Seek last retval %d", ret);
+
+       event = bt_ctf_iter_read_event(iter);
+
+       ok(event, "Event valid at last position");
+
+       timestamp = bt_ctf_get_timestamp(event);
+
+       ok1(timestamp == expected_last);
+
+       bt_context_put(ctx);
+}
+
 int main(int argc, char **argv)
 {
        char *path;
@@ -162,6 +243,7 @@ int main(int argc, char **argv)
 
        run_seek_begin(path, expected_begin);
        run_seek_last(path, expected_last);
+       run_seek_cycles(path, expected_begin, expected_last);
 
        return exit_status();
 }
This page took 0.040572 seconds and 4 git commands to generate.