1 package org
.eclipse
.linuxtools
.lttng
.tests
.trace
;
6 import junit
.framework
.TestCase
;
8 import org
.eclipse
.core
.runtime
.FileLocator
;
9 import org
.eclipse
.core
.runtime
.Path
;
10 import org
.eclipse
.linuxtools
.lttng
.tests
.LTTngCoreTestPlugin
;
11 import org
.eclipse
.linuxtools
.lttng
.trace
.LTTngTextTrace
;
12 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
13 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
14 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
15 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfLocation
;
18 Functions tested here :
19 public LTTngTextTrace(String path) throws Exception
20 public LTTngTextTrace(String path, boolean skipIndexing) throws Exception
22 public TmfTraceContext seekLocation(Object location) {
23 public TmfTraceContext seekEvent(TmfTimestamp timestamp) {
24 public TmfTraceContext seekEvent(long position) {
26 public TmfEvent getNextEvent(TmfTraceContext context) {
27 public Object getCurrentLocation() {
29 public LttngEvent parseEvent(TmfTraceContext context) {
31 public int getCpuNumber() {
34 public class LTTngTextTraceTest
extends TestCase
{
36 private final static String tracepath1
="traceset/trace-15316events_nolost_newformat.txt";
37 private final static String wrongTracePath
="/somewhere/that/does/not/exist";
39 private final static int traceCpuNumber
=1;
41 private final static boolean skipIndexing
=true;
43 private final static long firstEventTimestamp
= 13589759412128L;
44 private final static long secondEventTimestamp
= 13589759419903L;
45 private final static Long locationAfterFirstEvent
= 311L;
47 private final static String tracename
= "traceset/trace-15316events_nolost_newformat";
49 private final static long indexToSeekFirst
= 0;
50 private final static Long locationToSeekFirst
= 0L;
51 private final static long contextValueAfterFirstEvent
= 13589759412128L;
52 private final static String firstEventReference
= tracename
+ "/metadata_0";
55 private final static long timestampToSeekTest1
= 13589826657302L;
56 private final static Long indexToSeekTest1
= 7497L;
57 private final static long locationToSeekTest1
= 2177044;
58 private final static long contextValueAfterSeekTest1
= 13589826657302L;
59 private final static String seek1EventReference
= tracename
+ "/vm_state_0";
61 private final static long timestampToSeekLast
= 13589906758692L;
62 private final static Long indexToSeekLast
= 15315L;
63 private final static long locationToSeekLast
= 4420634;
64 private final static long contextValueAfterSeekLast
= 13589906758692L;
65 private final static String seekLastEventReference
= tracename
+ "/kernel_0";
67 private static LTTngTextTrace testStream
= null;
68 private LTTngTextTrace
prepareStreamToTest() {
69 if (testStream
== null) {
71 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(), new Path(tracepath1
), null);
72 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
73 LTTngTextTrace tmpStream
= new LTTngTextTrace(testfile
.getPath());
74 testStream
= tmpStream
;
77 System
.out
.println("ERROR : Could not open " + tracepath1
);
82 testStream
.seekEvent(0);
89 public void testTraceConstructors() {
90 @SuppressWarnings("unused")
91 LTTngTextTrace testStream1
= null;
93 // Default constructor
94 // Test constructor with argument on a wrong tracepath, skipping indexing
96 testStream1
= new LTTngTextTrace(wrongTracePath
, skipIndexing
);
97 fail("Construction with wrong tracepath should fail!");
102 // Test constructor with argument on a correct tracepath, skipping indexing
104 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(), new Path(tracepath1
), null);
105 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
106 testStream1
= new LTTngTextTrace(testfile
.getPath(), skipIndexing
);
108 catch( Exception e
) {
109 fail("Construction with correct tracepath failed!");
113 public void testGetNextEvent() {
114 TmfEvent tmpEvent
= null;
115 LTTngTextTrace testStream1
= prepareStreamToTest();
117 TmfContext tmpContext
= new TmfContext(null, 0);
118 // We should be at the beginning of the trace, so we will just read the first event now
119 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
120 assertNotSame("tmpEvent is null after first getNextEvent()",null,tmpEvent
);
121 assertEquals("tmpEvent has wrong timestamp after first getNextEvent()",firstEventTimestamp
,(long)tmpEvent
.getTimestamp().getValue() );
123 // Read the next event as well
124 tmpEvent
= testStream1
.getNextEvent( tmpContext
);
125 assertNotSame("tmpEvent is null after second getNextEvent()",null,tmpEvent
);
126 assertEquals("tmpEvent has wrong timestamp after second getNextEvent()",secondEventTimestamp
,(long)tmpEvent
.getTimestamp().getValue() );
129 public void testParseEvent() {
130 TmfEvent tmpEvent
= null;
131 LTTngTextTrace testStream1
= prepareStreamToTest();
133 TmfContext tmpContext
= new TmfContext(null, 0);
134 // We should be at the beginning of the trace, so we will just parse the first event now
135 tmpEvent
= testStream1
.parseEvent(tmpContext
);
136 assertNotSame("tmpEvent is null after first parseEvent()",null,tmpEvent
);
137 assertEquals("tmpEvent has wrong timestamp after first parseEvent()",firstEventTimestamp
,(long)tmpEvent
.getTimestamp().getValue() );
139 // Use parseEvent again. Should be the same event
140 tmpEvent
= testStream1
.parseEvent(tmpContext
);
141 assertNotSame("tmpEvent is null after first parseEvent()",null,tmpEvent
);
142 assertEquals("tmpEvent has wrong timestamp after first parseEvent()",firstEventTimestamp
,(long)tmpEvent
.getTimestamp().getValue() );
145 public void testSeekEventTimestamp() {
146 TmfEvent tmpEvent
= null;
147 TmfContext tmpContext
= new TmfContext(null, 0);
148 LTTngTextTrace testStream1
= prepareStreamToTest();
150 // We should be at the beginning of the trace, we will seek at a certain timestamp
151 tmpContext
= testStream1
.seekEvent(new TmfTimestamp(timestampToSeekTest1
, (byte) -9, 0));
152 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
153 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext
);
154 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
155 assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent
);
156 assertTrue("tmpEvent has wrong reference after first seekEvent()", ((String
)tmpEvent
.getReference().getReference()).contains(seek1EventReference
) );
158 // Seek to the last timestamp
159 tmpContext
= testStream1
.seekEvent(new TmfTimestamp(timestampToSeekLast
, (byte) -9, 0));
160 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
161 assertNotSame("tmpContext is null after seekEvent() to last",null,tmpContext
);
162 assertEquals("tmpContext has wrong timestamp after seekEvent() to last",contextValueAfterSeekLast
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
163 assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent
);
164 assertTrue("tmpEvent has wrong reference after seekEvent() to last",((String
)tmpEvent
.getReference().getReference()).contains(seekLastEventReference
) );
166 // Seek to the first timestamp (startTime)
167 tmpContext
= testStream1
.seekEvent(new TmfTimestamp(firstEventTimestamp
, (byte) -9, 0));
168 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
169 assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent
);
170 assertTrue("tmpEvent has wrong reference after seekEvent() to start",((String
)tmpEvent
.getReference().getReference()).contains(firstEventReference
) );
171 assertNotSame("tmpContext is null after seekEvent() to first",null,tmpContext
);
172 assertEquals("tmpContext has wrong timestamp after seekEvent() to first",contextValueAfterFirstEvent
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
175 public void testSeekEventIndex() {
176 TmfEvent tmpEvent
= null;
177 TmfContext tmpContext
= new TmfContext(null, 0);
178 LTTngTextTrace testStream1
= prepareStreamToTest();
180 // We should be at the beginning of the trace, we will seek at a certain timestamp
181 tmpContext
= testStream1
.seekEvent(indexToSeekTest1
);
182 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
183 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext
);
184 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
185 assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent
);
186 assertTrue("tmpEvent has wrong reference after first seekEvent()", ((String
)tmpEvent
.getReference().getReference()).contains(seek1EventReference
) );
188 // Seek to the last timestamp
189 tmpContext
= testStream1
.seekEvent(indexToSeekLast
);
190 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
191 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext
);
192 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekLast
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
193 assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent
);
194 assertTrue("tmpEvent has wrong reference after seekEvent() to last",((String
)tmpEvent
.getReference().getReference()).contains(seekLastEventReference
) );
196 // Seek to the first timestamp (startTime)
197 tmpContext
= testStream1
.seekEvent(indexToSeekFirst
);
198 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
199 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext
);
200 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterFirstEvent
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
201 assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent
);
202 assertTrue("tmpEvent has wrong reference after seekEvent() to start",((String
)tmpEvent
.getReference().getReference()).contains(firstEventReference
) );
205 public void testSeekLocation() {
206 TmfEvent tmpEvent
= null;
207 TmfContext tmpContext
= new TmfContext(null, 0);
208 LTTngTextTrace testStream1
= prepareStreamToTest();
210 // We should be at the beginning of the trace, we will seek at a certain timestamp
211 tmpContext
= testStream1
.seekLocation(new TmfLocation
<Long
>(locationToSeekTest1
));
212 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
213 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext
);
214 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekTest1
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
215 assertNotSame("tmpEvent is null after first seekLocation()",null,tmpEvent
);
216 assertTrue("tmpEvent has wrong reference after first seekLocation()", ((String
)tmpEvent
.getReference().getReference()).contains(seek1EventReference
) );
218 // Seek to the last timestamp
219 tmpContext
= testStream1
.seekLocation(new TmfLocation
<Long
>(locationToSeekLast
));
220 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
221 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext
);
222 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekLast
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
223 assertNotSame("tmpEvent is null after seekLocation() to last ",null,tmpEvent
);
224 assertTrue("tmpEvent has wrong reference after seekLocation() to last",((String
)tmpEvent
.getReference().getReference()).contains(seekLastEventReference
) );
226 // Seek to the first timestamp (startTime)
227 tmpContext
= testStream1
.seekLocation(new TmfLocation
<Long
>(locationToSeekFirst
));
228 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
229 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext
);
230 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterFirstEvent
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
231 assertNotSame("tmpEvent is null after seekLocation() to start ",null,tmpEvent
);
232 assertTrue("tmpEvent has wrong reference after seekLocation() to start",((String
)tmpEvent
.getReference().getReference()).contains(firstEventReference
) );
235 @SuppressWarnings("unchecked")
236 public void testGetter() {
237 TmfEvent tmpEvent
= null;
238 LTTngTextTrace testStream1
= prepareStreamToTest();
239 TmfContext tmpContext
= new TmfContext(null, 0);
241 // Move to the first event to have something to play with
242 tmpEvent
= testStream1
.parseEvent( tmpContext
);
244 // Test current event
245 assertNotSame("tmpEvent is null after first event",null,tmpEvent
);
246 assertTrue("tmpEvent has wrong reference after first event",((String
)tmpEvent
.getReference().getReference()).contains(firstEventReference
) );
247 assertNotSame("tmpContext is null after first seekEvent()",null,testStream1
.getCurrentLocation() );
248 assertEquals("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent
, ((TmfLocation
<Long
>) testStream1
.getCurrentLocation()).getLocation());
249 // Test CPU number of the trace
250 assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber
,testStream1
.getCpuNumber() );
253 public void testToString() {
254 LTTngTextTrace testStream1
= prepareStreamToTest();
256 // Move to the first event to have something to play with
257 testStream1
.parseEvent( new TmfContext(null, 0) );
259 // Just make sure toString() does not return null or the java reference
260 assertNotSame("toString returned null",null, testStream1
.toString() );
261 assertNotSame("toString is not overridded!", testStream1
.getClass().getName() + '@' + Integer
.toHexString(testStream1
.hashCode()), testStream1
.toString() );