New JNI implementation to support multiple version of traces (bug id 302987)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / jni / JniTraceTest.java
CommitLineData
03c71d1e
ASL
1
2package org.eclipse.linuxtools.lttng.tests.jni;
3
4import org.eclipse.linuxtools.lttng.jni.JniEvent;
86de1b08
ASL
5import org.eclipse.linuxtools.lttng.jni.JniException;
6import org.eclipse.linuxtools.lttng.jni.JniTime;
03c71d1e 7import org.eclipse.linuxtools.lttng.jni.JniTrace;
86de1b08 8import org.eclipse.linuxtools.lttng.jni.Jni_C_Pointer;
03c71d1e
ASL
9
10import junit.framework.TestCase;
11
12/*
13 Functions tested here :
14 public JniTrace()
15 public JniTrace(JniTrace oldTrace)
16 public JniTrace(String newpath) throws JafException
17 public JniTrace(long newPtr) throws JafException
18
19 public void openTrace(String newPath) throws JafException
20 public void openTrace() throws JafException
21 public void closeTrace( ) throws JafException
22
23 public JniEvent readNextEvent()
24 public JniEvent findNextEvent()
25 public JniEvent seekAndRead(JniTime seekTime)
26 public void seekToTime(JniTime seekTime)
27
28 public JniTracefile requestTracefileByName(String tracefileName)
29 public JniEvent requestEventByName(String tracefileName)
30 public ArrayList<Location> requestTraceLocation()
31
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()
03c71d1e
ASL
45 public JniTime getStartTimeFromTimestampCurrentCounter()
46 public HashMap<String, JniTracefile> getTracefilesMap()
47 public long getTracePtr()
48
49 public void printAllTracefilesInformation()
50 public void printTraceInformation()
51
52 public String toString()
53 */
54
55
56public class JniTraceTest extends TestCase
57{
58 private final static boolean printLttDebug = false;
59
1c859a36
WB
60 private final static String tracepath1="traceset/trace-15316events_nolost_newformat";
61 private final static String tracepath2="traceset/trace-15471events_nolost_newformat";
03c71d1e
ASL
62 private final static String wrongTracePath="/somewhere/that/does/not/exist";
63
64 private final static String correctTracefileName="kernel0";
65 private final static String wrongTracefileName="somethingThatDoesNotExists";
66
1c859a36 67 private final static int numberOfTracefilesInTrace = 16;
03c71d1e 68
1c859a36 69 private final static long firstEventTimestamp = 13589759412128L;
03c71d1e
ASL
70 private final static String firstEventTracefilename = "metadata0";
71
1c859a36 72 private final static long secondEventTimestamp = 13589759419903L;
03c71d1e
ASL
73 private final static String secondEventName = "metadata";
74
1c859a36 75 private final static long thirdEventTimestamp = 13589759422785L;
03c71d1e 76
1c859a36 77 private final static long eventTimestampAfterMetadata = 13589760262237L;
03c71d1e
ASL
78 private final static String eventTracefilenameAfterMetadata = "kernel0";
79
1c859a36 80 private final static long timestampToSeekTest1 = 13589821608319L;
03c71d1e
ASL
81 private final static String eventNameAfterSeekTest1 = "kernel";
82 private final static String eventTracefilenameAfterSeekTest1 = "kernel0";
1c859a36 83 private final static String nextEventNameAfterSeekTest1 = "vm_state";
03c71d1e 84
1c859a36 85 private final static long timestampToSeekTest2 = 13589861889350L;
03c71d1e
ASL
86 private final static String eventNameAfterSeekTest2 = "fs";
87 private final static String nextEventNameAfterSeekTest2 = "kernel";
88
1c859a36 89 private final static long timestampToSeekLast = 13589906758692L;
03c71d1e
ASL
90 private final static String eventNameAfterSeekLast = "kernel";
91
92
93 private JniTrace prepareTraceToTest() {
94 JniTrace tmpTrace = null;
95
96 // This trace should be valid
97 try {
86de1b08 98 tmpTrace = new JniTrace(tracepath1, printLttDebug);
1c859a36 99 //tmpTrace.seekToTime(new JniTime(0L));
03c71d1e
ASL
100 }
101 catch( JniException e) { }
102
103 return tmpTrace;
104 }
105
106 public void testTraceConstructors() {
86de1b08 107 JniTrace testTrace1 = null;
03c71d1e
ASL
108 @SuppressWarnings("unused")
109 JniTrace testTrace2 = null;
110
111 // Test constructor with argument on a wrong tracepath
112 try {
86de1b08 113 testTrace1 = new JniTrace(wrongTracePath, printLttDebug);
03c71d1e
ASL
114 fail("Construction with wrong tracepath should fail!");
115 }
116 catch( JniException e) {
117 }
118
119 // Test constructor with argument on a correct tracepath
120 try {
86de1b08 121 testTrace1 = new JniTrace(tracepath1, printLttDebug);
03c71d1e
ASL
122 }
123 catch( JniException e) {
124 fail("Construction with correct tracepath failed!");
125 }
86de1b08
ASL
126
127 // Test copy constructor that take a pointer with a good pointer
128 try {
129 testTrace1 = new JniTrace( new Jni_C_Pointer(0), printLttDebug);
130 fail("Construction with wrong pointer should fail!");
131 }
132 catch( JniException e) {
133 }
134
135 // Test copy constructor that take a pointer with a good pointer
136 try {
137 testTrace1 = new JniTrace(tracepath1, printLttDebug); // This trace should be valid
138 testTrace2 = new JniTrace( testTrace1.getTracePtr(), printLttDebug);
139 }
140 catch( JniException e) {
141 fail("Construction with correct pointer failed!");
142 }
143
03c71d1e
ASL
144 }
145
146 public void testTraceOpenClose() {
147
148 JniTrace testTrace = prepareTraceToTest(); // This trace should be valid
149
150 // test the constructor with arguments passing a wrong tracepath
151 try {
152 testTrace.openTrace(wrongTracePath);
153 fail("Open with wrong tracepath should fail!");
154 }
155 catch( JniException e) { }
156
157 // Test open with a correct tracepath
158 try {
159 testTrace.openTrace(tracepath1);
160 assertNotSame("getTracepath is empty after open","",testTrace.getTracepath() );
161 }
162 catch( JniException e) {
163 fail("Open with a correct tracepath failed!");
164 }
165
166 // Test to open a trace already opened
167 try {
168 testTrace.openTrace(tracepath1);
169 testTrace.openTrace(tracepath2);
170 assertNotSame("getTracepath is empty after open","",testTrace.getTracepath() );
171 }
172 catch( JniException e) {
173 fail("Reopen of a trace failed!");
174 }
175
176
177 // Test to open a trace already opened, but with a wrong tracepath
178 try {
179 testTrace.openTrace(tracepath1);
180 testTrace.openTrace(wrongTracePath);
181 fail("Reopen with wrong tracepath should fail!");
182 }
183 catch( JniException e) {
184 }
185 }
186
187 public void testGetSet() {
188
189 JniTrace testTrace = prepareTraceToTest();
190
191 // Test that all Get/Set return data
192 assertNotSame("getTracepath is empty","",testTrace.getTracepath() );
193 assertNotSame("getCpuNumber is 0",0,testTrace.getCpuNumber() );
194 assertNotSame("getArchType is 0",0,testTrace.getArchType() );
195 assertNotSame("getArchVariant is 0",0,testTrace.getArchVariant() );
196 assertNotSame("getArchSize is 0",0,testTrace.getArchSize() );
197 assertNotSame("getLttMajorVersion is 0",0,testTrace.getLttMajorVersion() );
198 assertNotSame("getLttMinorVersion is 0",0,testTrace.getLttMinorVersion() );
199 assertNotSame("getFlightRecorder is 0",0,testTrace.getFlightRecorder() );
200 assertNotSame("getFreqScale is 0",0,testTrace.getFreqScale() );
201 assertNotSame("getStartFreq is 0",0,testTrace.getStartFreq() );
202 assertNotSame("getStartTimestampCurrentCounter is 0",0,testTrace.getStartTimestampCurrentCounter());
203 assertNotSame("getStartMonotonic is 0",0,testTrace.getStartMonotonic() );
204 assertNotSame("getStartTime is null",null,testTrace.getStartTime() );
03c71d1e
ASL
205 assertNotSame("getStartTimeNoAdjustement is null",null,testTrace.getStartTimeNoAdjustement() );
206 assertNotSame("getTracefilesMap is null",null,testTrace.getTracefilesMap() );
207 // Also check that the map contain some tracefiles
208 assertSame("getTracefilesMap returned an unexpected number of tracefiles",numberOfTracefilesInTrace,testTrace.getTracefilesMap().size() );
209 assertNotSame("getTracePtr is 0",0,testTrace.getTracePtr() );
210
211
212 }
213
214 public void testPrintAndToString() {
215
216 JniTrace testTrace = prepareTraceToTest();
217
218 // Test printTraceInformation
219 try {
220 testTrace.printTraceInformation();
221 }
222 catch( Exception e) {
223 fail("printTraceInformation failed!");
224 }
225
226 // Test ToString()
227 assertNotSame("toString returned empty data","",testTrace.toString() );
228 }
229
230 public void testRequestFunctions() {
231
232 JniTrace testTrace = prepareTraceToTest();
233
234 // Test requestTracefileByName()
235 assertNotSame("requestTracefileByName returned null",null,testTrace.requestTracefileByName(correctTracefileName) );
236 assertSame("requestTracefileByName returned content on non existent name",null,testTrace.requestTracefileByName(wrongTracefileName) );
237
238 // Test requestEventByName()
239 assertNotSame("requestEventByName returned null",null,testTrace.requestEventByName(correctTracefileName) );
240 assertSame("requestEventByName returned content on non existent name",null,testTrace.requestEventByName(wrongTracefileName) );
241 }
242
243 public void testEventDisplacement() {
244
245 JniEvent testEvent = null;
246 JniTrace testTrace = prepareTraceToTest();
247
248 // Test readNextEvent()
249 testEvent = testTrace.readNextEvent();
250 assertNotSame("readNextEvent() returned null",null,testEvent);
251 assertEquals("readNextEvent() timestamp is incoherent",firstEventTimestamp,testEvent.getEventTime().getTime() );
252
253 // Test findNextEvent()
254 testEvent = testTrace.findNextEvent();
255 assertNotSame("findNextEvent() returned null",null,testEvent);
256 assertEquals("findNextEvent() name is incoherent",secondEventName,testEvent.getParentTracefile().getTracefileName() );
257
258 // Test readNextEvent()
259 testEvent = testTrace.readNextEvent();
260 assertNotSame("readNextEvent() returned null",null,testEvent);
261 assertEquals("readNextEvent() timestamp is incoherent",secondEventName,testEvent.getParentTracefile().getTracefileName() );
262
263 // Tests below are for seekAndRead()
264 // After, we will perform the same operation for seekTime
265 //
266 // Test #1 of seekAndRead()
267 testEvent = testTrace.seekAndRead(new JniTime(timestampToSeekTest1) );
268 assertNotSame("seekAndRead(time) returned null (test #1)",null,testEvent);
269 assertEquals("seekAndRead(time) timestamp is incoherent (test #1)",timestampToSeekTest1,testEvent.getEventTime().getTime());
270 assertEquals("event name after seekAndRead(time) is incoherent (test #1)",eventNameAfterSeekTest1,testEvent.getParentTracefile().getTracefileName());
271 // Test that the next event after seek in the one we expect
272 testEvent = testTrace.readNextEvent();
273 assertEquals("readNextEvent() name after seekAndRead(time) is incoherent (test #1)",nextEventNameAfterSeekTest1,testEvent.getParentTracefile().getTracefileName());
274
275 // Test #2 of seekAndRead()
276 testEvent = testTrace.seekAndRead(new JniTime(timestampToSeekTest2) );
277 assertNotSame("seekAndRead(time) returned null (test #2)",null,testEvent);
278 assertEquals("seekAndRead(time) timestamp is incoherent (test #2)",timestampToSeekTest2,testEvent.getEventTime().getTime());
279 assertEquals("event name after seekAndRead(time) is incoherent (test #2)",eventNameAfterSeekTest2,testEvent.getParentTracefile().getTracefileName());
280 // Test that the next event after seek in the one we expect
281 testEvent = testTrace.readNextEvent();
282 assertEquals("readNextEvent() name after seekAndRead(time) is incoherent (test #2)",nextEventNameAfterSeekTest2,testEvent.getParentTracefile().getTracefileName());
283
284
285 // Seek to the LAST event of the trace
286 testEvent = testTrace.seekAndRead(new JniTime(timestampToSeekLast) );
287 assertNotSame("seekAndRead(time) returned null ",null,testEvent);
288 assertEquals("seekAndRead(time) timestamp is incoherent ",timestampToSeekLast,testEvent.getEventTime().getTime());
289 assertEquals("event name after seekTime(time) is incoherent ",eventNameAfterSeekLast,testEvent.getParentTracefile().getTracefileName());
290 // Test that the next event is NULL (end of the trace)
291 testEvent = testTrace.readNextEvent();
292 assertSame("seekAndRead(time) returned null ",null,testEvent);
293
294
295 // Make sure we can seek back
296 testEvent = testTrace.seekAndRead(new JniTime(firstEventTimestamp) );
297 assertNotSame("seekAndRead(time) to seek back returned null",null,testEvent);
298 assertEquals("seekAndRead(time) timestamp after seek back is incoherent",firstEventTimestamp,testEvent.getEventTime().getTime());
299
300
301
302 // Tests below are for seekToTime()
303 // These are the same test as seekAndRead() for a readNextEvent() should be performed after seek
304 //
305 // Test #1 of seekToTime()
306 testTrace.seekToTime(new JniTime(timestampToSeekTest1) );
307 testEvent = testTrace.readNextEvent();
308 assertNotSame("seekToTime(time) returned null (test #1)",null,testEvent);
309 assertEquals("seekToTime(time) timestamp is incoherent (test #1)",timestampToSeekTest1,testEvent.getEventTime().getTime());
310 assertEquals("event name after seekTime(time) is incoherent (test #1)",eventNameAfterSeekTest1,testEvent.getParentTracefile().getTracefileName());
311 // Test that the next event after seek in the one we expect
312 testEvent = testTrace.readNextEvent();
313 assertEquals("readNextEvent() name after seekToTime(time) is incoherent (test #1)",nextEventNameAfterSeekTest1,testEvent.getParentTracefile().getTracefileName());
314
315 // Test #2 of seekToTime()
316 testTrace.seekToTime(new JniTime(timestampToSeekTest2) );
317 testEvent = testTrace.readNextEvent();
318 assertNotSame("seekToTime(time) returned null (test #2)",null,testEvent);
319 assertEquals("seekToTime(time) timestamp is incoherent (test #2)",timestampToSeekTest2,testEvent.getEventTime().getTime());
320 assertEquals("event name after seekTime(time) is incoherent (test #2)",eventNameAfterSeekTest2,testEvent.getParentTracefile().getTracefileName());
321 // Test that the next event after seek in the one we expect
322 testEvent = testTrace.readNextEvent();
323 assertEquals("readNextEvent() name after seekToTime(time) is incoherent (test #2)",nextEventNameAfterSeekTest2,testEvent.getParentTracefile().getTracefileName());
324
325
326 // Seek to the LAST event of the trace
327 testTrace.seekToTime(new JniTime(timestampToSeekLast) );
328 testEvent = testTrace.readNextEvent();
329 assertNotSame("seekToTime(time) returned null ",null,testEvent);
330 assertEquals("seekToTime(time) timestamp is incoherent ",timestampToSeekLast,testEvent.getEventTime().getTime());
331 assertEquals("event name after seekTime(time) is incoherent ",eventNameAfterSeekLast,testEvent.getParentTracefile().getTracefileName());
332 // Test that the next event is NULL (end of the trace)
333 testEvent = testTrace.readNextEvent();
334 assertSame("seekToTime(time) returned null ",null,testEvent);
335
336
337 // Make sure we can seek back
338 testTrace.seekToTime(new JniTime(firstEventTimestamp) );
339 testEvent = testTrace.readNextEvent();
340 assertNotSame("seekToTime(time) to seek back returned null",null,testEvent);
341 assertEquals("seekToTime(time) timestamp after seek back is incoherent",firstEventTimestamp,testEvent.getEventTime().getTime());
342 }
343
344 public void testEventDisplacementByTracefile() {
345
346 JniEvent testEvent = null;
347 JniTrace testTrace = prepareTraceToTest();
348
349 // Read first event for the metadata (which is also the first event in the trace)
350 testEvent = testTrace.readNextEvent(testTrace.requestTracefileByName(firstEventTracefilename) );
351 assertNotSame("readNextEvent() returned null",null,testEvent);
352 assertEquals("readNextEvent() timestamp is incoherent",firstEventTimestamp,testEvent.getEventTime().getTime() );
353
354 // If we read the next event again for this tracefile, we should get the SECOND event
355 testEvent = testTrace.readNextEvent(testTrace.requestTracefileByName(firstEventTracefilename));
356 assertNotSame("readNextEvent() on second read returned null",null,testEvent);
357 assertEquals("readNextEvent() timestamp on second read is incoherent",secondEventTimestamp,testEvent.getEventTime().getTime() );
358
359 // Reading the "global" event should take care of the change
360 // So if we read the next event, we should get the THIRD event
361 testEvent = testTrace.readNextEvent();
362 assertNotSame("readNextEvent() to read global event returned null",null,testEvent);
363 assertEquals("readNextEvent() timestamp to read global event is incoherent",thirdEventTimestamp,testEvent.getEventTime().getTime());
364
365 // Now read the next event for another type of tracefile
366 testEvent = testTrace.readNextEvent(testTrace.requestTracefileByName(eventTracefilenameAfterMetadata) );
367 assertNotSame("readNextEvent() returned null",null,testEvent);
368 assertEquals("readNextEvent() timestamp is incoherent",eventTimestampAfterMetadata,testEvent.getEventTime().getTime() );
369
370
371 // Seek back to the beginning
372 testTrace.seekToTime(new JniTime(firstEventTimestamp), testTrace.requestTracefileByName(firstEventTracefilename) );
373 // Read the first event
374 testEvent = testTrace.readNextEvent(testTrace.requestTracefileByName(firstEventTracefilename) );
375 assertNotSame("readNextEvent() after seekToTime returned null",null,testEvent);
376 assertEquals("readNextEvent() after seekToTime timestamp is incoherent",firstEventTimestamp,testEvent.getEventTime().getTime() );
377
378 // Seek and Read the first event for the metadata (again the first event in the trace)
379 testEvent = testTrace.seekAndRead(new JniTime(firstEventTimestamp), testTrace.requestTracefileByName(firstEventTracefilename) );
380 assertNotSame("seekAndRead() returned null",null,testEvent);
381 assertEquals("seekAndRead() timestamp is incoherent",firstEventTimestamp,testEvent.getEventTime().getTime() );
382
383 // Seek the whole trace to the infinity
384 testTrace.seekToTime(new JniTime(Long.MAX_VALUE));
385 // Seek and Read the next event in the trace
386 testEvent = testTrace.seekAndRead(new JniTime(timestampToSeekTest1), testTrace.requestTracefileByName(eventTracefilenameAfterSeekTest1) );
387 assertNotSame("seekAndRead() returned null",null,testEvent);
388 assertEquals("seekAndRead() timestamp is incoherent",timestampToSeekTest1,testEvent.getEventTime().getTime() );
389 // Read next event... only the same type should be here as other are exhausted
390 testEvent = testTrace.readNextEvent();
391 assertNotSame("readNextEvent() after seekToTime returned null",null,testEvent);
392 assertEquals("readNextEvent() name after seekToTime is incoherent",eventNameAfterSeekTest1,testEvent.getParentTracefile().getTracefileName());
393
394 }
395}
This page took 0.041065 seconds and 5 git commands to generate.