timing.core: Add local statistics to the latency statistics
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.core.tests / src / org / eclipse / tracecompass / analysis / timing / core / tests / segmentstore / statistics / AbstractStatsAnalysisTest.java
1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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
10 package org.eclipse.tracecompass.analysis.timing.core.tests.segmentstore.statistics;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17 import java.util.Collections;
18 import java.util.Map;
19
20 import org.eclipse.core.runtime.NullProgressMonitor;
21 import org.eclipse.jdt.annotation.NonNull;
22 import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.AbstractSegmentStatisticsAnalysis;
23 import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics;
24 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
25 import org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStub;
26 import org.junit.Test;
27
28 import com.google.common.collect.ImmutableSet;
29
30 /**
31 * Test class to test the {@link AbstractSegmentStatisticsAnalysis} class
32 *
33 * @author Matthew Khouzam
34 */
35 public class AbstractStatsAnalysisTest {
36
37 /**
38 * Test execution with no trace
39 *
40 * @throws TmfAnalysisException
41 * should not happen
42 */
43 @Test
44 public void testExecuteNoTrace() throws TmfAnalysisException {
45 StubSegmentStatisticsAnalysis fixture = new StubSegmentStatisticsAnalysis();
46 assertFalse(fixture.executeAnalysis(new NullProgressMonitor()));
47 }
48
49 /**
50 * Test execution with no dependent analyses
51 *
52 * @throws TmfAnalysisException
53 * should not happen
54 */
55 @Test
56 public void testExecuteNoDepend() throws TmfAnalysisException {
57 StubSegmentStatisticsAnalysis fixture = new StubSegmentStatisticsAnalysis();
58 fixture.setTrace(new TmfXmlTraceStub());
59 assertFalse(fixture.executeAnalysis(new NullProgressMonitor()));
60 }
61
62 /**
63 * Test good execution
64 *
65 * @throws TmfAnalysisException
66 * should not happen
67 */
68 @Test
69 public void testExecute() throws TmfAnalysisException {
70 StubSegmentStatisticsAnalysis fixture = new StubSegmentStatisticsAnalysis();
71 TmfXmlTraceStub trace = new TmfXmlTraceStub();
72 fixture.setTrace(trace);
73 fixture.getDependentAnalyses();
74 assertTrue(fixture.executeAnalysis(new NullProgressMonitor()));
75 }
76
77 /**
78 * Test total statistics
79 *
80 * @throws TmfAnalysisException
81 * should not happen
82 *
83 */
84 @Test
85 public void testTotalStats() throws TmfAnalysisException {
86 StubSegmentStatisticsAnalysis fixture = getValidSegmentStats();
87 SegmentStoreStatistics totalStats = fixture.getTotalStats();
88 assertNotNull(totalStats);
89 // no need to test the content much as it is tested in the other test.
90 assertEquals(StubSegmentStatisticsAnalysis.SIZE, totalStats.getNbSegments());
91 }
92
93 /**
94 * Test per-type statistics
95 *
96 * @throws TmfAnalysisException
97 * should not happen
98 *
99 */
100 @Test
101 public void testPerTypeStats() throws TmfAnalysisException {
102 StubSegmentStatisticsAnalysis fixture = getValidSegmentStats();
103 Map<@NonNull String, @NonNull SegmentStoreStatistics> perTypeStats = fixture.getPerSegmentTypeStats();
104 assertNotNull(perTypeStats);
105 // no need to test the content much as it is tested in the other test.
106 assertEquals(2, perTypeStats.size());
107 assertEquals(ImmutableSet.<String> of("odd", "even"), perTypeStats.keySet());
108 SegmentStoreStatistics segmentStoreStatistics = perTypeStats.get("even");
109 assertNotNull(segmentStoreStatistics);
110 // starts with 0 so size + 1
111 assertEquals(StubSegmentStatisticsAnalysis.SIZE / 2 + 1, segmentStoreStatistics.getNbSegments());
112 }
113
114 /**
115 * Test the partial statistics
116 *
117 * @throws TmfAnalysisException
118 * should not happen
119 *
120 */
121 @Test
122 public void testPartialStats() throws TmfAnalysisException {
123 StubSegmentStatisticsAnalysis fixture = getValidSegmentStats();
124 SegmentStoreStatistics totalStats = fixture.getTotalStatsForRange(100, 1100, new NullProgressMonitor());
125 assertNotNull(totalStats);
126 // no need to test the content much as it is tested in the other test.
127
128 // 1051 = 1001 where start is between start and end + 50 overlapping
129 // start
130 assertEquals(1051, totalStats.getNbSegments());
131 }
132
133 /**
134 * Test the partial per type statistic
135 *
136 * @throws TmfAnalysisException
137 * should not happen
138 *
139 */
140 @Test
141 public void testPartialPerTypeStats() throws TmfAnalysisException {
142 StubSegmentStatisticsAnalysis fixture = getValidSegmentStats();
143 Map<@NonNull String, @NonNull SegmentStoreStatistics> perTypeStats = fixture.getPerSegmentTypeStatsForRange(100, 1100, new NullProgressMonitor());
144 assertNotNull(perTypeStats);
145 // no need to test the content much as it is tested in the other test.
146 assertEquals(2, perTypeStats.size());
147 assertEquals(ImmutableSet.<String> of("odd", "even"), perTypeStats.keySet());
148 SegmentStoreStatistics segmentStoreStatistics = perTypeStats.get("even");
149 assertNotNull(segmentStoreStatistics);
150 // 526 = 1051/2+1 = see explanation of 1051 in #testPartialStats
151 assertEquals(526, segmentStoreStatistics.getNbSegments());
152 }
153
154 /**
155 * Test the cancel operation
156 *
157 * @throws TmfAnalysisException
158 * should not happen
159 */
160 @Test
161 public void testPartialPerTypeStatsCancel() throws TmfAnalysisException {
162 StubSegmentStatisticsAnalysis fixture = getValidSegmentStats();
163 NullProgressMonitor monitor = new NullProgressMonitor();
164 monitor.setCanceled(true);
165 Map<@NonNull String, @NonNull SegmentStoreStatistics> perTypeStats = fixture.getPerSegmentTypeStatsForRange(100, 1100, monitor);
166 assertEquals(Collections.emptyMap(), perTypeStats);
167 }
168
169 private static StubSegmentStatisticsAnalysis getValidSegmentStats() throws TmfAnalysisException {
170 StubSegmentStatisticsAnalysis fixture = new StubSegmentStatisticsAnalysis();
171 TmfXmlTraceStub trace = new TmfXmlTraceStub();
172 fixture.setTrace(trace);
173 fixture.getDependentAnalyses();
174 fixture.executeAnalysis(new NullProgressMonitor());
175 return fixture;
176 }
177
178 }
This page took 0.035045 seconds and 5 git commands to generate.