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