tmf.ui/timing: Update XY viewers even if there is no data
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests / src / org / eclipse / tracecompass / analysis / os / linux / ui / swtbot / tests / latency / SystemCallLatencyScatterChartViewTest.java
1 /*******************************************************************************
2 * Copyright (c) 2016 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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests.latency;
14
15 import static org.eclipse.swtbot.swt.finder.SWTBotAssert.assertVisible;
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertNotNull;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assert.fail;
20
21 import java.io.IOException;
22
23 import org.apache.log4j.ConsoleAppender;
24 import org.apache.log4j.Logger;
25 import org.apache.log4j.SimpleLayout;
26 import org.eclipse.core.runtime.FileLocator;
27 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
28 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
29 import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
30 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
31 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
32 import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
33 import org.eclipse.swtbot.swt.finder.results.Result;
34 import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
35 import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
36 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.SystemCallLatencyScatterView;
37 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
38 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
39 import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
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.swtbot.tests.shared.SWTBotUtils;
44 import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
45 import org.eclipse.ui.IViewPart;
46 import org.eclipse.ui.IViewReference;
47 import org.junit.After;
48 import org.junit.Before;
49 import org.junit.BeforeClass;
50 import org.junit.Test;
51 import org.junit.runner.RunWith;
52 import org.swtchart.Chart;
53 import org.swtchart.ILineSeries;
54 import org.swtchart.ISeries;
55 import org.swtchart.ISeriesSet;
56 import org.swtchart.Range;
57
58 /**
59 * Tests of the scatter chart view
60 *
61 * @author Matthew Khouzam
62 */
63 @RunWith(SWTBotJunit4ClassRunner.class)
64 public class SystemCallLatencyScatterChartViewTest {
65
66 private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype";
67 private static final String PROJECT_NAME = "test";
68 private static final String VIEW_ID = SystemCallLatencyScatterView.ID;
69
70 /** The Log4j logger instance. */
71 private static final Logger fLogger = Logger.getRootLogger();
72 private Chart fScatterChart;
73 private SystemCallLatencyScatterView fSystemCallLatencyScatterView = null;
74
75 /**
76 * Things to setup
77 */
78 @BeforeClass
79 public static void beforeClass() {
80
81 SWTBotUtils.initialize();
82 Thread.currentThread().setName("SWTBotTest");
83 /* set up for swtbot */
84 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
85 SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
86 fLogger.removeAllAppenders();
87 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
88 SWTWorkbenchBot bot = new SWTWorkbenchBot();
89 SWTBotUtils.closeView("welcome", bot);
90 /* Switch perspectives */
91 SWTBotUtils.switchToTracingPerspective();
92 /* Finish waiting for eclipse to load */
93 WaitUtils.waitForJobs();
94
95 }
96
97 /**
98 * Opens a latency scatter chart
99 *
100 * @throws SecurityException
101 * If a security manager is present and any the wrong class is
102 * loaded or the class loader is not the same as its ancestor's
103 * loader.
104 *
105 * @throws IllegalArgumentException
106 * the object is not the correct class type
107 *
108 *
109 */
110 @Before
111 public void createScatterViewer() throws SecurityException, IllegalArgumentException {
112 /*
113 * Open latency view
114 */
115 SWTBotUtils.openView(VIEW_ID);
116 SWTWorkbenchBot bot = new SWTWorkbenchBot();
117 SWTBotView viewBot = bot.viewById(VIEW_ID);
118 final IViewReference viewReference = viewBot.getViewReference();
119 IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() {
120 @Override
121 public IViewPart run() {
122 return viewReference.getView(true);
123 }
124 });
125 assertNotNull(viewPart);
126 if (!(viewPart instanceof SystemCallLatencyScatterView)) {
127 fail("Could not instanciate view");
128 }
129 fSystemCallLatencyScatterView = (SystemCallLatencyScatterView) viewPart;
130 fScatterChart = viewBot.bot().widget(WidgetOfType.widgetOfType(Chart.class));
131 assertNotNull(fScatterChart);
132 }
133
134 /**
135 * Closes the view
136 */
137 @After
138 public void closeDensityViewer() {
139 final SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot();
140 SWTBotView viewBot = swtWorkbenchBot.viewById(VIEW_ID);
141 viewBot.close();
142 }
143
144 /**
145 * Test with an actual trace, this is more of an integration test than a
146 * unit test. This test is a slow one too. If some analyses are not well
147 * configured, this test will also generates null pointer exceptions. These
148 * will be logged.
149 *
150 * @throws IOException
151 * trace not found?
152 * @throws SecurityException
153 * If a security manager is present and any the wrong class is
154 * loaded or the class loader is not the same as its ancestor's
155 * loader.
156 *
157 * @throws IllegalArgumentException
158 * the object is not the correct class type
159 *
160 */
161 @Test
162 public void testWithTrace() throws IOException, SecurityException, IllegalArgumentException {
163 String tracePath;
164 tracePath = FileLocator.toFileURL(CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL()).getPath();
165 SWTWorkbenchBot bot = new SWTWorkbenchBot();
166 SWTBotView view = bot.viewById(VIEW_ID);
167 view.close();
168 bot.waitUntil(ConditionHelpers.ViewIsClosed(view));
169 SWTBotUtils.createProject(PROJECT_NAME);
170 SWTBotUtils.openTrace(PROJECT_NAME, tracePath, TRACE_TYPE);
171 WaitUtils.waitForJobs();
172 createScatterViewer();
173 WaitUtils.waitForJobs();
174
175 final Chart scatterChart = fScatterChart;
176 assertNotNull(scatterChart);
177 bot.waitUntil(ConditionHelpers.numberOfSeries(scatterChart, 1));
178
179 SWTBotChart chartBot = new SWTBotChart(scatterChart);
180 assertVisible(chartBot);
181 assertEquals("", chartBot.getToolTipText());
182 Range range = scatterChart.getAxisSet().getXAxes()[0].getRange();
183 assertEquals(100000000, range.upper - range.lower, 0);
184 ISeriesSet seriesSet = fScatterChart.getSeriesSet();
185 assertNotNull(seriesSet);
186 ISeries[] series = seriesSet.getSeries();
187 assertNotNull(series);
188
189 // Update the time range to a range where there is no data
190 long noDataStart = 1412670961274443542L;
191 long noDataEnd = 1412670961298823940L;
192 TmfTimeRange windowRange = new TmfTimeRange(TmfTimestamp.fromNanos(noDataStart), TmfTimestamp.fromNanos(noDataEnd));
193 TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, windowRange));
194
195 bot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(fSystemCallLatencyScatterView.getChartViewer()));
196
197 range = scatterChart.getAxisSet().getXAxes()[0].getRange();
198 assertEquals(noDataEnd - noDataStart, range.upper - range.lower, 0);
199
200 // Verify that the chart has 1 series
201 assertEquals(1, series.length);
202 // Verify that each series is a ILineSeries
203 for (int i = 0; i < series.length; i++) {
204 assertTrue(series[i] instanceof ILineSeries);
205 }
206 bot.closeAllEditors();
207 SWTBotUtils.deleteProject(PROJECT_NAME, bot);
208 }
209
210 private static class SWTBotChart extends AbstractSWTBotControl<Chart> {
211 public SWTBotChart(Chart w) throws WidgetNotFoundException {
212 super(w);
213 }
214 }
215 }
This page took 0.039142 seconds and 5 git commands to generate.