Make test plugins fragments.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core.tests / src / org / eclipse / linuxtools / lttng / core / tests / trace / LTTngTraceTest.java
CommitLineData
6c13869b 1package org.eclipse.linuxtools.lttng.core.tests.trace;
03c71d1e
ASL
2
3import java.io.File;
4import java.net.URL;
5
6import junit.framework.TestCase;
7
8import org.eclipse.core.runtime.FileLocator;
9import org.eclipse.core.runtime.Path;
5945cec9
FC
10import org.eclipse.linuxtools.internal.lttng.core.event.LttngLocation;
11import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTrace;
6c13869b
FC
12import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
13import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
14import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
9269df72 15import org.osgi.framework.FrameworkUtil;
03c71d1e
ASL
16
17/*
18 Functions tested here :
19 public LTTngTrace(String path) throws Exception
20 public LTTngTrace(String path, boolean skipIndexing) throws Exception
21
22 public TmfTraceContext seekLocation(Object location) {
23 public TmfTraceContext seekEvent(TmfTimestamp timestamp) {
24 public TmfTraceContext seekEvent(long position) {
25
26 public TmfEvent getNextEvent(TmfTraceContext context) {
27 public Object getCurrentLocation() {
28
29 public LttngEvent parseEvent(TmfTraceContext context) {
30
31 public int getCpuNumber() {
32 */
33
3b38ea61 34@SuppressWarnings("nls")
03c71d1e
ASL
35public class LTTngTraceTest extends TestCase {
36
37 private final static String tracepath1="traceset/trace-15316events_nolost_newformat";
38 private final static String wrongTracePath="/somewhere/that/does/not/exist";
39
40 private final static int traceCpuNumber=1;
41
42 private final static boolean skipIndexing=true;
43
44 private final static long firstEventTimestamp = 13589759412128L;
45 private final static long secondEventTimestamp = 13589759419903L;
46 private final static Long locationAfterFirstEvent = 13589759412128L;
47
48 private final static String tracename = "traceset/trace-15316events_nolost_newformat";
49
50 private final static long indexToSeekFirst = 0;
51 private final static Long locationToSeekFirst = 13589759412128L;
52 private final static long contextValueAfterFirstEvent = 13589759412128L;
53 private final static String firstEventReference = tracename + "/metadata_0";
54
55
56 private final static long timestampToSeekTest1 = 13589826657302L;
57 private final static Long indexToSeekTest1 = 7497L;
58 private final static long locationToSeekTest1 = 13589826657302L;
59 private final static long contextValueAfterSeekTest1 = 13589826657302L;
60 private final static String seek1EventReference = tracename + "/vm_state_0";
61d428bd
PT
61 private final static long seekTimestamp = 13589826657302L;
62 private final static long nextEventTimestamp = 13589826659739L;
63 private final static long nextnextEventTimestamp = 13589826662017L;
03c71d1e
ASL
64
65 private final static long timestampToSeekLast = 13589906758692L;
66 private final static Long indexToSeekLast = 15315L;
67 private final static long locationToSeekLast = 13589906758692L;
68 private final static long contextValueAfterSeekLast = 13589906758692L;
69 private final static String seekLastEventReference = tracename + "/kernel_0";
70
71 private static LTTngTrace testStream = null;
72 private LTTngTrace prepareStreamToTest() {
73 if (testStream == null) {
74 try {
9269df72 75 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(tracepath1), null);
03c71d1e 76 File testfile = new File(FileLocator.toFileURL(location).toURI());
0710697b 77 LTTngTrace tmpStream = new LTTngTrace(testfile.getName(), testfile.getPath(), false);
03c71d1e
ASL
78 testStream = tmpStream;
79 }
80 catch (Exception e) {
81 System.out.println("ERROR : Could not open " + tracepath1);
82 testStream = null;
83 }
84 }
85 else {
bc9a0029 86 testStream.seekEvent(0L);
03c71d1e
ASL
87 }
88
89
90 return testStream;
91 }
92
93 public void testTraceConstructors() {
03c71d1e
ASL
94 // Default constructor
95 // Test constructor with argument on a wrong tracepath, skipping indexing
96 try {
f9a8715c 97 new LTTngTrace("", wrongTracePath, skipIndexing);
03c71d1e
ASL
98 fail("Construction with wrong tracepath should fail!");
99 }
100 catch( Exception e) {
101 }
102
103 // Test constructor with argument on a correct tracepath, skipping indexing
104 try {
9269df72 105 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(tracepath1), null);
03c71d1e 106 File testfile = new File(FileLocator.toFileURL(location).toURI());
f9a8715c 107 new LTTngTrace(testfile.getName(), testfile.getPath(), skipIndexing);
03c71d1e
ASL
108 }
109 catch( Exception e) {
110 fail("Construction with correct tracepath failed!");
111 }
f9a8715c 112// System.out.println("Test completed");
03c71d1e
ASL
113 }
114
115 public void testGetNextEvent() {
116 TmfEvent tmpEvent = null;
117 LTTngTrace testStream1 = prepareStreamToTest();
118
9f584e4c 119 TmfContext tmpContext = new TmfContext(null, 0);
03c71d1e
ASL
120 // We should be at the beginning of the trace, so we will just read the first event now
121 tmpEvent = testStream1.getNextEvent(tmpContext );
122 assertNotSame("tmpEvent is null after first getNextEvent()",null,tmpEvent );
123 assertEquals("tmpEvent has wrong timestamp after first getNextEvent()",firstEventTimestamp,(long)tmpEvent.getTimestamp().getValue() );
124
125 // Read the next event as well
126 tmpEvent = testStream1.getNextEvent( tmpContext);
127 assertNotSame("tmpEvent is null after second getNextEvent()",null,tmpEvent );
128 assertEquals("tmpEvent has wrong timestamp after second getNextEvent()",secondEventTimestamp,(long)tmpEvent.getTimestamp().getValue() );
129 }
130
131 public void testParseEvent() {
132 TmfEvent tmpEvent = null;
133 LTTngTrace testStream1 = prepareStreamToTest();
134
9f584e4c 135 TmfContext tmpContext = new TmfContext(null, 0);
03c71d1e
ASL
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,(long)tmpEvent.getTimestamp().getValue() );
140
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,(long)tmpEvent.getTimestamp().getValue() );
145 }
146
147 public void testSeekEventTimestamp() {
148 TmfEvent tmpEvent = null;
9f584e4c 149 TmfContext tmpContext = new TmfContext(null, 0);
03c71d1e
ASL
150 LTTngTrace testStream1 = prepareStreamToTest();
151
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.getNextEvent(tmpContext);
155 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
156 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
157 assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent );
4641c2f7 158 assertTrue("tmpEvent has wrong reference after first seekEvent()", seek1EventReference.contains((String)tmpEvent.getReference()));
03c71d1e
ASL
159
160 // Seek to the last timestamp
161 tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekLast, (byte) -9, 0));
162 tmpEvent = testStream1.getNextEvent(tmpContext);
163 assertNotSame("tmpContext is null after seekEvent() to last",null,tmpContext );
164 assertEquals("tmpContext has wrong timestamp after seekEvent() to last",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
165 assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent );
4641c2f7 166 assertTrue("tmpEvent has wrong reference after seekEvent() to last", seekLastEventReference.contains((String)tmpEvent.getReference()));
03c71d1e
ASL
167
168 // Seek to the first timestamp (startTime)
169 tmpContext = testStream1.seekEvent(new TmfTimestamp(firstEventTimestamp, (byte) -9, 0));
170 tmpEvent = testStream1.getNextEvent(tmpContext);
171 assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent );
4641c2f7 172 assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference.contains((String)tmpEvent.getReference()));
03c71d1e
ASL
173 assertNotSame("tmpContext is null after seekEvent() to first",null,tmpContext );
174 assertEquals("tmpContext has wrong timestamp after seekEvent() to first",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
175 }
176
177 public void testSeekEventIndex() {
178 TmfEvent tmpEvent = null;
9f584e4c 179 TmfContext tmpContext = new TmfContext(null, 0);
03c71d1e
ASL
180 LTTngTrace testStream1 = prepareStreamToTest();
181
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.getNextEvent(tmpContext);
185 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
186 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
187 assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent );
4641c2f7 188 assertTrue("tmpEvent has wrong reference after first seekEvent()", seek1EventReference.contains((String)tmpEvent.getReference()));
03c71d1e
ASL
189
190 // Seek to the last timestamp
191 tmpContext = testStream1.seekEvent(indexToSeekLast);
192 tmpEvent = testStream1.getNextEvent(tmpContext);
193 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
194 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
195 assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent );
4641c2f7 196 assertTrue("tmpEvent has wrong reference after seekEvent() to last", seekLastEventReference.contains((String)tmpEvent.getReference()));
03c71d1e
ASL
197
198 // Seek to the first timestamp (startTime)
199 tmpContext = testStream1.seekEvent(indexToSeekFirst);
200 tmpEvent = testStream1.getNextEvent(tmpContext);
201 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
202 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
203 assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent );
4641c2f7 204 assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference.contains((String)tmpEvent.getReference()));
03c71d1e
ASL
205 }
206
207 public void testSeekLocation() {
208 TmfEvent tmpEvent = null;
9f584e4c 209 TmfContext tmpContext = new TmfContext(null, 0);
03c71d1e
ASL
210 LTTngTrace testStream1 = prepareStreamToTest();
211
212 // We should be at the beginning of the trace, we will seek at a certain timestamp
bc9a0029 213 tmpContext = testStream1.seekLocation(new LttngLocation(locationToSeekTest1));
03c71d1e
ASL
214 tmpEvent = testStream1.getNextEvent(tmpContext);
215 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
216 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
217 assertNotSame("tmpEvent is null after first seekLocation()",null,tmpEvent );
4641c2f7 218 assertTrue("tmpEvent has wrong reference after first seekLocation()", seek1EventReference.contains((String)tmpEvent.getReference()));
03c71d1e
ASL
219
220 // Seek to the last timestamp
bc9a0029 221 tmpContext = testStream1.seekLocation(new LttngLocation(locationToSeekLast));
03c71d1e
ASL
222 tmpEvent = testStream1.getNextEvent(tmpContext);
223 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
224 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
225 assertNotSame("tmpEvent is null after seekLocation() to last ",null,tmpEvent );
4641c2f7 226 assertTrue("tmpEvent has wrong reference after seekLocation() to last", seekLastEventReference.contains((String)tmpEvent.getReference()));
03c71d1e
ASL
227
228 // Seek to the first timestamp (startTime)
bc9a0029 229 tmpContext = testStream1.seekLocation(new LttngLocation(locationToSeekFirst));
03c71d1e
ASL
230 tmpEvent = testStream1.getNextEvent(tmpContext);
231 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
232 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
233 assertNotSame("tmpEvent is null after seekLocation() to start ",null,tmpEvent );
4641c2f7 234 assertTrue("tmpEvent has wrong reference after seekLocation() to start", firstEventReference.contains((String)tmpEvent.getReference()));
03c71d1e 235 }
61d428bd
PT
236
237 public void testLocationOperations() {
238 TmfEvent tmpEvent = null;
239 TmfContext tmpContext = new TmfContext(null, 0);
240 LTTngTrace testStream1 = prepareStreamToTest();
241
242 // Test LttngLocation after a seek
243 tmpContext = testStream1.seekLocation(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.seekLocation(location);
248 tmpEvent = testStream1.getNextEvent(tmpContext);
249 assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
250 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
251
252 // Test LttngLocation after a parse
253 tmpContext = testStream1.seekLocation(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.seekLocation(location);
260 tmpEvent = testStream1.getNextEvent(tmpContext);
261 assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
262 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
263
264 // Test LttngLocation after a getNext
265 tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
266 tmpEvent = testStream.getNextEvent(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.seekLocation(location);
272 tmpEvent = testStream1.getNextEvent(tmpContext);
273 assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
274 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
275
276 // Test LttngLocation after a parse and parse
277 tmpContext = testStream1.seekLocation(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.seekLocation(location);
286 tmpEvent = testStream1.getNextEvent(tmpContext);
287 assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
288 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
289
290 // Test LttngLocation after a getNext and getNext
291 tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
292 tmpEvent = testStream.getNextEvent(tmpContext);
293 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
294 tmpEvent = testStream.getNextEvent(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.seekLocation(location);
300 tmpEvent = testStream1.getNextEvent(tmpContext);
301 assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
302 assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
303
304 // Test LttngLocation after a getNext and parse
305 tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
306 tmpEvent = testStream.getNextEvent(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.seekLocation(location);
314 tmpEvent = testStream1.getNextEvent(tmpContext);
315 assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
316 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
317
318 // Test LttngLocation after a parse and getNext
319 tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
320 tmpEvent = testStream.parseEvent(tmpContext);
321 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
322 tmpEvent = testStream.getNextEvent(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.seekLocation(location);
328 tmpEvent = testStream1.getNextEvent(tmpContext);
329 assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
330 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
331
332 // Test LttngLocation after a parse, getNext and parse
333 tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
334 tmpEvent = testStream.parseEvent(tmpContext);
335 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
336 tmpEvent = testStream.getNextEvent(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.seekLocation(location);
344 tmpEvent = testStream1.getNextEvent(tmpContext);
345 assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
346 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
347
348 // Test LttngLocation after a parse, getNext and getNext
349 tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
350 tmpEvent = testStream.parseEvent(tmpContext);
351 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
352 tmpEvent = testStream.getNextEvent(tmpContext);
353 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
354 tmpEvent = testStream.getNextEvent(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.seekLocation(location);
360 tmpEvent = testStream1.getNextEvent(tmpContext);
361 assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
362 assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
363
364 // Test LttngLocation after a getNext, parse and parse
365 tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
366 tmpEvent = testStream.getNextEvent(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.seekLocation(location);
376 tmpEvent = testStream1.getNextEvent(tmpContext);
377 assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
378 assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
379
380 // Test LttngLocation after a getNext, parse and getNext
381 tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
382 tmpEvent = testStream.getNextEvent(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.getNextEvent(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.seekLocation(location);
392 tmpEvent = testStream1.getNextEvent(tmpContext);
393 assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
394 assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
395
396 // Test LttngLocation after a getNext, getNext and parse
397 tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
398 tmpEvent = testStream.getNextEvent(tmpContext);
399 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
400 tmpEvent = testStream.getNextEvent(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.seekLocation(location);
408 tmpEvent = testStream1.getNextEvent(tmpContext);
409 assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
410 assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
411 }
412
03c71d1e
ASL
413 public void testGetter() {
414 TmfEvent tmpEvent = null;
415 LTTngTrace testStream1 = prepareStreamToTest();
416
417 // Move to the first event to have something to play with
9f584e4c 418 tmpEvent = testStream1.parseEvent( new TmfContext(null, 0));
03c71d1e
ASL
419
420 // Test current event
421 assertNotSame("tmpEvent is null after first event",null,tmpEvent );
4641c2f7 422 assertTrue("tmpEvent has wrong reference after first event", firstEventReference.contains((String)tmpEvent.getReference()));
03c71d1e 423 assertNotSame("tmpContext is null after first seekEvent()",null,testStream1.getCurrentLocation() );
04aa919f 424 assertTrue("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent.equals( ((LttngLocation)testStream1.getCurrentLocation()).getOperationTimeValue()) );
03c71d1e
ASL
425
426 // Test CPU number of the trace
427 assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber ,testStream1.getCpuNumber() );
428 }
429
430 public void testToString() {
431 LTTngTrace testStream1 = prepareStreamToTest();
432
433 // Move to the first event to have something to play with
9f584e4c 434 testStream1.parseEvent( new TmfContext(null, 0) );
03c71d1e
ASL
435
436 // Just make sure toString() does not return null or the java reference
437 assertNotSame("toString returned null",null, testStream1.toString() );
438 assertNotSame("toString is not overridded!", testStream1.getClass().getName() + '@' + Integer.toHexString(testStream1.hashCode()), testStream1.toString() );
439 }
440
441}
This page took 0.050022 seconds and 5 git commands to generate.