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
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;
516a0f0f 27import org.eclipse.jdt.annotation.NonNull;
ea120d7d
MK
28import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
29import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
30import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
31import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
32import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
33import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
34import org.eclipse.swtbot.swt.finder.results.Result;
35import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
36import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
37import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.SystemCallLatencyScatterView;
38import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
44af9da9
GB
39import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
40import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
41import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
42import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
516a0f0f 43import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
ea120d7d
MK
44import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
45import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
f0beeb4a 46import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
ea120d7d
MK
47import org.eclipse.ui.IViewPart;
48import org.eclipse.ui.IViewReference;
49import org.junit.After;
50import org.junit.Before;
51import org.junit.BeforeClass;
52import org.junit.Test;
53import org.junit.runner.RunWith;
54import org.swtchart.Chart;
55import org.swtchart.ILineSeries;
56import org.swtchart.ISeries;
57import org.swtchart.ISeriesSet;
58import org.swtchart.Range;
59
60/**
61 * Tests of the scatter chart view
62 *
63 * @author Matthew Khouzam
64 */
65@RunWith(SWTBotJunit4ClassRunner.class)
66public 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;
44af9da9 75 private SystemCallLatencyScatterView fSystemCallLatencyScatterView = null;
ea120d7d
MK
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 */
f0beeb4a 95 WaitUtils.waitForJobs();
ea120d7d
MK
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 }
44af9da9 131 fSystemCallLatencyScatterView = (SystemCallLatencyScatterView) viewPart;
ea120d7d
MK
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);
f0beeb4a 173 WaitUtils.waitForJobs();
ea120d7d 174 createScatterViewer();
f0beeb4a 175 WaitUtils.waitForJobs();
ea120d7d
MK
176
177 final Chart scatterChart = fScatterChart;
178 assertNotNull(scatterChart);
aa5b9bd6
MAL
179 bot.waitUntil(ConditionHelpers.numberOfSeries(scatterChart, 1));
180
ea120d7d
MK
181 SWTBotChart chartBot = new SWTBotChart(scatterChart);
182 assertVisible(chartBot);
183 assertEquals("", chartBot.getToolTipText());
516a0f0f
MAL
184 @NonNull TmfTimeRange traceWindowRange = TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange();
185 assertEquals("Unexpected trace window range", 100000000, traceWindowRange.getEndTime().getValue() - traceWindowRange.getStartTime().getValue());
44af9da9 186 Range range = scatterChart.getAxisSet().getXAxes()[0].getRange();
516a0f0f 187 assertEquals("Unexpected X-axis range", 100000000, range.upper - range.lower, 0);
ea120d7d
MK
188 ISeriesSet seriesSet = fScatterChart.getSeriesSet();
189 assertNotNull(seriesSet);
190 ISeries[] series = seriesSet.getSeries();
191 assertNotNull(series);
192
44af9da9
GB
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
ea120d7d
MK
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.047157 seconds and 5 git commands to generate.