8a066d9ce90c365ed487ccb878215f6d8cbb88b8
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
.tracecompass
.tmf
.ctf
.core
.tests
.temp
.statistics
;
15 import static org
.junit
.Assert
.assertEquals
;
17 import java
.util
.List
;
19 import java
.util
.concurrent
.TimeUnit
;
21 import org
.eclipse
.jdt
.annotation
.NonNull
;
22 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.statistics
.ITmfStatistics
;
24 import org
.junit
.Rule
;
25 import org
.junit
.Test
;
26 import org
.junit
.rules
.TestRule
;
27 import org
.junit
.rules
.Timeout
;
30 * Base unit test class for any type of ITmfStatistics. Sub-classes should
31 * implement a "@BeforeClass" method to setup the 'backend' fixture accordingly.
33 * @author Alexandre Montplaisir
35 public abstract class TmfStatisticsTest
{
37 /** Time-out tests after 30 seconds */
38 @Rule public TestRule globalTimeout
= new Timeout(30, TimeUnit
.SECONDS
);
40 /** Test trace used for these tests */
41 protected static final @NonNull CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
43 /** The statistics back-end object */
44 protected static ITmfStatistics backend
;
46 /* Known values about the trace */
47 private static final int totalNbEvents
= 695319;
48 private static final long tStart
= 1332170682440133097L; /* Timestamp of first event */
49 private static final long tEnd
= 1332170692664579801L; /* Timestamp of last event */
51 /* Timestamps of interest */
52 private static final long t1
= 1332170682490946000L;
53 private static final long t2
= 1332170682490947524L; /* event exactly here */
54 private static final long t3
= 1332170682490948000L;
55 private static final long t4
= 1332170682490949000L;
56 private static final long t5
= 1332170682490949270L; /* following event here */
57 private static final long t6
= 1332170682490949300L;
59 private static final String eventType
= "lttng_statedump_process_state";
62 // ------------------------------------------------------------------------
63 // Tests for histogramQuery()
64 // ------------------------------------------------------------------------
67 * Test the {@link ITmfStatistics#histogramQuery} method for the small known
71 public void testHistogramQuerySmall() {
72 final int NB_REQ
= 10;
73 List
<Long
> results
= backend
.histogramQuery(t1
, t6
, NB_REQ
);
75 /* Make sure the returned array has the right size */
76 assertEquals(NB_REQ
, results
.size());
78 /* Check the contents of each "bucket" */
79 assertEquals(0, results
.get(0).longValue());
80 assertEquals(0, results
.get(1).longValue());
81 assertEquals(0, results
.get(2).longValue());
82 assertEquals(0, results
.get(3).longValue());
83 assertEquals(1, results
.get(4).longValue());
84 assertEquals(0, results
.get(5).longValue());
85 assertEquals(0, results
.get(6).longValue());
86 assertEquals(0, results
.get(7).longValue());
87 assertEquals(0, results
.get(8).longValue());
88 assertEquals(1, results
.get(9).longValue());
93 * Test the {@link ITmfStatistics#histogramQuery} method over the whole
97 public void testHistogramQueryFull() {
98 final int NB_REQ
= 10;
99 List
<Long
> results
= backend
.histogramQuery(tStart
, tEnd
, NB_REQ
);
101 /* Make sure the returned array has the right size */
102 assertEquals(NB_REQ
, results
.size());
104 /* Check the total number of events */
106 for (long val
: results
) {
109 assertEquals(totalNbEvents
, count
);
111 /* Check the contents of each "bucket" */
112 assertEquals(94161, results
.get(0).longValue());
113 assertEquals(87348, results
.get(1).longValue());
114 assertEquals(58941, results
.get(2).longValue());
115 assertEquals(59879, results
.get(3).longValue());
116 assertEquals(66941, results
.get(4).longValue());
117 assertEquals(68939, results
.get(5).longValue());
118 assertEquals(72746, results
.get(6).longValue());
119 assertEquals(60749, results
.get(7).longValue());
120 assertEquals(61208, results
.get(8).longValue());
121 assertEquals(64407, results
.get(9).longValue());
124 // ------------------------------------------------------------------------
125 // Test for getEventsTotal()
126 // ------------------------------------------------------------------------
129 * Basic test for {@link ITmfStatistics#getEventsTotal}
132 public void testGetEventsTotal() {
133 long count
= backend
.getEventsTotal();
134 assertEquals(totalNbEvents
, count
);
137 // ------------------------------------------------------------------------
138 // Test for getEventTypesTotal()
139 // ------------------------------------------------------------------------
142 * Basic test for {@link ITmfStatistics#getEventTypesTotal}
145 public void testEventTypesTotal() {
146 Map
<String
, Long
> res
= backend
.getEventTypesTotal();
147 assertEquals(126, res
.size()); /* Number of different event types in the trace */
149 long count
= sumOfEvents(res
);
150 assertEquals(totalNbEvents
, count
);
153 // ------------------------------------------------------------------------
154 // Tests for getEventsInRange(ITmfTimestamp start, ITmfTimestamp end)
155 // ------------------------------------------------------------------------
158 * Test for {@link ITmfStatistics#getEventsInRange} over the whole trace.
161 public void testGetEventsInRangeWholeRange() {
162 long count
= backend
.getEventsInRange(tStart
, tEnd
);
163 assertEquals(totalNbEvents
, count
);
167 * Test for {@link ITmfStatistics#getEventsInRange} for the whole range,
168 * except the start time (there is only one event at the start time).
171 public void testGetEventsInRangeMinusStart() {
172 long count
= backend
.getEventsInRange(tStart
+ 1, tEnd
);
173 assertEquals(totalNbEvents
- 1, count
);
177 * Test for {@link ITmfStatistics#getEventsInRange} for the whole range,
178 * except the end time (there is only one event at the end time).
181 public void testGetEventsInRangeMinusEnd() {
182 long count
= backend
.getEventsInRange(tStart
, tEnd
- 1);
183 assertEquals(totalNbEvents
- 1, count
);
187 * Test for {@link ITmfStatistics#getEventsInRange} when both the start and
188 * end times don't match an event.
191 public void testGetEventsInRangeNoEventsAtEdges() {
192 long count
= backend
.getEventsInRange(t1
, t6
);
193 assertEquals(2, count
);
197 * Test for {@link ITmfStatistics#getEventsInRange} when the *start* of the
198 * interval is exactly on an event (that event should be included).
201 public void testGetEventsInRangeEventAtStart() {
202 long count
= backend
.getEventsInRange(t2
, t3
);
203 assertEquals(1, count
);
205 count
= backend
.getEventsInRange(t2
, t6
);
206 assertEquals(2, count
);
210 * Test for {@link ITmfStatistics#getEventsInRange} when the *end* of the
211 * interval is exactly on an event (that event should be included).
214 public void testGetEventsInRangeEventAtEnd() {
215 long count
= backend
.getEventsInRange(t4
, t5
);
216 assertEquals(1, count
);
218 count
= backend
.getEventsInRange(t1
, t5
);
219 assertEquals(2, count
);
223 * Test for {@link ITmfStatistics#getEventsInRange} when there are events
224 * matching exactly both the start and end times of the range (both should
228 public void testGetEventsInRangeEventAtBoth() {
229 long count
= backend
.getEventsInRange(t2
, t5
);
230 assertEquals(2, count
);
234 * Test for {@link ITmfStatistics#getEventsInRange} when there are no events
238 public void testGetEventsInRangeNoEvents() {
239 long count
= backend
.getEventsInRange(t3
, t4
);
240 assertEquals(0, count
);
243 // ------------------------------------------------------------------------
244 // Tests for getEventTypesInRange(ITmfTimestamp start, ITmfTimestamp end)
245 // ------------------------------------------------------------------------
248 * Test for {@link ITmfStatistics#getEventTypesInRange} over the whole trace.
251 public void testGetEventTypesInRangeWholeRange() {
252 Map
<String
, Long
> result
= backend
.getEventTypesInRange(tStart
, tEnd
);
253 /* Number of events of that type in the whole trace */
254 assertEquals(new Long(464L), result
.get(eventType
));
256 long count
= sumOfEvents(result
);
257 assertEquals(totalNbEvents
, count
);
261 * Test for {@link ITmfStatistics#getEventTypesInRange} for the whole range,
262 * except the start time (there is only one event at the start time).
265 public void testGetEventTypesInRangeMinusStart() {
266 Map
<String
, Long
> result
= backend
.getEventTypesInRange(tStart
+ 1, tEnd
);
268 long count
= sumOfEvents(result
);
269 assertEquals(totalNbEvents
- 1, count
);
273 * Test for {@link ITmfStatistics#getEventTypesInRange} for the whole range,
274 * except the end time (there is only one event at the end time).
277 public void testGetEventTypesInRangeMinusEnd() {
278 Map
<String
, Long
> result
= backend
.getEventTypesInRange(tStart
, tEnd
- 1);
280 long count
= sumOfEvents(result
);
281 assertEquals(totalNbEvents
- 1, count
);
285 * Test for {@link ITmfStatistics#getEventTypesInRange} when both the start
286 * and end times don't match an event.
289 public void testGetEventTypesInRangeNoEventsAtEdges() {
290 Map
<String
, Long
> result
= backend
.getEventTypesInRange(t1
, t6
);
291 assertEquals(new Long(2L), result
.get(eventType
));
293 long count
= sumOfEvents(result
);
294 assertEquals(2, count
);
298 * Test for {@link ITmfStatistics#getEventTypesInRange} when the *start* of
299 * the interval is exactly on an event (that event should be included).
302 public void testGetEventTypesInRangeEventAtStart() {
303 Map
<String
, Long
> result
= backend
.getEventTypesInRange(t2
, t3
);
304 assertEquals(new Long(1L), result
.get(eventType
));
305 long count
= sumOfEvents(result
);
306 assertEquals(1, count
);
308 result
= backend
.getEventTypesInRange(t2
, t6
);
309 assertEquals(new Long(2L), result
.get(eventType
));
310 count
= sumOfEvents(result
);
311 assertEquals(2, count
);
315 * Test for {@link ITmfStatistics#getEventTypesInRange} when the *end* of
316 * the interval is exactly on an event (that event should be included).
319 public void testGetEventTypesInRangeEventAtEnd() {
320 Map
<String
, Long
> result
= backend
.getEventTypesInRange(t4
, t5
);
321 assertEquals(new Long(1L), result
.get(eventType
));
322 long count
= sumOfEvents(result
);
323 assertEquals(1, count
);
325 result
= backend
.getEventTypesInRange(t1
, t5
);
326 assertEquals(new Long(2L), result
.get(eventType
));
327 count
= sumOfEvents(result
);
328 assertEquals(2, count
);
332 * Test for {@link ITmfStatistics#getEventTypesInRange} when there are
333 * events matching exactly both the start and end times of the range (both
334 * should be included).
337 public void testGetEventTypesInRangeEventAtBoth() {
338 Map
<String
, Long
> result
= backend
.getEventTypesInRange(t2
, t5
);
339 assertEquals(new Long(2L), result
.get(eventType
));
340 long count
= sumOfEvents(result
);
341 assertEquals(2, count
);
345 * Test for {@link ITmfStatistics#getEventTypesInRange} when there are no
346 * events in a given range.
349 public void testGetEventTypesInRangeNoEvents() {
350 Map
<String
, Long
> result
= backend
.getEventTypesInRange(t3
, t4
);
351 long count
= sumOfEvents(result
);
352 assertEquals(0, count
);
355 // ------------------------------------------------------------------------
356 // Convenience methods
357 // ------------------------------------------------------------------------
359 private static long sumOfEvents(Map
<String
, Long
> map
) {
361 for (long val
: map
.values()) {
This page took 0.042311 seconds and 5 git commands to generate.