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