1 package org
.eclipse
.linuxtools
.lttng
.core
.tests
.trace
;
6 import junit
.framework
.TestCase
;
8 import org
.eclipse
.core
.runtime
.FileLocator
;
9 import org
.eclipse
.core
.runtime
.Path
;
10 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngLocation
;
11 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.trace
.LTTngTrace
;
12 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
13 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
14 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
15 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
17 import org
.osgi
.framework
.FrameworkUtil
;
20 Functions tested here :
21 public LTTngTrace(String path) throws Exception
22 public LTTngTrace(String path, boolean skipIndexing) throws Exception
24 public TmfTraceContext seekLocation(Object location) {
25 public TmfTraceContext seekEvent(TmfTimestamp timestamp) {
26 public TmfTraceContext seekEvent(long position) {
28 public TmfEvent getNextEvent(TmfTraceContext context) {
29 public Object getCurrentLocation() {
31 public LttngEvent parseEvent(TmfTraceContext context) {
33 public int getCpuNumber() {
36 @SuppressWarnings("nls")
37 public class LTTngTraceTest
extends TestCase
{
39 private final static String tracepath1
="traceset/trace-15316events_nolost_newformat";
40 private final static String wrongTracePath
="/somewhere/that/does/not/exist";
42 private final static int traceCpuNumber
=1;
44 private final static boolean skipIndexing
=true;
46 private final static long firstEventTimestamp
= 13589759412128L;
47 private final static long secondEventTimestamp
= 13589759419903L;
48 private final static Long locationAfterFirstEvent
= 13589759412128L;
50 private final static String tracename
= "traceset/trace-15316events_nolost_newformat";
52 private final static long indexToSeekFirst
= 0;
53 private final static Long locationToSeekFirst
= 13589759412128L;
54 private final static long contextValueAfterFirstEvent
= 13589759412128L;
55 private final static String firstEventReference
= tracename
+ "/metadata_0";
58 private final static long timestampToSeekTest1
= 13589826657302L;
59 private final static Long indexToSeekTest1
= 7497L;
60 private final static long locationToSeekTest1
= 13589826657302L;
61 private final static long contextValueAfterSeekTest1
= 13589826657302L;
62 private final static String seek1EventReference
= tracename
+ "/vm_state_0";
63 private final static long seekTimestamp
= 13589826657302L;
64 private final static long nextEventTimestamp
= 13589826659739L;
65 private final static long nextnextEventTimestamp
= 13589826662017L;
67 private final static long timestampToSeekLast
= 13589906758692L;
68 private final static Long indexToSeekLast
= 15315L;
69 private final static long locationToSeekLast
= 13589906758692L;
70 private final static long contextValueAfterSeekLast
= 13589906758692L;
71 private final static String seekLastEventReference
= tracename
+ "/kernel_0";
73 private static LTTngTrace testStream
= null;
74 private LTTngTrace
prepareStreamToTest() {
75 if (testStream
== null)
77 final URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(tracepath1
), null);
78 final File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
79 final LTTngTrace tmpStream
= new LTTngTrace(null, testfile
.getPath(), false);
80 testStream
= tmpStream
;
82 catch (final Exception e
) {
83 System
.out
.println("ERROR : Could not open " + tracepath1
);
87 testStream
.seekEvent(0L);
93 public void testTraceConstructors() {
94 // Default constructor
95 // Test constructor with argument on a wrong tracepath, skipping indexing
97 new LTTngTrace(null, wrongTracePath
, skipIndexing
);
98 fail("Construction with wrong tracepath should fail!");
100 catch( final Exception e
) {
103 // Test constructor with argument on a correct tracepath, skipping indexing
105 final URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(tracepath1
), null);
106 final File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
107 new LTTngTrace(null, testfile
.getPath(), skipIndexing
);
109 catch( final Exception e
) {
110 fail("Construction with correct tracepath failed!");
112 // System.out.println("Test completed");
115 public void testGetNextEvent() {
116 TmfEvent tmpEvent
= null;
117 final LTTngTrace testStream1
= prepareStreamToTest();
119 final TmfContext tmpContext
= new TmfContext(null, 0);
120 // We should be at the beginning of the trace, so we will just read the first event now
121 tmpEvent
= testStream1
.getNext(tmpContext
);
122 assertNotSame("tmpEvent is null after first getNextEvent()",null,tmpEvent
);
123 assertEquals("tmpEvent has wrong timestamp after first getNextEvent()",firstEventTimestamp
,tmpEvent
.getTimestamp().getValue() );
125 // Read the next event as well
126 tmpEvent
= testStream1
.getNext( tmpContext
);
127 assertNotSame("tmpEvent is null after second getNextEvent()",null,tmpEvent
);
128 assertEquals("tmpEvent has wrong timestamp after second getNextEvent()",secondEventTimestamp
,tmpEvent
.getTimestamp().getValue() );
131 public void testParseEvent() {
132 TmfEvent tmpEvent
= null;
133 final LTTngTrace testStream1
= prepareStreamToTest();
135 final TmfContext tmpContext
= new TmfContext(null, 0);
136 // We should be at the beginning of the trace, so we will just parse the first event now
137 tmpEvent
= testStream1
.parseEvent(tmpContext
);
138 assertNotSame("tmpEvent is null after first parseEvent()",null,tmpEvent
);
139 assertEquals("tmpEvent has wrong timestamp after first parseEvent()",firstEventTimestamp
,tmpEvent
.getTimestamp().getValue() );
141 // Use parseEvent again. Should be the same event
142 tmpEvent
= testStream1
.parseEvent(tmpContext
);
143 assertNotSame("tmpEvent is null after first parseEvent()",null,tmpEvent
);
144 assertEquals("tmpEvent has wrong timestamp after first parseEvent()",firstEventTimestamp
,tmpEvent
.getTimestamp().getValue() );
147 public void testSeekEventTimestamp() {
148 TmfEvent tmpEvent
= null;
149 ITmfContext tmpContext
= new TmfContext(null, 0);
150 final LTTngTrace testStream1
= prepareStreamToTest();
152 // We should be at the beginning of the trace, we will seek at a certain timestamp
153 tmpContext
= testStream1
.seekEvent(new TmfTimestamp(timestampToSeekTest1
, (byte) -9, 0));
154 tmpEvent
= testStream1
.getNext(tmpContext
);
155 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext
);
156 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1
,((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
157 assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent
);
158 assertTrue("tmpEvent has wrong reference after first seekEvent()", seek1EventReference
.contains(tmpEvent
.getReference()));
160 // Seek to the last timestamp
161 tmpContext
= testStream1
.seekEvent(new TmfTimestamp(timestampToSeekLast
, (byte) -9, 0));
162 tmpEvent
= testStream1
.getNext(tmpContext
);
163 assertNotSame("tmpContext is null after seekEvent() to last",null,tmpContext
);
164 assertEquals("tmpContext has wrong timestamp after seekEvent() to last",contextValueAfterSeekLast
,((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
165 assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent
);
166 assertTrue("tmpEvent has wrong reference after seekEvent() to last", seekLastEventReference
.contains(tmpEvent
.getReference()));
168 // Seek to the first timestamp (startTime)
169 tmpContext
= testStream1
.seekEvent(new TmfTimestamp(firstEventTimestamp
, (byte) -9, 0));
170 tmpEvent
= testStream1
.getNext(tmpContext
);
171 assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent
);
172 assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference
.contains(tmpEvent
.getReference()));
173 assertNotSame("tmpContext is null after seekEvent() to first",null,tmpContext
);
174 assertEquals("tmpContext has wrong timestamp after seekEvent() to first",contextValueAfterFirstEvent
,((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
177 public void testSeekEventIndex() {
178 TmfEvent tmpEvent
= null;
179 ITmfContext tmpContext
= new TmfContext(null, 0);
180 final LTTngTrace testStream1
= prepareStreamToTest();
182 // We should be at the beginning of the trace, we will seek at a certain timestamp
183 tmpContext
= testStream1
.seekEvent(indexToSeekTest1
);
184 tmpEvent
= testStream1
.getNext(tmpContext
);
185 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext
);
186 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1
,((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
187 assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent
);
188 assertTrue("tmpEvent has wrong reference after first seekEvent()", seek1EventReference
.contains(tmpEvent
.getReference()));
190 // Seek to the last timestamp
191 tmpContext
= testStream1
.seekEvent(indexToSeekLast
);
192 tmpEvent
= testStream1
.getNext(tmpContext
);
193 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext
);
194 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekLast
,((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
195 assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent
);
196 assertTrue("tmpEvent has wrong reference after seekEvent() to last", seekLastEventReference
.contains(tmpEvent
.getReference()));
198 // Seek to the first timestamp (startTime)
199 tmpContext
= testStream1
.seekEvent(indexToSeekFirst
);
200 tmpEvent
= testStream1
.getNext(tmpContext
);
201 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext
);
202 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterFirstEvent
,((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
203 assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent
);
204 assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference
.contains(tmpEvent
.getReference()));
207 public void testSeekLocation() {
208 TmfEvent tmpEvent
= null;
209 ITmfContext tmpContext
= new TmfContext(null, 0);
210 final LTTngTrace testStream1
= prepareStreamToTest();
212 // We should be at the beginning of the trace, we will seek at a certain timestamp
213 tmpContext
= testStream1
.seekEvent(new LttngLocation(locationToSeekTest1
));
214 tmpEvent
= testStream1
.getNext(tmpContext
);
215 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext
);
216 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekTest1
,((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
217 assertNotSame("tmpEvent is null after first seekLocation()",null,tmpEvent
);
218 assertTrue("tmpEvent has wrong reference after first seekLocation()", seek1EventReference
.contains(tmpEvent
.getReference()));
220 // Seek to the last timestamp
221 tmpContext
= testStream1
.seekEvent(new LttngLocation(locationToSeekLast
));
222 tmpEvent
= testStream1
.getNext(tmpContext
);
223 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext
);
224 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekLast
,((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
225 assertNotSame("tmpEvent is null after seekLocation() to last ",null,tmpEvent
);
226 assertTrue("tmpEvent has wrong reference after seekLocation() to last", seekLastEventReference
.contains(tmpEvent
.getReference()));
228 // Seek to the first timestamp (startTime)
229 tmpContext
= testStream1
.seekEvent(new LttngLocation(locationToSeekFirst
));
230 tmpEvent
= testStream1
.getNext(tmpContext
);
231 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext
);
232 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterFirstEvent
,((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
233 assertNotSame("tmpEvent is null after seekLocation() to start ",null,tmpEvent
);
234 assertTrue("tmpEvent has wrong reference after seekLocation() to start", firstEventReference
.contains(tmpEvent
.getReference()));
237 public void testLocationOperations() {
238 TmfEvent tmpEvent
= null;
239 ITmfContext tmpContext
= new TmfContext(null, 0);
240 final LTTngTrace testStream1
= prepareStreamToTest();
242 // Test LttngLocation after a seek
243 tmpContext
= testStream1
.seekEvent(new LttngLocation(seekTimestamp
));
244 LttngLocation location
= (LttngLocation
) tmpContext
.getLocation().clone();
245 assertTrue("location has wrong flag", location
.isLastOperationSeek());
246 assertEquals("location has wrong operation time", seekTimestamp
, location
.getOperationTimeValue());
247 tmpContext
= testStream1
.seekEvent(location
);
248 tmpEvent
= testStream1
.getNext(tmpContext
);
249 assertTrue("tmpContext is null after getNextEvent()", tmpEvent
!= null);
250 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
252 // Test LttngLocation after a parse
253 tmpContext
= testStream1
.seekEvent(new LttngLocation(seekTimestamp
));
254 tmpEvent
= testStream
.parseEvent(tmpContext
);
255 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
256 location
= (LttngLocation
) tmpContext
.getLocation().clone();
257 assertTrue("location has wrong flag", location
.isLastOperationParse());
258 assertEquals("location has wrong operation time", seekTimestamp
, location
.getOperationTimeValue());
259 tmpContext
= testStream1
.seekEvent(location
);
260 tmpEvent
= testStream1
.getNext(tmpContext
);
261 assertTrue("tmpContext is null after getNextEvent()", tmpEvent
!= null);
262 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
264 // Test LttngLocation after a getNext
265 tmpContext
= testStream1
.seekEvent(new LttngLocation(seekTimestamp
));
266 tmpEvent
= testStream
.getNext(tmpContext
);
267 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
268 location
= (LttngLocation
) tmpContext
.getLocation().clone();
269 assertTrue("location has wrong flag", location
.isLastOperationReadNext());
270 assertEquals("location has wrong operation time", seekTimestamp
, location
.getOperationTimeValue());
271 tmpContext
= testStream1
.seekEvent(location
);
272 tmpEvent
= testStream1
.getNext(tmpContext
);
273 assertTrue("tmpContext is null after getNextEvent()", tmpEvent
!= null);
274 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
276 // Test LttngLocation after a parse and parse
277 tmpContext
= testStream1
.seekEvent(new LttngLocation(seekTimestamp
));
278 tmpEvent
= testStream
.parseEvent(tmpContext
);
279 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
280 tmpEvent
= testStream
.parseEvent(tmpContext
);
281 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
282 location
= (LttngLocation
) tmpContext
.getLocation().clone();
283 assertTrue("location has wrong flag", location
.isLastOperationParse());
284 assertEquals("location has wrong operation time", seekTimestamp
, location
.getOperationTimeValue());
285 tmpContext
= testStream1
.seekEvent(location
);
286 tmpEvent
= testStream1
.getNext(tmpContext
);
287 assertTrue("tmpContext is null after getNextEvent()", tmpEvent
!= null);
288 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
290 // Test LttngLocation after a getNext and getNext
291 tmpContext
= testStream1
.seekEvent(new LttngLocation(seekTimestamp
));
292 tmpEvent
= testStream
.getNext(tmpContext
);
293 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
294 tmpEvent
= testStream
.getNext(tmpContext
);
295 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
296 location
= (LttngLocation
) tmpContext
.getLocation().clone();
297 assertTrue("location has wrong flag", location
.isLastOperationReadNext());
298 assertEquals("location has wrong operation time", nextEventTimestamp
, location
.getOperationTimeValue());
299 tmpContext
= testStream1
.seekEvent(location
);
300 tmpEvent
= testStream1
.getNext(tmpContext
);
301 assertTrue("tmpContext is null after getNextEvent()", tmpEvent
!= null);
302 assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
304 // Test LttngLocation after a getNext and parse
305 tmpContext
= testStream1
.seekEvent(new LttngLocation(seekTimestamp
));
306 tmpEvent
= testStream
.getNext(tmpContext
);
307 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
308 tmpEvent
= testStream
.parseEvent(tmpContext
);
309 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
310 location
= (LttngLocation
) tmpContext
.getLocation().clone();
311 assertTrue("location has wrong flag", location
.isLastOperationParse());
312 assertEquals("location has wrong operation time", nextEventTimestamp
, location
.getOperationTimeValue());
313 tmpContext
= testStream1
.seekEvent(location
);
314 tmpEvent
= testStream1
.getNext(tmpContext
);
315 assertTrue("tmpContext is null after getNextEvent()", tmpEvent
!= null);
316 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
318 // Test LttngLocation after a parse and getNext
319 tmpContext
= testStream1
.seekEvent(new LttngLocation(seekTimestamp
));
320 tmpEvent
= testStream
.parseEvent(tmpContext
);
321 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
322 tmpEvent
= testStream
.getNext(tmpContext
);
323 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
324 location
= (LttngLocation
) tmpContext
.getLocation().clone();
325 assertTrue("location has wrong flag", location
.isLastOperationReadNext());
326 assertEquals("location has wrong operation time", seekTimestamp
, location
.getOperationTimeValue());
327 tmpContext
= testStream1
.seekEvent(location
);
328 tmpEvent
= testStream1
.getNext(tmpContext
);
329 assertTrue("tmpContext is null after getNextEvent()", tmpEvent
!= null);
330 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
332 // Test LttngLocation after a parse, getNext and parse
333 tmpContext
= testStream1
.seekEvent(new LttngLocation(seekTimestamp
));
334 tmpEvent
= testStream
.parseEvent(tmpContext
);
335 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
336 tmpEvent
= testStream
.getNext(tmpContext
);
337 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
338 tmpEvent
= testStream
.parseEvent(tmpContext
);
339 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
340 location
= (LttngLocation
) tmpContext
.getLocation().clone();
341 assertTrue("location has wrong flag", location
.isLastOperationParse());
342 assertEquals("location has wrong operation time", nextEventTimestamp
, location
.getOperationTimeValue());
343 tmpContext
= testStream1
.seekEvent(location
);
344 tmpEvent
= testStream1
.getNext(tmpContext
);
345 assertTrue("tmpContext is null after getNextEvent()", tmpEvent
!= null);
346 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
348 // Test LttngLocation after a parse, getNext and getNext
349 tmpContext
= testStream1
.seekEvent(new LttngLocation(seekTimestamp
));
350 tmpEvent
= testStream
.parseEvent(tmpContext
);
351 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
352 tmpEvent
= testStream
.getNext(tmpContext
);
353 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
354 tmpEvent
= testStream
.getNext(tmpContext
);
355 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
356 location
= (LttngLocation
) tmpContext
.getLocation().clone();
357 assertTrue("location has wrong flag", location
.isLastOperationReadNext());
358 assertEquals("location has wrong operation time", nextEventTimestamp
, location
.getOperationTimeValue());
359 tmpContext
= testStream1
.seekEvent(location
);
360 tmpEvent
= testStream1
.getNext(tmpContext
);
361 assertTrue("tmpContext is null after getNextEvent()", tmpEvent
!= null);
362 assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
364 // Test LttngLocation after a getNext, parse and parse
365 tmpContext
= testStream1
.seekEvent(new LttngLocation(seekTimestamp
));
366 tmpEvent
= testStream
.getNext(tmpContext
);
367 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
368 tmpEvent
= testStream
.parseEvent(tmpContext
);
369 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
370 tmpEvent
= testStream
.parseEvent(tmpContext
);
371 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
372 location
= (LttngLocation
) tmpContext
.getLocation().clone();
373 assertTrue("location has wrong flag", location
.isLastOperationParse());
374 assertEquals("location has wrong operation time", nextEventTimestamp
, location
.getOperationTimeValue());
375 tmpContext
= testStream1
.seekEvent(location
);
376 tmpEvent
= testStream1
.getNext(tmpContext
);
377 assertTrue("tmpContext is null after getNextEvent()", tmpEvent
!= null);
378 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
380 // Test LttngLocation after a getNext, parse and getNext
381 tmpContext
= testStream1
.seekEvent(new LttngLocation(seekTimestamp
));
382 tmpEvent
= testStream
.getNext(tmpContext
);
383 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
384 tmpEvent
= testStream
.parseEvent(tmpContext
);
385 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
386 tmpEvent
= testStream
.getNext(tmpContext
);
387 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
388 location
= (LttngLocation
) tmpContext
.getLocation().clone();
389 assertTrue("location has wrong flag", location
.isLastOperationReadNext());
390 assertEquals("location has wrong operation time", nextEventTimestamp
, location
.getOperationTimeValue());
391 tmpContext
= testStream1
.seekEvent(location
);
392 tmpEvent
= testStream1
.getNext(tmpContext
);
393 assertTrue("tmpContext is null after getNextEvent()", tmpEvent
!= null);
394 assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
396 // Test LttngLocation after a getNext, getNext and parse
397 tmpContext
= testStream1
.seekEvent(new LttngLocation(seekTimestamp
));
398 tmpEvent
= testStream
.getNext(tmpContext
);
399 assertEquals("tmpEvent has wrong timestamp", seekTimestamp
, tmpEvent
.getTimestamp().getValue());
400 tmpEvent
= testStream
.getNext(tmpContext
);
401 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
402 tmpEvent
= testStream
.parseEvent(tmpContext
);
403 assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
404 location
= (LttngLocation
) tmpContext
.getLocation().clone();
405 assertTrue("location has wrong flag", location
.isLastOperationParse());
406 assertEquals("location has wrong operation time", nextnextEventTimestamp
, location
.getOperationTimeValue());
407 tmpContext
= testStream1
.seekEvent(location
);
408 tmpEvent
= testStream1
.getNext(tmpContext
);
409 assertTrue("tmpContext is null after getNextEvent()", tmpEvent
!= null);
410 assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp
, tmpEvent
.getTimestamp().getValue());
413 public void testConcurrentOperations() {
414 final LTTngTrace testStream
= prepareStreamToTest();
415 ITmfEvent event1
= null;
416 ITmfEvent event2
= null;
417 ITmfContext context1
;
418 ITmfContext context2
;
420 // Test concurrent interference (seek) after a seek
421 context1
= testStream
.seekEvent(new LttngLocation(seekTimestamp
));
422 context2
= testStream
.seekEvent(new LttngLocation(timestampToSeekLast
));
423 event1
= testStream
.getNext(context1
);
424 assertTrue("event is null after getNext()", event1
!= null);
425 assertEquals("event has wrong timestamp", seekTimestamp
, event1
.getTimestamp().getValue());
427 // Test concurrent interference (parseEvent) after a seek
428 context2
= testStream
.seekEvent(new LttngLocation(timestampToSeekLast
));
429 context1
= testStream
.seekEvent(new LttngLocation(seekTimestamp
));
430 event2
= testStream
.parseEvent(context2
);
431 assertTrue("event is null after parseEvent()", event2
!= null);
432 assertEquals("event has wrong timestamp", timestampToSeekLast
, event2
.getTimestamp().getValue());
433 event1
= testStream
.getNext(context1
);
434 assertTrue("event is null after getNext()", event1
!= null);
435 assertEquals("event has wrong timestamp", seekTimestamp
, event1
.getTimestamp().getValue());
437 // Test concurrent interference (getNext) after a seek
438 context2
= testStream
.seekEvent(new LttngLocation(timestampToSeekLast
));
439 context1
= testStream
.seekEvent(new LttngLocation(seekTimestamp
));
440 event2
= testStream
.getNext(context2
);
441 assertTrue("event is null after getNext()", event2
!= null);
442 assertEquals("event has wrong timestamp", timestampToSeekLast
, event2
.getTimestamp().getValue());
443 event1
= testStream
.getNext(context1
);
444 assertTrue("event is null after getNext()", event1
!= null);
445 assertEquals("event has wrong timestamp", seekTimestamp
, event1
.getTimestamp().getValue());
447 // Test concurrent interference (seek) after a parseEvent
448 context1
= testStream
.seekEvent(new LttngLocation(seekTimestamp
));
449 event1
= testStream
.parseEvent(context1
);
450 assertTrue("event is null after getNext()", event1
!= null);
451 assertEquals("event has wrong timestamp", seekTimestamp
, event1
.getTimestamp().getValue());
452 context2
= testStream
.seekEvent(new LttngLocation(timestampToSeekLast
));
453 event1
= testStream
.getNext(context1
);
454 assertTrue("event is null after getNext()", event1
!= null);
455 assertEquals("event has wrong timestamp", seekTimestamp
, event1
.getTimestamp().getValue());
457 // Test concurrent interference (parseEvent) after a parseEvent
458 context2
= testStream
.seekEvent(new LttngLocation(timestampToSeekLast
));
459 context1
= testStream
.seekEvent(new LttngLocation(seekTimestamp
));
460 event1
= testStream
.parseEvent(context1
);
461 assertTrue("event is null after getNext()", event1
!= null);
462 assertEquals("event has wrong timestamp", seekTimestamp
, event1
.getTimestamp().getValue());
463 event2
= testStream
.parseEvent(context2
);
464 assertTrue("event is null after parseEvent()", event2
!= null);
465 assertEquals("event has wrong timestamp", timestampToSeekLast
, event2
.getTimestamp().getValue());
466 event1
= testStream
.getNext(context1
);
467 assertTrue("event is null after getNext()", event1
!= null);
468 assertEquals("event has wrong timestamp", seekTimestamp
, event1
.getTimestamp().getValue());
470 // Test concurrent interference (getNext) after a parseEvent
471 context2
= testStream
.seekEvent(new LttngLocation(timestampToSeekLast
));
472 context1
= testStream
.seekEvent(new LttngLocation(seekTimestamp
));
473 event1
= testStream
.parseEvent(context1
);
474 assertTrue("event is null after getNext()", event1
!= null);
475 assertEquals("event has wrong timestamp", seekTimestamp
, event1
.getTimestamp().getValue());
476 event2
= testStream
.getNext(context2
);
477 assertTrue("event is null after getNext()", event2
!= null);
478 assertEquals("event has wrong timestamp", timestampToSeekLast
, event2
.getTimestamp().getValue());
479 event1
= testStream
.getNext(context1
);
480 assertTrue("event is null after getNext()", event1
!= null);
481 assertEquals("event has wrong timestamp", seekTimestamp
, event1
.getTimestamp().getValue());
483 // Test concurrent interference (seek) after a getNext
484 context1
= testStream
.seekEvent(new LttngLocation(seekTimestamp
));
485 event1
= testStream
.getNext(context1
);
486 assertTrue("event is null after getNext()", event1
!= null);
487 assertEquals("event has wrong timestamp", seekTimestamp
, event1
.getTimestamp().getValue());
488 context2
= testStream
.seekEvent(new LttngLocation(timestampToSeekLast
));
489 event1
= testStream
.getNext(context1
);
490 assertTrue("event is null after getNext()", event1
!= null);
491 assertEquals("event has wrong timestamp", nextEventTimestamp
, event1
.getTimestamp().getValue());
493 // Test concurrent interference (parseEvent) after a getNext
494 context2
= testStream
.seekEvent(new LttngLocation(timestampToSeekLast
));
495 context1
= testStream
.seekEvent(new LttngLocation(seekTimestamp
));
496 event1
= testStream
.getNext(context1
);
497 assertTrue("event is null after getNext()", event1
!= null);
498 assertEquals("event has wrong timestamp", seekTimestamp
, event1
.getTimestamp().getValue());
499 event2
= testStream
.parseEvent(context2
);
500 assertTrue("event is null after parseEvent()", event2
!= null);
501 assertEquals("event has wrong timestamp", timestampToSeekLast
, event2
.getTimestamp().getValue());
502 event1
= testStream
.getNext(context1
);
503 assertTrue("event is null after getNext()", event1
!= null);
504 assertEquals("event has wrong timestamp", nextEventTimestamp
, event1
.getTimestamp().getValue());
506 // Test concurrent interference (getNext) after a getNext
507 context2
= testStream
.seekEvent(new LttngLocation(timestampToSeekLast
));
508 context1
= testStream
.seekEvent(new LttngLocation(seekTimestamp
));
509 event1
= testStream
.getNext(context1
);
510 assertTrue("event is null after getNext()", event1
!= null);
511 assertEquals("event has wrong timestamp", seekTimestamp
, event1
.getTimestamp().getValue());
512 event2
= testStream
.getNext(context2
);
513 assertTrue("event is null after getNext()", event2
!= null);
514 assertEquals("event has wrong timestamp", timestampToSeekLast
, event2
.getTimestamp().getValue());
515 event1
= testStream
.getNext(context1
);
516 assertTrue("event is null after getNext()", event1
!= null);
517 assertEquals("event has wrong timestamp", nextEventTimestamp
, event1
.getTimestamp().getValue());
520 public void testGetter() {
521 TmfEvent tmpEvent
= null;
522 final LTTngTrace testStream1
= prepareStreamToTest();
524 // Move to the first event to have something to play with
525 tmpEvent
= testStream1
.parseEvent( new TmfContext(null, 0));
527 // Test current event
528 assertNotSame("tmpEvent is null after first event",null,tmpEvent
);
529 assertTrue("tmpEvent has wrong reference after first event", firstEventReference
.contains(tmpEvent
.getReference()));
530 assertNotSame("tmpContext is null after first seekEvent()",null,testStream1
.getCurrentLocation() );
531 assertTrue("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent
.equals( ((LttngLocation
)testStream1
.getCurrentLocation()).getOperationTimeValue()) );
533 // Test CPU number of the trace
534 assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber
,testStream1
.getCpuNumber() );
537 public void testToString() {
538 final LTTngTrace testStream1
= prepareStreamToTest();
540 // Move to the first event to have something to play with
541 testStream1
.parseEvent( new TmfContext(null, 0) );
543 // Just make sure toString() does not return null or the java reference
544 assertNotSame("toString returned null",null, testStream1
.toString() );
545 assertNotSame("toString is not overridded!", testStream1
.getClass().getName() + '@' + Integer
.toHexString(testStream1
.hashCode()), testStream1
.toString() );