Commit | Line | Data |
---|---|---|
fc526aef | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2015 Ericsson |
fc526aef AM |
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 | |
0fcf3b09 | 11 | * Patrick Tasse - Support selection range |
fc526aef AM |
12 | *******************************************************************************/ |
13 | ||
9722e5d7 | 14 | package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.tracemanager; |
fc526aef AM |
15 | |
16 | import static org.junit.Assert.assertEquals; | |
17 | import static org.junit.Assert.assertNotNull; | |
fab18d20 | 18 | import static org.junit.Assert.assertSame; |
fc526aef | 19 | |
c14c0757 GB |
20 | import java.util.Collection; |
21 | import java.util.Collections; | |
c5648525 | 22 | import java.util.concurrent.TimeUnit; |
fab18d20 | 23 | |
6cfc180e | 24 | import org.eclipse.jdt.annotation.NonNull; |
c4d57ac1 | 25 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; |
2bdf0193 | 26 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
97c71024 | 27 | import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal; |
c4d57ac1 | 28 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; |
2bdf0193 AM |
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; | |
c4d57ac1 | 32 | import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal; |
2bdf0193 AM |
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; | |
21852dfa | 37 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext; |
2bdf0193 | 38 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; |
5c5fa260 | 39 | import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; |
c4d57ac1 | 40 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils; |
fc526aef | 41 | import org.junit.After; |
3568f816 | 42 | import org.junit.AfterClass; |
fc526aef AM |
43 | import org.junit.Before; |
44 | import org.junit.BeforeClass; | |
c5648525 | 45 | import org.junit.Rule; |
fc526aef | 46 | import org.junit.Test; |
c5648525 AM |
47 | import org.junit.rules.TestRule; |
48 | import org.junit.rules.Timeout; | |
fc526aef | 49 | |
0f8687b4 GB |
50 | import com.google.common.collect.ImmutableSet; |
51 | ||
fc526aef AM |
52 | /** |
53 | * Test suite for the {@link TmfTraceManager}. | |
54 | * | |
55 | * @author Alexandre Montplaisir | |
56 | */ | |
57 | public class TmfTraceManagerTest { | |
58 | ||
9e8daee1 | 59 | /** Time-out tests after 1 minute. */ |
c5648525 | 60 | @Rule |
9e8daee1 | 61 | public TestRule globalTimeout = new Timeout(1, TimeUnit.MINUTES); |
c5648525 | 62 | |
fc526aef AM |
63 | private static ITmfTrace trace1; |
64 | private static final long t1start = 1331668247314038062L; | |
16801c72 | 65 | private static final long t1end = 1331668259054285979L; |
fc526aef AM |
66 | |
67 | private static ITmfTrace trace2; | |
68 | private static final long t2start = 1332170682440133097L; | |
16801c72 | 69 | private static final long t2end = 1332170692664579801L; |
fc526aef AM |
70 | |
71 | private static final long ONE_SECOND = 1000000000L; | |
72 | ||
73 | private TmfTraceManager tm; | |
74 | ||
fc526aef AM |
75 | /** |
76 | * Test class initialization | |
77 | */ | |
78 | @BeforeClass | |
79 | public static void setUpClass() { | |
c4d57ac1 AM |
80 | trace1 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.TRACE2); |
81 | trace2 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.KERNEL); | |
fc526aef AM |
82 | |
83 | trace1.indexTrace(true); | |
84 | trace2.indexTrace(true); | |
3568f816 BH |
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); | |
fc526aef AM |
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 | ||
3568f816 BH |
110 | /** |
111 | * Test class clean-up | |
112 | */ | |
113 | @AfterClass | |
114 | public static void tearDownClass() { | |
c4d57ac1 AM |
115 | CtfTmfTestTraceUtils.dispose(CtfTestTrace.TRACE2); |
116 | CtfTmfTestTraceUtils.dispose(CtfTestTrace.KERNEL); | |
3568f816 BH |
117 | } |
118 | ||
fc526aef AM |
119 | // ------------------------------------------------------------------------ |
120 | // Dummy actions (fake signals) | |
121 | // ------------------------------------------------------------------------ | |
122 | ||
123 | private void openTrace(ITmfTrace trace) { | |
c1831960 AM |
124 | if (trace == null) { |
125 | throw new IllegalArgumentException(); | |
126 | } | |
fc526aef AM |
127 | TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, trace, null)); |
128 | selectTrace(trace); | |
129 | } | |
130 | ||
131 | private void closeTrace(ITmfTrace trace) { | |
c1831960 AM |
132 | if (trace == null) { |
133 | throw new IllegalArgumentException(); | |
134 | } | |
fc526aef | 135 | TmfSignalManager.dispatchSignal(new TmfTraceClosedSignal(this, trace)); |
fab18d20 AM |
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 | } | |
fc526aef AM |
143 | } |
144 | ||
145 | private void selectTrace(ITmfTrace trace) { | |
146 | TmfSignalManager.dispatchSignal(new TmfTraceSelectedSignal(this, trace)); | |
147 | } | |
148 | ||
6cfc180e | 149 | private void selectTimestamp(@NonNull ITmfTimestamp ts) { |
97c71024 | 150 | TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, ts)); |
fc526aef AM |
151 | } |
152 | ||
21852dfa | 153 | private void selectWindowRange(TmfTimeRange tr) { |
97c71024 | 154 | TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, tr)); |
fc526aef AM |
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); | |
fab18d20 AM |
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 | ||
c14c0757 GB |
180 | Collection<ITmfTrace> expected = Collections.singleton(trace2); |
181 | Collection<ITmfTrace> actual = tm.getActiveTraceSet(); | |
fab18d20 | 182 | |
c14c0757 GB |
183 | assertEquals(1, actual.size()); |
184 | assertEquals(expected, actual); | |
fab18d20 AM |
185 | } |
186 | ||
187 | /** | |
188 | * Test the contents of a trace set with an experiment. | |
189 | */ | |
190 | @Test | |
191 | public void testTraceSetExperiment() { | |
dbecae9c MK |
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); | |
fab18d20 AM |
198 | openTrace(exp); |
199 | ||
dbecae9c | 200 | Collection<ITmfTrace> expected = ImmutableSet.of(localTrace1, localTrace2); |
c14c0757 | 201 | Collection<ITmfTrace> actual = tm.getActiveTraceSet(); |
fab18d20 | 202 | |
c14c0757 GB |
203 | assertEquals(2, actual.size()); |
204 | assertEquals(expected, actual); | |
fab18d20 AM |
205 | } |
206 | ||
0f8687b4 GB |
207 | /** |
208 | * Test the contents of the complete trace set. | |
209 | */ | |
210 | @Test | |
211 | public void testTraceSetWithExperiment() { | |
dbecae9c MK |
212 | final ITmfTrace localTrace1 = trace1; |
213 | final ITmfTrace localTrace2 = trace2; | |
214 | assertNotNull(localTrace1); | |
215 | assertNotNull(localTrace2); | |
0f8687b4 | 216 | /* Test with a trace */ |
dbecae9c MK |
217 | Collection<ITmfTrace> expected = Collections.singleton(localTrace1); |
218 | Collection<ITmfTrace> actual = TmfTraceManager.getTraceSetWithExperiment(localTrace1); | |
0f8687b4 GB |
219 | assertEquals(1, actual.size()); |
220 | assertEquals(expected, actual); | |
221 | ||
222 | /* Test with an experiment */ | |
dbecae9c MK |
223 | TmfExperiment exp = createExperiment(localTrace1, localTrace2); |
224 | assertNotNull(exp); | |
225 | expected = ImmutableSet.of(localTrace1, localTrace2, exp); | |
0f8687b4 GB |
226 | actual = TmfTraceManager.getTraceSetWithExperiment(exp); |
227 | assertEquals(3, actual.size()); | |
228 | assertEquals(expected, actual); | |
229 | } | |
230 | ||
fc526aef AM |
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())); | |
21852dfa | 244 | TmfTimeRange actualRange = tm.getCurrentTraceContext().getWindowRange(); |
fc526aef AM |
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); | |
b2c971ec | 255 | ITmfTimestamp ts = TmfTimestamp.fromNanos(t2start + ONE_SECOND); |
fc526aef AM |
256 | selectTimestamp(ts); |
257 | ||
21852dfa AM |
258 | TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange(); |
259 | assertEquals(ts, selection.getStartTime()); | |
260 | assertEquals(ts, selection.getEndTime()); | |
fc526aef AM |
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); | |
21852dfa | 270 | TmfTimeRange beforeTr = tm.getCurrentTraceContext().getSelectionRange(); |
b2c971ec | 271 | ITmfTimestamp ts = TmfTimestamp.fromNanos(t2start - ONE_SECOND); |
fc526aef AM |
272 | selectTimestamp(ts); |
273 | ||
21852dfa AM |
274 | TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange(); |
275 | assertEquals(beforeTr, selection); | |
fc526aef AM |
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); | |
21852dfa | 285 | TmfTimeRange beforeTr = tm.getCurrentTraceContext().getSelectionRange(); |
b2c971ec | 286 | ITmfTimestamp ts = TmfTimestamp.fromNanos(t2end + ONE_SECOND); |
fc526aef AM |
287 | selectTimestamp(ts); |
288 | ||
21852dfa AM |
289 | TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange(); |
290 | assertEquals(beforeTr, selection); | |
fc526aef AM |
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( | |
b2c971ec MK |
300 | TmfTimestamp.fromNanos(t2start + ONE_SECOND), |
301 | TmfTimestamp.fromNanos(t2end - ONE_SECOND)); | |
21852dfa | 302 | selectWindowRange(range); |
fc526aef | 303 | |
21852dfa AM |
304 | TmfTimeRange curRange = tm.getCurrentTraceContext().getWindowRange(); |
305 | assertEquals(range, curRange); | |
fc526aef AM |
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( | |
b2c971ec MK |
316 | TmfTimestamp.fromNanos(t2start - ONE_SECOND), // minus here |
317 | TmfTimestamp.fromNanos(t2end - ONE_SECOND)); | |
21852dfa | 318 | selectWindowRange(range); |
fc526aef | 319 | |
21852dfa | 320 | TmfTimeRange curRange = tm.getCurrentTraceContext().getWindowRange(); |
fc526aef AM |
321 | assertEquals(t2start, curRange.getStartTime().getValue()); |
322 | assertEquals(range.getEndTime(), curRange.getEndTime()); | |
323 | } | |
324 | ||
325 | /** | |
16801c72 MK |
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. | |
fc526aef AM |
328 | */ |
329 | @Test | |
330 | public void testTraceTimeRangeClampingEnd() { | |
331 | openTrace(trace2); | |
332 | TmfTimeRange range = new TmfTimeRange( | |
b2c971ec MK |
333 | TmfTimestamp.fromNanos(t2start + ONE_SECOND), |
334 | TmfTimestamp.fromNanos(t2end + ONE_SECOND)); // plus here | |
21852dfa | 335 | selectWindowRange(range); |
fc526aef | 336 | |
21852dfa | 337 | TmfTimeRange curRange = tm.getCurrentTraceContext().getWindowRange(); |
fc526aef AM |
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( | |
b2c971ec MK |
351 | TmfTimestamp.fromNanos(t2start - ONE_SECOND), // minus here |
352 | TmfTimestamp.fromNanos(t2end + ONE_SECOND)); // plus here | |
21852dfa | 353 | selectWindowRange(range); |
fc526aef | 354 | |
21852dfa | 355 | TmfTimeRange curRange = tm.getCurrentTraceContext().getWindowRange(); |
fc526aef AM |
356 | assertEquals(t2start, curRange.getStartTime().getValue()); |
357 | assertEquals(t2end, curRange.getEndTime().getValue()); | |
358 | } | |
359 | ||
360 | // ------------------------------------------------------------------------ | |
fab18d20 | 361 | // Test multiple, non-overlapping traces in parallel |
fc526aef AM |
362 | // ------------------------------------------------------------------------ |
363 | ||
fab18d20 AM |
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); | |
b2c971ec | 376 | ITmfTimestamp ts = TmfTimestamp.fromNanos(t1start + ONE_SECOND); |
fab18d20 AM |
377 | selectTimestamp(ts); |
378 | ||
379 | /* Timestamp of trace1 should have been updated */ | |
21852dfa AM |
380 | TmfTraceContext ctx = tm.getCurrentTraceContext(); |
381 | assertEquals(ts, ctx.getSelectionRange().getStartTime()); | |
382 | assertEquals(ts, ctx.getSelectionRange().getEndTime()); | |
fab18d20 AM |
383 | |
384 | /* Timestamp of trace2 should not have changed */ | |
385 | selectTrace(trace2); | |
21852dfa AM |
386 | ctx = tm.getCurrentTraceContext(); |
387 | assertEquals(trace2.getStartTime(), ctx.getSelectionRange().getStartTime()); | |
388 | assertEquals(trace2.getStartTime(), ctx.getSelectionRange().getEndTime()); | |
fab18d20 AM |
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); | |
b2c971ec | 403 | ITmfTimestamp ts = TmfTimestamp.fromNanos(t1end + ONE_SECOND); |
fab18d20 AM |
404 | selectTimestamp(ts); |
405 | ||
406 | /* Timestamp of trace1 should not have changed */ | |
21852dfa AM |
407 | TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange(); |
408 | assertEquals(trace1.getStartTime(), selection.getStartTime()); | |
409 | assertEquals(trace1.getStartTime(), selection.getEndTime()); | |
fab18d20 AM |
410 | |
411 | /* Timestamp of trace2 should not have changed */ | |
412 | selectTrace(trace2); | |
21852dfa AM |
413 | selection = tm.getCurrentTraceContext().getSelectionRange(); |
414 | assertEquals(trace2.getStartTime(), selection.getStartTime()); | |
415 | assertEquals(trace2.getStartTime(), selection.getEndTime()); | |
fab18d20 AM |
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); | |
b2c971ec | 429 | ITmfTimestamp ts = TmfTimestamp.fromNanos(t2end + ONE_SECOND); |
fab18d20 AM |
430 | selectTimestamp(ts); |
431 | ||
432 | /* Timestamp of trace1 should not have changed */ | |
21852dfa AM |
433 | TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange(); |
434 | assertEquals(trace1.getStartTime(), selection.getStartTime()); | |
435 | assertEquals(trace1.getStartTime(), selection.getEndTime()); | |
fab18d20 AM |
436 | |
437 | /* Timestamp of trace2 should not have changed */ | |
438 | selectTrace(trace2); | |
21852dfa AM |
439 | selection = tm.getCurrentTraceContext().getSelectionRange(); |
440 | assertEquals(trace2.getStartTime(), selection.getStartTime()); | |
441 | assertEquals(trace2.getStartTime(), selection.getEndTime()); | |
fab18d20 AM |
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( | |
b2c971ec MK |
455 | TmfTimestamp.fromNanos(t1start + ONE_SECOND), |
456 | TmfTimestamp.fromNanos(t1end - ONE_SECOND)); | |
21852dfa | 457 | selectWindowRange(range); |
fab18d20 AM |
458 | |
459 | /* Range of trace1 should be equal to the requested one */ | |
21852dfa | 460 | assertEquals(range, tm.getCurrentTraceContext().getWindowRange()); |
fab18d20 AM |
461 | |
462 | /* The range of trace 2 should not have changed */ | |
463 | selectTrace(trace2); | |
21852dfa | 464 | assertEquals(getInitialRange(trace2), tm.getCurrentTraceContext().getWindowRange()); |
fab18d20 AM |
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( | |
b2c971ec MK |
480 | TmfTimestamp.fromNanos(t1start + ONE_SECOND), |
481 | TmfTimestamp.fromNanos(t1end + ONE_SECOND)); | |
21852dfa | 482 | selectWindowRange(range); |
fab18d20 AM |
483 | |
484 | /* Range of trace1 should get clamped to its end time */ | |
485 | TmfTimeRange expectedRange = new TmfTimeRange( | |
b2c971ec MK |
486 | TmfTimestamp.fromNanos(t1start + ONE_SECOND), |
487 | TmfTimestamp.fromNanos(t1end)); | |
21852dfa | 488 | assertEquals(expectedRange, tm.getCurrentTraceContext().getWindowRange()); |
fab18d20 AM |
489 | |
490 | /* Range of trace2 should not have changed */ | |
491 | selectTrace(trace2); | |
21852dfa | 492 | assertEquals(getInitialRange(trace2), tm.getCurrentTraceContext().getWindowRange()); |
fab18d20 AM |
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( | |
b2c971ec MK |
507 | TmfTimestamp.fromNanos(t1end - ONE_SECOND), |
508 | TmfTimestamp.fromNanos(t2start + ONE_SECOND)); | |
21852dfa | 509 | selectWindowRange(range); |
fab18d20 AM |
510 | |
511 | /* Range of trace1 should be clamped to its end time */ | |
512 | TmfTimeRange expectedRange = new TmfTimeRange( | |
b2c971ec MK |
513 | TmfTimestamp.fromNanos(t1end - ONE_SECOND), |
514 | TmfTimestamp.fromNanos(t1end)); | |
21852dfa | 515 | assertEquals(expectedRange, tm.getCurrentTraceContext().getWindowRange()); |
fab18d20 AM |
516 | |
517 | /* Range of trace2 should be clamped to its start time */ | |
518 | selectTrace(trace2); | |
519 | expectedRange = new TmfTimeRange( | |
b2c971ec MK |
520 | TmfTimestamp.fromNanos(t2start), |
521 | TmfTimestamp.fromNanos(t2start + ONE_SECOND)); | |
21852dfa | 522 | assertEquals(expectedRange, tm.getCurrentTraceContext().getWindowRange()); |
fab18d20 AM |
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( | |
b2c971ec MK |
537 | TmfTimestamp.fromNanos(t1end + ONE_SECOND), |
538 | TmfTimestamp.fromNanos(t1end - ONE_SECOND)); | |
21852dfa | 539 | selectWindowRange(range); |
fab18d20 AM |
540 | |
541 | /* Range of trace1 should not have changed */ | |
542 | TmfTimeRange expectedRange = getInitialRange(trace1); | |
21852dfa | 543 | TmfTimeRange curRange = tm.getCurrentTraceContext().getWindowRange(); |
fab18d20 AM |
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); | |
21852dfa | 550 | curRange = tm.getCurrentTraceContext().getWindowRange(); |
fab18d20 AM |
551 | assertEquals(expectedRange.getStartTime(), curRange.getStartTime()); |
552 | assertEquals(expectedRange.getEndTime(), curRange.getEndTime()); | |
553 | } | |
554 | ||
fc526aef AM |
555 | // ------------------------------------------------------------------------ |
556 | // Test an experiment | |
557 | // ------------------------------------------------------------------------ | |
558 | ||
fab18d20 AM |
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); | |
b2c971ec | 569 | ITmfTimestamp ts = TmfTimestamp.fromNanos(t1start + ONE_SECOND); |
fab18d20 AM |
570 | selectTimestamp(ts); |
571 | ||
572 | /* The experiment's current time should be updated. */ | |
21852dfa AM |
573 | TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange(); |
574 | assertEquals(ts, selection.getStartTime()); | |
575 | assertEquals(ts, selection.getEndTime()); | |
fab18d20 AM |
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); | |
b2c971ec | 589 | ITmfTimestamp ts = TmfTimestamp.fromNanos(t1end + ONE_SECOND); |
fab18d20 AM |
590 | selectTimestamp(ts); |
591 | ||
592 | /* The experiment's current time should be updated. */ | |
21852dfa AM |
593 | TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange(); |
594 | assertEquals(ts, selection.getStartTime()); | |
595 | assertEquals(ts, selection.getEndTime()); | |
fab18d20 AM |
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); | |
b2c971ec | 608 | ITmfTimestamp ts = TmfTimestamp.fromNanos(t2end + ONE_SECOND); |
fab18d20 AM |
609 | selectTimestamp(ts); |
610 | ||
611 | /* The experiment's current time should NOT be updated. */ | |
21852dfa AM |
612 | TmfTimeRange selection = tm.getCurrentTraceContext().getSelectionRange(); |
613 | assertEquals(trace1.getStartTime(), selection.getStartTime()); | |
614 | assertEquals(trace1.getStartTime(), selection.getEndTime()); | |
fab18d20 AM |
615 | } |
616 | ||
fc526aef AM |
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 | */ | |
21852dfa | 628 | final TmfTimeRange actualRange = tm.getCurrentTraceContext().getWindowRange(); |
fc526aef | 629 | |
fab18d20 AM |
630 | assertEquals(getInitialRange(trace1), actualRange); |
631 | assertEquals(getInitialRange(exp), actualRange); | |
632 | } | |
fc526aef | 633 | |
fab18d20 AM |
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); | |
fc526aef | 642 | |
fab18d20 | 643 | final TmfTimeRange range = new TmfTimeRange( |
b2c971ec MK |
644 | TmfTimestamp.fromNanos(t1start - ONE_SECOND), |
645 | TmfTimestamp.fromNanos(t1end - ONE_SECOND)); | |
21852dfa | 646 | selectWindowRange(range); |
fab18d20 | 647 | |
21852dfa | 648 | TmfTimeRange actualRange = tm.getCurrentTraceContext().getWindowRange(); |
fab18d20 AM |
649 | assertEquals(t1start, actualRange.getStartTime().getValue()); |
650 | assertEquals(t1end - ONE_SECOND, actualRange.getEndTime().getValue()); | |
fc526aef AM |
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( | |
b2c971ec MK |
664 | TmfTimestamp.fromNanos(t1start - ONE_SECOND), |
665 | TmfTimestamp.fromNanos(t2end + ONE_SECOND)); | |
21852dfa | 666 | selectWindowRange(range); |
fc526aef | 667 | |
21852dfa | 668 | TmfTimeRange actualRange = tm.getCurrentTraceContext().getWindowRange(); |
fc526aef AM |
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( | |
b2c971ec MK |
684 | TmfTimestamp.fromNanos(t1end + ONE_SECOND), |
685 | TmfTimestamp.fromNanos(t2start - ONE_SECOND)); | |
21852dfa | 686 | selectWindowRange(range); |
fc526aef | 687 | |
21852dfa | 688 | TmfTimeRange actualRange = tm.getCurrentTraceContext().getWindowRange(); |
fc526aef AM |
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 }; | |
4178260e AM |
698 | TmfExperiment exp = new TmfExperiment(ITmfEvent.class, "test-exp", traces, |
699 | TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null); | |
fc526aef | 700 | exp.indexTrace(true); |
3568f816 BH |
701 | // Deregister experiment from signal manager so that it doesn't |
702 | // interfere with the TmfTraceManager tests | |
703 | TmfSignalManager.deregister(exp); | |
fc526aef AM |
704 | return exp; |
705 | } | |
706 | ||
fab18d20 AM |
707 | private static TmfTimeRange getInitialRange(ITmfTrace trace) { |
708 | return new TmfTimeRange( | |
709 | trace.getStartTime(), | |
710 | calculateOffset(trace.getStartTime(), trace.getInitialRangeOffset())); | |
711 | } | |
712 | ||
fc526aef AM |
713 | /** |
714 | * Basically a "initial + offset" operation, but for ITmfTimetamp objects. | |
715 | */ | |
6cfc180e | 716 | private static @NonNull ITmfTimestamp calculateOffset(ITmfTimestamp initialTs, ITmfTimestamp offsetTs) { |
16801c72 MK |
717 | long start = initialTs.toNanos(); |
718 | long offset = offsetTs.toNanos(); | |
b2c971ec | 719 | return TmfTimestamp.fromNanos(start + offset); |
fc526aef AM |
720 | } |
721 | } |