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
.*;
18 import java
.io
.IOException
;
19 import java
.lang
.reflect
.Field
;
21 import org
.apache
.log4j
.ConsoleAppender
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.apache
.log4j
.SimpleLayout
;
24 import org
.eclipse
.core
.runtime
.FileLocator
;
25 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
26 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
27 import org
.eclipse
.swtbot
.swt
.finder
.exceptions
.WidgetNotFoundException
;
28 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
29 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
30 import org
.eclipse
.swtbot
.swt
.finder
.matchers
.WidgetOfType
;
31 import org
.eclipse
.swtbot
.swt
.finder
.results
.Result
;
32 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
33 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.AbstractSWTBotControl
;
34 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
35 import org
.eclipse
.tracecompass
.analysis
.timing
.ui
.views
.segmentstore
.density
.AbstractSegmentStoreDensityView
;
36 import org
.eclipse
.tracecompass
.analysis
.timing
.ui
.views
.segmentstore
.table
.AbstractSegmentStoreTableViewer
;
37 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.views
.latency
.SystemCallLatencyDensityView
;
38 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
39 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
40 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
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
.Range
;
52 * Tests of the density view
54 * @author Matthew Khouzam
56 @RunWith(SWTBotJunit4ClassRunner
.class)
57 public class SystemCallLatencyDensityViewTest
{
59 private static final String TRACE_TYPE
= "org.eclipse.linuxtools.lttng2.kernel.tracetype";
60 private static final String PROJECT_NAME
= "test";
61 private static final String VIEW_ID
= SystemCallLatencyDensityView
.ID
;
63 /** The Log4j logger instance. */
64 private static final Logger fLogger
= Logger
.getRootLogger();
65 private AbstractSegmentStoreDensityView fDensityView
;
66 private AbstractSegmentStoreTableViewer fDensityViewer
;
67 private Chart fDensityChart
;
73 public static void beforeClass() {
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();
92 * Opens a latency table
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
99 * @throws NoSuchFieldException
100 * Field not available
101 * @throws IllegalAccessException
102 * Field is inaccessible
103 * @throws IllegalArgumentException
104 * the object is not the correct class type
109 public void createDensityViewer() throws NoSuchFieldException
, SecurityException
, IllegalArgumentException
, IllegalAccessException
{
113 SWTBotUtils
.openView(VIEW_ID
);
114 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
115 SWTBotView viewBot
= bot
.viewById(VIEW_ID
);
116 final IViewReference viewReference
= viewBot
.getViewReference();
117 IViewPart viewPart
= UIThreadRunnable
.syncExec(new Result
<IViewPart
>() {
119 public IViewPart
run() {
120 return viewReference
.getView(true);
123 assertNotNull(viewPart
);
124 if (!(viewPart
instanceof SystemCallLatencyDensityView
)) {
125 fail("Could not instanciate view");
127 fDensityView
= (SystemCallLatencyDensityView
) viewPart
;
130 * Use reflection to access the table viewer
132 final Field field
= AbstractSegmentStoreDensityView
.class.getDeclaredField("fTableViewer");
133 field
.setAccessible(true);
134 fDensityViewer
= (AbstractSegmentStoreTableViewer
) field
.get(fDensityView
);
135 fDensityChart
= viewBot
.bot().widget(WidgetOfType
.widgetOfType(Chart
.class));
136 assertNotNull(fDensityViewer
);
143 public void closeDensityViewer() {
144 final SWTWorkbenchBot swtWorkbenchBot
= new SWTWorkbenchBot();
145 SWTBotView viewBot
= swtWorkbenchBot
.viewById(VIEW_ID
);
150 * Test with an actual trace, this is more of an integration test than a
151 * unit test. This test is a slow one too. If some analyses are not well
152 * configured, this test will also generates null pointer exceptions. These
155 * @throws IOException
157 * @throws SecurityException
158 * If a security manager is present and any the wrong class is
159 * loaded or the class loader is not the same as its ancestor's
162 * @throws NoSuchFieldException
163 * Field not available
164 * @throws IllegalAccessException
165 * Field is inaccessible
166 * @throws IllegalArgumentException
167 * the object is not the correct class type
171 public void testWithTrace() throws IOException
, NoSuchFieldException
, SecurityException
, IllegalArgumentException
, IllegalAccessException
{
173 tracePath
= FileLocator
.toFileURL(CtfTestTrace
.ARM_64_BIT_HEADER
.getTraceURL()).getPath();
174 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
175 SWTBotView view
= bot
.viewById(VIEW_ID
);
177 bot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
178 SWTBotUtils
.createProject(PROJECT_NAME
);
179 SWTBotUtils
.openTrace(PROJECT_NAME
, tracePath
, TRACE_TYPE
);
180 SWTBotUtils
.waitForJobs();
181 createDensityViewer();
182 SWTBotUtils
.waitForJobs();
183 SWTBotTable tableBot
= new SWTBotTable(fDensityViewer
.getTableViewer().getTable());
184 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "1600", 0, 2));
185 tableBot
.header("Duration").click();
186 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "1600", 0, 2));
187 tableBot
.header("Duration").click();
188 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "1001046400", 0, 2));
189 final Chart densityChart
= fDensityChart
;
190 assertNotNull(densityChart
);
191 SWTBotChart chartBot
= new SWTBotChart(densityChart
);
192 assertVisible(chartBot
);
193 assertEquals("", chartBot
.getToolTipText());
194 final Range range
= densityChart
.getAxisSet().getXAxes()[0].getRange();
195 assertTrue(0 > range
.lower
);
196 assertTrue(1001046400 < range
.upper
);
197 bot
.closeAllEditors();
198 SWTBotUtils
.deleteProject(PROJECT_NAME
, bot
);
201 private static class SWTBotChart
extends AbstractSWTBotControl
<Chart
> {
202 public SWTBotChart(Chart w
) throws WidgetNotFoundException
{