ad31fa9b3c44a0cf75a7e882a4e57db26f7d25ab
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ctf.core.tests / src / org / eclipse / tracecompass / tmf / ctf / core / tests / event / CtfTmfLostEventStatisticsTest.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
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
13 package org.eclipse.tracecompass.tmf.ctf.core.tests.event;
14
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;
20
21 import java.util.Map;
22
23 import org.eclipse.tracecompass.ctf.core.CTFStrings;
24 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
25 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
26 import org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics;
27 import org.eclipse.tracecompass.tmf.core.statistics.TmfStateStatistics;
28 import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsEventTypesModule;
29 import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsTotalsModule;
30 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
31 import org.eclipse.tracecompass.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;
39
40 /**
41 * Unit tests for handling of lost events by the statistics backends.
42 *
43 * @author Alexandre Montplaisir
44 */
45 public class CtfTmfLostEventStatisticsTest {
46
47 /** Time-out tests after 30 seconds */
48 @Rule
49 public TestRule globalTimeout= new Timeout(30000);
50
51 /**Test trace with lost events */
52 private static final CtfTmfTestTrace lostEventsTrace = CtfTmfTestTrace.HELLO_LOST;
53
54 private ITmfTrace fTrace;
55
56 /** The statistics back-end object for the trace with lost events */
57 private ITmfStatistics fStats;
58
59 /* The two analysis modules needed for fStats */
60 private TmfStatisticsTotalsModule fTotalsMod;
61 private TmfStatisticsEventTypesModule fEventTypesMod;
62
63 // ------------------------------------------------------------------------
64 // Maintenance
65 // ------------------------------------------------------------------------
66
67 /**
68 * Class setup
69 */
70 @BeforeClass
71 public static void setUpClass() {
72 assumeTrue(lostEventsTrace.exists());
73 }
74
75 /**
76 * Test setup
77 */
78 @Before
79 public void setUp() {
80 ITmfTrace trace = lostEventsTrace.getTrace();
81 fTrace = trace;
82
83 /* Prepare the two analysis-backed state systems */
84 fTotalsMod = new TmfStatisticsTotalsModule();
85 fEventTypesMod = new TmfStatisticsEventTypesModule();
86 try {
87 fTotalsMod.setTrace(trace);
88 fEventTypesMod.setTrace(trace);
89 } catch (TmfAnalysisException e) {
90 fail();
91 }
92
93 fTotalsMod.schedule();
94 fEventTypesMod.schedule();
95 assertTrue(fTotalsMod.waitForCompletion());
96 assertTrue(fEventTypesMod.waitForCompletion());
97
98 ITmfStateSystem totalsSS = fTotalsMod.getStateSystem();
99 ITmfStateSystem eventTypesSS = fEventTypesMod.getStateSystem();
100 assertNotNull(totalsSS);
101 assertNotNull(eventTypesSS);
102
103 fStats = new TmfStateStatistics(totalsSS, eventTypesSS);
104 }
105
106 /**
107 * Test cleanup
108 */
109 @After
110 public void tearDown() {
111 fStats.dispose();
112 fTotalsMod.dispose();
113 fEventTypesMod.dispose();
114 fTrace.dispose();
115 }
116
117 // ------------------------------------------------------------------------
118 // Test methods
119 // ------------------------------------------------------------------------
120
121 /*
122 * Trace start = 1376592664828559410
123 * Trace end = 1376592665108210547
124 */
125
126 private static final long rangeStart = 1376592664900000000L;
127 private static final long rangeEnd = 1376592665000000000L;
128
129 /**
130 * Test the total number of "real" events. Make sure the lost events aren't
131 * counted in the total.
132 */
133 @Test
134 public void testLostEventsTotals() {
135 long realEvents = fStats.getEventsTotal();
136 assertEquals(32300, realEvents);
137 }
138
139 /**
140 * Test the number of real events in a given range. Lost events shouldn't be
141 * counted.
142 */
143 @Test
144 public void testLostEventsTotalInRange() {
145 long realEventsInRange = fStats.getEventsInRange(rangeStart, rangeEnd);
146 assertEquals(11209L, realEventsInRange);
147 }
148
149 /**
150 * Test the total number of lost events reported in the trace.
151 */
152 @Test
153 public void testLostEventsTypes() {
154 Map<String, Long> events = fStats.getEventTypesTotal();
155 Long lostEvents = events.get(CTFStrings.LOST_EVENT_NAME);
156 assertEquals(Long.valueOf(967700L), lostEvents);
157 }
158
159 /**
160 * Test the number of lost events reported in a given range.
161 */
162 @Test
163 public void testLostEventsTypesInRange() {
164 Map<String, Long> eventsInRange = fStats.getEventTypesInRange(rangeStart, rangeEnd);
165 long lostEventsInRange = eventsInRange.get(CTFStrings.LOST_EVENT_NAME);
166 assertEquals(363494L, lostEventsInRange);
167 }
168 }
This page took 0.037466 seconds and 4 git commands to generate.