1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
10 * Matthew Khouzam - Initial generation with CodePro tools
11 * Alexandre Montplaisir - Clean up, consolidate redundant tests
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.ctfadaptor
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertFalse
;
18 import static org
.junit
.Assert
.assertNotNull
;
19 import static org
.junit
.Assert
.assertNull
;
20 import static org
.junit
.Assert
.assertTrue
;
21 import static org
.junit
.Assume
.assumeTrue
;
23 import org
.eclipse
.core
.resources
.IProject
;
24 import org
.eclipse
.core
.resources
.IResource
;
25 import org
.eclipse
.core
.runtime
.IStatus
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfLocation
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfLocationInfo
;
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
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEndSynchSignal
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignal
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTraces
;
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
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
40 import org
.junit
.After
;
41 import org
.junit
.Before
;
42 import org
.junit
.Test
;
45 * The class <code>CtfTmfTraceTest</code> contains tests for the class
46 * <code>{@link CtfTmfTrace}</code>.
51 public class CtfTmfTraceTest
{
53 private static final int TRACE_INDEX
= 0;
54 private static final String PATH
= CtfTmfTestTraces
.getTestTracePath(TRACE_INDEX
);
56 private CtfTmfTrace fixture
;
59 * Perform pre-test initialization.
61 * @throws TmfTraceException
62 * If the test trace is not found
65 public void setUp() throws TmfTraceException
{
66 assumeTrue(CtfTmfTestTraces
.tracesExist());
67 fixture
= new CtfTmfTrace();
68 fixture
.initTrace((IResource
) null, PATH
, CtfTmfEvent
.class);
72 * Perform post-test clean-up.
75 public void tearDown() {
76 if (fixture
!= null) {
82 * Run the CtfTmfTrace() constructor test.
85 public void testCtfTmfTrace() {
86 CtfTmfTrace result
= new CtfTmfTrace();
88 assertNotNull(result
);
89 assertNull(result
.getEventType());
90 assertEquals(1000, result
.getCacheSize());
91 assertEquals(0L, result
.getNbEvents());
92 assertEquals(0L, result
.getStreamingInterval());
93 assertNull(result
.getResource());
94 assertEquals(1000, result
.getQueueSize());
95 assertNull(result
.getType());
99 * Test the parseEvent() method
102 public void testParseEvent() {
103 ITmfContext ctx
= fixture
.seekEvent(0);
104 fixture
.getNext(ctx
);
105 CtfTmfEvent event
= fixture
.parseEvent(ctx
);
106 assertNotNull(event
);
110 * Run the void broadcast(TmfSignal) method test.
113 public void testBroadcast() {
114 TmfSignal signal
= new TmfEndSynchSignal(1);
115 fixture
.broadcast(signal
);
120 * Run the void dispose() method test.
123 public void testDispose() {
124 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
125 emptyFixture
.dispose();
130 * Run the int getCacheSize() method test.
133 public void testGetCacheSize() {
134 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
135 int result
= emptyFixture
.getCacheSize();
136 assertEquals(1000, result
);
140 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
143 public void testGetCurrentLocation() {
144 CtfLocation result
= (CtfLocation
) fixture
.getCurrentLocation();
149 * Test the seekEvent() method with a null location.
152 public void testSeekEventLoc_null() {
153 CtfLocation loc
= null;
154 fixture
.seekEvent(loc
);
155 assertNotNull(fixture
);
159 * Test the seekEvent() method with a location from a timestamp.
162 public void testSeekEventLoc_timetamp(){
163 CtfLocation loc
= new CtfLocation(new CtfTmfTimestamp(0L));
164 fixture
.seekEvent(loc
);
165 assertNotNull(fixture
);
170 * Run the ITmfTimestamp getEndTime() method test.
173 public void testGetEndTime() {
174 ITmfTimestamp result
= fixture
.getEndTime();
175 assertNotNull(result
);
179 * Run the String getEnvironment method test.
182 public void testGetEnvValue() {
183 String key
= "tracer_name";
184 String result
= fixture
.getTraceProperties().get(key
);
185 assertEquals("\"lttng-modules\"",result
);
189 * Run the Class<CtfTmfEvent> getEventType() method test.
192 public void testGetEventType() {
193 Class
<ITmfEvent
> result
= fixture
.getEventType();
194 assertNotNull(result
);
198 * Run the double getLocationRatio(ITmfLocation<?>) method test.
201 public void testGetLocationRatio() {
202 final CtfLocationInfo location2
= new CtfLocationInfo(1, 0);
203 CtfLocation location
= new CtfLocation(location2
);
204 double result
= fixture
.getLocationRatio(location
);
206 assertEquals(Double
.NEGATIVE_INFINITY
, result
, 0.1);
210 * Run the String getName() method test.
213 public void testGetName() {
214 String result
= fixture
.getName();
215 assertNotNull(result
);
219 * Run the int getNbEnvVars() method test.
222 public void testGetNbEnvVars() {
223 int result
= fixture
.getTraceProperties().size();
224 assertEquals(8, result
);
228 * Run the long getNbEvents() method test.
231 public void testGetNbEvents() {
232 long result
= fixture
.getNbEvents();
233 assertEquals(1L, result
);
237 * Run the CtfTmfEvent getNext(ITmfContext) method test.
240 public void testGetNext() {
241 ITmfContext context
= fixture
.seekEvent(0);
242 CtfTmfEvent result
= fixture
.getNext(context
);
243 assertNotNull(result
);
247 * Run the String getPath() method test.
250 public void testGetPath() {
251 String result
= fixture
.getPath();
252 assertNotNull(result
);
256 * Run the IResource getResource() method test.
259 public void testGetResource() {
260 IResource result
= fixture
.getResource();
265 * Run the ITmfTimestamp getStartTime() method test.
268 public void testGetStartTime() {
269 ITmfTimestamp result
= fixture
.getStartTime();
270 assertNotNull(result
);
274 * Run the long getStreamingInterval() method test.
277 public void testGetStreamingInterval() {
278 long result
= fixture
.getStreamingInterval();
279 assertEquals(0L, result
);
283 * Run the TmfTimeRange getTimeRange() method test.
286 public void testGetTimeRange() {
287 TmfTimeRange result
= fixture
.getTimeRange();
288 assertNotNull(result
);
292 * Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
295 public void testReadNextEvent() {
296 ITmfContext context
= fixture
.seekEvent(0);
297 CtfTmfEvent result
= fixture
.getNext(context
);
298 assertNotNull(result
);
302 * Run the ITmfContext seekEvent(double) method test.
305 public void testSeekEvent_ratio() {
307 ITmfContext result
= fixture
.seekEvent(ratio
);
308 assertNotNull(result
);
312 * Run the ITmfContext seekEvent(long) method test.
315 public void testSeekEvent_rank() {
317 ITmfContext result
= fixture
.seekEvent(rank
);
318 assertNotNull(result
);
322 * Run the ITmfContext seekEvent(ITmfTimestamp) method test.
325 public void testSeekEvent_timestamp() {
326 ITmfTimestamp timestamp
= new TmfTimestamp();
327 ITmfContext result
= fixture
.seekEvent(timestamp
);
328 assertNotNull(result
);
332 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
335 public void testSeekEvent_location() {
336 final CtfLocationInfo location2
= new CtfLocationInfo(1L, 0L);
337 CtfLocation ctfLocation
= new CtfLocation(location2
);
338 ITmfContext result
= fixture
.seekEvent(ctfLocation
);
339 assertNotNull(result
);
343 * Run the boolean validate(IProject,String) method test.
346 public void testValidate() {
347 IProject project
= null;
349 IStatus result
= fixture
.validate(project
, path
);
350 assertTrue(result
.isOK());
354 * Run the boolean hasEvent(final String) method test
357 public void testEventLookup() {
358 assertTrue(fixture
.hasEvent("sched_switch"));
359 assertFalse(fixture
.hasEvent("Sched_switch"));
360 String
[] events
= { "sched_switch", "sched_wakeup", "timer_init" };
361 assertTrue(fixture
.hasAllEvents(events
));
362 assertTrue(fixture
.hasAtLeastOneOfEvents(events
));
363 String
[] names
= { "inexistent", "sched_switch", "SomeThing" };
364 assertTrue(fixture
.hasAtLeastOneOfEvents(names
));
365 assertFalse(fixture
.hasAllEvents(names
));
369 * Run the String getHostId() method test
372 public void testCtfHostId() {
373 String a
= fixture
.getHostId();
374 assertEquals("\"84db105b-b3f4-4821-b662-efc51455106a\"", a
);