f952178b4d6bbd2c47b22bb9313337a876ee47f1
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests / src / org / eclipse / tracecompass / analysis / os / linux / ui / swtbot / tests / latency / SystemCallLatencyTableAnalysisTest.java
1 /*******************************************************************************
2 * Copyright (c) 2015, 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.junit.Assert.assertNotNull;
16 import static org.junit.Assert.fail;
17
18 import java.io.IOException;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Random;
22
23 import org.apache.log4j.ConsoleAppender;
24 import org.apache.log4j.Logger;
25 import org.apache.log4j.SimpleLayout;
26 import org.eclipse.core.runtime.FileLocator;
27 import org.eclipse.jdt.annotation.NonNull;
28 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
29 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
30 import org.eclipse.swtbot.swt.finder.SWTBot;
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.results.BoolResult;
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.SWTBotTable;
37 import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.table.AbstractSegmentStoreTableViewer;
38 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.SystemCallLatencyView;
39 import org.eclipse.tracecompass.segmentstore.core.BasicSegment;
40 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
41 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
42 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
43 import org.eclipse.ui.IViewPart;
44 import org.eclipse.ui.IViewReference;
45 import org.eclipse.ui.PlatformUI;
46 import org.eclipse.ui.WorkbenchException;
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
53 /**
54 * Tests of the latency table
55 *
56 * @author Matthew Khouzam
57 */
58 @RunWith(SWTBotJunit4ClassRunner.class)
59 public class SystemCallLatencyTableAnalysisTest {
60
61 private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype";
62 private static final String PROJECT_NAME = "test";
63 private static final String VIEW_ID = SystemCallLatencyView.ID;
64 private static final String TRACING_PERSPECTIVE_ID = "org.eclipse.linuxtools.tmf.ui.perspective";
65
66 /** The Log4j logger instance. */
67 private static final Logger fLogger = Logger.getRootLogger();
68 private SystemCallLatencyView fLatencyView;
69 private AbstractSegmentStoreTableViewer fTable;
70
71 /**
72 * Things to setup
73 */
74 @BeforeClass
75 public static void beforeClass() {
76
77 SWTBotUtils.initialize();
78 Thread.currentThread().setName("SWTBotTest");
79 /* set up for swtbot */
80 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
81 SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
82 fLogger.removeAllAppenders();
83 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
84 SWTWorkbenchBot bot = new SWTWorkbenchBot();
85 final List<SWTBotView> openViews = bot.views();
86 for (SWTBotView view : openViews) {
87 if (view.getTitle().equals("Welcome")) {
88 view.close();
89 bot.waitUntil(ConditionHelpers.ViewIsClosed(view));
90 }
91 }
92 /* Switch perspectives */
93 switchTracingPerspective();
94 /* Finish waiting for eclipse to load */
95 SWTBotUtils.waitForJobs();
96
97 }
98
99 /**
100 * Opens a latency table
101 */
102 @Before
103 public void createTable() {
104 /*
105 * Open latency view
106 */
107 SWTBotUtils.openView(VIEW_ID);
108 SWTWorkbenchBot bot = new SWTWorkbenchBot();
109 SWTBotView viewBot = bot.viewById(VIEW_ID);
110 final IViewReference viewReference = viewBot.getViewReference();
111 IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() {
112 @Override
113 public IViewPart run() {
114 return viewReference.getView(true);
115 }
116 });
117 assertNotNull(viewPart);
118 if (!(viewPart instanceof SystemCallLatencyView)) {
119 fail("Could not instanciate view");
120 }
121 fLatencyView = (SystemCallLatencyView) viewPart;
122 fTable = fLatencyView.getSegmentStoreViewer();
123 assertNotNull(fTable);
124 }
125
126 /**
127 * Closes the view
128 */
129 @After
130 public void closeTable() {
131 final SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot();
132 SWTBotView viewBot = swtWorkbenchBot.viewById(VIEW_ID);
133 viewBot.close();
134 }
135
136 private static void switchTracingPerspective() {
137 final Exception retE[] = new Exception[1];
138 if (!UIThreadRunnable.syncExec(new BoolResult() {
139 @Override
140 public Boolean run() {
141 try {
142 PlatformUI.getWorkbench().showPerspective(TRACING_PERSPECTIVE_ID,
143 PlatformUI.getWorkbench().getActiveWorkbenchWindow());
144 } catch (WorkbenchException e) {
145 retE[0] = e;
146 return false;
147 }
148 return true;
149 }
150 })) {
151 fail(retE[0].getMessage());
152 }
153
154 }
155
156 /**
157 * Test incrementing
158 */
159 @Test
160 public void climbTest() {
161 List<@NonNull BasicSegment> fixture = new ArrayList<>();
162 for (int i = 0; i < 100; i++) {
163 fixture.add(new BasicSegment(i, 2 * i));
164 }
165
166 assertNotNull(fTable);
167 fTable.updateModel(fixture);
168 SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable());
169 SWTBot bot = new SWTBot();
170 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
171 tableBot.header("Duration").click();
172 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
173 tableBot.header("Duration").click();
174 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "99", 0, 2));
175 }
176
177 /**
178 * Test decrementing
179 */
180 @Test
181 public void decrementingTest() {
182 List<@NonNull BasicSegment> fixture = new ArrayList<>();
183 for (int i = 100; i >= 0; i--) {
184 fixture.add(new BasicSegment(i, 2 * i));
185 }
186 assertNotNull(fTable);
187 fTable.updateModel(fixture);
188 SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable());
189 SWTBot bot = new SWTBot();
190 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "100", 0, 2));
191 tableBot.header("Duration").click();
192 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
193 tableBot.header("Duration").click();
194 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "100", 0, 2));
195 }
196
197 /**
198 * Test small table
199 */
200 @Test
201 public void smallTest() {
202 List<@NonNull BasicSegment> fixture = new ArrayList<>();
203 for (int i = 1; i >= 0; i--) {
204 fixture.add(new BasicSegment(i, 2 * i));
205 }
206 assertNotNull(fTable);
207 fTable.updateModel(fixture);
208 SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable());
209 SWTBot bot = new SWTBot();
210 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1", 0, 2));
211 tableBot.header("Duration").click();
212 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
213 tableBot.header("Duration").click();
214 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1", 0, 2));
215 }
216
217 /**
218 * Test large
219 */
220 @Test
221 public void largeTest() {
222 final int size = 1000000;
223 BasicSegment[] fixture = new BasicSegment[size];
224 for (int i = 0; i < size; i++) {
225 fixture[i] = (new BasicSegment(i, 2 * i));
226 }
227 assertNotNull(fTable);
228 fTable.updateModel(fixture);
229 SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable());
230 SWTBot bot = new SWTBot();
231 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
232 tableBot.header("Duration").click();
233 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
234 tableBot.header("Duration").click();
235 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "999,999", 0, 2));
236 }
237
238 /**
239 * Test noise
240 */
241 @Test
242 public void noiseTest() {
243 Random rnd = new Random();
244 rnd.setSeed(1234);
245 final int size = 1000000;
246 BasicSegment[] fixture = new BasicSegment[size];
247 for (int i = 0; i < size; i++) {
248 int start = Math.abs(rnd.nextInt(100000000));
249 int end = start + Math.abs(rnd.nextInt(1000000));
250 fixture[i] = (new BasicSegment(start, end));
251 }
252 assertNotNull(fTable);
253 fTable.updateModel(fixture);
254 SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable());
255 SWTBot bot = new SWTBot();
256 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "894,633", 0, 2));
257 tableBot.header("Duration").click();
258 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
259 tableBot.header("Duration").click();
260 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "999,999", 0, 2));
261 }
262
263 /**
264 * Test gaussian noise
265 */
266 @Test
267 public void gaussianNoiseTest() {
268 Random rnd = new Random();
269 rnd.setSeed(1234);
270 List<@NonNull BasicSegment> fixture = new ArrayList<>();
271 for (int i = 1; i <= 1000000; i++) {
272 int start = Math.abs(rnd.nextInt(100000000));
273 final int delta = Math.abs(rnd.nextInt(1000));
274 int end = start + delta * delta;
275 fixture.add(new BasicSegment(start, end));
276 }
277 assertNotNull(fTable);
278 fTable.updateModel(fixture);
279 SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable());
280 SWTBot bot = new SWTBot();
281 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "400,689", 0, 2));
282 tableBot.header("Duration").click();
283 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
284 tableBot.header("Duration").click();
285 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "998,001", 0, 2));
286 }
287
288 /**
289 * Test with an actual trace, this is more of an integration test than a
290 * unit test. This test is a slow one too. If some analyses are not well
291 * configured, this test will also generates null pointer exceptions. These
292 * are will be logged.
293 *
294 * @throws IOException
295 * trace not found?
296 */
297 @Test
298 public void testWithTrace() throws IOException {
299 String tracePath;
300 tracePath = FileLocator.toFileURL(CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL()).getPath();
301 SWTWorkbenchBot bot = new SWTWorkbenchBot();
302 SWTBotView view = bot.viewById(VIEW_ID);
303 view.close();
304 bot.waitUntil(ConditionHelpers.ViewIsClosed(view));
305 SWTBotUtils.createProject(PROJECT_NAME);
306 SWTBotUtils.openTrace(PROJECT_NAME, tracePath, TRACE_TYPE);
307 SWTBotUtils.waitForJobs();
308 createTable();
309 SWTBotUtils.waitForJobs();
310 SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable());
311 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "24,100", 0, 2));
312 tableBot.header("Duration").click();
313 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1,000", 0, 2));
314 tableBot.header("Duration").click();
315 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "5,904,091,700", 0, 2));
316 bot.closeAllEditors();
317 SWTBotUtils.deleteProject(PROJECT_NAME, bot);
318 }
319 }
This page took 0.037079 seconds and 4 git commands to generate.