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
.TmfTimestampTransform
;
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
.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());
56 fTraces
= new CtfTmfTrace
[2];
57 fTraces
[0] = CtfTmfTestTrace
.SYNC_SRC
.getTrace();
58 fTraces
[1] = CtfTmfTestTrace
.SYNC_DEST
.getTrace();
60 fExperiment
= new TmfExperiment(fTraces
[0].getEventType(), EXPERIMENT
, fTraces
, BLOCK_SIZE
);
62 TmfEventMatching
.registerMatchObject(new TcpEventMatching());
63 TmfEventMatching
.registerMatchObject(new TcpLttngEventMatching());
67 * Reset the timestamp transforms on the traces
70 public void cleanUp() {
71 fTraces
[0].setTimestampTransform(TmfTimestampTransform
.IDENTITY
);
72 fTraces
[1].setTimestampTransform(TmfTimestampTransform
.IDENTITY
);
78 * Testing experiment synchronization
81 public void testExperimentSync() {
83 SynchronizationAlgorithm syncAlgo
= fExperiment
.synchronizeTraces(true);
85 ITmfTimestampTransform tt1
, tt2
;
87 tt1
= syncAlgo
.getTimestampTransform(fTraces
[0]);
88 tt2
= syncAlgo
.getTimestampTransform(fTraces
[1]);
90 fTraces
[0].setTimestampTransform(tt1
);
91 fTraces
[1].setTimestampTransform(tt2
);
93 assertEquals("TmfTimestampTransform [ IDENTITY ]", tt2
.toString());
94 assertEquals("TmfTimestampLinear [ alpha = 0.9999413783703139011056845831168394, beta = 79796507913179.33347660124688298171 ]", tt1
.toString());
96 assertEquals(syncAlgo
.getTimestampTransform(fTraces
[0].getName()),fTraces
[0].getTimestampTransform());
97 assertEquals(syncAlgo
.getTimestampTransform(fTraces
[1].getName()),fTraces
[1].getTimestampTransform());
99 } catch (TmfTraceException e
) {
100 fail("Exception thrown in experiment synchronization " + e
.getMessage());