[CTF] Events wrongly parsed as Lost Events
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.core.tests / src / org / eclipse / tracecompass / tmf / ctf / core / tests / event / CtfTmfLostEventsTest.java
CommitLineData
45f672d6 1/*******************************************************************************
da707390 2 * Copyright (c) 2013, 2015 Ericsson
45f672d6
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 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
9722e5d7 13package org.eclipse.tracecompass.tmf.ctf.core.tests.event;
45f672d6
AM
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertFalse;
17import static org.junit.Assert.assertTrue;
18import static org.junit.Assume.assumeTrue;
19
6cfc180e 20import org.eclipse.jdt.annotation.NonNull;
2bdf0193
AM
21import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
22import org.eclipse.tracecompass.tmf.core.event.ITmfLostEvent;
23import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
24import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
25import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
da707390 26import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
2bdf0193 27import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
9722e5d7 28import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
2bdf0193 29import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
9722e5d7 30import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
243d662d
AM
31import org.junit.After;
32import org.junit.Before;
45f672d6
AM
33import org.junit.Test;
34
35/**
36 * Tests to verify that lost events are handled correctly.
37 *
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
41 *
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.
44 *
45 * @author Alexandre Montplaisir
46 */
47public class CtfTmfLostEventsTest {
48
49 private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.HELLO_LOST;
50
243d662d 51 private CtfTmfTrace fixture = null;
45f672d6
AM
52
53 /**
54 * Class setup
55 */
243d662d
AM
56 @Before
57 public void setUp() {
45f672d6
AM
58 assumeTrue(testTrace.exists());
59 fixture = testTrace.getTrace();
60 fixture.indexTrace(true);
61 }
62
63 /**
64 * Clean-up
65 */
243d662d
AM
66 @After
67 public void tearDown() {
45f672d6
AM
68 if (fixture != null) {
69 fixture.dispose();
70 }
71 }
72
73 // ------------------------------------------------------------------------
74 // Test methods
75 // ------------------------------------------------------------------------
76
77 /**
78 * Test that the number of events is reported correctly (a range of lost
79 * events is counted as one event).
80 */
81 @Test
82 public void testNbEvents() {
83 final long expectedReal = 32300;
84 final long expectedLost = 562;
85
86 EventCountRequest req = new EventCountRequest();
87 fixture.sendRequest(req);
88 try {
89 req.waitForCompletion();
90 } catch (InterruptedException e) {
91 e.printStackTrace();
92 }
93
94 assertEquals(expectedReal, req.getReal());
95 assertEquals(expectedLost, req.getLost());
96 }
97
dd7f1879
MAL
98 /**
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.
102 */
103 @Test
104 public void testNbEventsBug475007() {
105 final CtfTmfTestTrace tmfTestTrace = CtfTmfTestTrace.DYNSCOPE;
106 assumeTrue(tmfTestTrace.exists());
107 try (CtfTmfTrace trace = tmfTestTrace.getTrace()) {
108 trace.indexTrace(true);
109
110 final long expectedReal = 100003;
111 final long expectedLost = 1;
112
113 EventCountRequest req = new EventCountRequest();
114 trace.sendRequest(req);
115 try {
116 req.waitForCompletion();
117 } catch (InterruptedException e) {
118 e.printStackTrace();
119 }
120
121 assertEquals(expectedReal, req.getReal());
122 assertEquals(expectedLost, req.getLost());
123 }
124 }
125
45f672d6
AM
126 /**
127 * Test getting the first lost event from the trace.
128 */
129 @Test
130 public void testFirstLostEvent() {
74d58b9b
PT
131 final long rank = 190;
132 final ITmfTimestamp start = new TmfNanoTimestamp(1376592664828900165L);
133 final ITmfTimestamp end = new TmfNanoTimestamp(1376592664829403076L);
45f672d6
AM
134 final long nbLost = 859;
135
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);
140
141 assertTrue(ev instanceof ITmfLostEvent);
142 ITmfLostEvent event = (ITmfLostEvent) ev;
143
144 assertEquals(start, event.getTimestamp());
145 assertEquals(start, event.getTimeRange().getStartTime());
146 assertEquals(end, event.getTimeRange().getEndTime());
147 assertEquals(nbLost, event.getNbLostEvents());
148 }
149
150 /**
151 * Test getting the second lost event from the trace.
152 */
153 @Test
154 public void testSecondLostEvent() {
74d58b9b
PT
155 final long rank = 229;
156 final ITmfTimestamp start = new TmfNanoTimestamp(1376592664829477058L);
157 final ITmfTimestamp end = new TmfNanoTimestamp(1376592664829824514L);
45f672d6
AM
158 final long nbLost = 488;
159
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);
164
165 assertTrue(ev instanceof ITmfLostEvent);
166 ITmfLostEvent event = (ITmfLostEvent) ev;
167
168 assertEquals(start, event.getTimestamp());
169 assertEquals(start, event.getTimeRange().getStartTime());
170 assertEquals(end, event.getTimeRange().getEndTime());
171 assertEquals(nbLost, event.getNbLostEvents());
172 }
173
174 /**
175 * Test getting one normal event from the trace (lost events should not
176 * interfere).
177 */
178 @Test
179 public void testNormalEvent() {
180 final long rank = 200;
74d58b9b 181 final ITmfTimestamp ts = new TmfNanoTimestamp(1376592664829425780L);
45f672d6
AM
182
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);
187
188 assertFalse(event instanceof ITmfLostEvent);
189 assertEquals(ts, event.getTimestamp());
190 }
191
192 // ------------------------------------------------------------------------
193 // Event requests
194 // ------------------------------------------------------------------------
195
196 private CtfTmfEvent getOneEventRank(long rank) {
197 OneEventRequestPerRank req = new OneEventRequestPerRank(rank);
198 fixture.sendRequest(req);
199 try {
200 req.waitForCompletion();
201 } catch (InterruptedException e) {
202 e.printStackTrace();
203 }
204 return req.getEvent();
205 }
206
6cfc180e 207 private CtfTmfEvent getOneEventTime(@NonNull ITmfTimestamp ts) {
45f672d6
AM
208 OneEventRequestPerTs req = new OneEventRequestPerTs(ts);
209 fixture.sendRequest(req);
210 try {
211 req.waitForCompletion();
212 } catch (InterruptedException e) {
213 e.printStackTrace();
214 }
215 return req.getEvent();
216 }
217
218 private class OneEventRequestPerRank extends TmfEventRequest {
219
220 private CtfTmfEvent event = null;
221
222 public OneEventRequestPerRank(long rank) {
a627ffb8 223 super(CtfTmfEvent.class, TmfTimeRange.ETERNITY, rank, 1, ExecutionType.FOREGROUND);
45f672d6
AM
224 }
225
226 @Override
227 public void handleData(ITmfEvent ev) {
228 /* Type is checked by the request, cast should be safe */
229 event = (CtfTmfEvent) ev;
230 }
231
232 public CtfTmfEvent getEvent() {
233 return event;
234 }
235 }
236
237 private class OneEventRequestPerTs extends TmfEventRequest {
238
239 private CtfTmfEvent event = null;
240
6cfc180e 241 public OneEventRequestPerTs(@NonNull ITmfTimestamp ts) {
45f672d6 242 super(CtfTmfEvent.class,
74d58b9b
PT
243 new TmfTimeRange(ts, ts),
244 0, ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND);
45f672d6
AM
245 }
246
247 @Override
248 public void handleData(ITmfEvent ev) {
249 event = (CtfTmfEvent) ev;
250 }
251
252 public CtfTmfEvent getEvent() {
253 return event;
254 }
255 }
256
257 private class EventCountRequest extends TmfEventRequest {
258
259 private long nbReal = 0;
260 private long nbLost = 0;
261
262 public EventCountRequest() {
263 super(CtfTmfEvent.class, TmfTimeRange.ETERNITY, 0,
2740e05c 264 ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND);
45f672d6
AM
265 }
266
267 @Override
268 public void handleData(ITmfEvent event) {
269 if (event instanceof ITmfLostEvent) {
270 nbLost++;
271 } else {
272 nbReal++;
273 }
274 }
275
276 public long getReal() {
277 return nbReal;
278 }
279
280 public long getLost() {
281 return nbLost;
282 }
283 }
284}
This page took 0.076904 seconds and 5 git commands to generate.