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; | |
e73a4ba5 GB |
30 | import org.junit.After; |
31 | import org.junit.Before; | |
58ba027e | 32 | import org.junit.BeforeClass; |
e73a4ba5 GB |
33 | import org.junit.Test; |
34 | ||
35 | /** | |
36 | * Tests for experiment syncing | |
37 | * | |
38 | * @author Geneviève Bastien | |
39 | */ | |
40 | @SuppressWarnings("nls") | |
41 | public class ExperimentSyncTest { | |
42 | ||
43 | private static final String EXPERIMENT = "MyExperiment"; | |
44 | private static int BLOCK_SIZE = 1000; | |
45 | ||
46 | private static ITmfTrace[] fTraces; | |
47 | private static TmfExperiment fExperiment; | |
48 | ||
49 | /** | |
58ba027e | 50 | * Class setup |
e73a4ba5 | 51 | */ |
58ba027e AM |
52 | @BeforeClass |
53 | public static void setUpClass() { | |
75b7c1bc GB |
54 | assumeTrue(CtfTmfTestTrace.SYNC_SRC.exists()); |
55 | assumeTrue(CtfTmfTestTrace.SYNC_DEST.exists()); | |
58ba027e | 56 | } |
e73a4ba5 | 57 | |
58ba027e AM |
58 | /** |
59 | * Setup the traces and experiment | |
60 | */ | |
61 | @Before | |
62 | public void setUp() { | |
e73a4ba5 | 63 | fTraces = new CtfTmfTrace[2]; |
090c006e AM |
64 | fTraces[0] = CtfTmfTestTrace.SYNC_SRC.getTrace(); |
65 | fTraces[1] = CtfTmfTestTrace.SYNC_DEST.getTrace(); | |
e73a4ba5 | 66 | |
090c006e | 67 | fExperiment = new TmfExperiment(fTraces[0].getEventType(), EXPERIMENT, fTraces, BLOCK_SIZE); |
e73a4ba5 GB |
68 | |
69 | TmfEventMatching.registerMatchObject(new TcpEventMatching()); | |
70 | TmfEventMatching.registerMatchObject(new TcpLttngEventMatching()); | |
71 | } | |
72 | ||
73 | /** | |
74 | * Reset the timestamp transforms on the traces | |
75 | */ | |
76 | @After | |
77 | public void cleanUp() { | |
9ffcda7d GB |
78 | fTraces[0].setTimestampTransform(TimestampTransformFactory.getDefaultTransform()); |
79 | fTraces[1].setTimestampTransform(TimestampTransformFactory.getDefaultTransform()); | |
090c006e AM |
80 | fTraces[0].dispose(); |
81 | fTraces[1].dispose(); | |
e73a4ba5 GB |
82 | } |
83 | ||
84 | /** | |
85 | * Testing experiment synchronization | |
86 | */ | |
87 | @Test | |
88 | public void testExperimentSync() { | |
89 | try { | |
90 | SynchronizationAlgorithm syncAlgo = fExperiment.synchronizeTraces(true); | |
91 | ||
92 | ITmfTimestampTransform tt1, tt2; | |
93 | ||
94 | tt1 = syncAlgo.getTimestampTransform(fTraces[0]); | |
95 | tt2 = syncAlgo.getTimestampTransform(fTraces[1]); | |
96 | ||
97 | fTraces[0].setTimestampTransform(tt1); | |
98 | fTraces[1].setTimestampTransform(tt2); | |
99 | ||
9ffcda7d GB |
100 | assertEquals(tt2, TimestampTransformFactory.getDefaultTransform()); |
101 | assertEquals("TmfTimestampLinear [ slope = 0.9999413783703139011056845831168394, offset = 79796507913179.33347660124688298171 ]", tt1.toString()); | |
e73a4ba5 | 102 | |
578724ed GB |
103 | assertEquals(syncAlgo.getTimestampTransform(fTraces[0].getHostId()),fTraces[0].getTimestampTransform()); |
104 | assertEquals(syncAlgo.getTimestampTransform(fTraces[1].getHostId()),fTraces[1].getTimestampTransform()); | |
e73a4ba5 GB |
105 | |
106 | } catch (TmfTraceException e) { | |
107 | fail("Exception thrown in experiment synchronization " + e.getMessage()); | |
108 | } | |
109 | } | |
110 | } |