Commit | Line | Data |
---|---|---|
6c13869b | 1 | package org.eclipse.linuxtools.lttng.core.tests.trace; |
03c71d1e | 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; | |
5945cec9 | 10 | import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTextTrace; |
6c13869b | 11 | import org.eclipse.linuxtools.lttng.core.tests.LTTngCoreTestPlugin; |
72f1e62a | 12 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
6c13869b | 13 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; |
3791b5df | 14 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
6c13869b FC |
15 | import org.eclipse.linuxtools.tmf.core.trace.TmfContext; |
16 | import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; | |
03c71d1e ASL |
17 | |
18 | /* | |
19 | Functions tested here : | |
29465de6 FC |
20 | public LTTngTextTrace(String path) throws Exception |
21 | public LTTngTextTrace(String path, boolean skipIndexing) throws Exception | |
22 | ||
23 | public TmfTraceContext seekLocation(Object location) { | |
24 | public TmfTraceContext seekEvent(TmfTimestamp timestamp) { | |
25 | public TmfTraceContext seekEvent(long position) { | |
26 | ||
27 | public TmfEvent getNextEvent(TmfTraceContext context) { | |
28 | public Object getCurrentLocation() { | |
29 | ||
30 | public LttngEvent parseEvent(TmfTraceContext context) { | |
31 | ||
32 | public int getCpuNumber() { | |
03c71d1e ASL |
33 | */ |
34 | ||
3b38ea61 | 35 | @SuppressWarnings("nls") |
03c71d1e | 36 | public class LTTngTextTraceTest extends TestCase { |
29465de6 FC |
37 | |
38 | private final static String tracepath1 = "traceset/trace-15316events_nolost_newformat.txt"; | |
39 | private final static String wrongTracePath = "/somewhere/that/does/not/exist"; | |
40 | ||
41 | private final static int traceCpuNumber = 1; | |
42 | ||
43 | private final static boolean skipIndexing = true; | |
44 | ||
45 | private final static long firstEventTimestamp = 13589759412128L; | |
46 | private final static long secondEventTimestamp = 13589759419903L; | |
47 | private final static Long locationAfterFirstEvent = 311L; | |
48 | ||
9f861850 | 49 | private final static String tracename = "traceset/trace-15316events_nolost_newformat"; |
29465de6 FC |
50 | |
51 | private final static long indexToSeekFirst = 0; | |
52 | private final static Long locationToSeekFirst = 0L; | |
53 | private final static long contextValueAfterFirstEvent = 13589759412128L; | |
03c71d1e | 54 | private final static String firstEventReference = tracename + "/metadata_0"; |
29465de6 FC |
55 | |
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"; | |
61 | ||
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"; | |
03c71d1e | 67 | |
e1ab8984 | 68 | private static LTTngTextTrace testStream = null; |
29465de6 FC |
69 | |
70 | private synchronized LTTngTextTrace prepareStreamToTest() { | |
71 | if (testStream == null) { | |
72 | try { | |
73 | URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null); | |
74 | File testfile = new File(FileLocator.toFileURL(location).toURI()); | |
0710697b | 75 | LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getName(), testfile.getPath()); |
29465de6 FC |
76 | testStream = tmpStream; |
77 | } catch (Exception e) { | |
78 | System.out.println("ERROR : Could not open " + tracepath1); | |
79 | testStream = null; | |
80 | } | |
81 | } else { | |
82 | testStream.seekEvent(0); | |
03c71d1e | 83 | } |
29465de6 FC |
84 | |
85 | return testStream; | |
86 | } | |
87 | ||
88 | public void testTraceConstructorFailure() { | |
89 | // Default constructor | |
90 | // Test constructor with argument on a wrong tracepath, skipping | |
91 | // indexing | |
92 | try { | |
0710697b | 93 | LTTngTextTrace testStream = new LTTngTextTrace("wrong", wrongTracePath, skipIndexing); |
29465de6 FC |
94 | fail("Construction with wrong tracepath should fail!"); |
95 | testStream.dispose(); | |
96 | } catch (Exception e) { | |
03c71d1e | 97 | } |
29465de6 FC |
98 | } |
99 | /* | |
100 | public void testTraceConstructor() { | |
101 | // Test constructor with argument on a correct tracepath, skipping | |
102 | // indexing | |
03c71d1e | 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()); | |
29465de6 FC |
106 | LTTngTextTrace testStream = new LTTngTextTrace(testfile.getPath(), skipIndexing); |
107 | testStream.dispose(); | |
108 | } catch (Exception e) { | |
109 | fail("Construction with correct tracepath failed!"); | |
03c71d1e | 110 | } |
03c71d1e | 111 | } |
29465de6 FC |
112 | */ |
113 | public void testGetNextEvent() { | |
72f1e62a | 114 | ITmfEvent tmpEvent = null; |
29465de6 FC |
115 | LTTngTextTrace 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 | |
119 | // 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, tmpEvent.getTimestamp().getValue()); | |
123 | ||
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()); | |
03c71d1e | 128 | } |
29465de6 FC |
129 | |
130 | public void testParseEvent() { | |
72f1e62a | 131 | ITmfEvent tmpEvent = null; |
29465de6 FC |
132 | LTTngTextTrace testStream1 = prepareStreamToTest(); |
133 | ||
134 | TmfContext tmpContext = new TmfContext(null, 0); | |
135 | // We should be at the beginning of the trace, so we will just parse the | |
136 | // first event now | |
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()); | |
140 | ||
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()); | |
145 | } | |
146 | ||
147 | public void testSeekEventTimestamp() { | |
72f1e62a | 148 | ITmfEvent tmpEvent = null; |
3791b5df | 149 | ITmfContext tmpContext = new TmfContext(null, 0); |
29465de6 FC |
150 | LTTngTextTrace testStream1 = prepareStreamToTest(); |
151 | ||
152 | // We should be at the beginning of the trace, we will seek at a certain | |
153 | // timestamp | |
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); | |
4641c2f7 | 159 | assertTrue("tmpEvent has wrong reference after first seekEvent()", seek1EventReference.contains((String) tmpEvent.getReference())); |
29465de6 FC |
160 | |
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); | |
4641c2f7 | 167 | assertTrue("tmpEvent has wrong reference after seekEvent() to last", seekLastEventReference.contains((String) tmpEvent.getReference())); |
29465de6 FC |
168 | |
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); | |
4641c2f7 | 173 | assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference.contains((String) tmpEvent.getReference())); |
29465de6 FC |
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()); | |
176 | } | |
177 | ||
178 | public void testSeekEventIndex() { | |
72f1e62a | 179 | ITmfEvent tmpEvent = null; |
3791b5df | 180 | ITmfContext tmpContext = new TmfContext(null, 0); |
29465de6 FC |
181 | LTTngTextTrace testStream1 = prepareStreamToTest(); |
182 | ||
183 | // We should be at the beginning of the trace, we will seek at a certain | |
184 | // timestamp | |
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); | |
4641c2f7 | 190 | assertTrue("tmpEvent has wrong reference after first seekEvent()", seek1EventReference.contains((String) tmpEvent.getReference())); |
29465de6 FC |
191 | |
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); | |
4641c2f7 | 198 | assertTrue("tmpEvent has wrong reference after seekEvent() to last", seekLastEventReference.contains((String) tmpEvent.getReference())); |
29465de6 FC |
199 | |
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); | |
4641c2f7 | 206 | assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference.contains((String) tmpEvent.getReference())); |
29465de6 FC |
207 | } |
208 | ||
209 | public void testSeekLocation() { | |
72f1e62a | 210 | ITmfEvent tmpEvent = null; |
29465de6 FC |
211 | TmfContext tmpContext = new TmfContext(null, 0); |
212 | LTTngTextTrace testStream1 = prepareStreamToTest(); | |
213 | ||
214 | // We should be at the beginning of the trace, we will seek at a certain | |
215 | // timestamp | |
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); | |
4641c2f7 | 221 | assertTrue("tmpEvent has wrong reference after first seekLocation()", seek1EventReference.contains((String) tmpEvent.getReference())); |
29465de6 FC |
222 | |
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); | |
4641c2f7 | 229 | assertTrue("tmpEvent has wrong reference after seekLocation() to last", seekLastEventReference.contains((String) tmpEvent.getReference())); |
29465de6 FC |
230 | |
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); | |
4641c2f7 | 237 | assertTrue("tmpEvent has wrong reference after seekLocation() to start", firstEventReference.contains((String) tmpEvent.getReference())); |
29465de6 FC |
238 | } |
239 | ||
240 | @SuppressWarnings("unchecked") | |
241 | public void testGetter() { | |
72f1e62a | 242 | ITmfEvent tmpEvent = null; |
29465de6 FC |
243 | LTTngTextTrace testStream1 = prepareStreamToTest(); |
244 | TmfContext tmpContext = new TmfContext(null, 0); | |
245 | ||
246 | // Move to the first event to have something to play with | |
247 | tmpEvent = testStream1.parseEvent(tmpContext); | |
248 | ||
249 | // Test current event | |
250 | assertNotSame("tmpEvent is null after first event", null, tmpEvent); | |
4641c2f7 | 251 | assertTrue("tmpEvent has wrong reference after first event", firstEventReference.contains((String) tmpEvent.getReference())); |
29465de6 FC |
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()); | |
256 | } | |
257 | ||
258 | public void testToString() { | |
259 | LTTngTextTrace testStream1 = prepareStreamToTest(); | |
260 | ||
261 | // Move to the first event to have something to play with | |
262 | testStream1.parseEvent(new TmfContext(null, 0)); | |
263 | ||
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()); | |
267 | } | |
268 | ||
03c71d1e | 269 | } |