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