1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 * Geneviève Bastien - Initial implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.tests
.event
.matchandsync
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assume
.assumeTrue
;
18 import java
.util
.concurrent
.TimeUnit
;
20 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.event
.matching
.TcpEventMatching
;
21 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.event
.matching
.TcpLttngEventMatching
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.TmfEventMatching
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.synchronization
.ITmfTimestampTransform
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.synchronization
.SynchronizationAlgorithm
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.synchronization
.TimestampTransformFactory
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.experiment
.TmfExperiment
;
28 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
29 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
30 import org
.junit
.BeforeClass
;
31 import org
.junit
.Rule
;
32 import org
.junit
.Test
;
33 import org
.junit
.rules
.TestRule
;
34 import org
.junit
.rules
.Timeout
;
37 * Tests for experiment syncing
39 * @author Geneviève Bastien
41 @SuppressWarnings("nls")
42 public class ExperimentSyncTest
{
44 /** Timeout the tests after 2 minutes */
46 public TestRule timeoutRule
= new Timeout(2, TimeUnit
.MINUTES
);
48 private static final String EXPERIMENT
= "MyExperiment";
49 private static int BLOCK_SIZE
= 1000;
52 * Initialize some data
55 public static void setUp() {
56 TmfEventMatching
.registerMatchObject(new TcpEventMatching());
57 TmfEventMatching
.registerMatchObject(new TcpLttngEventMatching());
61 * Testing experiment synchronization
64 public void testExperimentSync() {
65 assumeTrue(CtfTmfTestTrace
.SYNC_SRC
.exists());
66 assumeTrue(CtfTmfTestTrace
.SYNC_DEST
.exists());
67 CtfTmfTrace trace1
= CtfTmfTestTrace
.SYNC_SRC
.getTrace();
68 CtfTmfTrace trace2
= CtfTmfTestTrace
.SYNC_DEST
.getTrace();
70 ITmfTrace
[] traces
= { trace1
, trace2
};
71 TmfExperiment experiment
= new TmfExperiment(traces
[0].getEventType(), EXPERIMENT
, traces
, BLOCK_SIZE
, null);
73 SynchronizationAlgorithm syncAlgo
= experiment
.synchronizeTraces(true);
75 ITmfTimestampTransform tt1
= syncAlgo
.getTimestampTransform(trace1
);
76 ITmfTimestampTransform tt2
= syncAlgo
.getTimestampTransform(trace2
);
78 trace1
.setTimestampTransform(tt1
);
79 trace2
.setTimestampTransform(tt2
);
81 assertEquals("TmfTimestampTransformLinearFast [ slope = 0.9999413783703139011056845831168394, offset = 79796507913179.33347660124688298171 ]", tt1
.toString());
82 assertEquals(TimestampTransformFactory
.getDefaultTransform(), tt2
);
84 assertEquals(syncAlgo
.getTimestampTransform(trace1
.getHostId()), trace1
.getTimestampTransform());
85 assertEquals(syncAlgo
.getTimestampTransform(trace2
.getHostId()), trace2
.getTimestampTransform());
92 * Testing synchronization with 3 traces, one of which synchronizes with
96 public void testDjangoExperimentSync() {
97 assumeTrue(CtfTmfTestTrace
.DJANGO_CLIENT
.exists());
98 assumeTrue(CtfTmfTestTrace
.DJANGO_DB
.exists());
99 assumeTrue(CtfTmfTestTrace
.DJANGO_HTTPD
.exists());
101 CtfTmfTrace trace1
= CtfTmfTestTrace
.DJANGO_CLIENT
.getTrace();
102 CtfTmfTrace trace2
= CtfTmfTestTrace
.DJANGO_DB
.getTrace();
103 CtfTmfTrace trace3
= CtfTmfTestTrace
.DJANGO_HTTPD
.getTrace();
105 ITmfTrace
[] traces
= { trace1
, trace2
, trace3
};
106 TmfExperiment experiment
= new TmfExperiment(traces
[0].getEventType(), EXPERIMENT
, traces
, BLOCK_SIZE
, null);
108 SynchronizationAlgorithm syncAlgo
= experiment
.synchronizeTraces(true);
110 ITmfTimestampTransform tt1
= syncAlgo
.getTimestampTransform(trace1
);
111 ITmfTimestampTransform tt2
= syncAlgo
.getTimestampTransform(trace2
);
112 ITmfTimestampTransform tt3
= syncAlgo
.getTimestampTransform(trace3
);
114 trace1
.setTimestampTransform(tt1
);
115 trace2
.setTimestampTransform(tt2
);
116 trace3
.setTimestampTransform(tt3
);
118 assertEquals(TimestampTransformFactory
.getDefaultTransform(), tt1
);
119 assertEquals("TmfTimestampTransformLinearFast [ slope = 0.9999996313017589597204633828681240, offset = 498490309972.0038068817738527724192 ]", tt2
.toString());
120 assertEquals("TmfTimestampTransformLinearFast [ slope = 1.000000119014882262265342419815932, offset = -166652893534.6189900382736187431134 ]", tt3
.toString());