1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Alexandre Montplaisir - Initial API and implementation
11 * Patrick Tasse - Support selection range
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.temp
.tracemanager
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertNotNull
;
18 import static org
.junit
.Assert
.assertSame
;
21 import java
.util
.Collection
;
22 import java
.util
.Collections
;
23 import java
.util
.concurrent
.TimeUnit
;
25 import org
.eclipse
.jdt
.annotation
.NonNull
;
26 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalManager
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
38 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceContext
;
39 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
40 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.experiment
.TmfExperiment
;
41 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
42 import org
.junit
.After
;
43 import org
.junit
.AfterClass
;
44 import org
.junit
.Before
;
45 import org
.junit
.BeforeClass
;
46 import org
.junit
.Rule
;
47 import org
.junit
.Test
;
48 import org
.junit
.rules
.TestRule
;
49 import org
.junit
.rules
.Timeout
;
51 import com
.google
.common
.collect
.ImmutableSet
;
54 * Test suite for the {@link TmfTraceManager}.
56 * @author Alexandre Montplaisir
58 public class TmfTraceManagerTest
{
60 /** Time-out tests after 1 minute. */
62 public TestRule globalTimeout
= new Timeout(1, TimeUnit
.MINUTES
);
64 private static final int SCALE
= ITmfTimestamp
.NANOSECOND_SCALE
;
66 private static ITmfTrace trace1
;
67 private static final long t1start
= 1331668247314038062L;
68 private static final long t1end
= 1331668259054285979L;
70 private static ITmfTrace trace2
;
71 private static final long t2start
= 1332170682440133097L;
72 private static final long t2end
= 1332170692664579801L;
74 private static final long ONE_SECOND
= 1000000000L;
76 private TmfTraceManager tm
;
79 * Test class initialization
82 public static void setUpClass() {
83 trace1
= CtfTmfTestTraceUtils
.getTrace(CtfTestTrace
.TRACE2
);
84 trace2
= CtfTmfTestTraceUtils
.getTrace(CtfTestTrace
.KERNEL
);
86 trace1
.indexTrace(true);
87 trace2
.indexTrace(true);
89 // Deregister traces from signal manager so that they don't
90 // interfere with the TmfTraceManager tests
91 TmfSignalManager
.deregister(trace1
);
92 TmfSignalManager
.deregister(trace2
);
100 tm
= TmfTraceManager
.getInstance();
107 public void tearDown() {
108 while (tm
.getActiveTrace() != null) {
109 closeTrace(tm
.getActiveTrace());
114 * Test class clean-up
117 public static void tearDownClass() {
118 CtfTmfTestTraceUtils
.dispose(CtfTestTrace
.TRACE2
);
119 CtfTmfTestTraceUtils
.dispose(CtfTestTrace
.KERNEL
);
122 // ------------------------------------------------------------------------
123 // Dummy actions (fake signals)
124 // ------------------------------------------------------------------------
126 private void openTrace(ITmfTrace trace
) {
128 throw new IllegalArgumentException();
130 TmfSignalManager
.dispatchSignal(new TmfTraceOpenedSignal(this, trace
, null));
134 private void closeTrace(ITmfTrace trace
) {
136 throw new IllegalArgumentException();
138 TmfSignalManager
.dispatchSignal(new TmfTraceClosedSignal(this, trace
));
140 * In TMF, the next tab would now be selected (if there are some), which
141 * would select another trace automatically.
143 if (tm
.getOpenedTraces().size() > 0) {
144 selectTrace(tm
.getOpenedTraces().toArray(new ITmfTrace
[0])[0]);
148 private void selectTrace(ITmfTrace trace
) {
149 TmfSignalManager
.dispatchSignal(new TmfTraceSelectedSignal(this, trace
));
152 private void selectTimestamp(@NonNull ITmfTimestamp ts
) {
153 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, ts
));
156 private void selectWindowRange(TmfTimeRange tr
) {
157 TmfSignalManager
.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, tr
));
160 // ------------------------------------------------------------------------
162 // ------------------------------------------------------------------------
165 * Test that the manager is correctly initialized
168 public void testInitialize() {
169 TmfTraceManager mgr
= TmfTraceManager
.getInstance();
175 * Test the contents of a trace set with one trace.
178 public void testTraceSet() {
183 Collection
<ITmfTrace
> expected
= Collections
.singleton(trace2
);
184 Collection
<ITmfTrace
> actual
= tm
.getActiveTraceSet();
186 assertEquals(1, actual
.size());
187 assertEquals(expected
, actual
);
191 * Test the contents of a trace set with an experiment.
194 public void testTraceSetExperiment() {
195 final ITmfTrace localTrace1
= trace1
;
196 final ITmfTrace localTrace2
= trace2
;
197 assertNotNull(localTrace1
);
198 assertNotNull(localTrace2
);
199 TmfExperiment exp
= createExperiment(localTrace1
, localTrace2
);
200 openTrace(localTrace1
);
203 Collection
<ITmfTrace
> expected
= ImmutableSet
.of(localTrace1
, localTrace2
);
204 Collection
<ITmfTrace
> actual
= tm
.getActiveTraceSet();
206 assertEquals(2, actual
.size());
207 assertEquals(expected
, actual
);
211 * Test the contents of the complete trace set.
214 public void testTraceSetWithExperiment() {
215 final ITmfTrace localTrace1
= trace1
;
216 final ITmfTrace localTrace2
= trace2
;
217 assertNotNull(localTrace1
);
218 assertNotNull(localTrace2
);
219 /* Test with a trace */
220 Collection
<ITmfTrace
> expected
= Collections
.singleton(localTrace1
);
221 Collection
<ITmfTrace
> actual
= TmfTraceManager
.getTraceSetWithExperiment(localTrace1
);
222 assertEquals(1, actual
.size());
223 assertEquals(expected
, actual
);
225 /* Test with an experiment */
226 TmfExperiment exp
= createExperiment(localTrace1
, localTrace2
);
228 expected
= ImmutableSet
.of(localTrace1
, localTrace2
, exp
);
229 actual
= TmfTraceManager
.getTraceSetWithExperiment(exp
);
230 assertEquals(3, actual
.size());
231 assertEquals(expected
, actual
);
235 * Test the {@link TmfTraceManager#getSupplementaryFileDir} method.
238 public void testSupplementaryFileDir() {
239 final ITmfTrace localTrace1
= trace1
;
240 final ITmfTrace localTrace2
= trace2
;
241 assertNotNull(localTrace1
);
242 assertNotNull(localTrace2
);
243 String name1
= localTrace1
.getName();
244 String name2
= localTrace2
.getName();
245 String basePath
= TmfTraceManager
.getTemporaryDirPath() + File
.separator
;
247 String expected1
= basePath
+ name1
+ File
.separator
;
248 String expected2
= basePath
+ name2
+ File
.separator
;
250 assertEquals(expected1
, TmfTraceManager
.getSupplementaryFileDir(localTrace1
));
251 assertEquals(expected2
, TmfTraceManager
.getSupplementaryFileDir(localTrace2
));
254 // ------------------------------------------------------------------------
255 // Test a single trace
256 // ------------------------------------------------------------------------
259 * Test the initial range of a single trace.
262 public void testTraceInitialRange() {
264 final TmfTimeRange expectedRange
= new TmfTimeRange(
265 trace2
.getStartTime(),
266 calculateOffset(trace2
.getStartTime(), trace2
.getInitialRangeOffset()));
267 TmfTimeRange actualRange
= tm
.getCurrentTraceContext().getWindowRange();
268 assertEquals(expectedRange
, actualRange
);
272 * Try selecting a timestamp contained inside the trace's range. The trace's
273 * current time should get updated correctly.
276 public void testNewTimestamp() {
278 ITmfTimestamp ts
= new TmfTimestamp(t2start
+ ONE_SECOND
, SCALE
);
281 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
282 assertEquals(ts
, selection
.getStartTime());
283 assertEquals(ts
, selection
.getEndTime());
287 * Try selecting a timestamp happening before the trace's start. The change
291 public void testTimestampBefore() {
293 TmfTimeRange beforeTr
= tm
.getCurrentTraceContext().getSelectionRange();
294 ITmfTimestamp ts
= new TmfTimestamp(t2start
- ONE_SECOND
, SCALE
);
297 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
298 assertEquals(beforeTr
, selection
);
302 * Try selecting a timestamp happening after the trace's end. The change
306 public void testTimestampAfter() {
308 TmfTimeRange beforeTr
= tm
.getCurrentTraceContext().getSelectionRange();
309 ITmfTimestamp ts
= new TmfTimestamp(t2end
+ ONE_SECOND
, SCALE
);
312 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
313 assertEquals(beforeTr
, selection
);
317 * Test selecting a normal sub-range of a single trace.
320 public void testTraceNewTimeRange() {
322 TmfTimeRange range
= new TmfTimeRange(
323 new TmfTimestamp(t2start
+ ONE_SECOND
, SCALE
),
324 new TmfTimestamp(t2end
- ONE_SECOND
, SCALE
));
325 selectWindowRange(range
);
327 TmfTimeRange curRange
= tm
.getCurrentTraceContext().getWindowRange();
328 assertEquals(range
, curRange
);
332 * Test selecting a range whose start time is before the trace's start time.
333 * The selected range should get clamped to the trace's range.
336 public void testTraceTimeRangeClampingStart() {
338 TmfTimeRange range
= new TmfTimeRange(
339 new TmfTimestamp(t2start
- ONE_SECOND
, SCALE
), // minus here
340 new TmfTimestamp(t2end
- ONE_SECOND
, SCALE
));
341 selectWindowRange(range
);
343 TmfTimeRange curRange
= tm
.getCurrentTraceContext().getWindowRange();
344 assertEquals(t2start
, curRange
.getStartTime().getValue());
345 assertEquals(range
.getEndTime(), curRange
.getEndTime());
349 * Test selecting a range whose end time is after the trace's end time. The
350 * selected range should get clamped to the trace's range.
353 public void testTraceTimeRangeClampingEnd() {
355 TmfTimeRange range
= new TmfTimeRange(
356 new TmfTimestamp(t2start
+ ONE_SECOND
, SCALE
),
357 new TmfTimestamp(t2end
+ ONE_SECOND
, SCALE
)); // plus here
358 selectWindowRange(range
);
360 TmfTimeRange curRange
= tm
.getCurrentTraceContext().getWindowRange();
361 assertEquals(range
.getStartTime(), curRange
.getStartTime());
362 assertEquals(t2end
, curRange
.getEndTime().getValue());
366 * Test selecting a range whose both start and end times are outside of the
367 * trace's range. The selected range should get clamped to the trace's
371 public void testTraceTimeRangeClampingBoth() {
373 TmfTimeRange range
= new TmfTimeRange(
374 new TmfTimestamp(t2start
- ONE_SECOND
, SCALE
), // minus here
375 new TmfTimestamp(t2end
+ ONE_SECOND
, SCALE
)); // plus here
376 selectWindowRange(range
);
378 TmfTimeRange curRange
= tm
.getCurrentTraceContext().getWindowRange();
379 assertEquals(t2start
, curRange
.getStartTime().getValue());
380 assertEquals(t2end
, curRange
.getEndTime().getValue());
383 // ------------------------------------------------------------------------
384 // Test multiple, non-overlapping traces in parallel
385 // ------------------------------------------------------------------------
388 * Test, with two traces in parallel, when we select a timestamp that is
389 * part of the first trace.
391 * The first trace's timestamp should be updated, but the second trace's one
395 public void testTwoTracesTimestampValid() {
399 TmfTimestamp ts
= new TmfTimestamp(t1start
+ ONE_SECOND
, SCALE
);
402 /* Timestamp of trace1 should have been updated */
403 TmfTraceContext ctx
= tm
.getCurrentTraceContext();
404 assertEquals(ts
, ctx
.getSelectionRange().getStartTime());
405 assertEquals(ts
, ctx
.getSelectionRange().getEndTime());
407 /* Timestamp of trace2 should not have changed */
409 ctx
= tm
.getCurrentTraceContext();
410 assertEquals(trace2
.getStartTime(), ctx
.getSelectionRange().getStartTime());
411 assertEquals(trace2
.getStartTime(), ctx
.getSelectionRange().getEndTime());
415 * Test, with two traces in parallel, when we select a timestamp that is
416 * between two traces.
418 * None of the trace's timestamps should be updated (we are not in an
422 public void testTwoTracesTimestampInBetween() {
426 TmfTimestamp ts
= new TmfTimestamp(t1end
+ ONE_SECOND
, SCALE
);
429 /* Timestamp of trace1 should not have changed */
430 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
431 assertEquals(trace1
.getStartTime(), selection
.getStartTime());
432 assertEquals(trace1
.getStartTime(), selection
.getEndTime());
434 /* Timestamp of trace2 should not have changed */
436 selection
= tm
.getCurrentTraceContext().getSelectionRange();
437 assertEquals(trace2
.getStartTime(), selection
.getStartTime());
438 assertEquals(trace2
.getStartTime(), selection
.getEndTime());
442 * Test, with two traces in parallel, when we select a timestamp that is
443 * completely out of the trace's range.
445 * None of the trace's timestamps should be updated.
448 public void testTwoTracesTimestampInvalid() {
452 TmfTimestamp ts
= new TmfTimestamp(t2end
+ ONE_SECOND
, SCALE
);
455 /* Timestamp of trace1 should not have changed */
456 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
457 assertEquals(trace1
.getStartTime(), selection
.getStartTime());
458 assertEquals(trace1
.getStartTime(), selection
.getEndTime());
460 /* Timestamp of trace2 should not have changed */
462 selection
= tm
.getCurrentTraceContext().getSelectionRange();
463 assertEquals(trace2
.getStartTime(), selection
.getStartTime());
464 assertEquals(trace2
.getStartTime(), selection
.getEndTime());
468 * Test, with two traces opened in parallel (not in an experiment), if we
469 * select a time range valid in one of them. That trace's time range should
470 * be updated, but not the other one.
473 public void testTwoTracesTimeRangeAllInOne() {
477 TmfTimeRange range
= new TmfTimeRange(
478 new TmfTimestamp(t1start
+ ONE_SECOND
, SCALE
),
479 new TmfTimestamp(t1end
- ONE_SECOND
, SCALE
));
480 selectWindowRange(range
);
482 /* Range of trace1 should be equal to the requested one */
483 assertEquals(range
, tm
.getCurrentTraceContext().getWindowRange());
485 /* The range of trace 2 should not have changed */
487 assertEquals(getInitialRange(trace2
), tm
.getCurrentTraceContext().getWindowRange());
491 * Test, with two traces in parallel, when we select a time range that is
492 * only partially valid for one of the traces.
494 * The first trace's time range should be clamped to a valid range, and the
495 * second one's should not change.
498 public void testTwoTracesTimeRangePartiallyInOne() {
502 TmfTimeRange range
= new TmfTimeRange(
503 new TmfTimestamp(t1start
+ ONE_SECOND
, SCALE
),
504 new TmfTimestamp(t1end
+ ONE_SECOND
, SCALE
));
505 selectWindowRange(range
);
507 /* Range of trace1 should get clamped to its end time */
508 TmfTimeRange expectedRange
= new TmfTimeRange(
509 new TmfTimestamp(t1start
+ ONE_SECOND
, SCALE
),
510 new TmfTimestamp(t1end
, SCALE
));
511 assertEquals(expectedRange
, tm
.getCurrentTraceContext().getWindowRange());
513 /* Range of trace2 should not have changed */
515 assertEquals(getInitialRange(trace2
), tm
.getCurrentTraceContext().getWindowRange());
519 * Test, with two traces in parallel, when we select a time range that is
520 * only partially valid for both traces.
522 * Each trace's time range should get clamped to respectively valid ranges.
525 public void testTwoTracesTimeRangeInBoth() {
529 TmfTimeRange range
= new TmfTimeRange(
530 new TmfTimestamp(t1end
- ONE_SECOND
, SCALE
),
531 new TmfTimestamp(t2start
+ ONE_SECOND
, SCALE
));
532 selectWindowRange(range
);
534 /* Range of trace1 should be clamped to its end time */
535 TmfTimeRange expectedRange
= new TmfTimeRange(
536 new TmfTimestamp(t1end
- ONE_SECOND
, SCALE
),
537 new TmfTimestamp(t1end
, SCALE
));
538 assertEquals(expectedRange
, tm
.getCurrentTraceContext().getWindowRange());
540 /* Range of trace2 should be clamped to its start time */
542 expectedRange
= new TmfTimeRange(
543 new TmfTimestamp(t2start
, SCALE
),
544 new TmfTimestamp(t2start
+ ONE_SECOND
, SCALE
));
545 assertEquals(expectedRange
, tm
.getCurrentTraceContext().getWindowRange());
549 * Test, with two traces in parallel, when we select a time range that is
550 * not valid for any trace.
552 * Each trace's time range should not be modified.
555 public void testTwoTracesTimeRangeInBetween() {
559 TmfTimeRange range
= new TmfTimeRange(
560 new TmfTimestamp(t1end
+ ONE_SECOND
, SCALE
),
561 new TmfTimestamp(t1end
- ONE_SECOND
, SCALE
));
562 selectWindowRange(range
);
564 /* Range of trace1 should not have changed */
565 TmfTimeRange expectedRange
= getInitialRange(trace1
);
566 TmfTimeRange curRange
= tm
.getCurrentTraceContext().getWindowRange();
567 assertEquals(expectedRange
.getStartTime(), curRange
.getStartTime());
568 assertEquals(expectedRange
.getEndTime(), curRange
.getEndTime());
570 /* Range of trace2 should not have changed */
572 expectedRange
= getInitialRange(trace2
);
573 curRange
= tm
.getCurrentTraceContext().getWindowRange();
574 assertEquals(expectedRange
.getStartTime(), curRange
.getStartTime());
575 assertEquals(expectedRange
.getEndTime(), curRange
.getEndTime());
578 // ------------------------------------------------------------------------
579 // Test an experiment
580 // ------------------------------------------------------------------------
583 * Test in an experiment when we select a timestamp that is part of one of
584 * the experiment's traces.
586 * The experiment's current time should be correctly updated.
589 public void testExperimentTimestampInTrace() {
590 TmfExperiment exp
= createExperiment(trace1
, trace2
);
592 TmfTimestamp ts
= new TmfTimestamp(t1start
+ ONE_SECOND
, SCALE
);
595 /* The experiment's current time should be updated. */
596 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
597 assertEquals(ts
, selection
.getStartTime());
598 assertEquals(ts
, selection
.getEndTime());
602 * Test in an experiment when we select a timestamp that is between two
603 * traces in the experiment.
605 * The experiment's current time should still be updated, since the
606 * timestamp is valid in the experiment itself.
609 public void testExperimentTimestampInBetween() {
610 TmfExperiment exp
= createExperiment(trace1
, trace2
);
612 TmfTimestamp ts
= new TmfTimestamp(t1end
+ ONE_SECOND
, SCALE
);
615 /* The experiment's current time should be updated. */
616 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
617 assertEquals(ts
, selection
.getStartTime());
618 assertEquals(ts
, selection
.getEndTime());
622 * Test in an experiment when we select a timestamp that is outside of the
623 * total range of the experiment.
625 * The experiment's current time should not be updated.
628 public void testExperimentTimestampInvalid() {
629 TmfExperiment exp
= createExperiment(trace1
, trace2
);
631 TmfTimestamp ts
= new TmfTimestamp(t2end
+ ONE_SECOND
, SCALE
);
634 /* The experiment's current time should NOT be updated. */
635 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
636 assertEquals(trace1
.getStartTime(), selection
.getStartTime());
637 assertEquals(trace1
.getStartTime(), selection
.getEndTime());
641 * Test the initial range of an experiment.
644 public void testExperimentInitialRange() {
645 TmfExperiment exp
= createExperiment(trace1
, trace2
);
648 * The initial range should be == to the initial range of the earliest
649 * trace (here trace1).
651 final TmfTimeRange actualRange
= tm
.getCurrentTraceContext().getWindowRange();
653 assertEquals(getInitialRange(trace1
), actualRange
);
654 assertEquals(getInitialRange(exp
), actualRange
);
658 * Test the range clamping with the start time of the range outside of the
659 * earliest trace's range. Only that start time should get clamped.
662 public void testExperimentRangeClampingOne() {
663 TmfExperiment exp
= createExperiment(trace1
, trace2
);
666 final TmfTimeRange range
= new TmfTimeRange(
667 new TmfTimestamp(t1start
- ONE_SECOND
, SCALE
),
668 new TmfTimestamp(t1end
- ONE_SECOND
, SCALE
));
669 selectWindowRange(range
);
671 TmfTimeRange actualRange
= tm
.getCurrentTraceContext().getWindowRange();
672 assertEquals(t1start
, actualRange
.getStartTime().getValue());
673 assertEquals(t1end
- ONE_SECOND
, actualRange
.getEndTime().getValue());
677 * Test the range clamping when both the start and end times of the signal's
678 * range are outside of the trace's range. The range should clamp to the
679 * experiment's range.
682 public void testExperimentRangeClampingBoth() {
683 TmfExperiment exp
= createExperiment(trace1
, trace2
);
686 final TmfTimeRange range
= new TmfTimeRange(
687 new TmfTimestamp(t1start
- ONE_SECOND
, SCALE
),
688 new TmfTimestamp(t2end
+ ONE_SECOND
, SCALE
));
689 selectWindowRange(range
);
691 TmfTimeRange actualRange
= tm
.getCurrentTraceContext().getWindowRange();
692 assertEquals(t1start
, actualRange
.getStartTime().getValue());
693 assertEquals(t2end
, actualRange
.getEndTime().getValue());
697 * Test selecting a range in-between two disjoint traces in an experiment.
698 * The range should still get correctly selected, even if no trace has any
699 * events in that range.
702 public void testExperimentRangeInBetween() {
703 TmfExperiment exp
= createExperiment(trace1
, trace2
);
706 final TmfTimeRange range
= new TmfTimeRange(
707 new TmfTimestamp(t1end
+ ONE_SECOND
, SCALE
),
708 new TmfTimestamp(t2start
- ONE_SECOND
, SCALE
));
709 selectWindowRange(range
);
711 TmfTimeRange actualRange
= tm
.getCurrentTraceContext().getWindowRange();
712 assertEquals(range
, actualRange
);
715 // ------------------------------------------------------------------------
717 // ------------------------------------------------------------------------
719 private static TmfExperiment
createExperiment(ITmfTrace t1
, ITmfTrace t2
) {
720 ITmfTrace
[] traces
= new ITmfTrace
[] { t1
, t2
};
721 TmfExperiment exp
= new TmfExperiment(ITmfEvent
.class, "test-exp", traces
,
722 TmfExperiment
.DEFAULT_INDEX_PAGE_SIZE
, null);
723 exp
.indexTrace(true);
724 // Deregister experiment from signal manager so that it doesn't
725 // interfere with the TmfTraceManager tests
726 TmfSignalManager
.deregister(exp
);
730 private static TmfTimeRange
getInitialRange(ITmfTrace trace
) {
731 return new TmfTimeRange(
732 trace
.getStartTime(),
733 calculateOffset(trace
.getStartTime(), trace
.getInitialRangeOffset()));
737 * Basically a "initial + offset" operation, but for ITmfTimetamp objects.
739 private static @NonNull ITmfTimestamp
calculateOffset(ITmfTimestamp initialTs
, ITmfTimestamp offsetTs
) {
740 long start
= initialTs
.toNanos();
741 long offset
= offsetTs
.toNanos();
742 return new TmfTimestamp(start
+ offset
, SCALE
);