tmf: initial pcap swtbot test
[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;
58ba027e 32import org.junit.BeforeClass;
e73a4ba5
GB
33import org.junit.Test;
34
35/**
36 * Tests for experiment syncing
37 *
38 * @author Geneviève Bastien
39 */
40@SuppressWarnings("nls")
41public class ExperimentSyncTest {
42
43 private static final String EXPERIMENT = "MyExperiment";
44 private static int BLOCK_SIZE = 1000;
45
46 private static ITmfTrace[] fTraces;
47 private static TmfExperiment fExperiment;
48
49 /**
58ba027e 50 * Class setup
e73a4ba5 51 */
58ba027e
AM
52 @BeforeClass
53 public static void setUpClass() {
75b7c1bc
GB
54 assumeTrue(CtfTmfTestTrace.SYNC_SRC.exists());
55 assumeTrue(CtfTmfTestTrace.SYNC_DEST.exists());
58ba027e 56 }
e73a4ba5 57
58ba027e
AM
58 /**
59 * Setup the traces and experiment
60 */
61 @Before
62 public void setUp() {
e73a4ba5 63 fTraces = new CtfTmfTrace[2];
090c006e
AM
64 fTraces[0] = CtfTmfTestTrace.SYNC_SRC.getTrace();
65 fTraces[1] = CtfTmfTestTrace.SYNC_DEST.getTrace();
e73a4ba5 66
090c006e 67 fExperiment = new TmfExperiment(fTraces[0].getEventType(), EXPERIMENT, fTraces, BLOCK_SIZE);
e73a4ba5
GB
68
69 TmfEventMatching.registerMatchObject(new TcpEventMatching());
70 TmfEventMatching.registerMatchObject(new TcpLttngEventMatching());
71 }
72
73 /**
74 * Reset the timestamp transforms on the traces
75 */
76 @After
77 public void cleanUp() {
78 fTraces[0].setTimestampTransform(TmfTimestampTransform.IDENTITY);
79 fTraces[1].setTimestampTransform(TmfTimestampTransform.IDENTITY);
090c006e
AM
80 fTraces[0].dispose();
81 fTraces[1].dispose();
e73a4ba5
GB
82 }
83
84 /**
85 * Testing experiment synchronization
86 */
87 @Test
88 public void testExperimentSync() {
89 try {
90 SynchronizationAlgorithm syncAlgo = fExperiment.synchronizeTraces(true);
91
92 ITmfTimestampTransform tt1, tt2;
93
94 tt1 = syncAlgo.getTimestampTransform(fTraces[0]);
95 tt2 = syncAlgo.getTimestampTransform(fTraces[1]);
96
97 fTraces[0].setTimestampTransform(tt1);
98 fTraces[1].setTimestampTransform(tt2);
99
578724ed 100 assertEquals(tt2, TmfTimestampTransform.IDENTITY);
e73a4ba5
GB
101 assertEquals("TmfTimestampLinear [ alpha = 0.9999413783703139011056845831168394, beta = 79796507913179.33347660124688298171 ]", tt1.toString());
102
578724ed
GB
103 assertEquals(syncAlgo.getTimestampTransform(fTraces[0].getHostId()),fTraces[0].getTimestampTransform());
104 assertEquals(syncAlgo.getTimestampTransform(fTraces[1].getHostId()),fTraces[1].getTimestampTransform());
e73a4ba5
GB
105
106 } catch (TmfTraceException e) {
107 fail("Exception thrown in experiment synchronization " + e.getMessage());
108 }
109 }
110}
This page took 0.040844 seconds and 5 git commands to generate.