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 try (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());
127 * Test getting the first lost event from the trace.
130 public void testFirstLostEvent() {
131 final long rank
= 190;
132 final ITmfTimestamp start
= new TmfNanoTimestamp(1376592664828900165L);
133 final ITmfTimestamp end
= new TmfNanoTimestamp(1376592664829403076L);
134 final long nbLost
= 859;
136 final CtfTmfEvent ev
= getOneEventTime(start
);
137 /* Make sure seeking by rank yields the same event */
138 final CtfTmfEvent ev2
= getOneEventRank(rank
);
139 assertEquals(ev
, ev2
);
141 assertTrue(ev
instanceof ITmfLostEvent
);
142 ITmfLostEvent event
= (ITmfLostEvent
) ev
;
144 assertEquals(start
, event
.getTimestamp());
145 assertEquals(start
, event
.getTimeRange().getStartTime());
146 assertEquals(end
, event
.getTimeRange().getEndTime());
147 assertEquals(nbLost
, event
.getNbLostEvents());
151 * Test getting the second lost event from the trace.
154 public void testSecondLostEvent() {
155 final long rank
= 229;
156 final ITmfTimestamp start
= new TmfNanoTimestamp(1376592664829477058L);
157 final ITmfTimestamp end
= new TmfNanoTimestamp(1376592664829824514L);
158 final long nbLost
= 488;
160 final CtfTmfEvent ev
= getOneEventTime(start
);
161 /* Make sure seeking by rank yields the same event */
162 final CtfTmfEvent ev2
= getOneEventRank(rank
);
163 assertEquals(ev
, ev2
);
165 assertTrue(ev
instanceof ITmfLostEvent
);
166 ITmfLostEvent event
= (ITmfLostEvent
) ev
;
168 assertEquals(start
, event
.getTimestamp());
169 assertEquals(start
, event
.getTimeRange().getStartTime());
170 assertEquals(end
, event
.getTimeRange().getEndTime());
171 assertEquals(nbLost
, event
.getNbLostEvents());
175 * Test getting one normal event from the trace (lost events should not
179 public void testNormalEvent() {
180 final long rank
= 200;
181 final ITmfTimestamp ts
= new TmfNanoTimestamp(1376592664829425780L);
183 final CtfTmfEvent event
= getOneEventTime(ts
);
184 /* Make sure seeking by rank yields the same event */
185 final CtfTmfEvent event2
= getOneEventRank(rank
);
186 assertEquals(event
, event2
);
188 assertFalse(event
instanceof ITmfLostEvent
);
189 assertEquals(ts
, event
.getTimestamp());
192 // ------------------------------------------------------------------------
194 // ------------------------------------------------------------------------
196 private CtfTmfEvent
getOneEventRank(long rank
) {
197 OneEventRequestPerRank req
= new OneEventRequestPerRank(rank
);
198 fixture
.sendRequest(req
);
200 req
.waitForCompletion();
201 } catch (InterruptedException e
) {
204 return req
.getEvent();
207 private CtfTmfEvent
getOneEventTime(@NonNull ITmfTimestamp ts
) {
208 OneEventRequestPerTs req
= new OneEventRequestPerTs(ts
);
209 fixture
.sendRequest(req
);
211 req
.waitForCompletion();
212 } catch (InterruptedException e
) {
215 return req
.getEvent();
218 private class OneEventRequestPerRank
extends TmfEventRequest
{
220 private CtfTmfEvent event
= null;
222 public OneEventRequestPerRank(long rank
) {
223 super(CtfTmfEvent
.class, TmfTimeRange
.ETERNITY
, rank
, 1, ExecutionType
.FOREGROUND
);
227 public void handleData(ITmfEvent ev
) {
228 /* Type is checked by the request, cast should be safe */
229 event
= (CtfTmfEvent
) ev
;
232 public CtfTmfEvent
getEvent() {
237 private class OneEventRequestPerTs
extends TmfEventRequest
{
239 private CtfTmfEvent event
= null;
241 public OneEventRequestPerTs(@NonNull ITmfTimestamp ts
) {
242 super(CtfTmfEvent
.class,
243 new TmfTimeRange(ts
, ts
),
244 0, ITmfEventRequest
.ALL_DATA
, ExecutionType
.FOREGROUND
);
248 public void handleData(ITmfEvent ev
) {
249 event
= (CtfTmfEvent
) ev
;
252 public CtfTmfEvent
getEvent() {
257 private class EventCountRequest
extends TmfEventRequest
{
259 private long nbReal
= 0;
260 private long nbLost
= 0;
262 public EventCountRequest() {
263 super(CtfTmfEvent
.class, TmfTimeRange
.ETERNITY
, 0,
264 ITmfEventRequest
.ALL_DATA
, ExecutionType
.FOREGROUND
);
268 public void handleData(ITmfEvent event
) {
269 if (event
instanceof ITmfLostEvent
) {
276 public long getReal() {
280 public long getLost() {