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
.assertArrayEquals
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertNotNull
;
20 import java
.util
.ArrayList
;
21 import java
.util
.Arrays
;
22 import java
.util
.List
;
23 import java
.util
.stream
.Collectors
;
25 import org
.apache
.log4j
.ConsoleAppender
;
26 import org
.apache
.log4j
.Logger
;
27 import org
.apache
.log4j
.SimpleLayout
;
28 import org
.eclipse
.jdt
.annotation
.NonNull
;
29 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
30 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
31 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
32 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
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
;
37 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
38 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
39 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalManager
;
40 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
41 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
42 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
43 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
44 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.callstack
.CallStackView
;
45 import org
.junit
.After
;
46 import org
.junit
.Before
;
47 import org
.junit
.BeforeClass
;
48 import org
.junit
.Ignore
;
49 import org
.junit
.Test
;
50 import org
.junit
.runner
.RunWith
;
52 import com
.google
.common
.collect
.ImmutableList
;
55 * Test for the Call Stack view in trace compass
57 @RunWith(SWTBotJunit4ClassRunner
.class)
58 public class CallStackViewTest
{
60 private static final String UST_ID
= "org.eclipse.linuxtools.lttng2.ust.tracetype";
62 private static final String PROJECT_NAME
= "TestForCallstack";
64 /** The Log4j logger instance. */
65 private static final Logger fLogger
= Logger
.getRootLogger();
66 private static SWTWorkbenchBot fBot
;
69 * Timestamps of consecutive events in the trace
71 private static final long TIMESTAMPS
[] = new long[] {
86 * Stack frames of consecutive events in the trace
88 private static final String
[] STACK_FRAMES
[] = new String
[][] {
89 {"0x40472b", "0x4045c8", "0x404412", "", ""},
90 {"0x40472b", "0x4045c8", "0x404412", "0x40392b", ""},
91 {"0x40472b", "0x4045c8", "0x404412", "", ""},
92 {"0x40472b", "0x4045c8", "", "", ""},
93 {"0x40472b", "0x4045c8", "0x404412", "", ""},
94 {"0x40472b", "0x4045c8", "0x404412", "0x40392b", ""},
95 {"0x40472b", "0x4045c8", "0x404412", "", ""},
96 {"0x40472b", "0x4045c8", "", "", ""},
97 {"0x40472b", "0x4045c8", "0x404412", "", ""},
98 {"0x40472b", "0x4045c8", "0x404412", "0x40392b", ""},
99 {"0x40472b", "0x4045c8", "0x404412", "", ""},
102 /** Tooltips of the toolbar buttons */
104 private static final @NonNull String ALIGN_VIEWS
= "Align Views";
105 private static final @NonNull String CONFIGURE_SYMBOL_PROVIDERS
= "Configure how the addresses are mapped to function names";
107 private static final @NonNull String SORT_BY_NAME
= "Sort threads by thread name";
108 private static final @NonNull String SORT_BY_ID
= "Sort threads by thread id";
109 private static final @NonNull String SORT_BY_START
= "Sort threads by start time";
111 private static final @NonNull String SHOW_VIEW_FILTERS
= "Show View Filters";
113 private static final @NonNull String RESET_TIME_SCALE
= "Reset the Time Scale to Default";
114 private static final @NonNull String SELECT_PREVIOUS_EVENT
= "Select Previous Event";
115 private static final @NonNull String SELECT_NEXT_EVENT
= "Select Next Event";
117 private static final @NonNull String ADD_BOOKMARK
= "Add Bookmark...";
118 private static final @NonNull String PREVIOUS_MARKER
= "Previous Marker";
119 private static final @NonNull String NEXT_MARKER
= "Next Marker";
121 private static final @NonNull String SELECT_PREVIOUS_ITEM
= "Select Previous Item";
122 private static final @NonNull String SELECT_NEXT_ITEM
= "Select Next Item";
123 private static final @NonNull String ZOOM_IN
= "Zoom In";
124 private static final @NonNull String ZOOM_OUT
= "Zoom Out";
126 private static final String PIN_VIEW
= "Pin View";
127 private static final List
<String
> TOOLBAR_BUTTONS_TOOLTIPS
= ImmutableList
.of(
128 ALIGN_VIEWS
, CONFIGURE_SYMBOL_PROVIDERS
,
130 SORT_BY_NAME
, SORT_BY_ID
, SORT_BY_START
,
134 RESET_TIME_SCALE
, SELECT_PREVIOUS_EVENT
, SELECT_NEXT_EVENT
,
136 ADD_BOOKMARK
, PREVIOUS_MARKER
, NEXT_MARKER
,
138 SELECT_PREVIOUS_ITEM
, SELECT_NEXT_ITEM
, ZOOM_IN
, ZOOM_OUT
,
146 public static void init() {
147 SWTBotUtils
.initialize();
149 Thread
.currentThread().setName("SWTBot Thread"); // for the debugger
150 /* set up for swtbot */
151 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
152 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout()));
153 fBot
= new SWTWorkbenchBot();
155 SWTBotUtils
.closeView("welcome", fBot
);
157 SWTBotUtils
.switchToTracingPerspective();
158 /* finish waiting for eclipse to load */
159 SWTBotUtils
.waitForJobs();
163 * Open a trace in an editor
166 public void beforeTest() {
167 SWTBotUtils
.createProject(PROJECT_NAME
);
168 SWTBotTreeItem treeItem
= SWTBotUtils
.selectTracesFolder(fBot
, PROJECT_NAME
);
169 assertNotNull(treeItem
);
170 final CtfTestTrace cygProfile
= CtfTestTrace
.CYG_PROFILE
;
171 final File file
= new File(CtfTmfTestTraceUtils
.getTrace(cygProfile
).getPath());
172 SWTBotUtils
.openTrace(PROJECT_NAME
, file
.getAbsolutePath(), UST_ID
);
173 SWTBotUtils
.openView(CallStackView
.ID
);
174 SWTBotUtils
.waitForJobs();
181 public void tearDown() {
182 fBot
.closeAllEditors();
183 SWTBotUtils
.deleteProject(PROJECT_NAME
, fBot
);
187 * Test if callstack is populated
190 public void testOpenCallstack() {
191 String node
= "glxgears-cyg-profile";
192 String processName
= "UNKNOWN";
193 String childName
= "glxgears-16073";
194 List
<String
> expected
= ImmutableList
.of("0x40472b", "", "", "", "");
196 SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
198 final SWTBotView viewBot1
= viewBot
;
199 SWTBotTree tree
= viewBot1
.bot().tree();
200 SWTBotTreeItem treeItem
= tree
.getTreeItem(node
).getNode(processName
);
201 assertEquals(childName
, treeItem
.getNodes().get(0));
202 List
<String
> names
= treeItem
.getNode(childName
).getNodes();
203 assertEquals(expected
, names
);
207 * Test check callstack at a time
210 public void testGoToTimeAndCheckStack() {
211 goToTime(TIMESTAMPS
[0]);
213 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
215 SWTBotUtils
.waitForJobs();
216 List
<String
> names
= getVisibleStackFrames(viewBot
);
217 assertArrayEquals(STACK_FRAMES
[0], names
.toArray());
221 * Test check callstack at a time after navigating
224 public void testGoToTimeGoBackAndForthAndCheckStack() {
225 int currentEventOffset
= 0;
226 goToTime(TIMESTAMPS
[currentEventOffset
]);
228 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
230 for (int i
= 0; i
< 10; i
++) {
231 viewBot
.toolbarPushButton(SELECT_NEXT_EVENT
).click();
232 currentEventOffset
++;
233 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, TIMESTAMPS
[currentEventOffset
]));
234 SWTBotUtils
.waitForJobs();
235 assertArrayEquals(STACK_FRAMES
[currentEventOffset
], getVisibleStackFrames(viewBot
).toArray());
239 for (int i
= 0; i
< 2; i
++) {
240 viewBot
.toolbarPushButton(SELECT_PREVIOUS_EVENT
).click();
241 currentEventOffset
--;
242 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, TIMESTAMPS
[currentEventOffset
]));
243 SWTBotUtils
.waitForJobs();
244 assertArrayEquals(STACK_FRAMES
[currentEventOffset
], getVisibleStackFrames(viewBot
).toArray());
246 // move up and down once to make sure it doesn't explode
247 viewBot
.toolbarPushButton(SELECT_PREVIOUS_ITEM
).click();
248 SWTBotUtils
.waitForJobs();
249 viewBot
.toolbarPushButton(SELECT_NEXT_ITEM
).click();
250 SWTBotUtils
.waitForJobs();
252 // Zoom in and out too
253 viewBot
.toolbarPushButton(ZOOM_IN
).click();
254 SWTBotUtils
.waitForJobs();
255 viewBot
.toolbarPushButton(ZOOM_OUT
).click();
256 SWTBotUtils
.waitForJobs();
260 * Test check callstack at a time with sorting, the trace is not sortable,
261 * this is a smoke test
264 public void testGoToTimeSortAndCheckStack() {
265 goToTime(TIMESTAMPS
[0]);
266 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
268 viewBot
.toolbarToggleButton(SORT_BY_NAME
).click();
269 viewBot
.toolbarToggleButton(SORT_BY_ID
).click();
270 viewBot
.toolbarToggleButton(SORT_BY_START
).click();
272 SWTBotUtils
.waitForJobs();
273 List
<String
> names
= getVisibleStackFrames(viewBot
);
274 assertArrayEquals(STACK_FRAMES
[0], names
.toArray());
277 private static List
<String
> getVisibleStackFrames(final SWTBotView viewBot
) {
278 SWTBotTree tree
= viewBot
.bot().tree();
279 return Arrays
.stream(tree
.getAllItems())
281 .flatMap(item
-> Arrays
.stream(item
.getItems()))
283 .flatMap(item
-> Arrays
.stream(item
.getItems()))
285 .flatMap(item
-> Arrays
.stream(item
.getItems()))
286 .map(item
-> item
.cell(0))
287 .collect(Collectors
.toList());
290 private static void goToTime(long timestamp
) {
291 SWTBotTable table
= fBot
.activeEditor().bot().table();
293 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(table
.widget
, TmfTimestamp
.fromNanos(timestamp
)));
294 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, timestamp
));
298 * Test check callstack at a time with function map
302 public void testGoToTimeAndCheckStackWithNames() {
303 goToTime(TIMESTAMPS
[0]);
304 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
306 // no way to load mappings yet! :(
307 SWTBotTree tree
= viewBot
.bot().tree();
308 SWTBotUtils
.waitForJobs();
309 List
<String
> names
= new ArrayList
<>();
310 for (SWTBotTreeItem swtBotTreeItem
: tree
.getAllItems()) {
311 for (SWTBotTreeItem items
: swtBotTreeItem
.getItems()) {
312 for (SWTBotTreeItem item
: items
.getItems()) {
313 names
.add(item
.cell(0));
320 * Test check callstack toolbar buttons
323 public void testCallstackNavigation() {
324 SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
326 List
<String
> buttons
= new ArrayList
<>();
327 for (SWTBotToolbarButton swtBotToolbarButton
: viewBot
.getToolbarButtons()) {
328 buttons
.add(swtBotToolbarButton
.getToolTipText());
330 assertEquals(TOOLBAR_BUTTONS_TOOLTIPS
, buttons
);