tmf: Add utility method to delete supplementary files of a trace
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.core.tests / src / org / eclipse / tracecompass / tmf / ctf / core / tests / temp / tracemanager / TmfTraceManagerTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
11 * Patrick Tasse - Support selection range
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.tracemanager;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertNotNull;
18 import static org.junit.Assert.assertSame;
19
20 import java.util.Collection;
21 import java.util.Collections;
22 import java.util.concurrent.TimeUnit;
23
24 import org.eclipse.jdt.annotation.NonNull;
25 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
26 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
27 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
28 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
29 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal;
30 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
31 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
32 import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
33 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
34 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
35 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
36 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
37 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext;
38 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
39 import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
40 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
41 import org.junit.After;
42 import org.junit.AfterClass;
43 import org.junit.Before;
44 import org.junit.BeforeClass;
45 import org.junit.Rule;
46 import org.junit.Test;
47 import org.junit.rules.TestRule;
48 import org.junit.rules.Timeout;
49
50 import com.google.common.collect.ImmutableSet;
51
52 /**
53 * Test suite for the {@link TmfTraceManager}.
54 *
55 * @author Alexandre Montplaisir
56 */
57 public class TmfTraceManagerTest {
58
59 /** Time-out tests after 1 minute. */
60 @Rule
61 public TestRule globalTimeout = new Timeout(1, TimeUnit.MINUTES);
62
63 private static ITmfTrace trace1;
64 private static final long t1start = 1331668247314038062L;
65 private static final long t1end = 1331668259054285979L;
66
67 private static ITmfTrace trace2;
68 private static final long t2start = 1332170682440133097L;
69 private static final long t2end = 1332170692664579801L;
70
71 private static final long ONE_SECOND = 1000000000L;
72
73 private TmfTraceManager tm;
74
75 /**
76 * Test class initialization
77 */
78 @BeforeClass
79 public static void setUpClass() {
80 trace1 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.TRACE2);
81 trace2 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.KERNEL);
82
83 trace1.indexTrace(true);
84 trace2.indexTrace(true);
85
86 // Deregister traces from signal manager so that they don't
87 // interfere with the TmfTraceManager tests
88 TmfSignalManager.deregister(trace1);
89 TmfSignalManager.deregister(trace2);
90 }
91
92 /**
93 * Test initialization
94 */
95 @Before
96 public void setUp() {
97 tm = TmfTraceManager.getInstance();
98 }
99
100 /**
101 * Test clean-up
102 */
103 @After
104 public void tearDown() {
105 while (tm.getActiveTrace() != null) {
106 closeTrace(tm.getActiveTrace());
107 }
108 }
109
110 /**
111 * Test class clean-up
112 */
113 @AfterClass
114 public static void tearDownClass() {
115 CtfTmfTestTraceUtils.dispose(CtfTestTrace.TRACE2);
116 CtfTmfTestTraceUtils.dispose(CtfTestTrace.KERNEL);
117 }
118
119 // ------------------------------------------------------------------------
120 // Dummy actions (fake signals)
121 // ------------------------------------------------------------------------
122
123 private void openTrace(ITmfTrace trace) {
124 if (trace == null) {
125 throw new IllegalArgumentException();
126 }
127 TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, trace, null));
128 selectTrace(trace);
129 }
130
131 private void closeTrace(ITmfTrace trace) {
132 if (trace == null) {
133 throw new IllegalArgumentException();
134 }
135 TmfSignalManager.dispatchSignal(new TmfTraceClosedSignal(this, trace));
136 /*
137 * In TMF, the next tab would now be selected (if there are some), which
138 * would select another trace automatically.
139 */
140 if (tm.getOpenedTraces().size() > 0) {
141 selectTrace(tm.getOpenedTraces().toArray(new ITmfTrace[0])[0]);
142 }
143 }
144
145 private void selectTrace(ITmfTrace trace) {
146 TmfSignalManager.dispatchSignal(new TmfTraceSelectedSignal(this, trace));
147 }
148
149 private void selectTimestamp(@NonNull ITmfTimestamp ts) {
150 TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, ts));
151 }
152
153 private void selectWindowRange(TmfTimeRange tr) {
154 TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, tr));
155 }
156
157 // ------------------------------------------------------------------------
158 // General tests
159 // ------------------------------------------------------------------------
160
161 /**
162 * Test that the manager is correctly initialized
163 */
164 @Test
165 public void testInitialize() {
166 TmfTraceManager mgr = TmfTraceManager.getInstance();
167 assertNotNull(mgr);
168 assertSame(tm, mgr);
169 }
170
171 /**
172 * Test the contents of a trace set with one trace.
173 */
174 @Test
175 public void testTraceSet() {
176 openTrace(trace1);
177 openTrace(trace2);
178 selectTrace(trace2);
179
180 Collection<ITmfTrace> expected = Collections.singleton(trace2);
181 Collection<ITmfTrace> actual = tm.getActiveTraceSet();
182
183 assertEquals(1, actual.size());
184 assertEquals(expected, actual);
185 }
186
187 /**
188 * Test the contents of a trace set with an experiment.
189 */
190 @Test
191 public void testTraceSetExperiment() {
192 final ITmfTrace localTrace1 = trace1;
193 final ITmfTrace localTrace2 = trace2;
194 assertNotNull(localTrace1);
195 assertNotNull(localTrace2);
196 TmfExperiment exp = createExperiment(localTrace1, localTrace2);
197 openTrace(localTrace1);
198 openTrace(exp);
199
200 Collection<ITmfTrace> expected = ImmutableSet.of(localTrace1, localTrace2);
201 Collection<ITmfTrace> actual = tm.getActiveTraceSet();
202
203 assertEquals(2, actual.size());
204 assertEquals(expected, actual);
205 }
206
207 /**
208 * Test the contents of the complete trace set.
209 */
210 @Test
211 public void testTraceSetWithExperiment() {
212 final ITmfTrace localTrace1 = trace1;
213 final ITmfTrace localTrace2 = trace2;
214 assertNotNull(localTrace1);
215 assertNotNull(localTrace2);
216 /* Test with a trace */
217 Collection<ITmfTrace> expected = Collections.singleton(localTrace1);
218 Collection<ITmfTrace> actual = TmfTraceManager.getTraceSetWithExperiment(localTrace1);
219 assertEquals(1, actual.size());
220 assertEquals(expected, actual);
221
222 /* Test with an experiment */
223 TmfExperiment exp = createExperiment(localTrace1, localTrace2);
224 assertNotNull(exp);
225 expected = ImmutableSet.of(localTrace1, localTrace2, exp);
226 actual = TmfTraceManager.getTraceSetWithExperiment(exp);
227 assertEquals(3, actual.size());
228 assertEquals(expected, actual);
229 }
230
231 // ------------------------------------------------------------------------
232 // Test a single trace
233 // ------------------------------------------------------------------------
234
235 /**
236 * Test the initial range of a single trace.
237 */
238 @Test
239 public void testTraceInitialRange() {
240 openTrace(trace2);
241 final TmfTimeRange expectedRange = new TmfTimeRange(
242 trace2.getStartTime(),
243 calculateOffset(trace2.getStartTime(), trace2.getInitialRangeOffset()));
244 TmfTimeRange actualRange = tm.getCurrentTraceContext().getWindowRange();
245 assertEquals(expectedRange, actualRange);
246 }
247
248 /**
249 * Try selecting a timestamp contained inside the trace's range. The trace's
250 * current time should get updated correctly.
251 */
252 @Test
253 public void testNewTimestamp() {
254 openTrace(trace2);
255 ITmfTimestamp ts = TmfTimestamp.fromNanos(t2start + ONE_SECOND);
256 selectTimestamp(ts);
257
258 TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange();
259 assertEquals(ts, selection.getStartTime());
260 assertEquals(ts, selection.getEndTime());
261 }
262
263 /**
264 * Try selecting a timestamp happening before the trace's start. The change
265 * should be ignored.
266 */
267 @Test
268 public void testTimestampBefore() {
269 openTrace(trace2);
270 TmfTimeRange beforeTr = tm.getCurrentTraceContext().getSelectionRange();
271 ITmfTimestamp ts = TmfTimestamp.fromNanos(t2start - ONE_SECOND);
272 selectTimestamp(ts);
273
274 TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange();
275 assertEquals(beforeTr, selection);
276 }
277
278 /**
279 * Try selecting a timestamp happening after the trace's end. The change
280 * should be ignored.
281 */
282 @Test
283 public void testTimestampAfter() {
284 openTrace(trace2);
285 TmfTimeRange beforeTr = tm.getCurrentTraceContext().getSelectionRange();
286 ITmfTimestamp ts = TmfTimestamp.fromNanos(t2end + ONE_SECOND);
287 selectTimestamp(ts);
288
289 TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange();
290 assertEquals(beforeTr, selection);
291 }
292
293 /**
294 * Test selecting a normal sub-range of a single trace.
295 */
296 @Test
297 public void testTraceNewTimeRange() {
298 openTrace(trace2);
299 TmfTimeRange range = new TmfTimeRange(
300 TmfTimestamp.fromNanos(t2start + ONE_SECOND),
301 TmfTimestamp.fromNanos(t2end - ONE_SECOND));
302 selectWindowRange(range);
303
304 TmfTimeRange curRange = tm.getCurrentTraceContext().getWindowRange();
305 assertEquals(range, curRange);
306 }
307
308 /**
309 * Test selecting a range whose start time is before the trace's start time.
310 * The selected range should get clamped to the trace's range.
311 */
312 @Test
313 public void testTraceTimeRangeClampingStart() {
314 openTrace(trace2);
315 TmfTimeRange range = new TmfTimeRange(
316 TmfTimestamp.fromNanos(t2start - ONE_SECOND), // minus here
317 TmfTimestamp.fromNanos(t2end - ONE_SECOND));
318 selectWindowRange(range);
319
320 TmfTimeRange curRange = tm.getCurrentTraceContext().getWindowRange();
321 assertEquals(t2start, curRange.getStartTime().getValue());
322 assertEquals(range.getEndTime(), curRange.getEndTime());
323 }
324
325 /**
326 * Test selecting a range whose end time is after the trace's end time. The
327 * selected range should get clamped to the trace's range.
328 */
329 @Test
330 public void testTraceTimeRangeClampingEnd() {
331 openTrace(trace2);
332 TmfTimeRange range = new TmfTimeRange(
333 TmfTimestamp.fromNanos(t2start + ONE_SECOND),
334 TmfTimestamp.fromNanos(t2end + ONE_SECOND)); // plus here
335 selectWindowRange(range);
336
337 TmfTimeRange curRange = tm.getCurrentTraceContext().getWindowRange();
338 assertEquals(range.getStartTime(), curRange.getStartTime());
339 assertEquals(t2end, curRange.getEndTime().getValue());
340 }
341
342 /**
343 * Test selecting a range whose both start and end times are outside of the
344 * trace's range. The selected range should get clamped to the trace's
345 * range.
346 */
347 @Test
348 public void testTraceTimeRangeClampingBoth() {
349 openTrace(trace2);
350 TmfTimeRange range = new TmfTimeRange(
351 TmfTimestamp.fromNanos(t2start - ONE_SECOND), // minus here
352 TmfTimestamp.fromNanos(t2end + ONE_SECOND)); // plus here
353 selectWindowRange(range);
354
355 TmfTimeRange curRange = tm.getCurrentTraceContext().getWindowRange();
356 assertEquals(t2start, curRange.getStartTime().getValue());
357 assertEquals(t2end, curRange.getEndTime().getValue());
358 }
359
360 // ------------------------------------------------------------------------
361 // Test multiple, non-overlapping traces in parallel
362 // ------------------------------------------------------------------------
363
364 /**
365 * Test, with two traces in parallel, when we select a timestamp that is
366 * part of the first trace.
367 *
368 * The first trace's timestamp should be updated, but the second trace's one
369 * should not change.
370 */
371 @Test
372 public void testTwoTracesTimestampValid() {
373 openTrace(trace1);
374 openTrace(trace2);
375 selectTrace(trace1);
376 ITmfTimestamp ts = TmfTimestamp.fromNanos(t1start + ONE_SECOND);
377 selectTimestamp(ts);
378
379 /* Timestamp of trace1 should have been updated */
380 TmfTraceContext ctx = tm.getCurrentTraceContext();
381 assertEquals(ts, ctx.getSelectionRange().getStartTime());
382 assertEquals(ts, ctx.getSelectionRange().getEndTime());
383
384 /* Timestamp of trace2 should not have changed */
385 selectTrace(trace2);
386 ctx = tm.getCurrentTraceContext();
387 assertEquals(trace2.getStartTime(), ctx.getSelectionRange().getStartTime());
388 assertEquals(trace2.getStartTime(), ctx.getSelectionRange().getEndTime());
389 }
390
391 /**
392 * Test, with two traces in parallel, when we select a timestamp that is
393 * between two traces.
394 *
395 * None of the trace's timestamps should be updated (we are not in an
396 * experiment!)
397 */
398 @Test
399 public void testTwoTracesTimestampInBetween() {
400 openTrace(trace1);
401 openTrace(trace2);
402 selectTrace(trace1);
403 ITmfTimestamp ts = TmfTimestamp.fromNanos(t1end + ONE_SECOND);
404 selectTimestamp(ts);
405
406 /* Timestamp of trace1 should not have changed */
407 TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange();
408 assertEquals(trace1.getStartTime(), selection.getStartTime());
409 assertEquals(trace1.getStartTime(), selection.getEndTime());
410
411 /* Timestamp of trace2 should not have changed */
412 selectTrace(trace2);
413 selection = tm.getCurrentTraceContext().getSelectionRange();
414 assertEquals(trace2.getStartTime(), selection.getStartTime());
415 assertEquals(trace2.getStartTime(), selection.getEndTime());
416 }
417
418 /**
419 * Test, with two traces in parallel, when we select a timestamp that is
420 * completely out of the trace's range.
421 *
422 * None of the trace's timestamps should be updated.
423 */
424 @Test
425 public void testTwoTracesTimestampInvalid() {
426 openTrace(trace1);
427 openTrace(trace2);
428 selectTrace(trace1);
429 ITmfTimestamp ts = TmfTimestamp.fromNanos(t2end + ONE_SECOND);
430 selectTimestamp(ts);
431
432 /* Timestamp of trace1 should not have changed */
433 TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange();
434 assertEquals(trace1.getStartTime(), selection.getStartTime());
435 assertEquals(trace1.getStartTime(), selection.getEndTime());
436
437 /* Timestamp of trace2 should not have changed */
438 selectTrace(trace2);
439 selection = tm.getCurrentTraceContext().getSelectionRange();
440 assertEquals(trace2.getStartTime(), selection.getStartTime());
441 assertEquals(trace2.getStartTime(), selection.getEndTime());
442 }
443
444 /**
445 * Test, with two traces opened in parallel (not in an experiment), if we
446 * select a time range valid in one of them. That trace's time range should
447 * be updated, but not the other one.
448 */
449 @Test
450 public void testTwoTracesTimeRangeAllInOne() {
451 openTrace(trace1);
452 openTrace(trace2);
453 selectTrace(trace1);
454 TmfTimeRange range = new TmfTimeRange(
455 TmfTimestamp.fromNanos(t1start + ONE_SECOND),
456 TmfTimestamp.fromNanos(t1end - ONE_SECOND));
457 selectWindowRange(range);
458
459 /* Range of trace1 should be equal to the requested one */
460 assertEquals(range, tm.getCurrentTraceContext().getWindowRange());
461
462 /* The range of trace 2 should not have changed */
463 selectTrace(trace2);
464 assertEquals(getInitialRange(trace2), tm.getCurrentTraceContext().getWindowRange());
465 }
466
467 /**
468 * Test, with two traces in parallel, when we select a time range that is
469 * only partially valid for one of the traces.
470 *
471 * The first trace's time range should be clamped to a valid range, and the
472 * second one's should not change.
473 */
474 @Test
475 public void testTwoTracesTimeRangePartiallyInOne() {
476 openTrace(trace1);
477 openTrace(trace2);
478 selectTrace(trace1);
479 TmfTimeRange range = new TmfTimeRange(
480 TmfTimestamp.fromNanos(t1start + ONE_SECOND),
481 TmfTimestamp.fromNanos(t1end + ONE_SECOND));
482 selectWindowRange(range);
483
484 /* Range of trace1 should get clamped to its end time */
485 TmfTimeRange expectedRange = new TmfTimeRange(
486 TmfTimestamp.fromNanos(t1start + ONE_SECOND),
487 TmfTimestamp.fromNanos(t1end));
488 assertEquals(expectedRange, tm.getCurrentTraceContext().getWindowRange());
489
490 /* Range of trace2 should not have changed */
491 selectTrace(trace2);
492 assertEquals(getInitialRange(trace2), tm.getCurrentTraceContext().getWindowRange());
493 }
494
495 /**
496 * Test, with two traces in parallel, when we select a time range that is
497 * only partially valid for both traces.
498 *
499 * Each trace's time range should get clamped to respectively valid ranges.
500 */
501 @Test
502 public void testTwoTracesTimeRangeInBoth() {
503 openTrace(trace1);
504 openTrace(trace2);
505 selectTrace(trace1);
506 TmfTimeRange range = new TmfTimeRange(
507 TmfTimestamp.fromNanos(t1end - ONE_SECOND),
508 TmfTimestamp.fromNanos(t2start + ONE_SECOND));
509 selectWindowRange(range);
510
511 /* Range of trace1 should be clamped to its end time */
512 TmfTimeRange expectedRange = new TmfTimeRange(
513 TmfTimestamp.fromNanos(t1end - ONE_SECOND),
514 TmfTimestamp.fromNanos(t1end));
515 assertEquals(expectedRange, tm.getCurrentTraceContext().getWindowRange());
516
517 /* Range of trace2 should be clamped to its start time */
518 selectTrace(trace2);
519 expectedRange = new TmfTimeRange(
520 TmfTimestamp.fromNanos(t2start),
521 TmfTimestamp.fromNanos(t2start + ONE_SECOND));
522 assertEquals(expectedRange, tm.getCurrentTraceContext().getWindowRange());
523 }
524
525 /**
526 * Test, with two traces in parallel, when we select a time range that is
527 * not valid for any trace.
528 *
529 * Each trace's time range should not be modified.
530 */
531 @Test
532 public void testTwoTracesTimeRangeInBetween() {
533 openTrace(trace1);
534 openTrace(trace2);
535 selectTrace(trace1);
536 TmfTimeRange range = new TmfTimeRange(
537 TmfTimestamp.fromNanos(t1end + ONE_SECOND),
538 TmfTimestamp.fromNanos(t1end - ONE_SECOND));
539 selectWindowRange(range);
540
541 /* Range of trace1 should not have changed */
542 TmfTimeRange expectedRange = getInitialRange(trace1);
543 TmfTimeRange curRange = tm.getCurrentTraceContext().getWindowRange();
544 assertEquals(expectedRange.getStartTime(), curRange.getStartTime());
545 assertEquals(expectedRange.getEndTime(), curRange.getEndTime());
546
547 /* Range of trace2 should not have changed */
548 selectTrace(trace2);
549 expectedRange = getInitialRange(trace2);
550 curRange = tm.getCurrentTraceContext().getWindowRange();
551 assertEquals(expectedRange.getStartTime(), curRange.getStartTime());
552 assertEquals(expectedRange.getEndTime(), curRange.getEndTime());
553 }
554
555 // ------------------------------------------------------------------------
556 // Test an experiment
557 // ------------------------------------------------------------------------
558
559 /**
560 * Test in an experiment when we select a timestamp that is part of one of
561 * the experiment's traces.
562 *
563 * The experiment's current time should be correctly updated.
564 */
565 @Test
566 public void testExperimentTimestampInTrace() {
567 TmfExperiment exp = createExperiment(trace1, trace2);
568 openTrace(exp);
569 ITmfTimestamp ts = TmfTimestamp.fromNanos(t1start + ONE_SECOND);
570 selectTimestamp(ts);
571
572 /* The experiment's current time should be updated. */
573 TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange();
574 assertEquals(ts, selection.getStartTime());
575 assertEquals(ts, selection.getEndTime());
576 }
577
578 /**
579 * Test in an experiment when we select a timestamp that is between two
580 * traces in the experiment.
581 *
582 * The experiment's current time should still be updated, since the
583 * timestamp is valid in the experiment itself.
584 */
585 @Test
586 public void testExperimentTimestampInBetween() {
587 TmfExperiment exp = createExperiment(trace1, trace2);
588 openTrace(exp);
589 ITmfTimestamp ts = TmfTimestamp.fromNanos(t1end + ONE_SECOND);
590 selectTimestamp(ts);
591
592 /* The experiment's current time should be updated. */
593 TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange();
594 assertEquals(ts, selection.getStartTime());
595 assertEquals(ts, selection.getEndTime());
596 }
597
598 /**
599 * Test in an experiment when we select a timestamp that is outside of the
600 * total range of the experiment.
601 *
602 * The experiment's current time should not be updated.
603 */
604 @Test
605 public void testExperimentTimestampInvalid() {
606 TmfExperiment exp = createExperiment(trace1, trace2);
607 openTrace(exp);
608 ITmfTimestamp ts = TmfTimestamp.fromNanos(t2end + ONE_SECOND);
609 selectTimestamp(ts);
610
611 /* The experiment's current time should NOT be updated. */
612 TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange();
613 assertEquals(trace1.getStartTime(), selection.getStartTime());
614 assertEquals(trace1.getStartTime(), selection.getEndTime());
615 }
616
617 /**
618 * Test the initial range of an experiment.
619 */
620 @Test
621 public void testExperimentInitialRange() {
622 TmfExperiment exp = createExperiment(trace1, trace2);
623 openTrace(exp);
624 /*
625 * The initial range should be == to the initial range of the earliest
626 * trace (here trace1).
627 */
628 final TmfTimeRange actualRange = tm.getCurrentTraceContext().getWindowRange();
629
630 assertEquals(getInitialRange(trace1), actualRange);
631 assertEquals(getInitialRange(exp), actualRange);
632 }
633
634 /**
635 * Test the range clamping with the start time of the range outside of the
636 * earliest trace's range. Only that start time should get clamped.
637 */
638 @Test
639 public void testExperimentRangeClampingOne() {
640 TmfExperiment exp = createExperiment(trace1, trace2);
641 openTrace(exp);
642
643 final TmfTimeRange range = new TmfTimeRange(
644 TmfTimestamp.fromNanos(t1start - ONE_SECOND),
645 TmfTimestamp.fromNanos(t1end - ONE_SECOND));
646 selectWindowRange(range);
647
648 TmfTimeRange actualRange = tm.getCurrentTraceContext().getWindowRange();
649 assertEquals(t1start, actualRange.getStartTime().getValue());
650 assertEquals(t1end - ONE_SECOND, actualRange.getEndTime().getValue());
651 }
652
653 /**
654 * Test the range clamping when both the start and end times of the signal's
655 * range are outside of the trace's range. The range should clamp to the
656 * experiment's range.
657 */
658 @Test
659 public void testExperimentRangeClampingBoth() {
660 TmfExperiment exp = createExperiment(trace1, trace2);
661 openTrace(exp);
662
663 final TmfTimeRange range = new TmfTimeRange(
664 TmfTimestamp.fromNanos(t1start - ONE_SECOND),
665 TmfTimestamp.fromNanos(t2end + ONE_SECOND));
666 selectWindowRange(range);
667
668 TmfTimeRange actualRange = tm.getCurrentTraceContext().getWindowRange();
669 assertEquals(t1start, actualRange.getStartTime().getValue());
670 assertEquals(t2end, actualRange.getEndTime().getValue());
671 }
672
673 /**
674 * Test selecting a range in-between two disjoint traces in an experiment.
675 * The range should still get correctly selected, even if no trace has any
676 * events in that range.
677 */
678 @Test
679 public void testExperimentRangeInBetween() {
680 TmfExperiment exp = createExperiment(trace1, trace2);
681 openTrace(exp);
682
683 final TmfTimeRange range = new TmfTimeRange(
684 TmfTimestamp.fromNanos(t1end + ONE_SECOND),
685 TmfTimestamp.fromNanos(t2start - ONE_SECOND));
686 selectWindowRange(range);
687
688 TmfTimeRange actualRange = tm.getCurrentTraceContext().getWindowRange();
689 assertEquals(range, actualRange);
690 }
691
692 // ------------------------------------------------------------------------
693 // Utility methods
694 // ------------------------------------------------------------------------
695
696 private static TmfExperiment createExperiment(ITmfTrace t1, ITmfTrace t2) {
697 ITmfTrace[] traces = new ITmfTrace[] { t1, t2 };
698 TmfExperiment exp = new TmfExperiment(ITmfEvent.class, "test-exp", traces,
699 TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null);
700 exp.indexTrace(true);
701 // Deregister experiment from signal manager so that it doesn't
702 // interfere with the TmfTraceManager tests
703 TmfSignalManager.deregister(exp);
704 return exp;
705 }
706
707 private static TmfTimeRange getInitialRange(ITmfTrace trace) {
708 return new TmfTimeRange(
709 trace.getStartTime(),
710 calculateOffset(trace.getStartTime(), trace.getInitialRangeOffset()));
711 }
712
713 /**
714 * Basically a "initial + offset" operation, but for ITmfTimetamp objects.
715 */
716 private static @NonNull ITmfTimestamp calculateOffset(ITmfTimestamp initialTs, ITmfTimestamp offsetTs) {
717 long start = initialTs.toNanos();
718 long offset = offsetTs.toNanos();
719 return TmfTimestamp.fromNanos(start + offset);
720 }
721 }
This page took 0.061391 seconds and 5 git commands to generate.