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 CONFIGURE_SYMBOL_PROVIDERS
= "Configure how the addresses are mapped to function names";
105 private static final @NonNull String SORT_BY_NAME
= "Sort threads by thread name";
106 private static final @NonNull String SORT_BY_ID
= "Sort threads by thread id";
107 private static final @NonNull String SORT_BY_START
= "Sort threads by start time";
109 private static final @NonNull String SHOW_VIEW_FILTERS
= "Show View Filters";
111 private static final @NonNull String RESET_TIME_SCALE
= "Reset the Time Scale to Default";
112 private static final @NonNull String SELECT_PREVIOUS_EVENT
= "Select Previous Event";
113 private static final @NonNull String SELECT_NEXT_EVENT
= "Select Next Event";
115 private static final @NonNull String ADD_BOOKMARK
= "Add Bookmark...";
116 private static final @NonNull String PREVIOUS_MARKER
= "Previous Marker";
117 private static final @NonNull String NEXT_MARKER
= "Next Marker";
119 private static final @NonNull String SELECT_PREVIOUS_ITEM
= "Select Previous Item";
120 private static final @NonNull String SELECT_NEXT_ITEM
= "Select Next Item";
121 private static final @NonNull String ZOOM_IN
= "Zoom In";
122 private static final @NonNull String ZOOM_OUT
= "Zoom Out";
124 private static final String PIN_VIEW
= "Pin View";
125 private static final List
<String
> TOOLBAR_BUTTONS_TOOLTIPS
= ImmutableList
.of(
126 ALIGN_VIEWS
, CONFIGURE_SYMBOL_PROVIDERS
,
128 SORT_BY_NAME
, SORT_BY_ID
, SORT_BY_START
,
132 RESET_TIME_SCALE
, SELECT_PREVIOUS_EVENT
, SELECT_NEXT_EVENT
,
134 ADD_BOOKMARK
, PREVIOUS_MARKER
, NEXT_MARKER
,
136 SELECT_PREVIOUS_ITEM
, SELECT_NEXT_ITEM
, ZOOM_IN
, ZOOM_OUT
,
144 public static void init() {
145 SWTBotUtils
.initialize();
147 Thread
.currentThread().setName("SWTBot Thread"); // for the debugger
148 /* set up for swtbot */
149 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
150 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout()));
151 fBot
= new SWTWorkbenchBot();
153 SWTBotUtils
.closeView("welcome", fBot
);
155 SWTBotUtils
.switchToTracingPerspective();
156 /* finish waiting for eclipse to load */
157 SWTBotUtils
.waitForJobs();
161 * Open a trace in an editor
164 public void beforeTest() {
165 SWTBotUtils
.createProject(PROJECT_NAME
);
166 SWTBotTreeItem treeItem
= SWTBotUtils
.selectTracesFolder(fBot
, PROJECT_NAME
);
167 assertNotNull(treeItem
);
168 final CtfTestTrace cygProfile
= CtfTestTrace
.CYG_PROFILE
;
169 final File file
= new File(CtfTmfTestTraceUtils
.getTrace(cygProfile
).getPath());
170 SWTBotUtils
.openTrace(PROJECT_NAME
, file
.getAbsolutePath(), UST_ID
);
171 SWTBotUtils
.openView(CallStackView
.ID
);
172 SWTBotUtils
.waitForJobs();
179 public void tearDown() {
180 fBot
.closeAllEditors();
181 SWTBotUtils
.deleteProject(PROJECT_NAME
, fBot
);
185 * Test if callstack is populated
188 public void testOpenCallstack() {
189 String node
= "glxgears-cyg-profile";
190 String childName
= "glxgears-16073";
191 List
<String
> expected
= ImmutableList
.of("40472b", "", "", "", "");
193 SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
195 final SWTBotView viewBot1
= viewBot
;
196 SWTBotTree tree
= viewBot1
.bot().tree();
197 SWTBotTreeItem treeItem
= tree
.getTreeItem(node
);
198 assertEquals(childName
, treeItem
.getNodes().get(0));
199 List
<String
> names
= treeItem
.getNode(childName
).getNodes();
200 assertEquals(expected
, names
);
204 * Test check callstack at a time
207 public void testGoToTimeAndCheckStack() {
208 goToTime(TIMESTAMPS
[0]);
210 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
212 SWTBotUtils
.waitForJobs();
213 List
<String
> names
= getVisibleStackFrames(viewBot
);
214 assertArrayEquals(STACK_FRAMES
[0], names
.toArray());
218 * Test check callstack at a time after navigating
221 public void testGoToTimeGoBackAndForthAndCheckStack() {
222 int currentEventOffset
= 0;
223 goToTime(TIMESTAMPS
[currentEventOffset
]);
225 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
227 for (int i
= 0; i
< 10; i
++) {
228 viewBot
.toolbarPushButton(SELECT_NEXT_EVENT
).click();
229 currentEventOffset
++;
230 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, TIMESTAMPS
[currentEventOffset
]));
231 SWTBotUtils
.waitForJobs();
232 assertArrayEquals(STACK_FRAMES
[currentEventOffset
], getVisibleStackFrames(viewBot
).toArray());
236 for (int i
= 0; i
< 2; i
++) {
237 viewBot
.toolbarPushButton(SELECT_PREVIOUS_EVENT
).click();
238 currentEventOffset
--;
239 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, TIMESTAMPS
[currentEventOffset
]));
240 SWTBotUtils
.waitForJobs();
241 assertArrayEquals(STACK_FRAMES
[currentEventOffset
], getVisibleStackFrames(viewBot
).toArray());
243 // move up and down once to make sure it doesn't explode
244 viewBot
.toolbarPushButton(SELECT_PREVIOUS_ITEM
).click();
245 SWTBotUtils
.waitForJobs();
246 viewBot
.toolbarPushButton(SELECT_NEXT_ITEM
).click();
247 SWTBotUtils
.waitForJobs();
249 // Zoom in and out too
250 viewBot
.toolbarPushButton(ZOOM_IN
).click();
251 SWTBotUtils
.waitForJobs();
252 viewBot
.toolbarPushButton(ZOOM_OUT
).click();
253 SWTBotUtils
.waitForJobs();
257 * Test check callstack at a time with sorting, the trace is not sortable,
258 * this is a smoke test
261 public void testGoToTimeSortAndCheckStack() {
262 goToTime(TIMESTAMPS
[0]);
263 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
265 viewBot
.toolbarToggleButton(SORT_BY_NAME
).click();
266 viewBot
.toolbarToggleButton(SORT_BY_ID
).click();
267 viewBot
.toolbarToggleButton(SORT_BY_START
).click();
269 SWTBotUtils
.waitForJobs();
270 List
<String
> names
= getVisibleStackFrames(viewBot
);
271 assertArrayEquals(STACK_FRAMES
[0], names
.toArray());
274 private static List
<String
> getVisibleStackFrames(final SWTBotView viewBot
) {
275 SWTBotTree tree
= viewBot
.bot().tree();
276 List
<String
> names
= new ArrayList
<>();
277 for (SWTBotTreeItem swtBotTreeItem
: tree
.getAllItems()) {
278 for (SWTBotTreeItem items
: swtBotTreeItem
.getItems()) {
279 for (SWTBotTreeItem item
: items
.getItems()) {
280 names
.add(item
.cell(0));
287 private static void goToTime(long timestamp
) {
288 SWTBotTable table
= fBot
.activeEditor().bot().table();
290 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(table
.widget
, new TmfNanoTimestamp(timestamp
)));
291 fBot
.waitUntil(ConditionHelpers
.selectionInEventsTable(fBot
, timestamp
));
295 * Test check callstack at a time with function map
299 public void testGoToTimeAndCheckStackWithNames() {
300 goToTime(TIMESTAMPS
[0]);
301 final SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
303 // no way to load mappings yet! :(
304 SWTBotTree tree
= viewBot
.bot().tree();
305 SWTBotUtils
.waitForJobs();
306 List
<String
> names
= new ArrayList
<>();
307 for (SWTBotTreeItem swtBotTreeItem
: tree
.getAllItems()) {
308 for (SWTBotTreeItem items
: swtBotTreeItem
.getItems()) {
309 for (SWTBotTreeItem item
: items
.getItems()) {
310 names
.add(item
.cell(0));
317 * Test check callstack toolbar buttons
320 public void testCallstackNavigation() {
321 SWTBotView viewBot
= fBot
.viewById(CallStackView
.ID
);
323 List
<String
> buttons
= new ArrayList
<>();
324 for (SWTBotToolbarButton swtBotToolbarButton
: viewBot
.getToolbarButtons()) {
325 buttons
.add(swtBotToolbarButton
.getToolTipText());
327 assertEquals(TOOLBAR_BUTTONS_TOOLTIPS
, buttons
);