2 package org
.eclipse
.linuxtools
.lttng
.jni
;
4 import junit
.framework
.TestCase
;
7 Functions tested here :
8 public JniTracefile(JniTracefile oldTracefile)
9 public JniTracefile(long newPtr) throws JniException
11 public int readNextEvent()
12 public int seekToTime(JniTime seekTime)
14 public Location requestTracefileLocation()
16 public boolean getIsCpuOnline()
17 public String getTracefilePath()
18 public String getTracefileName()
19 public long getCpuNumber()
22 public long getCreation()
23 public long getTracePtr()
24 public long getMarkerDataPtr()
25 public int getCFileDescriptor()
26 public long getFileSize()
27 public long getBlocksNumber()
28 public boolean getIsBytesOrderReversed()
29 public boolean getIsFloatWordOrdered()
30 public long getAlignement()
31 public long getBufferHeaderSize()
32 public int getBitsOfCurrentTimestampCounter()
33 public int getBitsOfEvent()
34 public long getCurrentTimestampCounterMask()
35 public long getCurrentTimestampCounterMaskNextBit()
36 public long getEventsLost()
37 public long getSubBufferCorrupt()
38 public JniEvent getCurrentEvent()
39 public long getBufferPtr()
40 public long getBufferSize()
41 public HashMap<Integer, JniMarker> getTracefileMarkersMap()
42 public JniTrace getParentTrace()
43 public long getTracefilePtr()
45 public String toString()
46 public void printTracefileInformation()
49 public class JniTracefileTest
extends TestCase
51 private final static boolean printLttDebug
= false;
53 private final static String tracepath1
="traceset/trace-618339events-1293lost-1cpu";
54 private final static String tracefileName1
="kernel0";
56 private final static int numberOfMarkersInTracefile
= 46;
58 private final static long firstEventTimestamp
= 952090116049L;
59 private final static long secondEventTimestamp
= 952092222957L;
60 private final static long thirdEventTimestamp
= 952102730748L;
62 private final static long timestampToSeekTest1
= 953852206193L;
63 private final static long timestampAfterSeekTest1
= 953852212349L;
65 private final static long timestampToSeekLast
= 960386638531L;
68 private JniTracefile
prepareTracefileToTest() {
70 JniTracefile tmpTracefile
= null;
72 // This trace should be valid
74 tmpTracefile
= new JniTrace(tracepath1
, printLttDebug
).requestTracefileByName(tracefileName1
);
77 catch( JniException e
) { }
83 public void testTracefileConstructors() {
84 JniTrace testTrace
= null;
85 JniTracefile testTracefile1
= null;
86 JniTracefile testTracefile2
= null;
88 // This trace should be valid and will be used in test
90 testTrace
= new JniTrace(tracepath1
, printLttDebug
);
92 catch( JniException e
) { }
95 // Test constructor with pointer on a wrong pointer
97 testTracefile1
= new JniTracefile( new Jni_C_Pointer(0), testTrace
);
98 fail("Construction with wrong pointer should fail!");
100 catch( JniException e
) {
103 // Test constructor with pointer on a correct pointer
105 testTracefile1
= new JniTracefile( testTrace
.requestEventByName(tracefileName1
).getTracefilePtr(), testTrace
);
107 catch( JniException e
) {
108 fail("Construction with correct pointer failed!");
112 // Test copy constructor
114 testTracefile1
= new JniTracefile( testTrace
.requestEventByName(tracefileName1
).getTracefilePtr(), testTrace
);
115 testTracefile2
= new JniTracefile( testTracefile1
);
117 catch( JniException e
) {
118 fail("Copy constructor failed!");
121 assertSame("JniTracefile name not same after using copy constructor", testTracefile1
.getTracefileName() , testTracefile2
.getTracefileName());
125 public void testGetSet() {
127 JniTracefile testTracefile
= prepareTracefileToTest();
129 // Test that all Get/Set return data
130 //boolean getIsCpuOnline will always be sane...
131 assertNotSame("getTracefilePath is empty","",testTracefile
.getTracefilePath() );
132 assertNotSame("getTracefileName is empty","",testTracefile
.getTracefileName() );
133 assertNotSame("getCpuNumber is 0",0,testTracefile
.getCpuNumber() );
134 assertNotSame("getTid is 0",0,testTracefile
.getTid() );
135 assertNotSame("getPgid is 0",0,testTracefile
.getPgid() );
136 assertNotSame("getCreation is 0",0,testTracefile
.getCreation() );
137 assertNotSame("getTracePtr is 0",0,testTracefile
.getTracePtr() );
138 assertNotSame("getMarkerDataPtr is 0",0,testTracefile
.getMarkerDataPtr() );
139 assertNotSame("getCFileDescriptor is 0",0,testTracefile
.getCFileDescriptor() );
140 assertNotSame("getFileSize is 0",0,testTracefile
.getFileSize() );
141 assertNotSame("getBlocksNumber is 0",0,testTracefile
.getBlocksNumber() );
142 //boolean getIsBytesOrderReversed will always be sane...
143 //boolean getIsFloatWordOrdered will always be sane...
144 assertNotSame("getAlignement is 0",0,testTracefile
.getAlignement() );
145 assertNotSame("getBufferHeaderSize is 0",0,testTracefile
.getBufferHeaderSize() );
146 assertNotSame("getBitsOfCurrentTimestampCounter is 0",0,testTracefile
.getBitsOfCurrentTimestampCounter() );
147 assertNotSame("getBitsOfEvent is 0",0,testTracefile
.getBitsOfEvent() );
148 assertNotSame("getCurrentTimestampCounterMask is 0",0,testTracefile
.getCurrentTimestampCounterMask() );
149 assertNotSame("getCurrentTimestampCounterMaskNextBit is 0",0,testTracefile
.getCurrentTimestampCounterMaskNextBit() );
150 assertNotSame("getEventsLost is 0",0,testTracefile
.getEventsLost() );
151 assertNotSame("getSubBufferCorrupt is 0",0,testTracefile
.getSubBufferCorrupt() );
152 // There should be at least 1 event, so it shouldn't be null
153 assertNotNull("getCurrentEvent returned null", testTracefile
.getCurrentEvent() );
155 assertNotSame("getBufferPtr is 0",0,testTracefile
.getBufferPtr() );
156 assertNotSame("getBufferSize is 0",0,testTracefile
.getBufferSize() );
158 assertNotSame("getTracefileMarkersMap is null",null,testTracefile
.getTracefileMarkersMap() );
159 // Also check that the map contain a certains number of data
160 assertSame("getTracefileMarkersMap returned an unexpected number of markers",numberOfMarkersInTracefile
,testTracefile
.getTracefileMarkersMap().size() );
162 assertNotSame("getParentTrace is null",null,testTracefile
.getParentTrace() );
164 assertNotSame("getTracefilePtr is 0",0,testTracefile
.getTracefilePtr() );
168 public void testPrintAndToString() {
170 JniTracefile testTracefile
= prepareTracefileToTest();
172 // Test printTraceInformation
174 testTracefile
.printTracefileInformation();
176 catch( Exception e
) {
177 fail("printTraceInformation failed!");
181 assertNotSame("toString returned empty data","",testTracefile
.toString() );
185 public void testEventDisplacement() {
189 JniTracefile testTracefile
= prepareTracefileToTest();
191 // Test #1 readNextEvent()
192 readValue
= testTracefile
.readNextEvent();
193 assertSame("readNextEvent() returned error (test #1)",0,readValue
);
194 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",secondEventTimestamp
,testTracefile
.getCurrentEvent().getEventTime().getTime() );
196 // Test #2 readNextEvent()
197 readValue
= testTracefile
.readNextEvent();
198 assertSame("readNextEvent() returned error (test #1)",0,readValue
);
199 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",thirdEventTimestamp
,testTracefile
.getCurrentEvent().getEventTime().getTime() );
202 // Test #1 of seekToTime()
203 seekValue
= testTracefile
.seekToTime(new JniTime(timestampToSeekTest1
) );
204 assertSame("seekToTime() returned error (test #1)",0,seekValue
);
205 // Read SHOULD NOT be performed after a seek!
206 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampToSeekTest1
,testTracefile
.getCurrentEvent().getEventTime().getTime() );
208 readValue
= testTracefile
.readNextEvent();
209 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampAfterSeekTest1
,testTracefile
.getCurrentEvent().getEventTime().getTime() );
212 // Test #2 of seekToTime()
213 seekValue
= testTracefile
.seekToTime(new JniTime(timestampToSeekLast
) );
214 assertSame("seekToTime() returned error (test #2)",0,seekValue
);
215 // Read SHOULD NOT be performed after a seek!
216 assertEquals("readNextEvent() event timestamp is incoherent (test #2)",timestampToSeekLast
,testTracefile
.getCurrentEvent().getEventTime().getTime() );
218 // Read AFTER the last event should bring an error
219 readValue
= testTracefile
.readNextEvent();
220 assertNotSame("readNextEvent() AFTER last event should return error (test #2)",0,readValue
);
223 // Test to see if we can seek back
224 seekValue
= testTracefile
.seekToTime(new JniTime(firstEventTimestamp
) );
225 assertSame("seekToTime() returned error (test seek back)",0,seekValue
);
226 // Read SHOULD NOT be performed after a seek!
227 assertEquals("readNextEvent() event timestamp is incoherent (test seek back)",firstEventTimestamp
,testTracefile
.getCurrentEvent().getEventTime().getTime() );