1 /*******************************************************************************
2 * Copyright (c) 2015 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
.List
;
23 import org
.apache
.log4j
.ConsoleAppender
;
24 import org
.apache
.log4j
.Logger
;
25 import org
.apache
.log4j
.SimpleLayout
;
26 import org
.eclipse
.jdt
.annotation
.NonNull
;
27 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
28 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
29 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
30 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
31 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
32 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotToolbarButton
;
33 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
34 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
35 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalManager
;
38 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
39 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
40 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
41 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
42 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.callstack
.CallStackView
;
43 import org
.junit
.After
;
44 import org
.junit
.Before
;
45 import org
.junit
.BeforeClass
;
46 import org
.junit
.Ignore
;
47 import org
.junit
.Test
;
48 import org
.junit
.runner
.RunWith
;
50 import com
.google
.common
.collect
.ImmutableList
;
53 * Test for the Call Stack view in trace compass
55 @RunWith(SWTBotJunit4ClassRunner
.class)
56 public class CallStackViewTest
{
58 private static final String UST_ID
= "org.eclipse.linuxtools.lttng2.ust.tracetype";
60 private static final String PROJECT_NAME
= "TestForCallstack";
62 /** The Log4j logger instance. */
63 private static final Logger fLogger
= Logger
.getRootLogger();
64 private static SWTWorkbenchBot fBot
;
67 * Timestamps of consecutive events in the trace
69 private static final long TIMESTAMPS
[] = new long[] {
84 * Stack frames of consecutive events in the trace
86 private static final String
[] STACK_FRAMES
[] = new String
[][] {
87 {"40472b", "4045c8", "404412", "", ""},
88 {"40472b", "4045c8", "404412", "40392b", ""},
89 {"40472b", "4045c8", "404412", "", ""},
90 {"40472b", "4045c8", "", "", ""},
91 {"40472b", "4045c8", "404412", "", ""},
92 {"40472b", "4045c8", "404412", "40392b", ""},
93 {"40472b", "4045c8", "404412", "", ""},
94 {"40472b", "4045c8", "", "", ""},
95 {"40472b", "4045c8", "404412", "", ""},
96 {"40472b", "4045c8", "404412", "40392b", ""},
97 {"40472b", "4045c8", "404412", "", ""},
100 /** Tooltips of the toolbar buttons */
102 private static final @NonNull String ALIGN_VIEWS
= "Align Views";
103 private static final @NonNull String IMPORT_BINARY
= "Import a binary file containing debugging symbols";
104 private static final @NonNull String IMPORT_TEXT
= "Import a text file containing the mapping between addresses and function names";
106 private static final @NonNull String SORT_BY_NAME
= "Sort threads by thread name";
107 private static final @NonNull String SORT_BY_ID
= "Sort threads by thread id";
108 private static final @NonNull String SORT_BY_START
= "Sort threads by start time";
110 private static final @NonNull String SHOW_VIEW_FILTERS
= "Show View Filters";
112 private static final @NonNull String RESET_TIME_SCALE
= "Reset the Time Scale to Default";
113 private static final @NonNull String SELECT_PREVIOUS_EVENT
= "Select Previous Event";
114 private static final @NonNull String SELECT_NEXT_EVENT
= "Select Next Event";
116 private static final @NonNull String ADD_BOOKMARK
= "Add Bookmark...";
117 private static final @NonNull String PREVIOUS_MARKER
= "Previous Marker";
118 private static final @NonNull String NEXT_MARKER
= "Next Marker";
120 private static final @NonNull String SELECT_PREVIOUS_ITEM
= "Select Previous Item";
121 private static final @NonNull String SELECT_NEXT_ITEM
= "Select Next Item";
122 private static final @NonNull String ZOOM_IN
= "Zoom In";
123 private static final @NonNull String ZOOM_OUT
= "Zoom Out";
125 private static final String PIN_VIEW
= "Pin View";
126 private static final List
<String
> TOOLBAR_BUTTONS_TOOLTIPS
= ImmutableList
.of(
127 ALIGN_VIEWS
, IMPORT_BINARY
, IMPORT_TEXT
,
129 SORT_BY_NAME
, SORT_BY_ID
, SORT_BY_START
,
133 RESET_TIME_SCALE
, SELECT_PREVIOUS_EVENT
, SELECT_NEXT_EVENT
,
135 ADD_BOOKMARK
, PREVIOUS_MARKER
, NEXT_MARKER
,
137 SELECT_PREVIOUS_ITEM
, SELECT_NEXT_ITEM
, ZOOM_IN
, ZOOM_OUT
,
145 public static void init() {
146 SWTBotUtils
.failIfUIThread();
148 Thread
.currentThread().setName("SWTBot Thread"); // for the debugger
149 /* set up for swtbot */
150 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
151 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout()));
152 fBot
= new SWTWorkbenchBot();
154 SWTBotUtils
.closeView("welcome", fBot
);
156 SWTBotUtils
.switchToTracingPerspective();
157 /* finish waiting for eclipse to load */
158 SWTBotUtils
.waitForJobs();
162 * Open a trace in an editor
165 public void beforeTest() {
166 SWTBotUtils
.createProject(PROJECT_NAME
);
167 SWTBotTreeItem treeItem
= SWTBotUtils
.selectTracesFolder(fBot
, PROJECT_NAME
);
168 assertNotNull(treeItem
);
169 final CtfTestTrace cygProfile
= CtfTestTrace
.CYG_PROFILE
;
170 final File file
= new File(CtfTmfTestTraceUtils
.getTrace(cygProfile
).getPath());
171 SWTBotUtils
.openTrace(PROJECT_NAME
, file
.getAbsolutePath(), UST_ID
);
172 SWTBotUtils
.openView(CallStackView
.ID
);
173 SWTBotUtils
.waitForJobs();
180 public void tearDown() {
181 fBot
.closeAllEditors();
182 SWTBotUtils
.deleteProject(PROJECT_NAME
, fBot
);
186 * Test if callstack is populated
189 public void testOpenCallstack() {
190 String node
= "glxgears-cyg-profile";
191 String childName
= "glxgears-16073";
192 List
<String
> expected
= ImmutableList
.of("40472b", "", "", "", "");
194 SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
196 final SWTBotView viewBot1
= viewBot
;
197 SWTBotTree tree
= viewBot1
.bot().tree();
198 SWTBotTreeItem treeItem
= tree
.getTreeItem(node
);
199 assertEquals(childName
, treeItem
.getNodes().get(0));
200 List
<String
> names
= treeItem
.getNode(childName
).getNodes();
201 assertEquals(expected
, names
);
205 * Test check callstack at a time
208 public void testGoToTimeAndCheckStack() {
209 goToTime(TIMESTAMPS
[0]);
211 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
213 SWTBotUtils
.waitForJobs();
214 List
<String
> names
= getVisibleStackFrames(viewBot
);
215 assertArrayEquals(STACK_FRAMES
[0], names
.toArray());
219 * Test check callstack at a time after navigating
222 public void testGoToTimeGoBackAndForthAndCheckStack() {
223 int currentEventOffset
= 0;
224 goToTime(TIMESTAMPS
[currentEventOffset
]);
226 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
228 for (int i
= 0; i
< 10; i
++) {
229 viewBot
.toolbarPushButton(SELECT_NEXT_EVENT
).click();
230 currentEventOffset
++;
231 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, TIMESTAMPS
[currentEventOffset
]));
232 SWTBotUtils
.waitForJobs();
233 assertArrayEquals(STACK_FRAMES
[currentEventOffset
], getVisibleStackFrames(viewBot
).toArray());
237 for (int i
= 0; i
< 2; i
++) {
238 viewBot
.toolbarPushButton(SELECT_PREVIOUS_EVENT
).click();
239 currentEventOffset
--;
240 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, TIMESTAMPS
[currentEventOffset
]));
241 SWTBotUtils
.waitForJobs();
242 assertArrayEquals(STACK_FRAMES
[currentEventOffset
], getVisibleStackFrames(viewBot
).toArray());
244 // move up and down once to make sure it doesn't explode
245 viewBot
.toolbarPushButton(SELECT_PREVIOUS_ITEM
).click();
246 SWTBotUtils
.waitForJobs();
247 viewBot
.toolbarPushButton(SELECT_NEXT_ITEM
).click();
248 SWTBotUtils
.waitForJobs();
250 // Zoom in and out too
251 viewBot
.toolbarPushButton(ZOOM_IN
).click();
252 SWTBotUtils
.waitForJobs();
253 viewBot
.toolbarPushButton(ZOOM_OUT
).click();
254 SWTBotUtils
.waitForJobs();
258 * Test check callstack at a time with sorting, the trace is not sortable,
259 * this is a smoke test
262 public void testGoToTimeSortAndCheckStack() {
263 goToTime(TIMESTAMPS
[0]);
264 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
266 viewBot
.toolbarToggleButton(SORT_BY_NAME
).click();
267 viewBot
.toolbarToggleButton(SORT_BY_ID
).click();
268 viewBot
.toolbarToggleButton(SORT_BY_START
).click();
270 SWTBotUtils
.waitForJobs();
271 List
<String
> names
= getVisibleStackFrames(viewBot
);
272 assertArrayEquals(STACK_FRAMES
[0], names
.toArray());
275 private static List
<String
> getVisibleStackFrames(final SWTBotView viewBot
) {
276 SWTBotTree tree
= viewBot
.bot().tree();
277 List
<String
> names
= new ArrayList
<>();
278 for (SWTBotTreeItem swtBotTreeItem
: tree
.getAllItems()) {
279 for (SWTBotTreeItem items
: swtBotTreeItem
.getItems()) {
280 for (SWTBotTreeItem item
: items
.getItems()) {
281 names
.add(item
.cell(0));
288 private static void goToTime(long timestamp
) {
289 SWTBotTable table
= fBot
.activeEditor().bot().table();
291 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(table
.widget
, new TmfNanoTimestamp(timestamp
)));
292 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, timestamp
));
296 * Test check callstack at a time with function map
300 public void testGoToTimeAndCheckStackWithNames() {
301 goToTime(TIMESTAMPS
[0]);
302 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
304 // no way to load mappings yet! :(
305 SWTBotTree tree
= viewBot
.bot().tree();
306 SWTBotUtils
.waitForJobs();
307 List
<String
> names
= new ArrayList
<>();
308 for (SWTBotTreeItem swtBotTreeItem
: tree
.getAllItems()) {
309 for (SWTBotTreeItem items
: swtBotTreeItem
.getItems()) {
310 for (SWTBotTreeItem item
: items
.getItems()) {
311 names
.add(item
.cell(0));
318 * Test check callstack toolbar buttons
321 public void testCallstackNavigation() {
322 SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
324 List
<String
> buttons
= new ArrayList
<>();
325 for (SWTBotToolbarButton swtBotToolbarButton
: viewBot
.getToolbarButtons()) {
326 buttons
.add(swtBotToolbarButton
.getToolTipText());
328 assertEquals(TOOLBAR_BUTTONS_TOOLTIPS
, buttons
);