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
;
22 import java
.lang
.reflect
.Field
;
24 import org
.apache
.log4j
.ConsoleAppender
;
25 import org
.apache
.log4j
.Logger
;
26 import org
.apache
.log4j
.SimpleLayout
;
27 import org
.eclipse
.core
.runtime
.FileLocator
;
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
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
38 import org
.eclipse
.tracecompass
.analysis
.timing
.ui
.views
.segmentstore
.density
.AbstractSegmentStoreDensityView
;
39 import org
.eclipse
.tracecompass
.analysis
.timing
.ui
.views
.segmentstore
.table
.AbstractSegmentStoreTableViewer
;
40 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.views
.latency
.SystemCallLatencyDensityView
;
41 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
42 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
43 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
44 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
45 import org
.eclipse
.ui
.IViewPart
;
46 import org
.eclipse
.ui
.IViewReference
;
47 import org
.junit
.After
;
48 import org
.junit
.Before
;
49 import org
.junit
.BeforeClass
;
50 import org
.junit
.Test
;
51 import org
.junit
.runner
.RunWith
;
52 import org
.swtchart
.Chart
;
53 import org
.swtchart
.Range
;
56 * Tests of the density view
58 * @author Matthew Khouzam
60 @RunWith(SWTBotJunit4ClassRunner
.class)
61 public class SystemCallLatencyDensityViewTest
{
63 private static final String TRACE_TYPE
= "org.eclipse.linuxtools.lttng2.kernel.tracetype";
64 private static final String PROJECT_NAME
= "test";
65 private static final String VIEW_ID
= SystemCallLatencyDensityView
.ID
;
67 /** The Log4j logger instance. */
68 private static final Logger fLogger
= Logger
.getRootLogger();
69 private AbstractSegmentStoreDensityView fDensityView
;
70 private AbstractSegmentStoreTableViewer fDensityViewer
;
71 private Chart fDensityChart
;
77 public static void beforeClass() {
79 SWTBotUtils
.initialize();
80 Thread
.currentThread().setName("SWTBotTest");
81 /* set up for swtbot */
82 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
83 SWTBotPreferences
.KEYBOARD_LAYOUT
= "EN_US";
84 fLogger
.removeAllAppenders();
85 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender
.SYSTEM_OUT
));
86 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
87 SWTBotUtils
.closeView("welcome", bot
);
88 /* Switch perspectives */
89 SWTBotUtils
.switchToTracingPerspective();
90 /* Finish waiting for eclipse to load */
91 WaitUtils
.waitForJobs();
96 * Opens a latency table
98 * @throws SecurityException
99 * If a security manager is present and any the wrong class is
100 * loaded or the class loader is not the same as its ancestor's
103 * @throws NoSuchFieldException
104 * Field not available
105 * @throws IllegalAccessException
106 * Field is inaccessible
107 * @throws IllegalArgumentException
108 * the object is not the correct class type
113 public void createDensityViewer() throws NoSuchFieldException
, SecurityException
, IllegalArgumentException
, IllegalAccessException
{
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 SystemCallLatencyDensityView
)) {
129 fail("Could not instanciate view");
131 fDensityView
= (SystemCallLatencyDensityView
) viewPart
;
134 * Use reflection to access the table viewer
136 final Field field
= AbstractSegmentStoreDensityView
.class.getDeclaredField("fTableViewer");
137 field
.setAccessible(true);
138 fDensityViewer
= (AbstractSegmentStoreTableViewer
) field
.get(fDensityView
);
139 fDensityChart
= viewBot
.bot().widget(WidgetOfType
.widgetOfType(Chart
.class));
140 assertNotNull(fDensityViewer
);
147 public void closeDensityViewer() {
148 final SWTWorkbenchBot swtWorkbenchBot
= new SWTWorkbenchBot();
149 SWTBotView viewBot
= swtWorkbenchBot
.viewById(VIEW_ID
);
154 * Test with an actual trace, this is more of an integration test than a
155 * unit test. This test is a slow one too. If some analyses are not well
156 * configured, this test will also generates null pointer exceptions. These
159 * @throws IOException
161 * @throws SecurityException
162 * If a security manager is present and any the wrong class is
163 * loaded or the class loader is not the same as its ancestor's
166 * @throws NoSuchFieldException
167 * Field not available
168 * @throws IllegalAccessException
169 * Field is inaccessible
170 * @throws IllegalArgumentException
171 * the object is not the correct class type
175 public void testWithTrace() throws IOException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, IllegalAccessException
{
177 tracePath
= FileLocator
.toFileURL(CtfTestTrace
.ARM_64_BIT_HEADER
.getTraceURL()).getPath();
178 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
179 SWTBotView view
= bot
.viewById(VIEW_ID
);
181 bot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
182 SWTBotUtils
.createProject(PROJECT_NAME
);
183 SWTBotUtils
.openTrace(PROJECT_NAME
, tracePath
, TRACE_TYPE
);
184 WaitUtils
.waitForJobs();
185 createDensityViewer();
186 WaitUtils
.waitForJobs();
187 SWTBotTable tableBot
= new SWTBotTable(fDensityViewer
.getTableViewer().getTable());
188 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "1,600", 0, 2));
189 tableBot
.header("Duration").click();
190 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "1,600", 0, 2));
191 tableBot
.header("Duration").click();
192 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "1,001,046,400", 0, 2));
193 final Chart densityChart
= fDensityChart
;
194 assertNotNull(densityChart
);
195 bot
.waitUntil(ConditionHelpers
.numberOfSeries(densityChart
, 1));
197 SWTBotChart chartBot
= new SWTBotChart(densityChart
);
198 assertVisible(chartBot
);
199 assertEquals("", chartBot
.getToolTipText());
200 final Range range
= densityChart
.getAxisSet().getXAxes()[0].getRange();
201 assertTrue(0 > range
.lower
);
202 assertTrue(1001046400 < range
.upper
);
203 bot
.closeAllEditors();
204 SWTBotUtils
.deleteProject(PROJECT_NAME
, bot
);
207 private static class SWTBotChart
extends AbstractSWTBotControl
<Chart
> {
208 public SWTBotChart(Chart w
) throws WidgetNotFoundException
{