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