2 package org
.eclipse
.linuxtools
.lttng
.core
.tests
.jni
;
4 import junit
.framework
.TestCase
;
6 import org
.eclipse
.linuxtools
.lttng
.jni
.JniTrace
;
7 import org
.eclipse
.linuxtools
.lttng
.jni
.JniTracefile
;
8 import org
.eclipse
.linuxtools
.lttng
.jni
.common
.JniTime
;
9 import org
.eclipse
.linuxtools
.lttng
.jni
.exception
.JniException
;
10 import org
.eclipse
.linuxtools
.lttng
.jni
.factory
.JniTraceFactory
;
13 Functions tested here :
14 public JniTracefile(JniTracefile oldTracefile)
15 public JniTracefile(long newPtr) throws JniException
17 public int readNextEvent()
18 public int seekToTime(JniTime seekTime)
20 public Location requestTracefileLocation()
22 public boolean getIsCpuOnline()
23 public String getTracefilePath()
24 public String getTracefileName()
25 public long getCpuNumber()
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()
51 public String toString()
52 public void printTracefileInformation()
55 @SuppressWarnings("nls")
56 public class JniTracefileTest
extends TestCase
{
58 private final static boolean printLttDebug
= false;
60 private final static String tracepath1
= "traceset/trace-15316events_nolost_newformat";
61 private final static String tracefileName1
= "kernel0";
63 private final static int numberOfMarkersInTracefile
= 45;
65 private final static long firstEventTimestamp
= 13589760262237L;
66 private final static long secondEventTimestamp
= 13589762149621L;
67 private final static long thirdEventTimestamp
= 13589762917527L;
69 private final static long timestampToSeekTest1
= 13589807108560L;
70 private final static long timestampAfterSeekTest1
= 13589807116344L;
72 private final static long timestampToSeekLast
= 13589906758692L;
74 private JniTracefile
prepareTracefileToTest() {
76 JniTracefile tmpTracefile
= null;
78 // This trace should be valid
80 tmpTracefile
= JniTraceFactory
.getJniTrace(tracepath1
, null, printLttDebug
)
81 .requestTracefileByName(tracefileName1
);
83 } catch (JniException e
) {
89 public void testTracefileConstructors() {
90 JniTrace testTrace
= null;
92 // This trace should be valid and will be used in test
94 testTrace
= JniTraceFactory
.getJniTrace(tracepath1
, null, printLttDebug
);
95 } catch (JniException e
) {
96 fail("Could not get trace file");
99 // Test constructor with pointer on a correct pointer
101 testTrace
.allocateNewJniTracefile(testTrace
.requestEventByName(tracefileName1
)
102 .getTracefilePtr(), testTrace
);
103 } catch (JniException e
) {
104 fail("Construction with correct pointer failed!");
108 // Test copy constructor
110 testTracefile1 = new JniTracefile( testTrace.requestEventByName(tracefileName1).getTracefilePtr(), testTrace );
111 testTracefile2 = new JniTracefile( testTracefile1);
113 catch( JniException e) {
114 fail("Copy constructor failed!");
116 assertSame("JniTracefile name not same after using copy constructor", testTracefile1.getTracefileName() , testTracefile2.getTracefileName());
121 public void testGetSet() {
123 JniTracefile testTracefile
= prepareTracefileToTest();
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());
158 assertNotSame("getBufferPtr is 0", 0, testTracefile
.getBufferPtr());
159 assertNotSame("getBufferSize is 0", 0, testTracefile
.getBufferSize());
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());
167 assertNotSame("getParentTrace is null", null, testTracefile
.getParentTrace());
169 assertNotSame("getTracefilePtr is 0", 0, testTracefile
.getTracefilePtr());
173 public void testPrintAndToString() {
175 JniTracefile testTracefile
= prepareTracefileToTest();
177 // Test printTraceInformation
179 testTracefile
.printTracefileInformation();
180 } catch (Exception e
) {
181 fail("printTraceInformation failed!");
185 assertNotSame("toString returned empty data", "", testTracefile
.toString());
189 public void testEventDisplacement() {
193 JniTracefile testTracefile
= prepareTracefileToTest();
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()
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()
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()
217 readValue
= testTracefile
.readNextEvent();
218 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",
219 timestampAfterSeekTest1
, testTracefile
.getCurrentEvent().getEventTime()
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()
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,
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()