lttng.swtbot: Add resources view swtbot tests
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / kernel / ui / swtbot / tests / ResourcesViewTest.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.assertEquals;
16 import static org.junit.Assert.assertFalse;
17 import static org.junit.Assert.assertTrue;
18
19 import java.util.Arrays;
20 import java.util.List;
21
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.eclipse.jface.bindings.keys.KeyStroke;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.graphics.Point;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
28 import org.eclipse.swtbot.swt.finder.SWTBot;
29 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
30 import org.eclipse.swtbot.swt.finder.keyboard.Keyboard;
31 import org.eclipse.swtbot.swt.finder.keyboard.KeyboardFactory;
32 import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
33 import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
34 import org.eclipse.swtbot.swt.finder.results.Result;
35 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCanvas;
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.signal.TmfWindowRangeUpdatedSignal;
39 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
40 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
41 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
42 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
43 import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
44 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
45 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphMarkerAxis;
46 import org.eclipse.ui.IWorkbenchPart;
47 import org.junit.Before;
48 import org.junit.Ignore;
49 import org.junit.Test;
50
51 /**
52 * SWTBot tests for Resources view
53 *
54 * @author Patrick Tasse
55 */
56 public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
57
58 private static final String NEXT_MARKER = "Next Marker";
59 private static final String PREVIOUS_MARKER = "Previous Marker";
60 private static final String SELECT_NEXT_STATE_CHANGE = "Select Next State Change";
61 private static final String SELECT_PREVIOUS_STATE_CHANGE = "Select Previous State Change";
62 private static final String ADD_BOOKMARK = "Add Bookmark...";
63 private static final String REMOVE_BOOKMARK = "Remove Bookmark";
64 private static final String ADD_BOOKMARK_DIALOG = "Add Bookmark";
65 private static final String LOST_EVENTS = "Lost Events";
66 private static final String OK = "OK";
67 private static final Keyboard KEYBOARD = KeyboardFactory.getSWTKeyboard();
68 private static final @NonNull ITmfTimestamp START_TIME = TmfTimestamp.fromNanos(1368000272650993664L);
69 private static final @NonNull ITmfTimestamp LOST_EVENT_TIME1 = TmfTimestamp.fromNanos(1368000272681793477L);
70 private static final @NonNull ITmfTimestamp LOST_EVENT_END1 = TmfTimestamp.fromNanos(1368000272681793477L + 7425331L);
71 private static final @NonNull ITmfTimestamp LOST_EVENT_TIME2 = TmfTimestamp.fromNanos(1368000272820875850L);
72 private static final @NonNull ITmfTimestamp LOST_EVENT_END2 = TmfTimestamp.fromNanos(1368000272820875850L + 6640670L);
73 private static final @NonNull ITmfTimestamp LOST_EVENT_TIME3 = TmfTimestamp.fromNanos(1368000272882715015L);
74 private static final @NonNull ITmfTimestamp LOST_EVENT_END3 = TmfTimestamp.fromNanos(1368000272882715015L + 11373385L);
75 private static final @NonNull ITmfTimestamp CPU0_TIME1 = TmfTimestamp.fromNanos(1368000272651208412L);
76 private static final @NonNull ITmfTimestamp CPU0_TIME2 = TmfTimestamp.fromNanos(1368000272651852656L);
77 private static final @NonNull ITmfTimestamp CPU0_TIME3 = TmfTimestamp.fromNanos(1368000272652067404L);
78 private static final @NonNull ITmfTimestamp CPU0_TIME4 = TmfTimestamp.fromNanos(1368000272652282152L);
79 private static final @NonNull ITmfTimestamp CPU0_TIME5 = TmfTimestamp.fromNanos(1368000272653141144L);
80 private static final int TOP_MARGIN = 1;
81 private static final Point TOGGLE_SIZE = new Point(7, 8);
82 private static final Point HIDE_SIZE = new Point(16, 16);
83
84 private SWTBotView fViewBot;
85
86 @Override
87 protected SWTBotView getViewBot() {
88 return fViewBot;
89 }
90
91 @Override
92 protected List<String> getLegendValues() {
93 return Arrays.asList("IDLE", "USERMODE", "SYSCALL", "IRQ", "SOFT_IRQ", "IRQ_ACTIVE", "SOFT_IRQ_RAISED", "SOFT_IRQ_ACTIVE");
94 }
95
96 @Override
97 protected List<String> getToolbarTooltips() {
98 return Arrays.asList("Align Views", "Show View Filters", "Show Legend", SEPARATOR,
99 "Reset the Time Scale to Default", "Select Previous State Change", "Select Next State Change", SEPARATOR,
100 "Add Bookmark...", "Previous Marker", "Next Marker", SEPARATOR,
101 "Select Previous Resource", "Select Next Resource", "Zoom In", "Zoom Out" );
102 }
103
104 /**
105 * Before Test
106 */
107 @Override
108 @Before
109 public void before() {
110 fViewBot = fBot.viewByTitle("Resources");
111 fViewBot.show();
112 super.before();
113 fViewBot.setFocus();
114 }
115
116 /**
117 * Test keyboard marker navigation using '.' and ','
118 */
119 @Test
120 public void testKeyboardSelectNextPreviousMarker() {
121 testNextPreviousMarker(
122 () -> KEYBOARD.pressShortcut(KeyStroke.getInstance('.')),
123 () -> KEYBOARD.pressShortcut(Keystrokes.SHIFT, KeyStroke.getInstance('.')),
124 () -> KEYBOARD.pressShortcut(KeyStroke.getInstance(',')),
125 () -> KEYBOARD.pressShortcut(Keystrokes.SHIFT, KeyStroke.getInstance(',')));
126 }
127
128 /**
129 * Test tool bar buttons "Next Marker" and "Previous Marker"
130 */
131 @Test
132 public void testToolBarSelectNextPreviousMarker() {
133 testNextPreviousMarker(
134 () -> fViewBot.toolbarButton(NEXT_MARKER).click(),
135 () -> fViewBot.toolbarButton(NEXT_MARKER).click(SWT.SHIFT),
136 () -> fViewBot.toolbarButton(PREVIOUS_MARKER).click(),
137 () -> fViewBot.toolbarButton(PREVIOUS_MARKER).click(SWT.SHIFT));
138 }
139
140 private void testNextPreviousMarker(Runnable nextMarker, Runnable shiftNextMarker, Runnable previousMarker, Runnable shiftPreviousMarker) {
141 /* set selection to trace start time */
142 TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
143 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME), START_TIME);
144
145 /* select first item */
146 KEYBOARD.pressShortcut(Keystrokes.HOME);
147
148 /* click "Next Marker" 3 times */
149 nextMarker.run();
150 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1, LOST_EVENT_END1), LOST_EVENT_TIME1);
151 nextMarker.run();
152 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME2, LOST_EVENT_END2), LOST_EVENT_TIME2);
153 nextMarker.run();
154 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_END3), LOST_EVENT_TIME3);
155
156 /* shift-click "Previous Marker" 3 times */
157 shiftPreviousMarker.run();
158 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_TIME3), LOST_EVENT_TIME3);
159 shiftPreviousMarker.run();
160 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_TIME2), LOST_EVENT_TIME2);
161 shiftPreviousMarker.run();
162 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_TIME1), LOST_EVENT_TIME1);
163
164 /* shift-click "Next Marker" 3 times */
165 shiftNextMarker.run();
166 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_END1), LOST_EVENT_END1);
167 shiftNextMarker.run();
168 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_END2), LOST_EVENT_END2);
169 shiftNextMarker.run();
170 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_END3), LOST_EVENT_END3);
171
172 /* click "Previous Marker" 3 times */
173 previousMarker.run();
174 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME2, LOST_EVENT_END2), LOST_EVENT_TIME2);
175 previousMarker.run();
176 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1, LOST_EVENT_END1), LOST_EVENT_TIME1);
177 previousMarker.run();
178 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1, LOST_EVENT_END1), LOST_EVENT_TIME1);
179 }
180
181 /**
182 * Test "Show Markers" view menu
183 */
184 @Test
185 public void testShowMarkers() {
186 /* set selection to trace start time */
187 TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
188 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME), START_TIME);
189
190 /* select first item */
191 KEYBOARD.pressShortcut(Keystrokes.HOME);
192
193 /* check that "Next Marker" and "Previous Marker" are enabled */
194 assertTrue(fViewBot.toolbarButton(NEXT_MARKER).isEnabled());
195 assertTrue(fViewBot.toolbarButton(PREVIOUS_MARKER).isEnabled());
196
197 /* disable Lost Events markers */
198 fViewBot.viewMenu(LOST_EVENTS).click();
199
200 /* check that "Next Marker" and "Previous Marker" are disabled */
201 assertFalse(fViewBot.toolbarButton(NEXT_MARKER).isEnabled());
202 assertFalse(fViewBot.toolbarButton(PREVIOUS_MARKER).isEnabled());
203
204 /* enable Lost Events markers */
205 fViewBot.viewMenu(LOST_EVENTS).click();
206
207 /* check that "Next Marker" and "Previous Marker" are enabled */
208 assertTrue(fViewBot.toolbarButton(NEXT_MARKER).isEnabled());
209 assertTrue(fViewBot.toolbarButton(PREVIOUS_MARKER).isEnabled());
210 }
211
212 /**
213 * Test "Next Event" tool bar button sub-menu
214 */
215 /* SWTBot doesn't support clicking the same tool bar sub-menu twice */
216 @Ignore
217 @Test
218 public void testMarkerNavigationSubMenu() {
219 /* set selection to trace start time */
220 TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
221 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME), START_TIME);
222
223 /* select first item */
224 KEYBOARD.pressShortcut(Keystrokes.HOME);
225
226 /* disable Lost Events navigation */
227 fViewBot.toolbarDropDownButton(NEXT_MARKER).menuItem(LOST_EVENTS).click();
228
229 /* click "Next Marker" */
230 fViewBot.toolbarButton(NEXT_MARKER).click();
231 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME), START_TIME);
232
233 /* enable Lost Events navigation */
234 fViewBot.toolbarDropDownButton(NEXT_MARKER).menuItem(LOST_EVENTS).click();
235
236 /* click "Next Marker" */
237 fViewBot.toolbarButton(NEXT_MARKER).click();
238 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1, LOST_EVENT_END1), LOST_EVENT_TIME1);
239 }
240
241 /**
242 * Test tool bar button "Add Bookmark..." and "Remove Bookmark"
243 */
244 @Test
245 public void testAddRemoveBookmark() {
246 /* change window range to 10 ms */
247 TmfTimeRange range = new TmfTimeRange(START_TIME, START_TIME.normalize(10000000L, ITmfTimestamp.NANOSECOND_SCALE));
248 TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range));
249 fBot.waitUntil(ConditionHelpers.windowRange(range));
250
251 /* set selection to trace start time */
252 TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
253 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME), START_TIME);
254
255 /* select first CPU resource */
256 KEYBOARD.pressShortcut(Keystrokes.HOME);
257 KEYBOARD.pressShortcut(Keystrokes.DOWN);
258
259 /* click "Select Next State Change" 2 times */
260 fViewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click();
261 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME1, CPU0_TIME1), CPU0_TIME1);
262 fViewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click();
263 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME2, CPU0_TIME2), CPU0_TIME2);
264
265 /* click "Add Bookmark..." and fill Add Bookmark dialog */
266 fViewBot.toolbarButton(ADD_BOOKMARK).click();
267 SWTBot dialogBot = fBot.shell(ADD_BOOKMARK_DIALOG).bot();
268 dialogBot.text().setText("B1");
269 dialogBot.button(OK).click();
270
271 /*
272 * click "Select Next State Change" 2 times and shift-click "Select Next
273 * State Change
274 */
275 fViewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click();
276 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME3, CPU0_TIME3), CPU0_TIME3);
277 fViewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click();
278 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME4), CPU0_TIME4);
279 fViewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click(SWT.SHIFT);
280 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME5), CPU0_TIME5);
281
282 /* click "Add Bookmark..." and fill Add Bookmark dialog */
283 fViewBot.toolbarButton(ADD_BOOKMARK).click();
284 dialogBot = fBot.shell(ADD_BOOKMARK_DIALOG).bot();
285 dialogBot.text().setText("B2");
286 dialogBot.button(OK).click();
287
288 /* click "Previous Marker" */
289 fViewBot.toolbarButton(PREVIOUS_MARKER).click();
290 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME2, CPU0_TIME2), CPU0_TIME2);
291
292 /* click "Remove Bookmark" */
293 fViewBot.toolbarButton(REMOVE_BOOKMARK).click();
294
295 /* click "Next Marker" */
296 fViewBot.toolbarButton(NEXT_MARKER).click();
297 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME5), CPU0_TIME5);
298
299 /* click "Remove Bookmark" */
300 fViewBot.toolbarButton(REMOVE_BOOKMARK).click();
301
302 /* click "Previous Marker" */
303 fViewBot.toolbarButton(PREVIOUS_MARKER).click();
304 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME5), CPU0_TIME5);
305
306 /* click "Select Previous State Change" */
307 fViewBot.toolbarButton(SELECT_PREVIOUS_STATE_CHANGE).click();
308 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME4), CPU0_TIME4);
309 }
310
311 /**
312 * Test the marker axis
313 */
314 @Test
315 public void testMarkerAxis() {
316 /* center window range of first lost event range */
317 ITmfTimestamp startTime = LOST_EVENT_TIME1.normalize(-10000000L, ITmfTimestamp.NANOSECOND_SCALE);
318 ITmfTimestamp endTime = LOST_EVENT_END1.normalize(10000000L, ITmfTimestamp.NANOSECOND_SCALE);
319 TmfTimeRange range = new TmfTimeRange(startTime, endTime);
320 TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range));
321 fBot.waitUntil(ConditionHelpers.windowRange(range));
322
323 /* set selection to window start time */
324 TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, startTime));
325 timeGraphIsReadyCondition(new TmfTimeRange(startTime, startTime), startTime);
326
327 /* get marker axis size with one category */
328 final TimeGraphMarkerAxis markerAxis = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphMarkerAxis.class));
329 final Point size1 = getSize(markerAxis);
330
331 /* add bookmark at window start time */
332 fViewBot.toolbarButton(ADD_BOOKMARK).click();
333 SWTBot dialogBot = fBot.shell(ADD_BOOKMARK_DIALOG).bot();
334 dialogBot.text().setText("B");
335 dialogBot.button(OK).click();
336
337 /* get marker axis size with two categories */
338 final Point size2 = getSize(markerAxis);
339 final int rowHeight = size2.y - size1.y;
340
341 /*
342 * get the state area bounds, since we don't know the name space width
343 */
344 final TimeGraphControl timeGraph = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
345 int x0 = getXForTime(timeGraph, startTime.toNanos());
346 int x1 = getXForTime(timeGraph, endTime.toNanos());
347
348 /*
349 * click at the center of the marker axis width and first row height, it
350 * should be within the lost event range
351 */
352 final SWTBotCanvas markerAxisCanvas = new SWTBotCanvas(markerAxis);
353 markerAxisCanvas.click((x0 + x1) / 2, TOP_MARGIN + rowHeight / 2);
354 fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(LOST_EVENT_TIME1, LOST_EVENT_END1)));
355
356 /*
357 * click near the left of the marker axis width and center of second row
358 * height, it should be on the bookmark label
359 */
360 markerAxisCanvas.click(x0 + 2, TOP_MARGIN + rowHeight + rowHeight / 2);
361 fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(startTime, startTime)));
362
363 /* click "Remove Bookmark" */
364 fViewBot.toolbarButton(REMOVE_BOOKMARK).click();
365 assertEquals(size1, getSize(markerAxis));
366
367 /* click the 'expanded' icon to collapse */
368 markerAxisCanvas.click(TOGGLE_SIZE.x / 2, TOGGLE_SIZE.y / 2);
369 assertEquals(TOGGLE_SIZE.y, getSize(markerAxis).y);
370
371 /* click the 'collapsed' icon to expand */
372 markerAxisCanvas.click(TOGGLE_SIZE.x / 2, TOGGLE_SIZE.y / 2);
373 assertEquals(size1, getSize(markerAxis));
374
375 /* click on the 'X' icon to hide the 'Lost Events' marker category */
376 markerAxisCanvas.click(TOGGLE_SIZE.x + HIDE_SIZE.x / 2, TOP_MARGIN + HIDE_SIZE.y / 2);
377 assertEquals(0, getSize(markerAxis).y);
378
379 /* show Lost Events markers */
380 fViewBot.viewMenu(LOST_EVENTS).click();
381 assertEquals(size1, getSize(markerAxis));
382 }
383
384 private void timeGraphIsReadyCondition(@NonNull TmfTimeRange selectionRange, @NonNull ITmfTimestamp visibleTime) {
385 IWorkbenchPart part = fViewBot.getViewReference().getPart(false);
386 fBot.waitUntil(ConditionHelpers.timeGraphIsReadyCondition((AbstractTimeGraphView) part, selectionRange, visibleTime));
387 }
388
389 private static int getXForTime(TimeGraphControl timeGraph, long time) {
390 return UIThreadRunnable.syncExec(new Result<Integer>() {
391 @Override
392 public Integer run() {
393 return timeGraph.getXForTime(time);
394 }
395 });
396 }
397
398 private static Point getSize(Control control) {
399 return UIThreadRunnable.syncExec(new Result<Point>() {
400 @Override
401 public Point run() {
402 return control.getSize();
403 }
404 });
405 }
406 }
This page took 0.039985 seconds and 5 git commands to generate.