lttng: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / kernel / ui / swtbot / tests / ControlFlowViewTest.java
1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
14
15 import static org.junit.Assert.assertTrue;
16
17 import java.util.List;
18
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;
42
43 /**
44 * SWTBot tests for Control Flow view
45 *
46 * @author Patrick Tasse
47 */
48 public class ControlFlowViewTest extends KernelTest {
49
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);
67
68 private SWTBotView fViewBot;
69
70 /**
71 * Before Test
72 */
73 @Override
74 @Before
75 public void before() {
76 super.before();
77 fViewBot = fBot.viewByTitle("Control Flow");
78 }
79
80 /**
81 * Test keyboard navigation using ARROW_RIGHT and ARROW_LEFT
82 */
83 @Test
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));
89
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)));
93
94 /* select first item */
95 final SWTBotTree tree = fViewBot.bot().tree();
96 tree.pressShortcut(Keystrokes.HOME);
97
98 /* set focus on time graph */
99 final TimeGraphControl timegraph = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
100 UIThreadRunnable.syncExec(new VoidResult() {
101 @Override
102 public void run() {
103 timegraph.setFocus();
104 }
105 });
106
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));
113
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));
120
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));
128
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));
134
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));
141
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));
149
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));
158 }
159
160 /**
161 * Test tool bar buttons "Select Next Event" and "Select Previous Event"
162 */
163 @Test
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));
169
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)));
173
174 /* select first item */
175 final SWTBotTree tree = fViewBot.bot().tree();
176 tree.pressShortcut(Keystrokes.HOME);
177
178 /* set focus on time graph */
179 final TimeGraphControl timegraph = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
180 UIThreadRunnable.syncExec(new VoidResult() {
181 @Override
182 public void run() {
183 timegraph.setFocus();
184 }
185 });
186
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));
193
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));
200
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));
208
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));
214
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));
221
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));
229
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));
238 }
239
240 /**
241 * Test tool bar buttons "Follow CPU Forward" and "Follow CPU Backward"
242 */
243 @Test
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));
249
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)));
253
254 /* select first item */
255 final SWTBotTree tree = fViewBot.bot().tree();
256 tree.pressShortcut(Keystrokes.HOME);
257
258 /* set focus on time graph */
259 final TimeGraphControl timegraph = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
260 UIThreadRunnable.syncExec(new VoidResult() {
261 @Override
262 public void run() {
263 timegraph.setFocus();
264 }
265 });
266
267 /* make sure arrows have been computed */
268 fBot.waitUntil(new DefaultCondition() {
269 @Override
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();
276 }
277 @Override
278 public String getFailureMessage() {
279 return "Arrows not found";
280 }
281 });
282
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));
290
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));
298
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));
307
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));
314
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));
322
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));
331
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));
340 }
341 }
This page took 0.047565 seconds and 6 git commands to generate.