Commit | Line | Data |
---|---|---|
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 | ||
9bc60be7 | 13 | package org.eclipse.tracecompass.lttng2.kernel.core.tests.event.matchandsync; |
e73a4ba5 GB |
14 | |
15 | import static org.junit.Assert.assertEquals; | |
75b7c1bc | 16 | import static org.junit.Assume.assumeTrue; |
e73a4ba5 | 17 | |
9bc60be7 AM |
18 | import org.eclipse.tracecompass.lttng2.kernel.core.event.matching.TcpEventMatching; |
19 | import org.eclipse.tracecompass.lttng2.kernel.core.event.matching.TcpLttngEventMatching; | |
2bdf0193 AM |
20 | import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching; |
21 | import org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform; | |
22 | import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm; | |
23 | import org.eclipse.tracecompass.tmf.core.synchronization.TimestampTransformFactory; | |
24 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
5c5fa260 | 25 | import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; |
2bdf0193 | 26 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace; |
9722e5d7 | 27 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
58ba027e | 28 | import org.junit.BeforeClass; |
e73a4ba5 GB |
29 | import org.junit.Test; |
30 | ||
31 | /** | |
32 | * Tests for experiment syncing | |
33 | * | |
34 | * @author Geneviève Bastien | |
35 | */ | |
36 | @SuppressWarnings("nls") | |
37 | public 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 }; | |
4178260e | 62 | TmfExperiment experiment = new TmfExperiment(traces[0].getEventType(), EXPERIMENT, traces, BLOCK_SIZE, null); |
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 }; | |
4178260e | 94 | TmfExperiment experiment = new TmfExperiment(traces[0].getEventType(), EXPERIMENT, traces, BLOCK_SIZE, null); |
ac29c59b FG |
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 | } |