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.tmf.core.tests.synchronization; | |
14 | ||
15 | import static org.junit.Assert.assertEquals; | |
16 | ||
17 | import org.eclipse.linuxtools.tmf.core.event.matching.TmfEventDependency; | |
18 | import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform; | |
19 | import org.eclipse.linuxtools.tmf.core.synchronization.SyncAlgorithmFullyIncremental; | |
20 | import org.eclipse.linuxtools.tmf.core.synchronization.SynchronizationAlgorithm; | |
21 | import org.eclipse.linuxtools.tmf.core.synchronization.SynchronizationAlgorithm.SyncQuality; | |
22 | import org.eclipse.linuxtools.tmf.core.synchronization.TmfTimestampTransform; | |
23 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; | |
24 | import org.eclipse.linuxtools.tmf.tests.stubs.event.TmfSyncEventStub; | |
25 | import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; | |
26 | import org.junit.Before; | |
27 | import org.junit.Test; | |
28 | ||
29 | /** | |
30 | * Tests for {@link SynchronizationAlgorithm} and its descendants | |
31 | * | |
32 | * @author Geneviève Bastien | |
33 | */ | |
34 | @SuppressWarnings("nls") | |
35 | public class SyncTest { | |
36 | ||
37 | private TmfTraceStub t1, t2; | |
38 | private TmfTraceStub[] fTraces; | |
39 | ||
40 | /** | |
41 | * Initializing the traces | |
42 | */ | |
43 | @Before | |
44 | public void init() { | |
45 | t1 = new TmfTraceStub(); | |
46 | t1.init("t1"); | |
47 | t2 = new TmfTraceStub(); | |
48 | t2.init("t2"); | |
49 | TmfTraceStub[] traces = { t1, t2 }; | |
50 | fTraces = traces; | |
51 | } | |
52 | ||
53 | /** | |
54 | * Testing fully incremental algorithm with communication between the two | |
55 | * traces | |
56 | */ | |
57 | @Test | |
58 | public void testFullyIncremental() { | |
59 | ||
60 | SynchronizationAlgorithm syncAlgo = new SyncAlgorithmFullyIncremental(); | |
61 | ||
62 | syncAlgo.init(fTraces); | |
63 | ||
64 | assertEquals(SyncQuality.ABSENT, syncAlgo.getSynchronizationQuality(t1, t2)); | |
65 | syncAlgo.addMatch( | |
66 | new TmfEventDependency(new TmfSyncEventStub(t2, new TmfTimestamp(1)), | |
67 | new TmfSyncEventStub(t1, new TmfTimestamp(1)) | |
68 | )); | |
69 | assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0 ]]", syncAlgo.toString()); | |
70 | assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
71 | ||
72 | syncAlgo.addMatch( | |
73 | new TmfEventDependency(new TmfSyncEventStub(t1, new TmfTimestamp(1)), | |
74 | new TmfSyncEventStub(t2, new TmfTimestamp(3)) | |
75 | )); | |
76 | assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0 ]]", syncAlgo.toString()); | |
77 | assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
78 | ||
79 | syncAlgo.addMatch( | |
80 | new TmfEventDependency(new TmfSyncEventStub(t2, new TmfTimestamp(2)), | |
81 | new TmfSyncEventStub(t1, new TmfTimestamp(3)) | |
82 | )); | |
83 | assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0.5 ]]", syncAlgo.toString()); | |
84 | assertEquals(SyncQuality.APPROXIMATE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
85 | ||
86 | syncAlgo.addMatch( | |
87 | new TmfEventDependency(new TmfSyncEventStub(t1, new TmfTimestamp(3)), | |
88 | new TmfSyncEventStub(t2, new TmfTimestamp(5)) | |
89 | )); | |
90 | assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 0.75 beta 1.25 ]]", syncAlgo.toString()); | |
91 | assertEquals(SyncQuality.ACCURATE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
92 | ||
93 | syncAlgo.addMatch( | |
94 | new TmfEventDependency(new TmfSyncEventStub(t1, new TmfTimestamp(4)), | |
95 | new TmfSyncEventStub(t2, new TmfTimestamp(8)) | |
96 | )); | |
97 | assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 0.75 beta 1.25 ]]", syncAlgo.toString()); | |
98 | assertEquals(SyncQuality.ACCURATE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
99 | ||
100 | syncAlgo.addMatch( | |
101 | new TmfEventDependency(new TmfSyncEventStub(t2, new TmfTimestamp(4)), | |
102 | new TmfSyncEventStub(t1, new TmfTimestamp(5)) | |
103 | )); | |
104 | assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1.125 beta 0.875 ]]", syncAlgo.toString()); | |
105 | assertEquals(SyncQuality.ACCURATE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
106 | ||
107 | syncAlgo.addMatch( | |
108 | new TmfEventDependency(new TmfSyncEventStub(t2, new TmfTimestamp(4)), | |
109 | new TmfSyncEventStub(t1, new TmfTimestamp(6)) | |
110 | )); | |
111 | assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1.125 beta 0.875 ]]", syncAlgo.toString()); | |
112 | assertEquals(SyncQuality.ACCURATE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
113 | ||
114 | syncAlgo.addMatch( | |
115 | new TmfEventDependency(new TmfSyncEventStub(t1, new TmfTimestamp(6)), | |
116 | new TmfSyncEventStub(t2, new TmfTimestamp(7)) | |
117 | )); | |
118 | assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 0.725 beta 1.275 ]]", syncAlgo.toString()); | |
119 | assertEquals(SyncQuality.ACCURATE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
120 | ||
121 | ITmfTimestampTransform tt2 = syncAlgo.getTimestampTransform(t2); | |
122 | ITmfTimestampTransform tt1 = syncAlgo.getTimestampTransform(t1); | |
123 | ||
124 | assertEquals(syncAlgo.getTimestampTransform("t1"), tt1); | |
125 | assertEquals(TmfTimestampTransform.IDENTITY, tt1); | |
126 | assertEquals(syncAlgo.getTimestampTransform("t2"), tt2); | |
127 | ||
128 | /* Make the two hulls intersect */ | |
129 | syncAlgo.addMatch( | |
130 | new TmfEventDependency(new TmfSyncEventStub(t1, new TmfTimestamp(7)), | |
131 | new TmfSyncEventStub(t2, new TmfTimestamp(4)) | |
132 | )); | |
133 | syncAlgo.addMatch( | |
134 | new TmfEventDependency(new TmfSyncEventStub(t2, new TmfTimestamp(7)), | |
135 | new TmfSyncEventStub(t1, new TmfTimestamp(3)) | |
136 | )); | |
137 | assertEquals(SyncQuality.FAIL, syncAlgo.getSynchronizationQuality(t1, t2)); | |
138 | } | |
139 | ||
140 | /** | |
141 | * Testing the fully incremental synchronization algorithm when | |
142 | * communication goes in only one direction | |
143 | */ | |
144 | @Test | |
145 | public void testOneHull() { | |
146 | ||
147 | SynchronizationAlgorithm syncAlgo = new SyncAlgorithmFullyIncremental(); | |
148 | ||
149 | syncAlgo.init(fTraces); | |
150 | ||
151 | assertEquals(SyncQuality.ABSENT, syncAlgo.getSynchronizationQuality(t1, t2)); | |
152 | ||
153 | syncAlgo.addMatch( | |
154 | new TmfEventDependency(new TmfSyncEventStub(t1, new TmfTimestamp(1)), | |
155 | new TmfSyncEventStub(t2, new TmfTimestamp(3))) | |
156 | ); | |
157 | assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
158 | ||
159 | syncAlgo.addMatch( | |
160 | new TmfEventDependency(new TmfSyncEventStub(t1, new TmfTimestamp(2)), | |
161 | new TmfSyncEventStub(t2, new TmfTimestamp(5))) | |
162 | ); | |
163 | ||
164 | assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
165 | ||
166 | syncAlgo.addMatch( | |
167 | new TmfEventDependency(new TmfSyncEventStub(t1, new TmfTimestamp(3)), | |
168 | new TmfSyncEventStub(t2, new TmfTimestamp(5))) | |
169 | ); | |
170 | assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
171 | ||
172 | syncAlgo.addMatch( | |
173 | new TmfEventDependency(new TmfSyncEventStub(t1, new TmfTimestamp(4)), | |
174 | new TmfSyncEventStub(t2, new TmfTimestamp(7))) | |
175 | ); | |
176 | assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
177 | assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0 ]]", syncAlgo.toString()); | |
178 | ||
179 | } | |
180 | ||
181 | /** | |
182 | * Testing the fully incremental synchronization algorithm when all | |
183 | * communication from trace1 to trace2 happens before all communication from | |
184 | * trace2 to trace1 | |
185 | */ | |
186 | @Test | |
187 | public void testDisjoint() { | |
188 | ||
189 | SynchronizationAlgorithm syncAlgo = new SyncAlgorithmFullyIncremental(); | |
190 | ||
191 | syncAlgo.init(fTraces); | |
192 | ||
193 | assertEquals(SyncQuality.ABSENT, syncAlgo.getSynchronizationQuality(t1, t2)); | |
194 | ||
195 | syncAlgo.addMatch( | |
196 | new TmfEventDependency(new TmfSyncEventStub(t1, new TmfTimestamp(1)), | |
197 | new TmfSyncEventStub(t2, new TmfTimestamp(3))) | |
198 | ); | |
199 | assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
200 | ||
201 | syncAlgo.addMatch( | |
202 | new TmfEventDependency(new TmfSyncEventStub(t1, new TmfTimestamp(2)), | |
203 | new TmfSyncEventStub(t2, new TmfTimestamp(5))) | |
204 | ); | |
205 | ||
206 | assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
207 | ||
208 | syncAlgo.addMatch( | |
209 | new TmfEventDependency(new TmfSyncEventStub(t1, new TmfTimestamp(3)), | |
210 | new TmfSyncEventStub(t2, new TmfTimestamp(5))) | |
211 | ); | |
212 | assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
213 | ||
214 | syncAlgo.addMatch( | |
215 | new TmfEventDependency(new TmfSyncEventStub(t1, new TmfTimestamp(4)), | |
216 | new TmfSyncEventStub(t2, new TmfTimestamp(7))) | |
217 | ); | |
218 | assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
219 | assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0 ]]", syncAlgo.toString()); | |
220 | ||
221 | syncAlgo.addMatch( | |
222 | new TmfEventDependency(new TmfSyncEventStub(t2, new TmfTimestamp(7)), | |
223 | new TmfSyncEventStub(t1, new TmfTimestamp(6))) | |
224 | ); | |
225 | assertEquals(SyncQuality.APPROXIMATE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
226 | ||
227 | syncAlgo.addMatch( | |
228 | new TmfEventDependency(new TmfSyncEventStub(t2, new TmfTimestamp(8)), | |
229 | new TmfSyncEventStub(t1, new TmfTimestamp(6))) | |
230 | ); | |
231 | assertEquals(SyncQuality.APPROXIMATE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
232 | ||
233 | syncAlgo.addMatch( | |
234 | new TmfEventDependency(new TmfSyncEventStub(t2, new TmfTimestamp(10)), | |
235 | new TmfSyncEventStub(t1, new TmfTimestamp(8))) | |
236 | ); | |
237 | assertEquals(SyncQuality.APPROXIMATE, syncAlgo.getSynchronizationQuality(t1, t2)); | |
238 | assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 2.5 ]]", syncAlgo.toString()); | |
239 | } | |
240 | } |