gdbtrace: Move plugins to the Trace Compass namespace
[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;
75b7c1bc 16import static org.junit.Assume.assumeTrue;
e73a4ba5
GB
17
18import org.eclipse.linuxtools.lttng2.kernel.core.event.matching.TcpEventMatching;
19import org.eclipse.linuxtools.lttng2.kernel.core.event.matching.TcpLttngEventMatching;
e73a4ba5 20import org.eclipse.linuxtools.tmf.core.event.matching.TmfEventMatching;
e73a4ba5
GB
21import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform;
22import org.eclipse.linuxtools.tmf.core.synchronization.SynchronizationAlgorithm;
9ffcda7d 23import org.eclipse.linuxtools.tmf.core.synchronization.TimestampTransformFactory;
e73a4ba5
GB
24import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
25import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
91e7f946
AM
26import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
27import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
58ba027e 28import org.junit.BeforeClass;
e73a4ba5
GB
29import org.junit.Test;
30
31/**
32 * Tests for experiment syncing
33 *
34 * @author Geneviève Bastien
35 */
36@SuppressWarnings("nls")
37public class ExperimentSyncTest {
38
ac29c59b
FG
39 private static final String EXPERIMENT = "MyExperiment";
40 private static int BLOCK_SIZE = 1000;
e73a4ba5
GB
41
42 /**
ac29c59b 43 * Initialize some data
e73a4ba5 44 */
58ba027e 45 @BeforeClass
ac29c59b 46 public static void setUp() {
e73a4ba5
GB
47 TmfEventMatching.registerMatchObject(new TcpEventMatching());
48 TmfEventMatching.registerMatchObject(new TcpLttngEventMatching());
49 }
50
e73a4ba5
GB
51 /**
52 * Testing experiment synchronization
53 */
54 @Test
55 public void testExperimentSync() {
ac29c59b
FG
56 assumeTrue(CtfTmfTestTrace.SYNC_SRC.exists());
57 assumeTrue(CtfTmfTestTrace.SYNC_DEST.exists());
58 try (CtfTmfTrace trace1 = CtfTmfTestTrace.SYNC_SRC.getTrace();
59 CtfTmfTrace trace2 = CtfTmfTestTrace.SYNC_DEST.getTrace();) {
60
61 ITmfTrace[] traces = { trace1, trace2 };
62 TmfExperiment experiment = new TmfExperiment(traces[0].getEventType(), EXPERIMENT, traces, BLOCK_SIZE);
e73a4ba5 63
ac29c59b 64 SynchronizationAlgorithm syncAlgo = experiment.synchronizeTraces(true);
e73a4ba5 65
ac29c59b
FG
66 ITmfTimestampTransform tt1 = syncAlgo.getTimestampTransform(trace1);
67 ITmfTimestampTransform tt2 = syncAlgo.getTimestampTransform(trace2);
e73a4ba5 68
ac29c59b
FG
69 trace1.setTimestampTransform(tt1);
70 trace2.setTimestampTransform(tt2);
e73a4ba5 71
9ffcda7d 72 assertEquals("TmfTimestampLinear [ slope = 0.9999413783703139011056845831168394, offset = 79796507913179.33347660124688298171 ]", tt1.toString());
ac29c59b
FG
73 assertEquals(TimestampTransformFactory.getDefaultTransform(), tt2);
74
75 assertEquals(syncAlgo.getTimestampTransform(trace1.getHostId()), trace1.getTimestampTransform());
76 assertEquals(syncAlgo.getTimestampTransform(trace2.getHostId()), trace2.getTimestampTransform());
77
ac29c59b
FG
78 }
79 }
e73a4ba5 80
ac29c59b
FG
81 /**
82 * Testing synchronization with 3 traces, one of which synchronizes with
83 * both other
84 */
85 @Test
86 public void testDjangoExperimentSync() {
87 assumeTrue(CtfTmfTestTrace.DJANGO_CLIENT.exists());
88 assumeTrue(CtfTmfTestTrace.DJANGO_DB.exists());
89 assumeTrue(CtfTmfTestTrace.DJANGO_HTTPD.exists());
90 try (CtfTmfTrace trace1 = CtfTmfTestTrace.DJANGO_CLIENT.getTrace();
91 CtfTmfTrace trace2 = CtfTmfTestTrace.DJANGO_DB.getTrace();
92 CtfTmfTrace trace3 = CtfTmfTestTrace.DJANGO_HTTPD.getTrace();) {
93 ITmfTrace[] traces = { trace1, trace2, trace3 };
94 TmfExperiment experiment = new TmfExperiment(traces[0].getEventType(), EXPERIMENT, traces, BLOCK_SIZE);
95
96 SynchronizationAlgorithm syncAlgo = experiment.synchronizeTraces(true);
97
98 ITmfTimestampTransform tt1 = syncAlgo.getTimestampTransform(trace1);
99 ITmfTimestampTransform tt2 = syncAlgo.getTimestampTransform(trace2);
100 ITmfTimestampTransform tt3 = syncAlgo.getTimestampTransform(trace3);
101
102 trace1.setTimestampTransform(tt1);
103 trace2.setTimestampTransform(tt2);
104 trace3.setTimestampTransform(tt3);
105
106 assertEquals(TimestampTransformFactory.getDefaultTransform(), tt1);
107 assertEquals("TmfTimestampLinear [ slope = 0.9999996313017589597204633828681240, offset = 498490309972.0038068817738527724192 ]", tt2.toString());
108 assertEquals("TmfTimestampLinear [ slope = 1.000000119014882262265342419815932, offset = -166652893534.6189900382736187431134 ]", tt3.toString());
e73a4ba5 109
e73a4ba5
GB
110 }
111 }
112}
This page took 0.048942 seconds and 5 git commands to generate.