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