diff options
author | Yonni Chen | 2017-07-31 20:41:20 +0000 |
---|---|---|
committer | Loic Prieur-Drevon | 2017-08-17 13:35:16 +0000 |
commit | 04f5ba55db972d67374495c90f06631ac781f6ee (patch) | |
tree | 162e716634d4db4723eae1ea6e4a4391181f3bf6 | |
parent | e2fa7a880aed56e7c20de4a1d23d700aea28aa94 (diff) | |
download | org.eclipse.tracecompass-04f5ba55db972d67374495c90f06631ac781f6ee.tar.gz org.eclipse.tracecompass-04f5ba55db972d67374495c90f06631ac781f6ee.tar.xz org.eclipse.tracecompass-04f5ba55db972d67374495c90f06631ac781f6ee.zip |
lttng2.swtbot Test MemoryUsageView
This tests the Memory Usage view's model. It uses SWTBot for
control, but tests the model, not the view.
Change-Id: I808484c3a5969c081441108534d625a3ce44dcb6
Signed-off-by: Yonni Chen <yonni.chen.kuang.piao@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/102271
Reviewed-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Tested-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Reviewed-by: Hudson CI
Reviewed-by: Loic Prieur-Drevon <loic.prieurdrevon@gmail.com>
4 files changed, 357 insertions, 64 deletions
diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/META-INF/MANIFEST.MF b/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/META-INF/MANIFEST.MF index 7742ec9824..be6845518a 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/META-INF/MANIFEST.MF +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/META-INF/MANIFEST.MF @@ -30,4 +30,5 @@ Require-Bundle: org.apache.log4j, Export-Package: org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests, org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests.perf Import-Package: com.google.common.collect, + org.eclipse.tracecompass.common.core, org.eclipse.tracecompass.testtraces.ctf diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/resources/memory-res50.json b/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/resources/memory-res50.json new file mode 100644 index 0000000000..fb3fd845f0 --- /dev/null +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/resources/memory-res50.json @@ -0,0 +1,277 @@ +{ + "title": "Relative Kernel Memory Usage", + "xValues": [ + 1, + 2040952, + 4081784, + 6122616, + 8163448, + 10204280, + 12245112, + 14285944, + 16326776, + 18367608, + 20408440, + 22449272, + 24490104, + 26530936, + 28571768, + 30612600, + 32653432, + 34694264, + 36735096, + 38775928, + 40816760, + 42857592, + 44898424, + 46939256, + 48980088, + 51020920, + 53061752, + 55102584, + 57143416, + 59184248, + 61225080, + 63265912, + 65306744, + 67347576, + 69388408, + 71429240, + 73470072, + 75510904, + 77551736, + 79592568, + 81633400, + 83674232, + 85715064, + 87755896, + 89796728, + 91837560, + 93878392, + 95919224, + 97960056, + 100000001 + ], + "series": { + "challenger (10611)": { + "label": "challenger (10611)", + "yValues": [ + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 16.0, + 32.0, + 32.0, + 32.0, + 32.0, + 52.0, + 32.0, + 32.0, + 32.0, + 32.0, + 32.0, + 44.0, + 32.0, + 32.0, + 32.0, + 32.0, + 32.0, + 32.0, + 32.0, + 32.0, + 32.0, + 32.0, + 52.0, + 40.0, + 40.0, + 40.0, + 40.0, + 40.0, + 40.0, + 40.0, + 40.0 + ] + }, + "master_player (10618)": { + "label": "master_player (10618)", + "yValues": [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 16392.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 16404.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ] + }, + "challenger (10604)": { + "label": "challenger (10604)", + "yValues": [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 8.0, + 8.0, + 12.0, + 12.0, + 12.0, + 12.0, + 12.0, + 16.0, + 16.0, + 16.0, + 16.0, + 16.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 8.0, + 16.0, + 16.0, + 24.0, + 24.0, + 24.0, + 24.0, + 44.0, + 24.0, + 24.0, + 24.0, + 24.0, + 24.0, + 52.0, + 32.0, + 52.0, + 40.0, + 40.0, + 60.0, + 40.0, + 60.0, + 40.0, + 40.0 + ] + }, + "master_player (10613)": { + "label": "master_player (10613)", + "yValues": [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 16416.0, + 16416.0, + 0.0, + 0.0, + 0.0, + 0.0, + 16404.0, + 0.0, + 16416.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 20.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ] + } + } +}
\ No newline at end of file diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/ust/ui/swtbot/tests/MemoryUsageViewTest.java b/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/ust/ui/swtbot/tests/MemoryUsageViewTest.java index ed10d508e3..2bd068698e 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/ust/ui/swtbot/tests/MemoryUsageViewTest.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/ust/ui/swtbot/tests/MemoryUsageViewTest.java @@ -12,95 +12,50 @@ package org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.io.File; +import java.lang.reflect.InvocationTargetException; -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.jdt.annotation.NonNull; +import org.eclipse.swt.graphics.RGB; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType; -import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; import org.eclipse.tracecompass.internal.lttng2.ust.ui.views.memusage.MemoryUsageView; import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; +import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils; +import org.eclipse.tracecompass.tmf.ui.swtbot.tests.XYDataProviderBaseTest; 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.tests.shared.WaitUtils; +import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.linecharts.TmfCommonXLineChartViewer; +import org.eclipse.ui.IViewPart; import org.hamcrest.Matcher; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.swtchart.Chart; import org.swtchart.ILineSeries; import org.swtchart.ISeries; import org.swtchart.ISeriesSet; +import org.swtchart.LineStyle; /** * Test for the Memory Usage view in trace compass */ @RunWith(SWTBotJunit4ClassRunner.class) -public class MemoryUsageViewTest { +public class MemoryUsageViewTest extends XYDataProviderBaseTest { private static final int EXPECTED_NUM_SERIES = 4; - private static final String UST_ID = "org.eclipse.linuxtools.lttng2.ust.tracetype"; + private static final RGB RED = new RGB(255, 0, 0); + private static final RGB BLUE = new RGB(0, 0, 255); + private static final RGB GREEN = new RGB(0, 255, 0); + private static final RGB MAGENTA = new RGB(255, 0, 255); - private static final String PROJECT_NAME = "TestForMemory"; + private static final @NonNull String TITLE = "Relative Kernel Memory Usage"; - /** The Log4j logger instance. */ - private static final Logger fLogger = Logger.getRootLogger(); - private static SWTWorkbenchBot fBot; - - /** - * Initialization - */ - @BeforeClass - public static void init() { - SWTBotUtils.initialize(); - - Thread.currentThread().setName("SWTBot Thread"); // for the debugger - /* set up for swtbot */ - SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ - fLogger.addAppender(new ConsoleAppender(new SimpleLayout())); - fBot = new SWTWorkbenchBot(); - - SWTBotUtils.closeView("welcome", fBot); - - SWTBotUtils.switchToTracingPerspective(); - - /* finish waiting for eclipse to load */ - WaitUtils.waitForJobs(); - } - - /** - * Open a trace in an editor - */ - @Before - public void beforeTest() { - SWTBotUtils.createProject(PROJECT_NAME); - SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME); - assertNotNull(treeItem); - final CtfTestTrace cygProfile = CtfTestTrace.MEMORY_ANALYSIS; - final File file = new File(CtfTmfTestTraceUtils.getTrace(cygProfile).getPath()); - CtfTmfTestTraceUtils.dispose(cygProfile); - SWTBotUtils.openTrace(PROJECT_NAME, file.getAbsolutePath(), UST_ID); - SWTBotUtils.openView(MemoryUsageView.ID); - WaitUtils.waitForJobs(); - } - - /** - * Close the editor - */ - @After - public void tearDown() { - fBot.closeAllEditors(); - SWTBotUtils.deleteProject(PROJECT_NAME, fBot); - } + private static final @NonNull String FIRST_SERIES_NAME = "challenger (10611)"; + private static final @NonNull String SECOND_SERIES_NAME = "master_player (10618)"; + private static final @NonNull String THIRD_SERIES_NAME = "challenger (10604)"; + private static final @NonNull String FOURTH_SERIES_NAME = "master_player (10613)"; /** * Test if Memory Usage is populated @@ -125,4 +80,65 @@ public class MemoryUsageViewTest { } } + /** + * Test Memory Usage data model + * + * @throws NoSuchMethodException + * Reflection exception should not happen + * @throws SecurityException + * Reflection exception should not happen + * @throws IllegalAccessException + * Reflection exception should not happen + * @throws IllegalArgumentException + * Reflection exception should not happen + * @throws InvocationTargetException + * Reflection exception should not happen + */ + @Test + public void testMemoryUsage() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + IViewPart viewSite = getSWTBotView().getViewReference().getView(true); + assertTrue(viewSite instanceof MemoryUsageView); + final TmfCommonXLineChartViewer chartViewer = getChartViewer(viewSite); + assertNotNull(chartViewer); + fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer)); + + final Chart chart = getChart(); + assertNotNull(chart); + + WaitUtils.waitUntil(c -> c.getSeriesSet().getSeries().length > 3, chart, "No data available"); + chartViewer.setNbPoints(50); + + /* Test data model*/ + WaitUtils.waitUntil(json -> isChartDataValid(chart, json, SECOND_SERIES_NAME, THIRD_SERIES_NAME, FOURTH_SERIES_NAME), "resources/memory-res50.json", "Chart data is not valid"); + + /* Test type, style and color of series */ + verifyChartStyle(); + } + + private void verifyChartStyle() { + verifySeriesStyle(FIRST_SERIES_NAME, ISeries.SeriesType.LINE, BLUE, LineStyle.SOLID, false); + verifySeriesStyle(SECOND_SERIES_NAME, ISeries.SeriesType.LINE, RED, LineStyle.SOLID, false); + verifySeriesStyle(THIRD_SERIES_NAME, ISeries.SeriesType.LINE, GREEN, LineStyle.SOLID, false); + verifySeriesStyle(FOURTH_SERIES_NAME, ISeries.SeriesType.LINE, MAGENTA, LineStyle.SOLID, false); + } + + @Override + protected @NonNull String getMainSeriesName() { + return FIRST_SERIES_NAME; + } + + @Override + protected @NonNull String getTitle() { + return TITLE; + } + + @Override + protected String getViewID() { + return MemoryUsageView.ID; + } + + @Override + protected ITmfTrace getTestTrace() { + return CtfTmfTestTraceUtils.getTrace(CtfTestTrace.MEMORY_ANALYSIS); + } }
\ No newline at end of file diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/XYDataProviderBaseTest.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/XYDataProviderBaseTest.java index 68f769ad55..bf973c9721 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/XYDataProviderBaseTest.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/XYDataProviderBaseTest.java @@ -174,7 +174,6 @@ public abstract class XYDataProviderBaseTest { double[] xMain = mainSeries.getXSeries(); double[] yMain = mainSeries.getYSeries(); - @NonNull Map<@NonNull String, @NonNull IYModel> yModels = new LinkedHashMap<>(); yModels.put(mainSeriesName, new YModel(mainSeriesName, Objects.requireNonNull(yMain))); |