[Bug 303523] LTTng/TMF udpates:
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / trace / LTTngTextTraceTest.java
1 package org.eclipse.linuxtools.lttng.tests.trace;
2
3 import org.eclipse.linuxtools.tmf.event.TmfEvent;
4 import java.io.File;
5 import java.net.URL;
6
7 import junit.framework.TestCase;
8
9 import org.eclipse.core.runtime.FileLocator;
10 import org.eclipse.core.runtime.Path;
11 import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin;
12 import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace;
13 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
14 import org.eclipse.linuxtools.tmf.trace.TmfTraceContext;
15
16 /*
17 Functions tested here :
18 public LTTngTextTrace(String path) throws Exception
19 public LTTngTextTrace(String path, boolean skipIndexing) throws Exception
20
21 public TmfTraceContext seekLocation(Object location) {
22 public TmfTraceContext seekEvent(TmfTimestamp timestamp) {
23 public TmfTraceContext seekEvent(long position) {
24
25 public TmfEvent getNextEvent(TmfTraceContext context) {
26 public Object getCurrentLocation() {
27
28 public LttngEvent parseEvent(TmfTraceContext context) {
29
30 public int getCpuNumber() {
31 */
32
33 public class LTTngTextTraceTest extends TestCase {
34
35 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
36 private final static String wrongTracePath="/somewhere/that/does/not/exist";
37
38 private final static int traceCpuNumber=1;
39
40 private final static boolean skipIndexing=true;
41
42 private final static long firstEventTimestamp = 13589759412127L;
43 private final static long secondEventTimestamp = 13589759419902L;
44 private final static Long locationAfterFirstEvent = 245L;
45
46 private final static String tracename = "traceset/trace_15316events_nolost_newformat";
47
48 private final static long indexToSeekFirst = 0;
49 private final static Long locationToSeekFirst = 0L;
50 private final static long contextValueAfterFirstEvent = 13589759412127L;
51 private final static String firstEventReference = tracename + "/metadata_0";
52
53
54 private final static long timestampToSeekTest1 = 13589826657302L;
55 private final static Long indexToSeekTest1 = 7497L;
56 private final static long locationToSeekTest1 = 1682942;
57 private final static long contextValueAfterSeekTest1 = 13589826657302L;
58 private final static String seek1EventReference = tracename + "/vm_state_0";
59
60 private final static long timestampToSeekLast = 13589906758691L;
61 private final static Long indexToSeekLast = 15315L;
62 private final static long locationToSeekLast = 3410544;
63 private final static long contextValueAfterSeekLast = 13589906758691L;
64 private final static String seekLastEventReference = tracename + "/kernel_0";
65
66 private static LTTngTextTrace testStream = null;
67 private LTTngTextTrace prepareStreamToTest() {
68 if (testStream == null) {
69 try {
70 URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null);
71 File testfile = new File(FileLocator.toFileURL(location).toURI());
72 LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getPath());
73 testStream = tmpStream;
74 }
75 catch (Exception e) {
76 System.out.println("ERROR : Could not open " + tracepath1);
77 testStream = null;
78 }
79 }
80 else {
81 testStream.seekEvent(0);
82 }
83
84
85 return testStream;
86 }
87
88 public void testTraceConstructors() {
89 @SuppressWarnings("unused")
90 LTTngTextTrace testStream1 = null;
91
92 // Default constructor
93 // Test constructor with argument on a wrong tracepath, skipping indexing
94 try {
95 testStream1 = new LTTngTextTrace(wrongTracePath, skipIndexing);
96 fail("Construction with wrong tracepath should fail!");
97 }
98 catch( Exception e) {
99 }
100
101 // Test constructor with argument on a correct tracepath, skipping indexing
102 try {
103 URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null);
104 File testfile = new File(FileLocator.toFileURL(location).toURI());
105 testStream1 = new LTTngTextTrace(testfile.getPath(), skipIndexing);
106 }
107 catch( Exception e) {
108 fail("Construction with correct tracepath failed!");
109 }
110 }
111
112 public void testGetNextEvent() {
113 TmfEvent tmpEvent = null;
114 LTTngTextTrace testStream1 = prepareStreamToTest();
115
116 TmfTraceContext tmpContext = new TmfTraceContext(null, 0);
117 // We should be at the beginning of the trace, so we will just read the first event now
118 tmpEvent = testStream1.getNextEvent(tmpContext );
119 assertNotSame("tmpEvent is null after first getNextEvent()",null,tmpEvent );
120 assertEquals("tmpEvent has wrong timestamp after first getNextEvent()",firstEventTimestamp,(long)tmpEvent.getTimestamp().getValue() );
121
122 // Read the next event as well
123 tmpEvent = testStream1.getNextEvent( tmpContext);
124 assertNotSame("tmpEvent is null after second getNextEvent()",null,tmpEvent );
125 assertEquals("tmpEvent has wrong timestamp after second getNextEvent()",secondEventTimestamp,(long)tmpEvent.getTimestamp().getValue() );
126 }
127
128 public void testParseEvent() {
129 TmfEvent tmpEvent = null;
130 LTTngTextTrace testStream1 = prepareStreamToTest();
131
132 TmfTraceContext tmpContext = new TmfTraceContext(null, 0);
133 // We should be at the beginning of the trace, so we will just parse the first event now
134 tmpEvent = testStream1.parseEvent(tmpContext );
135 assertNotSame("tmpEvent is null after first parseEvent()",null,tmpEvent );
136 assertEquals("tmpEvent has wrong timestamp after first parseEvent()",firstEventTimestamp,(long)tmpEvent.getTimestamp().getValue() );
137
138 // Use parseEvent again. Should be the same event
139 tmpEvent = testStream1.parseEvent(tmpContext );
140 assertNotSame("tmpEvent is null after first parseEvent()",null,tmpEvent );
141 assertEquals("tmpEvent has wrong timestamp after first parseEvent()",firstEventTimestamp,(long)tmpEvent.getTimestamp().getValue() );
142 }
143
144 public void testSeekEventTimestamp() {
145 TmfEvent tmpEvent = null;
146 TmfTraceContext tmpContext = new TmfTraceContext(null, 0);
147 LTTngTextTrace testStream1 = prepareStreamToTest();
148
149 // We should be at the beginning of the trace, we will seek at a certain timestamp
150 tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekTest1, (byte) -9, 0));
151 tmpEvent = testStream1.getNextEvent(tmpContext);
152 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
153 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
154 assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent );
155 assertTrue("tmpEvent has wrong reference after first seekEvent()", ((String)tmpEvent.getReference().getReference()).contains(seek1EventReference) );
156
157 // Seek to the last timestamp
158 tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekLast, (byte) -9, 0));
159 tmpEvent = testStream1.getNextEvent(tmpContext);
160 assertNotSame("tmpContext is null after seekEvent() to last",null,tmpContext );
161 assertEquals("tmpContext has wrong timestamp after seekEvent() to last",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
162 assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent );
163 assertTrue("tmpEvent has wrong reference after seekEvent() to last",((String)tmpEvent.getReference().getReference()).contains(seekLastEventReference) );
164
165 // Seek to the first timestamp (startTime)
166 tmpContext = testStream1.seekEvent(new TmfTimestamp(firstEventTimestamp, (byte) -9, 0));
167 tmpEvent = testStream1.getNextEvent(tmpContext);
168 assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent );
169 assertTrue("tmpEvent has wrong reference after seekEvent() to start",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
170 assertNotSame("tmpContext is null after seekEvent() to first",null,tmpContext );
171 assertEquals("tmpContext has wrong timestamp after seekEvent() to first",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
172 }
173
174 public void testSeekEventIndex() {
175 TmfEvent tmpEvent = null;
176 TmfTraceContext tmpContext = new TmfTraceContext(null, 0);
177 LTTngTextTrace testStream1 = prepareStreamToTest();
178
179 // We should be at the beginning of the trace, we will seek at a certain timestamp
180 tmpContext = testStream1.seekEvent(indexToSeekTest1);
181 tmpEvent = testStream1.getNextEvent(tmpContext);
182 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
183 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
184 assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent );
185 assertTrue("tmpEvent has wrong reference after first seekEvent()", ((String)tmpEvent.getReference().getReference()).contains(seek1EventReference) );
186
187 // Seek to the last timestamp
188 tmpContext = testStream1.seekEvent(indexToSeekLast);
189 tmpEvent = testStream1.getNextEvent(tmpContext);
190 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
191 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
192 assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent );
193 assertTrue("tmpEvent has wrong reference after seekEvent() to last",((String)tmpEvent.getReference().getReference()).contains(seekLastEventReference) );
194
195 // Seek to the first timestamp (startTime)
196 tmpContext = testStream1.seekEvent(indexToSeekFirst);
197 tmpEvent = testStream1.getNextEvent(tmpContext);
198 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
199 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
200 assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent );
201 assertTrue("tmpEvent has wrong reference after seekEvent() to start",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
202 }
203
204 public void testSeekLocation() {
205 TmfEvent tmpEvent = null;
206 TmfTraceContext tmpContext = new TmfTraceContext(null, 0);
207 LTTngTextTrace testStream1 = prepareStreamToTest();
208
209 // We should be at the beginning of the trace, we will seek at a certain timestamp
210 tmpContext = testStream1.seekLocation(locationToSeekTest1);
211 tmpEvent = testStream1.getNextEvent(tmpContext);
212 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
213 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
214 assertNotSame("tmpEvent is null after first seekLocation()",null,tmpEvent );
215 assertTrue("tmpEvent has wrong reference after first seekLocation()", ((String)tmpEvent.getReference().getReference()).contains(seek1EventReference) );
216
217 // Seek to the last timestamp
218 tmpContext = testStream1.seekLocation(locationToSeekLast);
219 tmpEvent = testStream1.getNextEvent(tmpContext);
220 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
221 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
222 assertNotSame("tmpEvent is null after seekLocation() to last ",null,tmpEvent );
223 assertTrue("tmpEvent has wrong reference after seekLocation() to last",((String)tmpEvent.getReference().getReference()).contains(seekLastEventReference) );
224
225 // Seek to the first timestamp (startTime)
226 tmpContext = testStream1.seekLocation(locationToSeekFirst);
227 tmpEvent = testStream1.getNextEvent(tmpContext);
228 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
229 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
230 assertNotSame("tmpEvent is null after seekLocation() to start ",null,tmpEvent );
231 assertTrue("tmpEvent has wrong reference after seekLocation() to start",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
232 }
233
234 public void testGetter() {
235 TmfEvent tmpEvent = null;
236 LTTngTextTrace testStream1 = prepareStreamToTest();
237
238 // Move to the first event to have something to play with
239 tmpEvent = testStream1.parseEvent( new TmfTraceContext(null, 0));
240
241 // Test current event
242 assertNotSame("tmpEvent is null after first event",null,tmpEvent );
243 assertTrue("tmpEvent has wrong reference after first event",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
244 assertNotSame("tmpContext is null after first seekEvent()",null,testStream1.getCurrentLocation() );
245 assertEquals("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent,(Long)testStream1.getCurrentLocation() );
246
247 // Test CPU number of the trace
248 assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber ,testStream1.getCpuNumber() );
249 }
250
251 public void testToString() {
252 LTTngTextTrace testStream1 = prepareStreamToTest();
253
254 // Move to the first event to have something to play with
255 testStream1.parseEvent( new TmfTraceContext(null, 0) );
256
257 // Just make sure toString() does not return null or the java reference
258 assertNotSame("toString returned null",null, testStream1.toString() );
259 assertNotSame("toString is not overridded!", testStream1.getClass().getName() + '@' + Integer.toHexString(testStream1.hashCode()), testStream1.toString() );
260 }
261
262 }
This page took 0.035561 seconds and 5 git commands to generate.