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