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
.event
.LttngLocation
;
11 import org
.eclipse
.linuxtools
.lttng
.tests
.LTTngCoreTestPlugin
;
12 import org
.eclipse
.linuxtools
.lttng
.trace
.LTTngTrace
;
13 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
14 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
15 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
18 Functions tested here :
19 public LTTngTrace(String path) throws Exception
20 public LTTngTrace(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 @SuppressWarnings("nls")
35 public class LTTngTraceTest
extends TestCase
{
37 private final static String tracepath1
="traceset/trace-15316events_nolost_newformat";
38 private final static String wrongTracePath
="/somewhere/that/does/not/exist";
40 private final static int traceCpuNumber
=1;
42 private final static boolean skipIndexing
=true;
44 private final static long firstEventTimestamp
= 13589759412128L;
45 private final static long secondEventTimestamp
= 13589759419903L;
46 private final static Long locationAfterFirstEvent
= 13589759412128L;
48 private final static String tracename
= "traceset/trace-15316events_nolost_newformat";
50 private final static long indexToSeekFirst
= 0;
51 private final static Long locationToSeekFirst
= 13589759412128L;
52 private final static long contextValueAfterFirstEvent
= 13589759412128L;
53 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
= 13589826657302L;
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
= 13589906758692L;
65 private final static long contextValueAfterSeekLast
= 13589906758692L;
66 private final static String seekLastEventReference
= tracename
+ "/kernel_0";
68 private static LTTngTrace testStream
= null;
69 private LTTngTrace
prepareStreamToTest() {
70 if (testStream
== null) {
72 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(), new Path(tracepath1
), null);
73 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
74 LTTngTrace tmpStream
= new LTTngTrace(testfile
.getPath());
75 testStream
= tmpStream
;
78 System
.out
.println("ERROR : Could not open " + tracepath1
);
83 testStream
.seekEvent(0L);
90 public void testTraceConstructors() {
91 @SuppressWarnings("unused")
92 LTTngTrace testStream1
= null;
94 // Default constructor
95 // Test constructor with argument on a wrong tracepath, skipping indexing
97 testStream1
= new LTTngTrace(wrongTracePath
, skipIndexing
);
98 fail("Construction with wrong tracepath should fail!");
100 catch( Exception e
) {
103 // Test constructor with argument on a correct tracepath, skipping indexing
105 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(), new Path(tracepath1
), null);
106 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
107 testStream1
= new LTTngTrace(testfile
.getPath(), skipIndexing
);
109 catch( Exception e
) {
110 fail("Construction with correct tracepath failed!");
114 public void testGetNextEvent() {
115 TmfEvent tmpEvent
= null;
116 LTTngTrace testStream1
= prepareStreamToTest();
118 TmfContext tmpContext
= new TmfContext(null, 0);
119 // We should be at the beginning of the trace, so we will just read the first event now
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
,(long)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
,(long)tmpEvent
.getTimestamp().getValue() );
130 public void testParseEvent() {
131 TmfEvent tmpEvent
= null;
132 LTTngTrace 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 first event now
136 tmpEvent
= testStream1
.parseEvent(tmpContext
);
137 assertNotSame("tmpEvent is null after first parseEvent()",null,tmpEvent
);
138 assertEquals("tmpEvent has wrong timestamp after first parseEvent()",firstEventTimestamp
,(long)tmpEvent
.getTimestamp().getValue() );
140 // Use parseEvent again. Should be the same event
141 tmpEvent
= testStream1
.parseEvent(tmpContext
);
142 assertNotSame("tmpEvent is null after first parseEvent()",null,tmpEvent
);
143 assertEquals("tmpEvent has wrong timestamp after first parseEvent()",firstEventTimestamp
,(long)tmpEvent
.getTimestamp().getValue() );
146 public void testSeekEventTimestamp() {
147 TmfEvent tmpEvent
= null;
148 TmfContext tmpContext
= new TmfContext(null, 0);
149 LTTngTrace testStream1
= prepareStreamToTest();
151 // We should be at the beginning of the trace, we will seek at a certain timestamp
152 tmpContext
= testStream1
.seekEvent(new TmfTimestamp(timestampToSeekTest1
, (byte) -9, 0));
153 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
154 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext
);
155 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
156 assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent
);
157 assertTrue("tmpEvent has wrong reference after first seekEvent()", ((String
)tmpEvent
.getReference().getReference()).contains(seek1EventReference
) );
159 // Seek to the last timestamp
160 tmpContext
= testStream1
.seekEvent(new TmfTimestamp(timestampToSeekLast
, (byte) -9, 0));
161 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
162 assertNotSame("tmpContext is null after seekEvent() to last",null,tmpContext
);
163 assertEquals("tmpContext has wrong timestamp after seekEvent() to last",contextValueAfterSeekLast
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
164 assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent
);
165 assertTrue("tmpEvent has wrong reference after seekEvent() to last",((String
)tmpEvent
.getReference().getReference()).contains(seekLastEventReference
) );
167 // Seek to the first timestamp (startTime)
168 tmpContext
= testStream1
.seekEvent(new TmfTimestamp(firstEventTimestamp
, (byte) -9, 0));
169 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
170 assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent
);
171 assertTrue("tmpEvent has wrong reference after seekEvent() to start",((String
)tmpEvent
.getReference().getReference()).contains(firstEventReference
) );
172 assertNotSame("tmpContext is null after seekEvent() to first",null,tmpContext
);
173 assertEquals("tmpContext has wrong timestamp after seekEvent() to first",contextValueAfterFirstEvent
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
176 public void testSeekEventIndex() {
177 TmfEvent tmpEvent
= null;
178 TmfContext tmpContext
= new TmfContext(null, 0);
179 LTTngTrace testStream1
= prepareStreamToTest();
181 // We should be at the beginning of the trace, we will seek at a certain timestamp
182 tmpContext
= testStream1
.seekEvent(indexToSeekTest1
);
183 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
184 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext
);
185 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
186 assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent
);
187 assertTrue("tmpEvent has wrong reference after first seekEvent()", ((String
)tmpEvent
.getReference().getReference()).contains(seek1EventReference
) );
189 // Seek to the last timestamp
190 tmpContext
= testStream1
.seekEvent(indexToSeekLast
);
191 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
192 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext
);
193 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekLast
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
194 assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent
);
195 assertTrue("tmpEvent has wrong reference after seekEvent() to last",((String
)tmpEvent
.getReference().getReference()).contains(seekLastEventReference
) );
197 // Seek to the first timestamp (startTime)
198 tmpContext
= testStream1
.seekEvent(indexToSeekFirst
);
199 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
200 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext
);
201 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterFirstEvent
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
202 assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent
);
203 assertTrue("tmpEvent has wrong reference after seekEvent() to start",((String
)tmpEvent
.getReference().getReference()).contains(firstEventReference
) );
206 public void testSeekLocation() {
207 TmfEvent tmpEvent
= null;
208 TmfContext tmpContext
= new TmfContext(null, 0);
209 LTTngTrace testStream1
= prepareStreamToTest();
211 // We should be at the beginning of the trace, we will seek at a certain timestamp
212 tmpContext
= testStream1
.seekLocation(new LttngLocation(locationToSeekTest1
));
213 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
214 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext
);
215 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekTest1
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
216 assertNotSame("tmpEvent is null after first seekLocation()",null,tmpEvent
);
217 assertTrue("tmpEvent has wrong reference after first seekLocation()", ((String
)tmpEvent
.getReference().getReference()).contains(seek1EventReference
) );
219 // Seek to the last timestamp
220 tmpContext
= testStream1
.seekLocation(new LttngLocation(locationToSeekLast
));
221 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
222 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext
);
223 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekLast
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
224 assertNotSame("tmpEvent is null after seekLocation() to last ",null,tmpEvent
);
225 assertTrue("tmpEvent has wrong reference after seekLocation() to last",((String
)tmpEvent
.getReference().getReference()).contains(seekLastEventReference
) );
227 // Seek to the first timestamp (startTime)
228 tmpContext
= testStream1
.seekLocation(new LttngLocation(locationToSeekFirst
));
229 tmpEvent
= testStream1
.getNextEvent(tmpContext
);
230 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext
);
231 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterFirstEvent
,(long)((TmfTimestamp
)tmpEvent
.getTimestamp()).getValue() );
232 assertNotSame("tmpEvent is null after seekLocation() to start ",null,tmpEvent
);
233 assertTrue("tmpEvent has wrong reference after seekLocation() to start",((String
)tmpEvent
.getReference().getReference()).contains(firstEventReference
) );
236 public void testGetter() {
237 TmfEvent tmpEvent
= null;
238 LTTngTrace testStream1
= prepareStreamToTest();
240 // Move to the first event to have something to play with
241 tmpEvent
= testStream1
.parseEvent( new TmfContext(null, 0));
243 // Test current event
244 assertNotSame("tmpEvent is null after first event",null,tmpEvent
);
245 assertTrue("tmpEvent has wrong reference after first event",((String
)tmpEvent
.getReference().getReference()).contains(firstEventReference
) );
246 assertNotSame("tmpContext is null after first seekEvent()",null,testStream1
.getCurrentLocation() );
247 assertTrue("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent
.equals( ((LttngLocation
)testStream1
.getCurrentLocation()).getOperationTimeValue()) );
249 // Test CPU number of the trace
250 assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber
,testStream1
.getCpuNumber() );
253 public void testToString() {
254 LTTngTrace 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() );