1 /*******************************************************************************
2 * Copyright (c) 2012 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
.linuxtools
.tmf
.core
.tests
.statistics
;
15 import static org
.junit
.Assert
.assertEquals
;
17 import java
.util
.List
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.statistics
.ITmfStatistics
;
21 import org
.junit
.Test
;
24 * Base unit test class for any type of ITmfStatistics. Sub-classes should
25 * implement a "@BeforeClass" method to setup the 'backend' fixture accordingly.
27 * @author Alexandre Montplaisir
29 public abstract class TmfStatisticsTest
{
31 /** The index of the test trace used for these tests */
32 protected static final int TRACE_INDEX
= 0;
34 /** The statistics back-end object */
35 protected static ITmfStatistics backend
;
37 /* Known values about the trace */
38 private static final int totalNbEvents
= 695319;
39 private static final long tStart
= 1332170682440133097L; /* Timestamp of first event */
40 private static final long tEnd
= 1332170692664579801L; /* Timestamp of last event */
42 /* Timestamps of interest */
43 private static final long t1
= 1332170682490946000L;
44 private static final long t2
= 1332170682490947524L; /* event exactly here */
45 private static final long t3
= 1332170682490948000L;
46 private static final long t4
= 1332170682490949000L;
47 private static final long t5
= 1332170682490949270L; /* following event here */
48 private static final long t6
= 1332170682490949300L;
50 private static final String eventType
= "lttng_statedump_process_state"; //$NON-NLS-1$
53 // ------------------------------------------------------------------------
54 // Tests for histogramQuery()
55 // ------------------------------------------------------------------------
58 * Test the {@link ITmfStatistics#histogramQuery} method for the small known
62 public void testHistogramQuerySmall() {
63 final int NB_REQ
= 10;
64 List
<Long
> results
= backend
.histogramQuery(t1
, t6
, NB_REQ
);
66 /* Make sure the returned array has the right size */
67 assertEquals(NB_REQ
, results
.size());
69 /* Check the contents of each "bucket" */
70 assertEquals(0, results
.get(0).longValue());
71 assertEquals(0, results
.get(1).longValue());
72 assertEquals(0, results
.get(2).longValue());
73 assertEquals(0, results
.get(3).longValue());
74 assertEquals(1, results
.get(4).longValue());
75 assertEquals(0, results
.get(5).longValue());
76 assertEquals(0, results
.get(6).longValue());
77 assertEquals(0, results
.get(7).longValue());
78 assertEquals(0, results
.get(8).longValue());
79 assertEquals(1, results
.get(9).longValue());
84 * Test the {@link ITmfStatistics#histogramQuery} method over the whole
88 public void testHistogramQueryFull() {
89 final int NB_REQ
= 10;
90 List
<Long
> results
= backend
.histogramQuery(tStart
, tEnd
, NB_REQ
);
92 /* Make sure the returned array has the right size */
93 assertEquals(NB_REQ
, results
.size());
95 /* Check the total number of events */
97 for (Long val
: results
) {
100 assertEquals(totalNbEvents
, count
);
102 /* Check the contents of each "bucket" */
103 assertEquals(94161, results
.get(0).longValue());
104 assertEquals(87348, results
.get(1).longValue());
105 assertEquals(58941, results
.get(2).longValue());
106 assertEquals(59879, results
.get(3).longValue());
107 assertEquals(66941, results
.get(4).longValue());
108 assertEquals(68939, results
.get(5).longValue());
109 assertEquals(72746, results
.get(6).longValue());
110 assertEquals(60749, results
.get(7).longValue());
111 assertEquals(61208, results
.get(8).longValue());
112 assertEquals(64407, results
.get(9).longValue());
115 // ------------------------------------------------------------------------
116 // Test for getEventsTotal()
117 // ------------------------------------------------------------------------
120 * Basic test for {@link ITmfStatistics#getEventsTotal}
123 public void testGetEventsTotal() {
124 long count
= backend
.getEventsTotal();
125 assertEquals(totalNbEvents
, count
);
128 // ------------------------------------------------------------------------
129 // Test for getEventTypesTotal()
130 // ------------------------------------------------------------------------
133 * Basic test for {@link ITmfStatistics#getEventTypesTotal}
136 public void testEventTypesTotal() {
137 Map
<String
, Long
> res
= backend
.getEventTypesTotal();
138 assertEquals(126, res
.size()); /* Number of different event types in the trace */
140 long count
= sumOfEvents(res
);
141 assertEquals(totalNbEvents
, count
);
144 // ------------------------------------------------------------------------
145 // Tests for getEventsInRange(ITmfTimestamp start, ITmfTimestamp end)
146 // ------------------------------------------------------------------------
149 * Test for {@link ITmfStatistics#getEventsInRange} over the whole trace.
152 public void testGetEventsInRangeWholeRange() {
153 long count
= backend
.getEventsInRange(tStart
, tEnd
);
154 assertEquals(totalNbEvents
, count
);
158 * Test for {@link ITmfStatistics#getEventsInRange} for the whole range,
159 * except the start time (there is only one event at the start time).
162 public void testGetEventsInRangeMinusStart() {
163 long count
= backend
.getEventsInRange(tStart
+ 1, tEnd
);
164 assertEquals(totalNbEvents
- 1, count
);
168 * Test for {@link ITmfStatistics#getEventsInRange} for the whole range,
169 * except the end time (there is only one event at the end time).
172 public void testGetEventsInRangeMinusEnd() {
173 long count
= backend
.getEventsInRange(tStart
, tEnd
- 1);
174 assertEquals(totalNbEvents
- 1, count
);
178 * Test for {@link ITmfStatistics#getEventsInRange} when both the start and
179 * end times don't match an event.
182 public void testGetEventsInRangeNoEventsAtEdges() {
183 long count
= backend
.getEventsInRange(t1
, t6
);
184 assertEquals(2, count
);
188 * Test for {@link ITmfStatistics#getEventsInRange} when the *start* of the
189 * interval is exactly on an event (that event should be included).
192 public void testGetEventsInRangeEventAtStart() {
193 long count
= backend
.getEventsInRange(t2
, t3
);
194 assertEquals(1, count
);
196 count
= backend
.getEventsInRange(t2
, t6
);
197 assertEquals(2, count
);
201 * Test for {@link ITmfStatistics#getEventsInRange} when the *end* of the
202 * interval is exactly on an event (that event should be included).
205 public void testGetEventsInRangeEventAtEnd() {
206 long count
= backend
.getEventsInRange(t4
, t5
);
207 assertEquals(1, count
);
209 count
= backend
.getEventsInRange(t1
, t5
);
210 assertEquals(2, count
);
214 * Test for {@link ITmfStatistics#getEventsInRange} when there are events
215 * matching exactly both the start and end times of the range (both should
219 public void testGetEventsInRangeEventAtBoth() {
220 long count
= backend
.getEventsInRange(t2
, t5
);
221 assertEquals(2, count
);
225 * Test for {@link ITmfStatistics#getEventsInRange} when there are no events
229 public void testGetEventsInRangeNoEvents() {
230 long count
= backend
.getEventsInRange(t3
, t4
);
231 assertEquals(0, count
);
234 // ------------------------------------------------------------------------
235 // Tests for getEventTypesInRange(ITmfTimestamp start, ITmfTimestamp end)
236 // ------------------------------------------------------------------------
239 * Test for {@link ITmfStatistics#getEventTypesInRange} over the whole trace.
242 public void testGetEventTypesInRangeWholeRange() {
243 Map
<String
, Long
> result
= backend
.getEventTypesInRange(tStart
, tEnd
);
244 /* Number of events of that type in the whole trace */
245 assertEquals(new Long(464L), result
.get(eventType
));
247 long count
= sumOfEvents(result
);
248 assertEquals(totalNbEvents
, count
);
252 * Test for {@link ITmfStatistics#getEventTypesInRange} for the whole range,
253 * except the start time (there is only one event at the start time).
256 public void testGetEventTypesInRangeMinusStart() {
257 Map
<String
, Long
> result
= backend
.getEventTypesInRange(tStart
+ 1, tEnd
);
259 long count
= sumOfEvents(result
);
260 assertEquals(totalNbEvents
- 1, count
);
264 * Test for {@link ITmfStatistics#getEventTypesInRange} for the whole range,
265 * except the end time (there is only one event at the end time).
268 public void testGetEventTypesInRangeMinusEnd() {
269 Map
<String
, Long
> result
= backend
.getEventTypesInRange(tStart
, tEnd
- 1);
271 long count
= sumOfEvents(result
);
272 assertEquals(totalNbEvents
- 1, count
);
276 * Test for {@link ITmfStatistics#getEventTypesInRange} when both the start
277 * and end times don't match an event.
280 public void testGetEventTypesInRangeNoEventsAtEdges() {
281 Map
<String
, Long
> result
= backend
.getEventTypesInRange(t1
, t6
);
282 assertEquals(new Long(2L), result
.get(eventType
));
284 long count
= sumOfEvents(result
);
285 assertEquals(2, count
);
289 * Test for {@link ITmfStatistics#getEventTypesInRange} when the *start* of
290 * the interval is exactly on an event (that event should be included).
293 public void testGetEventTypesInRangeEventAtStart() {
294 Map
<String
, Long
> result
= backend
.getEventTypesInRange(t2
, t3
);
295 assertEquals(new Long(1L), result
.get(eventType
));
296 long count
= sumOfEvents(result
);
297 assertEquals(1, count
);
299 result
= backend
.getEventTypesInRange(t2
, t6
);
300 assertEquals(new Long(2L), result
.get(eventType
));
301 count
= sumOfEvents(result
);
302 assertEquals(2, count
);
306 * Test for {@link ITmfStatistics#getEventTypesInRange} when the *end* of
307 * the interval is exactly on an event (that event should be included).
310 public void testGetEventTypesInRangeEventAtEnd() {
311 Map
<String
, Long
> result
= backend
.getEventTypesInRange(t4
, t5
);
312 assertEquals(new Long(1L), result
.get(eventType
));
313 long count
= sumOfEvents(result
);
314 assertEquals(1, count
);
316 result
= backend
.getEventTypesInRange(t1
, t5
);
317 assertEquals(new Long(2L), result
.get(eventType
));
318 count
= sumOfEvents(result
);
319 assertEquals(2, count
);
323 * Test for {@link ITmfStatistics#getEventTypesInRange} when there are
324 * events matching exactly both the start and end times of the range (both
325 * should be included).
328 public void testGetEventTypesInRangeEventAtBoth() {
329 Map
<String
, Long
> result
= backend
.getEventTypesInRange(t2
, t5
);
330 assertEquals(new Long(2L), result
.get(eventType
));
331 long count
= sumOfEvents(result
);
332 assertEquals(2, count
);
336 * Test for {@link ITmfStatistics#getEventTypesInRange} when there are no
337 * events in a given range.
340 public void testGetEventTypesInRangeNoEvents() {
341 Map
<String
, Long
> result
= backend
.getEventTypesInRange(t3
, t4
);
342 long count
= sumOfEvents(result
);
343 assertEquals(0, count
);
346 // ------------------------------------------------------------------------
347 // Convenience methods
348 // ------------------------------------------------------------------------
350 private static long sumOfEvents(Map
<String
, Long
> map
) {
352 for (Long val
: map
.values()) {
This page took 0.052267 seconds and 5 git commands to generate.