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