Commit | Line | Data |
---|---|---|
03c71d1e ASL |
1 | package org.eclipse.linuxtools.lttng.tests.trace; |
2 | ||
a5ec08e5 | 3 | import org.eclipse.linuxtools.tmf.event.TmfEvent; |
e1ab8984 FC |
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; | |
03c71d1e | 12 | import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace; |
03c71d1e | 13 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; |
86de1b08 | 14 | import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; |
03c71d1e ASL |
15 | |
16 | /* | |
17 | Functions tested here : | |
a5ec08e5 WB |
18 | public LTTngTextTrace(String path) throws Exception |
19 | public LTTngTextTrace(String path, boolean skipIndexing) throws Exception | |
03c71d1e | 20 | |
a5ec08e5 WB |
21 | public TmfTraceContext seekLocation(Object location) { |
22 | public TmfTraceContext seekEvent(TmfTimestamp timestamp) { | |
23 | public TmfTraceContext seekEvent(long position) { | |
03c71d1e | 24 | |
a5ec08e5 WB |
25 | public TmfEvent getNextEvent(TmfTraceContext context) { |
26 | public Object getCurrentLocation() { | |
03c71d1e | 27 | |
a5ec08e5 WB |
28 | public LttngEvent parseEvent(TmfTraceContext context) { |
29 | ||
30 | public int getCpuNumber() { | |
03c71d1e ASL |
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 | ||
a5ec08e5 WB |
38 | private final static int traceCpuNumber=1; |
39 | ||
03c71d1e ASL |
40 | private final static boolean skipIndexing=true; |
41 | ||
ac9e91f4 WB |
42 | private final static long firstEventTimestamp = 13589759412127L; |
43 | private final static long secondEventTimestamp = 13589759419902L; | |
44 | private final static Long locationAfterFirstEvent = 245L; | |
03c71d1e | 45 | |
ac9e91f4 | 46 | private final static String tracename = "traceset/trace_15316events_nolost_newformat"; |
03c71d1e ASL |
47 | |
48 | private final static long indexToSeekFirst = 0; | |
49 | private final static Long locationToSeekFirst = 0L; | |
ac9e91f4 | 50 | private final static long contextValueAfterFirstEvent = 13589759412127L; |
03c71d1e ASL |
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; | |
ac9e91f4 | 56 | private final static long locationToSeekTest1 = 1682942; |
03c71d1e ASL |
57 | private final static long contextValueAfterSeekTest1 = 13589826657302L; |
58 | private final static String seek1EventReference = tracename + "/vm_state_0"; | |
59 | ||
ac9e91f4 | 60 | private final static long timestampToSeekLast = 13589906758691L; |
03c71d1e | 61 | private final static Long indexToSeekLast = 15315L; |
ac9e91f4 WB |
62 | private final static long locationToSeekLast = 3410544; |
63 | private final static long contextValueAfterSeekLast = 13589906758691L; | |
03c71d1e ASL |
64 | private final static String seekLastEventReference = tracename + "/kernel_0"; |
65 | ||
e1ab8984 FC |
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 | } | |
03c71d1e | 79 | } |
ccc4dc5b WB |
80 | else { |
81 | testStream.seekEvent(0); | |
82 | } | |
83 | ||
84 | ||
e1ab8984 | 85 | return testStream; |
5fbe0b84 | 86 | } |
e1ab8984 FC |
87 | |
88 | public void testTraceConstructors() { | |
03c71d1e ASL |
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 { | |
e1ab8984 FC |
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); | |
03c71d1e ASL |
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 | ||
e31e01e8 | 116 | TmfTraceContext tmpContext = new TmfTraceContext(null, 0); |
03c71d1e ASL |
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 | ||
e31e01e8 | 132 | TmfTraceContext tmpContext = new TmfTraceContext(null, 0); |
03c71d1e ASL |
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; | |
e31e01e8 | 146 | TmfTraceContext tmpContext = new TmfTraceContext(null, 0); |
03c71d1e ASL |
147 | LTTngTextTrace testStream1 = prepareStreamToTest(); |
148 | ||
149 | // We should be at the beginning of the trace, we will seek at a certain timestamp | |
e31e01e8 | 150 | tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekTest1, (byte) -9, 0)); |
03c71d1e ASL |
151 | tmpEvent = testStream1.getNextEvent(tmpContext); |
152 | assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext ); | |
e31e01e8 | 153 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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 | |
e31e01e8 | 158 | tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekLast, (byte) -9, 0)); |
03c71d1e ASL |
159 | tmpEvent = testStream1.getNextEvent(tmpContext); |
160 | assertNotSame("tmpContext is null after seekEvent() to last",null,tmpContext ); | |
e31e01e8 | 161 | assertEquals("tmpContext has wrong timestamp after seekEvent() to last",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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) | |
e31e01e8 | 166 | tmpContext = testStream1.seekEvent(new TmfTimestamp(firstEventTimestamp, (byte) -9, 0)); |
03c71d1e ASL |
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 ); | |
e31e01e8 | 171 | assertEquals("tmpContext has wrong timestamp after seekEvent() to first",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
172 | } |
173 | ||
174 | public void testSeekEventIndex() { | |
175 | TmfEvent tmpEvent = null; | |
e31e01e8 | 176 | TmfTraceContext tmpContext = new TmfTraceContext(null, 0); |
03c71d1e ASL |
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 ); | |
e31e01e8 | 183 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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 ); | |
e31e01e8 | 191 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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 ); | |
e31e01e8 | 199 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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; | |
e31e01e8 | 206 | TmfTraceContext tmpContext = new TmfTraceContext(null, 0); |
03c71d1e ASL |
207 | LTTngTextTrace testStream1 = prepareStreamToTest(); |
208 | ||
209 | // We should be at the beginning of the trace, we will seek at a certain timestamp | |
86de1b08 | 210 | tmpContext = testStream1.seekLocation(locationToSeekTest1); |
03c71d1e ASL |
211 | tmpEvent = testStream1.getNextEvent(tmpContext); |
212 | assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext ); | |
e31e01e8 | 213 | assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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 | |
86de1b08 | 218 | tmpContext = testStream1.seekLocation(locationToSeekLast); |
03c71d1e ASL |
219 | tmpEvent = testStream1.getNextEvent(tmpContext); |
220 | assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext ); | |
e31e01e8 | 221 | assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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) | |
86de1b08 | 226 | tmpContext = testStream1.seekLocation(locationToSeekFirst); |
03c71d1e ASL |
227 | tmpEvent = testStream1.getNextEvent(tmpContext); |
228 | assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext ); | |
e31e01e8 | 229 | assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() ); |
03c71d1e ASL |
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 | ||
03c71d1e ASL |
234 | public void testGetter() { |
235 | TmfEvent tmpEvent = null; | |
236 | LTTngTextTrace testStream1 = prepareStreamToTest(); | |
86de1b08 | 237 | |
03c71d1e | 238 | // Move to the first event to have something to play with |
e31e01e8 | 239 | tmpEvent = testStream1.parseEvent( new TmfTraceContext(null, 0)); |
03c71d1e ASL |
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() ); | |
86de1b08 ASL |
245 | assertEquals("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent,(Long)testStream1.getCurrentLocation() ); |
246 | ||
a5ec08e5 WB |
247 | // Test CPU number of the trace |
248 | assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber ,testStream1.getCpuNumber() ); | |
03c71d1e ASL |
249 | } |
250 | ||
251 | public void testToString() { | |
252 | LTTngTextTrace testStream1 = prepareStreamToTest(); | |
253 | ||
254 | // Move to the first event to have something to play with | |
e31e01e8 | 255 | testStream1.parseEvent( new TmfTraceContext(null, 0) ); |
03c71d1e ASL |
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 | } |