timing: Add default implementations of deprecated methods
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests / src / org / eclipse / tracecompass / analysis / timing / ui / swtbot / tests / callgraph / CallGraphDensityViewTest.java
CommitLineData
b1d4e193
MK
1/*******************************************************************************
2 * Copyright (c) 2016 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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
10package org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests.callgraph;
11
12import static org.junit.Assert.assertEquals;
13import static org.junit.Assert.assertNotNull;
14import static org.junit.Assert.assertTrue;
15import static org.junit.Assert.fail;
16
b1d4e193
MK
17import java.util.concurrent.CountDownLatch;
18import java.util.concurrent.TimeUnit;
19
20import org.apache.log4j.ConsoleAppender;
21import org.apache.log4j.Logger;
22import org.apache.log4j.SimpleLayout;
23import org.eclipse.jdt.annotation.NonNull;
24import org.eclipse.jdt.annotation.Nullable;
25import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
26import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
27import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
1ee63dfc 28import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
b1d4e193
MK
29import org.eclipse.swtbot.swt.finder.results.Result;
30import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
31import org.eclipse.swtbot.swt.finder.widgets.SWTBotCanvas;
32import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
33import org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider;
edcd1f39
GB
34import org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics;
35import org.eclipse.tracecompass.analysis.timing.core.statistics.Statistics;
b1d4e193
MK
36import org.eclipse.tracecompass.analysis.timing.core.tests.flamegraph.AggregationTreeTest;
37import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.density.AbstractSegmentStoreDensityViewer;
38import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.density.ISegmentStoreDensityViewerDataListener;
39import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.table.AbstractSegmentStoreTableViewer;
40import org.eclipse.tracecompass.internal.analysis.timing.ui.callgraph.CallGraphDensityView;
b1d4e193
MK
41import org.eclipse.tracecompass.segmentstore.core.ISegment;
42import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
43import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
44import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
45import org.eclipse.ui.IViewPart;
46import org.junit.After;
47import org.junit.Assert;
48import org.junit.Before;
49import org.junit.BeforeClass;
1ee63dfc 50import org.junit.runner.RunWith;
b1d4e193
MK
51import org.swtchart.ISeries;
52
53/**
54 * Test the call graph density view, known as the Function Density view. The
55 * density view can change its data with respect to screen resolution, so
56 * descriptive statistics are used to check validity. This is one of the rare
57 * occasions that the error in the
58 * {@link Assert#assertEquals(double, double, double)} is actually quite useful
59 *
60 * @author Matthew Khouzam
61 */
1ee63dfc 62@RunWith(SWTBotJunit4ClassRunner.class)
b1d4e193
MK
63public class CallGraphDensityViewTest extends AggregationTreeTest {
64
65 private static final String CALLGRAPHDENSITY_ID = CallGraphDensityView.ID;
66
67 private final @NonNull ISegmentStoreDensityViewerDataListener fSyncListener = new ISegmentStoreDensityViewerDataListener() {
b1d4e193 68
fc409c43
GB
69 @Override
70 public void viewDataChanged(@NonNull Iterable<? extends @NonNull ISegment> newData) {
71 fLatch.countDown();
72 }
73
74 @Override
75 public void selectedDataChanged(@Nullable Iterable<? extends @NonNull ISegment> newSelectionData) {
76 // do nothing
77 }
78
b1d4e193
MK
79 };
80 private SWTWorkbenchBot fBot;
81 private SWTBotView fView;
82 private CallGraphDensityView fFuncDensityView;
83 private SWTBotTable fTableBot;
84 private SWTBotCanvas fDensityBot;
85 private AbstractSegmentStoreDensityViewer fDensityViewer;
86 private AbstractSegmentStoreTableViewer fTableViewer;
87 private CountDownLatch fLatch;
88
89 /** The Log4j logger instance. */
90 private static final Logger fLogger = Logger.getRootLogger();
91
92 /**
93 * Initialization
94 */
95 @BeforeClass
96 public static void beforeClass() {
97
98 SWTBotUtils.initialize();
99 Thread.currentThread().setName("SWTBotTest");
100 /* set up for swtbot */
101 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
102 SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
103 fLogger.removeAllAppenders();
104 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
105 SWTWorkbenchBot bot = new SWTWorkbenchBot();
106 SWTBotUtils.closeView("welcome", bot);
107 /* Switch perspectives */
108 SWTBotUtils.switchToTracingPerspective();
109 /* Finish waiting for eclipse to load */
110 WaitUtils.waitForJobs();
111 }
112
113 /**
114 * Setup for the test
115 */
116 @Before
117 public void before() {
118 fBot = new SWTWorkbenchBot();
119 SWTBotUtils.openView(CALLGRAPHDENSITY_ID);
120 SWTBotView view = fBot.viewById(CALLGRAPHDENSITY_ID);
121 assertNotNull(view);
122 fView = view;
123 CallGraphDensityView funcDensityView = UIThreadRunnable.syncExec((Result<CallGraphDensityView>) () -> {
124 IViewPart viewRef = fView.getViewReference().getView(true);
125 return (viewRef instanceof CallGraphDensityView) ? (CallGraphDensityView) viewRef : null;
126 });
127 assertNotNull(funcDensityView);
128 fTableBot = fView.bot().table();
129 assertNotNull(fTableBot);
130 fDensityBot = fView.bot().canvas();
131 assertNotNull(fDensityBot);
132 fDensityViewer = funcDensityView.getDensityViewer();
133 assertNotNull(fDensityViewer);
134 fLatch = new CountDownLatch(1);
135 fDensityViewer.removeDataListener(fSyncListener);
136 fDensityViewer.addDataListener(fSyncListener);
137 fTableViewer = funcDensityView.getTableViewer();
138 assertNotNull(fTableViewer);
139 SWTBotUtils.maximize(funcDensityView);
140 fFuncDensityView = funcDensityView;
141 }
142
143 /**
144 * Reset
145 */
146 @After
147 public void after() {
148 CallGraphDensityView funcDensityView = fFuncDensityView;
149 assertNotNull(funcDensityView);
150 SWTBotUtils.maximize(funcDensityView);
151
152 }
153
154 @Override
155 public void emptyStateSystemTest() {
156 super.emptyStateSystemTest();
157 loadData();
158 assertEquals(0, fTableBot.rowCount());
159 ISeries series = getSeries();
160 assertNotNull(series);
161 }
162
163 @Override
164 public void cascadeTest() {
165 super.cascadeTest();
166 loadData();
167 assertEquals(3, fTableBot.rowCount());
168 ISeries series = getSeries();
edcd1f39 169 IStatistics<@NonNull Long> sss = getDescriptiveStatistics(series);
b1d4e193 170 assertEquals(3.0, sss.getTotal(), 0.0);
edcd1f39 171 assertEquals(0.02, sss.getMean(), 0.02); // low mean
b1d4e193
MK
172 }
173
174 @Override
175 public void mergeFirstLevelCalleesTest() {
176 super.mergeFirstLevelCalleesTest();
177 loadData();
178 assertEquals(5, fTableBot.rowCount());
179 ISeries series = getSeries();
edcd1f39 180 IStatistics<@NonNull Long> sss = getDescriptiveStatistics(series);
b1d4e193 181 assertEquals(5.0, sss.getTotal(), 0.0);
edcd1f39 182 assertEquals(0.02, sss.getMean(), 0.03); // low mean
b1d4e193
MK
183 }
184
185 @Override
186 public void multiFunctionRootsSecondTest() {
187 super.multiFunctionRootsSecondTest();
188 loadData();
189 assertEquals(4, fTableBot.rowCount());
190 ISeries series = getSeries();
edcd1f39 191 IStatistics<@NonNull Long> sss = getDescriptiveStatistics(series);
b1d4e193 192 assertEquals(4.0, sss.getTotal(), 0.0);
edcd1f39 193 assertEquals(0.02, sss.getMean(), 0.02); // low mean
b1d4e193
MK
194 }
195
196 @Override
197 public void mergeSecondLevelCalleesTest() {
198 super.mergeSecondLevelCalleesTest();
199 loadData();
200 assertEquals(8, fTableBot.rowCount());
201 ISeries series = getSeries();
202 double[] ySeries = series.getYSeries();
203 assertNotNull(ySeries);
edcd1f39 204 IStatistics<@NonNull Long> sss = getDescriptiveStatistics(series);
b1d4e193 205 assertEquals(8.0, sss.getTotal(), 0.0);
edcd1f39 206 assertEquals(0.06, sss.getMean(), 0.02); // average mean
b1d4e193
MK
207 }
208
209 @Override
210 public void multiFunctionRootsTest() {
211 super.multiFunctionRootsTest();
212 loadData();
213 assertEquals(4, fTableBot.rowCount());
214 ISeries series = getSeries();
215 double[] ySeries = series.getYSeries();
216 assertNotNull(ySeries);
edcd1f39 217 IStatistics<@NonNull Long> sss = getDescriptiveStatistics(series);
b1d4e193 218 assertEquals(4.0, sss.getTotal(), 0.0);
edcd1f39 219 assertEquals(0.02, sss.getMean(), 0.02); // low mean
b1d4e193
MK
220 }
221
222 @Override
223 public void treeTest() {
224 super.treeTest();
225 loadData();
226 assertEquals(4, fTableBot.rowCount());
227 ISeries series = getSeries();
228 double[] ySeries = series.getYSeries();
229 assertNotNull(ySeries);
edcd1f39 230 IStatistics<@NonNull Long> sss = getDescriptiveStatistics(series);
b1d4e193 231 assertEquals(4.0, sss.getTotal(), 0.0);
edcd1f39 232 assertEquals(0.02, sss.getMean(), 0.02); // low mean
b1d4e193
MK
233 }
234
235 @Override
236 public void largeTest() {
237 super.largeTest();
238 loadData();
239 assertEquals(1000, fTableBot.rowCount());
240 ISeries series = getSeries();
241 double[] ySeries = series.getYSeries();
242 assertNotNull(ySeries);
edcd1f39 243 IStatistics<@NonNull Long> sss = getDescriptiveStatistics(series);
b1d4e193 244 assertEquals(1000.0, sss.getTotal(), 0.0);
edcd1f39 245 assertEquals(8, sss.getMean(), 1); // high mean
b1d4e193
MK
246 }
247
248 private ISeries getSeries() {
249 AbstractSegmentStoreDensityViewer densityViewer = fDensityViewer;
250 assertNotNull(densityViewer);
251 ISeries[] serieses = densityViewer.getControl().getSeriesSet().getSeries();
252 assertNotNull(serieses);
253 assertTrue(serieses.length > 0);
254 ISeries series = serieses[0];
255 assertNotNull(series);
256 return series;
257 }
258
259 private void loadData() {
260 final ISegmentStoreProvider cga = getCga();
261 UIThreadRunnable.syncExec(() -> {
262 fTableViewer.setData(cga);
263 fDensityViewer.setSegmentProvider(cga);
264 fDensityViewer.updateWithRange(TmfTimeRange.ETERNITY);
265 fDensityViewer.refresh();
266 });
267 if (cga != null) {
268 try {
269 /*
270 * timeout of the test
271 */
272 assertTrue(fLatch.await(20, TimeUnit.SECONDS));
273 } catch (InterruptedException e) {
274 fail(e.getMessage());
275 }
276 }
277
278 }
279
edcd1f39 280 private static IStatistics<@NonNull Long> getDescriptiveStatistics(ISeries series) {
b1d4e193
MK
281 double[] ySeries = series.getYSeries();
282 assertNotNull(ySeries);
edcd1f39 283 IStatistics<@NonNull Long> stats = new Statistics<>();
b1d4e193 284 for (double item : ySeries) {
edcd1f39 285 stats.update((long) (item - 1.0));
b1d4e193 286 }
edcd1f39 287 return stats;
b1d4e193
MK
288 }
289
290}
This page took 0.037882 seconds and 5 git commands to generate.