Commit | Line | Data |
---|---|---|
6c13869b | 1 | package org.eclipse.linuxtools.lttng.core.tests.trace; |
03c71d1e ASL |
2 | |
3 | import java.io.File; | |
4 | import java.net.URL; | |
5 | ||
6 | import junit.framework.TestCase; | |
7 | ||
8 | import org.eclipse.core.runtime.FileLocator; | |
9 | import org.eclipse.core.runtime.Path; | |
5945cec9 FC |
10 | import org.eclipse.linuxtools.internal.lttng.core.event.LttngLocation; |
11 | import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTrace; | |
6c13869b FC |
12 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
13 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
14 | import org.eclipse.linuxtools.tmf.core.trace.TmfContext; | |
9269df72 | 15 | import 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 | |
25e48683 | 21 | |
03c71d1e ASL |
22 | public TmfTraceContext seekLocation(Object location) { |
23 | public TmfTraceContext seekEvent(TmfTimestamp timestamp) { | |
24 | public TmfTraceContext seekEvent(long position) { | |
25e48683 | 25 | |
03c71d1e ASL |
26 | public TmfEvent getNextEvent(TmfTraceContext context) { |
27 | public Object getCurrentLocation() { | |
25e48683 | 28 | |
03c71d1e | 29 | public LttngEvent parseEvent(TmfTraceContext context) { |
25e48683 | 30 | |
03c71d1e ASL |
31 | public int getCpuNumber() { |
32 | */ | |
33 | ||
3b38ea61 | 34 | @SuppressWarnings("nls") |
03c71d1e | 35 | public class LTTngTraceTest extends TestCase { |
25e48683 | 36 | |
03c71d1e ASL |
37 | private final static String tracepath1="traceset/trace-15316events_nolost_newformat"; |
38 | private final static String wrongTracePath="/somewhere/that/does/not/exist"; | |
25e48683 | 39 | |
03c71d1e | 40 | private final static int traceCpuNumber=1; |
25e48683 | 41 | |
03c71d1e | 42 | private final static boolean skipIndexing=true; |
25e48683 | 43 | |
03c71d1e ASL |
44 | private final static long firstEventTimestamp = 13589759412128L; |
45 | private final static long secondEventTimestamp = 13589759419903L; | |
46 | private final static Long locationAfterFirstEvent = 13589759412128L; | |
25e48683 | 47 | |
03c71d1e | 48 | private final static String tracename = "traceset/trace-15316events_nolost_newformat"; |
25e48683 | 49 | |
03c71d1e ASL |
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"; | |
25e48683 FC |
54 | |
55 | ||
03c71d1e ASL |
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; | |
25e48683 | 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; | |
25e48683 | 64 | |
03c71d1e ASL |
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; | |
25e48683 | 69 | private final static String seekLastEventReference = tracename + "/kernel_0"; |
03c71d1e ASL |
70 | |
71 | private static LTTngTrace testStream = null; | |
72 | private LTTngTrace prepareStreamToTest() { | |
25e48683 FC |
73 | if (testStream == null) |
74 | try { | |
75 | final URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(tracepath1), null); | |
76 | final File testfile = new File(FileLocator.toFileURL(location).toURI()); | |
77 | final LTTngTrace tmpStream = new LTTngTrace(null, testfile.getPath(), false); | |
78 | testStream = tmpStream; | |
79 | } | |
80 | catch (final Exception e) { | |
81 | System.out.println("ERROR : Could not open " + tracepath1); | |
82 | testStream = null; | |
83 | } | |
84 | else | |
85 | testStream.seekEvent(0L); | |
86 | ||
87 | ||
88 | return testStream; | |
89 | } | |
03c71d1e ASL |
90 | |
91 | public void testTraceConstructors() { | |
25e48683 FC |
92 | // Default constructor |
93 | // Test constructor with argument on a wrong tracepath, skipping indexing | |
03c71d1e | 94 | try { |
25e48683 FC |
95 | new LTTngTrace(null, wrongTracePath, skipIndexing); |
96 | fail("Construction with wrong tracepath should fail!"); | |
03c71d1e | 97 | } |
25e48683 | 98 | catch( final Exception e) { |
03c71d1e | 99 | } |
25e48683 | 100 | |
03c71d1e ASL |
101 | // Test constructor with argument on a correct tracepath, skipping indexing |
102 | try { | |
25e48683 FC |
103 | final URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(tracepath1), null); |
104 | final File testfile = new File(FileLocator.toFileURL(location).toURI()); | |
105 | new LTTngTrace(null, testfile.getPath(), skipIndexing); | |
03c71d1e | 106 | } |
25e48683 FC |
107 | catch( final Exception e) { |
108 | fail("Construction with correct tracepath failed!"); | |
03c71d1e | 109 | } |
25e48683 FC |
110 | // System.out.println("Test completed"); |
111 | } | |
112 | ||
113 | public void testGetNextEvent() { | |
114 | TmfEvent tmpEvent = null; | |
115 | final LTTngTrace testStream1 = prepareStreamToTest(); | |
116 | ||
117 | final TmfContext tmpContext = new TmfContext(null, 0); | |
118 | // We should be at the beginning of the trace, so we will just read the first event now | |
119 | tmpEvent = testStream1.getNextEvent(tmpContext ); | |
120 | assertNotSame("tmpEvent is null after first getNextEvent()",null,tmpEvent ); | |
121 | assertEquals("tmpEvent has wrong timestamp after first getNextEvent()",firstEventTimestamp,tmpEvent.getTimestamp().getValue() ); | |
122 | ||
123 | // Read the next event as well | |
124 | tmpEvent = testStream1.getNextEvent( tmpContext); | |
125 | assertNotSame("tmpEvent is null after second getNextEvent()",null,tmpEvent ); | |
126 | assertEquals("tmpEvent has wrong timestamp after second getNextEvent()",secondEventTimestamp,tmpEvent.getTimestamp().getValue() ); | |
127 | } | |
128 | ||
129 | public void testParseEvent() { | |
130 | TmfEvent tmpEvent = null; | |
131 | final LTTngTrace testStream1 = prepareStreamToTest(); | |
132 | ||
133 | final TmfContext tmpContext = new TmfContext(null, 0); | |
134 | // We should be at the beginning of the trace, so we will just parse the first event now | |
135 | tmpEvent = testStream1.parseEvent(tmpContext ); | |
136 | assertNotSame("tmpEvent is null after first parseEvent()",null,tmpEvent ); | |
137 | assertEquals("tmpEvent has wrong timestamp after first parseEvent()",firstEventTimestamp,tmpEvent.getTimestamp().getValue() ); | |
138 | ||
139 | // Use parseEvent again. Should be the same event | |
140 | tmpEvent = testStream1.parseEvent(tmpContext ); | |
141 | assertNotSame("tmpEvent is null after first parseEvent()",null,tmpEvent ); | |
142 | assertEquals("tmpEvent has wrong timestamp after first parseEvent()",firstEventTimestamp,tmpEvent.getTimestamp().getValue() ); | |
143 | } | |
144 | ||
145 | public void testSeekEventTimestamp() { | |
146 | TmfEvent tmpEvent = null; | |
147 | TmfContext tmpContext = new TmfContext(null, 0); | |
148 | final LTTngTrace testStream1 = prepareStreamToTest(); | |
149 | ||
150 | // We should be at the beginning of the trace, we will seek at a certain timestamp | |
151 | tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekTest1, (byte) -9, 0)); | |
152 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
153 | assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext ); | |
154 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); | |
155 | assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent ); | |
156 | assertTrue("tmpEvent has wrong reference after first seekEvent()", seek1EventReference.contains(tmpEvent.getReference())); | |
157 | ||
158 | // Seek to the last timestamp | |
159 | tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekLast, (byte) -9, 0)); | |
160 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
161 | assertNotSame("tmpContext is null after seekEvent() to last",null,tmpContext ); | |
162 | assertEquals("tmpContext has wrong timestamp after seekEvent() to last",contextValueAfterSeekLast,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); | |
163 | assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent ); | |
164 | assertTrue("tmpEvent has wrong reference after seekEvent() to last", seekLastEventReference.contains(tmpEvent.getReference())); | |
165 | ||
166 | // Seek to the first timestamp (startTime) | |
167 | tmpContext = testStream1.seekEvent(new TmfTimestamp(firstEventTimestamp, (byte) -9, 0)); | |
168 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
169 | assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent ); | |
170 | assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference.contains(tmpEvent.getReference())); | |
171 | assertNotSame("tmpContext is null after seekEvent() to first",null,tmpContext ); | |
172 | assertEquals("tmpContext has wrong timestamp after seekEvent() to first",contextValueAfterFirstEvent,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); | |
173 | } | |
174 | ||
175 | public void testSeekEventIndex() { | |
176 | TmfEvent tmpEvent = null; | |
177 | TmfContext tmpContext = new TmfContext(null, 0); | |
178 | final LTTngTrace testStream1 = prepareStreamToTest(); | |
179 | ||
180 | // We should be at the beginning of the trace, we will seek at a certain timestamp | |
181 | tmpContext = testStream1.seekEvent(indexToSeekTest1); | |
182 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
183 | assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext ); | |
184 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); | |
185 | assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent ); | |
186 | assertTrue("tmpEvent has wrong reference after first seekEvent()", seek1EventReference.contains(tmpEvent.getReference())); | |
187 | ||
188 | // Seek to the last timestamp | |
189 | tmpContext = testStream1.seekEvent(indexToSeekLast); | |
190 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
191 | assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext ); | |
192 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekLast,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); | |
193 | assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent ); | |
194 | assertTrue("tmpEvent has wrong reference after seekEvent() to last", seekLastEventReference.contains(tmpEvent.getReference())); | |
195 | ||
196 | // Seek to the first timestamp (startTime) | |
197 | tmpContext = testStream1.seekEvent(indexToSeekFirst); | |
198 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
199 | assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext ); | |
200 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterFirstEvent,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); | |
201 | assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent ); | |
202 | assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference.contains(tmpEvent.getReference())); | |
203 | } | |
204 | ||
205 | public void testSeekLocation() { | |
206 | TmfEvent tmpEvent = null; | |
207 | TmfContext tmpContext = new TmfContext(null, 0); | |
208 | final LTTngTrace testStream1 = prepareStreamToTest(); | |
209 | ||
210 | // We should be at the beginning of the trace, we will seek at a certain timestamp | |
211 | tmpContext = testStream1.seekLocation(new LttngLocation(locationToSeekTest1)); | |
212 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
213 | assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext ); | |
214 | assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekTest1,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); | |
215 | assertNotSame("tmpEvent is null after first seekLocation()",null,tmpEvent ); | |
216 | assertTrue("tmpEvent has wrong reference after first seekLocation()", seek1EventReference.contains(tmpEvent.getReference())); | |
217 | ||
218 | // Seek to the last timestamp | |
219 | tmpContext = testStream1.seekLocation(new LttngLocation(locationToSeekLast)); | |
220 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
221 | assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext ); | |
222 | assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekLast,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); | |
223 | assertNotSame("tmpEvent is null after seekLocation() to last ",null,tmpEvent ); | |
224 | assertTrue("tmpEvent has wrong reference after seekLocation() to last", seekLastEventReference.contains(tmpEvent.getReference())); | |
225 | ||
226 | // Seek to the first timestamp (startTime) | |
227 | tmpContext = testStream1.seekLocation(new LttngLocation(locationToSeekFirst)); | |
228 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
229 | assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext ); | |
230 | assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterFirstEvent,((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); | |
231 | assertNotSame("tmpEvent is null after seekLocation() to start ",null,tmpEvent ); | |
232 | assertTrue("tmpEvent has wrong reference after seekLocation() to start", firstEventReference.contains(tmpEvent.getReference())); | |
233 | } | |
61d428bd PT |
234 | |
235 | public void testLocationOperations() { | |
236 | TmfEvent tmpEvent = null; | |
237 | TmfContext tmpContext = new TmfContext(null, 0); | |
25e48683 | 238 | final LTTngTrace testStream1 = prepareStreamToTest(); |
61d428bd PT |
239 | |
240 | // Test LttngLocation after a seek | |
241 | tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp)); | |
242 | LttngLocation location = (LttngLocation) tmpContext.getLocation().clone(); | |
243 | assertTrue("location has wrong flag", location.isLastOperationSeek()); | |
244 | assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue()); | |
245 | tmpContext = testStream1.seekLocation(location); | |
246 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
247 | assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null); | |
248 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
249 | ||
250 | // Test LttngLocation after a parse | |
251 | tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp)); | |
252 | tmpEvent = testStream.parseEvent(tmpContext); | |
253 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
254 | location = (LttngLocation) tmpContext.getLocation().clone(); | |
255 | assertTrue("location has wrong flag", location.isLastOperationParse()); | |
256 | assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue()); | |
257 | tmpContext = testStream1.seekLocation(location); | |
258 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
259 | assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null); | |
260 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
261 | ||
262 | // Test LttngLocation after a getNext | |
263 | tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp)); | |
264 | tmpEvent = testStream.getNextEvent(tmpContext); | |
265 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
266 | location = (LttngLocation) tmpContext.getLocation().clone(); | |
267 | assertTrue("location has wrong flag", location.isLastOperationReadNext()); | |
268 | assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue()); | |
269 | tmpContext = testStream1.seekLocation(location); | |
270 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
271 | assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null); | |
272 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
273 | ||
274 | // Test LttngLocation after a parse and parse | |
275 | tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp)); | |
276 | tmpEvent = testStream.parseEvent(tmpContext); | |
277 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
278 | tmpEvent = testStream.parseEvent(tmpContext); | |
279 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
280 | location = (LttngLocation) tmpContext.getLocation().clone(); | |
281 | assertTrue("location has wrong flag", location.isLastOperationParse()); | |
282 | assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue()); | |
283 | tmpContext = testStream1.seekLocation(location); | |
284 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
285 | assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null); | |
286 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
287 | ||
288 | // Test LttngLocation after a getNext and getNext | |
289 | tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp)); | |
290 | tmpEvent = testStream.getNextEvent(tmpContext); | |
291 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
292 | tmpEvent = testStream.getNextEvent(tmpContext); | |
293 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
294 | location = (LttngLocation) tmpContext.getLocation().clone(); | |
295 | assertTrue("location has wrong flag", location.isLastOperationReadNext()); | |
296 | assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue()); | |
297 | tmpContext = testStream1.seekLocation(location); | |
298 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
299 | assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null); | |
300 | assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
301 | ||
302 | // Test LttngLocation after a getNext and parse | |
303 | tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp)); | |
304 | tmpEvent = testStream.getNextEvent(tmpContext); | |
305 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
306 | tmpEvent = testStream.parseEvent(tmpContext); | |
307 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
308 | location = (LttngLocation) tmpContext.getLocation().clone(); | |
309 | assertTrue("location has wrong flag", location.isLastOperationParse()); | |
310 | assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue()); | |
311 | tmpContext = testStream1.seekLocation(location); | |
312 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
313 | assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null); | |
314 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
315 | ||
316 | // Test LttngLocation after a parse and getNext | |
317 | tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp)); | |
318 | tmpEvent = testStream.parseEvent(tmpContext); | |
319 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
320 | tmpEvent = testStream.getNextEvent(tmpContext); | |
321 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
322 | location = (LttngLocation) tmpContext.getLocation().clone(); | |
323 | assertTrue("location has wrong flag", location.isLastOperationReadNext()); | |
324 | assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue()); | |
325 | tmpContext = testStream1.seekLocation(location); | |
326 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
327 | assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null); | |
328 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
329 | ||
330 | // Test LttngLocation after a parse, getNext and parse | |
331 | tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp)); | |
332 | tmpEvent = testStream.parseEvent(tmpContext); | |
333 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
334 | tmpEvent = testStream.getNextEvent(tmpContext); | |
335 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
336 | tmpEvent = testStream.parseEvent(tmpContext); | |
337 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
338 | location = (LttngLocation) tmpContext.getLocation().clone(); | |
339 | assertTrue("location has wrong flag", location.isLastOperationParse()); | |
340 | assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue()); | |
341 | tmpContext = testStream1.seekLocation(location); | |
342 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
343 | assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null); | |
344 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
345 | ||
346 | // Test LttngLocation after a parse, getNext and getNext | |
347 | tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp)); | |
348 | tmpEvent = testStream.parseEvent(tmpContext); | |
349 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
350 | tmpEvent = testStream.getNextEvent(tmpContext); | |
351 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
352 | tmpEvent = testStream.getNextEvent(tmpContext); | |
353 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
354 | location = (LttngLocation) tmpContext.getLocation().clone(); | |
355 | assertTrue("location has wrong flag", location.isLastOperationReadNext()); | |
356 | assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue()); | |
357 | tmpContext = testStream1.seekLocation(location); | |
358 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
359 | assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null); | |
360 | assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
361 | ||
362 | // Test LttngLocation after a getNext, parse and parse | |
363 | tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp)); | |
364 | tmpEvent = testStream.getNextEvent(tmpContext); | |
365 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
366 | tmpEvent = testStream.parseEvent(tmpContext); | |
367 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
368 | tmpEvent = testStream.parseEvent(tmpContext); | |
369 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
370 | location = (LttngLocation) tmpContext.getLocation().clone(); | |
371 | assertTrue("location has wrong flag", location.isLastOperationParse()); | |
372 | assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue()); | |
373 | tmpContext = testStream1.seekLocation(location); | |
374 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
375 | assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null); | |
376 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
377 | ||
378 | // Test LttngLocation after a getNext, parse and getNext | |
379 | tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp)); | |
380 | tmpEvent = testStream.getNextEvent(tmpContext); | |
381 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
382 | tmpEvent = testStream.parseEvent(tmpContext); | |
383 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
384 | tmpEvent = testStream.getNextEvent(tmpContext); | |
385 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
386 | location = (LttngLocation) tmpContext.getLocation().clone(); | |
387 | assertTrue("location has wrong flag", location.isLastOperationReadNext()); | |
388 | assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue()); | |
389 | tmpContext = testStream1.seekLocation(location); | |
390 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
391 | assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null); | |
392 | assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
393 | ||
394 | // Test LttngLocation after a getNext, getNext and parse | |
395 | tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp)); | |
396 | tmpEvent = testStream.getNextEvent(tmpContext); | |
397 | assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue()); | |
398 | tmpEvent = testStream.getNextEvent(tmpContext); | |
399 | assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
400 | tmpEvent = testStream.parseEvent(tmpContext); | |
401 | assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
402 | location = (LttngLocation) tmpContext.getLocation().clone(); | |
403 | assertTrue("location has wrong flag", location.isLastOperationParse()); | |
404 | assertEquals("location has wrong operation time", nextnextEventTimestamp, location.getOperationTimeValue()); | |
405 | tmpContext = testStream1.seekLocation(location); | |
406 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
407 | assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null); | |
408 | assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue()); | |
409 | } | |
410 | ||
25e48683 FC |
411 | public void testGetter() { |
412 | TmfEvent tmpEvent = null; | |
413 | final LTTngTrace testStream1 = prepareStreamToTest(); | |
414 | ||
415 | // Move to the first event to have something to play with | |
416 | tmpEvent = testStream1.parseEvent( new TmfContext(null, 0)); | |
417 | ||
418 | // Test current event | |
419 | assertNotSame("tmpEvent is null after first event",null,tmpEvent ); | |
420 | assertTrue("tmpEvent has wrong reference after first event", firstEventReference.contains(tmpEvent.getReference())); | |
421 | assertNotSame("tmpContext is null after first seekEvent()",null,testStream1.getCurrentLocation() ); | |
422 | assertTrue("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent.equals( ((LttngLocation)testStream1.getCurrentLocation()).getOperationTimeValue()) ); | |
423 | ||
424 | // Test CPU number of the trace | |
425 | assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber ,testStream1.getCpuNumber() ); | |
03c71d1e | 426 | } |
25e48683 FC |
427 | |
428 | public void testToString() { | |
429 | final LTTngTrace testStream1 = prepareStreamToTest(); | |
430 | ||
431 | // Move to the first event to have something to play with | |
432 | testStream1.parseEvent( new TmfContext(null, 0) ); | |
433 | ||
434 | // Just make sure toString() does not return null or the java reference | |
435 | assertNotSame("toString returned null",null, testStream1.toString() ); | |
436 | assertNotSame("toString is not overridded!", testStream1.getClass().getName() + '@' + Integer.toHexString(testStream1.hashCode()), testStream1.toString() ); | |
03c71d1e | 437 | } |
25e48683 | 438 | |
03c71d1e | 439 | } |