linux.core: internalize System Call Analysis
[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 1/*******************************************************************************
edded5c1 2 * Copyright (c) 2015, 2016 Ericsson
b70c55af
MK
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 19import java.util.ArrayList;
94d1ce7d
MK
20import java.util.List;
21import java.util.Random;
22
23import org.apache.log4j.ConsoleAppender;
24import org.apache.log4j.Logger;
25import org.apache.log4j.SimpleLayout;
973f89f2 26import org.eclipse.core.runtime.FileLocator;
94d1ce7d
MK
27import org.eclipse.jdt.annotation.NonNull;
28import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
29import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
e92fbda6 30import org.eclipse.swtbot.swt.finder.SWTBot;
94d1ce7d 31import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
b70c55af 32import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
94d1ce7d
MK
33import org.eclipse.swtbot.swt.finder.results.BoolResult;
34import org.eclipse.swtbot.swt.finder.results.Result;
35import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
36import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
edded5c1 37import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.table.AbstractSegmentStoreTableViewer;
94d1ce7d 38import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.SystemCallLatencyView;
660d4ed9 39import org.eclipse.tracecompass.segmentstore.core.BasicSegment;
973f89f2 40import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
94d1ce7d
MK
41import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
42import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
43import org.eclipse.ui.IViewPart;
44import org.eclipse.ui.IViewReference;
45import org.eclipse.ui.PlatformUI;
46import org.eclipse.ui.WorkbenchException;
47import org.junit.After;
48import org.junit.Before;
49import org.junit.BeforeClass;
b70c55af
MK
50import org.junit.Test;
51import org.junit.runner.RunWith;
52
53/**
54 * Tests of the latency table
94d1ce7d 55 *
b70c55af
MK
56 * @author Matthew Khouzam
57 */
58@RunWith(SWTBotJunit4ClassRunner.class)
59public class SystemCallLatencyTableAnalysisTest {
60
973f89f2
MK
61 private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype";
62 private static final String PROJECT_NAME = "test";
94d1ce7d
MK
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() {
660d4ed9 161 List<@NonNull BasicSegment> fixture = new ArrayList<>();
94d1ce7d 162 for (int i = 0; i < 100; i++) {
660d4ed9 163 fixture.add(new BasicSegment(i, 2 * i));
94d1ce7d
MK
164 }
165
166 assertNotNull(fTable);
167 fTable.updateModel(fixture);
168 SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable());
e92fbda6
MAL
169 SWTBot bot = new SWTBot();
170 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
94d1ce7d 171 tableBot.header("Duration").click();
e92fbda6 172 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
94d1ce7d 173 tableBot.header("Duration").click();
e92fbda6 174 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "99", 0, 2));
94d1ce7d
MK
175 }
176
177 /**
178 * Test decrementing
179 */
180 @Test
181 public void decrementingTest() {
660d4ed9 182 List<@NonNull BasicSegment> fixture = new ArrayList<>();
94d1ce7d 183 for (int i = 100; i >= 0; i--) {
660d4ed9 184 fixture.add(new BasicSegment(i, 2 * i));
94d1ce7d
MK
185 }
186 assertNotNull(fTable);
187 fTable.updateModel(fixture);
188 SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable());
e92fbda6
MAL
189 SWTBot bot = new SWTBot();
190 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "100", 0, 2));
94d1ce7d 191 tableBot.header("Duration").click();
e92fbda6 192 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
94d1ce7d 193 tableBot.header("Duration").click();
e92fbda6 194 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "100", 0, 2));
94d1ce7d
MK
195 }
196
197 /**
198 * Test small table
199 */
200 @Test
201 public void smallTest() {
660d4ed9 202 List<@NonNull BasicSegment> fixture = new ArrayList<>();
94d1ce7d 203 for (int i = 1; i >= 0; i--) {
660d4ed9 204 fixture.add(new BasicSegment(i, 2 * i));
94d1ce7d
MK
205 }
206 assertNotNull(fTable);
207 fTable.updateModel(fixture);
208 SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable());
e92fbda6
MAL
209 SWTBot bot = new SWTBot();
210 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1", 0, 2));
94d1ce7d 211 tableBot.header("Duration").click();
e92fbda6 212 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
94d1ce7d 213 tableBot.header("Duration").click();
e92fbda6 214 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1", 0, 2));
94d1ce7d
MK
215 }
216
217 /**
218 * Test large
219 */
220 @Test
221 public void largeTest() {
222 final int size = 1000000;
660d4ed9 223 BasicSegment[] fixture = new BasicSegment[size];
94d1ce7d 224 for (int i = 0; i < size; i++) {
660d4ed9 225 fixture[i] = (new BasicSegment(i, 2 * i));
94d1ce7d
MK
226 }
227 assertNotNull(fTable);
228 fTable.updateModel(fixture);
229 SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable());
e92fbda6
MAL
230 SWTBot bot = new SWTBot();
231 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
94d1ce7d 232 tableBot.header("Duration").click();
e92fbda6 233 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
94d1ce7d 234 tableBot.header("Duration").click();
e92fbda6 235 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "999999", 0, 2));
94d1ce7d
MK
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;
660d4ed9 246 BasicSegment[] fixture = new BasicSegment[size];
94d1ce7d
MK
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));
660d4ed9 250 fixture[i] = (new BasicSegment(start, end));
94d1ce7d
MK
251 }
252 assertNotNull(fTable);
253 fTable.updateModel(fixture);
254 SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable());
e92fbda6
MAL
255 SWTBot bot = new SWTBot();
256 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "894633", 0, 2));
94d1ce7d 257 tableBot.header("Duration").click();
e92fbda6 258 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
94d1ce7d 259 tableBot.header("Duration").click();
e92fbda6 260 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "999999", 0, 2));
94d1ce7d
MK
261 }
262
b70c55af 263 /**
94d1ce7d 264 * Test gaussian noise
b70c55af
MK
265 */
266 @Test
94d1ce7d
MK
267 public void gaussianNoiseTest() {
268 Random rnd = new Random();
269 rnd.setSeed(1234);
660d4ed9 270 List<@NonNull BasicSegment> fixture = new ArrayList<>();
94d1ce7d
MK
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;
660d4ed9 275 fixture.add(new BasicSegment(start, end));
94d1ce7d
MK
276 }
277 assertNotNull(fTable);
278 fTable.updateModel(fixture);
279 SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable());
e92fbda6
MAL
280 SWTBot bot = new SWTBot();
281 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "400689", 0, 2));
94d1ce7d 282 tableBot.header("Duration").click();
e92fbda6 283 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
94d1ce7d 284 tableBot.header("Duration").click();
e92fbda6 285 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "998001", 0, 2));
b70c55af
MK
286 }
287
973f89f2
MK
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());
e92fbda6 311 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "24100", 0, 2));
973f89f2 312 tableBot.header("Duration").click();
e92fbda6 313 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1000", 0, 2));
973f89f2 314 tableBot.header("Duration").click();
e92fbda6 315 bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "5904091700", 0, 2));
973f89f2
MK
316 bot.closeAllEditors();
317 SWTBotUtils.deleteProject(PROJECT_NAME, bot);
318 }
b70c55af 319}
This page took 0.04614 seconds and 5 git commands to generate.