1bbad5616128554e9a3f5c522cd18d2beee1a782
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / ust / ui / swtbot / tests / CallStackViewTest.java
1 /*******************************************************************************
2 * Copyright (c) 2015, 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 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests;
14
15 import static org.junit.Assert.assertArrayEquals;
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertNotNull;
18
19 import java.io.File;
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.List;
23 import java.util.stream.Collectors;
24
25 import org.apache.log4j.ConsoleAppender;
26 import org.apache.log4j.Logger;
27 import org.apache.log4j.SimpleLayout;
28 import org.eclipse.jdt.annotation.NonNull;
29 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
30 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
31 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
32 import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
33 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
34 import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
35 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
36 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
37 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
38 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
39 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
40 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
41 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
42 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
43 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
44 import org.eclipse.tracecompass.tmf.ui.views.callstack.CallStackView;
45 import org.junit.After;
46 import org.junit.Before;
47 import org.junit.BeforeClass;
48 import org.junit.Ignore;
49 import org.junit.Test;
50 import org.junit.runner.RunWith;
51
52 import com.google.common.collect.ImmutableList;
53
54 /**
55 * Test for the Call Stack view in trace compass
56 */
57 @RunWith(SWTBotJunit4ClassRunner.class)
58 public class CallStackViewTest {
59
60 private static final String UST_ID = "org.eclipse.linuxtools.lttng2.ust.tracetype";
61
62 private static final String PROJECT_NAME = "TestForCallstack";
63
64 /** The Log4j logger instance. */
65 private static final Logger fLogger = Logger.getRootLogger();
66 private static SWTWorkbenchBot fBot;
67
68 /**
69 * Timestamps of consecutive events in the trace
70 */
71 private static final long TIMESTAMPS[] = new long[] {
72 1378850463804898643l,
73 1378850463804899057l,
74 1378850463804900219l,
75 1378850463804900678l,
76 1378850463804901308l,
77 1378850463804901909l,
78 1378850463804902763l,
79 1378850463804903168l,
80 1378850463804903766l,
81 1378850463804904165l,
82 1378850463804904970l,
83 };
84
85 /**
86 * Stack frames of consecutive events in the trace
87 */
88 private static final String[] STACK_FRAMES[] = new String[][] {
89 {"0x40472b", "0x4045c8", "0x404412", "", ""},
90 {"0x40472b", "0x4045c8", "0x404412", "0x40392b", ""},
91 {"0x40472b", "0x4045c8", "0x404412", "", ""},
92 {"0x40472b", "0x4045c8", "", "", ""},
93 {"0x40472b", "0x4045c8", "0x404412", "", ""},
94 {"0x40472b", "0x4045c8", "0x404412", "0x40392b", ""},
95 {"0x40472b", "0x4045c8", "0x404412", "", ""},
96 {"0x40472b", "0x4045c8", "", "", ""},
97 {"0x40472b", "0x4045c8", "0x404412", "", ""},
98 {"0x40472b", "0x4045c8", "0x404412", "0x40392b", ""},
99 {"0x40472b", "0x4045c8", "0x404412", "", ""},
100 };
101
102 /** Tooltips of the toolbar buttons */
103
104 private static final @NonNull String ALIGN_VIEWS = "Align Views";
105 private static final @NonNull String CONFIGURE_SYMBOL_PROVIDERS = "Configure how the addresses are mapped to function names";
106 // Separator
107 private static final @NonNull String SORT_BY_NAME = "Sort threads by thread name";
108 private static final @NonNull String SORT_BY_ID = "Sort threads by thread id";
109 private static final @NonNull String SORT_BY_START = "Sort threads by start time";
110 // Separator
111 private static final @NonNull String SHOW_VIEW_FILTERS = "Show View Filters";
112 // Separator
113 private static final @NonNull String RESET_TIME_SCALE = "Reset the Time Scale to Default";
114 private static final @NonNull String SELECT_PREVIOUS_STATE_CHANGE = "Select Previous State Change";
115 private static final @NonNull String SELECT_NEXT_STATE_CHANGE = "Select Next State Change";
116 // Separator
117 private static final @NonNull String ADD_BOOKMARK = "Add Bookmark...";
118 private static final @NonNull String PREVIOUS_MARKER = "Previous Marker";
119 private static final @NonNull String NEXT_MARKER = "Next Marker";
120 // Separator
121 private static final @NonNull String SELECT_PREVIOUS_ITEM = "Select Previous Item";
122 private static final @NonNull String SELECT_NEXT_ITEM = "Select Next Item";
123 private static final @NonNull String ZOOM_IN = "Zoom In";
124 private static final @NonNull String ZOOM_OUT = "Zoom Out";
125 // Separator
126 private static final String PIN_VIEW = "Pin View";
127 private static final List<String> TOOLBAR_BUTTONS_TOOLTIPS = ImmutableList.of(
128 ALIGN_VIEWS, CONFIGURE_SYMBOL_PROVIDERS,
129 "",
130 SORT_BY_NAME, SORT_BY_ID, SORT_BY_START,
131 "",
132 SHOW_VIEW_FILTERS,
133 "",
134 RESET_TIME_SCALE, SELECT_PREVIOUS_STATE_CHANGE, SELECT_NEXT_STATE_CHANGE,
135 "",
136 ADD_BOOKMARK, PREVIOUS_MARKER, NEXT_MARKER,
137 "",
138 SELECT_PREVIOUS_ITEM, SELECT_NEXT_ITEM, ZOOM_IN, ZOOM_OUT,
139 "",
140 PIN_VIEW);
141
142 /**
143 * Initialization
144 */
145 @BeforeClass
146 public static void init() {
147 SWTBotUtils.initialize();
148
149 Thread.currentThread().setName("SWTBot Thread"); // for the debugger
150 /* set up for swtbot */
151 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
152 fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
153 fBot = new SWTWorkbenchBot();
154
155 SWTBotUtils.closeView("welcome", fBot);
156
157 SWTBotUtils.switchToTracingPerspective();
158 /* finish waiting for eclipse to load */
159 SWTBotUtils.waitForJobs();
160 }
161
162 /**
163 * Open a trace in an editor
164 */
165 @Before
166 public void beforeTest() {
167 SWTBotUtils.createProject(PROJECT_NAME);
168 SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
169 assertNotNull(treeItem);
170 final CtfTestTrace cygProfile = CtfTestTrace.CYG_PROFILE;
171 final File file = new File(CtfTmfTestTraceUtils.getTrace(cygProfile).getPath());
172 SWTBotUtils.openTrace(PROJECT_NAME, file.getAbsolutePath(), UST_ID);
173 SWTBotUtils.openView(CallStackView.ID);
174 SWTBotUtils.waitForJobs();
175 }
176
177 /**
178 * Close the editor
179 */
180 @After
181 public void tearDown() {
182 fBot.closeAllEditors();
183 SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
184 }
185
186 /**
187 * Test if callstack is populated
188 */
189 @Test
190 public void testOpenCallstack() {
191 String node = "glxgears-cyg-profile";
192 String processName = "UNKNOWN";
193 String childName = "glxgears-16073";
194 List<String> expected = ImmutableList.of("0x40472b", "", "", "", "");
195
196 SWTBotView viewBot = fBot.viewById(CallStackView.ID);
197 viewBot.setFocus();
198 final SWTBotView viewBot1 = viewBot;
199 SWTBotTree tree = viewBot1.bot().tree();
200 SWTBotTreeItem treeItem = tree.getTreeItem(node).getNode(processName);
201 assertEquals(childName, treeItem.getNodes().get(0));
202 List<String> names = treeItem.getNode(childName).getNodes();
203 assertEquals(expected, names);
204 }
205
206 /**
207 * Test check callstack at a time
208 */
209 @Test
210 public void testGoToTimeAndCheckStack() {
211 goToTime(TIMESTAMPS[0]);
212
213 final SWTBotView viewBot = fBot.viewById(CallStackView.ID);
214 viewBot.setFocus();
215 SWTBotUtils.waitForJobs();
216 List<String> names = getVisibleStackFrames(viewBot);
217 assertArrayEquals(STACK_FRAMES[0], names.toArray());
218 }
219
220 /**
221 * Test check callstack at a time after navigating
222 */
223 @Test
224 public void testGoToTimeGoBackAndForthAndCheckStack() {
225 int currentEventOffset = 0;
226 goToTime(TIMESTAMPS[currentEventOffset]);
227
228 final SWTBotView viewBot = fBot.viewById(CallStackView.ID);
229 // forward 10 times
230 for (int i = 0; i < 10; i++) {
231 viewBot.toolbarPushButton(SELECT_NEXT_STATE_CHANGE).click();
232 currentEventOffset++;
233 fBot.waitUntil(ConditionHelpers.selectionInEventsTable(fBot, TIMESTAMPS[currentEventOffset]));
234 SWTBotUtils.waitForJobs();
235 assertArrayEquals(STACK_FRAMES[currentEventOffset], getVisibleStackFrames(viewBot).toArray());
236
237 }
238 // back twice
239 for (int i = 0; i < 2; i++) {
240 viewBot.toolbarPushButton(SELECT_PREVIOUS_STATE_CHANGE).click();
241 currentEventOffset--;
242 fBot.waitUntil(ConditionHelpers.selectionInEventsTable(fBot, TIMESTAMPS[currentEventOffset]));
243 SWTBotUtils.waitForJobs();
244 assertArrayEquals(STACK_FRAMES[currentEventOffset], getVisibleStackFrames(viewBot).toArray());
245 }
246 // move up and down once to make sure it doesn't explode
247 viewBot.toolbarPushButton(SELECT_PREVIOUS_ITEM).click();
248 SWTBotUtils.waitForJobs();
249 viewBot.toolbarPushButton(SELECT_NEXT_ITEM).click();
250 SWTBotUtils.waitForJobs();
251
252 // Zoom in and out too
253 viewBot.toolbarPushButton(ZOOM_IN).click();
254 SWTBotUtils.waitForJobs();
255 viewBot.toolbarPushButton(ZOOM_OUT).click();
256 SWTBotUtils.waitForJobs();
257 }
258
259 /**
260 * Test check callstack at a time with sorting, the trace is not sortable,
261 * this is a smoke test
262 */
263 @Test
264 public void testGoToTimeSortAndCheckStack() {
265 goToTime(TIMESTAMPS[0]);
266 final SWTBotView viewBot = fBot.viewById(CallStackView.ID);
267 viewBot.setFocus();
268 viewBot.toolbarToggleButton(SORT_BY_NAME).click();
269 viewBot.toolbarToggleButton(SORT_BY_ID).click();
270 viewBot.toolbarToggleButton(SORT_BY_START).click();
271 viewBot.setFocus();
272 SWTBotUtils.waitForJobs();
273 List<String> names = getVisibleStackFrames(viewBot);
274 assertArrayEquals(STACK_FRAMES[0], names.toArray());
275 }
276
277 private static List<String> getVisibleStackFrames(final SWTBotView viewBot) {
278 SWTBotTree tree = viewBot.bot().tree();
279 return Arrays.stream(tree.getAllItems())
280 // Process entries
281 .flatMap(item -> Arrays.stream(item.getItems()))
282 // Thread entries
283 .flatMap(item -> Arrays.stream(item.getItems()))
284 // Callstack entries
285 .flatMap(item -> Arrays.stream(item.getItems()))
286 .map(item -> item.cell(0))
287 .collect(Collectors.toList());
288 }
289
290 private static void goToTime(long timestamp) {
291 SWTBotTable table = fBot.activeEditor().bot().table();
292 table.setFocus();
293 TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(table.widget, TmfTimestamp.fromNanos(timestamp)));
294 fBot.waitUntil(ConditionHelpers.selectionInEventsTable(fBot, timestamp));
295 }
296
297 /**
298 * Test check callstack at a time with function map
299 */
300 @Ignore
301 @Test
302 public void testGoToTimeAndCheckStackWithNames() {
303 goToTime(TIMESTAMPS[0]);
304 final SWTBotView viewBot = fBot.viewById(CallStackView.ID);
305 viewBot.setFocus();
306 // no way to load mappings yet! :(
307 SWTBotTree tree = viewBot.bot().tree();
308 SWTBotUtils.waitForJobs();
309 List<String> names = new ArrayList<>();
310 for (SWTBotTreeItem swtBotTreeItem : tree.getAllItems()) {
311 for (SWTBotTreeItem items : swtBotTreeItem.getItems()) {
312 for (SWTBotTreeItem item : items.getItems()) {
313 names.add(item.cell(0));
314 }
315 }
316 }
317 }
318
319 /**
320 * Test check callstack toolbar buttons
321 */
322 @Test
323 public void testCallstackNavigation() {
324 SWTBotView viewBot = fBot.viewById(CallStackView.ID);
325 viewBot.setFocus();
326 List<String> buttons = new ArrayList<>();
327 for (SWTBotToolbarButton swtBotToolbarButton : viewBot.getToolbarButtons()) {
328 buttons.add(swtBotToolbarButton.getToolTipText());
329 }
330 assertEquals(TOOLBAR_BUTTONS_TOOLTIPS, buttons);
331 }
332 }
This page took 0.047288 seconds and 4 git commands to generate.