1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.analysis
.os
.linux
.ui
.swtbot
.tests
.latency
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assert
.fail
;
18 import java
.io
.IOException
;
19 import java
.util
.ArrayList
;
20 import java
.util
.Collections
;
21 import java
.util
.List
;
22 import java
.util
.Random
;
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
.jdt
.annotation
.NonNull
;
29 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
30 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
31 import org
.eclipse
.swtbot
.swt
.finder
.SWTBot
;
32 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
33 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
34 import org
.eclipse
.swtbot
.swt
.finder
.results
.BoolResult
;
35 import org
.eclipse
.swtbot
.swt
.finder
.results
.Result
;
36 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
37 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
38 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.latency
.SystemCall
;
39 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.latency
.SystemCall
.InitialInfo
;
40 import org
.eclipse
.tracecompass
.analysis
.timing
.ui
.views
.segmentstore
.table
.AbstractSegmentStoreTableViewer
;
41 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.views
.latency
.SystemCallLatencyView
;
42 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
43 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
44 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
45 import org
.eclipse
.ui
.IViewPart
;
46 import org
.eclipse
.ui
.IViewReference
;
47 import org
.eclipse
.ui
.PlatformUI
;
48 import org
.eclipse
.ui
.WorkbenchException
;
49 import org
.junit
.After
;
50 import org
.junit
.Before
;
51 import org
.junit
.BeforeClass
;
52 import org
.junit
.Test
;
53 import org
.junit
.runner
.RunWith
;
56 * Tests of the latency table
58 * @author Matthew Khouzam
60 @RunWith(SWTBotJunit4ClassRunner
.class)
61 public class SystemCallLatencyTableAnalysisTest
{
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
= SystemCallLatencyView
.ID
;
66 private static final String TRACING_PERSPECTIVE_ID
= "org.eclipse.linuxtools.tmf.ui.perspective";
68 /** The Log4j logger instance. */
69 private static final Logger fLogger
= Logger
.getRootLogger();
70 private SystemCallLatencyView fLatencyView
;
71 private AbstractSegmentStoreTableViewer fTable
;
77 public static void beforeClass() {
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")) {
91 bot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
94 /* Switch perspectives */
95 switchTracingPerspective();
96 /* Finish waiting for eclipse to load */
97 SWTBotUtils
.waitForJobs();
102 * Opens a latency table
105 public void createTable() {
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
>() {
115 public IViewPart
run() {
116 return viewReference
.getView(true);
119 assertNotNull(viewPart
);
120 if (!(viewPart
instanceof SystemCallLatencyView
)) {
121 fail("Could not instanciate view");
123 fLatencyView
= (SystemCallLatencyView
) viewPart
;
124 fTable
= fLatencyView
.getSegmentStoreViewer();
125 assertNotNull(fTable
);
132 public void closeTable() {
133 final SWTWorkbenchBot swtWorkbenchBot
= new SWTWorkbenchBot();
134 SWTBotView viewBot
= swtWorkbenchBot
.viewById(VIEW_ID
);
138 private static void switchTracingPerspective() {
139 final Exception retE
[] = new Exception
[1];
140 if (!UIThreadRunnable
.syncExec(new BoolResult() {
142 public Boolean
run() {
144 PlatformUI
.getWorkbench().showPerspective(TRACING_PERSPECTIVE_ID
,
145 PlatformUI
.getWorkbench().getActiveWorkbenchWindow());
146 } catch (WorkbenchException e
) {
153 fail(retE
[0].getMessage());
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));
168 assertNotNull(fTable
);
169 fTable
.updateModel(fixture
);
170 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
171 SWTBot bot
= new SWTBot();
172 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "0", 0, 2));
173 tableBot
.header("Duration").click();
174 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "0", 0, 2));
175 tableBot
.header("Duration").click();
176 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "99", 0, 2));
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));
188 assertNotNull(fTable
);
189 fTable
.updateModel(fixture
);
190 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
191 SWTBot bot
= new SWTBot();
192 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "100", 0, 2));
193 tableBot
.header("Duration").click();
194 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "0", 0, 2));
195 tableBot
.header("Duration").click();
196 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "100", 0, 2));
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));
208 assertNotNull(fTable
);
209 fTable
.updateModel(fixture
);
210 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
211 SWTBot bot
= new SWTBot();
212 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "1", 0, 2));
213 tableBot
.header("Duration").click();
214 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "0", 0, 2));
215 tableBot
.header("Duration").click();
216 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "1", 0, 2));
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));
229 assertNotNull(fTable
);
230 fTable
.updateModel(fixture
);
231 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
232 SWTBot bot
= new SWTBot();
233 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "0", 0, 2));
234 tableBot
.header("Duration").click();
235 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "0", 0, 2));
236 tableBot
.header("Duration").click();
237 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "999999", 0, 2));
244 public void noiseTest() {
245 Random rnd
= new Random();
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));
254 assertNotNull(fTable
);
255 fTable
.updateModel(fixture
);
256 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
257 SWTBot bot
= new SWTBot();
258 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "894633", 0, 2));
259 tableBot
.header("Duration").click();
260 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "0", 0, 2));
261 tableBot
.header("Duration").click();
262 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "999999", 0, 2));
266 * Test gaussian noise
269 public void gaussianNoiseTest() {
270 Random rnd
= new Random();
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));
279 assertNotNull(fTable
);
280 fTable
.updateModel(fixture
);
281 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
282 SWTBot bot
= new SWTBot();
283 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "400689", 0, 2));
284 tableBot
.header("Duration").click();
285 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "0", 0, 2));
286 tableBot
.header("Duration").click();
287 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "998001", 0, 2));
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.
296 * @throws IOException
300 public void testWithTrace() throws IOException
{
302 tracePath
= FileLocator
.toFileURL(CtfTestTrace
.ARM_64_BIT_HEADER
.getTraceURL()).getPath();
303 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
304 SWTBotView view
= bot
.viewById(VIEW_ID
);
306 bot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
307 SWTBotUtils
.createProject(PROJECT_NAME
);
308 SWTBotUtils
.openTrace(PROJECT_NAME
, tracePath
, TRACE_TYPE
);
309 SWTBotUtils
.waitForJobs();
311 SWTBotUtils
.waitForJobs();
312 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
313 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "24100", 0, 2));
314 tableBot
.header("Duration").click();
315 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "1000", 0, 2));
316 tableBot
.header("Duration").click();
317 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "5904091700", 0, 2));
318 bot
.closeAllEditors();
319 SWTBotUtils
.deleteProject(PROJECT_NAME
, bot
);