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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.lttng2
.kernel
.ui
.swtbot
.tests
;
15 import static org
.junit
.Assert
.assertTrue
;
17 import java
.util
.List
;
19 import org
.eclipse
.jdt
.annotation
.NonNull
;
20 import org
.eclipse
.swt
.SWT
;
21 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
22 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
23 import org
.eclipse
.swtbot
.swt
.finder
.keyboard
.Keyboard
;
24 import org
.eclipse
.swtbot
.swt
.finder
.keyboard
.KeyboardFactory
;
25 import org
.eclipse
.swtbot
.swt
.finder
.keyboard
.Keystrokes
;
26 import org
.eclipse
.swtbot
.swt
.finder
.matchers
.WidgetOfType
;
27 import org
.eclipse
.swtbot
.swt
.finder
.results
.VoidResult
;
28 import org
.eclipse
.swtbot
.swt
.finder
.waits
.DefaultCondition
;
29 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalManager
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
37 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
38 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
39 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
40 import org
.junit
.Before
;
41 import org
.junit
.Test
;
44 * SWTBot tests for Control Flow view
46 * @author Patrick Tasse
48 public class ControlFlowViewTest
extends KernelTest
{
50 private static final String FOLLOW_CPU_BACKWARD
= "Follow CPU Backward";
51 private static final String FOLLOW_CPU_FORWARD
= "Follow CPU Forward";
52 private static final String SELECT_PREVIOUS_EVENT
= "Select Previous Event";
53 private static final String SELECT_NEXT_EVENT
= "Select Next Event";
54 private static final Keyboard KEYBOARD
= KeyboardFactory
.getSWTKeyboard();
55 private static final @NonNull ITmfTimestamp START_TIME
= new TmfNanoTimestamp(1368000272650993664L);
56 private static final @NonNull ITmfTimestamp TID1_TIME1
= new TmfNanoTimestamp(1368000272651208412L);
57 private static final @NonNull ITmfTimestamp TID1_TIME2
= new TmfNanoTimestamp(1368000272656147616L);
58 private static final @NonNull ITmfTimestamp TID1_TIME3
= new TmfNanoTimestamp(1368000272656362364L);
59 private static final @NonNull ITmfTimestamp TID1_TIME4
= new TmfNanoTimestamp(1368000272663234300L);
60 private static final @NonNull ITmfTimestamp TID1_TIME5
= new TmfNanoTimestamp(1368000272663449048L);
61 private static final @NonNull ITmfTimestamp TID1_TIME6
= new TmfNanoTimestamp(1368000272665596528L);
62 private static final @NonNull ITmfTimestamp TID2_TIME1
= new TmfNanoTimestamp(1368000272651852656L);
63 private static final @NonNull ITmfTimestamp TID2_TIME2
= new TmfNanoTimestamp(1368000272652067404L);
64 private static final @NonNull ITmfTimestamp TID2_TIME3
= new TmfNanoTimestamp(1368000272652282152L);
65 private static final @NonNull ITmfTimestamp TID2_TIME4
= new TmfNanoTimestamp(1368000272652496900L);
66 private static final @NonNull ITmfTimestamp TID5_TIME1
= new TmfNanoTimestamp(1368000272652496900L);
68 private SWTBotView fViewBot
;
75 public void before() {
77 fViewBot
= fBot
.viewByTitle("Control Flow");
81 * Test keyboard navigation using ARROW_RIGHT and ARROW_LEFT
84 public void testKeyboardLeftRight() {
85 /* change window range to 10 ms */
86 TmfTimeRange range
= new TmfTimeRange(START_TIME
, START_TIME
.normalize(10000000L, ITmfTimestamp
.NANOSECOND_SCALE
));
87 TmfSignalManager
.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range
));
88 fBot
.waitUntil(ConditionHelpers
.windowRange(range
));
90 /* set selection to trace start time */
91 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME
));
92 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(START_TIME
, START_TIME
)));
94 /* select first item */
95 final SWTBotTree tree
= fViewBot
.bot().tree();
96 tree
.pressShortcut(Keystrokes
.HOME
);
98 /* set focus on time graph */
99 final TimeGraphControl timegraph
= fViewBot
.bot().widget(WidgetOfType
.widgetOfType(TimeGraphControl
.class));
100 UIThreadRunnable
.syncExec(new VoidResult() {
103 timegraph
.setFocus();
107 /* press ARROW_RIGHT 3 times */
108 KEYBOARD
.pressShortcut(Keystrokes
.RIGHT
);
109 KEYBOARD
.pressShortcut(Keystrokes
.RIGHT
);
110 KEYBOARD
.pressShortcut(Keystrokes
.RIGHT
);
111 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID1_TIME3
, TID1_TIME3
)));
112 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME3
));
114 /* press Shift-ARROW_RIGHT 3 times */
115 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.RIGHT
);
116 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.RIGHT
);
117 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.RIGHT
);
118 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID1_TIME3
, TID1_TIME6
)));
119 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME6
));
121 /* press Shift-ARROW_LEFT 4 times */
122 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.LEFT
);
123 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.LEFT
);
124 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.LEFT
);
125 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.LEFT
);
126 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID1_TIME3
, TID1_TIME2
)));
127 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME2
));
129 /* press ARROW_RIGHT 2 times */
130 KEYBOARD
.pressShortcut(Keystrokes
.RIGHT
);
131 KEYBOARD
.pressShortcut(Keystrokes
.RIGHT
);
132 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID1_TIME4
, TID1_TIME4
)));
133 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME4
));
135 /* press Shift-ARROW_LEFT 3 times */
136 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.LEFT
);
137 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.LEFT
);
138 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.LEFT
);
139 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID1_TIME4
, TID1_TIME1
)));
140 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME1
));
142 /* press Shift-ARROW_RIGHT 4 times */
143 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.RIGHT
);
144 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.RIGHT
);
145 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.RIGHT
);
146 KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, Keystrokes
.RIGHT
);
147 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID1_TIME4
, TID1_TIME5
)));
148 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME5
));
150 /* press ARROW_LEFT 5 times */
151 KEYBOARD
.pressShortcut(Keystrokes
.LEFT
);
152 KEYBOARD
.pressShortcut(Keystrokes
.LEFT
);
153 KEYBOARD
.pressShortcut(Keystrokes
.LEFT
);
154 KEYBOARD
.pressShortcut(Keystrokes
.LEFT
);
155 KEYBOARD
.pressShortcut(Keystrokes
.LEFT
);
156 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(START_TIME
, START_TIME
)));
157 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(START_TIME
));
161 * Test tool bar buttons "Select Next Event" and "Select Previous Event"
164 public void testToolBarSelectNextPreviousEvent() {
165 /* change window range to 10 ms */
166 TmfTimeRange range
= new TmfTimeRange(START_TIME
, START_TIME
.normalize(10000000L, ITmfTimestamp
.NANOSECOND_SCALE
));
167 TmfSignalManager
.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range
));
168 fBot
.waitUntil(ConditionHelpers
.windowRange(range
));
170 /* set selection to trace start time */
171 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME
));
172 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(START_TIME
, START_TIME
)));
174 /* select first item */
175 final SWTBotTree tree
= fViewBot
.bot().tree();
176 tree
.pressShortcut(Keystrokes
.HOME
);
178 /* set focus on time graph */
179 final TimeGraphControl timegraph
= fViewBot
.bot().widget(WidgetOfType
.widgetOfType(TimeGraphControl
.class));
180 UIThreadRunnable
.syncExec(new VoidResult() {
183 timegraph
.setFocus();
187 /* click "Select Next Event" 3 times */
188 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click();
189 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click();
190 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click();
191 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID1_TIME3
, TID1_TIME3
)));
192 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME3
));
194 /* shift-click "Select Next Event" 3 times */
195 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click(SWT
.SHIFT
);
196 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click(SWT
.SHIFT
);
197 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click(SWT
.SHIFT
);
198 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID1_TIME3
, TID1_TIME6
)));
199 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME6
));
201 /* shift-click "Select Previous Event" 4 times */
202 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click(SWT
.SHIFT
);
203 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click(SWT
.SHIFT
);
204 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click(SWT
.SHIFT
);
205 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click(SWT
.SHIFT
);
206 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID1_TIME3
, TID1_TIME2
)));
207 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME2
));
209 /* click "Select Next Event" 2 times */
210 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click();
211 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click();
212 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID1_TIME4
, TID1_TIME4
)));
213 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME4
));
215 /* shift-click "Select Previous Event" 3 times */
216 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click(SWT
.SHIFT
);
217 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click(SWT
.SHIFT
);
218 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click(SWT
.SHIFT
);
219 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID1_TIME4
, TID1_TIME1
)));
220 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME1
));
222 /* shift-click "Select Next Event" 4 times */
223 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click(SWT
.SHIFT
);
224 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click(SWT
.SHIFT
);
225 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click(SWT
.SHIFT
);
226 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click(SWT
.SHIFT
);
227 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID1_TIME4
, TID1_TIME5
)));
228 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME5
));
230 /* click "Select Previous Event" 5 times */
231 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click();
232 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click();
233 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click();
234 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click();
235 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click();
236 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(START_TIME
, START_TIME
)));
237 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(START_TIME
));
241 * Test tool bar buttons "Follow CPU Forward" and "Follow CPU Backward"
244 public void testToolBarFollowCPUForwardBackward() {
245 /* change window range to 10 ms */
246 TmfTimeRange range
= new TmfTimeRange(START_TIME
, START_TIME
.normalize(10000000L, ITmfTimestamp
.NANOSECOND_SCALE
));
247 TmfSignalManager
.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range
));
248 fBot
.waitUntil(ConditionHelpers
.windowRange(range
));
250 /* set selection to trace start time */
251 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME
));
252 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(START_TIME
, START_TIME
)));
254 /* select first item */
255 final SWTBotTree tree
= fViewBot
.bot().tree();
256 tree
.pressShortcut(Keystrokes
.HOME
);
258 /* set focus on time graph */
259 final TimeGraphControl timegraph
= fViewBot
.bot().widget(WidgetOfType
.widgetOfType(TimeGraphControl
.class));
260 UIThreadRunnable
.syncExec(new VoidResult() {
263 timegraph
.setFocus();
267 /* make sure arrows have been computed */
268 fBot
.waitUntil(new DefaultCondition() {
270 public boolean test() throws Exception
{
271 List
<ILinkEvent
> arrows
= timegraph
.getArrows();
272 return arrows
.size() >= 3 &&
273 arrows
.get(0).getTime() == TID1_TIME1
.getValue() &&
274 arrows
.get(1).getTime() == TID2_TIME2
.getValue() &&
275 arrows
.get(2).getTime() == TID2_TIME4
.getValue();
278 public String
getFailureMessage() {
279 return "Arrows not found";
283 /* click "Follow CPU Forward" 3 times */
284 fViewBot
.toolbarButton(FOLLOW_CPU_FORWARD
).click();
285 fViewBot
.toolbarButton(FOLLOW_CPU_FORWARD
).click();
286 fViewBot
.toolbarButton(FOLLOW_CPU_FORWARD
).click();
287 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID2_TIME2
, TID2_TIME2
)));
288 fBot
.waitUntil(ConditionHelpers
.treeSelectionContains(tree
, 1, "2"));
289 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME2
));
291 /* shift-click "Follow CPU Forward" 3 times */
292 fViewBot
.toolbarButton(FOLLOW_CPU_FORWARD
).click(SWT
.SHIFT
);
293 fViewBot
.toolbarButton(FOLLOW_CPU_FORWARD
).click(SWT
.SHIFT
);
294 fViewBot
.toolbarButton(FOLLOW_CPU_FORWARD
).click(SWT
.SHIFT
);
295 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID2_TIME2
, TID5_TIME1
)));
296 fBot
.waitUntil(ConditionHelpers
.treeSelectionContains(tree
, 1, "5"));
297 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID5_TIME1
));
299 /* shift-click "Follow CPU Backward" 4 times */
300 fViewBot
.toolbarButton(FOLLOW_CPU_BACKWARD
).click(SWT
.SHIFT
);
301 fViewBot
.toolbarButton(FOLLOW_CPU_BACKWARD
).click(SWT
.SHIFT
);
302 fViewBot
.toolbarButton(FOLLOW_CPU_BACKWARD
).click(SWT
.SHIFT
);
303 fViewBot
.toolbarButton(FOLLOW_CPU_BACKWARD
).click(SWT
.SHIFT
);
304 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID2_TIME2
, TID2_TIME1
)));
305 fBot
.waitUntil(ConditionHelpers
.treeSelectionContains(tree
, 1, "2"));
306 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME1
));
308 /* click "Follow CPU Forward" 2 times */
309 fViewBot
.toolbarButton(FOLLOW_CPU_FORWARD
).click();
310 fViewBot
.toolbarButton(FOLLOW_CPU_FORWARD
).click();
311 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID2_TIME3
, TID2_TIME3
)));
312 fBot
.waitUntil(ConditionHelpers
.treeSelectionContains(tree
, 1, "2"));
313 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME3
));
315 /* shift-click "Follow CPU Backward" 3 times */
316 fViewBot
.toolbarButton(FOLLOW_CPU_BACKWARD
).click(SWT
.SHIFT
);
317 fViewBot
.toolbarButton(FOLLOW_CPU_BACKWARD
).click(SWT
.SHIFT
);
318 fViewBot
.toolbarButton(FOLLOW_CPU_BACKWARD
).click(SWT
.SHIFT
);
319 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID2_TIME3
, TID1_TIME1
)));
320 fBot
.waitUntil(ConditionHelpers
.treeSelectionContains(tree
, 1, "1"));
321 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME1
));
323 /* shift-click "Follow CPU Forward" 4 times */
324 fViewBot
.toolbarButton(FOLLOW_CPU_FORWARD
).click(SWT
.SHIFT
);
325 fViewBot
.toolbarButton(FOLLOW_CPU_FORWARD
).click(SWT
.SHIFT
);
326 fViewBot
.toolbarButton(FOLLOW_CPU_FORWARD
).click(SWT
.SHIFT
);
327 fViewBot
.toolbarButton(FOLLOW_CPU_FORWARD
).click(SWT
.SHIFT
);
328 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(TID2_TIME3
, TID2_TIME4
)));
329 fBot
.waitUntil(ConditionHelpers
.treeSelectionContains(tree
, 1, "2"));
330 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME4
));
332 /* click "Follow CPU Backward" 5 times */
333 fViewBot
.toolbarButton(FOLLOW_CPU_BACKWARD
).click();
334 fViewBot
.toolbarButton(FOLLOW_CPU_BACKWARD
).click();
335 fViewBot
.toolbarButton(FOLLOW_CPU_BACKWARD
).click();
336 fViewBot
.toolbarButton(FOLLOW_CPU_BACKWARD
).click();
337 fViewBot
.toolbarButton(FOLLOW_CPU_BACKWARD
).click();
338 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(START_TIME
, START_TIME
)));
339 assertTrue(TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange().contains(START_TIME
));