1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.analysis
.os
.linux
.ui
.swtbot
.tests
.latency
;
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
;
21 import java
.io
.IOException
;
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
;
61 * Tests of the scatter chart view
63 * @author Matthew Khouzam
65 @RunWith(SWTBotJunit4ClassRunner
.class)
66 public class SystemCallLatencyScatterChartViewTest
{
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
;
72 /** The Log4j logger instance. */
73 private static final Logger fLogger
= Logger
.getRootLogger();
74 private Chart fScatterChart
;
75 private SystemCallLatencyScatterView fSystemCallLatencyScatterView
= null;
81 public static void beforeClass() {
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();
100 * Opens a latency scatter chart
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
107 * @throws IllegalArgumentException
108 * the object is not the correct class type
113 public void createScatterViewer() throws SecurityException
, IllegalArgumentException
{
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
>() {
123 public IViewPart
run() {
124 return viewReference
.getView(true);
127 assertNotNull(viewPart
);
128 if (!(viewPart
instanceof SystemCallLatencyScatterView
)) {
129 fail("Could not instanciate view");
131 fSystemCallLatencyScatterView
= (SystemCallLatencyScatterView
) viewPart
;
132 fScatterChart
= viewBot
.bot().widget(WidgetOfType
.widgetOfType(Chart
.class));
133 assertNotNull(fScatterChart
);
140 public void closeDensityViewer() {
141 final SWTWorkbenchBot swtWorkbenchBot
= new SWTWorkbenchBot();
142 SWTBotView viewBot
= swtWorkbenchBot
.viewById(VIEW_ID
);
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
152 * @throws IOException
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
159 * @throws IllegalArgumentException
160 * the object is not the correct class type
164 public void testWithTrace() throws IOException
, SecurityException
, IllegalArgumentException
{
166 tracePath
= FileLocator
.toFileURL(CtfTestTrace
.ARM_64_BIT_HEADER
.getTraceURL()).getPath();
167 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
168 SWTBotView view
= bot
.viewById(VIEW_ID
);
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();
177 final Chart scatterChart
= fScatterChart
;
178 assertNotNull(scatterChart
);
179 bot
.waitUntil(ConditionHelpers
.numberOfSeries(scatterChart
, 1));
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
);
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
));
199 bot
.waitUntil(ConditionHelpers
.xyViewerIsReadyCondition(fSystemCallLatencyScatterView
.getChartViewer()));
201 range
= scatterChart
.getAxisSet().getXAxes()[0].getRange();
202 assertEquals(noDataEnd
- noDataStart
, range
.upper
- range
.lower
, 0);
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
);
210 bot
.closeAllEditors();
211 SWTBotUtils
.deleteProject(PROJECT_NAME
, bot
);
214 private static class SWTBotChart
extends AbstractSWTBotControl
<Chart
> {
215 public SWTBotChart(Chart w
) throws WidgetNotFoundException
{