tmf: Add waitUntil / condition to tmf.ui.tests
[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
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
13 package org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests.latency;
14
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;
20
21 import java.io.IOException;
22 import java.lang.reflect.Field;
23
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;
54
55 /**
56 * Tests of the density view
57 *
58 * @author Matthew Khouzam
59 */
60 @RunWith(SWTBotJunit4ClassRunner.class)
61 public class SystemCallLatencyDensityViewTest {
62
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;
66
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;
72
73 /**
74 * Things to setup
75 */
76 @BeforeClass
77 public static void beforeClass() {
78
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();
92
93 }
94
95 /**
96 * Opens a latency table
97 *
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
101 * loader.
102 *
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
109 *
110 *
111 */
112 @Before
113 public void createDensityViewer() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
114 /*
115 * Open latency view
116 */
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>() {
122 @Override
123 public IViewPart run() {
124 return viewReference.getView(true);
125 }
126 });
127 assertNotNull(viewPart);
128 if (!(viewPart instanceof SystemCallLatencyDensityView)) {
129 fail("Could not instanciate view");
130 }
131 fDensityView = (SystemCallLatencyDensityView) viewPart;
132
133 /*
134 * Use reflection to access the table viewer
135 */
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);
141 }
142
143 /**
144 * Closes the view
145 */
146 @After
147 public void closeDensityViewer() {
148 final SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot();
149 SWTBotView viewBot = swtWorkbenchBot.viewById(VIEW_ID);
150 viewBot.close();
151 }
152
153 /**
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
157 * will be logged.
158 *
159 * @throws IOException
160 * trace not found?
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
164 * loader.
165 *
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
172 *
173 */
174 @Test
175 public void testWithTrace() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
176 String tracePath;
177 tracePath = FileLocator.toFileURL(CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL()).getPath();
178 SWTWorkbenchBot bot = new SWTWorkbenchBot();
179 SWTBotView view = bot.viewById(VIEW_ID);
180 view.close();
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));
196
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);
205 }
206
207 private static class SWTBotChart extends AbstractSWTBotControl<Chart> {
208 public SWTBotChart(Chart w) throws WidgetNotFoundException {
209 super(w);
210 }
211 }
212 }
This page took 0.038418 seconds and 5 git commands to generate.