[156247] Preparation work for LTTng/TMF automated testing in Linux Tools build system.
[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 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;
9
10 import junit.framework.TestCase;
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 public class JniTracefileTest extends TestCase
56 {
57 private final static boolean printLttDebug = false;
58
59 private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu";
60 private final static String tracefileName1="kernel0";
61
62 private final static int numberOfMarkersInTracefile = 46;
63
64 private final static long firstEventTimestamp = 952090116049L;
65 private final static long secondEventTimestamp = 952092222957L;
66 private final static long thirdEventTimestamp = 952102730748L;
67
68 private final static long timestampToSeekTest1 = 953852206193L;
69 private final static long timestampAfterSeekTest1 = 953852212349L;
70
71 private final static long timestampToSeekLast = 960386638531L;
72
73
74 private JniTracefile prepareTracefileToTest() {
75
76 JniTracefile tmpTracefile = null;
77
78 // This trace should be valid
79 try {
80 tmpTracefile = new JniTrace(tracepath1, printLttDebug).requestTracefileByName(tracefileName1);
81
82 }
83 catch( JniException e) { }
84
85 return tmpTracefile;
86 }
87
88
89 public void testTracefileConstructors() {
90 JniTrace testTrace = null;
91 JniTracefile testTracefile1 = null;
92 JniTracefile testTracefile2 = null;
93
94 // This trace should be valid and will be used in test
95 try {
96 testTrace = new JniTrace(tracepath1, printLttDebug);
97 }
98 catch( JniException e) { }
99
100
101 // Test constructor with pointer on a wrong pointer
102 try {
103 testTracefile1 = new JniTracefile( new Jni_C_Pointer(0), testTrace );
104 fail("Construction with wrong pointer should fail!");
105 }
106 catch( JniException e) {
107 }
108
109 // Test constructor with pointer on a correct pointer
110 try {
111 testTracefile1 = new JniTracefile( testTrace.requestEventByName(tracefileName1).getTracefilePtr(), testTrace );
112 }
113 catch( JniException e) {
114 fail("Construction with correct pointer failed!");
115 }
116
117
118 // Test copy constructor
119 try {
120 testTracefile1 = new JniTracefile( testTrace.requestEventByName(tracefileName1).getTracefilePtr(), testTrace );
121 testTracefile2 = new JniTracefile( testTracefile1);
122 }
123 catch( JniException e) {
124 fail("Copy constructor failed!");
125 }
126
127 assertSame("JniTracefile name not same after using copy constructor", testTracefile1.getTracefileName() , testTracefile2.getTracefileName());
128
129 }
130
131 public void testGetSet() {
132
133 JniTracefile testTracefile = prepareTracefileToTest();
134
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() );
160
161 assertNotSame("getBufferPtr is 0",0,testTracefile.getBufferPtr() );
162 assertNotSame("getBufferSize is 0",0,testTracefile.getBufferSize() );
163
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() );
167
168 assertNotSame("getParentTrace is null",null,testTracefile.getParentTrace() );
169
170 assertNotSame("getTracefilePtr is 0",0,testTracefile.getTracefilePtr() );
171
172 }
173
174 public void testPrintAndToString() {
175
176 JniTracefile testTracefile = prepareTracefileToTest();
177
178 // Test printTraceInformation
179 try {
180 testTracefile.printTracefileInformation();
181 }
182 catch( Exception e) {
183 fail("printTraceInformation failed!");
184 }
185
186 // Test ToString()
187 assertNotSame("toString returned empty data","",testTracefile.toString() );
188
189 }
190
191 public void testEventDisplacement() {
192
193 int readValue = -1;
194 int seekValue = -1;
195 JniTracefile testTracefile = prepareTracefileToTest();
196
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() );
201
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() );
206
207
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() );
213
214 readValue = testTracefile.readNextEvent();
215 assertEquals("readNextEvent() event timestamp is incoherent (test #1)",timestampAfterSeekTest1,testTracefile.getCurrentEvent().getEventTime().getTime() );
216
217
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() );
223
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);
227
228
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() );
234
235 }
236 }
This page took 0.038623 seconds and 6 git commands to generate.