1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.lttng2
.ust
.ui
.swtbot
.tests
;
15 import static org
.junit
.Assert
.*;
18 import java
.io
.IOException
;
19 import java
.net
.URISyntaxException
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Arrays
;
23 import java
.util
.List
;
24 import java
.util
.stream
.Collectors
;
26 import org
.apache
.log4j
.ConsoleAppender
;
27 import org
.apache
.log4j
.Logger
;
28 import org
.apache
.log4j
.SimpleLayout
;
29 import org
.eclipse
.core
.runtime
.FileLocator
;
30 import org
.eclipse
.jdt
.annotation
.NonNull
;
31 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
32 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
33 import org
.eclipse
.swtbot
.swt
.finder
.SWTBot
;
34 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
35 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
36 import org
.eclipse
.swtbot
.swt
.finder
.waits
.Conditions
;
37 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
38 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
39 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotToolbarButton
;
40 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
41 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
42 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
43 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
44 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalManager
;
45 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
46 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
47 import org
.eclipse
.tracecompass
.tmf
.ui
.dialog
.TmfFileDialogFactory
;
48 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
49 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
50 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
51 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.callstack
.CallStackView
;
52 import org
.junit
.After
;
53 import org
.junit
.Before
;
54 import org
.junit
.BeforeClass
;
55 import org
.junit
.Test
;
56 import org
.junit
.runner
.RunWith
;
58 import com
.google
.common
.collect
.ImmutableList
;
61 * Test for the Call Stack view in trace compass
63 @RunWith(SWTBotJunit4ClassRunner
.class)
64 public class CallStackViewTest
{
66 private static final String UST_ID
= "org.eclipse.linuxtools.lttng2.ust.tracetype";
68 private static final String PROJECT_NAME
= "TestForCallstack";
70 /** The Log4j logger instance. */
71 private static final Logger fLogger
= Logger
.getRootLogger();
72 private static SWTWorkbenchBot fBot
;
75 * Timestamps of consecutive events in the trace
77 private static final long TIMESTAMPS
[] = new long[] {
92 * Stack frames of consecutive events in the trace
94 private static final String
[] STACK_FRAMES
[] = new String
[][] {
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", "", "" },
108 /** Tooltips of the toolbar buttons */
110 private static final @NonNull String ALIGN_VIEWS
= "Align Views";
111 private static final @NonNull String CONFIGURE_SYMBOL_PROVIDERS
= "Configure how the addresses are mapped to function names";
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";
117 private static final @NonNull String SHOW_VIEW_FILTERS
= "Show View Filters";
119 private static final @NonNull String RESET_TIME_SCALE
= "Reset the Time Scale to Default";
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";
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";
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";
132 private static final String PIN_VIEW
= "Pin View";
133 private static final List
<String
> TOOLBAR_BUTTONS_TOOLTIPS
= ImmutableList
.of(
134 ALIGN_VIEWS
, CONFIGURE_SYMBOL_PROVIDERS
,
136 SORT_BY_NAME
, SORT_BY_ID
, SORT_BY_START
,
140 RESET_TIME_SCALE
, SELECT_PREVIOUS_STATE_CHANGE
, SELECT_NEXT_STATE_CHANGE
,
142 ADD_BOOKMARK
, PREVIOUS_MARKER
, NEXT_MARKER
,
144 SELECT_PREVIOUS_ITEM
, SELECT_NEXT_ITEM
, ZOOM_IN
, ZOOM_OUT
,
152 public static void init() {
153 SWTBotUtils
.initialize();
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();
161 SWTBotUtils
.closeView("welcome", fBot
);
163 SWTBotUtils
.switchToTracingPerspective();
164 /* finish waiting for eclipse to load */
165 WaitUtils
.waitForJobs();
169 * Open a trace in an editor
172 public void beforeTest() {
173 SWTBotUtils
.createProject(PROJECT_NAME
);
174 SWTBotTreeItem treeItem
= SWTBotUtils
.selectTracesFolder(fBot
, PROJECT_NAME
);
175 assertNotNull(treeItem
);
176 final CtfTestTrace cygProfile
= CtfTestTrace
.CYG_PROFILE
;
177 final File file
= new File(CtfTmfTestTraceUtils
.getTrace(cygProfile
).getPath());
178 SWTBotUtils
.openTrace(PROJECT_NAME
, file
.getAbsolutePath(), UST_ID
);
179 SWTBotUtils
.openView(CallStackView
.ID
);
180 WaitUtils
.waitForJobs();
187 public void tearDown() {
188 fBot
.closeAllEditors();
189 SWTBotUtils
.deleteProject(PROJECT_NAME
, fBot
);
193 * Test if callstack is populated
196 public void testOpenCallstack() {
197 String node
= "glxgears-cyg-profile";
198 String processName
= "UNKNOWN";
199 String childName
= "glxgears-16073";
200 List
<String
> expected
= ImmutableList
.of("0x40472b", "", "", "", "");
202 SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
204 final SWTBotView viewBot1
= viewBot
;
205 SWTBotTree tree
= viewBot1
.bot().tree();
206 SWTBotTreeItem treeItem
= tree
.getTreeItem(node
).getNode(processName
);
207 assertEquals(childName
, treeItem
.getNodes().get(0));
208 List
<String
> names
= treeItem
.getNode(childName
).getNodes();
209 assertEquals(expected
, names
);
213 * Test check callstack at a time
216 public void testGoToTimeAndCheckStack() {
217 goToTime(TIMESTAMPS
[0]);
219 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
221 WaitUtils
.waitForJobs();
222 List
<String
> names
= getVisibleStackFrames(viewBot
);
223 assertArrayEquals(STACK_FRAMES
[0], names
.toArray());
227 * Test check callstack at a time after navigating
230 public void testGoToTimeGoBackAndForthAndCheckStack() {
231 int currentEventOffset
= 0;
232 goToTime(TIMESTAMPS
[currentEventOffset
]);
234 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
236 for (int i
= 0; i
< 10; i
++) {
237 viewBot
.toolbarPushButton(SELECT_NEXT_STATE_CHANGE
).click();
238 currentEventOffset
++;
239 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, TIMESTAMPS
[currentEventOffset
]));
240 WaitUtils
.waitForJobs();
241 assertArrayEquals(STACK_FRAMES
[currentEventOffset
], getVisibleStackFrames(viewBot
).toArray());
245 for (int i
= 0; i
< 2; i
++) {
246 viewBot
.toolbarPushButton(SELECT_PREVIOUS_STATE_CHANGE
).click();
247 currentEventOffset
--;
248 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, TIMESTAMPS
[currentEventOffset
]));
249 WaitUtils
.waitForJobs();
250 assertArrayEquals(STACK_FRAMES
[currentEventOffset
], getVisibleStackFrames(viewBot
).toArray());
252 // move up and down once to make sure it doesn't explode
253 viewBot
.toolbarPushButton(SELECT_PREVIOUS_ITEM
).click();
254 WaitUtils
.waitForJobs();
255 viewBot
.toolbarPushButton(SELECT_NEXT_ITEM
).click();
256 WaitUtils
.waitForJobs();
258 // Zoom in and out too
259 viewBot
.toolbarPushButton(ZOOM_IN
).click();
260 WaitUtils
.waitForJobs();
261 viewBot
.toolbarPushButton(ZOOM_OUT
).click();
262 WaitUtils
.waitForJobs();
266 * Test check callstack at a time with sorting, the trace is not sortable,
267 * this is a smoke test
270 public void testGoToTimeSortAndCheckStack() {
271 goToTime(TIMESTAMPS
[0]);
272 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
274 viewBot
.toolbarToggleButton(SORT_BY_NAME
).click();
275 viewBot
.toolbarToggleButton(SORT_BY_ID
).click();
276 viewBot
.toolbarToggleButton(SORT_BY_START
).click();
278 WaitUtils
.waitForJobs();
279 List
<String
> names
= getVisibleStackFrames(viewBot
);
280 assertArrayEquals(STACK_FRAMES
[0], names
.toArray());
283 private static List
<String
> getVisibleStackFrames(final SWTBotView viewBot
) {
284 SWTBotTree tree
= viewBot
.bot().tree();
285 return Arrays
.stream(tree
.getAllItems())
287 .flatMap(item
-> Arrays
.stream(item
.getItems()))
289 .flatMap(item
-> Arrays
.stream(item
.getItems()))
291 .flatMap(item
-> Arrays
.stream(item
.getItems()))
292 .map(item
-> item
.cell(0))
293 .collect(Collectors
.toList());
296 private static void goToTime(long timestamp
) {
297 SWTBotTable table
= fBot
.activeEditor().bot().table();
299 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(table
.widget
, TmfTimestamp
.fromNanos(timestamp
)));
300 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, timestamp
));
304 * Test check callstack at a time with function map
306 * @throws URISyntaxException
308 * @throws IOException
312 public void testGoToTimeAndCheckStackWithNames() throws URISyntaxException
, IOException
{
313 goToTime(TIMESTAMPS
[0]);
314 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
316 Object mapObj
= CtfTmfTestTraceUtils
.class.getResource("cyg-profile-mapping.txt");
317 assertTrue(mapObj
instanceof URL
);
318 URL mapUrl
= (URL
) mapObj
;
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
));
332 SWTBotTree tree
= viewBot
.bot().tree();
333 WaitUtils
.waitForJobs();
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));
342 assertEquals(names
, ImmutableList
.of("glxgears-16073"));
346 * Test check callstack toolbar buttons
349 public void testCallstackNavigation() {
350 SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
352 List
<String
> buttons
= new ArrayList
<>();
353 for (SWTBotToolbarButton swtBotToolbarButton
: viewBot
.getToolbarButtons()) {
354 buttons
.add(swtBotToolbarButton
.getToolTipText());
356 assertEquals(TOOLBAR_BUTTONS_TOOLTIPS
, buttons
);