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
.ui
.IViewPart
;
45 import org
.eclipse
.ui
.IViewReference
;
46 import org
.junit
.After
;
47 import org
.junit
.Before
;
48 import org
.junit
.BeforeClass
;
49 import org
.junit
.Test
;
50 import org
.junit
.runner
.RunWith
;
51 import org
.swtchart
.Chart
;
52 import org
.swtchart
.Range
;
55 * Tests of the density view
57 * @author Matthew Khouzam
59 @RunWith(SWTBotJunit4ClassRunner
.class)
60 public class SystemCallLatencyDensityViewTest
{
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
= SystemCallLatencyDensityView
.ID
;
66 /** The Log4j logger instance. */
67 private static final Logger fLogger
= Logger
.getRootLogger();
68 private AbstractSegmentStoreDensityView fDensityView
;
69 private AbstractSegmentStoreTableViewer fDensityViewer
;
70 private Chart fDensityChart
;
76 public static void beforeClass() {
78 SWTBotUtils
.initialize();
79 Thread
.currentThread().setName("SWTBotTest");
80 /* set up for swtbot */
81 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
82 SWTBotPreferences
.KEYBOARD_LAYOUT
= "EN_US";
83 fLogger
.removeAllAppenders();
84 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender
.SYSTEM_OUT
));
85 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
86 SWTBotUtils
.closeView("welcome", bot
);
87 /* Switch perspectives */
88 SWTBotUtils
.switchToTracingPerspective();
89 /* Finish waiting for eclipse to load */
90 SWTBotUtils
.waitForJobs();
95 * Opens a latency table
97 * @throws SecurityException
98 * If a security manager is present and any the wrong class is
99 * loaded or the class loader is not the same as its ancestor's
102 * @throws NoSuchFieldException
103 * Field not available
104 * @throws IllegalAccessException
105 * Field is inaccessible
106 * @throws IllegalArgumentException
107 * the object is not the correct class type
112 public void createDensityViewer() throws NoSuchFieldException
, SecurityException
, IllegalArgumentException
, IllegalAccessException
{
116 SWTBotUtils
.openView(VIEW_ID
);
117 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
118 SWTBotView viewBot
= bot
.viewById(VIEW_ID
);
119 final IViewReference viewReference
= viewBot
.getViewReference();
120 IViewPart viewPart
= UIThreadRunnable
.syncExec(new Result
<IViewPart
>() {
122 public IViewPart
run() {
123 return viewReference
.getView(true);
126 assertNotNull(viewPart
);
127 if (!(viewPart
instanceof SystemCallLatencyDensityView
)) {
128 fail("Could not instanciate view");
130 fDensityView
= (SystemCallLatencyDensityView
) viewPart
;
133 * Use reflection to access the table viewer
135 final Field field
= AbstractSegmentStoreDensityView
.class.getDeclaredField("fTableViewer");
136 field
.setAccessible(true);
137 fDensityViewer
= (AbstractSegmentStoreTableViewer
) field
.get(fDensityView
);
138 fDensityChart
= viewBot
.bot().widget(WidgetOfType
.widgetOfType(Chart
.class));
139 assertNotNull(fDensityViewer
);
146 public void closeDensityViewer() {
147 final SWTWorkbenchBot swtWorkbenchBot
= new SWTWorkbenchBot();
148 SWTBotView viewBot
= swtWorkbenchBot
.viewById(VIEW_ID
);
153 * Test with an actual trace, this is more of an integration test than a
154 * unit test. This test is a slow one too. If some analyses are not well
155 * configured, this test will also generates null pointer exceptions. These
158 * @throws IOException
160 * @throws SecurityException
161 * If a security manager is present and any the wrong class is
162 * loaded or the class loader is not the same as its ancestor's
165 * @throws NoSuchFieldException
166 * Field not available
167 * @throws IllegalAccessException
168 * Field is inaccessible
169 * @throws IllegalArgumentException
170 * the object is not the correct class type
174 public void testWithTrace() throws IOException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, IllegalAccessException
{
176 tracePath
= FileLocator
.toFileURL(CtfTestTrace
.ARM_64_BIT_HEADER
.getTraceURL()).getPath();
177 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
178 SWTBotView view
= bot
.viewById(VIEW_ID
);
180 bot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
181 SWTBotUtils
.createProject(PROJECT_NAME
);
182 SWTBotUtils
.openTrace(PROJECT_NAME
, tracePath
, TRACE_TYPE
);
183 SWTBotUtils
.waitForJobs();
184 createDensityViewer();
185 SWTBotUtils
.waitForJobs();
186 SWTBotTable tableBot
= new SWTBotTable(fDensityViewer
.getTableViewer().getTable());
187 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "1,600", 0, 2));
188 tableBot
.header("Duration").click();
189 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "1,600", 0, 2));
190 tableBot
.header("Duration").click();
191 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "1,001,046,400", 0, 2));
192 final Chart densityChart
= fDensityChart
;
193 assertNotNull(densityChart
);
194 bot
.waitUntil(ConditionHelpers
.numberOfSeries(densityChart
, 1));
196 SWTBotChart chartBot
= new SWTBotChart(densityChart
);
197 assertVisible(chartBot
);
198 assertEquals("", chartBot
.getToolTipText());
199 final Range range
= densityChart
.getAxisSet().getXAxes()[0].getRange();
200 assertTrue(0 > range
.lower
);
201 assertTrue(1001046400 < range
.upper
);
202 bot
.closeAllEditors();
203 SWTBotUtils
.deleteProject(PROJECT_NAME
, bot
);
206 private static class SWTBotChart
extends AbstractSWTBotControl
<Chart
> {
207 public SWTBotChart(Chart w
) throws WidgetNotFoundException
{