(no commit message)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / trace / LTTngTraceTest.java
1 package org.eclipse.linuxtools.lttng.tests.trace;
2
3 import java.io.File;
4 import java.net.URL;
5
6 import junit.framework.TestCase;
7
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;
16
17 /*
18 Functions tested here :
19 public LTTngTrace(String path) throws Exception
20 public LTTngTrace(String path, boolean skipIndexing) throws Exception
21
22 public TmfTraceContext seekLocation(Object location) {
23 public TmfTraceContext seekEvent(TmfTimestamp timestamp) {
24 public TmfTraceContext seekEvent(long position) {
25
26 public TmfEvent getNextEvent(TmfTraceContext context) {
27 public Object getCurrentLocation() {
28
29 public LttngEvent parseEvent(TmfTraceContext context) {
30
31 public int getCpuNumber() {
32 */
33
34 public class LTTngTraceTest extends TestCase {
35
36 private final static String tracepath1="traceset/trace-15316events_nolost_newformat";
37 private final static String wrongTracePath="/somewhere/that/does/not/exist";
38
39 private final static int traceCpuNumber=1;
40
41 private final static boolean skipIndexing=true;
42
43 private final static long firstEventTimestamp = 13589759412128L;
44 private final static long secondEventTimestamp = 13589759419903L;
45 private final static Long locationAfterFirstEvent = 13589759412128L;
46
47 private final static String tracename = "traceset/trace-15316events_nolost_newformat";
48
49 private final static long indexToSeekFirst = 0;
50 private final static Long locationToSeekFirst = 13589759412128L;
51 private final static long contextValueAfterFirstEvent = 13589759412128L;
52 private final static String firstEventReference = tracename + "/metadata_0";
53
54
55 private final static long timestampToSeekTest1 = 13589826657302L;
56 private final static Long indexToSeekTest1 = 7497L;
57 private final static long locationToSeekTest1 = 13589826657302L;
58 private final static long contextValueAfterSeekTest1 = 13589826657302L;
59 private final static String seek1EventReference = tracename + "/vm_state_0";
60
61 private final static long timestampToSeekLast = 13589906758692L;
62 private final static Long indexToSeekLast = 15315L;
63 private final static long locationToSeekLast = 13589906758692L;
64 private final static long contextValueAfterSeekLast = 13589906758692L;
65 private final static String seekLastEventReference = tracename + "/kernel_0";
66
67 private static LTTngTrace testStream = null;
68 private LTTngTrace prepareStreamToTest() {
69 if (testStream == null) {
70 try {
71 URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null);
72 File testfile = new File(FileLocator.toFileURL(location).toURI());
73 LTTngTrace tmpStream = new LTTngTrace(testfile.getPath());
74 testStream = tmpStream;
75 }
76 catch (Exception e) {
77 System.out.println("ERROR : Could not open " + tracepath1);
78 testStream = null;
79 }
80 }
81 else {
82 testStream.seekEvent(0L);
83 }
84
85
86 return testStream;
87 }
88
89 public void testTraceConstructors() {
90 @SuppressWarnings("unused")
91 LTTngTrace testStream1 = null;
92
93 // Default constructor
94 // Test constructor with argument on a wrong tracepath, skipping indexing
95 try {
96 testStream1 = new LTTngTrace(wrongTracePath, skipIndexing);
97 fail("Construction with wrong tracepath should fail!");
98 }
99 catch( Exception e) {
100 }
101
102 // Test constructor with argument on a correct tracepath, skipping indexing
103 try {
104 URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null);
105 File testfile = new File(FileLocator.toFileURL(location).toURI());
106 testStream1 = new LTTngTrace(testfile.getPath(), skipIndexing);
107 }
108 catch( Exception e) {
109 fail("Construction with correct tracepath failed!");
110 }
111 }
112
113 public void testGetNextEvent() {
114 TmfEvent tmpEvent = null;
115 LTTngTrace testStream1 = prepareStreamToTest();
116
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() );
122
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() );
127 }
128
129 public void testParseEvent() {
130 TmfEvent tmpEvent = null;
131 LTTngTrace testStream1 = prepareStreamToTest();
132
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() );
138
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() );
143 }
144
145 public void testSeekEventTimestamp() {
146 TmfEvent tmpEvent = null;
147 TmfContext tmpContext = new TmfContext(null, 0);
148 LTTngTrace testStream1 = prepareStreamToTest();
149
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) );
157
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) );
165
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() );
173 }
174
175 public void testSeekEventIndex() {
176 TmfEvent tmpEvent = null;
177 TmfContext tmpContext = new TmfContext(null, 0);
178 LTTngTrace testStream1 = prepareStreamToTest();
179
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) );
187
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) );
195
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) );
203 }
204
205 public void testSeekLocation() {
206 TmfEvent tmpEvent = null;
207 TmfContext tmpContext = new TmfContext(null, 0);
208 LTTngTrace testStream1 = prepareStreamToTest();
209
210 // We should be at the beginning of the trace, we will seek at a certain timestamp
211 tmpContext = testStream1.seekLocation(new LttngLocation(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) );
217
218 // Seek to the last timestamp
219 tmpContext = testStream1.seekLocation(new LttngLocation(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) );
225
226 // Seek to the first timestamp (startTime)
227 tmpContext = testStream1.seekLocation(new LttngLocation(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) );
233 }
234
235 public void testGetter() {
236 TmfEvent tmpEvent = null;
237 LTTngTrace testStream1 = prepareStreamToTest();
238
239 // Move to the first event to have something to play with
240 tmpEvent = testStream1.parseEvent( new TmfContext(null, 0));
241
242 // Test current event
243 assertNotSame("tmpEvent is null after first event",null,tmpEvent );
244 assertTrue("tmpEvent has wrong reference after first event",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
245 assertNotSame("tmpContext is null after first seekEvent()",null,testStream1.getCurrentLocation() );
246 assertTrue("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent.equals( ((LttngLocation)testStream1.getCurrentLocation()).getOperationTimeValue()) );
247
248 // Test CPU number of the trace
249 assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber ,testStream1.getCpuNumber() );
250 }
251
252 public void testToString() {
253 LTTngTrace testStream1 = prepareStreamToTest();
254
255 // Move to the first event to have something to play with
256 testStream1.parseEvent( new TmfContext(null, 0) );
257
258 // Just make sure toString() does not return null or the java reference
259 assertNotSame("toString returned null",null, testStream1.toString() );
260 assertNotSame("toString is not overridded!", testStream1.getClass().getName() + '@' + Integer.toHexString(testStream1.hashCode()), testStream1.toString() );
261 }
262
263 }
This page took 0.037097 seconds and 6 git commands to generate.