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
.List
;
21 import java
.util
.Random
;
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
;
54 * Tests of the latency table
56 * @author Matthew Khouzam
58 @RunWith(SWTBotJunit4ClassRunner
.class)
59 public class SystemCallLatencyTableAnalysisTest
{
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";
66 /** The Log4j logger instance. */
67 private static final Logger fLogger
= Logger
.getRootLogger();
68 private SystemCallLatencyView fLatencyView
;
69 private AbstractSegmentStoreTableViewer fTable
;
75 public static void beforeClass() {
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")) {
89 bot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
92 /* Switch perspectives */
93 switchTracingPerspective();
94 /* Finish waiting for eclipse to load */
95 SWTBotUtils
.waitForJobs();
100 * Opens a latency table
103 public void createTable() {
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
>() {
113 public IViewPart
run() {
114 return viewReference
.getView(true);
117 assertNotNull(viewPart
);
118 if (!(viewPart
instanceof SystemCallLatencyView
)) {
119 fail("Could not instanciate view");
121 fLatencyView
= (SystemCallLatencyView
) viewPart
;
122 fTable
= fLatencyView
.getSegmentStoreViewer();
123 assertNotNull(fTable
);
130 public void closeTable() {
131 final SWTWorkbenchBot swtWorkbenchBot
= new SWTWorkbenchBot();
132 SWTBotView viewBot
= swtWorkbenchBot
.viewById(VIEW_ID
);
136 private static void switchTracingPerspective() {
137 final Exception retE
[] = new Exception
[1];
138 if (!UIThreadRunnable
.syncExec(new BoolResult() {
140 public Boolean
run() {
142 PlatformUI
.getWorkbench().showPerspective(TRACING_PERSPECTIVE_ID
,
143 PlatformUI
.getWorkbench().getActiveWorkbenchWindow());
144 } catch (WorkbenchException e
) {
151 fail(retE
[0].getMessage());
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
));
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));
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
));
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));
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
));
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));
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
));
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
, "999999", 0, 2));
242 public void noiseTest() {
243 Random rnd
= new Random();
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
));
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
, "894633", 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
, "999999", 0, 2));
264 * Test gaussian noise
267 public void gaussianNoiseTest() {
268 Random rnd
= new Random();
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
));
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
, "400689", 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
, "998001", 0, 2));
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.
294 * @throws IOException
298 public void testWithTrace() throws IOException
{
300 tracePath
= FileLocator
.toFileURL(CtfTestTrace
.ARM_64_BIT_HEADER
.getTraceURL()).getPath();
301 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
302 SWTBotView view
= bot
.viewById(VIEW_ID
);
304 bot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
305 SWTBotUtils
.createProject(PROJECT_NAME
);
306 SWTBotUtils
.openTrace(PROJECT_NAME
, tracePath
, TRACE_TYPE
);
307 SWTBotUtils
.waitForJobs();
309 SWTBotUtils
.waitForJobs();
310 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
311 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "24100", 0, 2));
312 tableBot
.header("Duration").click();
313 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "1000", 0, 2));
314 tableBot
.header("Duration").click();
315 bot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, "5904091700", 0, 2));
316 bot
.closeAllEditors();
317 SWTBotUtils
.deleteProject(PROJECT_NAME
, bot
);