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