--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+import org.eclipse.swtbot.swt.finder.keyboard.Keyboard;
+import org.eclipse.swtbot.swt.finder.keyboard.KeyboardFactory;
+import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
+import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
+import org.eclipse.swtbot.swt.finder.results.VoidResult;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
+import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * SWTBot tests for Control Flow view
+ *
+ * @author Patrick Tasse
+ */
+public class ControlFlowViewTest extends KernelTest {
+
+ private static final String FOLLOW_CPU_BACKWARD = "Follow CPU Backward";
+ private static final String FOLLOW_CPU_FORWARD = "Follow CPU Forward";
+ private static final String SELECT_PREVIOUS_EVENT = "Select Previous Event";
+ private static final String SELECT_NEXT_EVENT = "Select Next Event";
+ private static final Keyboard KEYBOARD = KeyboardFactory.getSWTKeyboard();
+ private static final @NonNull ITmfTimestamp START_TIME = new TmfNanoTimestamp(1368000272650993664L);
+ private static final @NonNull ITmfTimestamp TID1_TIME1 = new TmfNanoTimestamp(1368000272651208412L);
+ private static final @NonNull ITmfTimestamp TID1_TIME2 = new TmfNanoTimestamp(1368000272656147616L);
+ private static final @NonNull ITmfTimestamp TID1_TIME3 = new TmfNanoTimestamp(1368000272656362364L);
+ private static final @NonNull ITmfTimestamp TID1_TIME4 = new TmfNanoTimestamp(1368000272663234300L);
+ private static final @NonNull ITmfTimestamp TID1_TIME5 = new TmfNanoTimestamp(1368000272663449048L);
+ private static final @NonNull ITmfTimestamp TID1_TIME6 = new TmfNanoTimestamp(1368000272665596528L);
+ private static final @NonNull ITmfTimestamp TID2_TIME1 = new TmfNanoTimestamp(1368000272651852656L);
+ private static final @NonNull ITmfTimestamp TID2_TIME2 = new TmfNanoTimestamp(1368000272652067404L);
+ private static final @NonNull ITmfTimestamp TID2_TIME3 = new TmfNanoTimestamp(1368000272652282152L);
+ private static final @NonNull ITmfTimestamp TID2_TIME4 = new TmfNanoTimestamp(1368000272652496900L);
+ private static final @NonNull ITmfTimestamp TID5_TIME1 = new TmfNanoTimestamp(1368000272652496900L);
+
+ private SWTBotView fViewBot;
+
+ /**
+ * Before Test
+ */
+ @Override
+ @Before
+ public void before() {
+ super.before();
+ fViewBot = fBot.viewByTitle("Control Flow");
+ }
+
+ /**
+ * Test keyboard navigation using ARROW_RIGHT and ARROW_LEFT
+ */
+ @Test
+ public void testKeyboardLeftRight() {
+ /* change window range to 10 ms */
+ TmfTimeRange range = new TmfTimeRange(START_TIME, START_TIME.normalize(10000000L, ITmfTimestamp.NANOSECOND_SCALE));
+ TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range));
+ fBot.waitUntil(ConditionHelpers.windowRange(range));
+
+ /* set selection to trace start time */
+ TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(START_TIME, START_TIME)));
+
+ /* select first item */
+ final SWTBotTree tree = fViewBot.bot().tree();
+ tree.pressShortcut(Keystrokes.HOME);
+
+ /* set focus on time graph */
+ final TimeGraphControl timegraph = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
+ UIThreadRunnable.syncExec(new VoidResult() {
+ @Override
+ public void run() {
+ timegraph.setFocus();
+ }
+ });
+
+ /* press ARROW_RIGHT 3 times */
+ KEYBOARD.pressShortcut(Keystrokes.RIGHT);
+ KEYBOARD.pressShortcut(Keystrokes.RIGHT);
+ KEYBOARD.pressShortcut(Keystrokes.RIGHT);
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME3)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME3));
+
+ /* press Shift-ARROW_RIGHT 3 times */
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME6)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME6));
+
+ /* press Shift-ARROW_LEFT 4 times */
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME2)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME2));
+
+ /* press ARROW_RIGHT 2 times */
+ KEYBOARD.pressShortcut(Keystrokes.RIGHT);
+ KEYBOARD.pressShortcut(Keystrokes.RIGHT);
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME4)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME4));
+
+ /* press Shift-ARROW_LEFT 3 times */
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME1)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME1));
+
+ /* press Shift-ARROW_RIGHT 4 times */
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+ KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME5)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME5));
+
+ /* press ARROW_LEFT 5 times */
+ KEYBOARD.pressShortcut(Keystrokes.LEFT);
+ KEYBOARD.pressShortcut(Keystrokes.LEFT);
+ KEYBOARD.pressShortcut(Keystrokes.LEFT);
+ KEYBOARD.pressShortcut(Keystrokes.LEFT);
+ KEYBOARD.pressShortcut(Keystrokes.LEFT);
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(START_TIME, START_TIME)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(START_TIME));
+ }
+
+ /**
+ * Test tool bar buttons "Select Next Event" and "Select Previous Event"
+ */
+ @Test
+ public void testToolBarSelectNextPreviousEvent() {
+ /* change window range to 10 ms */
+ TmfTimeRange range = new TmfTimeRange(START_TIME, START_TIME.normalize(10000000L, ITmfTimestamp.NANOSECOND_SCALE));
+ TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range));
+ fBot.waitUntil(ConditionHelpers.windowRange(range));
+
+ /* set selection to trace start time */
+ TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(START_TIME, START_TIME)));
+
+ /* select first item */
+ final SWTBotTree tree = fViewBot.bot().tree();
+ tree.pressShortcut(Keystrokes.HOME);
+
+ /* set focus on time graph */
+ final TimeGraphControl timegraph = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
+ UIThreadRunnable.syncExec(new VoidResult() {
+ @Override
+ public void run() {
+ timegraph.setFocus();
+ }
+ });
+
+ /* click "Select Next Event" 3 times */
+ fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+ fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+ fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME3)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME3));
+
+// /* shift-click "Select Next Event" 3 times */
+// fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+// fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+// fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+// fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME6)));
+ /* click "Select Next Event" 3 times */
+ fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+ fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+ fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME6, TID1_TIME6)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME6));
+
+// /* shift-click "Select Previous Event" 4 times */
+// fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+// fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+// fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+// fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+// fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME2)));
+ /* click "Select Previous Event" 4 times */
+ fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+ fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+ fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+ fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME2, TID1_TIME2)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME2));
+
+ /* click "Select Next Event" 2 times */
+ fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+ fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME4)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME4));
+
+// /* shift-click "Select Previous Event" 3 times */
+// fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+// fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+// fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+// fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME1)));
+ /* click "Select Previous Event" 3 times */
+ fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+ fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+ fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME1, TID1_TIME1)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME1));
+
+// /* shift-click "Select Next Event" 4 times */
+// fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+// fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+// fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+// fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+// fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME5)));
+ /* click "Select Next Event" 4 times */
+ fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+ fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+ fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+ fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME5, TID1_TIME5)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME5));
+
+ /* click "Select Previous Event" 5 times */
+ fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+ fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+ fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+ fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+ fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(START_TIME, START_TIME)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(START_TIME));
+ }
+
+ /**
+ * Test tool bar buttons "Follow CPU Forward" and "Follow CPU Backward"
+ */
+ @Test
+ public void testToolBarFollowCPUForwardBackward() {
+ /* change window range to 10 ms */
+ TmfTimeRange range = new TmfTimeRange(START_TIME, START_TIME.normalize(10000000L, ITmfTimestamp.NANOSECOND_SCALE));
+ TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range));
+ fBot.waitUntil(ConditionHelpers.windowRange(range));
+
+ /* set selection to trace start time */
+ TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(START_TIME, START_TIME)));
+
+ /* select first item */
+ final SWTBotTree tree = fViewBot.bot().tree();
+ tree.pressShortcut(Keystrokes.HOME);
+
+ /* set focus on time graph */
+ final TimeGraphControl timegraph = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
+ UIThreadRunnable.syncExec(new VoidResult() {
+ @Override
+ public void run() {
+ timegraph.setFocus();
+ }
+ });
+
+ /* make sure arrows have been computed */
+ fBot.waitUntil(new DefaultCondition() {
+ @Override
+ public boolean test() throws Exception {
+ List<ILinkEvent> arrows = timegraph.getArrows();
+ return arrows.size() >= 3 &&
+ arrows.get(0).getTime() == TID1_TIME1.getValue() &&
+ arrows.get(1).getTime() == TID2_TIME2.getValue() &&
+ arrows.get(2).getTime() == TID2_TIME4.getValue();
+ }
+ @Override
+ public String getFailureMessage() {
+ return "Arrows not found";
+ }
+ });
+
+ /* click "Follow CPU Forward" 3 times */
+ fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME2, TID2_TIME2)));
+ assertEquals("2", tree.selection().get(0, 1));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME2));
+
+// /* shift-click "Follow CPU Forward" 3 times */
+// fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+// fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+// fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+// fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME2, TID5_TIME1)));
+ /* click "Follow CPU Forward" 3 times */
+ fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID5_TIME1, TID5_TIME1)));
+ assertEquals("5", tree.selection().get(0, 1));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID5_TIME1));
+
+// /* shift-click "Follow CPU Backward" 4 times */
+// fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+// fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+// fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+// fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+// fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME2, TID2_TIME1)));
+ /* click "Follow CPU Backward" 4 times */
+ fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME1, TID2_TIME1)));
+ assertEquals("2", tree.selection().get(0, 1));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME1));
+
+ /* click "Follow CPU Forward" 2 times */
+ fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME3, TID2_TIME3)));
+ assertEquals("2", tree.selection().get(0, 1));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME3));
+
+// /* shift-click "Follow CPU Backward" 3 times */
+// fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+// fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+// fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+// fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME3, TID1_TIME1)));
+ /* click "Follow CPU Backward" 3 times */
+ fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME1, TID1_TIME1)));
+ assertEquals("1", tree.selection().get(0, 1));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME1));
+
+// /* shift-click "Follow CPU Forward" 4 times */
+// fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+// fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+// fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+// fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+// fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME3, TID2_TIME4)));
+ /* click "Follow CPU Forward" 4 times */
+ fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME4, TID2_TIME4)));
+ assertEquals("2", tree.selection().get(0, 1));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME4));
+
+ /* click "Follow CPU Backward" 5 times */
+ fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+ fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+ fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(START_TIME, START_TIME)));
+ assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(START_TIME));
+ }
+}
* Contributors:
* Matthew Khouzam - Initial API and implementation
* Marc-Andre Laperle
- * Patrick Tasse - Add support for folder elements
+ * Patrick Tasse - Extract base class from ImportAndReadKernelSmokeTest
*******************************************************************************/
package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
import java.util.List;
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Logger;
-import org.apache.log4j.SimpleLayout;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
-import org.eclipse.swtbot.swt.finder.results.BoolResult;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
-import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
import org.eclipse.tracecompass.analysis.os.linux.ui.views.controlflow.ControlFlowView;
import org.eclipse.tracecompass.analysis.os.linux.ui.views.resources.ResourcesView;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
-import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.WorkbenchException;
import org.hamcrest.Matcher;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
* @author Matthew Khouzam
*/
@RunWith(SWTBotJunit4ClassRunner.class)
-public class ImportAndReadKernelSmokeTest {
+public class ImportAndReadKernelSmokeTest extends KernelTest {
- private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype";
- private static final String KERNEL_PERSPECTIVE_ID = "org.eclipse.linuxtools.lttng2.kernel.ui.perspective";
- private static final String TRACE_PROJECT_NAME = "test";
private static final CtfTmfTestTrace CTT = CtfTmfTestTrace.SYNTHETIC_TRACE;
- private static SWTWorkbenchBot fBot;
private ITmfEvent fDesired1;
private ITmfEvent fDesired2;
- /** The Log4j logger instance. */
- private static final Logger fLogger = Logger.getRootLogger();
-
- /**
- * Test Class setup
- */
- @BeforeClass
- public static void init() {
- SWTBotUtils.failIfUIThread();
-
- /* set up for swtbot */
- SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
- fLogger.removeAllAppenders();
- fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
- fBot = new SWTWorkbenchBot();
-
- final List<SWTBotView> openViews = fBot.views();
- for (SWTBotView view : openViews) {
- if (view.getTitle().equals("Welcome")) {
- view.close();
- fBot.waitUntil(ConditionHelpers.ViewIsClosed(view));
- }
- }
- /* Switch perspectives */
- switchKernelPerspective();
- /* Finish waiting for eclipse to load */
- SWTBotUtils.waitForJobs();
- }
-
- /**
- * Test Class teardown
- */
- @AfterClass
- public static void terminate() {
- fLogger.removeAllAppenders();
- }
-
- private static void switchKernelPerspective() {
- final Exception retE[] = new Exception[1];
- if (!UIThreadRunnable.syncExec(new BoolResult() {
- @Override
- public Boolean run() {
- try {
- PlatformUI.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID,
- PlatformUI.getWorkbench().getActiveWorkbenchWindow());
- } catch (WorkbenchException e) {
- retE[0] = e;
- return false;
- }
- return true;
- }
- })) {
- fail(retE[0].getMessage());
- }
-
- }
-
/**
* Main test case
*/
@Test
public void test() {
- SWTBotUtils.createProject(TRACE_PROJECT_NAME);
- SWTBotUtils.openTrace(TRACE_PROJECT_NAME, CTT.getPath(), TRACE_TYPE);
- openEditor();
- testHV(getViewPart("Histogram"));
- testCFV((ControlFlowView) getViewPart("Control Flow"));
- testRV((ResourcesView) getViewPart("Resources"));
-
- fBot.closeAllEditors();
- SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
- }
-
- private void openEditor() {
Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(CTT.getTrace().getName());
IEditorPart iep = fBot.editor(matcher).getReference().getEditor(true);
+ final TmfEventsEditor tmfEd = (TmfEventsEditor) iep;
fDesired1 = getEvent(100);
fDesired2 = getEvent(10000);
- final TmfEventsEditor tmfEd = (TmfEventsEditor) iep;
UIThreadRunnable.syncExec(new VoidResult() {
@Override
public void run() {
tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(fDesired1)));
}
});
-
- SWTBotUtils.waitForJobs();
- SWTBotUtils.delay(1000);
- assertNotNull(tmfEd);
+ testHV(getViewPart("Histogram"));
+ testCFV((ControlFlowView) getViewPart("Control Flow"));
+ testRV((ResourcesView) getViewPart("Resources"));
}
private static void testCFV(ControlFlowView vp) {
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ * Marc-Andre Laperle
+ * Patrick Tasse - Extract base class from ImportAndReadKernelSmokeTest
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
+
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.results.BoolResult;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.WorkbenchException;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+
+/**
+ * Base SWTBot test for LTTng Kernel UI.
+ *
+ * @author Matthew Khouzam
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class KernelTest {
+
+ private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype";
+ private static final String KERNEL_PERSPECTIVE_ID = "org.eclipse.linuxtools.lttng2.kernel.ui.perspective";
+ private static final String TRACE_PROJECT_NAME = "test";
+ private static final CtfTmfTestTrace CTT = CtfTmfTestTrace.SYNTHETIC_TRACE;
+
+ /** The workbench bot */
+ protected static SWTWorkbenchBot fBot;
+
+ /** The Log4j logger instance. */
+ private static final Logger fLogger = Logger.getRootLogger();
+
+ /**
+ * Before Class
+ */
+ @BeforeClass
+ public static void beforeClass() {
+ SWTBotUtils.failIfUIThread();
+
+ /* set up for swtbot */
+ SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
+ fLogger.removeAllAppenders();
+ fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
+ fBot = new SWTWorkbenchBot();
+
+ final List<SWTBotView> openViews = fBot.views();
+ for (SWTBotView view : openViews) {
+ if (view.getTitle().equals("Welcome")) {
+ view.close();
+ fBot.waitUntil(ConditionHelpers.ViewIsClosed(view));
+ }
+ }
+ /* Switch perspectives */
+ switchKernelPerspective();
+ /* Finish waiting for eclipse to load */
+ SWTBotUtils.waitForJobs();
+ SWTBotUtils.createProject(TRACE_PROJECT_NAME);
+ }
+
+ /**
+ * After Class
+ */
+ @AfterClass
+ public static void afterClass() {
+ SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
+ fLogger.removeAllAppenders();
+ }
+
+ private static void switchKernelPerspective() {
+ final Exception retE[] = new Exception[1];
+ if (!UIThreadRunnable.syncExec(new BoolResult() {
+ @Override
+ public Boolean run() {
+ try {
+ PlatformUI.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID,
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow());
+ } catch (WorkbenchException e) {
+ retE[0] = e;
+ return false;
+ }
+ return true;
+ }
+ })) {
+ fail(retE[0].getMessage());
+ }
+
+ }
+
+ /**
+ * Before Test
+ */
+ @Before
+ public void before() {
+ SWTBotUtils.openTrace(TRACE_PROJECT_NAME, CTT.getPath(), TRACE_TYPE);
+ SWTBotUtils.activateEditor(fBot, CTT.getTrace().getName());
+ }
+
+ /**
+ * After Test
+ */
+ @After
+ public void after() {
+ fBot.closeAllEditors();
+ }
+}