Analysis: Add unit tests for the critical path module
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / src / org / eclipse / tracecompass / lttng2 / kernel / core / tests / event / matchandsync / ExperimentSyncTest.java
CommitLineData
e73a4ba5 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
e73a4ba5
GB
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
9bc60be7 13package org.eclipse.tracecompass.lttng2.kernel.core.tests.event.matchandsync;
e73a4ba5
GB
14
15import static org.junit.Assert.assertEquals;
75b7c1bc 16import static org.junit.Assume.assumeTrue;
e73a4ba5 17
8258d369
AM
18import java.util.concurrent.TimeUnit;
19
dc327459
GB
20import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpEventMatching;
21import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpLttngEventMatching;
2bdf0193
AM
22import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching;
23import org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform;
24import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm;
25import org.eclipse.tracecompass.tmf.core.synchronization.TimestampTransformFactory;
26import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
5c5fa260 27import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
2bdf0193 28import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
9722e5d7 29import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
58ba027e 30import org.junit.BeforeClass;
8258d369 31import org.junit.Rule;
e73a4ba5 32import org.junit.Test;
8258d369
AM
33import org.junit.rules.TestRule;
34import org.junit.rules.Timeout;
e73a4ba5
GB
35
36/**
37 * Tests for experiment syncing
38 *
39 * @author Geneviève Bastien
40 */
41@SuppressWarnings("nls")
42public class ExperimentSyncTest {
43
8258d369
AM
44 /** Timeout the tests after 2 minutes */
45 @Rule
46 public TestRule timeoutRule = new Timeout(2, TimeUnit.MINUTES);
47
ac29c59b
FG
48 private static final String EXPERIMENT = "MyExperiment";
49 private static int BLOCK_SIZE = 1000;
e73a4ba5
GB
50
51 /**
ac29c59b 52 * Initialize some data
e73a4ba5 53 */
58ba027e 54 @BeforeClass
ac29c59b 55 public static void setUp() {
e73a4ba5
GB
56 TmfEventMatching.registerMatchObject(new TcpEventMatching());
57 TmfEventMatching.registerMatchObject(new TcpLttngEventMatching());
58 }
59
e73a4ba5
GB
60 /**
61 * Testing experiment synchronization
62 */
63 @Test
64 public void testExperimentSync() {
ac29c59b
FG
65 assumeTrue(CtfTmfTestTrace.SYNC_SRC.exists());
66 assumeTrue(CtfTmfTestTrace.SYNC_DEST.exists());
0ff9e595
AM
67 CtfTmfTrace trace1 = CtfTmfTestTrace.SYNC_SRC.getTrace();
68 CtfTmfTrace trace2 = CtfTmfTestTrace.SYNC_DEST.getTrace();
ac29c59b 69
0ff9e595
AM
70 ITmfTrace[] traces = { trace1, trace2 };
71 TmfExperiment experiment = new TmfExperiment(traces[0].getEventType(), EXPERIMENT, traces, BLOCK_SIZE, null);
e73a4ba5 72
0ff9e595 73 SynchronizationAlgorithm syncAlgo = experiment.synchronizeTraces(true);
e73a4ba5 74
0ff9e595
AM
75 ITmfTimestampTransform tt1 = syncAlgo.getTimestampTransform(trace1);
76 ITmfTimestampTransform tt2 = syncAlgo.getTimestampTransform(trace2);
e73a4ba5 77
0ff9e595
AM
78 trace1.setTimestampTransform(tt1);
79 trace2.setTimestampTransform(tt2);
e73a4ba5 80
0ff9e595
AM
81 assertEquals("TmfTimestampTransformLinearFast [ slope = 0.9999413783703139011056845831168394, offset = 79796507913179.33347660124688298171 ]", tt1.toString());
82 assertEquals(TimestampTransformFactory.getDefaultTransform(), tt2);
ac29c59b 83
0ff9e595
AM
84 assertEquals(syncAlgo.getTimestampTransform(trace1.getHostId()), trace1.getTimestampTransform());
85 assertEquals(syncAlgo.getTimestampTransform(trace2.getHostId()), trace2.getTimestampTransform());
ac29c59b 86
0ff9e595
AM
87 trace1.dispose();
88 trace2.dispose();
ac29c59b 89 }
e73a4ba5 90
ac29c59b
FG
91 /**
92 * Testing synchronization with 3 traces, one of which synchronizes with
93 * both other
94 */
95 @Test
96 public void testDjangoExperimentSync() {
97 assumeTrue(CtfTmfTestTrace.DJANGO_CLIENT.exists());
98 assumeTrue(CtfTmfTestTrace.DJANGO_DB.exists());
99 assumeTrue(CtfTmfTestTrace.DJANGO_HTTPD.exists());
ac29c59b 100
0ff9e595
AM
101 CtfTmfTrace trace1 = CtfTmfTestTrace.DJANGO_CLIENT.getTrace();
102 CtfTmfTrace trace2 = CtfTmfTestTrace.DJANGO_DB.getTrace();
103 CtfTmfTrace trace3 = CtfTmfTestTrace.DJANGO_HTTPD.getTrace();
ac29c59b 104
0ff9e595
AM
105 ITmfTrace[] traces = { trace1, trace2, trace3 };
106 TmfExperiment experiment = new TmfExperiment(traces[0].getEventType(), EXPERIMENT, traces, BLOCK_SIZE, null);
ac29c59b 107
0ff9e595 108 SynchronizationAlgorithm syncAlgo = experiment.synchronizeTraces(true);
ac29c59b 109
0ff9e595
AM
110 ITmfTimestampTransform tt1 = syncAlgo.getTimestampTransform(trace1);
111 ITmfTimestampTransform tt2 = syncAlgo.getTimestampTransform(trace2);
112 ITmfTimestampTransform tt3 = syncAlgo.getTimestampTransform(trace3);
e73a4ba5 113
0ff9e595
AM
114 trace1.setTimestampTransform(tt1);
115 trace2.setTimestampTransform(tt2);
116 trace3.setTimestampTransform(tt3);
117
118 assertEquals(TimestampTransformFactory.getDefaultTransform(), tt1);
119 assertEquals("TmfTimestampTransformLinearFast [ slope = 0.9999996313017589597204633828681240, offset = 498490309972.0038068817738527724192 ]", tt2.toString());
120 assertEquals("TmfTimestampTransformLinearFast [ slope = 1.000000119014882262265342419815932, offset = -166652893534.6189900382736187431134 ]", tt3.toString());
121
122 trace1.dispose();
123 trace2.dispose();
124 trace3.dispose();
e73a4ba5
GB
125 }
126}
This page took 0.061688 seconds and 5 git commands to generate.