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 | ||
3b38ea61 | 34 | @SuppressWarnings("nls") |
03c71d1e ASL |
35 | public class LTTngTextTraceTest extends TestCase { |
36 | ||
37 | private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt"; | |
38 | private final static String wrongTracePath="/somewhere/that/does/not/exist"; | |
39 | ||
a5ec08e5 WB |
40 | private final static int traceCpuNumber=1; |
41 | ||
03c71d1e ASL |
42 | private final static boolean skipIndexing=true; |
43 | ||
9f861850 WB |
44 | private final static long firstEventTimestamp = 13589759412128L; |
45 | private final static long secondEventTimestamp = 13589759419903L; | |
46 | private final static Long locationAfterFirstEvent = 311L; | |
03c71d1e | 47 | |
9f861850 | 48 | private final static String tracename = "traceset/trace-15316events_nolost_newformat"; |
03c71d1e ASL |
49 | |
50 | private final static long indexToSeekFirst = 0; | |
51 | private final static Long locationToSeekFirst = 0L; | |
9f861850 | 52 | private final static long contextValueAfterFirstEvent = 13589759412128L; |
03c71d1e ASL |
53 | private final static String firstEventReference = tracename + "/metadata_0"; |
54 | ||
55 | ||
56 | private final static long timestampToSeekTest1 = 13589826657302L; | |
57 | private final static Long indexToSeekTest1 = 7497L; | |
9f861850 | 58 | private final static long locationToSeekTest1 = 2177044; |
03c71d1e ASL |
59 | private final static long contextValueAfterSeekTest1 = 13589826657302L; |
60 | private final static String seek1EventReference = tracename + "/vm_state_0"; | |
61 | ||
9f861850 | 62 | private final static long timestampToSeekLast = 13589906758692L; |
03c71d1e | 63 | private final static Long indexToSeekLast = 15315L; |
9f861850 WB |
64 | private final static long locationToSeekLast = 4420634; |
65 | private final static long contextValueAfterSeekLast = 13589906758692L; | |
03c71d1e ASL |
66 | private final static String seekLastEventReference = tracename + "/kernel_0"; |
67 | ||
e1ab8984 FC |
68 | private static LTTngTextTrace testStream = null; |
69 | private LTTngTextTrace prepareStreamToTest() { | |
70 | if (testStream == null) { | |
71 | try { | |
72 | URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null); | |
73 | File testfile = new File(FileLocator.toFileURL(location).toURI()); | |
74 | LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getPath()); | |
75 | testStream = tmpStream; | |
76 | } | |
77 | catch (Exception e) { | |
78 | System.out.println("ERROR : Could not open " + tracepath1); | |
79 | testStream = null; | |
80 | } | |
03c71d1e | 81 | } |
ccc4dc5b WB |
82 | else { |
83 | testStream.seekEvent(0); | |
84 | } | |
85 | ||
86 | ||
e1ab8984 | 87 | return testStream; |
5fbe0b84 | 88 | } |
e1ab8984 FC |
89 | |
90 | public void testTraceConstructors() { | |
03c71d1e ASL |
91 | @SuppressWarnings("unused") |
92 | LTTngTextTrace testStream1 = null; | |
93 | ||
94 | // Default constructor | |
95 | // Test constructor with argument on a wrong tracepath, skipping indexing | |
96 | try { | |
97 | testStream1 = new LTTngTextTrace(wrongTracePath, skipIndexing); | |
98 | fail("Construction with wrong tracepath should fail!"); | |
99 | } | |
100 | catch( Exception e) { | |
101 | } | |
102 | ||
103 | // Test constructor with argument on a correct tracepath, skipping indexing | |
104 | try { | |
e1ab8984 FC |
105 | URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null); |
106 | File testfile = new File(FileLocator.toFileURL(location).toURI()); | |
107 | testStream1 = new LTTngTextTrace(testfile.getPath(), skipIndexing); | |
03c71d1e ASL |
108 | } |
109 | catch( Exception e) { | |
110 | fail("Construction with correct tracepath failed!"); | |
111 | } | |
112 | } | |
113 | ||
114 | public void testGetNextEvent() { | |
115 | TmfEvent tmpEvent = null; | |
116 | LTTngTextTrace testStream1 = prepareStreamToTest(); | |
117 | ||
9f584e4c | 118 | TmfContext tmpContext = new TmfContext(null, 0); |
03c71d1e ASL |
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() ); | |
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,(long)tmpEvent.getTimestamp().getValue() ); | |
128 | } | |
129 | ||
130 | public void testParseEvent() { | |
131 | TmfEvent tmpEvent = null; | |
132 | LTTngTextTrace testStream1 = prepareStreamToTest(); | |
133 | ||
9f584e4c | 134 | TmfContext tmpContext = new TmfContext(null, 0); |
03c71d1e ASL |
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() ); | |
139 | ||
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() ); | |
144 | } | |
145 | ||
146 | public void testSeekEventTimestamp() { | |
147 | TmfEvent tmpEvent = null; | |
9f584e4c | 148 | TmfContext tmpContext = new TmfContext(null, 0); |
03c71d1e ASL |
149 | LTTngTextTrace testStream1 = prepareStreamToTest(); |
150 | ||
151 | // We should be at the beginning of the trace, we will seek at a certain timestamp | |
e31e01e8 | 152 | tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekTest1, (byte) -9, 0)); |
03c71d1e ASL |
153 | tmpEvent = testStream1.getNextEvent(tmpContext); |
154 | assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext ); | |
e31e01e8 | 155 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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) ); | |
158 | ||
159 | // Seek to the last timestamp | |
e31e01e8 | 160 | tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekLast, (byte) -9, 0)); |
03c71d1e ASL |
161 | tmpEvent = testStream1.getNextEvent(tmpContext); |
162 | assertNotSame("tmpContext is null after seekEvent() to last",null,tmpContext ); | |
e31e01e8 | 163 | assertEquals("tmpContext has wrong timestamp after seekEvent() to last",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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) ); | |
166 | ||
167 | // Seek to the first timestamp (startTime) | |
e31e01e8 | 168 | tmpContext = testStream1.seekEvent(new TmfTimestamp(firstEventTimestamp, (byte) -9, 0)); |
03c71d1e ASL |
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 ); | |
e31e01e8 | 173 | assertEquals("tmpContext has wrong timestamp after seekEvent() to first",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
174 | } |
175 | ||
176 | public void testSeekEventIndex() { | |
177 | TmfEvent tmpEvent = null; | |
9f584e4c | 178 | TmfContext tmpContext = new TmfContext(null, 0); |
03c71d1e ASL |
179 | LTTngTextTrace testStream1 = prepareStreamToTest(); |
180 | ||
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 ); | |
2ecaca9d ASL |
185 | assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterSeekTest1, |
186 | (long) ((TmfTimestamp) tmpEvent.getTimestamp()).getValue()); | |
03c71d1e ASL |
187 | assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent ); |
188 | assertTrue("tmpEvent has wrong reference after first seekEvent()", ((String)tmpEvent.getReference().getReference()).contains(seek1EventReference) ); | |
189 | ||
190 | // Seek to the last timestamp | |
191 | tmpContext = testStream1.seekEvent(indexToSeekLast); | |
192 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
193 | assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext ); | |
e31e01e8 | 194 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
195 | assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent ); |
196 | assertTrue("tmpEvent has wrong reference after seekEvent() to last",((String)tmpEvent.getReference().getReference()).contains(seekLastEventReference) ); | |
197 | ||
198 | // Seek to the first timestamp (startTime) | |
199 | tmpContext = testStream1.seekEvent(indexToSeekFirst); | |
200 | tmpEvent = testStream1.getNextEvent(tmpContext); | |
201 | assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext ); | |
e31e01e8 | 202 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
203 | assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent ); |
204 | assertTrue("tmpEvent has wrong reference after seekEvent() to start",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) ); | |
205 | } | |
206 | ||
207 | public void testSeekLocation() { | |
208 | TmfEvent tmpEvent = null; | |
9f584e4c | 209 | TmfContext tmpContext = new TmfContext(null, 0); |
03c71d1e ASL |
210 | LTTngTextTrace testStream1 = prepareStreamToTest(); |
211 | ||
212 | // We should be at the beginning of the trace, we will seek at a certain timestamp | |
9f584e4c | 213 | tmpContext = testStream1.seekLocation(new TmfLocation<Long>(locationToSeekTest1)); |
03c71d1e ASL |
214 | tmpEvent = testStream1.getNextEvent(tmpContext); |
215 | assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext ); | |
e31e01e8 | 216 | assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
217 | assertNotSame("tmpEvent is null after first seekLocation()",null,tmpEvent ); |
218 | assertTrue("tmpEvent has wrong reference after first seekLocation()", ((String)tmpEvent.getReference().getReference()).contains(seek1EventReference) ); | |
219 | ||
220 | // Seek to the last timestamp | |
9f584e4c | 221 | tmpContext = testStream1.seekLocation(new TmfLocation<Long>(locationToSeekLast)); |
03c71d1e ASL |
222 | tmpEvent = testStream1.getNextEvent(tmpContext); |
223 | assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext ); | |
e31e01e8 | 224 | assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
225 | assertNotSame("tmpEvent is null after seekLocation() to last ",null,tmpEvent ); |
226 | assertTrue("tmpEvent has wrong reference after seekLocation() to last",((String)tmpEvent.getReference().getReference()).contains(seekLastEventReference) ); | |
227 | ||
228 | // Seek to the first timestamp (startTime) | |
9f584e4c | 229 | tmpContext = testStream1.seekLocation(new TmfLocation<Long>(locationToSeekFirst)); |
03c71d1e ASL |
230 | tmpEvent = testStream1.getNextEvent(tmpContext); |
231 | assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext ); | |
e31e01e8 | 232 | assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
233 | assertNotSame("tmpEvent is null after seekLocation() to start ",null,tmpEvent ); |
234 | assertTrue("tmpEvent has wrong reference after seekLocation() to start",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) ); | |
235 | } | |
236 | ||
9f584e4c | 237 | @SuppressWarnings("unchecked") |
03c71d1e ASL |
238 | public void testGetter() { |
239 | TmfEvent tmpEvent = null; | |
240 | LTTngTextTrace testStream1 = prepareStreamToTest(); | |
9f584e4c | 241 | TmfContext tmpContext = new TmfContext(null, 0); |
9f861850 | 242 | |
03c71d1e | 243 | // Move to the first event to have something to play with |
9f861850 | 244 | tmpEvent = testStream1.parseEvent( tmpContext ); |
03c71d1e ASL |
245 | |
246 | // Test current event | |
247 | assertNotSame("tmpEvent is null after first event",null,tmpEvent ); | |
248 | assertTrue("tmpEvent has wrong reference after first event",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) ); | |
249 | assertNotSame("tmpContext is null after first seekEvent()",null,testStream1.getCurrentLocation() ); | |
452ad365 | 250 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent, ((TmfLocation<Long>) testStream1.getCurrentLocation()).getLocation()); |
a5ec08e5 WB |
251 | // Test CPU number of the trace |
252 | assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber ,testStream1.getCpuNumber() ); | |
03c71d1e ASL |
253 | } |
254 | ||
255 | public void testToString() { | |
256 | LTTngTextTrace testStream1 = prepareStreamToTest(); | |
257 | ||
258 | // Move to the first event to have something to play with | |
9f584e4c | 259 | testStream1.parseEvent( new TmfContext(null, 0) ); |
03c71d1e ASL |
260 | |
261 | // Just make sure toString() does not return null or the java reference | |
262 | assertNotSame("toString returned null",null, testStream1.toString() ); | |
263 | assertNotSame("toString is not overridded!", testStream1.getClass().getName() + '@' + Integer.toHexString(testStream1.hashCode()), testStream1.toString() ); | |
264 | } | |
265 | ||
266 | } |