1 package org
.eclipse
.linuxtools
.lttng
.core
.tests
.jni
;
3 import org
.eclipse
.linuxtools
.lttng
.jni
.JniEvent
;
4 import org
.eclipse
.linuxtools
.lttng
.jni
.JniTrace
;
5 import org
.eclipse
.linuxtools
.lttng
.jni
.common
.JniTime
;
6 import org
.eclipse
.linuxtools
.lttng
.jni
.exception
.JniException
;
7 import org
.eclipse
.linuxtools
.lttng
.jni
.factory
.JniTraceFactory
;
9 import junit
.framework
.TestCase
;
12 * Functions tested here : public JniTrace() public JniTrace(JniTrace oldTrace)
13 * public JniTrace(String newpath) throws JafException public JniTrace(long
14 * newPtr) throws JafException
16 * public void openTrace(String newPath) throws JafException public void
17 * openTrace() throws JafException public void closeTrace( ) throws JafException
19 * public JniEvent readNextEvent() public JniEvent findNextEvent() public
20 * JniEvent seekAndRead(JniTime seekTime) public void seekToTime(JniTime
23 * public JniTracefile requestTracefileByName(String tracefileName) public
24 * JniEvent requestEventByName(String tracefileName) public ArrayList<Location>
25 * requestTraceLocation()
27 * public String getTracepath() public int getCpuNumber() public long
28 * getArchType() public long getArchVariant() public short getArchSize() public
29 * short getLttMajorVersion() public short getLttMinorVersion() public short
30 * getFlightRecorder() public long getFreqScale() public long getStartFreq()
31 * public long getStartTimestampCurrentCounter() public long getStartMonotonic()
32 * public JniTime getStartTime() pubilc JniTime getEndTime() public JniTime
33 * getStartTimeFromTimestampCurrentCounter() public HashMap<String,
34 * JniTracefile> getTracefilesMap() public long getTracePtr()
36 * public void printAllTracefilesInformation() public void
37 * printTraceInformation()
39 * public String toString()
42 @SuppressWarnings("nls")
43 public class JniTraceTest
extends TestCase
{
45 private final static boolean printLttDebug
= false;
47 private final static String tracepath1
= "traceset/trace-15316events_nolost_newformat";
48 private final static String tracepath2
= "traceset/trace-15471events_nolost_newformat";
49 private final static String wrongTracePath
= "/somewhere/that/does/not/exist";
51 private final static String correctTracefileName
= "kernel0";
52 private final static String wrongTracefileName
= "somethingThatDoesNotExists";
54 private final static int numberOfTracefilesInTrace
= 16;
56 private final static long firstEventTimestamp
= 13589759412128L;
57 private final static String firstEventTracefilename
= "metadata0";
59 private final static long secondEventTimestamp
= 13589759419903L;
60 private final static String secondEventName
= "metadata";
62 private final static long thirdEventTimestamp
= 13589759422785L;
64 private final static long eventTimestampAfterMetadata
= 13589760262237L;
65 private final static String eventTracefilenameAfterMetadata
= "kernel0";
67 private final static long timestampToSeekTest1
= 13589821608319L;
68 private final static String eventNameAfterSeekTest1
= "kernel";
69 private final static String eventTracefilenameAfterSeekTest1
= "kernel0";
70 private final static String nextEventNameAfterSeekTest1
= "vm_state";
72 private final static long timestampToSeekTest2
= 13589861889350L;
73 private final static String eventNameAfterSeekTest2
= "fs";
74 private final static String nextEventNameAfterSeekTest2
= "kernel";
76 private final static long timestampToSeekLast
= 13589906758692L;
77 private final static String eventNameAfterSeekLast
= "kernel";
79 private JniTrace
prepareTraceToTest() {
80 JniTrace tmpTrace
= null;
82 // This trace should be valid
84 tmpTrace
= JniTraceFactory
.getJniTrace(tracepath1
, null, printLttDebug
);
85 //tmpTrace.seekToTime(new JniTime(0L));
86 } catch (JniException e
) {
92 public void testTraceConstructors() {
93 // Test constructor with argument on a wrong tracepath
95 JniTraceFactory
.getJniTrace(wrongTracePath
, null, printLttDebug
);
96 fail("Construction with wrong tracepath should fail!");
97 } catch (JniException e
) {
100 // Test constructor with argument on a correct tracepath
102 JniTraceFactory
.getJniTrace(tracepath1
, null, printLttDebug
);
103 } catch (JniException e
) {
104 fail("Construction with correct tracepath failed!");
108 public void testTraceOpenClose() {
110 JniTrace testTrace
= prepareTraceToTest(); // This trace should be valid
112 // test the constructor with arguments passing a wrong tracepath
114 testTrace
.openTrace(wrongTracePath
);
115 fail("Open with wrong tracepath should fail!");
116 } catch (JniException e
) {
119 // Test open with a correct tracepath
121 testTrace
.openTrace(tracepath1
);
122 assertNotSame("getTracepath is empty after open", "", testTrace
.getTracepath());
123 } catch (JniException e
) {
124 fail("Open with a correct tracepath failed!");
127 // Test to open a trace already opened
129 testTrace
.openTrace(tracepath1
);
130 testTrace
.openTrace(tracepath2
);
131 assertNotSame("getTracepath is empty after open", "", testTrace
.getTracepath());
132 } catch (JniException e
) {
133 fail("Reopen of a trace failed!");
136 // Test to open a trace already opened, but with a wrong tracepath
138 testTrace
.openTrace(tracepath1
);
139 testTrace
.openTrace(wrongTracePath
);
140 fail("Reopen with wrong tracepath should fail!");
141 } catch (JniException e
) {
145 public void testGetSet() {
147 JniTrace testTrace
= prepareTraceToTest();
149 // Test that all Get/Set return data
150 assertNotSame("getTracepath is empty", "", testTrace
.getTracepath());
151 assertNotSame("getCpuNumber is 0", 0, testTrace
.getCpuNumber());
152 assertNotSame("getArchType is 0", 0, testTrace
.getArchType());
153 assertNotSame("getArchVariant is 0", 0, testTrace
.getArchVariant());
154 assertNotSame("getArchSize is 0", 0, testTrace
.getArchSize());
155 assertNotSame("getLttMajorVersion is 0", 0, testTrace
.getLttMajorVersion());
156 assertNotSame("getLttMinorVersion is 0", 0, testTrace
.getLttMinorVersion());
157 assertNotSame("getFlightRecorder is 0", 0, testTrace
.getFlightRecorder());
158 assertNotSame("getFreqScale is 0", 0, testTrace
.getFreqScale());
159 assertNotSame("getStartFreq is 0", 0, testTrace
.getStartFreq());
160 assertNotSame("getStartTimestampCurrentCounter is 0", 0,
161 testTrace
.getStartTimestampCurrentCounter());
162 assertNotSame("getStartMonotonic is 0", 0, testTrace
.getStartMonotonic());
163 assertNotSame("getStartTime is null", null, testTrace
.getStartTime());
164 assertNotSame("getEndTime() is null", null, testTrace
.getEndTime());
165 assertNotSame("getStartTimeNoAdjustement is null", null,
166 testTrace
.getStartTimeNoAdjustement());
167 assertNotSame("getTracefilesMap is null", null, testTrace
.getTracefilesMap());
168 // Also check that the map contain some tracefiles
169 assertSame("getTracefilesMap returned an unexpected number of tracefiles",
170 numberOfTracefilesInTrace
, testTrace
.getTracefilesMap().size());
171 assertNotSame("getTracePtr is 0", 0, testTrace
.getTracePtr());
175 public void testPrintAndToString() {
177 JniTrace testTrace
= prepareTraceToTest();
179 // Test printTraceInformation
181 testTrace
.printTraceInformation();
182 } catch (Exception e
) {
183 fail("printTraceInformation failed!");
187 assertNotSame("toString returned empty data", "", testTrace
.toString());
190 public void testRequestFunctions() {
192 JniTrace testTrace
= prepareTraceToTest();
194 // Test requestTracefileByName()
195 assertNotSame("requestTracefileByName returned null", null,
196 testTrace
.requestTracefileByName(correctTracefileName
));
197 assertSame("requestTracefileByName returned content on non existent name", null,
198 testTrace
.requestTracefileByName(wrongTracefileName
));
200 // Test requestEventByName()
201 assertNotSame("requestEventByName returned null", null,
202 testTrace
.requestEventByName(correctTracefileName
));
203 assertSame("requestEventByName returned content on non existent name", null,
204 testTrace
.requestEventByName(wrongTracefileName
));
207 public void testEventDisplacement() {
209 JniEvent testEvent
= null;
210 JniTrace testTrace
= prepareTraceToTest();
212 // Test readNextEvent()
213 testEvent
= testTrace
.readNextEvent();
214 assertNotSame("readNextEvent() returned null", null, testEvent
);
215 assertEquals("readNextEvent() timestamp is incoherent", firstEventTimestamp
, testEvent
216 .getEventTime().getTime());
218 // Test findNextEvent()
219 testEvent
= testTrace
.findNextEvent();
220 assertNotSame("findNextEvent() returned null", null, testEvent
);
221 assertEquals("findNextEvent() name is incoherent", secondEventName
, testEvent
222 .getParentTracefile().getTracefileName());
224 // Test readNextEvent()
225 testEvent
= testTrace
.readNextEvent();
226 assertNotSame("readNextEvent() returned null", null, testEvent
);
227 assertEquals("readNextEvent() timestamp is incoherent", secondEventName
, testEvent
228 .getParentTracefile().getTracefileName());
230 // Tests below are for seekAndRead()
231 // After, we will perform the same operation for seekTime
233 // Test #1 of seekAndRead()
234 testEvent
= testTrace
.seekAndRead(new JniTime(timestampToSeekTest1
));
235 assertNotSame("seekAndRead(time) returned null (test #1)", null, testEvent
);
236 assertEquals("seekAndRead(time) timestamp is incoherent (test #1)", timestampToSeekTest1
,
237 testEvent
.getEventTime().getTime());
238 assertEquals("event name after seekAndRead(time) is incoherent (test #1)",
239 eventNameAfterSeekTest1
, testEvent
.getParentTracefile().getTracefileName());
240 // Test that the next event after seek in the one we expect
241 testEvent
= testTrace
.readNextEvent();
242 assertEquals("readNextEvent() name after seekAndRead(time) is incoherent (test #1)",
243 nextEventNameAfterSeekTest1
, testEvent
.getParentTracefile()
244 .getTracefileName());
246 // Test #2 of seekAndRead()
247 testEvent
= testTrace
.seekAndRead(new JniTime(timestampToSeekTest2
));
248 assertNotSame("seekAndRead(time) returned null (test #2)", null, testEvent
);
249 assertEquals("seekAndRead(time) timestamp is incoherent (test #2)", timestampToSeekTest2
,
250 testEvent
.getEventTime().getTime());
251 assertEquals("event name after seekAndRead(time) is incoherent (test #2)",
252 eventNameAfterSeekTest2
, testEvent
.getParentTracefile().getTracefileName());
253 // Test that the next event after seek in the one we expect
254 testEvent
= testTrace
.readNextEvent();
255 assertEquals("readNextEvent() name after seekAndRead(time) is incoherent (test #2)",
256 nextEventNameAfterSeekTest2
, testEvent
.getParentTracefile()
257 .getTracefileName());
259 // Seek to the LAST event of the trace
260 testEvent
= testTrace
.seekAndRead(new JniTime(timestampToSeekLast
));
261 assertNotSame("seekAndRead(time) returned null ", null, testEvent
);
262 assertEquals("seekAndRead(time) timestamp is incoherent ", timestampToSeekLast
, testEvent
263 .getEventTime().getTime());
264 assertEquals("event name after seekTime(time) is incoherent ", eventNameAfterSeekLast
,
265 testEvent
.getParentTracefile().getTracefileName());
266 // Test that the next event is NULL (end of the trace)
267 testEvent
= testTrace
.readNextEvent();
268 assertSame("seekAndRead(time) returned null ", null, testEvent
);
270 // Make sure we can seek back
271 testEvent
= testTrace
.seekAndRead(new JniTime(firstEventTimestamp
));
272 assertNotSame("seekAndRead(time) to seek back returned null", null, testEvent
);
273 assertEquals("seekAndRead(time) timestamp after seek back is incoherent",
274 firstEventTimestamp
, testEvent
.getEventTime().getTime());
276 // Tests below are for seekToTime()
277 // These are the same test as seekAndRead() for a readNextEvent() should be performed after seek
279 // Test #1 of seekToTime()
280 testTrace
.seekToTime(new JniTime(timestampToSeekTest1
));
281 testEvent
= testTrace
.readNextEvent();
282 assertNotSame("seekToTime(time) returned null (test #1)", null, testEvent
);
283 assertEquals("seekToTime(time) timestamp is incoherent (test #1)", timestampToSeekTest1
,
284 testEvent
.getEventTime().getTime());
285 assertEquals("event name after seekTime(time) is incoherent (test #1)",
286 eventNameAfterSeekTest1
, testEvent
.getParentTracefile().getTracefileName());
287 // Test that the next event after seek in the one we expect
288 testEvent
= testTrace
.readNextEvent();
289 assertEquals("readNextEvent() name after seekToTime(time) is incoherent (test #1)",
290 nextEventNameAfterSeekTest1
, testEvent
.getParentTracefile()
291 .getTracefileName());
293 // Test #2 of seekToTime()
294 testTrace
.seekToTime(new JniTime(timestampToSeekTest2
));
295 testEvent
= testTrace
.readNextEvent();
296 assertNotSame("seekToTime(time) returned null (test #2)", null, testEvent
);
297 assertEquals("seekToTime(time) timestamp is incoherent (test #2)", timestampToSeekTest2
,
298 testEvent
.getEventTime().getTime());
299 assertEquals("event name after seekTime(time) is incoherent (test #2)",
300 eventNameAfterSeekTest2
, testEvent
.getParentTracefile().getTracefileName());
301 // Test that the next event after seek in the one we expect
302 testEvent
= testTrace
.readNextEvent();
303 assertEquals("readNextEvent() name after seekToTime(time) is incoherent (test #2)",
304 nextEventNameAfterSeekTest2
, testEvent
.getParentTracefile()
305 .getTracefileName());
307 // Seek to the LAST event of the trace
308 testTrace
.seekToTime(new JniTime(timestampToSeekLast
));
309 testEvent
= testTrace
.readNextEvent();
310 assertNotSame("seekToTime(time) returned null ", null, testEvent
);
311 assertEquals("seekToTime(time) timestamp is incoherent ", timestampToSeekLast
, testEvent
312 .getEventTime().getTime());
313 assertEquals("event name after seekTime(time) is incoherent ", eventNameAfterSeekLast
,
314 testEvent
.getParentTracefile().getTracefileName());
315 // Test that the next event is NULL (end of the trace)
316 testEvent
= testTrace
.readNextEvent();
317 assertSame("seekToTime(time) returned null ", null, testEvent
);
319 // Make sure we can seek back
320 testTrace
.seekToTime(new JniTime(firstEventTimestamp
));
321 testEvent
= testTrace
.readNextEvent();
322 assertNotSame("seekToTime(time) to seek back returned null", null, testEvent
);
323 assertEquals("seekToTime(time) timestamp after seek back is incoherent",
324 firstEventTimestamp
, testEvent
.getEventTime().getTime());
327 public void testEventDisplacementByTracefile() {
329 JniEvent testEvent
= null;
330 JniTrace testTrace
= prepareTraceToTest();
332 // Read first event for the metadata (which is also the first event in the trace)
333 testEvent
= testTrace
.readNextEvent(testTrace
334 .requestTracefileByName(firstEventTracefilename
));
335 assertNotSame("readNextEvent() returned null", null, testEvent
);
336 assertEquals("readNextEvent() timestamp is incoherent", firstEventTimestamp
, testEvent
337 .getEventTime().getTime());
339 // If we read the next event again for this tracefile, we should get the SECOND event
340 testEvent
= testTrace
.readNextEvent(testTrace
341 .requestTracefileByName(firstEventTracefilename
));
342 assertNotSame("readNextEvent() on second read returned null", null, testEvent
);
343 assertEquals("readNextEvent() timestamp on second read is incoherent",
344 secondEventTimestamp
, testEvent
.getEventTime().getTime());
346 // Reading the "global" event should take care of the change
347 // So if we read the next event, we should get the THIRD event
348 testEvent
= testTrace
.readNextEvent();
349 assertNotSame("readNextEvent() to read global event returned null", null, testEvent
);
350 assertEquals("readNextEvent() timestamp to read global event is incoherent",
351 thirdEventTimestamp
, testEvent
.getEventTime().getTime());
353 // Now read the next event for another type of tracefile
354 testEvent
= testTrace
.readNextEvent(testTrace
355 .requestTracefileByName(eventTracefilenameAfterMetadata
));
356 assertNotSame("readNextEvent() returned null", null, testEvent
);
357 assertEquals("readNextEvent() timestamp is incoherent", eventTimestampAfterMetadata
,
358 testEvent
.getEventTime().getTime());
360 // Seek back to the beginning
361 testTrace
.seekToTime(new JniTime(firstEventTimestamp
),
362 testTrace
.requestTracefileByName(firstEventTracefilename
));
363 // Read the first event
364 testEvent
= testTrace
.readNextEvent(testTrace
365 .requestTracefileByName(firstEventTracefilename
));
366 assertNotSame("readNextEvent() after seekToTime returned null", null, testEvent
);
367 assertEquals("readNextEvent() after seekToTime timestamp is incoherent",
368 firstEventTimestamp
, testEvent
.getEventTime().getTime());
370 // Seek and Read the first event for the metadata (again the first event in the trace)
371 testEvent
= testTrace
.seekAndRead(new JniTime(firstEventTimestamp
),
372 testTrace
.requestTracefileByName(firstEventTracefilename
));
373 assertNotSame("seekAndRead() returned null", null, testEvent
);
374 assertEquals("seekAndRead() timestamp is incoherent", firstEventTimestamp
, testEvent
375 .getEventTime().getTime());
377 // Seek the whole trace to the infinity
378 testTrace
.seekToTime(new JniTime(Long
.MAX_VALUE
));
379 // Seek and Read the next event in the trace
380 testEvent
= testTrace
.seekAndRead(new JniTime(timestampToSeekTest1
),
381 testTrace
.requestTracefileByName(eventTracefilenameAfterSeekTest1
));
382 assertNotSame("seekAndRead() returned null", null, testEvent
);
383 assertEquals("seekAndRead() timestamp is incoherent", timestampToSeekTest1
, testEvent
384 .getEventTime().getTime());
385 // Read next event... only the same type should be here as other are exhausted
386 testEvent
= testTrace
.readNextEvent();
387 assertNotSame("readNextEvent() after seekToTime returned null", null, testEvent
);
388 assertEquals("readNextEvent() name after seekToTime is incoherent",
389 eventNameAfterSeekTest1
, testEvent
.getParentTracefile().getTracefileName());