Commit | Line | Data |
---|---|---|
03c71d1e ASL |
1 | |
2 | /* | |
3 | Functions tested here : | |
4 | public JniEvent(JniEvent oldEvent) | |
5 | public JniEvent(long newEventPtr, long newTracefilePtr, HashMap<Integer, JniMarker> newMarkersMap, JniTracefile newParentTracefile) throws JafException | |
6 | ||
7 | public int readNextEvent() | |
8 | public int seekToTime(JniTime seekTime) | |
9 | public int seekOrFallBack(JniTime seekTime) | |
10 | ||
11 | public JniMarker requestEventMarker() | |
12 | public String requestEventSource() | |
13 | public JniTime requestNextEventTime() | |
14 | ||
15 | public ArrayList<ParsedContent> parse() | |
16 | ||
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() | |
25 | ||
26 | public String toString() | |
27 | public void printEventInformation() | |
28 | */ | |
29 | ||
30 | ||
31 | package org.eclipse.linuxtools.lttng.tests.jni; | |
32 | ||
33 | ||
34 | import junit.framework.TestCase; | |
35 | ||
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; | |
41 | ||
42 | public class JniEventTest extends TestCase | |
43 | { | |
44 | private final static boolean printLttDebug = false; | |
45 | ||
46 | private final static String tracepath="traceset/trace-15316events_nolost_newformat"; | |
47 | private final static String eventName="kernel0"; | |
48 | ||
49 | private final static int numberOfMarkersInTracefile = 45; | |
50 | ||
51 | private final static int numberOfparsedFieldsFirstEvent = 1; | |
52 | private final static int numberOfparsedFieldsSecondEvent = 3; | |
53 | ||
54 | private final static int chosenPositionOfFieldsFirstEvent = 1; | |
55 | private final static int chosenPositionOfFieldsSecondEvent = 0; | |
56 | private final static int chosenPositionOfFieldsAfterSeekEvent = 1; | |
57 | ||
58 | private final static String chosenNameOfFieldsFirstEvent = "string"; | |
59 | private final static String chosenNameOfFieldsSecondEvent = "ip"; | |
60 | private final static String chosenNameOfFieldsThirdEvent = "syscall_id"; | |
61 | ||
62 | private final static String contentOfFieldsFirstEvent = "LTT state dump begin"; | |
63 | private final static String contentOfFieldsSecondEvent = "0xc142176d"; | |
64 | private final static long contentOfFieldsThirdEvent = 3L; | |
65 | ||
66 | private final static int numberOfByteInContent = 4; | |
67 | ||
68 | private final static long firstEventTimestamp = 13589760262237L; | |
69 | private final static long secondEventTimestamp = 13589762149621L; | |
70 | private final static long thirdEventTimestamp = 13589762917527L; | |
71 | ||
72 | private final static long timestampToSeekTest1 = 13589807108560L; | |
73 | private final static long timestampAfterSeekTest1 = 13589807116344L; | |
74 | ||
75 | private final static long timestampToSeekLast = 13589906758692L; | |
76 | ||
77 | private final static long timestampToSeekTooFarAway = Long.MAX_VALUE; | |
78 | ||
79 | private JniEvent prepareEventToTest() { | |
80 | ||
81 | JniEvent tmpEvent = null; | |
82 | ||
83 | // This trace should be valid | |
84 | try { | |
85 | tmpEvent = JniTraceFactory.getJniTrace(tracepath, printLttDebug).requestEventByName(eventName); | |
86 | } | |
87 | catch( JniException e) { } | |
88 | ||
89 | return tmpEvent; | |
90 | } | |
91 | ||
92 | ||
93 | public void testEventConstructors() { | |
94 | JniTracefile testTracefile = null; | |
95 | ||
96 | @SuppressWarnings("unused") | |
97 | JniEvent testEvent1 = null; | |
98 | @SuppressWarnings("unused") | |
99 | JniEvent testEvent2 = null; | |
100 | ||
101 | // This trace should be valid and will be used in test | |
102 | try { | |
103 | testTracefile = JniTraceFactory.getJniTrace(tracepath, printLttDebug).requestTracefileByName(eventName); | |
104 | } | |
105 | catch( JniException e) { } | |
106 | ||
107 | ||
108 | // Test constructor on a wrong marker HashMap | |
109 | try { | |
110 | testEvent1 = testTracefile.allocateNewJniEvent( testTracefile.getCurrentEvent().getEventPtr(), null, testTracefile ); | |
111 | fail("Construction with wrong marker hashmap should fail!"); | |
112 | } | |
113 | catch( JniException e) { | |
114 | } | |
115 | ||
116 | // Test constructor on a wrong tracefile reference | |
117 | try { | |
118 | testEvent1 = testTracefile.allocateNewJniEvent( testTracefile.getCurrentEvent().getEventPtr(), testTracefile.getTracefileMarkersMap(), null ); | |
119 | fail("Construction with wrong tracefile reference should fail!"); | |
120 | } | |
121 | catch( JniException e) { | |
122 | } | |
123 | ||
124 | ||
125 | // Finally, test constructor with correct information | |
126 | try { | |
127 | testEvent1 = testTracefile.allocateNewJniEvent( testTracefile.getCurrentEvent().getEventPtr(), testTracefile.getTracefileMarkersMap(), testTracefile ); | |
128 | } | |
129 | catch( JniException e) { | |
130 | fail("Construction with correct information failed!"); | |
131 | } | |
132 | ||
133 | /* | |
134 | // Test copy constructor | |
135 | try { | |
136 | testEvent1 = new JniEvent( testTracefile.getCurrentEvent() ); | |
137 | testEvent2 = new JniEvent( testEvent1); | |
138 | } | |
139 | catch( Exception e) { | |
140 | fail("Copy constructor failed!"); | |
141 | } | |
142 | assertEquals("JniEvent timestamp not same after using copy constructor", testEvent1.getEventTime().getTime() , testEvent2.getEventTime().getTime() ); | |
143 | */ | |
144 | ||
145 | } | |
146 | ||
147 | public void testPrintAndToString() { | |
148 | ||
149 | JniEvent testEvent = prepareEventToTest(); | |
150 | ||
151 | // Test printEventInformation | |
152 | try { | |
153 | testEvent.printEventInformation(); | |
154 | } | |
155 | catch( Exception e) { | |
156 | fail("printEventInformation failed!"); | |
157 | } | |
158 | ||
159 | // Test ToString() | |
160 | assertNotSame("toString returned empty data","",testEvent.toString() ); | |
161 | ||
162 | } | |
163 | ||
164 | public void testEventDisplacement() { | |
165 | ||
166 | int readValue = -1; | |
167 | int seekValue = -1; | |
168 | JniEvent testEvent = prepareEventToTest(); | |
169 | ||
170 | // Test #1 readNextEvent() | |
171 | readValue = testEvent.readNextEvent(); | |
172 | assertSame("readNextEvent() returned error (test #1)",0,readValue); | |
173 | assertEquals("readNextEvent() event timestamp is incoherent (test #1)",secondEventTimestamp,testEvent.getEventTime().getTime() ); | |
174 | ||
175 | // Test #2 readNextEvent() | |
176 | readValue = testEvent.readNextEvent(); | |
177 | assertSame("readNextEvent() returned error (test #1)",0,readValue); | |
178 | assertEquals("readNextEvent() event timestamp is incoherent (test #1)",thirdEventTimestamp,testEvent.getEventTime().getTime() ); | |
179 | ||
180 | ||
181 | // Test #1 of seekToTime() | |
182 | seekValue = testEvent.seekToTime(new JniTime(timestampToSeekTest1) ); | |
183 | assertSame("seekToTime() returned error (test #1)",0,seekValue); | |
184 | // Read SHOULD NOT be performed after a seek! | |
185 | assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampToSeekTest1,testEvent.getEventTime().getTime() ); | |
186 | ||
187 | readValue = testEvent.readNextEvent(); | |
188 | assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampAfterSeekTest1,testEvent.getEventTime().getTime() ); | |
189 | ||
190 | ||
191 | // Test #2 of seekToTime() | |
192 | seekValue = testEvent.seekToTime(new JniTime(timestampToSeekLast) ); | |
193 | assertSame("seekToTime() returned error (test #2)",0,seekValue); | |
194 | // Read SHOULD NOT be performed after a seek! | |
195 | assertEquals("readNextEvent() event timestamp is incoherent (test #2)",timestampToSeekLast,testEvent.getEventTime().getTime() ); | |
196 | ||
197 | // Read AFTER the last event should bring an error | |
198 | readValue = testEvent.readNextEvent(); | |
199 | assertNotSame("readNextEvent() AFTER last event should return error (test #2)",0,readValue); | |
200 | ||
201 | ||
202 | // Test to see if we can seek back | |
203 | seekValue = testEvent.seekToTime(new JniTime(firstEventTimestamp) ); | |
204 | assertSame("seekToTime() returned error (test seek back)",0,seekValue); | |
205 | // Read SHOULD NOT be performed after a seek! | |
206 | assertEquals("readNextEvent() event timestamp is incoherent (test seek back)",firstEventTimestamp,testEvent.getEventTime().getTime() ); | |
207 | ||
208 | ||
209 | // Test #1 of seekOrFallBack() (seek within range) | |
210 | seekValue = testEvent.seekOrFallBack(new JniTime(timestampToSeekTest1) ); | |
211 | assertSame("seekToTime() returned error (test #1)",0,seekValue); | |
212 | // Read SHOULD NOT be performed after a seek! | |
213 | assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampToSeekTest1,testEvent.getEventTime().getTime() ); | |
214 | ||
215 | // Test #2 of seekOrFallBack() (seek out of range, should fall back) | |
216 | seekValue = testEvent.seekOrFallBack(new JniTime(timestampToSeekTooFarAway) ); | |
217 | assertNotSame("seekOrFallBack() should return an error (test #2)",0,seekValue); | |
218 | // The read should return the "last" value as we seek back | |
219 | assertEquals("readNextEvent() event timestamp is incoherent (test #2)",timestampToSeekTest1,testEvent.getEventTime().getTime() ); | |
220 | } | |
221 | ||
222 | public void testGetSet() { | |
223 | ||
224 | JniEvent testEvent = prepareEventToTest(); | |
225 | ||
226 | // Test that all Get/Set return data | |
227 | assertNotSame("getEventMarkerId is 0",0,testEvent.getEventMarkerId() ); | |
228 | ||
229 | // JniTime should never be null | |
230 | assertNotNull("getEventTime returned null", testEvent.getEventTime() ); | |
231 | ||
232 | assertNotSame("getEventDataSize is 0",0,testEvent.getEventDataSize() ); | |
233 | ||
234 | // Test that the marker map is not null | |
235 | assertNotSame("getMarkersMap is null",null,testEvent.getMarkersMap() ); | |
236 | // Also check that the map contain some data | |
237 | assertSame("getMarkersMap returned an unexpected number of markers",numberOfMarkersInTracefile,testEvent.getMarkersMap().size() ); | |
238 | ||
239 | assertNotSame("getTracefilePtr is 0",0,testEvent.getTracefilePtr() ); | |
240 | assertNotSame("getEventPtr is 0",0,testEvent.getEventPtr() ); | |
241 | // State 0 (EOK) means the event is in a sane state | |
242 | assertSame("getEventState is not EOK",0,testEvent.getEventState() ); | |
243 | ||
244 | // ParentTracefile should never be null | |
245 | assertNotNull("getParentTracefile returned null", testEvent.getParentTracefile() ); | |
246 | } | |
247 | ||
248 | public void testRequestFunctions() { | |
249 | ||
250 | JniEvent testEvent = prepareEventToTest(); | |
251 | ||
252 | // Test requestEventMarker(). Should return an unique marker | |
253 | assertNotNull("requestEventMarker returned null",testEvent.requestEventMarker() ); | |
254 | ||
255 | // Test requestEventSource() | |
256 | assertNotSame("requestEventSource is empty","",testEvent.requestEventSource() ); | |
257 | ||
258 | // Test requestEventContent() | |
259 | assertNotNull("requestEventContent returned null",testEvent.requestEventContent() ); | |
260 | ||
261 | // Also check that the byte array contain some data | |
262 | assertSame("requestEventContent returned an unexpected number of markers",numberOfByteInContent,testEvent.requestEventContent().length ); | |
263 | ||
264 | } | |
265 | ||
266 | public void testParseAllFieldsFunctions() { | |
267 | ||
268 | JniEvent testEvent = prepareEventToTest(); | |
269 | ||
270 | // Test parse() | |
271 | assertNotNull("parseAllFields returned null",testEvent.parseAllFields() ); | |
272 | // Parse shouldn't be empty | |
273 | assertSame("parseAllFields returned an unexpected number of parsed fields",numberOfparsedFieldsFirstEvent,testEvent.parseAllFields().size() ); | |
274 | ||
275 | // MORE PARSING TESTS | |
276 | // We will perform several more unit tests about parsing as it is very important | |
277 | // All those below use the same call as in the displacement test | |
278 | // Test #1 readNextEvent() | |
279 | testEvent.readNextEvent(); | |
280 | assertNotNull("parseAllFields returned null",testEvent.parseAllFields() ); | |
281 | assertSame("parseAllFields returned an unexpected number of parsed fields",numberOfparsedFieldsSecondEvent,testEvent.parseAllFields().size() ); | |
282 | // Test #2 readNextEvent() | |
283 | testEvent.readNextEvent(); | |
284 | assertNotNull("parseAllFields returned null",testEvent.parseAllFields() ); | |
285 | ||
286 | // Test #1 of seekToTime() | |
287 | testEvent.seekToTime(new JniTime(timestampToSeekTest1) ); | |
288 | // Read need to be perform after a seek! | |
289 | testEvent.readNextEvent(); | |
290 | assertNotNull("parseAllFields returned null",testEvent.parseAllFields() ); | |
291 | testEvent.readNextEvent(); | |
292 | assertNotNull("parseAllFields returned null",testEvent.parseAllFields() ); | |
293 | ||
294 | // Test #2 of seekToTime() | |
295 | testEvent.seekToTime(new JniTime(timestampToSeekLast) ); | |
296 | // Read need to be perform after a seek! | |
297 | testEvent.readNextEvent(); | |
298 | assertNotNull("parseAllFields returned null",testEvent.parseAllFields() ); | |
299 | ||
300 | // Test to see if we can seek back | |
301 | testEvent.seekToTime(new JniTime(firstEventTimestamp) ); | |
302 | // Read need to be perform after a seek! | |
303 | testEvent.readNextEvent(); | |
304 | assertNotNull("parseAllFields returned null",testEvent.parseAllFields() ); | |
305 | } | |
306 | ||
307 | public void testParseFieldByIdFunctions() { | |
308 | JniEvent testEvent = prepareEventToTest(); | |
309 | ||
310 | // Test parse() | |
311 | assertNotNull("parseFieldById returned null",testEvent.parseFieldById(0) ); | |
312 | ||
313 | testEvent.readNextEvent(); | |
314 | assertNotNull("parseFieldById returned null",testEvent.parseFieldById(chosenPositionOfFieldsFirstEvent) ); | |
315 | assertEquals("Content return by parseFieldById is invalid",contentOfFieldsFirstEvent, testEvent.parseFieldById(chosenPositionOfFieldsFirstEvent) ); | |
316 | assertEquals("Content return by parseFieldByName is invalid",contentOfFieldsFirstEvent, testEvent.parseFieldByName(chosenNameOfFieldsFirstEvent) ); | |
317 | ||
318 | // MORE PARSING TESTS | |
319 | // We will perform several more unit tests about parsing as it is very important | |
320 | // All those below use the same call as in the displacement test | |
321 | // Test #1 readNextEvent() | |
322 | testEvent.readNextEvent(); | |
323 | assertNotNull("parseFieldById returned null",testEvent.parseFieldById(chosenPositionOfFieldsSecondEvent) ); | |
324 | assertEquals("Content return by parseFieldById is invalid", contentOfFieldsSecondEvent, testEvent.parseFieldById(chosenPositionOfFieldsSecondEvent).toString() ); | |
325 | assertEquals("Content return by parseFieldByName is invalid",contentOfFieldsSecondEvent, testEvent.parseFieldByName(chosenNameOfFieldsSecondEvent).toString() ); | |
326 | ||
327 | // Test #1 of seekToTime() | |
328 | testEvent.seekToTime(new JniTime(timestampToSeekTest1) ); | |
329 | // Read need to be perform after a seek! | |
330 | testEvent.readNextEvent(); | |
331 | assertNotNull("parseFieldById returned null",testEvent.parseFieldById(chosenPositionOfFieldsAfterSeekEvent) ); | |
332 | assertEquals("Content return by parseFieldById is invalid",contentOfFieldsThirdEvent, testEvent.parseFieldById(chosenPositionOfFieldsAfterSeekEvent) ); | |
333 | assertEquals("Content return by parseFieldByName is invalid",contentOfFieldsThirdEvent, testEvent.parseFieldByName(chosenNameOfFieldsThirdEvent) ); | |
334 | ||
335 | // Test to see if we can seek back | |
336 | testEvent.seekToTime(new JniTime(firstEventTimestamp) ); | |
337 | // Read need to be perform after a seek! | |
338 | testEvent.readNextEvent(); | |
339 | assertNotNull("parseFieldById returned null",testEvent.parseFieldById(chosenPositionOfFieldsFirstEvent) ); | |
340 | assertEquals("Content return by parseFieldById is invalid",contentOfFieldsFirstEvent, testEvent.parseFieldById(chosenPositionOfFieldsFirstEvent) ); | |
341 | assertEquals("Content return by parseFieldByName is invalid",contentOfFieldsFirstEvent, testEvent.parseFieldByName(chosenNameOfFieldsFirstEvent) ); | |
342 | } | |
343 | } |