Commit | Line | Data |
---|---|---|
03c71d1e ASL |
1 | package org.eclipse.linuxtools.lttng.tests.trace; |
2 | ||
e1ab8984 FC |
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.tests.LTTngCoreTestPlugin; | |
03c71d1e | 11 | import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace; |
9f584e4c | 12 | import org.eclipse.linuxtools.tmf.event.TmfEvent; |
03c71d1e | 13 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; |
9f584e4c FC |
14 | import org.eclipse.linuxtools.tmf.trace.TmfContext; |
15 | import org.eclipse.linuxtools.tmf.trace.TmfLocation; | |
03c71d1e ASL |
16 | |
17 | /* | |
18 | Functions tested here : | |
a5ec08e5 WB |
19 | public LTTngTextTrace(String path) throws Exception |
20 | public LTTngTextTrace(String path, boolean skipIndexing) throws Exception | |
03c71d1e | 21 | |
a5ec08e5 WB |
22 | public TmfTraceContext seekLocation(Object location) { |
23 | public TmfTraceContext seekEvent(TmfTimestamp timestamp) { | |
24 | public TmfTraceContext seekEvent(long position) { | |
03c71d1e | 25 | |
a5ec08e5 WB |
26 | public TmfEvent getNextEvent(TmfTraceContext context) { |
27 | public Object getCurrentLocation() { | |
03c71d1e | 28 | |
a5ec08e5 WB |
29 | public LttngEvent parseEvent(TmfTraceContext context) { |
30 | ||
31 | public int getCpuNumber() { | |
03c71d1e ASL |
32 | */ |
33 | ||
34 | public class LTTngTextTraceTest extends TestCase { | |
35 | ||
36 | private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt"; | |
37 | private final static String wrongTracePath="/somewhere/that/does/not/exist"; | |
38 | ||
a5ec08e5 WB |
39 | private final static int traceCpuNumber=1; |
40 | ||
03c71d1e ASL |
41 | private final static boolean skipIndexing=true; |
42 | ||
9f861850 WB |
43 | private final static long firstEventTimestamp = 13589759412128L; |
44 | private final static long secondEventTimestamp = 13589759419903L; | |
45 | private final static Long locationAfterFirstEvent = 311L; | |
03c71d1e | 46 | |
9f861850 | 47 | private final static String tracename = "traceset/trace-15316events_nolost_newformat"; |
03c71d1e ASL |
48 | |
49 | private final static long indexToSeekFirst = 0; | |
50 | private final static Long locationToSeekFirst = 0L; | |
9f861850 | 51 | private final static long contextValueAfterFirstEvent = 13589759412128L; |
03c71d1e ASL |
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; | |
9f861850 | 57 | private final static long locationToSeekTest1 = 2177044; |
03c71d1e ASL |
58 | private final static long contextValueAfterSeekTest1 = 13589826657302L; |
59 | private final static String seek1EventReference = tracename + "/vm_state_0"; | |
60 | ||
9f861850 | 61 | private final static long timestampToSeekLast = 13589906758692L; |
03c71d1e | 62 | private final static Long indexToSeekLast = 15315L; |
9f861850 WB |
63 | private final static long locationToSeekLast = 4420634; |
64 | private final static long contextValueAfterSeekLast = 13589906758692L; | |
03c71d1e ASL |
65 | private final static String seekLastEventReference = tracename + "/kernel_0"; |
66 | ||
e1ab8984 FC |
67 | private static LTTngTextTrace testStream = null; |
68 | private LTTngTextTrace 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 | LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getPath()); | |
74 | testStream = tmpStream; | |
75 | } | |
76 | catch (Exception e) { | |
77 | System.out.println("ERROR : Could not open " + tracepath1); | |
78 | testStream = null; | |
79 | } | |
03c71d1e | 80 | } |
ccc4dc5b WB |
81 | else { |
82 | testStream.seekEvent(0); | |
83 | } | |
84 | ||
85 | ||
e1ab8984 | 86 | return testStream; |
5fbe0b84 | 87 | } |
e1ab8984 FC |
88 | |
89 | public void testTraceConstructors() { | |
03c71d1e ASL |
90 | @SuppressWarnings("unused") |
91 | LTTngTextTrace testStream1 = null; | |
92 | ||
93 | // Default constructor | |
94 | // Test constructor with argument on a wrong tracepath, skipping indexing | |
95 | try { | |
96 | testStream1 = new LTTngTextTrace(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 { | |
e1ab8984 FC |
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); | |
03c71d1e ASL |
107 | } |
108 | catch( Exception e) { | |
109 | fail("Construction with correct tracepath failed!"); | |
110 | } | |
111 | } | |
112 | ||
113 | public void testGetNextEvent() { | |
114 | TmfEvent tmpEvent = null; | |
115 | LTTngTextTrace testStream1 = prepareStreamToTest(); | |
116 | ||
9f584e4c | 117 | TmfContext tmpContext = new TmfContext(null, 0); |
03c71d1e ASL |
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 | LTTngTextTrace testStream1 = prepareStreamToTest(); | |
132 | ||
9f584e4c | 133 | TmfContext tmpContext = new TmfContext(null, 0); |
03c71d1e ASL |
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; | |
9f584e4c | 147 | TmfContext tmpContext = new TmfContext(null, 0); |
03c71d1e ASL |
148 | LTTngTextTrace testStream1 = prepareStreamToTest(); |
149 | ||
150 | // We should be at the beginning of the trace, we will seek at a certain timestamp | |
e31e01e8 | 151 | tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekTest1, (byte) -9, 0)); |
03c71d1e ASL |
152 | tmpEvent = testStream1.getNextEvent(tmpContext); |
153 | assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext ); | |
e31e01e8 | 154 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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 | |
e31e01e8 | 159 | tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekLast, (byte) -9, 0)); |
03c71d1e ASL |
160 | tmpEvent = testStream1.getNextEvent(tmpContext); |
161 | assertNotSame("tmpContext is null after seekEvent() to last",null,tmpContext ); | |
e31e01e8 | 162 | assertEquals("tmpContext has wrong timestamp after seekEvent() to last",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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) | |
e31e01e8 | 167 | tmpContext = testStream1.seekEvent(new TmfTimestamp(firstEventTimestamp, (byte) -9, 0)); |
03c71d1e ASL |
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 ); | |
e31e01e8 | 172 | assertEquals("tmpContext has wrong timestamp after seekEvent() to first",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
173 | } |
174 | ||
175 | public void testSeekEventIndex() { | |
176 | TmfEvent tmpEvent = null; | |
9f584e4c | 177 | TmfContext tmpContext = new TmfContext(null, 0); |
03c71d1e ASL |
178 | LTTngTextTrace 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 ); | |
2ecaca9d ASL |
184 | assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterSeekTest1, |
185 | (long) ((TmfTimestamp) tmpEvent.getTimestamp()).getValue()); | |
03c71d1e ASL |
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) ); | |
188 | ||
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 ); | |
e31e01e8 | 193 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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) ); | |
196 | ||
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 ); | |
e31e01e8 | 201 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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) ); | |
204 | } | |
205 | ||
206 | public void testSeekLocation() { | |
207 | TmfEvent tmpEvent = null; | |
9f584e4c | 208 | TmfContext tmpContext = new TmfContext(null, 0); |
03c71d1e ASL |
209 | LTTngTextTrace testStream1 = prepareStreamToTest(); |
210 | ||
211 | // We should be at the beginning of the trace, we will seek at a certain timestamp | |
9f584e4c | 212 | tmpContext = testStream1.seekLocation(new TmfLocation<Long>(locationToSeekTest1)); |
03c71d1e ASL |
213 | tmpEvent = testStream1.getNextEvent(tmpContext); |
214 | assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext ); | |
e31e01e8 | 215 | assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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) ); | |
218 | ||
219 | // Seek to the last timestamp | |
9f584e4c | 220 | tmpContext = testStream1.seekLocation(new TmfLocation<Long>(locationToSeekLast)); |
03c71d1e ASL |
221 | tmpEvent = testStream1.getNextEvent(tmpContext); |
222 | assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext ); | |
e31e01e8 | 223 | assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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) ); | |
226 | ||
227 | // Seek to the first timestamp (startTime) | |
9f584e4c | 228 | tmpContext = testStream1.seekLocation(new TmfLocation<Long>(locationToSeekFirst)); |
03c71d1e ASL |
229 | tmpEvent = testStream1.getNextEvent(tmpContext); |
230 | assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext ); | |
e31e01e8 | 231 | assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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) ); | |
234 | } | |
235 | ||
9f584e4c | 236 | @SuppressWarnings("unchecked") |
03c71d1e ASL |
237 | public void testGetter() { |
238 | TmfEvent tmpEvent = null; | |
239 | LTTngTextTrace testStream1 = prepareStreamToTest(); | |
9f584e4c | 240 | TmfContext tmpContext = new TmfContext(null, 0); |
9f861850 | 241 | |
03c71d1e | 242 | // Move to the first event to have something to play with |
9f861850 | 243 | tmpEvent = testStream1.parseEvent( tmpContext ); |
03c71d1e ASL |
244 | |
245 | // Test current event | |
246 | assertNotSame("tmpEvent is null after first event",null,tmpEvent ); | |
247 | assertTrue("tmpEvent has wrong reference after first event",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) ); | |
248 | assertNotSame("tmpContext is null after first seekEvent()",null,testStream1.getCurrentLocation() ); | |
452ad365 | 249 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent, ((TmfLocation<Long>) testStream1.getCurrentLocation()).getLocation()); |
a5ec08e5 WB |
250 | // Test CPU number of the trace |
251 | assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber ,testStream1.getCpuNumber() ); | |
03c71d1e ASL |
252 | } |
253 | ||
254 | public void testToString() { | |
255 | LTTngTextTrace testStream1 = prepareStreamToTest(); | |
256 | ||
257 | // Move to the first event to have something to play with | |
9f584e4c | 258 | testStream1.parseEvent( new TmfContext(null, 0) ); |
03c71d1e ASL |
259 | |
260 | // Just make sure toString() does not return null or the java reference | |
261 | assertNotSame("toString returned null",null, testStream1.toString() ); | |
262 | assertNotSame("toString is not overridded!", testStream1.getClass().getName() + '@' + Integer.toHexString(testStream1.hashCode()), testStream1.toString() ); | |
263 | } | |
264 | ||
265 | } |