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