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
CommitLineData
e73a4ba5
GB
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
13package org.eclipse.linuxtools.lttng2.kernel.core.tests.event.matchandsync;
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.fail;
75b7c1bc 17import static org.junit.Assume.assumeTrue;
e73a4ba5
GB
18
19import org.eclipse.linuxtools.lttng2.kernel.core.event.matching.TcpEventMatching;
20import org.eclipse.linuxtools.lttng2.kernel.core.event.matching.TcpLttngEventMatching;
e73a4ba5
GB
21import org.eclipse.linuxtools.tmf.core.event.matching.TmfEventMatching;
22import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
23import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform;
24import org.eclipse.linuxtools.tmf.core.synchronization.SynchronizationAlgorithm;
25import org.eclipse.linuxtools.tmf.core.synchronization.TmfTimestampTransform;
e73a4ba5
GB
26import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
27import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
91e7f946
AM
28import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
29import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
e73a4ba5
GB
30import org.junit.After;
31import org.junit.Before;
32import org.junit.Test;
33
34/**
35 * Tests for experiment syncing
36 *
37 * @author Geneviève Bastien
38 */
39@SuppressWarnings("nls")
40public 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() {
75b7c1bc
GB
53 assumeTrue(CtfTmfTestTrace.SYNC_SRC.exists());
54 assumeTrue(CtfTmfTestTrace.SYNC_DEST.exists());
e73a4ba5
GB
55
56 fTraces = new CtfTmfTrace[2];
090c006e
AM
57 fTraces[0] = CtfTmfTestTrace.SYNC_SRC.getTrace();
58 fTraces[1] = CtfTmfTestTrace.SYNC_DEST.getTrace();
e73a4ba5 59
090c006e 60 fExperiment = new TmfExperiment(fTraces[0].getEventType(), EXPERIMENT, fTraces, BLOCK_SIZE);
e73a4ba5
GB
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);
090c006e
AM
73 fTraces[0].dispose();
74 fTraces[1].dispose();
e73a4ba5
GB
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.037619 seconds and 5 git commands to generate.