tmf: Use tabs in statistics view for each traces
[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;
bcf8b0f3 12import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
6c13869b
FC
13import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
14import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
07671572 15import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
6c13869b 16import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
9269df72 17import org.osgi.framework.FrameworkUtil;
03c71d1e
ASL
18
19/*
20 Functions tested here :
21 public LTTngTrace(String path) throws Exception
22 public LTTngTrace(String path, boolean skipIndexing) throws Exception
25e48683 23
03c71d1e
ASL
24 public TmfTraceContext seekLocation(Object location) {
25 public TmfTraceContext seekEvent(TmfTimestamp timestamp) {
26 public TmfTraceContext seekEvent(long position) {
25e48683 27
03c71d1e
ASL
28 public TmfEvent getNextEvent(TmfTraceContext context) {
29 public Object getCurrentLocation() {
25e48683 30
03c71d1e 31 public LttngEvent parseEvent(TmfTraceContext context) {
25e48683 32
03c71d1e
ASL
33 public int getCpuNumber() {
34 */
35
3b38ea61 36@SuppressWarnings("nls")
03c71d1e 37public class LTTngTraceTest extends TestCase {
25e48683 38
03c71d1e
ASL
39 private final static String tracepath1="traceset/trace-15316events_nolost_newformat";
40 private final static String wrongTracePath="/somewhere/that/does/not/exist";
25e48683 41
03c71d1e 42 private final static int traceCpuNumber=1;
25e48683 43
03c71d1e 44 private final static boolean skipIndexing=true;
25e48683 45
03c71d1e
ASL
46 private final static long firstEventTimestamp = 13589759412128L;
47 private final static long secondEventTimestamp = 13589759419903L;
48 private final static Long locationAfterFirstEvent = 13589759412128L;
25e48683 49
03c71d1e 50 private final static String tracename = "traceset/trace-15316events_nolost_newformat";
25e48683 51
03c71d1e
ASL
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";
25e48683
FC
56
57
03c71d1e
ASL
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;
25e48683 62 private final static String seek1EventReference = tracename + "/vm_state_0";
61d428bd
PT
63 private final static long seekTimestamp = 13589826657302L;
64 private final static long nextEventTimestamp = 13589826659739L;
65 private final static long nextnextEventTimestamp = 13589826662017L;
25e48683 66
03c71d1e
ASL
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;
25e48683 71 private final static String seekLastEventReference = tracename + "/kernel_0";
03c71d1e
ASL
72
73 private static LTTngTrace testStream = null;
74 private LTTngTrace prepareStreamToTest() {
25e48683
FC
75 if (testStream == null)
76 try {
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;
81 }
82 catch (final Exception e) {
83 System.out.println("ERROR : Could not open " + tracepath1);
84 testStream = null;
85 }
86 else
87 testStream.seekEvent(0L);
88
89
90 return testStream;
91 }
03c71d1e
ASL
92
93 public void testTraceConstructors() {
25e48683
FC
94 // Default constructor
95 // Test constructor with argument on a wrong tracepath, skipping indexing
03c71d1e 96 try {
25e48683
FC
97 new LTTngTrace(null, wrongTracePath, skipIndexing);
98 fail("Construction with wrong tracepath should fail!");
03c71d1e 99 }
25e48683 100 catch( final Exception e) {
03c71d1e 101 }
25e48683 102
03c71d1e
ASL
103 // Test constructor with argument on a correct tracepath, skipping indexing
104 try {
25e48683
FC
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);
03c71d1e 108 }
25e48683
FC
109 catch( final Exception e) {
110 fail("Construction with correct tracepath failed!");
03c71d1e 111 }
25e48683
FC
112 // System.out.println("Test completed");
113 }
114
115 public void testGetNextEvent() {
116 TmfEvent tmpEvent = null;
117 final LTTngTrace testStream1 = prepareStreamToTest();
118
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
c32744d6 121 tmpEvent = testStream1.getNext(tmpContext );
25e48683
FC
122 assertNotSame("tmpEvent is null after first getNextEvent()",null,tmpEvent );
123 assertEquals("tmpEvent has wrong timestamp after first getNextEvent()",firstEventTimestamp,tmpEvent.getTimestamp().getValue() );
124
125 // Read the next event as well
c32744d6 126 tmpEvent = testStream1.getNext( tmpContext);
25e48683
FC
127 assertNotSame("tmpEvent is null after second getNextEvent()",null,tmpEvent );
128 assertEquals("tmpEvent has wrong timestamp after second getNextEvent()",secondEventTimestamp,tmpEvent.getTimestamp().getValue() );
129 }
130
131 public void testParseEvent() {
132 TmfEvent tmpEvent = null;
133 final LTTngTrace testStream1 = prepareStreamToTest();
134
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() );
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,tmpEvent.getTimestamp().getValue() );
145 }
146
147 public void testSeekEventTimestamp() {
148 TmfEvent tmpEvent = null;
07671572 149 ITmfContext tmpContext = new TmfContext(null, 0);
25e48683
FC
150 final 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));
c32744d6 154 tmpEvent = testStream1.getNext(tmpContext);
25e48683
FC
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()));
159
160 // Seek to the last timestamp
161 tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekLast, (byte) -9, 0));
c32744d6 162 tmpEvent = testStream1.getNext(tmpContext);
25e48683
FC
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()));
167
168 // Seek to the first timestamp (startTime)
169 tmpContext = testStream1.seekEvent(new TmfTimestamp(firstEventTimestamp, (byte) -9, 0));
c32744d6 170 tmpEvent = testStream1.getNext(tmpContext);
25e48683
FC
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() );
175 }
176
177 public void testSeekEventIndex() {
178 TmfEvent tmpEvent = null;
07671572 179 ITmfContext tmpContext = new TmfContext(null, 0);
25e48683
FC
180 final 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);
c32744d6 184 tmpEvent = testStream1.getNext(tmpContext);
25e48683
FC
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()));
189
190 // Seek to the last timestamp
191 tmpContext = testStream1.seekEvent(indexToSeekLast);
c32744d6 192 tmpEvent = testStream1.getNext(tmpContext);
25e48683
FC
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()));
197
198 // Seek to the first timestamp (startTime)
199 tmpContext = testStream1.seekEvent(indexToSeekFirst);
c32744d6 200 tmpEvent = testStream1.getNext(tmpContext);
25e48683
FC
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()));
205 }
206
207 public void testSeekLocation() {
208 TmfEvent tmpEvent = null;
07671572 209 ITmfContext tmpContext = new TmfContext(null, 0);
25e48683
FC
210 final LTTngTrace testStream1 = prepareStreamToTest();
211
212 // We should be at the beginning of the trace, we will seek at a certain timestamp
7e6347b0 213 tmpContext = testStream1.seekEvent(new LttngLocation(locationToSeekTest1));
c32744d6 214 tmpEvent = testStream1.getNext(tmpContext);
25e48683
FC
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()));
219
220 // Seek to the last timestamp
7e6347b0 221 tmpContext = testStream1.seekEvent(new LttngLocation(locationToSeekLast));
c32744d6 222 tmpEvent = testStream1.getNext(tmpContext);
25e48683
FC
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()));
227
228 // Seek to the first timestamp (startTime)
7e6347b0 229 tmpContext = testStream1.seekEvent(new LttngLocation(locationToSeekFirst));
c32744d6 230 tmpEvent = testStream1.getNext(tmpContext);
25e48683
FC
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()));
235 }
61d428bd
PT
236
237 public void testLocationOperations() {
238 TmfEvent tmpEvent = null;
07671572 239 ITmfContext tmpContext = new TmfContext(null, 0);
25e48683 240 final LTTngTrace testStream1 = prepareStreamToTest();
61d428bd
PT
241
242 // Test LttngLocation after a seek
7e6347b0 243 tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
61d428bd
PT
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());
7e6347b0 247 tmpContext = testStream1.seekEvent(location);
c32744d6 248 tmpEvent = testStream1.getNext(tmpContext);
61d428bd
PT
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
7e6347b0 253 tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
61d428bd
PT
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());
7e6347b0 259 tmpContext = testStream1.seekEvent(location);
c32744d6 260 tmpEvent = testStream1.getNext(tmpContext);
61d428bd
PT
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
7e6347b0 265 tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
c32744d6 266 tmpEvent = testStream.getNext(tmpContext);
61d428bd
PT
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());
7e6347b0 271 tmpContext = testStream1.seekEvent(location);
c32744d6 272 tmpEvent = testStream1.getNext(tmpContext);
61d428bd
PT
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
7e6347b0 277 tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
61d428bd
PT
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());
7e6347b0 285 tmpContext = testStream1.seekEvent(location);
c32744d6 286 tmpEvent = testStream1.getNext(tmpContext);
61d428bd
PT
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
7e6347b0 291 tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
c32744d6 292 tmpEvent = testStream.getNext(tmpContext);
61d428bd 293 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
c32744d6 294 tmpEvent = testStream.getNext(tmpContext);
61d428bd
PT
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());
7e6347b0 299 tmpContext = testStream1.seekEvent(location);
c32744d6 300 tmpEvent = testStream1.getNext(tmpContext);
61d428bd
PT
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
7e6347b0 305 tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
c32744d6 306 tmpEvent = testStream.getNext(tmpContext);
61d428bd
PT
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());
7e6347b0 313 tmpContext = testStream1.seekEvent(location);
c32744d6 314 tmpEvent = testStream1.getNext(tmpContext);
61d428bd
PT
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
7e6347b0 319 tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
61d428bd
PT
320 tmpEvent = testStream.parseEvent(tmpContext);
321 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
c32744d6 322 tmpEvent = testStream.getNext(tmpContext);
61d428bd
PT
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());
7e6347b0 327 tmpContext = testStream1.seekEvent(location);
c32744d6 328 tmpEvent = testStream1.getNext(tmpContext);
61d428bd
PT
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
7e6347b0 333 tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
61d428bd
PT
334 tmpEvent = testStream.parseEvent(tmpContext);
335 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
c32744d6 336 tmpEvent = testStream.getNext(tmpContext);
61d428bd
PT
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());
7e6347b0 343 tmpContext = testStream1.seekEvent(location);
c32744d6 344 tmpEvent = testStream1.getNext(tmpContext);
61d428bd
PT
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
7e6347b0 349 tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
61d428bd
PT
350 tmpEvent = testStream.parseEvent(tmpContext);
351 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
c32744d6 352 tmpEvent = testStream.getNext(tmpContext);
61d428bd 353 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
c32744d6 354 tmpEvent = testStream.getNext(tmpContext);
61d428bd
PT
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());
7e6347b0 359 tmpContext = testStream1.seekEvent(location);
c32744d6 360 tmpEvent = testStream1.getNext(tmpContext);
61d428bd
PT
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
7e6347b0 365 tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
c32744d6 366 tmpEvent = testStream.getNext(tmpContext);
61d428bd
PT
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());
7e6347b0 375 tmpContext = testStream1.seekEvent(location);
c32744d6 376 tmpEvent = testStream1.getNext(tmpContext);
61d428bd
PT
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
7e6347b0 381 tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
c32744d6 382 tmpEvent = testStream.getNext(tmpContext);
61d428bd
PT
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());
c32744d6 386 tmpEvent = testStream.getNext(tmpContext);
61d428bd
PT
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());
7e6347b0 391 tmpContext = testStream1.seekEvent(location);
c32744d6 392 tmpEvent = testStream1.getNext(tmpContext);
61d428bd
PT
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
7e6347b0 397 tmpContext = testStream1.seekEvent(new LttngLocation(seekTimestamp));
c32744d6 398 tmpEvent = testStream.getNext(tmpContext);
61d428bd 399 assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
c32744d6 400 tmpEvent = testStream.getNext(tmpContext);
61d428bd
PT
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());
7e6347b0 407 tmpContext = testStream1.seekEvent(location);
c32744d6 408 tmpEvent = testStream1.getNext(tmpContext);
61d428bd
PT
409 assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
410 assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
411 }
412
bcf8b0f3
PT
413 public void testConcurrentOperations() {
414 final LTTngTrace testStream = prepareStreamToTest();
415 ITmfEvent event1 = null;
416 ITmfEvent event2 = null;
417 ITmfContext context1;
418 ITmfContext context2;
419
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());
426
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());
436
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());
446
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());
456
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());
469
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());
482
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());
492
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());
505
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());
518 }
519
25e48683
FC
520 public void testGetter() {
521 TmfEvent tmpEvent = null;
522 final LTTngTrace testStream1 = prepareStreamToTest();
523
524 // Move to the first event to have something to play with
525 tmpEvent = testStream1.parseEvent( new TmfContext(null, 0));
526
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()) );
532
533 // Test CPU number of the trace
534 assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber ,testStream1.getCpuNumber() );
03c71d1e 535 }
25e48683
FC
536
537 public void testToString() {
538 final LTTngTrace testStream1 = prepareStreamToTest();
539
540 // Move to the first event to have something to play with
541 testStream1.parseEvent( new TmfContext(null, 0) );
542
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() );
03c71d1e 546 }
25e48683 547
03c71d1e 548}
This page took 0.061317 seconds and 5 git commands to generate.