2 package org
.eclipse
.linuxtools
.lttng
.core
.tests
.jni
;
4 import org
.eclipse
.linuxtools
.lttng
.jni
.JniEvent
;
5 import org
.eclipse
.linuxtools
.lttng
.jni
.JniTrace
;
6 import org
.eclipse
.linuxtools
.lttng
.jni
.common
.JniTime
;
7 import org
.eclipse
.linuxtools
.lttng
.jni
.exception
.JniException
;
8 import org
.eclipse
.linuxtools
.lttng
.jni
.factory
.JniTraceFactory
;
10 import junit
.framework
.TestCase
;
13 Functions tested here :
15 public JniTrace(JniTrace oldTrace)
16 public JniTrace(String newpath) throws JafException
17 public JniTrace(long newPtr) throws JafException
19 public void openTrace(String newPath) throws JafException
20 public void openTrace() throws JafException
21 public void closeTrace( ) throws JafException
23 public JniEvent readNextEvent()
24 public JniEvent findNextEvent()
25 public JniEvent seekAndRead(JniTime seekTime)
26 public void seekToTime(JniTime seekTime)
28 public JniTracefile requestTracefileByName(String tracefileName)
29 public JniEvent requestEventByName(String tracefileName)
30 public ArrayList<Location> requestTraceLocation()
32 public String getTracepath()
33 public int getCpuNumber()
34 public long getArchType()
35 public long getArchVariant()
36 public short getArchSize()
37 public short getLttMajorVersion()
38 public short getLttMinorVersion()
39 public short getFlightRecorder()
40 public long getFreqScale()
41 public long getStartFreq()
42 public long getStartTimestampCurrentCounter()
43 public long getStartMonotonic()
44 public JniTime getStartTime()
45 pubilc JniTime getEndTime()
46 public JniTime getStartTimeFromTimestampCurrentCounter()
47 public HashMap<String, JniTracefile> getTracefilesMap()
48 public long getTracePtr()
50 public void printAllTracefilesInformation()
51 public void printTraceInformation()
53 public String toString()
56 @SuppressWarnings("nls")
57 public class JniTraceTest
extends TestCase
59 private final static boolean printLttDebug
= false;
61 private final static String tracepath1
="traceset/trace-15316events_nolost_newformat";
62 private final static String tracepath2
="traceset/trace-15471events_nolost_newformat";
63 private final static String wrongTracePath
="/somewhere/that/does/not/exist";
65 private final static String correctTracefileName
="kernel0";
66 private final static String wrongTracefileName
="somethingThatDoesNotExists";
68 private final static int numberOfTracefilesInTrace
= 16;
70 private final static long firstEventTimestamp
= 13589759412128L;
71 private final static String firstEventTracefilename
= "metadata0";
73 private final static long secondEventTimestamp
= 13589759419903L;
74 private final static String secondEventName
= "metadata";
76 private final static long thirdEventTimestamp
= 13589759422785L;
78 private final static long eventTimestampAfterMetadata
= 13589760262237L;
79 private final static String eventTracefilenameAfterMetadata
= "kernel0";
81 private final static long timestampToSeekTest1
= 13589821608319L;
82 private final static String eventNameAfterSeekTest1
= "kernel";
83 private final static String eventTracefilenameAfterSeekTest1
= "kernel0";
84 private final static String nextEventNameAfterSeekTest1
= "vm_state";
86 private final static long timestampToSeekTest2
= 13589861889350L;
87 private final static String eventNameAfterSeekTest2
= "fs";
88 private final static String nextEventNameAfterSeekTest2
= "kernel";
90 private final static long timestampToSeekLast
= 13589906758692L;
91 private final static String eventNameAfterSeekLast
= "kernel";
94 private JniTrace
prepareTraceToTest() {
95 JniTrace tmpTrace
= null;
97 // This trace should be valid
99 tmpTrace
= JniTraceFactory
.getJniTrace(tracepath1
, null, printLttDebug
);
100 //tmpTrace.seekToTime(new JniTime(0L));
102 catch( JniException e
) { }
107 public void testTraceConstructors() {
108 @SuppressWarnings("unused")
109 JniTrace testTrace1
= null;
110 @SuppressWarnings("unused")
111 JniTrace testTrace2
= null;
113 // Test constructor with argument on a wrong tracepath
115 testTrace1
= JniTraceFactory
.getJniTrace(wrongTracePath
, null, printLttDebug
);
116 fail("Construction with wrong tracepath should fail!");
118 catch( JniException e
) {
121 // Test constructor with argument on a correct tracepath
123 testTrace1
= JniTraceFactory
.getJniTrace(tracepath1
, null, printLttDebug
);
125 catch( JniException e
) {
126 fail("Construction with correct tracepath failed!");
130 public void testTraceOpenClose() {
132 JniTrace testTrace
= prepareTraceToTest(); // This trace should be valid
134 // test the constructor with arguments passing a wrong tracepath
136 testTrace
.openTrace(wrongTracePath
);
137 fail("Open with wrong tracepath should fail!");
139 catch( JniException e
) { }
141 // Test open with a correct tracepath
143 testTrace
.openTrace(tracepath1
);
144 assertNotSame("getTracepath is empty after open","",testTrace
.getTracepath() );
146 catch( JniException e
) {
147 fail("Open with a correct tracepath failed!");
150 // Test to open a trace already opened
152 testTrace
.openTrace(tracepath1
);
153 testTrace
.openTrace(tracepath2
);
154 assertNotSame("getTracepath is empty after open","",testTrace
.getTracepath() );
156 catch( JniException e
) {
157 fail("Reopen of a trace failed!");
161 // Test to open a trace already opened, but with a wrong tracepath
163 testTrace
.openTrace(tracepath1
);
164 testTrace
.openTrace(wrongTracePath
);
165 fail("Reopen with wrong tracepath should fail!");
167 catch( JniException e
) {
171 public void testGetSet() {
173 JniTrace testTrace
= prepareTraceToTest();
175 // Test that all Get/Set return data
176 assertNotSame("getTracepath is empty","",testTrace
.getTracepath() );
177 assertNotSame("getCpuNumber is 0",0,testTrace
.getCpuNumber() );
178 assertNotSame("getArchType is 0",0,testTrace
.getArchType() );
179 assertNotSame("getArchVariant is 0",0,testTrace
.getArchVariant() );
180 assertNotSame("getArchSize is 0",0,testTrace
.getArchSize() );
181 assertNotSame("getLttMajorVersion is 0",0,testTrace
.getLttMajorVersion() );
182 assertNotSame("getLttMinorVersion is 0",0,testTrace
.getLttMinorVersion() );
183 assertNotSame("getFlightRecorder is 0",0,testTrace
.getFlightRecorder() );
184 assertNotSame("getFreqScale is 0",0,testTrace
.getFreqScale() );
185 assertNotSame("getStartFreq is 0",0,testTrace
.getStartFreq() );
186 assertNotSame("getStartTimestampCurrentCounter is 0",0,testTrace
.getStartTimestampCurrentCounter());
187 assertNotSame("getStartMonotonic is 0",0,testTrace
.getStartMonotonic() );
188 assertNotSame("getStartTime is null",null,testTrace
.getStartTime() );
189 assertNotSame("getEndTime() is null", null, testTrace
.getEndTime() );
190 assertNotSame("getStartTimeNoAdjustement is null",null,testTrace
.getStartTimeNoAdjustement() );
191 assertNotSame("getTracefilesMap is null",null,testTrace
.getTracefilesMap() );
192 // Also check that the map contain some tracefiles
193 assertSame("getTracefilesMap returned an unexpected number of tracefiles",numberOfTracefilesInTrace
,testTrace
.getTracefilesMap().size() );
194 assertNotSame("getTracePtr is 0",0,testTrace
.getTracePtr() );
199 public void testPrintAndToString() {
201 JniTrace testTrace
= prepareTraceToTest();
203 // Test printTraceInformation
205 testTrace
.printTraceInformation();
207 catch( Exception e
) {
208 fail("printTraceInformation failed!");
212 assertNotSame("toString returned empty data","",testTrace
.toString() );
215 public void testRequestFunctions() {
217 JniTrace testTrace
= prepareTraceToTest();
219 // Test requestTracefileByName()
220 assertNotSame("requestTracefileByName returned null",null,testTrace
.requestTracefileByName(correctTracefileName
) );
221 assertSame("requestTracefileByName returned content on non existent name",null,testTrace
.requestTracefileByName(wrongTracefileName
) );
223 // Test requestEventByName()
224 assertNotSame("requestEventByName returned null",null,testTrace
.requestEventByName(correctTracefileName
) );
225 assertSame("requestEventByName returned content on non existent name",null,testTrace
.requestEventByName(wrongTracefileName
) );
228 public void testEventDisplacement() {
230 JniEvent testEvent
= null;
231 JniTrace testTrace
= prepareTraceToTest();
233 // Test readNextEvent()
234 testEvent
= testTrace
.readNextEvent();
235 assertNotSame("readNextEvent() returned null",null,testEvent
);
236 assertEquals("readNextEvent() timestamp is incoherent",firstEventTimestamp
,testEvent
.getEventTime().getTime() );
238 // Test findNextEvent()
239 testEvent
= testTrace
.findNextEvent();
240 assertNotSame("findNextEvent() returned null",null,testEvent
);
241 assertEquals("findNextEvent() name is incoherent",secondEventName
,testEvent
.getParentTracefile().getTracefileName() );
243 // Test readNextEvent()
244 testEvent
= testTrace
.readNextEvent();
245 assertNotSame("readNextEvent() returned null",null,testEvent
);
246 assertEquals("readNextEvent() timestamp is incoherent",secondEventName
,testEvent
.getParentTracefile().getTracefileName() );
248 // Tests below are for seekAndRead()
249 // After, we will perform the same operation for seekTime
251 // Test #1 of seekAndRead()
252 testEvent
= testTrace
.seekAndRead(new JniTime(timestampToSeekTest1
) );
253 assertNotSame("seekAndRead(time) returned null (test #1)",null,testEvent
);
254 assertEquals("seekAndRead(time) timestamp is incoherent (test #1)",timestampToSeekTest1
,testEvent
.getEventTime().getTime());
255 assertEquals("event name after seekAndRead(time) is incoherent (test #1)",eventNameAfterSeekTest1
,testEvent
.getParentTracefile().getTracefileName());
256 // Test that the next event after seek in the one we expect
257 testEvent
= testTrace
.readNextEvent();
258 assertEquals("readNextEvent() name after seekAndRead(time) is incoherent (test #1)",nextEventNameAfterSeekTest1
,testEvent
.getParentTracefile().getTracefileName());
260 // Test #2 of seekAndRead()
261 testEvent
= testTrace
.seekAndRead(new JniTime(timestampToSeekTest2
) );
262 assertNotSame("seekAndRead(time) returned null (test #2)",null,testEvent
);
263 assertEquals("seekAndRead(time) timestamp is incoherent (test #2)",timestampToSeekTest2
,testEvent
.getEventTime().getTime());
264 assertEquals("event name after seekAndRead(time) is incoherent (test #2)",eventNameAfterSeekTest2
,testEvent
.getParentTracefile().getTracefileName());
265 // Test that the next event after seek in the one we expect
266 testEvent
= testTrace
.readNextEvent();
267 assertEquals("readNextEvent() name after seekAndRead(time) is incoherent (test #2)",nextEventNameAfterSeekTest2
,testEvent
.getParentTracefile().getTracefileName());
270 // Seek to the LAST event of the trace
271 testEvent
= testTrace
.seekAndRead(new JniTime(timestampToSeekLast
) );
272 assertNotSame("seekAndRead(time) returned null ",null,testEvent
);
273 assertEquals("seekAndRead(time) timestamp is incoherent ",timestampToSeekLast
,testEvent
.getEventTime().getTime());
274 assertEquals("event name after seekTime(time) is incoherent ",eventNameAfterSeekLast
,testEvent
.getParentTracefile().getTracefileName());
275 // Test that the next event is NULL (end of the trace)
276 testEvent
= testTrace
.readNextEvent();
277 assertSame("seekAndRead(time) returned null ",null,testEvent
);
280 // Make sure we can seek back
281 testEvent
= testTrace
.seekAndRead(new JniTime(firstEventTimestamp
) );
282 assertNotSame("seekAndRead(time) to seek back returned null",null,testEvent
);
283 assertEquals("seekAndRead(time) timestamp after seek back is incoherent",firstEventTimestamp
,testEvent
.getEventTime().getTime());
287 // Tests below are for seekToTime()
288 // These are the same test as seekAndRead() for a readNextEvent() should be performed after seek
290 // Test #1 of seekToTime()
291 testTrace
.seekToTime(new JniTime(timestampToSeekTest1
) );
292 testEvent
= testTrace
.readNextEvent();
293 assertNotSame("seekToTime(time) returned null (test #1)",null,testEvent
);
294 assertEquals("seekToTime(time) timestamp is incoherent (test #1)",timestampToSeekTest1
,testEvent
.getEventTime().getTime());
295 assertEquals("event name after seekTime(time) is incoherent (test #1)",eventNameAfterSeekTest1
,testEvent
.getParentTracefile().getTracefileName());
296 // Test that the next event after seek in the one we expect
297 testEvent
= testTrace
.readNextEvent();
298 assertEquals("readNextEvent() name after seekToTime(time) is incoherent (test #1)",nextEventNameAfterSeekTest1
,testEvent
.getParentTracefile().getTracefileName());
300 // Test #2 of seekToTime()
301 testTrace
.seekToTime(new JniTime(timestampToSeekTest2
) );
302 testEvent
= testTrace
.readNextEvent();
303 assertNotSame("seekToTime(time) returned null (test #2)",null,testEvent
);
304 assertEquals("seekToTime(time) timestamp is incoherent (test #2)",timestampToSeekTest2
,testEvent
.getEventTime().getTime());
305 assertEquals("event name after seekTime(time) is incoherent (test #2)",eventNameAfterSeekTest2
,testEvent
.getParentTracefile().getTracefileName());
306 // Test that the next event after seek in the one we expect
307 testEvent
= testTrace
.readNextEvent();
308 assertEquals("readNextEvent() name after seekToTime(time) is incoherent (test #2)",nextEventNameAfterSeekTest2
,testEvent
.getParentTracefile().getTracefileName());
311 // Seek to the LAST event of the trace
312 testTrace
.seekToTime(new JniTime(timestampToSeekLast
) );
313 testEvent
= testTrace
.readNextEvent();
314 assertNotSame("seekToTime(time) returned null ",null,testEvent
);
315 assertEquals("seekToTime(time) timestamp is incoherent ",timestampToSeekLast
,testEvent
.getEventTime().getTime());
316 assertEquals("event name after seekTime(time) is incoherent ",eventNameAfterSeekLast
,testEvent
.getParentTracefile().getTracefileName());
317 // Test that the next event is NULL (end of the trace)
318 testEvent
= testTrace
.readNextEvent();
319 assertSame("seekToTime(time) returned null ",null,testEvent
);
322 // Make sure we can seek back
323 testTrace
.seekToTime(new JniTime(firstEventTimestamp
) );
324 testEvent
= testTrace
.readNextEvent();
325 assertNotSame("seekToTime(time) to seek back returned null",null,testEvent
);
326 assertEquals("seekToTime(time) timestamp after seek back is incoherent",firstEventTimestamp
,testEvent
.getEventTime().getTime());
329 public void testEventDisplacementByTracefile() {
331 JniEvent testEvent
= null;
332 JniTrace testTrace
= prepareTraceToTest();
334 // Read first event for the metadata (which is also the first event in the trace)
335 testEvent
= testTrace
.readNextEvent(testTrace
.requestTracefileByName(firstEventTracefilename
) );
336 assertNotSame("readNextEvent() returned null",null,testEvent
);
337 assertEquals("readNextEvent() timestamp is incoherent",firstEventTimestamp
,testEvent
.getEventTime().getTime() );
339 // If we read the next event again for this tracefile, we should get the SECOND event
340 testEvent
= testTrace
.readNextEvent(testTrace
.requestTracefileByName(firstEventTracefilename
));
341 assertNotSame("readNextEvent() on second read returned null",null,testEvent
);
342 assertEquals("readNextEvent() timestamp on second read is incoherent",secondEventTimestamp
,testEvent
.getEventTime().getTime() );
344 // Reading the "global" event should take care of the change
345 // So if we read the next event, we should get the THIRD event
346 testEvent
= testTrace
.readNextEvent();
347 assertNotSame("readNextEvent() to read global event returned null",null,testEvent
);
348 assertEquals("readNextEvent() timestamp to read global event is incoherent",thirdEventTimestamp
,testEvent
.getEventTime().getTime());
350 // Now read the next event for another type of tracefile
351 testEvent
= testTrace
.readNextEvent(testTrace
.requestTracefileByName(eventTracefilenameAfterMetadata
) );
352 assertNotSame("readNextEvent() returned null",null,testEvent
);
353 assertEquals("readNextEvent() timestamp is incoherent",eventTimestampAfterMetadata
,testEvent
.getEventTime().getTime() );
356 // Seek back to the beginning
357 testTrace
.seekToTime(new JniTime(firstEventTimestamp
), testTrace
.requestTracefileByName(firstEventTracefilename
) );
358 // Read the first event
359 testEvent
= testTrace
.readNextEvent(testTrace
.requestTracefileByName(firstEventTracefilename
) );
360 assertNotSame("readNextEvent() after seekToTime returned null",null,testEvent
);
361 assertEquals("readNextEvent() after seekToTime timestamp is incoherent",firstEventTimestamp
,testEvent
.getEventTime().getTime() );
363 // Seek and Read the first event for the metadata (again the first event in the trace)
364 testEvent
= testTrace
.seekAndRead(new JniTime(firstEventTimestamp
), testTrace
.requestTracefileByName(firstEventTracefilename
) );
365 assertNotSame("seekAndRead() returned null",null,testEvent
);
366 assertEquals("seekAndRead() timestamp is incoherent",firstEventTimestamp
,testEvent
.getEventTime().getTime() );
368 // Seek the whole trace to the infinity
369 testTrace
.seekToTime(new JniTime(Long
.MAX_VALUE
));
370 // Seek and Read the next event in the trace
371 testEvent
= testTrace
.seekAndRead(new JniTime(timestampToSeekTest1
), testTrace
.requestTracefileByName(eventTracefilenameAfterSeekTest1
) );
372 assertNotSame("seekAndRead() returned null",null,testEvent
);
373 assertEquals("seekAndRead() timestamp is incoherent",timestampToSeekTest1
,testEvent
.getEventTime().getTime() );
374 // Read next event... only the same type should be here as other are exhausted
375 testEvent
= testTrace
.readNextEvent();
376 assertNotSame("readNextEvent() after seekToTime returned null",null,testEvent
);
377 assertEquals("readNextEvent() name after seekToTime is incoherent",eventNameAfterSeekTest1
,testEvent
.getParentTracefile().getTracefileName());