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; | |
17 | ||
18 | import org.eclipse.linuxtools.lttng2.kernel.core.event.matching.TcpEventMatching; | |
19 | import org.eclipse.linuxtools.lttng2.kernel.core.event.matching.TcpLttngEventMatching; | |
20 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; | |
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; | |
25 | import org.eclipse.linuxtools.tmf.core.synchronization.TmfTimestampTransform; | |
6cd87900 | 26 | import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace; |
e73a4ba5 GB |
27 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
28 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; | |
29 | import org.junit.After; | |
30 | import org.junit.Before; | |
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 | ||
41 | private static final String EXPERIMENT = "MyExperiment"; | |
42 | private static int BLOCK_SIZE = 1000; | |
43 | ||
44 | private static ITmfTrace[] fTraces; | |
45 | private static TmfExperiment fExperiment; | |
46 | ||
47 | /** | |
48 | * Setup the traces and experiment | |
49 | */ | |
50 | @Before | |
51 | public void setUp() { | |
6cd87900 AM |
52 | CtfTmfTrace trace1 = CtfTmfTestTrace.SYNC_SRC.getTrace(); |
53 | CtfTmfTrace trace2 = CtfTmfTestTrace.SYNC_DEST.getTrace(); | |
e73a4ba5 GB |
54 | |
55 | fTraces = new CtfTmfTrace[2]; | |
56 | fTraces[0] = trace1; | |
57 | fTraces[1] = trace2; | |
58 | ||
59 | fExperiment = new TmfExperiment(trace1.getEventType(), EXPERIMENT, fTraces, BLOCK_SIZE); | |
60 | ||
61 | TmfEventMatching.registerMatchObject(new TcpEventMatching()); | |
62 | TmfEventMatching.registerMatchObject(new TcpLttngEventMatching()); | |
63 | } | |
64 | ||
65 | /** | |
66 | * Reset the timestamp transforms on the traces | |
67 | */ | |
68 | @After | |
69 | public void cleanUp() { | |
70 | fTraces[0].setTimestampTransform(TmfTimestampTransform.IDENTITY); | |
71 | fTraces[1].setTimestampTransform(TmfTimestampTransform.IDENTITY); | |
72 | } | |
73 | ||
74 | /** | |
75 | * Testing experiment synchronization | |
76 | */ | |
77 | @Test | |
78 | public void testExperimentSync() { | |
79 | try { | |
80 | SynchronizationAlgorithm syncAlgo = fExperiment.synchronizeTraces(true); | |
81 | ||
82 | ITmfTimestampTransform tt1, tt2; | |
83 | ||
84 | tt1 = syncAlgo.getTimestampTransform(fTraces[0]); | |
85 | tt2 = syncAlgo.getTimestampTransform(fTraces[1]); | |
86 | ||
87 | fTraces[0].setTimestampTransform(tt1); | |
88 | fTraces[1].setTimestampTransform(tt2); | |
89 | ||
90 | assertEquals("TmfTimestampTransform [ IDENTITY ]", tt2.toString()); | |
91 | assertEquals("TmfTimestampLinear [ alpha = 0.9999413783703139011056845831168394, beta = 79796507913179.33347660124688298171 ]", tt1.toString()); | |
92 | ||
93 | assertEquals(syncAlgo.getTimestampTransform(fTraces[0].getName()),fTraces[0].getTimestampTransform()); | |
94 | assertEquals(syncAlgo.getTimestampTransform(fTraces[1].getName()),fTraces[1].getTimestampTransform()); | |
95 | ||
96 | } catch (TmfTraceException e) { | |
97 | fail("Exception thrown in experiment synchronization " + e.getMessage()); | |
98 | } | |
99 | } | |
100 | } |