3 Functions tested here :
4 public JniEvent(JniEvent oldEvent)
5 public JniEvent(long newEventPtr, long newTracefilePtr, HashMap<Integer, JniMarker> newMarkersMap, JniTracefile newParentTracefile) throws JafException
7 public int readNextEvent()
8 public int seekToTime(JniTime seekTime)
9 public int seekOrFallBack(JniTime seekTime)
11 public JniMarker requestEventMarker()
12 public String requestEventSource()
13 public JniTime requestNextEventTime()
15 public ArrayList<ParsedContent> parse()
17 public int getEventMarkerId()
18 public JniTime getEventTime()
19 public long getEventDataSize()
20 public HashMap<Integer, JniMarker> getMarkersMap()
21 public long getTracefilePtr()
22 public long getEventPtr()
23 public int getEventState()
24 public JniTracefile getParentTracefile()
26 public String toString()
27 public void printEventInformation()
31 package org
.eclipse
.linuxtools
.lttng
.tests
.jni
;
34 import junit
.framework
.TestCase
;
36 import org
.eclipse
.linuxtools
.lttng
.jni
.JniEvent
;
37 import org
.eclipse
.linuxtools
.lttng
.jni
.JniTracefile
;
38 import org
.eclipse
.linuxtools
.lttng
.jni
.common
.JniTime
;
39 import org
.eclipse
.linuxtools
.lttng
.jni
.exception
.JniException
;
40 import org
.eclipse
.linuxtools
.lttng
.jni
.factory
.JniTraceFactory
;
42 @SuppressWarnings("nls")
43 public class JniEventTest
extends TestCase
45 private final static boolean printLttDebug
= false;
47 private final static String tracepath
="traceset/trace-15316events_nolost_newformat";
48 private final static String eventName
="kernel0";
50 private final static int numberOfMarkersInTracefile
= 45;
52 private final static int numberOfparsedFieldsFirstEvent
= 1;
53 private final static int numberOfparsedFieldsSecondEvent
= 3;
55 private final static int chosenPositionOfFieldsFirstEvent
= 1;
56 private final static int chosenPositionOfFieldsSecondEvent
= 0;
57 private final static int chosenPositionOfFieldsAfterSeekEvent
= 1;
59 private final static String chosenNameOfFieldsFirstEvent
= "string";
60 private final static String chosenNameOfFieldsSecondEvent
= "ip";
61 private final static String chosenNameOfFieldsThirdEvent
= "syscall_id";
63 private final static String contentOfFieldsFirstEvent
= "LTT state dump begin";
64 private final static String contentOfFieldsSecondEvent
= "0xc142176d";
65 private final static long contentOfFieldsThirdEvent
= 3L;
67 private final static int numberOfByteInContent
= 4;
69 private final static long firstEventTimestamp
= 13589760262237L;
70 private final static long secondEventTimestamp
= 13589762149621L;
71 private final static long thirdEventTimestamp
= 13589762917527L;
73 private final static long timestampToSeekTest1
= 13589807108560L;
74 private final static long timestampAfterSeekTest1
= 13589807116344L;
76 private final static long timestampToSeekLast
= 13589906758692L;
78 private final static long timestampToSeekTooFarAway
= Long
.MAX_VALUE
;
80 private JniEvent
prepareEventToTest() {
82 JniEvent tmpEvent
= null;
84 // This trace should be valid
86 tmpEvent
= JniTraceFactory
.getJniTrace(tracepath
, null, printLttDebug
).requestEventByName(eventName
);
88 catch( JniException e
) { }
94 public void testEventConstructors() {
95 JniTracefile testTracefile
= null;
97 @SuppressWarnings("unused")
98 JniEvent testEvent1
= null;
99 @SuppressWarnings("unused")
100 JniEvent testEvent2
= null;
102 // This trace should be valid and will be used in test
104 testTracefile
= JniTraceFactory
.getJniTrace(tracepath
, null, printLttDebug
).requestTracefileByName(eventName
);
106 catch( JniException e
) { }
109 // Test constructor on a wrong marker HashMap
111 testEvent1
= testTracefile
.allocateNewJniEvent( testTracefile
.getCurrentEvent().getEventPtr(), null, testTracefile
);
112 fail("Construction with wrong marker hashmap should fail!");
114 catch( JniException e
) {
117 // Test constructor on a wrong tracefile reference
119 testEvent1
= testTracefile
.allocateNewJniEvent( testTracefile
.getCurrentEvent().getEventPtr(), testTracefile
.getTracefileMarkersMap(), null );
120 fail("Construction with wrong tracefile reference should fail!");
122 catch( JniException e
) {
126 // Finally, test constructor with correct information
128 testEvent1
= testTracefile
.allocateNewJniEvent( testTracefile
.getCurrentEvent().getEventPtr(), testTracefile
.getTracefileMarkersMap(), testTracefile
);
130 catch( JniException e
) {
131 fail("Construction with correct information failed!");
135 // Test copy constructor
137 testEvent1 = new JniEvent( testTracefile.getCurrentEvent() );
138 testEvent2 = new JniEvent( testEvent1);
140 catch( Exception e) {
141 fail("Copy constructor failed!");
143 assertEquals("JniEvent timestamp not same after using copy constructor", testEvent1.getEventTime().getTime() , testEvent2.getEventTime().getTime() );
148 public void testPrintAndToString() {
150 JniEvent testEvent
= prepareEventToTest();
152 // Test printEventInformation
154 testEvent
.printEventInformation();
156 catch( Exception e
) {
157 fail("printEventInformation failed!");
161 assertNotSame("toString returned empty data","",testEvent
.toString() );
165 public void testEventDisplacement() {
169 JniEvent testEvent
= prepareEventToTest();
171 // Test #1 readNextEvent()
172 readValue
= testEvent
.readNextEvent();
173 assertSame("readNextEvent() returned error (test #1)",0,readValue
);
174 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",secondEventTimestamp
,testEvent
.getEventTime().getTime() );
176 // Test #2 readNextEvent()
177 readValue
= testEvent
.readNextEvent();
178 assertSame("readNextEvent() returned error (test #1)",0,readValue
);
179 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",thirdEventTimestamp
,testEvent
.getEventTime().getTime() );
182 // Test #1 of seekToTime()
183 seekValue
= testEvent
.seekToTime(new JniTime(timestampToSeekTest1
) );
184 assertSame("seekToTime() returned error (test #1)",0,seekValue
);
185 // Read SHOULD NOT be performed after a seek!
186 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampToSeekTest1
,testEvent
.getEventTime().getTime() );
188 readValue
= testEvent
.readNextEvent();
189 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampAfterSeekTest1
,testEvent
.getEventTime().getTime() );
192 // Test #2 of seekToTime()
193 seekValue
= testEvent
.seekToTime(new JniTime(timestampToSeekLast
) );
194 assertSame("seekToTime() returned error (test #2)",0,seekValue
);
195 // Read SHOULD NOT be performed after a seek!
196 assertEquals("readNextEvent() event timestamp is incoherent (test #2)",timestampToSeekLast
,testEvent
.getEventTime().getTime() );
198 // Read AFTER the last event should bring an error
199 readValue
= testEvent
.readNextEvent();
200 assertNotSame("readNextEvent() AFTER last event should return error (test #2)",0,readValue
);
203 // Test to see if we can seek back
204 seekValue
= testEvent
.seekToTime(new JniTime(firstEventTimestamp
) );
205 assertSame("seekToTime() returned error (test seek back)",0,seekValue
);
206 // Read SHOULD NOT be performed after a seek!
207 assertEquals("readNextEvent() event timestamp is incoherent (test seek back)",firstEventTimestamp
,testEvent
.getEventTime().getTime() );
210 // Test #1 of seekOrFallBack() (seek within range)
211 seekValue
= testEvent
.seekOrFallBack(new JniTime(timestampToSeekTest1
) );
212 assertSame("seekToTime() returned error (test #1)",0,seekValue
);
213 // Read SHOULD NOT be performed after a seek!
214 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampToSeekTest1
,testEvent
.getEventTime().getTime() );
216 // Test #2 of seekOrFallBack() (seek out of range, should fall back)
217 seekValue
= testEvent
.seekOrFallBack(new JniTime(timestampToSeekTooFarAway
) );
218 assertNotSame("seekOrFallBack() should return an error (test #2)",0,seekValue
);
219 // The read should return the "last" value as we seek back
220 assertEquals("readNextEvent() event timestamp is incoherent (test #2)",timestampToSeekTest1
,testEvent
.getEventTime().getTime() );
223 public void testGetSet() {
225 JniEvent testEvent
= prepareEventToTest();
227 // Test that all Get/Set return data
228 assertNotSame("getEventMarkerId is 0",0,testEvent
.getEventMarkerId() );
230 // JniTime should never be null
231 assertNotNull("getEventTime returned null", testEvent
.getEventTime() );
233 assertNotSame("getEventDataSize is 0",0,testEvent
.getEventDataSize() );
235 // Test that the marker map is not null
236 assertNotSame("getMarkersMap is null",null,testEvent
.getMarkersMap() );
237 // Also check that the map contain some data
238 assertSame("getMarkersMap returned an unexpected number of markers",numberOfMarkersInTracefile
,testEvent
.getMarkersMap().size() );
240 assertNotSame("getTracefilePtr is 0",0,testEvent
.getTracefilePtr() );
241 assertNotSame("getEventPtr is 0",0,testEvent
.getEventPtr() );
242 // State 0 (EOK) means the event is in a sane state
243 assertSame("getEventState is not EOK",0,testEvent
.getEventState() );
245 // ParentTracefile should never be null
246 assertNotNull("getParentTracefile returned null", testEvent
.getParentTracefile() );
249 public void testRequestFunctions() {
251 JniEvent testEvent
= prepareEventToTest();
253 // Test requestEventMarker(). Should return an unique marker
254 assertNotNull("requestEventMarker returned null",testEvent
.requestEventMarker() );
256 // Test requestEventSource()
257 assertNotSame("requestEventSource is empty","",testEvent
.requestEventSource() );
259 // Test requestEventContent()
260 assertNotNull("requestEventContent returned null",testEvent
.requestEventContent() );
262 // Also check that the byte array contain some data
263 assertSame("requestEventContent returned an unexpected number of markers",numberOfByteInContent
,testEvent
.requestEventContent().length
);
267 public void testParseAllFieldsFunctions() {
269 JniEvent testEvent
= prepareEventToTest();
272 assertNotNull("parseAllFields returned null",testEvent
.parseAllFields() );
273 // Parse shouldn't be empty
274 assertSame("parseAllFields returned an unexpected number of parsed fields",numberOfparsedFieldsFirstEvent
,testEvent
.parseAllFields().size() );
276 // MORE PARSING TESTS
277 // We will perform several more unit tests about parsing as it is very important
278 // All those below use the same call as in the displacement test
279 // Test #1 readNextEvent()
280 testEvent
.readNextEvent();
281 assertNotNull("parseAllFields returned null",testEvent
.parseAllFields() );
282 assertSame("parseAllFields returned an unexpected number of parsed fields",numberOfparsedFieldsSecondEvent
,testEvent
.parseAllFields().size() );
283 // Test #2 readNextEvent()
284 testEvent
.readNextEvent();
285 assertNotNull("parseAllFields returned null",testEvent
.parseAllFields() );
287 // Test #1 of seekToTime()
288 testEvent
.seekToTime(new JniTime(timestampToSeekTest1
) );
289 // Read need to be perform after a seek!
290 testEvent
.readNextEvent();
291 assertNotNull("parseAllFields returned null",testEvent
.parseAllFields() );
292 testEvent
.readNextEvent();
293 assertNotNull("parseAllFields returned null",testEvent
.parseAllFields() );
295 // Test #2 of seekToTime()
296 testEvent
.seekToTime(new JniTime(timestampToSeekLast
) );
297 // Read need to be perform after a seek!
298 testEvent
.readNextEvent();
299 assertNotNull("parseAllFields returned null",testEvent
.parseAllFields() );
301 // Test to see if we can seek back
302 testEvent
.seekToTime(new JniTime(firstEventTimestamp
) );
303 // Read need to be perform after a seek!
304 testEvent
.readNextEvent();
305 assertNotNull("parseAllFields returned null",testEvent
.parseAllFields() );
308 public void testParseFieldByIdFunctions() {
309 JniEvent testEvent
= prepareEventToTest();
312 assertNotNull("parseFieldById returned null",testEvent
.parseFieldById(0) );
314 testEvent
.readNextEvent();
315 assertNotNull("parseFieldById returned null",testEvent
.parseFieldById(chosenPositionOfFieldsFirstEvent
) );
316 assertEquals("Content return by parseFieldById is invalid",contentOfFieldsFirstEvent
, testEvent
.parseFieldById(chosenPositionOfFieldsFirstEvent
) );
317 assertEquals("Content return by parseFieldByName is invalid",contentOfFieldsFirstEvent
, testEvent
.parseFieldByName(chosenNameOfFieldsFirstEvent
) );
319 // MORE PARSING TESTS
320 // We will perform several more unit tests about parsing as it is very important
321 // All those below use the same call as in the displacement test
322 // Test #1 readNextEvent()
323 testEvent
.readNextEvent();
324 assertNotNull("parseFieldById returned null",testEvent
.parseFieldById(chosenPositionOfFieldsSecondEvent
) );
325 assertEquals("Content return by parseFieldById is invalid", contentOfFieldsSecondEvent
, testEvent
.parseFieldById(chosenPositionOfFieldsSecondEvent
).toString() );
326 assertEquals("Content return by parseFieldByName is invalid",contentOfFieldsSecondEvent
, testEvent
.parseFieldByName(chosenNameOfFieldsSecondEvent
).toString() );
328 // Test #1 of seekToTime()
329 testEvent
.seekToTime(new JniTime(timestampToSeekTest1
) );
330 // Read need to be perform after a seek!
331 testEvent
.readNextEvent();
332 assertNotNull("parseFieldById returned null",testEvent
.parseFieldById(chosenPositionOfFieldsAfterSeekEvent
) );
333 assertEquals("Content return by parseFieldById is invalid",contentOfFieldsThirdEvent
, testEvent
.parseFieldById(chosenPositionOfFieldsAfterSeekEvent
) );
334 assertEquals("Content return by parseFieldByName is invalid",contentOfFieldsThirdEvent
, testEvent
.parseFieldByName(chosenNameOfFieldsThirdEvent
) );
336 // Test to see if we can seek back
337 testEvent
.seekToTime(new JniTime(firstEventTimestamp
) );
338 // Read need to be perform after a seek!
339 testEvent
.readNextEvent();
340 assertNotNull("parseFieldById returned null",testEvent
.parseFieldById(chosenPositionOfFieldsFirstEvent
) );
341 assertEquals("Content return by parseFieldById is invalid",contentOfFieldsFirstEvent
, testEvent
.parseFieldById(chosenPositionOfFieldsFirstEvent
) );
342 assertEquals("Content return by parseFieldByName is invalid",contentOfFieldsFirstEvent
, testEvent
.parseFieldByName(chosenNameOfFieldsFirstEvent
) );