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
.linuxtools
.tmf
.ctf
.core
.tests
;
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
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.CTFStrings
;
24 import org
.eclipse
.linuxtools
.statesystem
.core
.ITmfStateSystem
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfAnalysisException
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.statistics
.ITmfStatistics
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.statistics
.TmfStateStatistics
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.statistics
.TmfStatisticsEventTypesModule
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.statistics
.TmfStatisticsTotalsModule
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
31 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
32 import org
.junit
.After
;
33 import org
.junit
.Before
;
34 import org
.junit
.BeforeClass
;
35 import org
.junit
.Rule
;
36 import org
.junit
.Test
;
37 import org
.junit
.rules
.TestRule
;
38 import org
.junit
.rules
.Timeout
;
41 * Unit tests for handling of lost events by the statistics backends.
43 * @author Alexandre Montplaisir
45 public class CtfTmfLostEventStatisticsTest
{
47 /** Time-out tests after 30 seconds */
49 public TestRule globalTimeout
= new Timeout(30000);
51 /**Test trace with lost events */
52 private static final CtfTmfTestTrace lostEventsTrace
= CtfTmfTestTrace
.HELLO_LOST
;
54 private ITmfTrace fTrace
;
56 /** The statistics back-end object for the trace with lost events */
57 private ITmfStatistics fStats
;
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
67 public static void setUpClass() {
68 assumeTrue(lostEventsTrace
.exists());
76 fTrace
= lostEventsTrace
.getTrace();
78 /* Prepare the two analysis-backed state systems */
79 TmfStatisticsTotalsModule totalsMod
= new TmfStatisticsTotalsModule();
80 TmfStatisticsEventTypesModule eventTypesMod
= new TmfStatisticsEventTypesModule();
82 totalsMod
.setTrace(fTrace
);
83 eventTypesMod
.setTrace(fTrace
);
84 } catch (TmfAnalysisException e
) {
89 eventTypesMod
.schedule();
90 assertTrue(totalsMod
.waitForCompletion());
91 assertTrue(eventTypesMod
.waitForCompletion());
93 ITmfStateSystem totalsSS
= totalsMod
.getStateSystem();
94 ITmfStateSystem eventTypesSS
= eventTypesMod
.getStateSystem();
95 assertNotNull(totalsSS
);
96 assertNotNull(eventTypesSS
);
98 fStats
= new TmfStateStatistics(totalsSS
, eventTypesSS
);
105 public void tearDown() {
109 // ------------------------------------------------------------------------
111 // ------------------------------------------------------------------------
114 * Trace start = 1376592664828559410
115 * Trace end = 1376592665108210547
118 private static final long rangeStart
= 1376592664900000000L;
119 private static final long rangeEnd
= 1376592665000000000L;
122 * Test the total number of "real" events. Make sure the lost events aren't
123 * counted in the total.
126 public void testLostEventsTotals() {
127 long realEvents
= fStats
.getEventsTotal();
128 assertEquals(32300, realEvents
);
132 * Test the number of real events in a given range. Lost events shouldn't be
136 public void testLostEventsTotalInRange() {
137 long realEventsInRange
= fStats
.getEventsInRange(rangeStart
, rangeEnd
);
138 assertEquals(11209L, realEventsInRange
);
142 * Test the total number of lost events reported in the trace.
145 public void testLostEventsTypes() {
146 Map
<String
, Long
> events
= fStats
.getEventTypesTotal();
147 Long lostEvents
= events
.get(CTFStrings
.LOST_EVENT_NAME
);
148 assertEquals(Long
.valueOf(967700L), lostEvents
);
152 * Test the number of lost events reported in a given range.
155 public void testLostEventsTypesInRange() {
156 Map
<String
, Long
> eventsInRange
= fStats
.getEventTypesInRange(rangeStart
, rangeEnd
);
157 long lostEventsInRange
= eventsInRange
.get(CTFStrings
.LOST_EVENT_NAME
);
158 assertEquals(363494L, lostEventsInRange
);