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