Merge branch 'master' into luna
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core.tests / src / org / eclipse / linuxtools / lttng2 / kernel / core / tests / event / matchandsync / ExperimentSyncTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013 École Polytechnique de Montréal
3 *
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
8 *
9 * Contributors:
10 * Geneviève Bastien - Initial implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.lttng2.kernel.core.tests.event.matchandsync;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.fail;
17 import static org.junit.Assume.assumeTrue;
18
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;
33
34 /**
35 * Tests for experiment syncing
36 *
37 * @author Geneviève Bastien
38 */
39 @SuppressWarnings("nls")
40 public class ExperimentSyncTest {
41
42 private static final String EXPERIMENT = "MyExperiment";
43 private static int BLOCK_SIZE = 1000;
44
45 private static ITmfTrace[] fTraces;
46 private static TmfExperiment fExperiment;
47
48 /**
49 * Setup the traces and experiment
50 */
51 @Before
52 public void setUp() {
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();
57
58 fTraces = new CtfTmfTrace[2];
59 fTraces[0] = trace1;
60 fTraces[1] = trace2;
61
62 fExperiment = new TmfExperiment(trace1.getEventType(), EXPERIMENT, fTraces, BLOCK_SIZE);
63
64 TmfEventMatching.registerMatchObject(new TcpEventMatching());
65 TmfEventMatching.registerMatchObject(new TcpLttngEventMatching());
66 }
67
68 /**
69 * Reset the timestamp transforms on the traces
70 */
71 @After
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();
77 }
78
79 /**
80 * Testing experiment synchronization
81 */
82 @Test
83 public void testExperimentSync() {
84 try {
85 SynchronizationAlgorithm syncAlgo = fExperiment.synchronizeTraces(true);
86
87 ITmfTimestampTransform tt1, tt2;
88
89 tt1 = syncAlgo.getTimestampTransform(fTraces[0]);
90 tt2 = syncAlgo.getTimestampTransform(fTraces[1]);
91
92 fTraces[0].setTimestampTransform(tt1);
93 fTraces[1].setTimestampTransform(tt2);
94
95 assertEquals("TmfTimestampTransform [ IDENTITY ]", tt2.toString());
96 assertEquals("TmfTimestampLinear [ alpha = 0.9999413783703139011056845831168394, beta = 79796507913179.33347660124688298171 ]", tt1.toString());
97
98 assertEquals(syncAlgo.getTimestampTransform(fTraces[0].getName()),fTraces[0].getTimestampTransform());
99 assertEquals(syncAlgo.getTimestampTransform(fTraces[1].getName()),fTraces[1].getTimestampTransform());
100
101 } catch (TmfTraceException e) {
102 fail("Exception thrown in experiment synchronization " + e.getMessage());
103 }
104 }
105 }
This page took 0.034694 seconds and 6 git commands to generate.