From 976af99f412987fd0bf96dc36644ed2dadef9bdf Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Tue, 18 Oct 2016 14:16:38 -0400 Subject: [PATCH] lttng.swtbot: Add resources view swtbot tests This removes two tests from the manual tests. Also, it adds the notion of a shared test base with control flow view. Change-Id: Ieea4539eafcd00d62d56347b6cab55654d137d53 Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/83468 Reviewed-by: Hudson CI Reviewed-by: Genevieve Bastien Tested-by: Genevieve Bastien Reviewed-by: Jonathan Rajotte Julien --- .../ui/swtbot/tests/ControlFlowViewTest.java | 65 +++---------- .../tests/KernelTimeGraphViewTestBase.java | 94 +++++++++++++++++++ .../ui/swtbot/tests/ResourcesViewTest.java | 42 ++++++++- 3 files changed, 142 insertions(+), 59 deletions(-) create mode 100644 lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/KernelTimeGraphViewTestBase.java diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ControlFlowViewTest.java b/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ControlFlowViewTest.java index f8655d702f..f17395aba0 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ControlFlowViewTest.java +++ b/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ControlFlowViewTest.java @@ -13,10 +13,8 @@ package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -31,7 +29,6 @@ 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.widgets.SWTBotLabel; import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; @@ -58,9 +55,8 @@ import org.junit.runner.RunWith; * @author Patrick Tasse */ @RunWith(SWTBotJunit4ClassRunner.class) -public class ControlFlowViewTest extends KernelTestBase { +public class ControlFlowViewTest extends KernelTimeGraphViewTestBase { - private static final String SEPARATOR = ""; private static final String CHECK_SELECTED = "Check selected"; private static final String CHECK_ALL = "Check all"; private static final String CHECK_SUBTREE = "Check subtree"; @@ -91,30 +87,25 @@ public class ControlFlowViewTest extends KernelTestBase { private SWTBotView fViewBot; - /** - * Get the legend text values in order (override if you subclass the test) - * - * @return the legend text values in order - */ + @Override + protected SWTBotView getViewBot() { + return fViewBot; + } + + @Override protected List getLegendValues() { - String[] labelValues = { "UNKNOWN", "WAIT_UNKNOWN", "WAIT_BLOCKED", "WAIT_FOR_CPU", "USERMODE", "SYSCALL", "INTERRUPTED" }; - return Arrays.asList(labelValues); + return Arrays.asList("UNKNOWN", "WAIT_UNKNOWN", "WAIT_BLOCKED", "WAIT_FOR_CPU", "USERMODE", "SYSCALL", "INTERRUPTED"); } - /** - * Get the tool bar tool tip text values in order (override if you subclass the test) - * - * @return the tool bar tool tip text values in order - */ + @Override protected List getToolbarTooltips() { - String[] tooltipsArray = { "Align Views", "Optimize", SEPARATOR, + return Arrays.asList("Align Views", "Optimize", SEPARATOR, "Show View Filters", "Show Legend", SEPARATOR, "Reset the Time Scale to Default", "Select Previous State Change", "Select Next State Change", SEPARATOR, "Add Bookmark...", "Previous Marker", "Next Marker", SEPARATOR, "Select Previous Process", "Select Next Process", "Zoom In", "Zoom Out", SEPARATOR, "Hide Arrows", "Follow CPU Backward", "Follow CPU Forward", - "Go to previous event of the selected thread", "Go to next event of the selected thread" }; - return Arrays.asList(tooltipsArray); + "Go to previous event of the selected thread", "Go to next event of the selected thread" ); } /** @@ -252,40 +243,6 @@ public class ControlFlowViewTest extends KernelTestBase { assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(START_TIME)); } - /** - * Test toolbar button order and that all buttons are enabled and visible - */ - @Test - public void testToolbar() { - List buttons = fViewBot.getToolbarButtons(); - List tooltipsExpected = getToolbarTooltips(); - List tooltips = new ArrayList<>(); - for (SWTBotToolbarButton button : buttons) { - tooltips.add(button.getToolTipText()); - assertTrue(button.getText() + " enabled", button.isEnabled()); - assertTrue(button.getText() + " visible", button.isVisible()); - } - assertEquals(tooltipsExpected, tooltips); - } - - /** - * Test the legend content - */ - @Test - public void testLegend() { - List labelValues = getLegendValues(); - SWTBotToolbarButton legendButton = fViewBot.toolbarButton("Show Legend"); - legendButton.click(); - fBot.waitUntil(org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive("States Transition Visualizer")); - SWTBot bot = fBot.activeShell().bot(); - for (int i = 1; i <= labelValues.size(); i++) { - SWTBotLabel label = bot.label(i); - assertNotNull(label); - assertEquals(labelValues.get(i - 1), label.getText()); - } - bot.button("OK").click(); - } - /** * Test the filter */ diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/KernelTimeGraphViewTestBase.java b/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/KernelTimeGraphViewTestBase.java new file mode 100644 index 0000000000..b0b585169d --- /dev/null +++ b/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/KernelTimeGraphViewTestBase.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2016 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 + *******************************************************************************/ + +package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.SWTBot; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotLabel; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton; +import org.junit.Test; + +/** + * Kernel based time graph view test base. Used to test time graph views using + * kernel traces + * + * @author Matthew Khouzam + * + */ +public abstract class KernelTimeGraphViewTestBase extends KernelTestBase { + + /** + * Tooltip used for separator toolbar items + */ + protected static final String SEPARATOR = ""; + + /** + * Get an SWTBotView of the view being tested + * + * @return a bot of the view being tested + */ + protected abstract SWTBotView getViewBot(); + + /** + * Get the tool bar tool tip text values in order + * + * @return the tool bar tool tip text values in order + */ + protected abstract List getToolbarTooltips(); + + /** + * Get the legend text values in order + * + * @return the legend text values in order + */ + protected abstract List getLegendValues(); + + /** + * Test toolbar button order and that all buttons are enabled and visible + */ + @Test + public void testToolbar() { + List buttons = getViewBot().getToolbarButtons(); + List tooltipsExpected = getToolbarTooltips(); + List tooltips = new ArrayList<>(); + for (SWTBotToolbarButton button : buttons) { + tooltips.add(button.getToolTipText()); + assertTrue(button.getText() + " enabled", button.isEnabled()); + assertTrue(button.getText() + " visible", button.isVisible()); + } + assertEquals(tooltipsExpected, tooltips); + } + + /** + * Test the legend content + */ + @Test + public void testLegend() { + List labelValues = getLegendValues(); + SWTBotToolbarButton legendButton = getViewBot().toolbarButton("Show Legend"); + legendButton.click(); + fBot.waitUntil(org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive("States Transition Visualizer")); + SWTBot bot = fBot.activeShell().bot(); + for (int i = 1; i <= labelValues.size(); i++) { + SWTBotLabel label = bot.label(i); + assertNotNull(label); + assertEquals(labelValues.get(i - 1), label.getText()); + } + bot.button("OK").click(); + } + +} \ No newline at end of file diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ResourcesViewTest.java b/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ResourcesViewTest.java index 8e1ae21d17..fdfb05c7ff 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ResourcesViewTest.java +++ b/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ResourcesViewTest.java @@ -16,6 +16,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.util.Arrays; +import java.util.List; + import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jface.bindings.keys.KeyStroke; import org.eclipse.swt.SWT; @@ -50,7 +53,7 @@ import org.junit.Test; * * @author Patrick Tasse */ -public class ResourcesViewTest extends KernelTestBase { +public class ResourcesViewTest extends KernelTimeGraphViewTestBase { private static final String NEXT_MARKER = "Next Marker"; private static final String PREVIOUS_MARKER = "Previous Marker"; @@ -80,6 +83,24 @@ public class ResourcesViewTest extends KernelTestBase { private SWTBotView fViewBot; + @Override + protected SWTBotView getViewBot() { + return fViewBot; + } + + @Override + protected List getLegendValues() { + return Arrays.asList("IDLE", "USERMODE", "SYSCALL", "IRQ", "SOFT_IRQ", "IRQ_ACTIVE", "SOFT_IRQ_RAISED", "SOFT_IRQ_ACTIVE"); + } + + @Override + protected List getToolbarTooltips() { + return Arrays.asList("Align Views", "Show View Filters", "Show Legend", SEPARATOR, + "Reset the Time Scale to Default", "Select Previous State Change", "Select Next State Change", SEPARATOR, + "Add Bookmark...", "Previous Marker", "Next Marker", SEPARATOR, + "Select Previous Resource", "Select Next Resource", "Zoom In", "Zoom Out" ); + } + /** * Before Test */ @@ -247,7 +268,10 @@ public class ResourcesViewTest extends KernelTestBase { dialogBot.text().setText("B1"); dialogBot.button(OK).click(); - /* click "Select Next State Change" 2 times and shift-click "Select Next State Change*/ + /* + * click "Select Next State Change" 2 times and shift-click "Select Next + * State Change + */ fViewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click(); timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME3, CPU0_TIME3), CPU0_TIME3); fViewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click(); @@ -314,17 +338,25 @@ public class ResourcesViewTest extends KernelTestBase { final Point size2 = getSize(markerAxis); final int rowHeight = size2.y - size1.y; - /* get the state area bounds, since we don't know the name space width */ + /* + * get the state area bounds, since we don't know the name space width + */ final TimeGraphControl timeGraph = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class)); int x0 = getXForTime(timeGraph, startTime.toNanos()); int x1 = getXForTime(timeGraph, endTime.toNanos()); - /* click at the center of the marker axis width and first row height, it should be within the lost event range */ + /* + * click at the center of the marker axis width and first row height, it + * should be within the lost event range + */ final SWTBotCanvas markerAxisCanvas = new SWTBotCanvas(markerAxis); markerAxisCanvas.click((x0 + x1) / 2, TOP_MARGIN + rowHeight / 2); fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(LOST_EVENT_TIME1, LOST_EVENT_END1))); - /* click near the left of the marker axis width and center of second row height, it should be on the bookmark label */ + /* + * click near the left of the marker axis width and center of second row + * height, it should be on the bookmark label + */ markerAxisCanvas.click(x0 + 2, TOP_MARGIN + rowHeight + rowHeight / 2); fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(startTime, startTime))); -- 2.34.1