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 20 seconds */
62 public TestRule globalTimeout
= new Timeout(20, TimeUnit
.SECONDS
);
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
;
80 * Test class initialization
83 public static void setUpClass() {
84 trace1
= CtfTmfTestTraceUtils
.getTrace(CtfTestTrace
.TRACE2
);
85 trace2
= CtfTmfTestTraceUtils
.getTrace(CtfTestTrace
.KERNEL
);
87 trace1
.indexTrace(true);
88 trace2
.indexTrace(true);
90 // Deregister traces from signal manager so that they don't
91 // interfere with the TmfTraceManager tests
92 TmfSignalManager
.deregister(trace1
);
93 TmfSignalManager
.deregister(trace2
);
100 public void setUp() {
101 tm
= TmfTraceManager
.getInstance();
108 public void tearDown() {
109 while (tm
.getActiveTrace() != null) {
110 closeTrace(tm
.getActiveTrace());
115 * Test class clean-up
118 public static void tearDownClass() {
119 CtfTmfTestTraceUtils
.dispose(CtfTestTrace
.TRACE2
);
120 CtfTmfTestTraceUtils
.dispose(CtfTestTrace
.KERNEL
);
123 // ------------------------------------------------------------------------
124 // Dummy actions (fake signals)
125 // ------------------------------------------------------------------------
127 private void openTrace(ITmfTrace trace
) {
129 throw new IllegalArgumentException();
131 TmfSignalManager
.dispatchSignal(new TmfTraceOpenedSignal(this, trace
, null));
135 private void closeTrace(ITmfTrace trace
) {
137 throw new IllegalArgumentException();
139 TmfSignalManager
.dispatchSignal(new TmfTraceClosedSignal(this, trace
));
141 * In TMF, the next tab would now be selected (if there are some), which
142 * would select another trace automatically.
144 if (tm
.getOpenedTraces().size() > 0) {
145 selectTrace(tm
.getOpenedTraces().toArray(new ITmfTrace
[0])[0]);
149 private void selectTrace(ITmfTrace trace
) {
150 TmfSignalManager
.dispatchSignal(new TmfTraceSelectedSignal(this, trace
));
153 private void selectTimestamp(@NonNull ITmfTimestamp ts
) {
154 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, ts
));
157 private void selectWindowRange(TmfTimeRange tr
) {
158 TmfSignalManager
.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, tr
));
161 // ------------------------------------------------------------------------
163 // ------------------------------------------------------------------------
166 * Test that the manager is correctly initialized
169 public void testInitialize() {
170 TmfTraceManager mgr
= TmfTraceManager
.getInstance();
176 * Test the contents of a trace set with one trace.
179 public void testTraceSet() {
184 Collection
<ITmfTrace
> expected
= Collections
.singleton(trace2
);
185 Collection
<ITmfTrace
> actual
= tm
.getActiveTraceSet();
187 assertEquals(1, actual
.size());
188 assertEquals(expected
, actual
);
192 * Test the contents of a trace set with an experiment.
195 public void testTraceSetExperiment() {
196 final ITmfTrace localTrace1
= trace1
;
197 final ITmfTrace localTrace2
= trace2
;
198 assertNotNull(localTrace1
);
199 assertNotNull(localTrace2
);
200 TmfExperiment exp
= createExperiment(localTrace1
, localTrace2
);
201 openTrace(localTrace1
);
204 Collection
<ITmfTrace
> expected
= ImmutableSet
.of(localTrace1
, localTrace2
);
205 Collection
<ITmfTrace
> actual
= tm
.getActiveTraceSet();
207 assertEquals(2, actual
.size());
208 assertEquals(expected
, actual
);
212 * Test the contents of the complete trace set.
215 public void testTraceSetWithExperiment() {
216 final ITmfTrace localTrace1
= trace1
;
217 final ITmfTrace localTrace2
= trace2
;
218 assertNotNull(localTrace1
);
219 assertNotNull(localTrace2
);
220 /* Test with a trace */
221 Collection
<ITmfTrace
> expected
= Collections
.singleton(localTrace1
);
222 Collection
<ITmfTrace
> actual
= TmfTraceManager
.getTraceSetWithExperiment(localTrace1
);
223 assertEquals(1, actual
.size());
224 assertEquals(expected
, actual
);
226 /* Test with an experiment */
227 TmfExperiment exp
= createExperiment(localTrace1
, localTrace2
);
229 expected
= ImmutableSet
.of(localTrace1
, localTrace2
, exp
);
230 actual
= TmfTraceManager
.getTraceSetWithExperiment(exp
);
231 assertEquals(3, actual
.size());
232 assertEquals(expected
, actual
);
236 * Test the {@link TmfTraceManager#getSupplementaryFileDir} method.
239 public void testSupplementaryFileDir() {
240 final ITmfTrace localTrace1
= trace1
;
241 final ITmfTrace localTrace2
= trace2
;
242 assertNotNull(localTrace1
);
243 assertNotNull(localTrace2
);
244 String name1
= localTrace1
.getName();
245 String name2
= localTrace2
.getName();
246 String basePath
= TmfTraceManager
.getTemporaryDirPath() + File
.separator
;
248 String expected1
= basePath
+ name1
+ File
.separator
;
249 String expected2
= basePath
+ name2
+ File
.separator
;
251 assertEquals(expected1
, TmfTraceManager
.getSupplementaryFileDir(localTrace1
));
252 assertEquals(expected2
, TmfTraceManager
.getSupplementaryFileDir(localTrace2
));
255 // ------------------------------------------------------------------------
256 // Test a single trace
257 // ------------------------------------------------------------------------
260 * Test the initial range of a single trace.
263 public void testTraceInitialRange() {
265 final TmfTimeRange expectedRange
= new TmfTimeRange(
266 trace2
.getStartTime(),
267 calculateOffset(trace2
.getStartTime(), trace2
.getInitialRangeOffset()));
268 TmfTimeRange actualRange
= tm
.getCurrentTraceContext().getWindowRange();
269 assertEquals(expectedRange
, actualRange
);
273 * Try selecting a timestamp contained inside the trace's range. The trace's
274 * current time should get updated correctly.
277 public void testNewTimestamp() {
279 ITmfTimestamp ts
= new TmfTimestamp(t2start
+ ONE_SECOND
, SCALE
);
282 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
283 assertEquals(ts
, selection
.getStartTime());
284 assertEquals(ts
, selection
.getEndTime());
288 * Try selecting a timestamp happening before the trace's start. The change
292 public void testTimestampBefore() {
294 TmfTimeRange beforeTr
= tm
.getCurrentTraceContext().getSelectionRange();
295 ITmfTimestamp ts
= new TmfTimestamp(t2start
- ONE_SECOND
, SCALE
);
298 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
299 assertEquals(beforeTr
, selection
);
303 * Try selecting a timestamp happening after the trace's end. The change
307 public void testTimestampAfter() {
309 TmfTimeRange beforeTr
= tm
.getCurrentTraceContext().getSelectionRange();
310 ITmfTimestamp ts
= new TmfTimestamp(t2end
+ ONE_SECOND
, SCALE
);
313 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
314 assertEquals(beforeTr
, selection
);
318 * Test selecting a normal sub-range of a single trace.
321 public void testTraceNewTimeRange() {
323 TmfTimeRange range
= new TmfTimeRange(
324 new TmfTimestamp(t2start
+ ONE_SECOND
, SCALE
),
325 new TmfTimestamp(t2end
- ONE_SECOND
, SCALE
));
326 selectWindowRange(range
);
328 TmfTimeRange curRange
= tm
.getCurrentTraceContext().getWindowRange();
329 assertEquals(range
, curRange
);
333 * Test selecting a range whose start time is before the trace's start time.
334 * The selected range should get clamped to the trace's range.
337 public void testTraceTimeRangeClampingStart() {
339 TmfTimeRange range
= new TmfTimeRange(
340 new TmfTimestamp(t2start
- ONE_SECOND
, SCALE
), // minus here
341 new TmfTimestamp(t2end
- ONE_SECOND
, SCALE
));
342 selectWindowRange(range
);
344 TmfTimeRange curRange
= tm
.getCurrentTraceContext().getWindowRange();
345 assertEquals(t2start
, curRange
.getStartTime().getValue());
346 assertEquals(range
.getEndTime(), curRange
.getEndTime());
350 * Test selecting a range whose end time is after the trace's end time.
351 * The selected range should get clamped to the trace's range.
354 public void testTraceTimeRangeClampingEnd() {
356 TmfTimeRange range
= new TmfTimeRange(
357 new TmfTimestamp(t2start
+ ONE_SECOND
, SCALE
),
358 new TmfTimestamp(t2end
+ ONE_SECOND
, SCALE
)); // plus here
359 selectWindowRange(range
);
361 TmfTimeRange curRange
= tm
.getCurrentTraceContext().getWindowRange();
362 assertEquals(range
.getStartTime(), curRange
.getStartTime());
363 assertEquals(t2end
, curRange
.getEndTime().getValue());
367 * Test selecting a range whose both start and end times are outside of the
368 * trace's range. The selected range should get clamped to the trace's
372 public void testTraceTimeRangeClampingBoth() {
374 TmfTimeRange range
= new TmfTimeRange(
375 new TmfTimestamp(t2start
- ONE_SECOND
, SCALE
), // minus here
376 new TmfTimestamp(t2end
+ ONE_SECOND
, SCALE
)); // plus here
377 selectWindowRange(range
);
379 TmfTimeRange curRange
= tm
.getCurrentTraceContext().getWindowRange();
380 assertEquals(t2start
, curRange
.getStartTime().getValue());
381 assertEquals(t2end
, curRange
.getEndTime().getValue());
384 // ------------------------------------------------------------------------
385 // Test multiple, non-overlapping traces in parallel
386 // ------------------------------------------------------------------------
389 * Test, with two traces in parallel, when we select a timestamp that is
390 * part of the first trace.
392 * The first trace's timestamp should be updated, but the second trace's one
396 public void testTwoTracesTimestampValid() {
400 TmfTimestamp ts
= new TmfTimestamp(t1start
+ ONE_SECOND
, SCALE
);
403 /* Timestamp of trace1 should have been updated */
404 TmfTraceContext ctx
= tm
.getCurrentTraceContext();
405 assertEquals(ts
, ctx
.getSelectionRange().getStartTime());
406 assertEquals(ts
, ctx
.getSelectionRange().getEndTime());
408 /* Timestamp of trace2 should not have changed */
410 ctx
= tm
.getCurrentTraceContext();
411 assertEquals(trace2
.getStartTime(), ctx
.getSelectionRange().getStartTime());
412 assertEquals(trace2
.getStartTime(), ctx
.getSelectionRange().getEndTime());
416 * Test, with two traces in parallel, when we select a timestamp that is
417 * between two traces.
419 * None of the trace's timestamps should be updated (we are not in an
423 public void testTwoTracesTimestampInBetween() {
427 TmfTimestamp ts
= new TmfTimestamp(t1end
+ ONE_SECOND
, SCALE
);
430 /* Timestamp of trace1 should not have changed */
431 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
432 assertEquals(trace1
.getStartTime(), selection
.getStartTime());
433 assertEquals(trace1
.getStartTime(), selection
.getEndTime());
435 /* Timestamp of trace2 should not have changed */
437 selection
= tm
.getCurrentTraceContext().getSelectionRange();
438 assertEquals(trace2
.getStartTime(), selection
.getStartTime());
439 assertEquals(trace2
.getStartTime(), selection
.getEndTime());
443 * Test, with two traces in parallel, when we select a timestamp that is
444 * completely out of the trace's range.
446 * None of the trace's timestamps should be updated.
449 public void testTwoTracesTimestampInvalid() {
453 TmfTimestamp ts
= new TmfTimestamp(t2end
+ ONE_SECOND
, SCALE
);
456 /* Timestamp of trace1 should not have changed */
457 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
458 assertEquals(trace1
.getStartTime(), selection
.getStartTime());
459 assertEquals(trace1
.getStartTime(), selection
.getEndTime());
461 /* Timestamp of trace2 should not have changed */
463 selection
= tm
.getCurrentTraceContext().getSelectionRange();
464 assertEquals(trace2
.getStartTime(), selection
.getStartTime());
465 assertEquals(trace2
.getStartTime(), selection
.getEndTime());
469 * Test, with two traces opened in parallel (not in an experiment), if we
470 * select a time range valid in one of them. That trace's time range should
471 * be updated, but not the other one.
474 public void testTwoTracesTimeRangeAllInOne() {
478 TmfTimeRange range
= new TmfTimeRange(
479 new TmfTimestamp(t1start
+ ONE_SECOND
, SCALE
),
480 new TmfTimestamp(t1end
- ONE_SECOND
, SCALE
));
481 selectWindowRange(range
);
483 /* Range of trace1 should be equal to the requested one */
484 assertEquals(range
, tm
.getCurrentTraceContext().getWindowRange());
486 /* The range of trace 2 should not have changed */
488 assertEquals(getInitialRange(trace2
), tm
.getCurrentTraceContext().getWindowRange());
492 * Test, with two traces in parallel, when we select a time range that is
493 * only partially valid for one of the traces.
495 * The first trace's time range should be clamped to a valid range, and the
496 * second one's should not change.
499 public void testTwoTracesTimeRangePartiallyInOne() {
503 TmfTimeRange range
= new TmfTimeRange(
504 new TmfTimestamp(t1start
+ ONE_SECOND
, SCALE
),
505 new TmfTimestamp(t1end
+ ONE_SECOND
, SCALE
));
506 selectWindowRange(range
);
508 /* Range of trace1 should get clamped to its end time */
509 TmfTimeRange expectedRange
= new TmfTimeRange(
510 new TmfTimestamp(t1start
+ ONE_SECOND
, SCALE
),
511 new TmfTimestamp(t1end
, SCALE
));
512 assertEquals(expectedRange
, tm
.getCurrentTraceContext().getWindowRange());
514 /* Range of trace2 should not have changed */
516 assertEquals(getInitialRange(trace2
), tm
.getCurrentTraceContext().getWindowRange());
520 * Test, with two traces in parallel, when we select a time range that is
521 * only partially valid for both traces.
523 * Each trace's time range should get clamped to respectively valid ranges.
526 public void testTwoTracesTimeRangeInBoth() {
530 TmfTimeRange range
= new TmfTimeRange(
531 new TmfTimestamp(t1end
- ONE_SECOND
, SCALE
),
532 new TmfTimestamp(t2start
+ ONE_SECOND
, SCALE
));
533 selectWindowRange(range
);
535 /* Range of trace1 should be clamped to its end time */
536 TmfTimeRange expectedRange
= new TmfTimeRange(
537 new TmfTimestamp(t1end
- ONE_SECOND
, SCALE
),
538 new TmfTimestamp(t1end
, SCALE
));
539 assertEquals(expectedRange
, tm
.getCurrentTraceContext().getWindowRange());
541 /* Range of trace2 should be clamped to its start time */
543 expectedRange
= new TmfTimeRange(
544 new TmfTimestamp(t2start
, SCALE
),
545 new TmfTimestamp(t2start
+ ONE_SECOND
, SCALE
));
546 assertEquals(expectedRange
, tm
.getCurrentTraceContext().getWindowRange());
550 * Test, with two traces in parallel, when we select a time range that is
551 * not valid for any trace.
553 * Each trace's time range should not be modified.
556 public void testTwoTracesTimeRangeInBetween() {
560 TmfTimeRange range
= new TmfTimeRange(
561 new TmfTimestamp(t1end
+ ONE_SECOND
, SCALE
),
562 new TmfTimestamp(t1end
- ONE_SECOND
, SCALE
));
563 selectWindowRange(range
);
565 /* Range of trace1 should not have changed */
566 TmfTimeRange expectedRange
= getInitialRange(trace1
);
567 TmfTimeRange curRange
= tm
.getCurrentTraceContext().getWindowRange();
568 assertEquals(expectedRange
.getStartTime(), curRange
.getStartTime());
569 assertEquals(expectedRange
.getEndTime(), curRange
.getEndTime());
571 /* Range of trace2 should not have changed */
573 expectedRange
= getInitialRange(trace2
);
574 curRange
= tm
.getCurrentTraceContext().getWindowRange();
575 assertEquals(expectedRange
.getStartTime(), curRange
.getStartTime());
576 assertEquals(expectedRange
.getEndTime(), curRange
.getEndTime());
579 // ------------------------------------------------------------------------
580 // Test an experiment
581 // ------------------------------------------------------------------------
584 * Test in an experiment when we select a timestamp that is part of one of
585 * the experiment's traces.
587 * The experiment's current time should be correctly updated.
590 public void testExperimentTimestampInTrace() {
591 TmfExperiment exp
= createExperiment(trace1
, trace2
);
593 TmfTimestamp ts
= new TmfTimestamp(t1start
+ ONE_SECOND
, SCALE
);
596 /* The experiment's current time should be updated. */
597 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
598 assertEquals(ts
, selection
.getStartTime());
599 assertEquals(ts
, selection
.getEndTime());
603 * Test in an experiment when we select a timestamp that is between two
604 * traces in the experiment.
606 * The experiment's current time should still be updated, since the
607 * timestamp is valid in the experiment itself.
610 public void testExperimentTimestampInBetween() {
611 TmfExperiment exp
= createExperiment(trace1
, trace2
);
613 TmfTimestamp ts
= new TmfTimestamp(t1end
+ ONE_SECOND
, SCALE
);
616 /* The experiment's current time should be updated. */
617 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
618 assertEquals(ts
, selection
.getStartTime());
619 assertEquals(ts
, selection
.getEndTime());
623 * Test in an experiment when we select a timestamp that is outside of the
624 * total range of the experiment.
626 * The experiment's current time should not be updated.
629 public void testExperimentTimestampInvalid() {
630 TmfExperiment exp
= createExperiment(trace1
, trace2
);
632 TmfTimestamp ts
= new TmfTimestamp(t2end
+ ONE_SECOND
, SCALE
);
635 /* The experiment's current time should NOT be updated. */
636 TmfTimeRange selection
= tm
.getCurrentTraceContext().getSelectionRange();
637 assertEquals(trace1
.getStartTime(), selection
.getStartTime());
638 assertEquals(trace1
.getStartTime(), selection
.getEndTime());
642 * Test the initial range of an experiment.
645 public void testExperimentInitialRange() {
646 TmfExperiment exp
= createExperiment(trace1
, trace2
);
649 * The initial range should be == to the initial range of the earliest
650 * trace (here trace1).
652 final TmfTimeRange actualRange
= tm
.getCurrentTraceContext().getWindowRange();
654 assertEquals(getInitialRange(trace1
), actualRange
);
655 assertEquals(getInitialRange(exp
), actualRange
);
659 * Test the range clamping with the start time of the range outside of the
660 * earliest trace's range. Only that start time should get clamped.
663 public void testExperimentRangeClampingOne() {
664 TmfExperiment exp
= createExperiment(trace1
, trace2
);
667 final TmfTimeRange range
= new TmfTimeRange(
668 new TmfTimestamp(t1start
- ONE_SECOND
, SCALE
),
669 new TmfTimestamp(t1end
- ONE_SECOND
, SCALE
));
670 selectWindowRange(range
);
672 TmfTimeRange actualRange
= tm
.getCurrentTraceContext().getWindowRange();
673 assertEquals(t1start
, actualRange
.getStartTime().getValue());
674 assertEquals(t1end
- ONE_SECOND
, actualRange
.getEndTime().getValue());
678 * Test the range clamping when both the start and end times of the signal's
679 * range are outside of the trace's range. The range should clamp to the
680 * experiment's range.
683 public void testExperimentRangeClampingBoth() {
684 TmfExperiment exp
= createExperiment(trace1
, trace2
);
687 final TmfTimeRange range
= new TmfTimeRange(
688 new TmfTimestamp(t1start
- ONE_SECOND
, SCALE
),
689 new TmfTimestamp(t2end
+ ONE_SECOND
, SCALE
));
690 selectWindowRange(range
);
692 TmfTimeRange actualRange
= tm
.getCurrentTraceContext().getWindowRange();
693 assertEquals(t1start
, actualRange
.getStartTime().getValue());
694 assertEquals(t2end
, actualRange
.getEndTime().getValue());
698 * Test selecting a range in-between two disjoint traces in an experiment.
699 * The range should still get correctly selected, even if no trace has any
700 * events in that range.
703 public void testExperimentRangeInBetween() {
704 TmfExperiment exp
= createExperiment(trace1
, trace2
);
707 final TmfTimeRange range
= new TmfTimeRange(
708 new TmfTimestamp(t1end
+ ONE_SECOND
, SCALE
),
709 new TmfTimestamp(t2start
- ONE_SECOND
, SCALE
));
710 selectWindowRange(range
);
712 TmfTimeRange actualRange
= tm
.getCurrentTraceContext().getWindowRange();
713 assertEquals(range
, actualRange
);
716 // ------------------------------------------------------------------------
718 // ------------------------------------------------------------------------
720 private static TmfExperiment
createExperiment(ITmfTrace t1
, ITmfTrace t2
) {
721 ITmfTrace
[] traces
= new ITmfTrace
[] { t1
, t2
};
722 TmfExperiment exp
= new TmfExperiment(ITmfEvent
.class, "test-exp", traces
,
723 TmfExperiment
.DEFAULT_INDEX_PAGE_SIZE
, null);
724 exp
.indexTrace(true);
725 // Deregister experiment from signal manager so that it doesn't
726 // interfere with the TmfTraceManager tests
727 TmfSignalManager
.deregister(exp
);
731 private static TmfTimeRange
getInitialRange(ITmfTrace trace
) {
732 return new TmfTimeRange(
733 trace
.getStartTime(),
734 calculateOffset(trace
.getStartTime(), trace
.getInitialRangeOffset()));
738 * Basically a "initial + offset" operation, but for ITmfTimetamp objects.
740 private static @NonNull ITmfTimestamp
calculateOffset(ITmfTimestamp initialTs
, ITmfTimestamp offsetTs
) {
741 long start
= initialTs
.normalize(0, SCALE
).getValue();
742 long offset
= offsetTs
.normalize(0, SCALE
).getValue();
743 return new TmfTimestamp(start
+ offset
, SCALE
);