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