analysis: Move timing analysis ui classes in own java packages
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests / src / org / eclipse / tracecompass / analysis / os / linux / ui / swtbot / tests / latency / SystemCallLatencyDensityViewTest.java
CommitLineData
3162c616
MK
1/*******************************************************************************
2 * Copyright (c) 2016 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests.latency;
14
c6dd173d
MK
15import static org.eclipse.swtbot.swt.finder.SWTBotAssert.assertVisible;
16import static org.junit.Assert.*;
3162c616
MK
17
18import java.io.IOException;
19import java.lang.reflect.Field;
20
21import org.apache.log4j.ConsoleAppender;
22import org.apache.log4j.Logger;
23import org.apache.log4j.SimpleLayout;
24import org.eclipse.core.runtime.FileLocator;
25import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
26import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
c6dd173d 27import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
3162c616
MK
28import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
29import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
c6dd173d 30import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
3162c616
MK
31import org.eclipse.swtbot.swt.finder.results.Result;
32import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
c6dd173d 33import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
3162c616 34import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
3162c616 35import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.density.AbstractSegmentStoreDensityView;
edded5c1 36import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.table.AbstractSegmentStoreTableViewer;
3162c616
MK
37import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.SystemCallLatencyDensityView;
38import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
39import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
40import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
41import org.eclipse.ui.IViewPart;
42import org.eclipse.ui.IViewReference;
43import org.junit.After;
44import org.junit.Before;
45import org.junit.BeforeClass;
46import org.junit.Test;
47import org.junit.runner.RunWith;
c6dd173d
MK
48import org.swtchart.Chart;
49import org.swtchart.Range;
3162c616
MK
50
51/**
52 * Tests of the density view
53 *
54 * @author Matthew Khouzam
55 */
56@RunWith(SWTBotJunit4ClassRunner.class)
57public class SystemCallLatencyDensityViewTest {
58
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;
62
63 /** The Log4j logger instance. */
64 private static final Logger fLogger = Logger.getRootLogger();
65 private AbstractSegmentStoreDensityView fDensityView;
66 private AbstractSegmentStoreTableViewer fDensityViewer;
c6dd173d 67 private Chart fDensityChart;
3162c616
MK
68
69 /**
70 * Things to setup
71 */
72 @BeforeClass
73 public static void beforeClass() {
74
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();
88
89 }
90
91 /**
92 * Opens a latency table
93 *
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
97 * loader.
98 *
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
105 *
106 *
107 */
108 @Before
109 public void createDensityViewer() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
110 /*
111 * Open latency view
112 */
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>() {
118 @Override
119 public IViewPart run() {
120 return viewReference.getView(true);
121 }
122 });
123 assertNotNull(viewPart);
124 if (!(viewPart instanceof SystemCallLatencyDensityView)) {
125 fail("Could not instanciate view");
126 }
127 fDensityView = (SystemCallLatencyDensityView) viewPart;
128
129 /*
130 * Use reflection to access the table viewer
131 */
132 final Field field = AbstractSegmentStoreDensityView.class.getDeclaredField("fTableViewer");
133 field.setAccessible(true);
134 fDensityViewer = (AbstractSegmentStoreTableViewer) field.get(fDensityView);
c6dd173d 135 fDensityChart = viewBot.bot().widget(WidgetOfType.widgetOfType(Chart.class));
3162c616
MK
136 assertNotNull(fDensityViewer);
137 }
138
139 /**
140 * Closes the view
141 */
142 @After
143 public void closeDensityViewer() {
144 final SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot();
145 SWTBotView viewBot = swtWorkbenchBot.viewById(VIEW_ID);
146 viewBot.close();
147 }
148
149 /**
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
153 * will be logged.
154 *
155 * @throws IOException
156 * trace not found?
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
160 * loader.
161 *
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
168 *
169 */
170 @Test
171 public void testWithTrace() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
172 String tracePath;
173 tracePath = FileLocator.toFileURL(CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL()).getPath();
174 SWTWorkbenchBot bot = new SWTWorkbenchBot();
175 SWTBotView view = bot.viewById(VIEW_ID);
176 view.close();
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));
c6dd173d
MK
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);
3162c616
MK
197 bot.closeAllEditors();
198 SWTBotUtils.deleteProject(PROJECT_NAME, bot);
199 }
c6dd173d
MK
200
201 private static class SWTBotChart extends AbstractSWTBotControl<Chart> {
202 public SWTBotChart(Chart w) throws WidgetNotFoundException {
203 super(w);
204 }
205 }
3162c616 206}
This page took 0.033481 seconds and 5 git commands to generate.