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
CommitLineData
ea120d7d
MK
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
13package org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests.latency;
14
15import static org.eclipse.swtbot.swt.finder.SWTBotAssert.assertVisible;
16import static org.junit.Assert.assertEquals;
17import static org.junit.Assert.assertNotNull;
18import static org.junit.Assert.assertTrue;
19import static org.junit.Assert.fail;
20
21import java.io.IOException;
22
23import org.apache.log4j.ConsoleAppender;
24import org.apache.log4j.Logger;
25import org.apache.log4j.SimpleLayout;
26import org.eclipse.core.runtime.FileLocator;
27import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
28import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
29import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
30import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
31import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
32import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
33import org.eclipse.swtbot.swt.finder.results.Result;
34import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
35import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
36import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.SystemCallLatencyScatterView;
37import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
44af9da9
GB
38import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
39import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
40import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
41import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
ea120d7d
MK
42import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
43import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
f0beeb4a 44import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
ea120d7d
MK
45import org.eclipse.ui.IViewPart;
46import org.eclipse.ui.IViewReference;
47import org.junit.After;
48import org.junit.Before;
49import org.junit.BeforeClass;
50import org.junit.Test;
51import org.junit.runner.RunWith;
52import org.swtchart.Chart;
53import org.swtchart.ILineSeries;
54import org.swtchart.ISeries;
55import org.swtchart.ISeriesSet;
56import org.swtchart.Range;
57
58/**
59 * Tests of the scatter chart view
60 *
61 * @author Matthew Khouzam
62 */
63@RunWith(SWTBotJunit4ClassRunner.class)
64public 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;
44af9da9 73 private SystemCallLatencyScatterView fSystemCallLatencyScatterView = null;
ea120d7d
MK
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 */
f0beeb4a 93 WaitUtils.waitForJobs();
ea120d7d
MK
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 }
44af9da9 129 fSystemCallLatencyScatterView = (SystemCallLatencyScatterView) viewPart;
ea120d7d
MK
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);
f0beeb4a 171 WaitUtils.waitForJobs();
ea120d7d 172 createScatterViewer();
f0beeb4a 173 WaitUtils.waitForJobs();
ea120d7d
MK
174
175 final Chart scatterChart = fScatterChart;
176 assertNotNull(scatterChart);
aa5b9bd6
MAL
177 bot.waitUntil(ConditionHelpers.numberOfSeries(scatterChart, 1));
178
ea120d7d
MK
179 SWTBotChart chartBot = new SWTBotChart(scatterChart);
180 assertVisible(chartBot);
181 assertEquals("", chartBot.getToolTipText());
44af9da9 182 Range range = scatterChart.getAxisSet().getXAxes()[0].getRange();
ea120d7d
MK
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
44af9da9
GB
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
ea120d7d
MK
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.041526 seconds and 5 git commands to generate.