+ /* Seek at specified interval, using states computed in 6, making
+ * sure that there is no more than the number of events between
+ * state save interval to read before getting there.
+ */
+
+ if((a_test8 && a_test6) || a_test_all) {
+ g_message("Running test 8 : check save interval");
+ LttTime time = tc->time_span.start_time;
+ LttTime interval;
+ interval.tv_sec = 0;
+ interval.tv_nsec = 175674987;
+ guint count;
+
+ while(ltt_time_compare(time, tc->time_span.end_time) < 0) {
+ //g_message("Seeking at time %u.%u", time.tv_sec, time.tv_nsec);
+ lttv_process_traceset_seek_time(&ts->parent, ltt_time_zero);
+ lttv_state_traceset_seek_time_closest(ts, time);
+ /* We add no hook to the traceset, not necessary */
+ count = lttv_process_traceset_middle(&ts->parent,
+ time, G_MAXUINT, NULL);
+ g_info("Number of events to jump over : %u", count);
+
+ if(count > LTTV_STATE_SAVE_INTERVAL)
+ g_warning("Oops! Save interval is %u and it took %u events to seek to a time %lu.%lu supposed to be closer from the last saved state.",
+ LTTV_STATE_SAVE_INTERVAL, count, time.tv_sec, time.tv_nsec);
+ time = ltt_time_add(time, interval);
+ }
+
+ }
+
+ if(a_test9 || a_test_all) {
+ double t0, t1;
+ /* Run seek_forward and seek_backward test */
+ guint count;
+ LttvTracesetContext *tsc = &ts->parent;
+ LttvTracesetContextPosition *saved_pos =
+ lttv_traceset_context_position_new(tsc);
+ g_message("Running test 9 : seek_forward and seek_backward");
+ lttv_process_traceset_seek_time(tsc, ltt_time_zero);
+
+ count = lttv_process_traceset_seek_n_forward(tsc, 500, NULL, NULL, NULL);
+ g_assert(count == 500);
+ lttv_traceset_context_position_save(tsc, saved_pos);
+ t0 = get_time();
+ count = lttv_process_traceset_seek_n_forward(tsc, 150000, NULL, NULL, NULL);
+ t1 = get_time();
+ g_message("Seek forward 150000 events in %g seconds", t1 - t0);
+ g_assert(count == 150000);
+ t0 = get_time();
+ count = lttv_process_traceset_seek_n_backward(tsc, 150000,
+ seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
+ NULL, NULL);
+ t1 = get_time();
+ g_message("Seek backward 150000 events in %g seconds", t1 - t0);
+ g_assert(count == 150000);
+ if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
+ g_warning("Problem with seek_n ! Positions differ. (1)");
+ }
+
+ lttv_process_traceset_seek_n_forward(tsc, 500, NULL, NULL, NULL);
+ lttv_traceset_context_position_save(tsc, saved_pos);
+ lttv_process_traceset_seek_n_forward(tsc, 15000, NULL, NULL, NULL);
+ lttv_process_traceset_seek_n_backward(tsc, 15005,
+ seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
+ NULL, NULL);
+ lttv_process_traceset_seek_n_forward(tsc, 5, NULL, NULL, NULL);
+ if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
+ g_warning("Problem with seek_n ! Positions differ. (2)");
+ }
+
+ lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
+
+ count = lttv_process_traceset_seek_n_forward(tsc, 15000, NULL, NULL, NULL);
+ if(count > 0)
+ g_warning("Problem with seek_n ! Forward at end of traceset.");
+
+ lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
+
+ lttv_traceset_context_position_save(tsc, saved_pos);
+ t0 = get_time();
+ lttv_process_traceset_seek_n_backward(tsc, 300,
+ seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
+ NULL, NULL);
+ t1 = get_time();
+ g_message("Seek backward 300 events in %g seconds", t1 - t0);
+ count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL, NULL, NULL);
+ count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL, NULL, NULL);
+
+ if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
+ g_warning("Problem with seek_n ! Positions differ. (4)");
+ }
+
+ lttv_traceset_context_position_save(tsc, saved_pos);
+ t0 = get_time();
+ lttv_process_traceset_seek_n_backward(tsc, 10,
+ seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
+ NULL, NULL);
+ t1 = get_time();
+ g_message("Seek backward 10 events in %g seconds", t1 - t0);
+ t0 = get_time();
+ count = lttv_process_traceset_seek_n_forward(tsc, 10, NULL, NULL, NULL);
+ t1 = get_time();
+ g_message("Seek forward 10 events in %g seconds", t1 - t0);
+
+
+ /* try a volountary error */
+ lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
+
+ lttv_traceset_context_position_save(tsc, saved_pos);
+ lttv_process_traceset_seek_n_backward(tsc, 301,
+ seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
+ NULL, NULL);
+ count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL, NULL, NULL);
+ count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL, NULL, NULL);
+
+ if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) == 0) {
+ g_warning("Problem with seek_n ! Positions _should_ differ. (5)");
+ }
+
+ /* Try a seek by closest time : Hint : try this one with and without states
+ * computed. */
+ lttv_process_traceset_seek_time(tsc, ltt_time_zero);
+ count = lttv_process_traceset_seek_n_forward(tsc, 200000, NULL, NULL, NULL);
+ lttv_traceset_context_position_save(tsc, saved_pos);
+ t0 = get_time();
+ lttv_process_traceset_seek_n_backward(tsc, 100301,
+ seek_back_default_offset,
+ (seek_time_fct)lttv_state_traceset_seek_time_closest, NULL,
+ NULL, NULL);
+ t1 = get_time();
+ g_message("Seek backward 100301 events (with seek closest) in %g seconds",
+ t1 - t0);
+ count = lttv_process_traceset_seek_n_forward(tsc, 100301, NULL, NULL, NULL);
+
+ if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) {
+ g_warning("Problem with seek_n with state seek time! Positions differ. (6)");
+ }
+
+ lttv_traceset_context_position_destroy(saved_pos);
+ }
+
+ if(a_test10 || a_test_all) {
+ g_message("Running test 10 : check seek traceset context position");
+ LttvTracesetContext *tsc = &ts->parent;
+ LttvTracesetContextPosition *saved_pos =
+ lttv_traceset_context_position_new(tsc);
+
+ lttv_process_traceset_seek_time(tsc, ltt_time_zero);
+ lttv_process_traceset_seek_n_forward(tsc, 200000, NULL, NULL, NULL);
+ lttv_traceset_context_position_save(tsc, saved_pos);
+ if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) != 0)
+ g_critical("Error in seek position. (1)");
+
+ lttv_process_traceset_seek_time(tsc, ltt_time_infinite);
+ lttv_process_traceset_seek_n_backward(tsc, 500,
+ seek_back_default_offset, lttv_process_traceset_seek_time, NULL,
+ NULL, NULL);
+ lttv_traceset_context_position_save(tsc, saved_pos);
+
+ if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) != 0)
+ g_critical("Error in seek position. (2)");
+
+ lttv_traceset_context_position_destroy(saved_pos);
+ }
+
+ if(a_trace_event) lttv_hooks_remove_data(event_hook, trace_event, NULL);