1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 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 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.event
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertFalse
;
17 import static org
.junit
.Assert
.assertTrue
;
18 import static org
.junit
.Assume
.assumeTrue
;
20 import org
.eclipse
.jdt
.annotation
.NonNull
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfLostEvent
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
28 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
29 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
30 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
31 import org
.junit
.After
;
32 import org
.junit
.Before
;
33 import org
.junit
.Test
;
36 * Tests to verify that lost events are handled correctly.
38 * Be wary if you are using Babeltrace to cross-check those values. There could
39 * be a bug in Babeltrace with regards to lost events. See
40 * http://bugs.lttng.org/issues/589
42 * It's not 100% sure at this point which implementation is correct, so for now
43 * these tests assume the Java implementation is the right one.
45 * @author Alexandre Montplaisir
47 public class CtfTmfLostEventsTest
{
49 private static final CtfTmfTestTrace testTrace
= CtfTmfTestTrace
.HELLO_LOST
;
51 private CtfTmfTrace fixture
= null;
58 assumeTrue(testTrace
.exists());
59 fixture
= testTrace
.getTrace();
60 fixture
.indexTrace(true);
67 public void tearDown() {
68 if (fixture
!= null) {
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
78 * Test that the number of events is reported correctly (a range of lost
79 * events is counted as one event).
82 public void testNbEvents() {
83 final long expectedReal
= 32300;
84 final long expectedLost
= 562;
86 EventCountRequest req
= new EventCountRequest();
87 fixture
.sendRequest(req
);
89 req
.waitForCompletion();
90 } catch (InterruptedException e
) {
94 assertEquals(expectedReal
, req
.getReal());
95 assertEquals(expectedLost
, req
.getLost());
99 * Test that the number of events is reported correctly (a range of lost
100 * events is counted as one event). Events could be wrongly counted as lost
101 * events in certain situations.
104 public void testNbEventsBug475007() {
105 final CtfTmfTestTrace tmfTestTrace
= CtfTmfTestTrace
.DYNSCOPE
;
106 assumeTrue(tmfTestTrace
.exists());
107 CtfTmfTrace trace
= tmfTestTrace
.getTrace();
108 trace
.indexTrace(true);
110 final long expectedReal
= 100003;
111 final long expectedLost
= 1;
113 EventCountRequest req
= new EventCountRequest();
114 trace
.sendRequest(req
);
116 req
.waitForCompletion();
117 } catch (InterruptedException e
) {
121 assertEquals(expectedReal
, req
.getReal());
122 assertEquals(expectedLost
, req
.getLost());
128 * Test getting the first lost event from the trace.
131 public void testFirstLostEvent() {
132 final long rank
= 190;
133 final ITmfTimestamp start
= new TmfNanoTimestamp(1376592664828900165L);
134 final ITmfTimestamp end
= new TmfNanoTimestamp(1376592664829403076L);
135 final long nbLost
= 859;
137 final CtfTmfEvent ev
= getOneEventTime(start
);
138 /* Make sure seeking by rank yields the same event */
139 final CtfTmfEvent ev2
= getOneEventRank(rank
);
140 assertEquals(ev
, ev2
);
142 assertTrue(ev
instanceof ITmfLostEvent
);
143 ITmfLostEvent event
= (ITmfLostEvent
) ev
;
145 assertEquals(start
, event
.getTimestamp());
146 assertEquals(start
, event
.getTimeRange().getStartTime());
147 assertEquals(end
, event
.getTimeRange().getEndTime());
148 assertEquals(nbLost
, event
.getNbLostEvents());
152 * Test getting the second lost event from the trace.
155 public void testSecondLostEvent() {
156 final long rank
= 229;
157 final ITmfTimestamp start
= new TmfNanoTimestamp(1376592664829477058L);
158 final ITmfTimestamp end
= new TmfNanoTimestamp(1376592664829824514L);
159 final long nbLost
= 488;
161 final CtfTmfEvent ev
= getOneEventTime(start
);
162 /* Make sure seeking by rank yields the same event */
163 final CtfTmfEvent ev2
= getOneEventRank(rank
);
164 assertEquals(ev
, ev2
);
166 assertTrue(ev
instanceof ITmfLostEvent
);
167 ITmfLostEvent event
= (ITmfLostEvent
) ev
;
169 assertEquals(start
, event
.getTimestamp());
170 assertEquals(start
, event
.getTimeRange().getStartTime());
171 assertEquals(end
, event
.getTimeRange().getEndTime());
172 assertEquals(nbLost
, event
.getNbLostEvents());
176 * Test getting one normal event from the trace (lost events should not
180 public void testNormalEvent() {
181 final long rank
= 200;
182 final ITmfTimestamp ts
= new TmfNanoTimestamp(1376592664829425780L);
184 final CtfTmfEvent event
= getOneEventTime(ts
);
185 /* Make sure seeking by rank yields the same event */
186 final CtfTmfEvent event2
= getOneEventRank(rank
);
187 assertEquals(event
, event2
);
189 assertFalse(event
instanceof ITmfLostEvent
);
190 assertEquals(ts
, event
.getTimestamp());
193 // ------------------------------------------------------------------------
195 // ------------------------------------------------------------------------
197 private CtfTmfEvent
getOneEventRank(long rank
) {
198 OneEventRequestPerRank req
= new OneEventRequestPerRank(rank
);
199 fixture
.sendRequest(req
);
201 req
.waitForCompletion();
202 } catch (InterruptedException e
) {
205 return req
.getEvent();
208 private CtfTmfEvent
getOneEventTime(@NonNull ITmfTimestamp ts
) {
209 OneEventRequestPerTs req
= new OneEventRequestPerTs(ts
);
210 fixture
.sendRequest(req
);
212 req
.waitForCompletion();
213 } catch (InterruptedException e
) {
216 return req
.getEvent();
219 private class OneEventRequestPerRank
extends TmfEventRequest
{
221 private CtfTmfEvent event
= null;
223 public OneEventRequestPerRank(long rank
) {
224 super(CtfTmfEvent
.class, TmfTimeRange
.ETERNITY
, rank
, 1, ExecutionType
.FOREGROUND
);
228 public void handleData(ITmfEvent ev
) {
229 /* Type is checked by the request, cast should be safe */
230 event
= (CtfTmfEvent
) ev
;
233 public CtfTmfEvent
getEvent() {
238 private class OneEventRequestPerTs
extends TmfEventRequest
{
240 private CtfTmfEvent event
= null;
242 public OneEventRequestPerTs(@NonNull ITmfTimestamp ts
) {
243 super(CtfTmfEvent
.class,
244 new TmfTimeRange(ts
, ts
),
245 0, ITmfEventRequest
.ALL_DATA
, ExecutionType
.FOREGROUND
);
249 public void handleData(ITmfEvent ev
) {
250 event
= (CtfTmfEvent
) ev
;
253 public CtfTmfEvent
getEvent() {
258 private class EventCountRequest
extends TmfEventRequest
{
260 private long nbReal
= 0;
261 private long nbLost
= 0;
263 public EventCountRequest() {
264 super(CtfTmfEvent
.class, TmfTimeRange
.ETERNITY
, 0,
265 ITmfEventRequest
.ALL_DATA
, ExecutionType
.FOREGROUND
);
269 public void handleData(ITmfEvent event
) {
270 if (event
instanceof ITmfLostEvent
) {
277 public long getReal() {
281 public long getLost() {