Commit | Line | Data |
---|---|---|
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 | ||
9722e5d7 | 13 | package org.eclipse.tracecompass.tmf.ctf.core.tests.event; |
e8f9ac01 AM |
14 | |
15 | import static org.junit.Assert.assertEquals; | |
c1264bdc AM |
16 | import static org.junit.Assert.assertNotNull; |
17 | import static org.junit.Assert.assertTrue; | |
e8f9ac01 AM |
18 | import static org.junit.Assert.fail; |
19 | import static org.junit.Assume.assumeTrue; | |
20 | ||
e8f9ac01 AM |
21 | import java.util.Map; |
22 | ||
f357bcd4 | 23 | import org.eclipse.tracecompass.ctf.core.CTFStrings; |
e894a508 | 24 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; |
2bdf0193 AM |
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; | |
c1264bdc AM |
32 | import org.junit.After; |
33 | import org.junit.Before; | |
e8f9ac01 AM |
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 | */ | |
91e7f946 | 45 | public class CtfTmfLostEventStatisticsTest { |
e8f9ac01 | 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 | 58 | |
bd64ee73 AM |
59 | /* The two analysis modules needed for fStats */ |
60 | private TmfStatisticsTotalsModule fTotalsMod; | |
61 | private TmfStatisticsEventTypesModule fEventTypesMod; | |
62 | ||
e8f9ac01 AM |
63 | // ------------------------------------------------------------------------ |
64 | // Maintenance | |
65 | // ------------------------------------------------------------------------ | |
66 | ||
67 | /** | |
68 | * Class setup | |
69 | */ | |
70 | @BeforeClass | |
71 | public static void setUpClass() { | |
c1264bdc AM |
72 | assumeTrue(lostEventsTrace.exists()); |
73 | } | |
802017fe | 74 | |
c1264bdc AM |
75 | /** |
76 | * Test setup | |
77 | */ | |
78 | @Before | |
79 | public void setUp() { | |
80 | fTrace = lostEventsTrace.getTrace(); | |
e8f9ac01 | 81 | |
c1264bdc | 82 | /* Prepare the two analysis-backed state systems */ |
bd64ee73 AM |
83 | fTotalsMod = new TmfStatisticsTotalsModule(); |
84 | fEventTypesMod = new TmfStatisticsEventTypesModule(); | |
c1264bdc | 85 | try { |
bd64ee73 AM |
86 | fTotalsMod.setTrace(fTrace); |
87 | fEventTypesMod.setTrace(fTrace); | |
c1264bdc | 88 | } catch (TmfAnalysisException e) { |
e8f9ac01 AM |
89 | fail(); |
90 | } | |
c1264bdc | 91 | |
bd64ee73 AM |
92 | fTotalsMod.schedule(); |
93 | fEventTypesMod.schedule(); | |
94 | assertTrue(fTotalsMod.waitForCompletion()); | |
95 | assertTrue(fEventTypesMod.waitForCompletion()); | |
c1264bdc | 96 | |
bd64ee73 AM |
97 | ITmfStateSystem totalsSS = fTotalsMod.getStateSystem(); |
98 | ITmfStateSystem eventTypesSS = fEventTypesMod.getStateSystem(); | |
c1264bdc AM |
99 | assertNotNull(totalsSS); |
100 | assertNotNull(eventTypesSS); | |
101 | ||
102 | fStats = new TmfStateStatistics(totalsSS, eventTypesSS); | |
103 | } | |
104 | ||
105 | /** | |
106 | * Test cleanup | |
107 | */ | |
108 | @After | |
109 | public void tearDown() { | |
bd64ee73 | 110 | fStats.dispose(); |
03f0b0b1 AM |
111 | fTotalsMod.dispose(); |
112 | fEventTypesMod.dispose(); | |
c1264bdc | 113 | fTrace.dispose(); |
e8f9ac01 AM |
114 | } |
115 | ||
116 | // ------------------------------------------------------------------------ | |
117 | // Test methods | |
118 | // ------------------------------------------------------------------------ | |
119 | ||
120 | /* | |
121 | * Trace start = 1376592664828559410 | |
122 | * Trace end = 1376592665108210547 | |
123 | */ | |
124 | ||
125 | private static final long rangeStart = 1376592664900000000L; | |
126 | private static final long rangeEnd = 1376592665000000000L; | |
127 | ||
128 | /** | |
129 | * Test the total number of "real" events. Make sure the lost events aren't | |
130 | * counted in the total. | |
131 | */ | |
132 | @Test | |
133 | public void testLostEventsTotals() { | |
c1264bdc | 134 | long realEvents = fStats.getEventsTotal(); |
e8f9ac01 AM |
135 | assertEquals(32300, realEvents); |
136 | } | |
137 | ||
138 | /** | |
139 | * Test the number of real events in a given range. Lost events shouldn't be | |
140 | * counted. | |
141 | */ | |
142 | @Test | |
143 | public void testLostEventsTotalInRange() { | |
c1264bdc | 144 | long realEventsInRange = fStats.getEventsInRange(rangeStart, rangeEnd); |
e8f9ac01 AM |
145 | assertEquals(11209L, realEventsInRange); |
146 | } | |
147 | ||
148 | /** | |
149 | * Test the total number of lost events reported in the trace. | |
150 | */ | |
151 | @Test | |
152 | public void testLostEventsTypes() { | |
c1264bdc | 153 | Map<String, Long> events = fStats.getEventTypesTotal(); |
e8f9ac01 AM |
154 | Long lostEvents = events.get(CTFStrings.LOST_EVENT_NAME); |
155 | assertEquals(Long.valueOf(967700L), lostEvents); | |
156 | } | |
157 | ||
158 | /** | |
159 | * Test the number of lost events reported in a given range. | |
160 | */ | |
161 | @Test | |
162 | public void testLostEventsTypesInRange() { | |
c1264bdc | 163 | Map<String, Long> eventsInRange = fStats.getEventTypesInRange(rangeStart, rangeEnd); |
e8f9ac01 AM |
164 | long lostEventsInRange = eventsInRange.get(CTFStrings.LOST_EVENT_NAME); |
165 | assertEquals(363494L, lostEventsInRange); | |
166 | } | |
167 | } |