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