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