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
.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
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
41 import org
.eclipse
.ui
.IViewPart
;
42 import org
.eclipse
.ui
.IViewReference
;
43 import org
.junit
.After
;
44 import org
.junit
.Before
;
45 import org
.junit
.BeforeClass
;
46 import org
.junit
.Test
;
47 import org
.junit
.runner
.RunWith
;
48 import org
.swtchart
.Chart
;
49 import org
.swtchart
.ILineSeries
;
50 import org
.swtchart
.ISeries
;
51 import org
.swtchart
.ISeriesSet
;
52 import org
.swtchart
.Range
;
55 * Tests of the scatter chart view
57 * @author Matthew Khouzam
59 @RunWith(SWTBotJunit4ClassRunner
.class)
60 public class SystemCallLatencyScatterChartViewTest
{
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
;
66 /** The Log4j logger instance. */
67 private static final Logger fLogger
= Logger
.getRootLogger();
68 private Chart fScatterChart
;
74 public static void beforeClass() {
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 */
88 WaitUtils
.waitForJobs();
93 * Opens a latency scatter chart
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
100 * @throws IllegalArgumentException
101 * the object is not the correct class type
106 public void createScatterViewer() throws SecurityException
, IllegalArgumentException
{
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
>() {
116 public IViewPart
run() {
117 return viewReference
.getView(true);
120 assertNotNull(viewPart
);
121 if (!(viewPart
instanceof SystemCallLatencyScatterView
)) {
122 fail("Could not instanciate view");
124 fScatterChart
= viewBot
.bot().widget(WidgetOfType
.widgetOfType(Chart
.class));
125 assertNotNull(fScatterChart
);
132 public void closeDensityViewer() {
133 final SWTWorkbenchBot swtWorkbenchBot
= new SWTWorkbenchBot();
134 SWTBotView viewBot
= swtWorkbenchBot
.viewById(VIEW_ID
);
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
144 * @throws IOException
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
151 * @throws IllegalArgumentException
152 * the object is not the correct class type
156 public void testWithTrace() throws IOException
, SecurityException
, IllegalArgumentException
{
158 tracePath
= FileLocator
.toFileURL(CtfTestTrace
.ARM_64_BIT_HEADER
.getTraceURL()).getPath();
159 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
160 SWTBotView view
= bot
.viewById(VIEW_ID
);
162 bot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
163 SWTBotUtils
.createProject(PROJECT_NAME
);
164 SWTBotUtils
.openTrace(PROJECT_NAME
, tracePath
, TRACE_TYPE
);
165 WaitUtils
.waitForJobs();
166 createScatterViewer();
167 WaitUtils
.waitForJobs();
169 final Chart scatterChart
= fScatterChart
;
170 assertNotNull(scatterChart
);
171 bot
.waitUntil(ConditionHelpers
.numberOfSeries(scatterChart
, 1));
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
);
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
);
189 bot
.closeAllEditors();
190 SWTBotUtils
.deleteProject(PROJECT_NAME
, bot
);
193 private static class SWTBotChart
extends AbstractSWTBotControl
<Chart
> {
194 public SWTBotChart(Chart w
) throws WidgetNotFoundException
{