Monster fix: TMF model update + corresponding LTTng adaptations + JUnits
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / jni / JniTracefileTest.java
1
2 package org.eclipse.linuxtools.lttng.jni;
3
4 import junit.framework.TestCase;
5
6 /*
7 Functions tested here :
8 public JniTracefile(JniTracefile oldTracefile)
9 public JniTracefile(long newPtr) throws JniException
10
11 public int readNextEvent()
12 public int seekToTime(JniTime seekTime)
13
14 public Location requestTracefileLocation()
15
16 public boolean getIsCpuOnline()
17 public String getTracefilePath()
18 public String getTracefileName()
19 public long getCpuNumber()
20 public long getTid()
21 public long getPgid()
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()
44
45 public String toString()
46 public void printTracefileInformation()
47 */
48
49 public class JniTracefileTest extends TestCase
50 {
51 private final static boolean printLttDebug = false;
52
53 private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu";
54 private final static String tracefileName1="kernel0";
55
56 private final static int numberOfMarkersInTracefile = 46;
57
58 private final static long firstEventTimestamp = 952090116049L;
59 private final static long secondEventTimestamp = 952092222957L;
60 private final static long thirdEventTimestamp = 952102730748L;
61
62 private final static long timestampToSeekTest1 = 953852206193L;
63 private final static long timestampAfterSeekTest1 = 953852212349L;
64
65 private final static long timestampToSeekLast = 960386638531L;
66
67
68 private JniTracefile prepareTracefileToTest() {
69
70 JniTracefile tmpTracefile = null;
71
72 // This trace should be valid
73 try {
74 tmpTracefile = new JniTrace(tracepath1, printLttDebug).requestTracefileByName(tracefileName1);
75
76 }
77 catch( JniException e) { }
78
79 return tmpTracefile;
80 }
81
82
83 public void testTracefileConstructors() {
84 JniTrace testTrace = null;
85 JniTracefile testTracefile1 = null;
86 JniTracefile testTracefile2 = null;
87
88 // This trace should be valid and will be used in test
89 try {
90 testTrace = new JniTrace(tracepath1, printLttDebug);
91 }
92 catch( JniException e) { }
93
94
95 // Test constructor with pointer on a wrong pointer
96 try {
97 testTracefile1 = new JniTracefile( new Jni_C_Pointer(0), testTrace );
98 fail("Construction with wrong pointer should fail!");
99 }
100 catch( JniException e) {
101 }
102
103 // Test constructor with pointer on a correct pointer
104 try {
105 testTracefile1 = new JniTracefile( testTrace.requestEventByName(tracefileName1).getTracefilePtr(), testTrace );
106 }
107 catch( JniException e) {
108 fail("Construction with correct pointer failed!");
109 }
110
111
112 // Test copy constructor
113 try {
114 testTracefile1 = new JniTracefile( testTrace.requestEventByName(tracefileName1).getTracefilePtr(), testTrace );
115 testTracefile2 = new JniTracefile( testTracefile1);
116 }
117 catch( JniException e) {
118 fail("Copy constructor failed!");
119 }
120
121 assertSame("JniTracefile name not same after using copy constructor", testTracefile1.getTracefileName() , testTracefile2.getTracefileName());
122
123 }
124
125 public void testGetSet() {
126
127 JniTracefile testTracefile = prepareTracefileToTest();
128
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() );
154
155 assertNotSame("getBufferPtr is 0",0,testTracefile.getBufferPtr() );
156 assertNotSame("getBufferSize is 0",0,testTracefile.getBufferSize() );
157
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() );
161
162 assertNotSame("getParentTrace is null",null,testTracefile.getParentTrace() );
163
164 assertNotSame("getTracefilePtr is 0",0,testTracefile.getTracefilePtr() );
165
166 }
167
168 public void testPrintAndToString() {
169
170 JniTracefile testTracefile = prepareTracefileToTest();
171
172 // Test printTraceInformation
173 try {
174 testTracefile.printTracefileInformation();
175 }
176 catch( Exception e) {
177 fail("printTraceInformation failed!");
178 }
179
180 // Test ToString()
181 assertNotSame("toString returned empty data","",testTracefile.toString() );
182
183 }
184
185 public void testEventDisplacement() {
186
187 int readValue = -1;
188 int seekValue = -1;
189 JniTracefile testTracefile = prepareTracefileToTest();
190
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() );
195
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() );
200
201
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() );
207
208 readValue = testTracefile.readNextEvent();
209 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampAfterSeekTest1,testTracefile.getCurrentEvent().getEventTime().getTime() );
210
211
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() );
217
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);
221
222
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() );
228
229 }
230 }
This page took 0.034636 seconds and 5 git commands to generate.