Commit | Line | Data |
---|---|---|
03c71d1e | 1 | |
6c13869b | 2 | package org.eclipse.linuxtools.lttng.core.tests.jni; |
03c71d1e | 3 | |
8b63111e WB |
4 | import junit.framework.TestCase; |
5 | ||
ce38c104 FC |
6 | import org.eclipse.linuxtools.internal.lttng.jni.common.JniTime; |
7 | import org.eclipse.linuxtools.internal.lttng.jni.exception.JniException; | |
03c71d1e ASL |
8 | import org.eclipse.linuxtools.lttng.jni.JniTrace; |
9 | import org.eclipse.linuxtools.lttng.jni.JniTracefile; | |
9c841e9c | 10 | import org.eclipse.linuxtools.lttng.jni.factory.JniTraceFactory; |
86de1b08 | 11 | |
03c71d1e ASL |
12 | /* |
13 | Functions tested here : | |
14 | public JniTracefile(JniTracefile oldTracefile) | |
15 | public JniTracefile(long newPtr) throws JniException | |
16 | ||
17 | public int readNextEvent() | |
18 | public int seekToTime(JniTime seekTime) | |
19 | ||
20 | public Location requestTracefileLocation() | |
21 | ||
22 | public boolean getIsCpuOnline() | |
23 | public String getTracefilePath() | |
24 | public String getTracefileName() | |
25 | public long getCpuNumber() | |
26 | public long getTid() | |
27 | public long getPgid() | |
28 | public long getCreation() | |
29 | public long getTracePtr() | |
30 | public long getMarkerDataPtr() | |
31 | public int getCFileDescriptor() | |
32 | public long getFileSize() | |
33 | public long getBlocksNumber() | |
34 | public boolean getIsBytesOrderReversed() | |
35 | public boolean getIsFloatWordOrdered() | |
36 | public long getAlignement() | |
37 | public long getBufferHeaderSize() | |
38 | public int getBitsOfCurrentTimestampCounter() | |
39 | public int getBitsOfEvent() | |
40 | public long getCurrentTimestampCounterMask() | |
41 | public long getCurrentTimestampCounterMaskNextBit() | |
42 | public long getEventsLost() | |
43 | public long getSubBufferCorrupt() | |
44 | public JniEvent getCurrentEvent() | |
45 | public long getBufferPtr() | |
46 | public long getBufferSize() | |
47 | public HashMap<Integer, JniMarker> getTracefileMarkersMap() | |
48 | public JniTrace getParentTrace() | |
49 | public long getTracefilePtr() | |
50 | ||
51 | public String toString() | |
52 | public void printTracefileInformation() | |
53 | */ | |
54 | ||
3b38ea61 | 55 | @SuppressWarnings("nls") |
f9a8715c FC |
56 | public class JniTracefileTest extends TestCase { |
57 | ||
58 | private final static boolean printLttDebug = false; | |
59 | ||
60 | private final static String tracepath1 = "traceset/trace-15316events_nolost_newformat"; | |
61 | private final static String tracefileName1 = "kernel0"; | |
62 | ||
63 | private final static int numberOfMarkersInTracefile = 45; | |
64 | ||
65 | private final static long firstEventTimestamp = 13589760262237L; | |
66 | private final static long secondEventTimestamp = 13589762149621L; | |
67 | private final static long thirdEventTimestamp = 13589762917527L; | |
68 | ||
69 | private final static long timestampToSeekTest1 = 13589807108560L; | |
70 | private final static long timestampAfterSeekTest1 = 13589807116344L; | |
71 | ||
72 | private final static long timestampToSeekLast = 13589906758692L; | |
73 | ||
74 | private JniTracefile prepareTracefileToTest() { | |
75 | ||
76 | JniTracefile tmpTracefile = null; | |
77 | ||
78 | // This trace should be valid | |
79 | try { | |
80 | tmpTracefile = JniTraceFactory.getJniTrace(tracepath1, null, printLttDebug) | |
81 | .requestTracefileByName(tracefileName1); | |
82 | ||
83 | } catch (JniException e) { | |
03c71d1e | 84 | } |
f9a8715c FC |
85 | |
86 | return tmpTracefile; | |
87 | } | |
88 | ||
89 | public void testTracefileConstructors() { | |
90 | JniTrace testTrace = null; | |
91 | ||
92 | // This trace should be valid and will be used in test | |
93 | try { | |
94 | testTrace = JniTraceFactory.getJniTrace(tracepath1, null, printLttDebug); | |
95 | } catch (JniException e) { | |
96 | fail("Could not get trace file"); | |
03c71d1e | 97 | } |
f9a8715c FC |
98 | |
99 | // Test constructor with pointer on a correct pointer | |
100 | try { | |
101 | testTrace.allocateNewJniTracefile(testTrace.requestEventByName(tracefileName1) | |
102 | .getTracefilePtr(), testTrace); | |
103 | } catch (JniException e) { | |
104 | fail("Construction with correct pointer failed!"); | |
03c71d1e | 105 | } |
f9a8715c FC |
106 | |
107 | /* | |
108 | // Test copy constructor | |
109 | try { | |
110 | testTracefile1 = new JniTracefile( testTrace.requestEventByName(tracefileName1).getTracefilePtr(), testTrace ); | |
111 | testTracefile2 = new JniTracefile( testTracefile1); | |
03c71d1e | 112 | } |
f9a8715c FC |
113 | catch( JniException e) { |
114 | fail("Copy constructor failed!"); | |
03c71d1e | 115 | } |
f9a8715c FC |
116 | assertSame("JniTracefile name not same after using copy constructor", testTracefile1.getTracefileName() , testTracefile2.getTracefileName()); |
117 | */ | |
118 | ||
119 | } | |
120 | ||
121 | public void testGetSet() { | |
122 | ||
123 | JniTracefile testTracefile = prepareTracefileToTest(); | |
124 | ||
125 | // Test that all Get/Set return data | |
126 | //boolean getIsCpuOnline will always be sane... | |
127 | assertNotSame("getIsCpuOnline() failed", null, testTracefile.getIsCpuOnline()); | |
128 | assertNotSame("getTracefilePath is empty", "", testTracefile.getTracefilePath()); | |
129 | assertNotSame("getTracefileName is empty", "", testTracefile.getTracefileName()); | |
130 | assertNotSame("getCpuNumber is 0", 0, testTracefile.getCpuNumber()); | |
131 | assertNotSame("getTid is 0", 0, testTracefile.getTid()); | |
132 | assertNotSame("getPgid is 0", 0, testTracefile.getPgid()); | |
133 | assertNotSame("getCreation is 0", 0, testTracefile.getCreation()); | |
134 | assertNotSame("getTracePtr is 0", 0, testTracefile.getTracePtr()); | |
135 | assertNotSame("getMarkerDataPtr is 0", 0, testTracefile.getMarkerDataPtr()); | |
136 | assertNotSame("getCFileDescriptor is 0", 0, testTracefile.getCFileDescriptor()); | |
137 | assertNotSame("getFileSize is 0", 0, testTracefile.getFileSize()); | |
138 | assertNotSame("getBlocksNumber is 0", 0, testTracefile.getBlocksNumber()); | |
139 | //boolean getIsBytesOrderReversed will always be sane... | |
140 | assertNotSame("getIsBytesOrderReversed() failed", null, | |
141 | testTracefile.getIsBytesOrderReversed()); | |
142 | //boolean getIsFloatWordOrdered will always be sane... | |
143 | assertNotSame("getIsFloatWordOrdered() failed", null, testTracefile.getIsFloatWordOrdered()); | |
144 | assertNotSame("getAlignement is 0", 0, testTracefile.getAlignement()); | |
145 | assertNotSame("getBufferHeaderSize is 0", 0, testTracefile.getBufferHeaderSize()); | |
146 | assertNotSame("getBitsOfCurrentTimestampCounter is 0", 0, | |
147 | testTracefile.getBitsOfCurrentTimestampCounter()); | |
148 | assertNotSame("getBitsOfEvent is 0", 0, testTracefile.getBitsOfEvent()); | |
149 | assertNotSame("getCurrentTimestampCounterMask is 0", 0, | |
150 | testTracefile.getCurrentTimestampCounterMask()); | |
151 | assertNotSame("getCurrentTimestampCounterMaskNextBit is 0", 0, | |
152 | testTracefile.getCurrentTimestampCounterMaskNextBit()); | |
153 | assertNotSame("getEventsLost is 0", 0, testTracefile.getEventsLost()); | |
154 | assertNotSame("getSubBufferCorrupt is 0", 0, testTracefile.getSubBufferCorrupt()); | |
155 | // There should be at least 1 event, so it shouldn't be null | |
156 | assertNotNull("getCurrentEvent returned null", testTracefile.getCurrentEvent()); | |
157 | ||
158 | assertNotSame("getBufferPtr is 0", 0, testTracefile.getBufferPtr()); | |
159 | assertNotSame("getBufferSize is 0", 0, testTracefile.getBufferSize()); | |
160 | ||
161 | assertNotSame("getTracefileMarkersMap is null", null, | |
162 | testTracefile.getTracefileMarkersMap()); | |
163 | // Also check that the map contain a certains number of data | |
164 | assertSame("getTracefileMarkersMap returned an unexpected number of markers", | |
165 | numberOfMarkersInTracefile, testTracefile.getTracefileMarkersMap().size()); | |
166 | ||
167 | assertNotSame("getParentTrace is null", null, testTracefile.getParentTrace()); | |
168 | ||
169 | assertNotSame("getTracefilePtr is 0", 0, testTracefile.getTracefilePtr()); | |
170 | ||
171 | } | |
172 | ||
173 | public void testPrintAndToString() { | |
174 | ||
175 | JniTracefile testTracefile = prepareTracefileToTest(); | |
176 | ||
177 | // Test printTraceInformation | |
178 | try { | |
179 | testTracefile.printTracefileInformation(); | |
180 | } catch (Exception e) { | |
181 | fail("printTraceInformation failed!"); | |
182 | } | |
183 | ||
184 | // Test ToString() | |
185 | assertNotSame("toString returned empty data", "", testTracefile.toString()); | |
186 | ||
187 | } | |
188 | ||
189 | public void testEventDisplacement() { | |
190 | ||
191 | int readValue = -1; | |
192 | int seekValue = -1; | |
193 | JniTracefile testTracefile = prepareTracefileToTest(); | |
194 | ||
195 | // Test #1 readNextEvent() | |
196 | readValue = testTracefile.readNextEvent(); | |
197 | assertSame("readNextEvent() returned error (test #1)", 0, readValue); | |
198 | assertEquals("readNextEvent() event timestamp is incoherent (test #1)", | |
199 | secondEventTimestamp, testTracefile.getCurrentEvent().getEventTime() | |
200 | .getTime()); | |
201 | ||
202 | // Test #2 readNextEvent() | |
203 | readValue = testTracefile.readNextEvent(); | |
204 | assertSame("readNextEvent() returned error (test #1)", 0, readValue); | |
205 | assertEquals("readNextEvent() event timestamp is incoherent (test #1)", | |
206 | thirdEventTimestamp, testTracefile.getCurrentEvent().getEventTime() | |
207 | .getTime()); | |
208 | ||
209 | // Test #1 of seekToTime() | |
210 | seekValue = testTracefile.seekToTime(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)", | |
214 | timestampToSeekTest1, testTracefile.getCurrentEvent().getEventTime() | |
215 | .getTime()); | |
216 | ||
217 | readValue = testTracefile.readNextEvent(); | |
218 | assertEquals("readNextEvent() event timestamp is incoherent (test #1)", | |
219 | timestampAfterSeekTest1, testTracefile.getCurrentEvent().getEventTime() | |
220 | .getTime()); | |
221 | ||
222 | // Test #2 of seekToTime() | |
223 | seekValue = testTracefile.seekToTime(new JniTime(timestampToSeekLast)); | |
224 | assertSame("seekToTime() returned error (test #2)", 0, seekValue); | |
225 | // Read SHOULD NOT be performed after a seek! | |
226 | assertEquals("readNextEvent() event timestamp is incoherent (test #2)", | |
227 | timestampToSeekLast, testTracefile.getCurrentEvent().getEventTime() | |
228 | .getTime()); | |
229 | ||
230 | // Read AFTER the last event should bring an error | |
231 | readValue = testTracefile.readNextEvent(); | |
232 | assertNotSame("readNextEvent() AFTER last event should return error (test #2)", 0, | |
233 | readValue); | |
234 | ||
235 | // Test to see if we can seek back | |
236 | seekValue = testTracefile.seekToTime(new JniTime(firstEventTimestamp)); | |
237 | assertSame("seekToTime() returned error (test seek back)", 0, seekValue); | |
238 | // Read SHOULD NOT be performed after a seek! | |
239 | assertEquals("readNextEvent() event timestamp is incoherent (test seek back)", | |
240 | firstEventTimestamp, testTracefile.getCurrentEvent().getEventTime() | |
241 | .getTime()); | |
242 | ||
243 | } | |
03c71d1e | 244 | } |