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