2 package org
.eclipse
.linuxtools
.lttng
.tests
.jni
;
4 import org
.eclipse
.linuxtools
.lttng
.jni
.JniException
;
5 import org
.eclipse
.linuxtools
.lttng
.jni
.JniTime
;
6 import org
.eclipse
.linuxtools
.lttng
.jni
.JniTrace
;
7 import org
.eclipse
.linuxtools
.lttng
.jni
.JniTracefile
;
8 import org
.eclipse
.linuxtools
.lttng
.jni
.Jni_C_Pointer
;
10 import junit
.framework
.TestCase
;
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 public class JniTracefileTest
extends TestCase
57 private final static boolean printLttDebug
= false;
59 private final static String tracepath1
="traceset/trace-618339events-1293lost-1cpu";
60 private final static String tracefileName1
="kernel0";
62 private final static int numberOfMarkersInTracefile
= 46;
64 private final static long firstEventTimestamp
= 952090116049L;
65 private final static long secondEventTimestamp
= 952092222957L;
66 private final static long thirdEventTimestamp
= 952102730748L;
68 private final static long timestampToSeekTest1
= 953852206193L;
69 private final static long timestampAfterSeekTest1
= 953852212349L;
71 private final static long timestampToSeekLast
= 960386638531L;
74 private JniTracefile
prepareTracefileToTest() {
76 JniTracefile tmpTracefile
= null;
78 // This trace should be valid
80 tmpTracefile
= new JniTrace(tracepath1
, printLttDebug
).requestTracefileByName(tracefileName1
);
83 catch( JniException e
) { }
89 public void testTracefileConstructors() {
90 JniTrace testTrace
= null;
91 JniTracefile testTracefile1
= null;
92 JniTracefile testTracefile2
= null;
94 // This trace should be valid and will be used in test
96 testTrace
= new JniTrace(tracepath1
, printLttDebug
);
98 catch( JniException e
) { }
101 // Test constructor with pointer on a wrong pointer
103 testTracefile1
= new JniTracefile( new Jni_C_Pointer(0), testTrace
);
104 fail("Construction with wrong pointer should fail!");
106 catch( JniException e
) {
109 // Test constructor with pointer on a correct pointer
111 testTracefile1
= new JniTracefile( testTrace
.requestEventByName(tracefileName1
).getTracefilePtr(), testTrace
);
113 catch( JniException e
) {
114 fail("Construction with correct pointer failed!");
118 // Test copy constructor
120 testTracefile1
= new JniTracefile( testTrace
.requestEventByName(tracefileName1
).getTracefilePtr(), testTrace
);
121 testTracefile2
= new JniTracefile( testTracefile1
);
123 catch( JniException e
) {
124 fail("Copy constructor failed!");
127 assertSame("JniTracefile name not same after using copy constructor", testTracefile1
.getTracefileName() , testTracefile2
.getTracefileName());
131 public void testGetSet() {
133 JniTracefile testTracefile
= prepareTracefileToTest();
135 // Test that all Get/Set return data
136 //boolean getIsCpuOnline will always be sane...
137 assertNotSame("getTracefilePath is empty","",testTracefile
.getTracefilePath() );
138 assertNotSame("getTracefileName is empty","",testTracefile
.getTracefileName() );
139 assertNotSame("getCpuNumber is 0",0,testTracefile
.getCpuNumber() );
140 assertNotSame("getTid is 0",0,testTracefile
.getTid() );
141 assertNotSame("getPgid is 0",0,testTracefile
.getPgid() );
142 assertNotSame("getCreation is 0",0,testTracefile
.getCreation() );
143 assertNotSame("getTracePtr is 0",0,testTracefile
.getTracePtr() );
144 assertNotSame("getMarkerDataPtr is 0",0,testTracefile
.getMarkerDataPtr() );
145 assertNotSame("getCFileDescriptor is 0",0,testTracefile
.getCFileDescriptor() );
146 assertNotSame("getFileSize is 0",0,testTracefile
.getFileSize() );
147 assertNotSame("getBlocksNumber is 0",0,testTracefile
.getBlocksNumber() );
148 //boolean getIsBytesOrderReversed will always be sane...
149 //boolean getIsFloatWordOrdered will always be sane...
150 assertNotSame("getAlignement is 0",0,testTracefile
.getAlignement() );
151 assertNotSame("getBufferHeaderSize is 0",0,testTracefile
.getBufferHeaderSize() );
152 assertNotSame("getBitsOfCurrentTimestampCounter is 0",0,testTracefile
.getBitsOfCurrentTimestampCounter() );
153 assertNotSame("getBitsOfEvent is 0",0,testTracefile
.getBitsOfEvent() );
154 assertNotSame("getCurrentTimestampCounterMask is 0",0,testTracefile
.getCurrentTimestampCounterMask() );
155 assertNotSame("getCurrentTimestampCounterMaskNextBit is 0",0,testTracefile
.getCurrentTimestampCounterMaskNextBit() );
156 assertNotSame("getEventsLost is 0",0,testTracefile
.getEventsLost() );
157 assertNotSame("getSubBufferCorrupt is 0",0,testTracefile
.getSubBufferCorrupt() );
158 // There should be at least 1 event, so it shouldn't be null
159 assertNotNull("getCurrentEvent returned null", testTracefile
.getCurrentEvent() );
161 assertNotSame("getBufferPtr is 0",0,testTracefile
.getBufferPtr() );
162 assertNotSame("getBufferSize is 0",0,testTracefile
.getBufferSize() );
164 assertNotSame("getTracefileMarkersMap is null",null,testTracefile
.getTracefileMarkersMap() );
165 // Also check that the map contain a certains number of data
166 assertSame("getTracefileMarkersMap returned an unexpected number of markers",numberOfMarkersInTracefile
,testTracefile
.getTracefileMarkersMap().size() );
168 assertNotSame("getParentTrace is null",null,testTracefile
.getParentTrace() );
170 assertNotSame("getTracefilePtr is 0",0,testTracefile
.getTracefilePtr() );
174 public void testPrintAndToString() {
176 JniTracefile testTracefile
= prepareTracefileToTest();
178 // Test printTraceInformation
180 testTracefile
.printTracefileInformation();
182 catch( Exception e
) {
183 fail("printTraceInformation failed!");
187 assertNotSame("toString returned empty data","",testTracefile
.toString() );
191 public void testEventDisplacement() {
195 JniTracefile testTracefile
= prepareTracefileToTest();
197 // Test #1 readNextEvent()
198 readValue
= testTracefile
.readNextEvent();
199 assertSame("readNextEvent() returned error (test #1)",0,readValue
);
200 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",secondEventTimestamp
,testTracefile
.getCurrentEvent().getEventTime().getTime() );
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)",thirdEventTimestamp
,testTracefile
.getCurrentEvent().getEventTime().getTime() );
208 // Test #1 of seekToTime()
209 seekValue
= testTracefile
.seekToTime(new JniTime(timestampToSeekTest1
) );
210 assertSame("seekToTime() returned error (test #1)",0,seekValue
);
211 // Read SHOULD NOT be performed after a seek!
212 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampToSeekTest1
,testTracefile
.getCurrentEvent().getEventTime().getTime() );
214 readValue
= testTracefile
.readNextEvent();
215 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampAfterSeekTest1
,testTracefile
.getCurrentEvent().getEventTime().getTime() );
218 // Test #2 of seekToTime()
219 seekValue
= testTracefile
.seekToTime(new JniTime(timestampToSeekLast
) );
220 assertSame("seekToTime() returned error (test #2)",0,seekValue
);
221 // Read SHOULD NOT be performed after a seek!
222 assertEquals("readNextEvent() event timestamp is incoherent (test #2)",timestampToSeekLast
,testTracefile
.getCurrentEvent().getEventTime().getTime() );
224 // Read AFTER the last event should bring an error
225 readValue
= testTracefile
.readNextEvent();
226 assertNotSame("readNextEvent() AFTER last event should return error (test #2)",0,readValue
);
229 // Test to see if we can seek back
230 seekValue
= testTracefile
.seekToTime(new JniTime(firstEventTimestamp
) );
231 assertSame("seekToTime() returned error (test seek back)",0,seekValue
);
232 // Read SHOULD NOT be performed after a seek!
233 assertEquals("readNextEvent() event timestamp is incoherent (test seek back)",firstEventTimestamp
,testTracefile
.getCurrentEvent().getEventTime().getTime() );