Monster fix: TMF model update + corresponding LTTng adaptations + JUnits
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / jni / JniTraceTest.java
1
2 package org.eclipse.linuxtools.lttng.jni;
3
4 import junit.framework.TestCase;
5
6 /*
7 Functions tested here :
8 public JniTrace()
9 public JniTrace(JniTrace oldTrace)
10 public JniTrace(String newpath) throws JafException
11 public JniTrace(long newPtr) throws JafException
12
13 public void openTrace(String newPath) throws JafException
14 public void openTrace() throws JafException
15 public void closeTrace( ) throws JafException
16
17 public JniEvent readNextEvent()
18 public JniEvent findNextEvent()
19 public JniEvent seekAndRead(JniTime seekTime)
20 public void seekToTime(JniTime seekTime)
21
22 public JniTracefile requestTracefileByName(String tracefileName)
23 public JniEvent requestEventByName(String tracefileName)
24 public ArrayList<Location> requestTraceLocation()
25
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()
42
43 public void printAllTracefilesInformation()
44 public void printTraceInformation()
45
46 public String toString()
47 */
48
49
50 public class JniTraceTest extends TestCase
51 {
52 private final static boolean printLttDebug = false;
53
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";
57
58 private final static String correctTracefileName="kernel0";
59 private final static String wrongTracefileName="somethingThatDoesNotExists";
60
61 private final static int numberOfTracefilesInTrace = 18;
62
63 private final static long firstEventTimestamp = 952088954601L;
64 private final static String firstEventTracefilename = "metadata0";
65
66 private final static long secondEventTimestamp = 952088959952L;
67 private final static String secondEventName = "metadata";
68
69 private final static long thirdEventTimestamp = 952088965599L;
70
71 private final static long eventTimestampAfterMetadata = 952090116049L;
72 private final static String eventTracefilenameAfterMetadata = "kernel0";
73
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";
78
79 private final static long timestampToSeekTest2 = 953852210706L;
80 private final static String eventNameAfterSeekTest2 = "fs";
81 private final static String nextEventNameAfterSeekTest2 = "kernel";
82
83 private final static long timestampToSeekLast = 960386638531L;
84 private final static String eventNameAfterSeekLast = "kernel";
85
86
87 private JniTrace prepareTraceToTest() {
88 JniTrace tmpTrace = null;
89
90 // This trace should be valid
91 try {
92 tmpTrace = new JniTrace(tracepath1, printLttDebug);
93 }
94 catch( JniException e) { }
95
96 return tmpTrace;
97 }
98
99 public void testTraceConstructors() {
100 JniTrace testTrace1 = null;
101 @SuppressWarnings("unused")
102 JniTrace testTrace2 = null;
103
104 // Test constructor with argument on a wrong tracepath
105 try {
106 testTrace1 = new JniTrace(wrongTracePath, printLttDebug);
107 fail("Construction with wrong tracepath should fail!");
108 }
109 catch( JniException e) {
110 }
111
112 // Test constructor with argument on a correct tracepath
113 try {
114 testTrace1 = new JniTrace(tracepath1, printLttDebug);
115 }
116 catch( JniException e) {
117 fail("Construction with correct tracepath failed!");
118 }
119
120 // Test copy constructor that take a pointer with a good pointer
121 try {
122 testTrace1 = new JniTrace( new Jni_C_Pointer(0), printLttDebug);
123 fail("Construction with wrong pointer should fail!");
124 }
125 catch( JniException e) {
126 }
127
128 // Test copy constructor that take a pointer with a good pointer
129 try {
130 testTrace1 = new JniTrace(tracepath1, printLttDebug); // This trace should be valid
131 testTrace2 = new JniTrace( testTrace1.getTracePtr(), printLttDebug);
132 }
133 catch( JniException e) {
134 fail("Construction with correct pointer failed!");
135 }
136
137 }
138
139 public void testTraceOpenClose() {
140
141 JniTrace testTrace = prepareTraceToTest(); // This trace should be valid
142
143 // test the constructor with arguments passing a wrong tracepath
144 try {
145 testTrace.openTrace(wrongTracePath);
146 fail("Open with wrong tracepath should fail!");
147 }
148 catch( JniException e) { }
149
150 // Test open with a correct tracepath
151 try {
152 testTrace.openTrace(tracepath1);
153 assertNotSame("getTracepath is empty after open","",testTrace.getTracepath() );
154 }
155 catch( JniException e) {
156 fail("Open with a correct tracepath failed!");
157 }
158
159 // Test to open a trace already opened
160 try {
161 testTrace.openTrace(tracepath1);
162 testTrace.openTrace(tracepath2);
163 assertNotSame("getTracepath is empty after open","",testTrace.getTracepath() );
164 }
165 catch( JniException e) {
166 fail("Reopen of a trace failed!");
167 }
168
169
170 // Test to open a trace already opened, but with a wrong tracepath
171 try {
172 testTrace.openTrace(tracepath1);
173 testTrace.openTrace(wrongTracePath);
174 fail("Reopen with wrong tracepath should fail!");
175 }
176 catch( JniException e) {
177 }
178 }
179
180 public void testGetSet() {
181
182 JniTrace testTrace = prepareTraceToTest();
183
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() );
203
204
205 }
206
207 public void testPrintAndToString() {
208
209 JniTrace testTrace = prepareTraceToTest();
210
211 // Test printTraceInformation
212 try {
213 testTrace.printTraceInformation();
214 }
215 catch( Exception e) {
216 fail("printTraceInformation failed!");
217 }
218
219 // Test ToString()
220 assertNotSame("toString returned empty data","",testTrace.toString() );
221 }
222
223 public void testRequestFunctions() {
224
225 JniTrace testTrace = prepareTraceToTest();
226
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) );
230
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) );
234 }
235
236 public void testEventDisplacement() {
237
238 JniEvent testEvent = null;
239 JniTrace testTrace = prepareTraceToTest();
240
241 // Test readNextEvent()
242 testEvent = testTrace.readNextEvent();
243 assertNotSame("readNextEvent() returned null",null,testEvent);
244 assertEquals("readNextEvent() timestamp is incoherent",firstEventTimestamp,testEvent.getEventTime().getTime() );
245
246 // Test findNextEvent()
247 testEvent = testTrace.findNextEvent();
248 assertNotSame("findNextEvent() returned null",null,testEvent);
249 assertEquals("findNextEvent() name is incoherent",secondEventName,testEvent.getParentTracefile().getTracefileName() );
250
251 // Test readNextEvent()
252 testEvent = testTrace.readNextEvent();
253 assertNotSame("readNextEvent() returned null",null,testEvent);
254 assertEquals("readNextEvent() timestamp is incoherent",secondEventName,testEvent.getParentTracefile().getTracefileName() );
255
256 // Tests below are for seekAndRead()
257 // After, we will perform the same operation for seekTime
258 //
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());
267
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());
276
277
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);
286
287
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());
292
293
294
295 // Tests below are for seekToTime()
296 // These are the same test as seekAndRead() for a readNextEvent() should be performed after seek
297 //
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());
307
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());
317
318
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);
328
329
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());
335 }
336
337 public void testEventDisplacementByTracefile() {
338
339 JniEvent testEvent = null;
340 JniTrace testTrace = prepareTraceToTest();
341
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() );
346
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() );
351
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());
357
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() );
362
363
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() );
370
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() );
375
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());
386
387 }
388 }
This page took 0.040151 seconds and 5 git commands to generate.