1 /*******************************************************************************
2 * Copyright (c) 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 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.ctfadaptor
;
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
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfLostEvent
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTrace
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
31 import org
.junit
.AfterClass
;
32 import org
.junit
.BeforeClass
;
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 static CtfTmfTrace fixture
= null;
57 public static void setUpClass() {
58 assumeTrue(testTrace
.exists());
59 fixture
= testTrace
.getTrace();
60 fixture
.indexTrace(true);
67 public static void tearDownClass() {
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 getting the first lost event from the trace.
102 public void testFirstLostEvent() {
103 final long rank
= 153;
104 final ITmfTimestamp start
= new CtfTmfTimestamp(1376592664828848222L);
105 final ITmfTimestamp end
= new CtfTmfTimestamp(1376592664828848540L);
106 final long nbLost
= 859;
108 final CtfTmfEvent ev
= getOneEventTime(start
);
109 /* Make sure seeking by rank yields the same event */
110 final CtfTmfEvent ev2
= getOneEventRank(rank
);
111 assertEquals(ev
, ev2
);
113 assertTrue(ev
instanceof ITmfLostEvent
);
114 ITmfLostEvent event
= (ITmfLostEvent
) ev
;
116 assertEquals(start
, event
.getTimestamp());
117 assertEquals(start
, event
.getTimeRange().getStartTime());
118 assertEquals(end
, event
.getTimeRange().getEndTime());
119 assertEquals(nbLost
, event
.getNbLostEvents());
123 * Test getting the second lost event from the trace.
126 public void testSecondLostEvent() {
127 final long rank
= 191;
128 final ITmfTimestamp start
= new CtfTmfTimestamp(1376592664829402521L);
129 final ITmfTimestamp end
= new CtfTmfTimestamp(1376592664829403076L);
130 final long nbLost
= 488;
132 final CtfTmfEvent ev
= getOneEventTime(start
);
133 /* Make sure seeking by rank yields the same event */
134 final CtfTmfEvent ev2
= getOneEventRank(rank
);
135 assertEquals(ev
, ev2
);
137 assertTrue(ev
instanceof ITmfLostEvent
);
138 ITmfLostEvent event
= (ITmfLostEvent
) ev
;
140 assertEquals(start
, event
.getTimestamp());
141 assertEquals(start
, event
.getTimeRange().getStartTime());
142 assertEquals(end
, event
.getTimeRange().getEndTime());
143 assertEquals(nbLost
, event
.getNbLostEvents());
147 * Test getting one normal event from the trace (lost events should not
151 public void testNormalEvent() {
152 final long rank
= 200;
153 final ITmfTimestamp ts
= new CtfTmfTimestamp(1376592664829423928L);
155 final CtfTmfEvent event
= getOneEventTime(ts
);
156 /* Make sure seeking by rank yields the same event */
157 final CtfTmfEvent event2
= getOneEventRank(rank
);
158 assertEquals(event
, event2
);
160 assertFalse(event
instanceof ITmfLostEvent
);
161 assertEquals(ts
, event
.getTimestamp());
164 // ------------------------------------------------------------------------
166 // ------------------------------------------------------------------------
168 private CtfTmfEvent
getOneEventRank(long rank
) {
169 OneEventRequestPerRank req
= new OneEventRequestPerRank(rank
);
170 fixture
.sendRequest(req
);
172 req
.waitForCompletion();
173 } catch (InterruptedException e
) {
176 return req
.getEvent();
179 private CtfTmfEvent
getOneEventTime(ITmfTimestamp ts
) {
180 OneEventRequestPerTs req
= new OneEventRequestPerTs(ts
);
181 fixture
.sendRequest(req
);
183 req
.waitForCompletion();
184 } catch (InterruptedException e
) {
187 return req
.getEvent();
190 private class OneEventRequestPerRank
extends TmfEventRequest
{
192 private CtfTmfEvent event
= null;
194 public OneEventRequestPerRank(long rank
) {
195 super(CtfTmfEvent
.class, TmfTimeRange
.ETERNITY
, rank
, 1, 1, ExecutionType
.FOREGROUND
);
199 public void handleData(ITmfEvent ev
) {
200 /* Type is checked by the request, cast should be safe */
201 event
= (CtfTmfEvent
) ev
;
204 public CtfTmfEvent
getEvent() {
209 private class OneEventRequestPerTs
extends TmfEventRequest
{
211 private CtfTmfEvent event
= null;
213 public OneEventRequestPerTs(ITmfTimestamp ts
) {
214 super(CtfTmfEvent
.class,
215 new TmfTimeRange(ts
, TmfTimestamp
.PROJECT_IS_CANNED
),
216 0, 1, 1, ExecutionType
.FOREGROUND
);
220 public void handleData(ITmfEvent ev
) {
221 event
= (CtfTmfEvent
) ev
;
224 public CtfTmfEvent
getEvent() {
229 private class EventCountRequest
extends TmfEventRequest
{
231 private long nbReal
= 0;
232 private long nbLost
= 0;
234 public EventCountRequest() {
235 super(CtfTmfEvent
.class, TmfTimeRange
.ETERNITY
, 0,
236 TmfDataRequest
.ALL_DATA
, 1, ExecutionType
.FOREGROUND
);
240 public void handleData(ITmfEvent event
) {
241 if (event
instanceof ITmfLostEvent
) {
248 public long getReal() {
252 public long getLost() {