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
.tests
.shared
.WaitUtils
;
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
;
51 import org
.junit
.runner
.RunWith
;
53 import com
.google
.common
.collect
.ImmutableList
;
56 * Test for the Call Stack view in trace compass
58 @RunWith(SWTBotJunit4ClassRunner
.class)
59 public class CallStackViewTest
{
61 private static final String UST_ID
= "org.eclipse.linuxtools.lttng2.ust.tracetype";
63 private static final String PROJECT_NAME
= "TestForCallstack";
65 /** The Log4j logger instance. */
66 private static final Logger fLogger
= Logger
.getRootLogger();
67 private static SWTWorkbenchBot fBot
;
70 * Timestamps of consecutive events in the trace
72 private static final long TIMESTAMPS
[] = new long[] {
87 * Stack frames of consecutive events in the trace
89 private static final String
[] STACK_FRAMES
[] = new String
[][] {
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", "", ""},
103 /** Tooltips of the toolbar buttons */
105 private static final @NonNull String ALIGN_VIEWS
= "Align Views";
106 private static final @NonNull String CONFIGURE_SYMBOL_PROVIDERS
= "Configure how the addresses are mapped to function names";
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";
112 private static final @NonNull String SHOW_VIEW_FILTERS
= "Show View Filters";
114 private static final @NonNull String RESET_TIME_SCALE
= "Reset the Time Scale to Default";
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";
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";
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";
127 private static final String PIN_VIEW
= "Pin View";
128 private static final List
<String
> TOOLBAR_BUTTONS_TOOLTIPS
= ImmutableList
.of(
129 ALIGN_VIEWS
, CONFIGURE_SYMBOL_PROVIDERS
,
131 SORT_BY_NAME
, SORT_BY_ID
, SORT_BY_START
,
135 RESET_TIME_SCALE
, SELECT_PREVIOUS_STATE_CHANGE
, SELECT_NEXT_STATE_CHANGE
,
137 ADD_BOOKMARK
, PREVIOUS_MARKER
, NEXT_MARKER
,
139 SELECT_PREVIOUS_ITEM
, SELECT_NEXT_ITEM
, ZOOM_IN
, ZOOM_OUT
,
147 public static void init() {
148 SWTBotUtils
.initialize();
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();
156 SWTBotUtils
.closeView("welcome", fBot
);
158 SWTBotUtils
.switchToTracingPerspective();
159 /* finish waiting for eclipse to load */
160 WaitUtils
.waitForJobs();
164 * Open a trace in an editor
167 public void beforeTest() {
168 SWTBotUtils
.createProject(PROJECT_NAME
);
169 SWTBotTreeItem treeItem
= SWTBotUtils
.selectTracesFolder(fBot
, PROJECT_NAME
);
170 assertNotNull(treeItem
);
171 final CtfTestTrace cygProfile
= CtfTestTrace
.CYG_PROFILE
;
172 final File file
= new File(CtfTmfTestTraceUtils
.getTrace(cygProfile
).getPath());
173 SWTBotUtils
.openTrace(PROJECT_NAME
, file
.getAbsolutePath(), UST_ID
);
174 SWTBotUtils
.openView(CallStackView
.ID
);
175 WaitUtils
.waitForJobs();
182 public void tearDown() {
183 fBot
.closeAllEditors();
184 SWTBotUtils
.deleteProject(PROJECT_NAME
, fBot
);
188 * Test if callstack is populated
191 public void testOpenCallstack() {
192 String node
= "glxgears-cyg-profile";
193 String processName
= "UNKNOWN";
194 String childName
= "glxgears-16073";
195 List
<String
> expected
= ImmutableList
.of("0x40472b", "", "", "", "");
197 SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
199 final SWTBotView viewBot1
= viewBot
;
200 SWTBotTree tree
= viewBot1
.bot().tree();
201 SWTBotTreeItem treeItem
= tree
.getTreeItem(node
).getNode(processName
);
202 assertEquals(childName
, treeItem
.getNodes().get(0));
203 List
<String
> names
= treeItem
.getNode(childName
).getNodes();
204 assertEquals(expected
, names
);
208 * Test check callstack at a time
211 public void testGoToTimeAndCheckStack() {
212 goToTime(TIMESTAMPS
[0]);
214 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
216 WaitUtils
.waitForJobs();
217 List
<String
> names
= getVisibleStackFrames(viewBot
);
218 assertArrayEquals(STACK_FRAMES
[0], names
.toArray());
222 * Test check callstack at a time after navigating
225 public void testGoToTimeGoBackAndForthAndCheckStack() {
226 int currentEventOffset
= 0;
227 goToTime(TIMESTAMPS
[currentEventOffset
]);
229 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
231 for (int i
= 0; i
< 10; i
++) {
232 viewBot
.toolbarPushButton(SELECT_NEXT_STATE_CHANGE
).click();
233 currentEventOffset
++;
234 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, TIMESTAMPS
[currentEventOffset
]));
235 WaitUtils
.waitForJobs();
236 assertArrayEquals(STACK_FRAMES
[currentEventOffset
], getVisibleStackFrames(viewBot
).toArray());
240 for (int i
= 0; i
< 2; i
++) {
241 viewBot
.toolbarPushButton(SELECT_PREVIOUS_STATE_CHANGE
).click();
242 currentEventOffset
--;
243 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, TIMESTAMPS
[currentEventOffset
]));
244 WaitUtils
.waitForJobs();
245 assertArrayEquals(STACK_FRAMES
[currentEventOffset
], getVisibleStackFrames(viewBot
).toArray());
247 // move up and down once to make sure it doesn't explode
248 viewBot
.toolbarPushButton(SELECT_PREVIOUS_ITEM
).click();
249 WaitUtils
.waitForJobs();
250 viewBot
.toolbarPushButton(SELECT_NEXT_ITEM
).click();
251 WaitUtils
.waitForJobs();
253 // Zoom in and out too
254 viewBot
.toolbarPushButton(ZOOM_IN
).click();
255 WaitUtils
.waitForJobs();
256 viewBot
.toolbarPushButton(ZOOM_OUT
).click();
257 WaitUtils
.waitForJobs();
261 * Test check callstack at a time with sorting, the trace is not sortable,
262 * this is a smoke test
265 public void testGoToTimeSortAndCheckStack() {
266 goToTime(TIMESTAMPS
[0]);
267 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
269 viewBot
.toolbarToggleButton(SORT_BY_NAME
).click();
270 viewBot
.toolbarToggleButton(SORT_BY_ID
).click();
271 viewBot
.toolbarToggleButton(SORT_BY_START
).click();
273 WaitUtils
.waitForJobs();
274 List
<String
> names
= getVisibleStackFrames(viewBot
);
275 assertArrayEquals(STACK_FRAMES
[0], names
.toArray());
278 private static List
<String
> getVisibleStackFrames(final SWTBotView viewBot
) {
279 SWTBotTree tree
= viewBot
.bot().tree();
280 return Arrays
.stream(tree
.getAllItems())
282 .flatMap(item
-> Arrays
.stream(item
.getItems()))
284 .flatMap(item
-> Arrays
.stream(item
.getItems()))
286 .flatMap(item
-> Arrays
.stream(item
.getItems()))
287 .map(item
-> item
.cell(0))
288 .collect(Collectors
.toList());
291 private static void goToTime(long timestamp
) {
292 SWTBotTable table
= fBot
.activeEditor().bot().table();
294 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(table
.widget
, TmfTimestamp
.fromNanos(timestamp
)));
295 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, timestamp
));
299 * Test check callstack at a time with function map
303 public void testGoToTimeAndCheckStackWithNames() {
304 goToTime(TIMESTAMPS
[0]);
305 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
307 // no way to load mappings yet! :(
308 SWTBotTree tree
= viewBot
.bot().tree();
309 WaitUtils
.waitForJobs();
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));
321 * Test check callstack toolbar buttons
324 public void testCallstackNavigation() {
325 SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
327 List
<String
> buttons
= new ArrayList
<>();
328 for (SWTBotToolbarButton swtBotToolbarButton
: viewBot
.getToolbarButtons()) {
329 buttons
.add(swtBotToolbarButton
.getToolTipText());
331 assertEquals(TOOLBAR_BUTTONS_TOOLTIPS
, buttons
);