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