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
.ctfadaptor
.CtfTmfTrace
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.matching
.TmfEventMatching
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.ITmfTimestampTransform
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.SynchronizationAlgorithm
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.TmfTimestampTransform
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTrace
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfExperiment
;
30 import org
.junit
.After
;
31 import org
.junit
.Before
;
32 import org
.junit
.Test
;
35 * Tests for experiment syncing
37 * @author Geneviève Bastien
39 @SuppressWarnings("nls")
40 public class ExperimentSyncTest
{
42 private static final String EXPERIMENT
= "MyExperiment";
43 private static int BLOCK_SIZE
= 1000;
45 private static ITmfTrace
[] fTraces
;
46 private static TmfExperiment fExperiment
;
49 * Setup the traces and experiment
53 assumeTrue(CtfTmfTestTrace
.SYNC_SRC
.exists());
54 assumeTrue(CtfTmfTestTrace
.SYNC_DEST
.exists());
55 CtfTmfTrace trace1
= CtfTmfTestTrace
.SYNC_SRC
.getTrace();
56 CtfTmfTrace trace2
= CtfTmfTestTrace
.SYNC_DEST
.getTrace();
58 fTraces
= new CtfTmfTrace
[2];
62 fExperiment
= new TmfExperiment(trace1
.getEventType(), EXPERIMENT
, fTraces
, BLOCK_SIZE
);
64 TmfEventMatching
.registerMatchObject(new TcpEventMatching());
65 TmfEventMatching
.registerMatchObject(new TcpLttngEventMatching());
69 * Reset the timestamp transforms on the traces
72 public void cleanUp() {
73 fTraces
[0].setTimestampTransform(TmfTimestampTransform
.IDENTITY
);
74 fTraces
[1].setTimestampTransform(TmfTimestampTransform
.IDENTITY
);
75 CtfTmfTestTrace
.SYNC_SRC
.dispose();
76 CtfTmfTestTrace
.SYNC_DEST
.dispose();
80 * Testing experiment synchronization
83 public void testExperimentSync() {
85 SynchronizationAlgorithm syncAlgo
= fExperiment
.synchronizeTraces(true);
87 ITmfTimestampTransform tt1
, tt2
;
89 tt1
= syncAlgo
.getTimestampTransform(fTraces
[0]);
90 tt2
= syncAlgo
.getTimestampTransform(fTraces
[1]);
92 fTraces
[0].setTimestampTransform(tt1
);
93 fTraces
[1].setTimestampTransform(tt2
);
95 assertEquals("TmfTimestampTransform [ IDENTITY ]", tt2
.toString());
96 assertEquals("TmfTimestampLinear [ alpha = 0.9999413783703139011056845831168394, beta = 79796507913179.33347660124688298171 ]", tt1
.toString());
98 assertEquals(syncAlgo
.getTimestampTransform(fTraces
[0].getName()),fTraces
[0].getTimestampTransform());
99 assertEquals(syncAlgo
.getTimestampTransform(fTraces
[1].getName()),fTraces
[1].getTimestampTransform());
101 } catch (TmfTraceException e
) {
102 fail("Exception thrown in experiment synchronization " + e
.getMessage());