Commit | Line | Data |
---|---|---|
95bf10e7 | 1 | /******************************************************************************* |
da707390 | 2 | * Copyright (c) 2012, 2015 Ericsson |
95bf10e7 AM |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Matthew Khouzam - Initial generation with CodePro tools | |
11 | * Alexandre Montplaisir - Clean up, consolidate redundant tests | |
4a1f6c41 | 12 | * Patrick Tasse - Fix location ratio |
95bf10e7 AM |
13 | *******************************************************************************/ |
14 | ||
9722e5d7 | 15 | package org.eclipse.tracecompass.tmf.ctf.core.tests.trace; |
81c8e6f7 MK |
16 | |
17 | import static org.junit.Assert.assertEquals; | |
3480bf12 | 18 | import static org.junit.Assert.assertFalse; |
81c8e6f7 MK |
19 | import static org.junit.Assert.assertNotNull; |
20 | import static org.junit.Assert.assertNull; | |
21 | import static org.junit.Assert.assertTrue; | |
5dd1fa65 | 22 | import static org.junit.Assume.assumeTrue; |
81c8e6f7 | 23 | |
409bea20 GB |
24 | import java.util.Arrays; |
25 | import java.util.HashSet; | |
26 | import java.util.Set; | |
27 | ||
81c8e6f7 MK |
28 | import org.eclipse.core.resources.IProject; |
29 | import org.eclipse.core.resources.IResource; | |
a94410d9 | 30 | import org.eclipse.core.runtime.IStatus; |
2bdf0193 AM |
31 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventType; |
32 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; | |
33 | import org.eclipse.tracecompass.tmf.core.signal.TmfEndSynchSignal; | |
34 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignal; | |
35 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; | |
da707390 | 36 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp; |
2bdf0193 AM |
37 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; |
38 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; | |
39 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; | |
40 | import org.eclipse.tracecompass.tmf.core.trace.TmfEventTypeCollectionHelper; | |
9722e5d7 AM |
41 | import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation; |
42 | import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo; | |
43 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; | |
2bdf0193 | 44 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace; |
9722e5d7 | 45 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
81c8e6f7 MK |
46 | import org.junit.After; |
47 | import org.junit.Before; | |
48 | import org.junit.Test; | |
49 | ||
50 | /** | |
95bf10e7 AM |
51 | * The class <code>CtfTmfTraceTest</code> contains tests for the class |
52 | * <code>{@link CtfTmfTrace}</code>. | |
81c8e6f7 | 53 | * |
81c8e6f7 | 54 | * @author ematkho |
95bf10e7 | 55 | * @version 1.0 |
81c8e6f7 MK |
56 | */ |
57 | public class CtfTmfTraceTest { | |
95bf10e7 | 58 | |
9ac63b5b | 59 | private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL; |
81c8e6f7 | 60 | |
95bf10e7 AM |
61 | private CtfTmfTrace fixture; |
62 | ||
95bf10e7 AM |
63 | /** |
64 | * Perform pre-test initialization. | |
81c8e6f7 | 65 | * |
95bf10e7 AM |
66 | * @throws TmfTraceException |
67 | * If the test trace is not found | |
81c8e6f7 | 68 | */ |
95bf10e7 AM |
69 | @Before |
70 | public void setUp() throws TmfTraceException { | |
9ac63b5b | 71 | assumeTrue(testTrace.exists()); |
95bf10e7 | 72 | fixture = new CtfTmfTrace(); |
9ac63b5b | 73 | fixture.initTrace((IResource) null, testTrace.getPath(), CtfTmfEvent.class); |
95bf10e7 | 74 | } |
81c8e6f7 | 75 | |
95bf10e7 AM |
76 | /** |
77 | * Perform post-test clean-up. | |
78 | */ | |
79 | @After | |
80 | public void tearDown() { | |
5dd1fa65 AM |
81 | if (fixture != null) { |
82 | fixture.dispose(); | |
83 | } | |
95bf10e7 AM |
84 | } |
85 | ||
86 | /** | |
87 | * Run the CtfTmfTrace() constructor test. | |
88 | */ | |
89 | @Test | |
90 | public void testCtfTmfTrace() { | |
090c006e AM |
91 | try (CtfTmfTrace result = new CtfTmfTrace();) { |
92 | assertNotNull(result); | |
090c006e AM |
93 | assertEquals(1000, result.getCacheSize()); |
94 | assertEquals(0L, result.getNbEvents()); | |
95 | assertEquals(0L, result.getStreamingInterval()); | |
96 | assertNull(result.getResource()); | |
97 | assertNull(result.getType()); | |
98 | } | |
81c8e6f7 MK |
99 | } |
100 | ||
95bf10e7 AM |
101 | /** |
102 | * Test the parseEvent() method | |
103 | */ | |
788ddcbc | 104 | @Test |
95bf10e7 | 105 | public void testParseEvent() { |
788ddcbc MK |
106 | ITmfContext ctx = fixture.seekEvent(0); |
107 | fixture.getNext(ctx); | |
108 | CtfTmfEvent event = fixture.parseEvent(ctx); | |
109 | assertNotNull(event); | |
4a1f6c41 | 110 | ctx.dispose(); |
788ddcbc MK |
111 | } |
112 | ||
81c8e6f7 MK |
113 | /** |
114 | * Run the void broadcast(TmfSignal) method test. | |
81c8e6f7 MK |
115 | */ |
116 | @Test | |
95bf10e7 | 117 | public void testBroadcast() { |
81c8e6f7 | 118 | TmfSignal signal = new TmfEndSynchSignal(1); |
81c8e6f7 | 119 | fixture.broadcast(signal); |
81c8e6f7 MK |
120 | } |
121 | ||
409bea20 GB |
122 | /** |
123 | * Run the void dispose() method test. | |
124 | */ | |
125 | @Test | |
126 | public void testClose() { | |
127 | try (CtfTmfTrace emptyFixture = new CtfTmfTrace();) { | |
128 | } | |
129 | } | |
130 | ||
81c8e6f7 MK |
131 | /** |
132 | * Run the int getCacheSize() method test. | |
81c8e6f7 MK |
133 | */ |
134 | @Test | |
95bf10e7 | 135 | public void testGetCacheSize() { |
090c006e AM |
136 | try (CtfTmfTrace emptyFixture = new CtfTmfTrace();) { |
137 | int result = emptyFixture.getCacheSize(); | |
138 | assertEquals(1000, result); | |
139 | } | |
81c8e6f7 MK |
140 | } |
141 | ||
142 | /** | |
143 | * Run the ITmfLocation<Comparable> getCurrentLocation() method test. | |
81c8e6f7 MK |
144 | */ |
145 | @Test | |
95bf10e7 | 146 | public void testGetCurrentLocation() { |
81c8e6f7 | 147 | CtfLocation result = (CtfLocation) fixture.getCurrentLocation(); |
f474d36b | 148 | assertNull(result); |
81c8e6f7 MK |
149 | } |
150 | ||
95bf10e7 AM |
151 | /** |
152 | * Test the seekEvent() method with a null location. | |
153 | */ | |
81c8e6f7 | 154 | @Test |
95bf10e7 | 155 | public void testSeekEventLoc_null() { |
81c8e6f7 MK |
156 | CtfLocation loc = null; |
157 | fixture.seekEvent(loc); | |
158 | assertNotNull(fixture); | |
159 | } | |
160 | ||
95bf10e7 AM |
161 | /** |
162 | * Test the seekEvent() method with a location from a timestamp. | |
163 | */ | |
81c8e6f7 | 164 | @Test |
409bea20 | 165 | public void testSeekEventLoc_timetamp() { |
da707390 | 166 | CtfLocation loc = new CtfLocation(new TmfNanoTimestamp(0L)); |
81c8e6f7 MK |
167 | fixture.seekEvent(loc); |
168 | assertNotNull(fixture); | |
169 | } | |
170 | ||
81c8e6f7 MK |
171 | /** |
172 | * Run the ITmfTimestamp getEndTime() method test. | |
81c8e6f7 MK |
173 | */ |
174 | @Test | |
95bf10e7 | 175 | public void testGetEndTime() { |
81c8e6f7 MK |
176 | ITmfTimestamp result = fixture.getEndTime(); |
177 | assertNotNull(result); | |
178 | } | |
179 | ||
180 | /** | |
299e494e | 181 | * Run the String getEnvironment method test. |
81c8e6f7 MK |
182 | */ |
183 | @Test | |
95bf10e7 | 184 | public void testGetEnvValue() { |
cad06250 | 185 | String key = "tracer_name"; |
22307af3 | 186 | String result = fixture.getTraceProperties().get(key); |
409bea20 | 187 | assertEquals("\"lttng-modules\"", result); |
81c8e6f7 MK |
188 | } |
189 | ||
190 | /** | |
409bea20 | 191 | * Test the {@link CtfTmfTrace#getEventType()} method. |
81c8e6f7 MK |
192 | */ |
193 | @Test | |
95bf10e7 | 194 | public void testGetEventType() { |
409bea20 GB |
195 | Class<?> result = fixture.getEventType(); |
196 | assertNotNull(result); | |
197 | assertEquals(CtfTmfEvent.class, result); | |
198 | } | |
199 | ||
200 | /** | |
201 | * Run the Class<CtfTmfEvent> getContainedEventTypes() method test. | |
202 | */ | |
203 | @Test | |
204 | public void testGetContainedEventTypes() { | |
e600c338 | 205 | Set<? extends ITmfEventType> result = fixture.getContainedEventTypes(); |
bfe038ff | 206 | assertNotNull(result); |
409bea20 | 207 | assertFalse(result.isEmpty()); |
81c8e6f7 MK |
208 | } |
209 | ||
210 | /** | |
211 | * Run the double getLocationRatio(ITmfLocation<?>) method test. | |
81c8e6f7 MK |
212 | */ |
213 | @Test | |
95bf10e7 | 214 | public void testGetLocationRatio() { |
4a1f6c41 PT |
215 | ITmfContext context = fixture.seekEvent(0); |
216 | long t1 = ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp(); | |
217 | fixture.getNext(context); | |
218 | long t2 = ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp(); | |
219 | fixture.getNext(context); | |
220 | long t3 = ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp(); | |
221 | fixture.getNext(context); | |
222 | context.dispose(); | |
223 | double ratio1 = fixture.getLocationRatio(new CtfLocation(t1, 0)); | |
224 | assertEquals(0.0, ratio1, 0.01); | |
225 | double ratio2 = fixture.getLocationRatio(new CtfLocation(t2, 0)); | |
226 | assertEquals((double) (t2 - t1) / (t3 - t1), ratio2, 0.01); | |
227 | double ratio3 = fixture.getLocationRatio(new CtfLocation(t3, 0)); | |
228 | assertEquals(1.0, ratio3, 0.01); | |
81c8e6f7 MK |
229 | } |
230 | ||
231 | /** | |
232 | * Run the String getName() method test. | |
81c8e6f7 MK |
233 | */ |
234 | @Test | |
95bf10e7 | 235 | public void testGetName() { |
81c8e6f7 | 236 | String result = fixture.getName(); |
81c8e6f7 MK |
237 | assertNotNull(result); |
238 | } | |
239 | ||
240 | /** | |
2db2b43a | 241 | * Run the getTraceProperties() method test. |
81c8e6f7 MK |
242 | */ |
243 | @Test | |
2db2b43a | 244 | public void testGetTraceProperties() { |
22307af3 | 245 | int result = fixture.getTraceProperties().size(); |
2db2b43a | 246 | assertEquals(9, result); |
81c8e6f7 MK |
247 | } |
248 | ||
249 | /** | |
250 | * Run the long getNbEvents() method test. | |
81c8e6f7 MK |
251 | */ |
252 | @Test | |
95bf10e7 | 253 | public void testGetNbEvents() { |
81c8e6f7 | 254 | long result = fixture.getNbEvents(); |
132a02b0 | 255 | assertEquals(1L, result); |
81c8e6f7 MK |
256 | } |
257 | ||
258 | /** | |
259 | * Run the CtfTmfEvent getNext(ITmfContext) method test. | |
81c8e6f7 MK |
260 | */ |
261 | @Test | |
95bf10e7 | 262 | public void testGetNext() { |
f474d36b | 263 | ITmfContext context = fixture.seekEvent(0); |
81c8e6f7 | 264 | CtfTmfEvent result = fixture.getNext(context); |
81c8e6f7 | 265 | assertNotNull(result); |
4a1f6c41 | 266 | context.dispose(); |
81c8e6f7 MK |
267 | } |
268 | ||
269 | /** | |
270 | * Run the String getPath() method test. | |
81c8e6f7 MK |
271 | */ |
272 | @Test | |
95bf10e7 | 273 | public void testGetPath() { |
81c8e6f7 | 274 | String result = fixture.getPath(); |
81c8e6f7 MK |
275 | assertNotNull(result); |
276 | } | |
277 | ||
278 | /** | |
279 | * Run the IResource getResource() method test. | |
81c8e6f7 MK |
280 | */ |
281 | @Test | |
95bf10e7 | 282 | public void testGetResource() { |
81c8e6f7 | 283 | IResource result = fixture.getResource(); |
81c8e6f7 MK |
284 | assertNull(result); |
285 | } | |
286 | ||
287 | /** | |
288 | * Run the ITmfTimestamp getStartTime() method test. | |
81c8e6f7 MK |
289 | */ |
290 | @Test | |
95bf10e7 | 291 | public void testGetStartTime() { |
81c8e6f7 | 292 | ITmfTimestamp result = fixture.getStartTime(); |
81c8e6f7 MK |
293 | assertNotNull(result); |
294 | } | |
295 | ||
81c8e6f7 MK |
296 | /** |
297 | * Run the long getStreamingInterval() method test. | |
81c8e6f7 MK |
298 | */ |
299 | @Test | |
95bf10e7 | 300 | public void testGetStreamingInterval() { |
81c8e6f7 | 301 | long result = fixture.getStreamingInterval(); |
81c8e6f7 MK |
302 | assertEquals(0L, result); |
303 | } | |
304 | ||
305 | /** | |
306 | * Run the TmfTimeRange getTimeRange() method test. | |
81c8e6f7 MK |
307 | */ |
308 | @Test | |
95bf10e7 | 309 | public void testGetTimeRange() { |
81c8e6f7 | 310 | TmfTimeRange result = fixture.getTimeRange(); |
81c8e6f7 MK |
311 | assertNotNull(result); |
312 | } | |
313 | ||
81c8e6f7 MK |
314 | /** |
315 | * Run the CtfTmfEvent readNextEvent(ITmfContext) method test. | |
81c8e6f7 MK |
316 | */ |
317 | @Test | |
95bf10e7 | 318 | public void testReadNextEvent() { |
f474d36b | 319 | ITmfContext context = fixture.seekEvent(0); |
c32744d6 | 320 | CtfTmfEvent result = fixture.getNext(context); |
81c8e6f7 | 321 | assertNotNull(result); |
4a1f6c41 | 322 | context.dispose(); |
81c8e6f7 MK |
323 | } |
324 | ||
325 | /** | |
326 | * Run the ITmfContext seekEvent(double) method test. | |
81c8e6f7 MK |
327 | */ |
328 | @Test | |
95bf10e7 | 329 | public void testSeekEvent_ratio() { |
4a1f6c41 PT |
330 | ITmfContext context = fixture.seekEvent(0); |
331 | long t1 = ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp(); | |
332 | fixture.getNext(context); | |
333 | long t2 = ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp(); | |
334 | fixture.getNext(context); | |
335 | long t3 = ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp(); | |
336 | fixture.getNext(context); | |
337 | context.dispose(); | |
338 | context = fixture.seekEvent(0.0); | |
339 | assertEquals(t1, ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp()); | |
340 | context.dispose(); | |
341 | context = fixture.seekEvent(0.5); | |
342 | assertEquals(t2, ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp()); | |
343 | context.dispose(); | |
344 | context = fixture.seekEvent(1.0); | |
345 | assertEquals(t3, ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp()); | |
346 | context.dispose(); | |
81c8e6f7 MK |
347 | } |
348 | ||
349 | /** | |
350 | * Run the ITmfContext seekEvent(long) method test. | |
81c8e6f7 MK |
351 | */ |
352 | @Test | |
95bf10e7 | 353 | public void testSeekEvent_rank() { |
81c8e6f7 | 354 | long rank = 1L; |
81c8e6f7 | 355 | ITmfContext result = fixture.seekEvent(rank); |
81c8e6f7 | 356 | assertNotNull(result); |
4a1f6c41 | 357 | result.dispose(); |
81c8e6f7 MK |
358 | } |
359 | ||
360 | /** | |
361 | * Run the ITmfContext seekEvent(ITmfTimestamp) method test. | |
81c8e6f7 MK |
362 | */ |
363 | @Test | |
95bf10e7 | 364 | public void testSeekEvent_timestamp() { |
81c8e6f7 | 365 | ITmfTimestamp timestamp = new TmfTimestamp(); |
81c8e6f7 | 366 | ITmfContext result = fixture.seekEvent(timestamp); |
81c8e6f7 | 367 | assertNotNull(result); |
4a1f6c41 | 368 | result.dispose(); |
81c8e6f7 MK |
369 | } |
370 | ||
81c8e6f7 | 371 | /** |
95bf10e7 | 372 | * Run the ITmfContext seekEvent(ITmfLocation<?>) method test. |
81c8e6f7 MK |
373 | */ |
374 | @Test | |
95bf10e7 | 375 | public void testSeekEvent_location() { |
f5df94f8 | 376 | final CtfLocationInfo location2 = new CtfLocationInfo(1L, 0L); |
132a02b0 | 377 | CtfLocation ctfLocation = new CtfLocation(location2); |
95bf10e7 AM |
378 | ITmfContext result = fixture.seekEvent(ctfLocation); |
379 | assertNotNull(result); | |
4a1f6c41 | 380 | result.dispose(); |
81c8e6f7 MK |
381 | } |
382 | ||
383 | /** | |
384 | * Run the boolean validate(IProject,String) method test. | |
81c8e6f7 MK |
385 | */ |
386 | @Test | |
95bf10e7 | 387 | public void testValidate() { |
81c8e6f7 | 388 | IProject project = null; |
9ac63b5b | 389 | IStatus result = fixture.validate(project, testTrace.getPath()); |
a94410d9 | 390 | assertTrue(result.isOK()); |
81c8e6f7 | 391 | } |
3480bf12 GB |
392 | |
393 | /** | |
394 | * Run the boolean hasEvent(final String) method test | |
395 | */ | |
396 | @Test | |
397 | public void testEventLookup() { | |
e600c338 | 398 | Set<? extends ITmfEventType> eventTypes = fixture.getContainedEventTypes(); |
409bea20 GB |
399 | Set<String> eventNames = TmfEventTypeCollectionHelper.getEventNames(eventTypes); |
400 | assertTrue(eventNames.contains("sched_switch")); | |
401 | assertFalse(eventNames.contains("Sched_switch")); | |
3480bf12 | 402 | String[] events = { "sched_switch", "sched_wakeup", "timer_init" }; |
409bea20 GB |
403 | assertTrue(eventNames.containsAll(Arrays.asList(events))); |
404 | Set<String> copy = new HashSet<>(eventNames); | |
405 | copy.retainAll(Arrays.asList(events)); | |
406 | assertFalse(copy.isEmpty()); | |
3480bf12 | 407 | String[] names = { "inexistent", "sched_switch", "SomeThing" }; |
409bea20 GB |
408 | copy = new HashSet<>(eventNames); |
409 | copy.retainAll(Arrays.asList(names)); | |
410 | assertTrue(!copy.isEmpty()); | |
411 | assertFalse(eventNames.containsAll(Arrays.asList(names))); | |
3480bf12 | 412 | } |
bb52f9bc GB |
413 | |
414 | /** | |
415 | * Run the String getHostId() method test | |
416 | */ | |
417 | @Test | |
418 | public void testCtfHostId() { | |
419 | String a = fixture.getHostId(); | |
420 | assertEquals("\"84db105b-b3f4-4821-b662-efc51455106a\"", a); | |
421 | } | |
422 | ||
2d223a34 | 423 | } |