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