Fix for Bug354541 - TraceLibPath handling + JUnits
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / jni / JniTracefileTest.java
1
2 package org.eclipse.linuxtools.lttng.tests.jni;
3
4 import junit.framework.TestCase;
5
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;
11
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
55 @SuppressWarnings("nls")
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
75 private JniTracefile prepareTracefileToTest() {
76
77 JniTracefile tmpTracefile = null;
78
79 // This trace should be valid
80 try {
81 tmpTracefile = JniTraceFactory.getJniTrace(tracepath1, null, printLttDebug).requestTracefileByName(tracefileName1);
82
83 }
84 catch( JniException e) { }
85
86 return tmpTracefile;
87 }
88
89
90 public void testTracefileConstructors() {
91 JniTrace testTrace = null;
92 @SuppressWarnings("unused")
93 JniTracefile testTracefile1 = null;
94 @SuppressWarnings("unused")
95 JniTracefile testTracefile2 = null;
96
97 // This trace should be valid and will be used in test
98 try {
99 testTrace = JniTraceFactory.getJniTrace(tracepath1, null, printLttDebug);
100 }
101 catch( JniException e) { }
102
103 // Test constructor with pointer on a correct pointer
104 try {
105 testTracefile1 = testTrace.allocateNewJniTracefile( 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 assertSame("JniTracefile name not same after using copy constructor", testTracefile1.getTracefileName() , testTracefile2.getTracefileName());
121 */
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("getIsCpuOnline() failed",null, testTracefile.getIsCpuOnline() );
132 assertNotSame("getTracefilePath is empty","",testTracefile.getTracefilePath() );
133 assertNotSame("getTracefileName is empty","",testTracefile.getTracefileName() );
134 assertNotSame("getCpuNumber is 0",0,testTracefile.getCpuNumber() );
135 assertNotSame("getTid is 0",0,testTracefile.getTid() );
136 assertNotSame("getPgid is 0",0,testTracefile.getPgid() );
137 assertNotSame("getCreation is 0",0,testTracefile.getCreation() );
138 assertNotSame("getTracePtr is 0",0,testTracefile.getTracePtr() );
139 assertNotSame("getMarkerDataPtr is 0",0,testTracefile.getMarkerDataPtr() );
140 assertNotSame("getCFileDescriptor is 0",0,testTracefile.getCFileDescriptor() );
141 assertNotSame("getFileSize is 0",0,testTracefile.getFileSize() );
142 assertNotSame("getBlocksNumber is 0",0,testTracefile.getBlocksNumber() );
143 //boolean getIsBytesOrderReversed will always be sane...
144 assertNotSame("getIsBytesOrderReversed() failed",null, testTracefile.getIsBytesOrderReversed() );
145 //boolean getIsFloatWordOrdered will always be sane...
146 assertNotSame("getIsFloatWordOrdered() failed",null, testTracefile.getIsFloatWordOrdered() );
147 assertNotSame("getAlignement is 0",0,testTracefile.getAlignement() );
148 assertNotSame("getBufferHeaderSize is 0",0,testTracefile.getBufferHeaderSize() );
149 assertNotSame("getBitsOfCurrentTimestampCounter is 0",0,testTracefile.getBitsOfCurrentTimestampCounter() );
150 assertNotSame("getBitsOfEvent is 0",0,testTracefile.getBitsOfEvent() );
151 assertNotSame("getCurrentTimestampCounterMask is 0",0,testTracefile.getCurrentTimestampCounterMask() );
152 assertNotSame("getCurrentTimestampCounterMaskNextBit is 0",0,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,testTracefile.getTracefileMarkersMap() );
162 // Also check that the map contain a certains number of data
163 assertSame("getTracefileMarkersMap returned an unexpected number of markers",numberOfMarkersInTracefile,testTracefile.getTracefileMarkersMap().size() );
164
165 assertNotSame("getParentTrace is null",null,testTracefile.getParentTrace() );
166
167 assertNotSame("getTracefilePtr is 0",0,testTracefile.getTracefilePtr() );
168
169 }
170
171 public void testPrintAndToString() {
172
173 JniTracefile testTracefile = prepareTracefileToTest();
174
175 // Test printTraceInformation
176 try {
177 testTracefile.printTracefileInformation();
178 }
179 catch( Exception e) {
180 fail("printTraceInformation failed!");
181 }
182
183 // Test ToString()
184 assertNotSame("toString returned empty data","",testTracefile.toString() );
185
186 }
187
188 public void testEventDisplacement() {
189
190 int readValue = -1;
191 int seekValue = -1;
192 JniTracefile testTracefile = prepareTracefileToTest();
193
194 // Test #1 readNextEvent()
195 readValue = testTracefile.readNextEvent();
196 assertSame("readNextEvent() returned error (test #1)",0,readValue);
197 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",secondEventTimestamp,testTracefile.getCurrentEvent().getEventTime().getTime() );
198
199 // Test #2 readNextEvent()
200 readValue = testTracefile.readNextEvent();
201 assertSame("readNextEvent() returned error (test #1)",0,readValue);
202 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",thirdEventTimestamp,testTracefile.getCurrentEvent().getEventTime().getTime() );
203
204
205 // Test #1 of seekToTime()
206 seekValue = testTracefile.seekToTime(new JniTime(timestampToSeekTest1) );
207 assertSame("seekToTime() returned error (test #1)",0,seekValue);
208 // Read SHOULD NOT be performed after a seek!
209 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampToSeekTest1,testTracefile.getCurrentEvent().getEventTime().getTime() );
210
211 readValue = testTracefile.readNextEvent();
212 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampAfterSeekTest1,testTracefile.getCurrentEvent().getEventTime().getTime() );
213
214
215 // Test #2 of seekToTime()
216 seekValue = testTracefile.seekToTime(new JniTime(timestampToSeekLast) );
217 assertSame("seekToTime() returned error (test #2)",0,seekValue);
218 // Read SHOULD NOT be performed after a seek!
219 assertEquals("readNextEvent() event timestamp is incoherent (test #2)",timestampToSeekLast,testTracefile.getCurrentEvent().getEventTime().getTime() );
220
221 // Read AFTER the last event should bring an error
222 readValue = testTracefile.readNextEvent();
223 assertNotSame("readNextEvent() AFTER last event should return error (test #2)",0,readValue);
224
225
226 // Test to see if we can seek back
227 seekValue = testTracefile.seekToTime(new JniTime(firstEventTimestamp) );
228 assertSame("seekToTime() returned error (test seek back)",0,seekValue);
229 // Read SHOULD NOT be performed after a seek!
230 assertEquals("readNextEvent() event timestamp is incoherent (test seek back)",firstEventTimestamp,testTracefile.getCurrentEvent().getEventTime().getTime() );
231
232 }
233 }
This page took 0.034355 seconds and 5 git commands to generate.