timing.swtbot: add flamegraph doubleclick on row test
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests / src / org / eclipse / tracecompass / analysis / timing / ui / swtbot / tests / flamegraph / FlameGraphTest.java
CommitLineData
89e91a67
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.flamegraph;
11
12import static org.junit.Assert.assertEquals;
13import static org.junit.Assert.assertNotNull;
14import static org.junit.Assert.assertNull;
15import static org.junit.Assert.assertTrue;
16import static org.junit.Assert.fail;
17
18import java.util.Map;
19import java.util.Optional;
20import java.util.Spliterator;
21import java.util.Spliterators;
22import java.util.stream.StreamSupport;
23
24import org.apache.log4j.ConsoleAppender;
25import org.apache.log4j.Logger;
26import org.apache.log4j.SimpleLayout;
89e91a67 27import org.eclipse.jdt.annotation.NonNull;
89e91a67
MK
28import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
29import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
30import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
1ee63dfc 31import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
89e91a67
MK
32import org.eclipse.swtbot.swt.finder.results.Result;
33import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
34import org.eclipse.tracecompass.analysis.timing.core.tests.flamegraph.AggregationTreeTest;
35import org.eclipse.tracecompass.internal.analysis.timing.ui.flamegraph.FlameGraphPresentationProvider;
36import org.eclipse.tracecompass.internal.analysis.timing.ui.flamegraph.FlameGraphView;
fda3700b
MK
37import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
38import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
39import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotTimeGraph;
40import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotTimeGraphEntry;
89e91a67
MK
41import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
42import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
43import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer;
44import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
45import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
46import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent;
47import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent;
48import org.eclipse.ui.IViewPart;
89e91a67
MK
49import org.junit.Before;
50import org.junit.BeforeClass;
51import org.junit.Ignore;
fda3700b 52import org.junit.Test;
1ee63dfc 53import org.junit.runner.RunWith;
89e91a67
MK
54
55/**
56 * Unit tests for the flame graph view
57 *
58 * @author Matthew Khouzam
59 */
1ee63dfc 60@RunWith(SWTBotJunit4ClassRunner.class)
89e91a67
MK
61public class FlameGraphTest extends AggregationTreeTest {
62
63 private static final String FLAMEGRAPH_ID = FlameGraphView.ID;
64 private SWTWorkbenchBot fBot;
65 private SWTBotView fView;
66 private FlameGraphView fFg;
67 /** The Log4j logger instance. */
68 private static final Logger fLogger = Logger.getRootLogger();
69 private TimeGraphViewer fTimeGraphViewer;
70
71 /**
72 * Initialization
73 */
74 @BeforeClass
75 public static void beforeClass() {
76
77 SWTBotUtils.initialize();
78 Thread.currentThread().setName("SWTBotTest");
79 /* set up for swtbot */
80 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
81 SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
82 fLogger.removeAllAppenders();
83 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
84 SWTWorkbenchBot bot = new SWTWorkbenchBot();
85 SWTBotUtils.closeView("welcome", bot);
86 /* Switch perspectives */
87 SWTBotUtils.switchToTracingPerspective();
88 /* Finish waiting for eclipse to load */
89 WaitUtils.waitForJobs();
90 }
91
92 /**
93 * Open a flamegraph
94 */
95 @Before
96 public void before() {
97 fBot = new SWTWorkbenchBot();
98 SWTBotUtils.openView(FLAMEGRAPH_ID);
99 SWTBotView view = fBot.viewById(FLAMEGRAPH_ID);
100 assertNotNull(view);
101 fView = view;
102 FlameGraphView flamegraph = UIThreadRunnable.syncExec((Result<FlameGraphView>) () -> {
103 IViewPart viewRef = fView.getViewReference().getView(true);
104 return (viewRef instanceof FlameGraphView) ? (FlameGraphView) viewRef : null;
105 });
106 assertNotNull(flamegraph);
107 fTimeGraphViewer = flamegraph.getTimeGraphViewer();
108 assertNotNull(fTimeGraphViewer);
b1d4e193 109 SWTBotUtils.maximize(flamegraph);
89e91a67
MK
110 fFg = flamegraph;
111 }
112
89e91a67
MK
113 private void loadFlameGraph() {
114 UIThreadRunnable.syncExec(() -> fFg.buildFlameGraph(getCga()));
115 try {
116 fFg.waitForUpdate();
117 } catch (InterruptedException e) {
118 fail(e.getMessage());
119 }
120 }
121
122 private ITimeGraphEntry selectRoot() {
123 UIThreadRunnable.syncExec(() -> fTimeGraphViewer.selectNextItem());
124 ITimeGraphEntry entry = fTimeGraphViewer.getSelection();
125 assertNotNull(entry);
126 return entry;
127 }
128
129 private static ITimeEvent getFirstEvent(ITimeGraphEntry actualEntry) {
130 Optional<@NonNull ? extends ITimeEvent> actualEventOpt = StreamSupport.stream(Spliterators.spliteratorUnknownSize(actualEntry.getTimeEventsIterator(), Spliterator.NONNULL), false)
131 .filter(i -> (i instanceof TimeEvent)).filter(j -> !(j instanceof NullTimeEvent))
132 .findFirst();
133 assertTrue(actualEventOpt.isPresent());
fda3700b 134 return actualEventOpt.get();
89e91a67
MK
135 }
136
137 @Override
138 public void emptyStateSystemTest() {
139 super.emptyStateSystemTest();
140 loadFlameGraph();
141 ITimeGraphEntry entry = fTimeGraphViewer.getSelection();
142 assertNull(entry);
143 }
144
145 @Override
146 public void cascadeTest() {
147 super.cascadeTest();
148 loadFlameGraph();
149 ITimeGraphEntry entry = selectRoot();
150 assertEquals(3, entry.getChildren().size());
151 ITimeGraphEntry actualEntry = entry.getChildren().get(1);
152 ITimeEvent actualEvent = getFirstEvent(actualEntry);
153 assertNotNull(actualEvent);
154 assertEquals(996, actualEvent.getDuration());
155
156 }
157
158 @Override
159 public void mergeFirstLevelCalleesTest() {
160 super.mergeFirstLevelCalleesTest();
161 loadFlameGraph();
162 ITimeGraphEntry entry = selectRoot();
163 assertEquals(3, entry.getChildren().size());
164 ITimeGraphEntry actualEntry = entry.getChildren().get(1);
165 ITimeEvent actualEvent = getFirstEvent(actualEntry);
166 assertNotNull(actualEvent);
167 assertEquals(80, actualEvent.getDuration());
168 }
169
170 @Override
171 public void multiFunctionRootsSecondTest() {
172 super.multiFunctionRootsSecondTest();
173 loadFlameGraph();
174 ITimeGraphEntry entry = selectRoot();
175 assertEquals(2, entry.getChildren().size());
176 ITimeGraphEntry actualEntry = entry.getChildren().get(1);
177 ITimeEvent actualEvent = getFirstEvent(actualEntry);
178 assertNotNull(actualEvent);
179 assertEquals(10, actualEvent.getDuration());
180 }
181
182 @Override
183 public void mergeSecondLevelCalleesTest() {
184 super.mergeSecondLevelCalleesTest();
185 loadFlameGraph();
186 ITimeGraphEntry entry = selectRoot();
187 assertEquals(4, entry.getChildren().size());
188 ITimeGraphEntry actualEntry = entry.getChildren().get(1);
189 ITimeEvent actualEvent = getFirstEvent(actualEntry);
190 assertNotNull(actualEvent);
191 assertEquals(90, actualEvent.getDuration());
192 }
193
194 @Override
195 public void multiFunctionRootsTest() {
196 super.multiFunctionRootsTest();
197 loadFlameGraph();
198 ITimeGraphEntry entry = selectRoot();
199 assertEquals(2, entry.getChildren().size());
200 ITimeGraphEntry actualEntry = entry.getChildren().get(1);
201 ITimeEvent actualEvent = getFirstEvent(actualEntry);
202 assertNotNull(actualEvent);
203 assertEquals(10, actualEvent.getDuration());
204 }
205
206 /**
207 * Also test statistics tooltip
208 */
209 @Override
210 public void treeTest() {
211 super.treeTest();
212 loadFlameGraph();
213 ITimeGraphEntry entry = selectRoot();
214 assertEquals(3, entry.getChildren().size());
215 ITimeGraphEntry actualEntry = entry.getChildren().get(1);
216 ITimeEvent actualEvent = getFirstEvent(actualEntry);
217 assertNotNull(actualEvent);
218 assertEquals(80, actualEvent.getDuration());
219 Map<String, String> tooltip = new FlameGraphPresentationProvider().getEventHoverToolTipInfo(actualEvent);
220 assertNull(tooltip);
221 tooltip = new FlameGraphPresentationProvider().getEventHoverToolTipInfo(actualEvent, 5);
222 assertTrue(tooltip.toString().contains("duration=80 ns"));
223 assertTrue(tooltip.toString().contains("duration=40 ns"));
224 }
225
fda3700b
MK
226 /**
227 * Try to zoom by doubleclicking an event
228 *
229 * @throws InterruptedException
230 * on interruption
231 */
232 @Test
233 public void tryMouseDoubleclickZoom() throws InterruptedException {
234 super.treeTest();
235 loadFlameGraph();
236
237 SWTBotTimeGraph sbtg = new SWTBotTimeGraph(fView.bot());
238 // Test the number of timegraph entries in the graph
239 SWTBotTimeGraphEntry sbtge = sbtg.getEntry("Thread");
240 assertEquals(3, sbtge.getEntries().length);
241 SWTBotTimeGraphEntry actualEntry = sbtge.getEntry("1");
242
243 actualEntry.doubleClick(40);
244 fFg.waitForUpdate();
245
246 assertEquals(new TmfTimeRange(TmfTimestamp.fromNanos(0), TmfTimestamp.fromNanos(80)), new TmfTimeRange(TmfTimestamp.fromNanos(fTimeGraphViewer.getTime0()), TmfTimestamp.fromNanos(fTimeGraphViewer.getTime1())));
247 }
248
89e91a67
MK
249 /**
250 * Takes too much ram
251 */
252 @Ignore
253 @Override
254 public void largeTest() {
255 // Do nothing
256 }
257
258}
This page took 0.035292 seconds and 5 git commands to generate.