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