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 RESET_TIME_SCALE
= "Reset the Time Scale to Default";
111 private static final @NonNull String SELECT_PREVIOUS_EVENT
= "Select Previous Event";
112 private static final @NonNull String SELECT_NEXT_EVENT
= "Select Next Event";
113 private static final @NonNull String SELECT_PREVIOUS_ITEM
= "Select Previous Item";
114 private static final @NonNull String SELECT_NEXT_ITEM
= "Select Next Item";
115 private static final @NonNull String ZOOM_IN
= "Zoom In";
116 private static final @NonNull String ZOOM_OUT
= "Zoom Out";
118 private static final String PIN_VIEW
= "Pin View";
119 private static final List
<String
> TOOLBAR_BUTTONS_TOOLTIPS
= ImmutableList
.of(
120 ALIGN_VIEWS
, IMPORT_BINARY
, IMPORT_TEXT
,
122 SORT_BY_NAME
, SORT_BY_ID
, SORT_BY_START
,
124 RESET_TIME_SCALE
, SELECT_PREVIOUS_EVENT
, SELECT_NEXT_EVENT
,
125 SELECT_PREVIOUS_ITEM
, SELECT_NEXT_ITEM
, ZOOM_IN
, ZOOM_OUT
,
133 public static void init() {
134 SWTBotUtils
.failIfUIThread();
136 Thread
.currentThread().setName("SWTBot Thread"); // for the debugger
137 /* set up for swtbot */
138 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
139 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout()));
140 fBot
= new SWTWorkbenchBot();
142 SWTBotUtils
.closeView("welcome", fBot
);
144 SWTBotUtils
.switchToTracingPerspective();
145 /* finish waiting for eclipse to load */
146 SWTBotUtils
.waitForJobs();
150 * Open a trace in an editor
153 public void beforeTest() {
154 SWTBotUtils
.createProject(PROJECT_NAME
);
155 SWTBotTreeItem treeItem
= SWTBotUtils
.selectTracesFolder(fBot
, PROJECT_NAME
);
156 assertNotNull(treeItem
);
157 final CtfTestTrace cygProfile
= CtfTestTrace
.CYG_PROFILE
;
158 final File file
= new File(CtfTmfTestTraceUtils
.getTrace(cygProfile
).getPath());
159 SWTBotUtils
.openTrace(PROJECT_NAME
, file
.getAbsolutePath(), UST_ID
);
160 SWTBotUtils
.openView(CallStackView
.ID
);
161 SWTBotUtils
.waitForJobs();
168 public void tearDown() {
169 fBot
.closeAllEditors();
170 SWTBotUtils
.deleteProject(PROJECT_NAME
, fBot
);
174 * Test if callstack is populated
177 public void testOpenCallstack() {
178 String node
= "glxgears-cyg-profile";
179 String childName
= "glxgears-16073";
180 List
<String
> expected
= ImmutableList
.of("40472b", "", "", "", "");
182 SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
184 final SWTBotView viewBot1
= viewBot
;
185 SWTBotTree tree
= viewBot1
.bot().tree();
186 SWTBotTreeItem treeItem
= tree
.getTreeItem(node
);
187 assertEquals(childName
, treeItem
.getNodes().get(0));
188 List
<String
> names
= treeItem
.getNode(childName
).getNodes();
189 assertEquals(expected
, names
);
193 * Test check callstack at a time
196 public void testGoToTimeAndCheckStack() {
197 goToTime(TIMESTAMPS
[0]);
199 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
201 SWTBotUtils
.waitForJobs();
202 List
<String
> names
= getVisibleStackFrames(viewBot
);
203 assertArrayEquals(STACK_FRAMES
[0], names
.toArray());
207 * Test check callstack at a time after navigating
210 public void testGoToTimeGoBackAndForthAndCheckStack() {
211 int currentEventOffset
= 0;
212 goToTime(TIMESTAMPS
[currentEventOffset
]);
214 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
216 for (int i
= 0; i
< 10; i
++) {
217 viewBot
.toolbarPushButton(SELECT_NEXT_EVENT
).click();
218 currentEventOffset
++;
219 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, TIMESTAMPS
[currentEventOffset
]));
220 SWTBotUtils
.waitForJobs();
221 assertArrayEquals(STACK_FRAMES
[currentEventOffset
], getVisibleStackFrames(viewBot
).toArray());
225 for (int i
= 0; i
< 2; i
++) {
226 viewBot
.toolbarPushButton(SELECT_PREVIOUS_EVENT
).click();
227 currentEventOffset
--;
228 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, TIMESTAMPS
[currentEventOffset
]));
229 SWTBotUtils
.waitForJobs();
230 assertArrayEquals(STACK_FRAMES
[currentEventOffset
], getVisibleStackFrames(viewBot
).toArray());
232 // move up and down once to make sure it doesn't explode
233 viewBot
.toolbarPushButton(SELECT_PREVIOUS_ITEM
).click();
234 SWTBotUtils
.waitForJobs();
235 viewBot
.toolbarPushButton(SELECT_NEXT_ITEM
).click();
236 SWTBotUtils
.waitForJobs();
238 // Zoom in and out too
239 viewBot
.toolbarPushButton(ZOOM_IN
).click();
240 SWTBotUtils
.waitForJobs();
241 viewBot
.toolbarPushButton(ZOOM_OUT
).click();
242 SWTBotUtils
.waitForJobs();
246 * Test check callstack at a time with sorting, the trace is not sortable,
247 * this is a smoke test
250 public void testGoToTimeSortAndCheckStack() {
251 goToTime(TIMESTAMPS
[0]);
252 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
254 viewBot
.toolbarToggleButton(SORT_BY_NAME
).click();
255 viewBot
.toolbarToggleButton(SORT_BY_ID
).click();
256 viewBot
.toolbarToggleButton(SORT_BY_START
).click();
258 SWTBotUtils
.waitForJobs();
259 List
<String
> names
= getVisibleStackFrames(viewBot
);
260 assertArrayEquals(STACK_FRAMES
[0], names
.toArray());
263 private static List
<String
> getVisibleStackFrames(final SWTBotView viewBot
) {
264 SWTBotTree tree
= viewBot
.bot().tree();
265 List
<String
> names
= new ArrayList
<>();
266 for (SWTBotTreeItem swtBotTreeItem
: tree
.getAllItems()) {
267 for (SWTBotTreeItem items
: swtBotTreeItem
.getItems()) {
268 for (SWTBotTreeItem item
: items
.getItems()) {
269 names
.add(item
.cell(0));
276 private static void goToTime(long timestamp
) {
277 SWTBotTable table
= fBot
.activeEditor().bot().table();
279 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(table
.widget
, new TmfNanoTimestamp(timestamp
)));
280 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, timestamp
));
284 * Test check callstack at a time with function map
288 public void testGoToTimeAndCheckStackWithNames() {
289 goToTime(TIMESTAMPS
[0]);
290 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
292 // no way to load mappings yet! :(
293 SWTBotTree tree
= viewBot
.bot().tree();
294 SWTBotUtils
.waitForJobs();
295 List
<String
> names
= new ArrayList
<>();
296 for (SWTBotTreeItem swtBotTreeItem
: tree
.getAllItems()) {
297 for (SWTBotTreeItem items
: swtBotTreeItem
.getItems()) {
298 for (SWTBotTreeItem item
: items
.getItems()) {
299 names
.add(item
.cell(0));
306 * Test check callstack toolbar buttons
309 public void testCallstackNavigation() {
310 SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
312 List
<String
> buttons
= new ArrayList
<>();
313 for (SWTBotToolbarButton swtBotToolbarButton
: viewBot
.getToolbarButtons()) {
314 buttons
.add(swtBotToolbarButton
.getToolTipText());
316 assertEquals(TOOLBAR_BUTTONS_TOOLTIPS
, buttons
);