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