1 /*******************************************************************************
2 * Copyright (c) 2013 É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
.linuxtools
.lttng2
.kernel
.core
.tests
.event
.matchandsync
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.fail
;
17 import static org
.junit
.Assume
.assumeTrue
;
19 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.event
.matching
.TcpEventMatching
;
20 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.event
.matching
.TcpLttngEventMatching
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.matching
.TmfEventMatching
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.ITmfTimestampTransform
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.SynchronizationAlgorithm
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.TimestampTransformFactory
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfExperiment
;
28 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.CtfTmfTrace
;
29 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
30 import org
.junit
.BeforeClass
;
31 import org
.junit
.Test
;
34 * Tests for experiment syncing
36 * @author Geneviève Bastien
38 @SuppressWarnings("nls")
39 public class ExperimentSyncTest
{
41 private static final String EXPERIMENT
= "MyExperiment";
42 private static int BLOCK_SIZE
= 1000;
45 * Initialize some data
48 public static void setUp() {
49 TmfEventMatching
.registerMatchObject(new TcpEventMatching());
50 TmfEventMatching
.registerMatchObject(new TcpLttngEventMatching());
54 * Testing experiment synchronization
57 public void testExperimentSync() {
58 assumeTrue(CtfTmfTestTrace
.SYNC_SRC
.exists());
59 assumeTrue(CtfTmfTestTrace
.SYNC_DEST
.exists());
60 try (CtfTmfTrace trace1
= CtfTmfTestTrace
.SYNC_SRC
.getTrace();
61 CtfTmfTrace trace2
= CtfTmfTestTrace
.SYNC_DEST
.getTrace();) {
63 ITmfTrace
[] traces
= { trace1
, trace2
};
64 TmfExperiment experiment
= new TmfExperiment(traces
[0].getEventType(), EXPERIMENT
, traces
, BLOCK_SIZE
);
66 SynchronizationAlgorithm syncAlgo
= experiment
.synchronizeTraces(true);
68 ITmfTimestampTransform tt1
= syncAlgo
.getTimestampTransform(trace1
);
69 ITmfTimestampTransform tt2
= syncAlgo
.getTimestampTransform(trace2
);
71 trace1
.setTimestampTransform(tt1
);
72 trace2
.setTimestampTransform(tt2
);
74 assertEquals("TmfTimestampLinear [ slope = 0.9999413783703139011056845831168394, offset = 79796507913179.33347660124688298171 ]", tt1
.toString());
75 assertEquals(TimestampTransformFactory
.getDefaultTransform(), tt2
);
77 assertEquals(syncAlgo
.getTimestampTransform(trace1
.getHostId()), trace1
.getTimestampTransform());
78 assertEquals(syncAlgo
.getTimestampTransform(trace2
.getHostId()), trace2
.getTimestampTransform());
80 } catch (TmfTraceException e
) {
81 fail("Exception thrown in experiment synchronization " + e
.getMessage());
86 * Testing synchronization with 3 traces, one of which synchronizes with
90 public void testDjangoExperimentSync() {
91 assumeTrue(CtfTmfTestTrace
.DJANGO_CLIENT
.exists());
92 assumeTrue(CtfTmfTestTrace
.DJANGO_DB
.exists());
93 assumeTrue(CtfTmfTestTrace
.DJANGO_HTTPD
.exists());
94 try (CtfTmfTrace trace1
= CtfTmfTestTrace
.DJANGO_CLIENT
.getTrace();
95 CtfTmfTrace trace2
= CtfTmfTestTrace
.DJANGO_DB
.getTrace();
96 CtfTmfTrace trace3
= CtfTmfTestTrace
.DJANGO_HTTPD
.getTrace();) {
97 ITmfTrace
[] traces
= { trace1
, trace2
, trace3
};
98 TmfExperiment experiment
= new TmfExperiment(traces
[0].getEventType(), EXPERIMENT
, traces
, BLOCK_SIZE
);
100 SynchronizationAlgorithm syncAlgo
= experiment
.synchronizeTraces(true);
102 ITmfTimestampTransform tt1
= syncAlgo
.getTimestampTransform(trace1
);
103 ITmfTimestampTransform tt2
= syncAlgo
.getTimestampTransform(trace2
);
104 ITmfTimestampTransform tt3
= syncAlgo
.getTimestampTransform(trace3
);
106 trace1
.setTimestampTransform(tt1
);
107 trace2
.setTimestampTransform(tt2
);
108 trace3
.setTimestampTransform(tt3
);
110 assertEquals(TimestampTransformFactory
.getDefaultTransform(), tt1
);
111 assertEquals("TmfTimestampLinear [ slope = 0.9999996313017589597204633828681240, offset = 498490309972.0038068817738527724192 ]", tt2
.toString());
112 assertEquals("TmfTimestampLinear [ slope = 1.000000119014882262265342419815932, offset = -166652893534.6189900382736187431134 ]", tt3
.toString());
114 } catch (TmfTraceException e
) {
115 fail("Exception thrown in experiment synchronization " + e
.getMessage());