1 package org
.eclipse
.linuxtools
.lttng
.core
.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
.internal
.lttng
.core
.trace
.LTTngTextTrace
;
11 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
12 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
13 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
14 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
15 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
16 import org
.osgi
.framework
.FrameworkUtil
;
19 Functions tested here :
20 public LTTngTextTrace(String path) throws Exception
21 public LTTngTextTrace(String path, boolean skipIndexing) throws Exception
23 public TmfTraceContext seekLocation(Object location) {
24 public TmfTraceContext seekEvent(TmfTimestamp timestamp) {
25 public TmfTraceContext seekEvent(long position) {
27 public TmfEvent getNextEvent(TmfTraceContext context) {
28 public Object getCurrentLocation() {
30 public LttngEvent parseEvent(TmfTraceContext context) {
32 public int getCpuNumber() {
35 @SuppressWarnings("nls")
36 public class LTTngTextTraceTest
extends TestCase
{
38 private final static String tracepath1
= "traceset/trace-15316events_nolost_newformat.txt";
39 private final static String wrongTracePath
= "/somewhere/that/does/not/exist";
41 private final static int traceCpuNumber
= 1;
43 private final static boolean skipIndexing
= true;
45 private final static long firstEventTimestamp
= 13589759412128L;
46 private final static long secondEventTimestamp
= 13589759419903L;
47 private final static Long locationAfterFirstEvent
= 311L;
49 private final static String tracename
= "traceset/trace-15316events_nolost_newformat";
51 private final static long indexToSeekFirst
= 0;
52 private final static Long locationToSeekFirst
= 0L;
53 private final static long contextValueAfterFirstEvent
= 13589759412128L;
54 private final static String firstEventReference
= tracename
+ "/metadata_0";
56 private final static long timestampToSeekTest1
= 13589826657302L;
57 private final static Long indexToSeekTest1
= 7497L;
58 private final static long locationToSeekTest1
= 2177044;
59 private final static long contextValueAfterSeekTest1
= 13589826657302L;
60 private final static String seek1EventReference
= tracename
+ "/vm_state_0";
62 private final static long timestampToSeekLast
= 13589906758692L;
63 private final static Long indexToSeekLast
= 15315L;
64 private final static long locationToSeekLast
= 4420634;
65 private final static long contextValueAfterSeekLast
= 13589906758692L;
66 private final static String seekLastEventReference
= tracename
+ "/kernel_0";
68 private static LTTngTextTrace testStream
= null;
70 private synchronized LTTngTextTrace
prepareStreamToTest() {
71 if (testStream
== null) {
73 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(tracepath1
), null);
74 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
75 LTTngTextTrace tmpStream
= new LTTngTextTrace(testfile
.getName(), testfile
.getPath());
76 testStream
= tmpStream
;
77 } catch (Exception e
) {
78 System
.out
.println("ERROR : Could not open " + tracepath1
);
82 testStream
.seekEvent(0);
88 public void testTraceConstructorFailure() {
89 // Default constructor
90 // Test constructor with argument on a wrong tracepath, skipping
93 LTTngTextTrace testStream
= new LTTngTextTrace("wrong", wrongTracePath
, skipIndexing
);
94 fail("Construction with wrong tracepath should fail!");
96 } catch (Exception e
) {
100 public void testTraceConstructor() {
101 // Test constructor with argument on a correct tracepath, skipping
104 URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null);
105 File testfile = new File(FileLocator.toFileURL(location).toURI());
106 LTTngTextTrace testStream = new LTTngTextTrace(testfile.getPath(), skipIndexing);
107 testStream.dispose();
108 } catch (Exception e) {
109 fail("Construction with correct tracepath failed!");
113 public void testGetNextEvent() {
114 ITmfEvent 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
120 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
121 assertNotSame("tmpEvent is null after first getNextEvent()", null, tmpEvent
);
122 assertEquals("tmpEvent has wrong timestamp after first getNextEvent()", firstEventTimestamp
, tmpEvent
.getTimestamp().getValue());
124 // Read the next event as well
125 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
126 assertNotSame("tmpEvent is null after second getNextEvent()", null, tmpEvent
);
127 assertEquals("tmpEvent has wrong timestamp after second getNextEvent()", secondEventTimestamp
, tmpEvent
.getTimestamp().getValue());
130 public void testParseEvent() {
131 ITmfEvent tmpEvent
= null;
132 LTTngTextTrace testStream1
= prepareStreamToTest();
134 TmfContext tmpContext
= new TmfContext(null, 0);
135 // We should be at the beginning of the trace, so we will just parse the
137 tmpEvent
= testStream1
.parseEvent(tmpContext
);
138 assertNotSame("tmpEvent is null after first parseEvent()", null, tmpEvent
);
139 assertEquals("tmpEvent has wrong timestamp after first parseEvent()", firstEventTimestamp
, tmpEvent
.getTimestamp().getValue());
141 // Use parseEvent again. Should be the same event
142 tmpEvent
= testStream1
.parseEvent(tmpContext
);
143 assertNotSame("tmpEvent is null after first parseEvent()", null, tmpEvent
);
144 assertEquals("tmpEvent has wrong timestamp after first parseEvent()", firstEventTimestamp
, tmpEvent
.getTimestamp().getValue());
147 public void testSeekEventTimestamp() {
148 ITmfEvent tmpEvent
= null;
149 ITmfContext tmpContext
= new TmfContext(null, 0);
150 LTTngTextTrace testStream1
= prepareStreamToTest();
152 // We should be at the beginning of the trace, we will seek at a certain
154 tmpContext
= testStream1
.seekEvent(new TmfTimestamp(timestampToSeekTest1
, (byte) -9, 0));
155 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
156 assertNotSame("tmpContext is null after first seekEvent()", null, tmpContext
);
157 assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterSeekTest1
, tmpEvent
.getTimestamp().getValue());
158 assertNotSame("tmpEvent is null after first seekEvent()", null, tmpEvent
);
159 assertTrue("tmpEvent has wrong reference after first seekEvent()", seek1EventReference
.contains((String
) tmpEvent
.getReference()));
161 // Seek to the last timestamp
162 tmpContext
= testStream1
.seekEvent(new TmfTimestamp(timestampToSeekLast
, (byte) -9, 0));
163 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
164 assertNotSame("tmpContext is null after seekEvent() to last", null, tmpContext
);
165 assertEquals("tmpContext has wrong timestamp after seekEvent() to last", contextValueAfterSeekLast
, tmpEvent
.getTimestamp().getValue());
166 assertNotSame("tmpEvent is null after seekEvent() to last ", null, tmpEvent
);
167 assertTrue("tmpEvent has wrong reference after seekEvent() to last", seekLastEventReference
.contains((String
) tmpEvent
.getReference()));
169 // Seek to the first timestamp (startTime)
170 tmpContext
= testStream1
.seekEvent(new TmfTimestamp(firstEventTimestamp
, (byte) -9, 0));
171 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
172 assertNotSame("tmpEvent is null after seekEvent() to start ", null, tmpEvent
);
173 assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference
.contains((String
) tmpEvent
.getReference()));
174 assertNotSame("tmpContext is null after seekEvent() to first", null, tmpContext
);
175 assertEquals("tmpContext has wrong timestamp after seekEvent() to first", contextValueAfterFirstEvent
, tmpEvent
.getTimestamp().getValue());
178 public void testSeekEventIndex() {
179 ITmfEvent tmpEvent
= null;
180 ITmfContext tmpContext
= new TmfContext(null, 0);
181 LTTngTextTrace testStream1
= prepareStreamToTest();
183 // We should be at the beginning of the trace, we will seek at a certain
185 tmpContext
= testStream1
.seekEvent(indexToSeekTest1
);
186 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
187 assertNotSame("tmpContext is null after first seekEvent()", null, tmpContext
);
188 assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterSeekTest1
, tmpEvent
.getTimestamp().getValue());
189 assertNotSame("tmpEvent is null after first seekEvent()", null, tmpEvent
);
190 assertTrue("tmpEvent has wrong reference after first seekEvent()", seek1EventReference
.contains((String
) tmpEvent
.getReference()));
192 // Seek to the last timestamp
193 tmpContext
= testStream1
.seekEvent(indexToSeekLast
);
194 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
195 assertNotSame("tmpContext is null after first seekEvent()", null, tmpContext
);
196 assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterSeekLast
, tmpEvent
.getTimestamp().getValue());
197 assertNotSame("tmpEvent is null after seekEvent() to last ", null, tmpEvent
);
198 assertTrue("tmpEvent has wrong reference after seekEvent() to last", seekLastEventReference
.contains((String
) tmpEvent
.getReference()));
200 // Seek to the first timestamp (startTime)
201 tmpContext
= testStream1
.seekEvent(indexToSeekFirst
);
202 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
203 assertNotSame("tmpContext is null after first seekEvent()", null, tmpContext
);
204 assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterFirstEvent
, tmpEvent
.getTimestamp().getValue());
205 assertNotSame("tmpEvent is null after seekEvent() to start ", null, tmpEvent
);
206 assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference
.contains((String
) tmpEvent
.getReference()));
209 public void testSeekLocation() {
210 ITmfEvent tmpEvent
= null;
211 TmfContext tmpContext
= new TmfContext(null, 0);
212 LTTngTextTrace testStream1
= prepareStreamToTest();
214 // We should be at the beginning of the trace, we will seek at a certain
216 tmpContext
= testStream1
.seekLocation(new TmfLocation
<Long
>(locationToSeekTest1
));
217 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
218 assertNotSame("tmpContext is null after first seekLocation()", null, tmpContext
);
219 assertEquals("tmpContext has wrong timestamp after first seekLocation()", contextValueAfterSeekTest1
, tmpEvent
.getTimestamp().getValue());
220 assertNotSame("tmpEvent is null after first seekLocation()", null, tmpEvent
);
221 assertTrue("tmpEvent has wrong reference after first seekLocation()", seek1EventReference
.contains((String
) tmpEvent
.getReference()));
223 // Seek to the last timestamp
224 tmpContext
= testStream1
.seekLocation(new TmfLocation
<Long
>(locationToSeekLast
));
225 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
226 assertNotSame("tmpContext is null after first seekLocation()", null, tmpContext
);
227 assertEquals("tmpContext has wrong timestamp after first seekLocation()", contextValueAfterSeekLast
, tmpEvent
.getTimestamp().getValue());
228 assertNotSame("tmpEvent is null after seekLocation() to last ", null, tmpEvent
);
229 assertTrue("tmpEvent has wrong reference after seekLocation() to last", seekLastEventReference
.contains((String
) tmpEvent
.getReference()));
231 // Seek to the first timestamp (startTime)
232 tmpContext
= testStream1
.seekLocation(new TmfLocation
<Long
>(locationToSeekFirst
));
233 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
234 assertNotSame("tmpContext is null after first seekLocation()", null, tmpContext
);
235 assertEquals("tmpContext has wrong timestamp after first seekLocation()", contextValueAfterFirstEvent
, tmpEvent
.getTimestamp().getValue());
236 assertNotSame("tmpEvent is null after seekLocation() to start ", null, tmpEvent
);
237 assertTrue("tmpEvent has wrong reference after seekLocation() to start", firstEventReference
.contains((String
) tmpEvent
.getReference()));
240 @SuppressWarnings("unchecked")
241 public void testGetter() {
242 ITmfEvent tmpEvent
= null;
243 LTTngTextTrace testStream1
= prepareStreamToTest();
244 TmfContext tmpContext
= new TmfContext(null, 0);
246 // Move to the first event to have something to play with
247 tmpEvent
= testStream1
.parseEvent(tmpContext
);
249 // Test current event
250 assertNotSame("tmpEvent is null after first event", null, tmpEvent
);
251 assertTrue("tmpEvent has wrong reference after first event", firstEventReference
.contains((String
) tmpEvent
.getReference()));
252 assertNotSame("tmpContext is null after first seekEvent()", null, testStream1
.getCurrentLocation());
253 assertEquals("tmpContext has wrong timestamp after first seekEvent()", locationAfterFirstEvent
, ((TmfLocation
<Long
>) testStream1
.getCurrentLocation()).getLocation());
254 // Test CPU number of the trace
255 assertSame("getCpuNumber() return wrong number of cpu", traceCpuNumber
, testStream1
.getCpuNumber());
258 public void testToString() {
259 LTTngTextTrace testStream1
= prepareStreamToTest();
261 // Move to the first event to have something to play with
262 testStream1
.parseEvent(new TmfContext(null, 0));
264 // Just make sure toString() does not return null or the java reference
265 assertNotSame("toString returned null", null, testStream1
.toString());
266 assertNotSame("toString is not overridded!", testStream1
.getClass().getName() + '@' + Integer
.toHexString(testStream1
.hashCode()), testStream1
.toString());