tmf: Make CtfTmfTrace AutoCloseable
[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.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;
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
56 fTraces = new CtfTmfTrace[2];
57 fTraces[0] = CtfTmfTestTrace.SYNC_SRC.getTrace();
58 fTraces[1] = CtfTmfTestTrace.SYNC_DEST.getTrace();
59
60 fExperiment = new TmfExperiment(fTraces[0].getEventType(), EXPERIMENT, fTraces, BLOCK_SIZE);
61
62 TmfEventMatching.registerMatchObject(new TcpEventMatching());
63 TmfEventMatching.registerMatchObject(new TcpLttngEventMatching());
64 }
65
66 /**
67 * Reset the timestamp transforms on the traces
68 */
69 @After
70 public void cleanUp() {
71 fTraces[0].setTimestampTransform(TmfTimestampTransform.IDENTITY);
72 fTraces[1].setTimestampTransform(TmfTimestampTransform.IDENTITY);
73 fTraces[0].dispose();
74 fTraces[1].dispose();
75 }
76
77 /**
78 * Testing experiment synchronization
79 */
80 @Test
81 public void testExperimentSync() {
82 try {
83 SynchronizationAlgorithm syncAlgo = fExperiment.synchronizeTraces(true);
84
85 ITmfTimestampTransform tt1, tt2;
86
87 tt1 = syncAlgo.getTimestampTransform(fTraces[0]);
88 tt2 = syncAlgo.getTimestampTransform(fTraces[1]);
89
90 fTraces[0].setTimestampTransform(tt1);
91 fTraces[1].setTimestampTransform(tt2);
92
93 assertEquals("TmfTimestampTransform [ IDENTITY ]", tt2.toString());
94 assertEquals("TmfTimestampLinear [ alpha = 0.9999413783703139011056845831168394, beta = 79796507913179.33347660124688298171 ]", tt1.toString());
95
96 assertEquals(syncAlgo.getTimestampTransform(fTraces[0].getName()),fTraces[0].getTimestampTransform());
97 assertEquals(syncAlgo.getTimestampTransform(fTraces[1].getName()),fTraces[1].getTimestampTransform());
98
99 } catch (TmfTraceException e) {
100 fail("Exception thrown in experiment synchronization " + e.getMessage());
101 }
102 }
103 }
This page took 0.034397 seconds and 6 git commands to generate.