2 package org
.eclipse
.linuxtools
.lttng
.jni
;
4 import junit
.framework
.TestCase
;
7 Functions tested here :
9 public JniTrace(JniTrace oldTrace)
10 public JniTrace(String newpath) throws JafException
11 public JniTrace(long newPtr) throws JafException
13 public void openTrace(String newPath) throws JafException
14 public void openTrace() throws JafException
15 public void closeTrace( ) throws JafException
17 public JniEvent readNextEvent()
18 public JniEvent findNextEvent()
19 public JniEvent seekAndRead(JniTime seekTime)
20 public void seekToTime(JniTime seekTime)
22 public JniTracefile requestTracefileByName(String tracefileName)
23 public JniEvent requestEventByName(String tracefileName)
24 public ArrayList<Location> requestTraceLocation()
26 public String getTracepath()
27 public int getCpuNumber()
28 public long getArchType()
29 public long getArchVariant()
30 public short getArchSize()
31 public short getLttMajorVersion()
32 public short getLttMinorVersion()
33 public short getFlightRecorder()
34 public long getFreqScale()
35 public long getStartFreq()
36 public long getStartTimestampCurrentCounter()
37 public long getStartMonotonic()
38 public JniTime getStartTime()
39 public JniTime getStartTimeFromTimestampCurrentCounter()
40 public HashMap<String, JniTracefile> getTracefilesMap()
41 public long getTracePtr()
43 public void printAllTracefilesInformation()
44 public void printTraceInformation()
46 public String toString()
50 public class JniTraceTest
extends TestCase
52 private final static boolean printLttDebug
= false;
54 private final static String tracepath1
="traceset/trace-618339events-1293lost-1cpu";
55 private final static String tracepath2
="traceset/trace-1021events-nolost-1cpu";
56 private final static String wrongTracePath
="/somewhere/that/does/not/exist";
58 private final static String correctTracefileName
="kernel0";
59 private final static String wrongTracefileName
="somethingThatDoesNotExists";
61 private final static int numberOfTracefilesInTrace
= 18;
63 private final static long firstEventTimestamp
= 952088954601L;
64 private final static String firstEventTracefilename
= "metadata0";
66 private final static long secondEventTimestamp
= 952088959952L;
67 private final static String secondEventName
= "metadata";
69 private final static long thirdEventTimestamp
= 952088965599L;
71 private final static long eventTimestampAfterMetadata
= 952090116049L;
72 private final static String eventTracefilenameAfterMetadata
= "kernel0";
74 private final static long timestampToSeekTest1
= 953852206193L;
75 private final static String eventNameAfterSeekTest1
= "kernel";
76 private final static String eventTracefilenameAfterSeekTest1
= "kernel0";
77 private final static String nextEventNameAfterSeekTest1
= "fs";
79 private final static long timestampToSeekTest2
= 953852210706L;
80 private final static String eventNameAfterSeekTest2
= "fs";
81 private final static String nextEventNameAfterSeekTest2
= "kernel";
83 private final static long timestampToSeekLast
= 960386638531L;
84 private final static String eventNameAfterSeekLast
= "kernel";
87 private JniTrace
prepareTraceToTest() {
88 JniTrace tmpTrace
= null;
90 // This trace should be valid
92 tmpTrace
= new JniTrace(tracepath1
, printLttDebug
);
94 catch( JniException e
) { }
99 public void testTraceConstructors() {
100 JniTrace testTrace1
= null;
101 @SuppressWarnings("unused")
102 JniTrace testTrace2
= null;
104 // Test constructor with argument on a wrong tracepath
106 testTrace1
= new JniTrace(wrongTracePath
, printLttDebug
);
107 fail("Construction with wrong tracepath should fail!");
109 catch( JniException e
) {
112 // Test constructor with argument on a correct tracepath
114 testTrace1
= new JniTrace(tracepath1
, printLttDebug
);
116 catch( JniException e
) {
117 fail("Construction with correct tracepath failed!");
120 // Test copy constructor that take a pointer with a good pointer
122 testTrace1
= new JniTrace( new Jni_C_Pointer(0), printLttDebug
);
123 fail("Construction with wrong pointer should fail!");
125 catch( JniException e
) {
128 // Test copy constructor that take a pointer with a good pointer
130 testTrace1
= new JniTrace(tracepath1
, printLttDebug
); // This trace should be valid
131 testTrace2
= new JniTrace( testTrace1
.getTracePtr(), printLttDebug
);
133 catch( JniException e
) {
134 fail("Construction with correct pointer failed!");
139 public void testTraceOpenClose() {
141 JniTrace testTrace
= prepareTraceToTest(); // This trace should be valid
143 // test the constructor with arguments passing a wrong tracepath
145 testTrace
.openTrace(wrongTracePath
);
146 fail("Open with wrong tracepath should fail!");
148 catch( JniException e
) { }
150 // Test open with a correct tracepath
152 testTrace
.openTrace(tracepath1
);
153 assertNotSame("getTracepath is empty after open","",testTrace
.getTracepath() );
155 catch( JniException e
) {
156 fail("Open with a correct tracepath failed!");
159 // Test to open a trace already opened
161 testTrace
.openTrace(tracepath1
);
162 testTrace
.openTrace(tracepath2
);
163 assertNotSame("getTracepath is empty after open","",testTrace
.getTracepath() );
165 catch( JniException e
) {
166 fail("Reopen of a trace failed!");
170 // Test to open a trace already opened, but with a wrong tracepath
172 testTrace
.openTrace(tracepath1
);
173 testTrace
.openTrace(wrongTracePath
);
174 fail("Reopen with wrong tracepath should fail!");
176 catch( JniException e
) {
180 public void testGetSet() {
182 JniTrace testTrace
= prepareTraceToTest();
184 // Test that all Get/Set return data
185 assertNotSame("getTracepath is empty","",testTrace
.getTracepath() );
186 assertNotSame("getCpuNumber is 0",0,testTrace
.getCpuNumber() );
187 assertNotSame("getArchType is 0",0,testTrace
.getArchType() );
188 assertNotSame("getArchVariant is 0",0,testTrace
.getArchVariant() );
189 assertNotSame("getArchSize is 0",0,testTrace
.getArchSize() );
190 assertNotSame("getLttMajorVersion is 0",0,testTrace
.getLttMajorVersion() );
191 assertNotSame("getLttMinorVersion is 0",0,testTrace
.getLttMinorVersion() );
192 assertNotSame("getFlightRecorder is 0",0,testTrace
.getFlightRecorder() );
193 assertNotSame("getFreqScale is 0",0,testTrace
.getFreqScale() );
194 assertNotSame("getStartFreq is 0",0,testTrace
.getStartFreq() );
195 assertNotSame("getStartTimestampCurrentCounter is 0",0,testTrace
.getStartTimestampCurrentCounter());
196 assertNotSame("getStartMonotonic is 0",0,testTrace
.getStartMonotonic() );
197 assertNotSame("getStartTime is null",null,testTrace
.getStartTime() );
198 assertNotSame("getStartTimeFromTimestampCurrentCounter is null",null,testTrace
.getStartTimeFromTimestampCurrentCounter() );
199 assertNotSame("getTracefilesMap is null",null,testTrace
.getTracefilesMap() );
200 // Also check that the map contain some tracefiles
201 assertSame("getTracefilesMap returned an unexpected number of tracefiles",numberOfTracefilesInTrace
,testTrace
.getTracefilesMap().size() );
202 assertNotSame("getTracePtr is 0",0,testTrace
.getTracePtr() );
207 public void testPrintAndToString() {
209 JniTrace testTrace
= prepareTraceToTest();
211 // Test printTraceInformation
213 testTrace
.printTraceInformation();
215 catch( Exception e
) {
216 fail("printTraceInformation failed!");
220 assertNotSame("toString returned empty data","",testTrace
.toString() );
223 public void testRequestFunctions() {
225 JniTrace testTrace
= prepareTraceToTest();
227 // Test requestTracefileByName()
228 assertNotSame("requestTracefileByName returned null",null,testTrace
.requestTracefileByName(correctTracefileName
) );
229 assertSame("requestTracefileByName returned content on non existent name",null,testTrace
.requestTracefileByName(wrongTracefileName
) );
231 // Test requestEventByName()
232 assertNotSame("requestEventByName returned null",null,testTrace
.requestEventByName(correctTracefileName
) );
233 assertSame("requestEventByName returned content on non existent name",null,testTrace
.requestEventByName(wrongTracefileName
) );
236 public void testEventDisplacement() {
238 JniEvent testEvent
= null;
239 JniTrace testTrace
= prepareTraceToTest();
241 // Test readNextEvent()
242 testEvent
= testTrace
.readNextEvent();
243 assertNotSame("readNextEvent() returned null",null,testEvent
);
244 assertEquals("readNextEvent() timestamp is incoherent",firstEventTimestamp
,testEvent
.getEventTime().getTime() );
246 // Test findNextEvent()
247 testEvent
= testTrace
.findNextEvent();
248 assertNotSame("findNextEvent() returned null",null,testEvent
);
249 assertEquals("findNextEvent() name is incoherent",secondEventName
,testEvent
.getParentTracefile().getTracefileName() );
251 // Test readNextEvent()
252 testEvent
= testTrace
.readNextEvent();
253 assertNotSame("readNextEvent() returned null",null,testEvent
);
254 assertEquals("readNextEvent() timestamp is incoherent",secondEventName
,testEvent
.getParentTracefile().getTracefileName() );
256 // Tests below are for seekAndRead()
257 // After, we will perform the same operation for seekTime
259 // Test #1 of seekAndRead()
260 testEvent
= testTrace
.seekAndRead(new JniTime(timestampToSeekTest1
) );
261 assertNotSame("seekAndRead(time) returned null (test #1)",null,testEvent
);
262 assertEquals("seekAndRead(time) timestamp is incoherent (test #1)",timestampToSeekTest1
,testEvent
.getEventTime().getTime());
263 assertEquals("event name after seekAndRead(time) is incoherent (test #1)",eventNameAfterSeekTest1
,testEvent
.getParentTracefile().getTracefileName());
264 // Test that the next event after seek in the one we expect
265 testEvent
= testTrace
.readNextEvent();
266 assertEquals("readNextEvent() name after seekAndRead(time) is incoherent (test #1)",nextEventNameAfterSeekTest1
,testEvent
.getParentTracefile().getTracefileName());
268 // Test #2 of seekAndRead()
269 testEvent
= testTrace
.seekAndRead(new JniTime(timestampToSeekTest2
) );
270 assertNotSame("seekAndRead(time) returned null (test #2)",null,testEvent
);
271 assertEquals("seekAndRead(time) timestamp is incoherent (test #2)",timestampToSeekTest2
,testEvent
.getEventTime().getTime());
272 assertEquals("event name after seekAndRead(time) is incoherent (test #2)",eventNameAfterSeekTest2
,testEvent
.getParentTracefile().getTracefileName());
273 // Test that the next event after seek in the one we expect
274 testEvent
= testTrace
.readNextEvent();
275 assertEquals("readNextEvent() name after seekAndRead(time) is incoherent (test #2)",nextEventNameAfterSeekTest2
,testEvent
.getParentTracefile().getTracefileName());
278 // Seek to the LAST event of the trace
279 testEvent
= testTrace
.seekAndRead(new JniTime(timestampToSeekLast
) );
280 assertNotSame("seekAndRead(time) returned null ",null,testEvent
);
281 assertEquals("seekAndRead(time) timestamp is incoherent ",timestampToSeekLast
,testEvent
.getEventTime().getTime());
282 assertEquals("event name after seekTime(time) is incoherent ",eventNameAfterSeekLast
,testEvent
.getParentTracefile().getTracefileName());
283 // Test that the next event is NULL (end of the trace)
284 testEvent
= testTrace
.readNextEvent();
285 assertSame("seekAndRead(time) returned null ",null,testEvent
);
288 // Make sure we can seek back
289 testEvent
= testTrace
.seekAndRead(new JniTime(firstEventTimestamp
) );
290 assertNotSame("seekAndRead(time) to seek back returned null",null,testEvent
);
291 assertEquals("seekAndRead(time) timestamp after seek back is incoherent",firstEventTimestamp
,testEvent
.getEventTime().getTime());
295 // Tests below are for seekToTime()
296 // These are the same test as seekAndRead() for a readNextEvent() should be performed after seek
298 // Test #1 of seekToTime()
299 testTrace
.seekToTime(new JniTime(timestampToSeekTest1
) );
300 testEvent
= testTrace
.readNextEvent();
301 assertNotSame("seekToTime(time) returned null (test #1)",null,testEvent
);
302 assertEquals("seekToTime(time) timestamp is incoherent (test #1)",timestampToSeekTest1
,testEvent
.getEventTime().getTime());
303 assertEquals("event name after seekTime(time) is incoherent (test #1)",eventNameAfterSeekTest1
,testEvent
.getParentTracefile().getTracefileName());
304 // Test that the next event after seek in the one we expect
305 testEvent
= testTrace
.readNextEvent();
306 assertEquals("readNextEvent() name after seekToTime(time) is incoherent (test #1)",nextEventNameAfterSeekTest1
,testEvent
.getParentTracefile().getTracefileName());
308 // Test #2 of seekToTime()
309 testTrace
.seekToTime(new JniTime(timestampToSeekTest2
) );
310 testEvent
= testTrace
.readNextEvent();
311 assertNotSame("seekToTime(time) returned null (test #2)",null,testEvent
);
312 assertEquals("seekToTime(time) timestamp is incoherent (test #2)",timestampToSeekTest2
,testEvent
.getEventTime().getTime());
313 assertEquals("event name after seekTime(time) is incoherent (test #2)",eventNameAfterSeekTest2
,testEvent
.getParentTracefile().getTracefileName());
314 // Test that the next event after seek in the one we expect
315 testEvent
= testTrace
.readNextEvent();
316 assertEquals("readNextEvent() name after seekToTime(time) is incoherent (test #2)",nextEventNameAfterSeekTest2
,testEvent
.getParentTracefile().getTracefileName());
319 // Seek to the LAST event of the trace
320 testTrace
.seekToTime(new JniTime(timestampToSeekLast
) );
321 testEvent
= testTrace
.readNextEvent();
322 assertNotSame("seekToTime(time) returned null ",null,testEvent
);
323 assertEquals("seekToTime(time) timestamp is incoherent ",timestampToSeekLast
,testEvent
.getEventTime().getTime());
324 assertEquals("event name after seekTime(time) is incoherent ",eventNameAfterSeekLast
,testEvent
.getParentTracefile().getTracefileName());
325 // Test that the next event is NULL (end of the trace)
326 testEvent
= testTrace
.readNextEvent();
327 assertSame("seekToTime(time) returned null ",null,testEvent
);
330 // Make sure we can seek back
331 testTrace
.seekToTime(new JniTime(firstEventTimestamp
) );
332 testEvent
= testTrace
.readNextEvent();
333 assertNotSame("seekToTime(time) to seek back returned null",null,testEvent
);
334 assertEquals("seekToTime(time) timestamp after seek back is incoherent",firstEventTimestamp
,testEvent
.getEventTime().getTime());
337 public void testEventDisplacementByTracefile() {
339 JniEvent testEvent
= null;
340 JniTrace testTrace
= prepareTraceToTest();
342 // Read first event for the metadata (which is also the first event in the trace)
343 testEvent
= testTrace
.readNextEvent(testTrace
.requestTracefileByName(firstEventTracefilename
) );
344 assertNotSame("readNextEvent() returned null",null,testEvent
);
345 assertEquals("readNextEvent() timestamp is incoherent",firstEventTimestamp
,testEvent
.getEventTime().getTime() );
347 // If we read the next event again for this tracefile, we should get the SECOND event
348 testEvent
= testTrace
.readNextEvent(testTrace
.requestTracefileByName(firstEventTracefilename
));
349 assertNotSame("readNextEvent() on second read returned null",null,testEvent
);
350 assertEquals("readNextEvent() timestamp on second read is incoherent",secondEventTimestamp
,testEvent
.getEventTime().getTime() );
352 // Reading the "global" event should take care of the change
353 // So if we read the next event, we should get the THIRD event
354 testEvent
= testTrace
.readNextEvent();
355 assertNotSame("readNextEvent() to read global event returned null",null,testEvent
);
356 assertEquals("readNextEvent() timestamp to read global event is incoherent",thirdEventTimestamp
,testEvent
.getEventTime().getTime());
358 // Now read the next event for another type of tracefile
359 testEvent
= testTrace
.readNextEvent(testTrace
.requestTracefileByName(eventTracefilenameAfterMetadata
) );
360 assertNotSame("readNextEvent() returned null",null,testEvent
);
361 assertEquals("readNextEvent() timestamp is incoherent",eventTimestampAfterMetadata
,testEvent
.getEventTime().getTime() );
364 // Seek back to the beginning
365 testTrace
.seekToTime(new JniTime(firstEventTimestamp
), testTrace
.requestTracefileByName(firstEventTracefilename
) );
366 // Read the first event
367 testEvent
= testTrace
.readNextEvent(testTrace
.requestTracefileByName(firstEventTracefilename
) );
368 assertNotSame("readNextEvent() after seekToTime returned null",null,testEvent
);
369 assertEquals("readNextEvent() after seekToTime timestamp is incoherent",firstEventTimestamp
,testEvent
.getEventTime().getTime() );
371 // Seek and Read the first event for the metadata (again the first event in the trace)
372 testEvent
= testTrace
.seekAndRead(new JniTime(firstEventTimestamp
), testTrace
.requestTracefileByName(firstEventTracefilename
) );
373 assertNotSame("seekAndRead() returned null",null,testEvent
);
374 assertEquals("seekAndRead() timestamp is incoherent",firstEventTimestamp
,testEvent
.getEventTime().getTime() );
376 // Seek the whole trace to the infinity
377 testTrace
.seekToTime(new JniTime(Long
.MAX_VALUE
));
378 // Seek and Read the next event in the trace
379 testEvent
= testTrace
.seekAndRead(new JniTime(timestampToSeekTest1
), testTrace
.requestTracefileByName(eventTracefilenameAfterSeekTest1
) );
380 assertNotSame("seekAndRead() returned null",null,testEvent
);
381 assertEquals("seekAndRead() timestamp is incoherent",timestampToSeekTest1
,testEvent
.getEventTime().getTime() );
382 // Read next event... only the same type should be here as other are exhausted
383 testEvent
= testTrace
.readNextEvent();
384 assertNotSame("readNextEvent() after seekToTime returned null",null,testEvent
);
385 assertEquals("readNextEvent() name after seekToTime is incoherent",eventNameAfterSeekTest1
,testEvent
.getParentTracefile().getTracefileName());