1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 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
.assertNotNull
;
17 import static org
.junit
.Assert
.assertTrue
;
18 import static org
.junit
.Assert
.fail
;
19 import static org
.junit
.Assume
.assumeTrue
;
22 import java
.util
.concurrent
.TimeUnit
;
24 import org
.eclipse
.tracecompass
.ctf
.core
.CTFStrings
;
25 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.statistics
.ITmfStatistics
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.statistics
.TmfStateStatistics
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.statistics
.TmfStatisticsEventTypesModule
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.statistics
.TmfStatisticsTotalsModule
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
32 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
33 import org
.junit
.After
;
34 import org
.junit
.Before
;
35 import org
.junit
.BeforeClass
;
36 import org
.junit
.Rule
;
37 import org
.junit
.Test
;
38 import org
.junit
.rules
.TestRule
;
39 import org
.junit
.rules
.Timeout
;
42 * Unit tests for handling of lost events by the statistics backends.
44 * @author Alexandre Montplaisir
46 public class CtfTmfLostEventStatisticsTest
{
48 /** Time-out tests after 30 seconds */
50 public TestRule globalTimeout
= new Timeout(30, TimeUnit
.SECONDS
);
52 /**Test trace with lost events */
53 private static final CtfTmfTestTrace lostEventsTrace
= CtfTmfTestTrace
.HELLO_LOST
;
55 private ITmfTrace fTrace
;
57 /** The statistics back-end object for the trace with lost events */
58 private ITmfStatistics fStats
;
60 /* The two analysis modules needed for fStats */
61 private TmfStatisticsTotalsModule fTotalsMod
;
62 private TmfStatisticsEventTypesModule fEventTypesMod
;
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
72 public static void setUpClass() {
73 assumeTrue(lostEventsTrace
.exists());
81 ITmfTrace trace
= lostEventsTrace
.getTrace();
84 /* Prepare the two analysis-backed state systems */
85 fTotalsMod
= new TmfStatisticsTotalsModule();
86 fEventTypesMod
= new TmfStatisticsEventTypesModule();
88 fTotalsMod
.setTrace(trace
);
89 fEventTypesMod
.setTrace(trace
);
90 } catch (TmfAnalysisException e
) {
94 fTotalsMod
.schedule();
95 fEventTypesMod
.schedule();
96 assertTrue(fTotalsMod
.waitForCompletion());
97 assertTrue(fEventTypesMod
.waitForCompletion());
99 ITmfStateSystem totalsSS
= fTotalsMod
.getStateSystem();
100 ITmfStateSystem eventTypesSS
= fEventTypesMod
.getStateSystem();
101 assertNotNull(totalsSS
);
102 assertNotNull(eventTypesSS
);
104 fStats
= new TmfStateStatistics(totalsSS
, eventTypesSS
);
111 public void tearDown() {
113 fTotalsMod
.dispose();
114 fEventTypesMod
.dispose();
118 // ------------------------------------------------------------------------
120 // ------------------------------------------------------------------------
123 * Trace start = 1376592664828559410
124 * Trace end = 1376592665108210547
127 private static final long rangeStart
= 1376592664900000000L;
128 private static final long rangeEnd
= 1376592665000000000L;
131 * Test the total number of "real" events. Make sure the lost events aren't
132 * counted in the total.
135 public void testLostEventsTotals() {
136 long realEvents
= fStats
.getEventsTotal();
137 assertEquals(32300, realEvents
);
141 * Test the number of real events in a given range. Lost events shouldn't be
145 public void testLostEventsTotalInRange() {
146 long realEventsInRange
= fStats
.getEventsInRange(rangeStart
, rangeEnd
);
147 assertEquals(11209L, realEventsInRange
);
151 * Test the total number of lost events reported in the trace.
154 public void testLostEventsTypes() {
155 Map
<String
, Long
> events
= fStats
.getEventTypesTotal();
156 Long lostEvents
= events
.get(CTFStrings
.LOST_EVENT_NAME
);
157 assertEquals(Long
.valueOf(967700L), lostEvents
);
161 * Test the number of lost events reported in a given range.
164 public void testLostEventsTypesInRange() {
165 Map
<String
, Long
> eventsInRange
= fStats
.getEventTypesInRange(rangeStart
, rangeEnd
);
166 long lostEventsInRange
= eventsInRange
.get(CTFStrings
.LOST_EVENT_NAME
);
167 assertEquals(363494L, lostEventsInRange
);