Commit | Line | Data |
---|---|---|
03c71d1e | 1 | |
6c13869b | 2 | package org.eclipse.linuxtools.lttng.core.tests.jni; |
03c71d1e ASL |
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() | |
1d1ae093 | 45 | pubilc JniTime getEndTime() |
03c71d1e ASL |
46 | public JniTime getStartTimeFromTimestampCurrentCounter() |
47 | public HashMap<String, JniTracefile> getTracefilesMap() | |
48 | public long getTracePtr() | |
49 | ||
50 | public void printAllTracefilesInformation() | |
51 | public void printTraceInformation() | |
52 | ||
53 | public String toString() | |
54 | */ | |
55 | ||
3b38ea61 | 56 | @SuppressWarnings("nls") |
03c71d1e ASL |
57 | public class JniTraceTest extends TestCase |
58 | { | |
59 | private final static boolean printLttDebug = false; | |
60 | ||
1c859a36 WB |
61 | private final static String tracepath1="traceset/trace-15316events_nolost_newformat"; |
62 | private final static String tracepath2="traceset/trace-15471events_nolost_newformat"; | |
03c71d1e ASL |
63 | private final static String wrongTracePath="/somewhere/that/does/not/exist"; |
64 | ||
65 | private final static String correctTracefileName="kernel0"; | |
66 | private final static String wrongTracefileName="somethingThatDoesNotExists"; | |
67 | ||
1c859a36 | 68 | private final static int numberOfTracefilesInTrace = 16; |
03c71d1e | 69 | |
1c859a36 | 70 | private final static long firstEventTimestamp = 13589759412128L; |
03c71d1e ASL |
71 | private final static String firstEventTracefilename = "metadata0"; |
72 | ||
1c859a36 | 73 | private final static long secondEventTimestamp = 13589759419903L; |
03c71d1e ASL |
74 | private final static String secondEventName = "metadata"; |
75 | ||
1c859a36 | 76 | private final static long thirdEventTimestamp = 13589759422785L; |
03c71d1e | 77 | |
1c859a36 | 78 | private final static long eventTimestampAfterMetadata = 13589760262237L; |
03c71d1e ASL |
79 | private final static String eventTracefilenameAfterMetadata = "kernel0"; |
80 | ||
1c859a36 | 81 | private final static long timestampToSeekTest1 = 13589821608319L; |
03c71d1e ASL |
82 | private final static String eventNameAfterSeekTest1 = "kernel"; |
83 | private final static String eventTracefilenameAfterSeekTest1 = "kernel0"; | |
1c859a36 | 84 | private final static String nextEventNameAfterSeekTest1 = "vm_state"; |
03c71d1e | 85 | |
1c859a36 | 86 | private final static long timestampToSeekTest2 = 13589861889350L; |
03c71d1e ASL |
87 | private final static String eventNameAfterSeekTest2 = "fs"; |
88 | private final static String nextEventNameAfterSeekTest2 = "kernel"; | |
89 | ||
1c859a36 | 90 | private final static long timestampToSeekLast = 13589906758692L; |
03c71d1e ASL |
91 | private final static String eventNameAfterSeekLast = "kernel"; |
92 | ||
93 | ||
94 | private JniTrace prepareTraceToTest() { | |
95 | JniTrace tmpTrace = null; | |
96 | ||
97 | // This trace should be valid | |
98 | try { | |
a3767fd9 | 99 | tmpTrace = JniTraceFactory.getJniTrace(tracepath1, null, printLttDebug); |
1c859a36 | 100 | //tmpTrace.seekToTime(new JniTime(0L)); |
03c71d1e ASL |
101 | } |
102 | catch( JniException e) { } | |
103 | ||
104 | return tmpTrace; | |
105 | } | |
106 | ||
107 | public void testTraceConstructors() { | |
9c841e9c WB |
108 | @SuppressWarnings("unused") |
109 | JniTrace testTrace1 = null; | |
03c71d1e ASL |
110 | @SuppressWarnings("unused") |
111 | JniTrace testTrace2 = null; | |
112 | ||
113 | // Test constructor with argument on a wrong tracepath | |
114 | try { | |
a3767fd9 | 115 | testTrace1 = JniTraceFactory.getJniTrace(wrongTracePath, null, printLttDebug); |
03c71d1e ASL |
116 | fail("Construction with wrong tracepath should fail!"); |
117 | } | |
118 | catch( JniException e) { | |
119 | } | |
120 | ||
121 | // Test constructor with argument on a correct tracepath | |
122 | try { | |
a3767fd9 | 123 | testTrace1 = JniTraceFactory.getJniTrace(tracepath1, null, printLttDebug); |
03c71d1e ASL |
124 | } |
125 | catch( JniException e) { | |
126 | fail("Construction with correct tracepath failed!"); | |
127 | } | |
128 | } | |
129 | ||
130 | public void testTraceOpenClose() { | |
131 | ||
132 | JniTrace testTrace = prepareTraceToTest(); // This trace should be valid | |
133 | ||
134 | // test the constructor with arguments passing a wrong tracepath | |
135 | try { | |
136 | testTrace.openTrace(wrongTracePath); | |
137 | fail("Open with wrong tracepath should fail!"); | |
138 | } | |
139 | catch( JniException e) { } | |
140 | ||
141 | // Test open with a correct tracepath | |
142 | try { | |
143 | testTrace.openTrace(tracepath1); | |
144 | assertNotSame("getTracepath is empty after open","",testTrace.getTracepath() ); | |
145 | } | |
146 | catch( JniException e) { | |
147 | fail("Open with a correct tracepath failed!"); | |
148 | } | |
149 | ||
150 | // Test to open a trace already opened | |
151 | try { | |
152 | testTrace.openTrace(tracepath1); | |
153 | testTrace.openTrace(tracepath2); | |
154 | assertNotSame("getTracepath is empty after open","",testTrace.getTracepath() ); | |
155 | } | |
156 | catch( JniException e) { | |
157 | fail("Reopen of a trace failed!"); | |
158 | } | |
159 | ||
160 | ||
161 | // Test to open a trace already opened, but with a wrong tracepath | |
162 | try { | |
163 | testTrace.openTrace(tracepath1); | |
164 | testTrace.openTrace(wrongTracePath); | |
165 | fail("Reopen with wrong tracepath should fail!"); | |
166 | } | |
167 | catch( JniException e) { | |
168 | } | |
169 | } | |
170 | ||
171 | public void testGetSet() { | |
172 | ||
173 | JniTrace testTrace = prepareTraceToTest(); | |
174 | ||
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() ); | |
1d1ae093 | 189 | assertNotSame("getEndTime() is null", null, testTrace.getEndTime() ); |
03c71d1e ASL |
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() ); | |
195 | ||
196 | ||
197 | } | |
198 | ||
199 | public void testPrintAndToString() { | |
200 | ||
201 | JniTrace testTrace = prepareTraceToTest(); | |
202 | ||
203 | // Test printTraceInformation | |
204 | try { | |
205 | testTrace.printTraceInformation(); | |
206 | } | |
207 | catch( Exception e) { | |
208 | fail("printTraceInformation failed!"); | |
209 | } | |
210 | ||
211 | // Test ToString() | |
212 | assertNotSame("toString returned empty data","",testTrace.toString() ); | |
213 | } | |
214 | ||
215 | public void testRequestFunctions() { | |
216 | ||
217 | JniTrace testTrace = prepareTraceToTest(); | |
218 | ||
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) ); | |
222 | ||
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) ); | |
226 | } | |
227 | ||
228 | public void testEventDisplacement() { | |
229 | ||
230 | JniEvent testEvent = null; | |
231 | JniTrace testTrace = prepareTraceToTest(); | |
232 | ||
233 | // Test readNextEvent() | |
234 | testEvent = testTrace.readNextEvent(); | |
235 | assertNotSame("readNextEvent() returned null",null,testEvent); | |
236 | assertEquals("readNextEvent() timestamp is incoherent",firstEventTimestamp,testEvent.getEventTime().getTime() ); | |
237 | ||
238 | // Test findNextEvent() | |
239 | testEvent = testTrace.findNextEvent(); | |
240 | assertNotSame("findNextEvent() returned null",null,testEvent); | |
241 | assertEquals("findNextEvent() name is incoherent",secondEventName,testEvent.getParentTracefile().getTracefileName() ); | |
242 | ||
243 | // Test readNextEvent() | |
244 | testEvent = testTrace.readNextEvent(); | |
245 | assertNotSame("readNextEvent() returned null",null,testEvent); | |
246 | assertEquals("readNextEvent() timestamp is incoherent",secondEventName,testEvent.getParentTracefile().getTracefileName() ); | |
247 | ||
248 | // Tests below are for seekAndRead() | |
249 | // After, we will perform the same operation for seekTime | |
250 | // | |
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()); | |
259 | ||
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()); | |
268 | ||
269 | ||
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); | |
278 | ||
279 | ||
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()); | |
284 | ||
285 | ||
286 | ||
287 | // Tests below are for seekToTime() | |
288 | // These are the same test as seekAndRead() for a readNextEvent() should be performed after seek | |
289 | // | |
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()); | |
299 | ||
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()); | |
309 | ||
310 | ||
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); | |
320 | ||
321 | ||
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()); | |
327 | } | |
328 | ||
329 | public void testEventDisplacementByTracefile() { | |
330 | ||
331 | JniEvent testEvent = null; | |
332 | JniTrace testTrace = prepareTraceToTest(); | |
333 | ||
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() ); | |
338 | ||
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() ); | |
343 | ||
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()); | |
349 | ||
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() ); | |
354 | ||
355 | ||
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() ); | |
362 | ||
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() ); | |
367 | ||
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()); | |
378 | ||
379 | } | |
380 | } |