Commit | Line | Data |
---|---|---|
6c13869b | 1 | package org.eclipse.linuxtools.lttng.core.tests; |
03c71d1e ASL |
2 | |
3 | import java.io.File; | |
4 | import java.net.URL; | |
5 | ||
6 | import junit.framework.TestCase; | |
7 | ||
8 | import org.eclipse.core.runtime.FileLocator; | |
9 | import org.eclipse.core.runtime.Path; | |
6c13869b FC |
10 | import org.eclipse.linuxtools.lttng.core.TraceDebug; |
11 | import org.eclipse.linuxtools.lttng.core.control.LttngCoreProviderFactory; | |
12 | import org.eclipse.linuxtools.lttng.core.event.LttngEvent; | |
13 | import org.eclipse.linuxtools.lttng.core.event.LttngSyntheticEvent; | |
14 | import org.eclipse.linuxtools.lttng.core.event.LttngTimestamp; | |
15 | import org.eclipse.linuxtools.lttng.core.event.LttngSyntheticEvent.SequenceInd; | |
16 | import org.eclipse.linuxtools.lttng.core.state.experiment.IStateExperimentManager; | |
17 | import org.eclipse.linuxtools.lttng.core.state.experiment.StateManagerFactory; | |
18 | import org.eclipse.linuxtools.lttng.core.trace.LTTngTextTrace; | |
19 | import org.eclipse.linuxtools.lttng.core.trace.LTTngTrace; | |
20 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; | |
21 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
22 | import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; | |
23 | import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; | |
24 | import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; | |
25 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; | |
26 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
03c71d1e | 27 | |
3b38ea61 | 28 | @SuppressWarnings("nls") |
03c71d1e ASL |
29 | public abstract class LttngTestPreparation extends TestCase { |
30 | // ======================================================================== | |
31 | // Data | |
32 | // ======================================================================== | |
33 | private final static String ftracepath_T1 = "traceset/trace-15316events_nolost_newformat"; | |
34 | final static String fTextTracepath_T1 = "traceset/trace-15316events_nolost_newformat.txt"; | |
35 | ||
36 | private static final Long CHECK_POINT_INTERVAL = 1000L; | |
37 | ||
38 | final Long[] expectedEvents_T1 = new Long[20]; | |
39 | final Long[] requestIntervals_T1 = new Long[32]; | |
40 | ||
41 | static LTTngTextTrace ftextStream_T1 = null; | |
42 | private static LTTngTrace frealStream = null; | |
43 | ||
44 | private TmfExperiment<LttngEvent> fTestExperiment = null; | |
45 | protected volatile int feventCount = 0; | |
46 | protected boolean validSequence = true; | |
47 | ||
48 | public LttngTestPreparation() { | |
49 | super(); | |
50 | init(); | |
51 | } | |
52 | ||
53 | public LttngTestPreparation(String name) { | |
54 | super(name); | |
55 | init(); | |
56 | } | |
57 | ||
58 | protected void init() { | |
59 | fillInRequestIntervals(); | |
60 | fillInExpectedEvents(); | |
61 | feventCount = 0; | |
62 | } | |
63 | ||
a72a38d9 ASL |
64 | /** |
65 | * @return | |
66 | */ | |
67 | protected TmfExperiment<LttngEvent> prepareExperimentToTest() { | |
68 | if (fTestExperiment == null) { | |
69 | String expId = "testExperiment"; | |
70 | int nbTraces = 1; | |
71 | ||
72 | // Define traces in experiment | |
603e1b20 FC |
73 | @SuppressWarnings("unchecked") |
74 | ITmfTrace<LttngEvent>[] traces = new ITmfTrace[nbTraces]; | |
75 | ITmfTrace<LttngEvent> trace = prepareStreamToTest(); | |
a72a38d9 ASL |
76 | traces[0] = trace; |
77 | ||
78 | // create experiment and associate traces | |
79 | fTestExperiment = new TmfExperiment<LttngEvent>(LttngEvent.class, | |
f6b14ce2 | 80 | expId, traces, TmfTimestamp.Zero, TmfExperiment.DEFAULT_BLOCK_SIZE, true); |
a72a38d9 ASL |
81 | // fTestExperiment.indexExperiment(waitForCompletion); |
82 | ||
83 | // Set the current selected experiment as the test experiment | |
84 | TmfExperimentSelectedSignal<LttngEvent> signal = new TmfExperimentSelectedSignal<LttngEvent>( | |
85 | this, fTestExperiment); | |
86 | fTestExperiment.experimentSelected(signal); | |
03c71d1e | 87 | } |
a72a38d9 ASL |
88 | |
89 | return fTestExperiment; | |
03c71d1e ASL |
90 | } |
91 | ||
92 | /** | |
93 | * @return | |
94 | */ | |
95 | protected TmfExperiment<LttngEvent> prepareTextExperimentToTest() { | |
96 | if (fTestExperiment == null) { | |
97 | String expId = "testExperiment"; | |
98 | int nbTraces = 1; | |
a72a38d9 | 99 | |
03c71d1e | 100 | // Define traces in experiment |
603e1b20 FC |
101 | @SuppressWarnings("unchecked") |
102 | ITmfTrace<LttngEvent>[] traces = new ITmfTrace[nbTraces]; | |
103 | ITmfTrace<LttngEvent> trace = prepareTextStreamToTest(); | |
03c71d1e | 104 | traces[0] = trace; |
a72a38d9 | 105 | |
03c71d1e ASL |
106 | // create experiment and associate traces |
107 | fTestExperiment = new TmfExperiment<LttngEvent>(LttngEvent.class, | |
108 | expId, traces); | |
109 | ||
110 | // Set the current selected experiment as the test experiment | |
111 | TmfExperimentSelectedSignal<LttngEvent> signal = new TmfExperimentSelectedSignal<LttngEvent>( | |
112 | this, fTestExperiment); | |
113 | fTestExperiment.experimentSelected(signal); | |
114 | ||
115 | } | |
a72a38d9 | 116 | |
03c71d1e ASL |
117 | return fTestExperiment; |
118 | } | |
119 | ||
120 | protected LTTngTrace prepareStreamToTest() { | |
121 | if (frealStream == null) { | |
122 | try { | |
a72a38d9 ASL |
123 | URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(ftracepath_T1), |
124 | null); | |
125 | File testfile = new File(FileLocator.toFileURL(location).toURI()); | |
603e1b20 | 126 | LTTngTrace tmpStream = new LTTngTrace(testfile.getPath(), false); |
03c71d1e ASL |
127 | frealStream = tmpStream; |
128 | } catch (Exception e) { | |
129 | System.out.println("ERROR : Could not open " + ftracepath_T1); | |
130 | frealStream = null; | |
131 | } | |
132 | } else { | |
133 | frealStream.seekEvent(0L); | |
134 | } | |
135 | ||
136 | return frealStream; | |
137 | } | |
138 | ||
a72a38d9 ASL |
139 | protected LTTngTextTrace prepareTextStreamToTest() { |
140 | if (ftextStream_T1 == null) { | |
141 | try { | |
142 | URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), | |
143 | new Path(fTextTracepath_T1), null); | |
144 | File testfile = new File(FileLocator.toFileURL(location).toURI()); | |
145 | LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getPath()); | |
146 | ftextStream_T1 = tmpStream; | |
03c71d1e | 147 | |
a72a38d9 ASL |
148 | } catch (Exception e) { |
149 | System.out.println("ERROR : Could not open " + fTextTracepath_T1); | |
150 | ftextStream_T1 = null; | |
151 | } | |
152 | } else { | |
153 | ftextStream_T1.seekEvent(0); | |
03c71d1e ASL |
154 | } |
155 | ||
a72a38d9 | 156 | return ftextStream_T1; |
03c71d1e ASL |
157 | } |
158 | ||
159 | protected IStateExperimentManager prepareExperimentContext( | |
160 | boolean waitForRequest) { | |
161 | // Create a new Experiment manager | |
162 | IStateExperimentManager expManager = StateManagerFactory | |
163 | .getExperimentManager(); | |
164 | // Configure the interval to create check points so this can be tested | |
165 | // with medium size files i.e. default is 50000 events | |
166 | StateManagerFactory.setTraceCheckPointInterval(CHECK_POINT_INTERVAL); | |
167 | ||
168 | // Lets wait for the request completion to analyse the results | |
c1c69938 | 169 | LttngCoreProviderFactory.getEventProvider(0) |
03c71d1e ASL |
170 | .setWaitForRequest(waitForRequest); |
171 | return expManager; | |
172 | } | |
173 | ||
174 | /** | |
175 | * @param <T> | |
176 | * @param k | |
177 | * @param startIdx | |
178 | * , > 0 and between 0 - 31 | |
179 | * @param endIdx | |
180 | * , > startIdx and between 0 - 31 | |
181 | * @return | |
182 | */ | |
2ecaca9d ASL |
183 | protected <T extends LttngEvent> TmfEventRequest<T> prepareEventRequest(Class<T> k, int startIdx, int endIdx) { |
184 | return prepareEventRequest(k, startIdx, endIdx, true); | |
185 | } | |
186 | ||
187 | /** | |
188 | * @param <T> | |
189 | * @param k | |
190 | * @param startIdx | |
191 | * , > 0 and between 0 - 31 | |
192 | * @param endIdx | |
193 | * , > startIdx and between 0 - 31 | |
194 | * @param printFirst20 | |
195 | * , print the first expected events vs actual events | |
196 | * @return | |
197 | */ | |
03c71d1e | 198 | protected <T extends LttngEvent> TmfEventRequest<T> prepareEventRequest( |
f6b14ce2 FC |
199 | Class<T> k, final int startIdx, int endIdx, final boolean printFirst20) { |
200 | // verify bounds | |
201 | if (!(endIdx > startIdx && startIdx >= 0 && endIdx <= 31)) { | |
202 | TraceDebug.debug("Event request indexes out of bounds"); | |
203 | return null; | |
204 | } | |
205 | ||
206 | int DEFAULT_CHUNK = 1; | |
207 | ||
208 | // time range | |
209 | TmfTimeRange trange = new TmfTimeRange(new LttngTimestamp( | |
210 | requestIntervals_T1[startIdx]), new LttngTimestamp( | |
211 | requestIntervals_T1[endIdx])); | |
212 | ||
213 | // request | |
214 | validSequence = true; | |
f9673903 | 215 | TmfEventRequest<T> request = new TmfEventRequest<T>(k, trange, TmfDataRequest.ALL_DATA, DEFAULT_CHUNK) { |
f6b14ce2 FC |
216 | |
217 | @Override | |
f9673903 | 218 | public void handleData(T event) { |
f6b14ce2 FC |
219 | if (event == null) { |
220 | System.out | |
221 | .println("Syntheric Event Received is null, after event: " | |
222 | + feventCount); | |
223 | return; | |
224 | } | |
225 | ||
226 | // Listen to only one variant of synthetic event to keep | |
227 | // track of | |
228 | if (event instanceof LttngSyntheticEvent) { | |
229 | if (((LttngSyntheticEvent) event).getSynType() != SequenceInd.BEFORE) { | |
230 | return; | |
231 | } | |
232 | } | |
233 | ||
234 | // Validating the orders of the first 20 events | |
235 | if (printFirst20 && feventCount < 20) { | |
236 | long timevalue = event.getTimestamp().getValue(); | |
237 | if (timevalue != expectedEvents_T1[feventCount]) { | |
238 | validSequence = false; | |
239 | System.out.println("Expected Event: " | |
240 | + expectedEvents_T1[feventCount] + " actual: " | |
241 | + event.getTimestamp().getValue()); | |
242 | } else { | |
243 | System.out.println("Synthetic Event: " + feventCount | |
244 | + " matched expected time"); | |
245 | } | |
246 | } | |
247 | ||
248 | // increment count | |
249 | incrementCount(); | |
250 | } | |
251 | ||
252 | /** | |
253 | * possibly increased by multiple request threads | |
254 | */ | |
255 | private synchronized void incrementCount() { | |
256 | feventCount++; | |
257 | } | |
258 | ||
259 | @Override | |
260 | public void handleCompleted() { | |
261 | // if (isCancelled() || isFailed()) { | |
262 | // // No notification to end request handlers | |
263 | // } else { | |
264 | // // notify the associated end request handlers | |
265 | // requestCompleted(); | |
266 | // } | |
267 | ||
268 | System.out.println("handleCompleted(request:" + startIdx + ") Number of events processed: " + feventCount); | |
269 | } | |
270 | ||
271 | }; | |
272 | return request; | |
273 | } | |
274 | ||
275 | /** | |
276 | * @param <T> | |
277 | * @param k | |
278 | * @param startIdx | |
279 | * , > 0 and between 0 - 31 | |
280 | * @param endIdx | |
281 | * , > startIdx and between 0 - 31 | |
282 | * @param printFirst20 | |
283 | * , print the first expected events vs actual events | |
284 | * @return | |
285 | */ | |
286 | protected <T extends LttngEvent> TmfEventRequest<T> prepareEventRequest2( | |
287 | Class<T> k, final int startIdx, int endIdx, final boolean printFirst20) { | |
03c71d1e ASL |
288 | // verify bounds |
289 | if (!(endIdx > startIdx && startIdx >= 0 && endIdx <= 31)) { | |
290 | TraceDebug.debug("Event request indexes out of bounds"); | |
291 | return null; | |
292 | } | |
293 | ||
294 | int DEFAULT_CHUNK = 1; | |
03c71d1e ASL |
295 | |
296 | // time range | |
297 | TmfTimeRange trange = new TmfTimeRange(new LttngTimestamp( | |
298 | requestIntervals_T1[startIdx]), new LttngTimestamp( | |
299 | requestIntervals_T1[endIdx])); | |
300 | ||
301 | // request | |
302 | validSequence = true; | |
f9673903 | 303 | TmfEventRequest<T> request = new TmfEventRequest<T>(k, trange, TmfDataRequest.ALL_DATA, DEFAULT_CHUNK) { |
03c71d1e | 304 | |
03c71d1e | 305 | @Override |
f9673903 | 306 | public void handleData(T event) { |
cb866e08 | 307 | if (event == null) { |
03c71d1e ASL |
308 | System.out |
309 | .println("Syntheric Event Received is null, after event: " | |
310 | + feventCount); | |
311 | return; | |
312 | } | |
313 | ||
03c71d1e ASL |
314 | // Listen to only one variant of synthetic event to keep |
315 | // track of | |
316 | if (event instanceof LttngSyntheticEvent) { | |
317 | if (((LttngSyntheticEvent) event).getSynType() != SequenceInd.BEFORE) { | |
318 | return; | |
319 | } | |
320 | } | |
321 | ||
322 | // Validating the orders of the first 20 events | |
2ecaca9d | 323 | if (printFirst20 && feventCount < 20) { |
03c71d1e ASL |
324 | long timevalue = event.getTimestamp().getValue(); |
325 | if (timevalue != expectedEvents_T1[feventCount]) { | |
326 | validSequence = false; | |
327 | System.out.println("Expected Event: " | |
328 | + expectedEvents_T1[feventCount] + " actual: " | |
329 | + event.getTimestamp().getValue()); | |
330 | } else { | |
331 | System.out.println("Synthetic Event: " + feventCount | |
332 | + " matched expected time"); | |
333 | } | |
334 | } | |
335 | ||
336 | // increment count | |
337 | incrementCount(); | |
338 | } | |
339 | ||
340 | /** | |
341 | * possibly increased by multiple request threads | |
342 | */ | |
343 | private synchronized void incrementCount() { | |
344 | feventCount++; | |
345 | } | |
346 | ||
347 | @Override | |
348 | public void handleCompleted() { | |
349 | // if (isCancelled() || isFailed()) { | |
350 | // // No notification to end request handlers | |
351 | // } else { | |
352 | // // notify the associated end request handlers | |
353 | // requestCompleted(); | |
354 | // } | |
355 | ||
f6b14ce2 | 356 | System.out.println("handleCompleted(request:" + startIdx + ") Number of events processed: " + feventCount); |
03c71d1e ASL |
357 | } |
358 | ||
359 | }; | |
360 | return request; | |
361 | } | |
362 | ||
363 | /** | |
364 | * Validation points | |
365 | */ | |
366 | private void fillInExpectedEvents() { | |
367 | expectedEvents_T1[0] = 13589759412128L; | |
368 | expectedEvents_T1[1] = 13589759419903L; | |
369 | expectedEvents_T1[2] = 13589759422785L; | |
370 | expectedEvents_T1[3] = 13589759425598L; | |
371 | expectedEvents_T1[4] = 13589759430979L; | |
372 | expectedEvents_T1[5] = 13589759433694L; | |
373 | expectedEvents_T1[6] = 13589759436212L; | |
374 | expectedEvents_T1[7] = 13589759438797L; | |
375 | expectedEvents_T1[8] = 13589759441253L; | |
376 | expectedEvents_T1[9] = 13589759444795L; | |
377 | expectedEvents_T1[10] = 13589759447800L; | |
378 | expectedEvents_T1[11] = 13589759450836L; | |
379 | expectedEvents_T1[12] = 13589759453835L; | |
380 | expectedEvents_T1[13] = 13589759459351L; | |
381 | expectedEvents_T1[14] = 13589759464411L; | |
382 | expectedEvents_T1[15] = 13589759467021L; | |
383 | expectedEvents_T1[16] = 13589759469668L; | |
384 | expectedEvents_T1[17] = 13589759474938L; | |
385 | expectedEvents_T1[18] = 13589759477536L; | |
386 | expectedEvents_T1[19] = 13589759480485L; | |
387 | } | |
388 | ||
389 | /** | |
390 | * Intervals for trace 1, separated %500 + last event | |
391 | */ | |
392 | private void fillInRequestIntervals() { | |
393 | requestIntervals_T1[0] = 13589759412128L; /* check point expected */ | |
394 | requestIntervals_T1[1] = 13589763490945L; /* between check points */ | |
395 | requestIntervals_T1[2] = 13589778265041L; /* check point expected */ | |
396 | requestIntervals_T1[3] = 13589783143445L; /* between check points */ | |
397 | requestIntervals_T1[4] = 13589786300104L; /* check point expected */ | |
398 | requestIntervals_T1[5] = 13589790722564L; /* between check points */ | |
399 | requestIntervals_T1[6] = 13589796139823L; /* check point expected */ | |
400 | requestIntervals_T1[7] = 13589800400562L; /* between check points */ | |
401 | requestIntervals_T1[8] = 13589801594374L; /* check point expected */ | |
402 | requestIntervals_T1[9] = 13589802750295L; /* between check points */ | |
403 | requestIntervals_T1[10] = 13589804071157L; /* check point expected */ | |
404 | requestIntervals_T1[11] = 13589810124488L; /* between check points */ | |
405 | requestIntervals_T1[12] = 13589822493183L; /* check point expected */ | |
406 | requestIntervals_T1[13] = 13589824131273L; /* between check points */ | |
407 | requestIntervals_T1[14] = 13589825398284L; /* check point expected */ | |
408 | requestIntervals_T1[15] = 13589826664185L; /* between check points */ | |
409 | requestIntervals_T1[16] = 13589827811998L; /* check point expected */ | |
410 | requestIntervals_T1[17] = 13589828915763L; /* between check points */ | |
411 | requestIntervals_T1[18] = 13589830074220L; /* check point expected */ | |
412 | requestIntervals_T1[19] = 13589831232050L; /* between check points */ | |
413 | requestIntervals_T1[20] = 13589832394049L; /* check point expected */ | |
414 | requestIntervals_T1[21] = 13589833852883L; /* between check points */ | |
415 | requestIntervals_T1[22] = 13589839626892L; /* check point expected */ | |
416 | requestIntervals_T1[23] = 13589849509798L; /* between check points */ | |
417 | requestIntervals_T1[24] = 13589850728538L; /* check point expected */ | |
418 | requestIntervals_T1[25] = 13589851889230L; /* between check points */ | |
419 | requestIntervals_T1[26] = 13589853294800L; /* check point expected */ | |
420 | requestIntervals_T1[27] = 13589859414998L; /* between check points */ | |
421 | requestIntervals_T1[28] = 13589878046089L; /* check point expected */ | |
422 | requestIntervals_T1[29] = 13589886468603L; /* between check points */ | |
423 | requestIntervals_T1[30] = 13589902256918L; /* check point expected */ | |
424 | requestIntervals_T1[31] = 13589906758692L; /* last event in T1 */ | |
425 | } | |
426 | ||
427 | } |