1 /*******************************************************************************
2 * Copyright (c) 2015 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
.assertEquals
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.fail
;
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
.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
.finders
.UIThreadRunnable
;
31 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
32 import org
.eclipse
.swtbot
.swt
.finder
.results
.BoolResult
;
33 import org
.eclipse
.swtbot
.swt
.finder
.results
.Result
;
34 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
35 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
36 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.latency
.SystemCall
;
37 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.latency
.SystemCall
.InitialInfo
;
38 import org
.eclipse
.tracecompass
.analysis
.timing
.ui
.views
.segmentstore
.AbstractSegmentStoreTableViewer
;
39 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.views
.latency
.SystemCallLatencyView
;
40 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
41 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
42 import org
.eclipse
.ui
.IViewPart
;
43 import org
.eclipse
.ui
.IViewReference
;
44 import org
.eclipse
.ui
.PlatformUI
;
45 import org
.eclipse
.ui
.WorkbenchException
;
46 import org
.junit
.After
;
47 import org
.junit
.Before
;
48 import org
.junit
.BeforeClass
;
49 import org
.junit
.Test
;
50 import org
.junit
.runner
.RunWith
;
53 * Tests of the latency table
55 * @author Matthew Khouzam
57 @RunWith(SWTBotJunit4ClassRunner
.class)
58 public class SystemCallLatencyTableAnalysisTest
{
60 private static final String VIEW_ID
= SystemCallLatencyView
.ID
;
61 private static final String TRACING_PERSPECTIVE_ID
= "org.eclipse.linuxtools.tmf.ui.perspective";
63 /** The Log4j logger instance. */
64 private static final Logger fLogger
= Logger
.getRootLogger();
65 private SystemCallLatencyView fLatencyView
;
66 private AbstractSegmentStoreTableViewer fTable
;
72 public static void beforeClass() {
74 SWTBotUtils
.initialize();
75 Thread
.currentThread().setName("SWTBotTest");
76 /* set up for swtbot */
77 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
78 SWTBotPreferences
.KEYBOARD_LAYOUT
= "EN_US";
79 fLogger
.removeAllAppenders();
80 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender
.SYSTEM_OUT
));
81 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
82 final List
<SWTBotView
> openViews
= bot
.views();
83 for (SWTBotView view
: openViews
) {
84 if (view
.getTitle().equals("Welcome")) {
86 bot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
89 /* Switch perspectives */
90 switchTracingPerspective();
91 /* Finish waiting for eclipse to load */
92 SWTBotUtils
.waitForJobs();
97 * Opens a latency table
100 public void createTable() {
104 SWTBotUtils
.openView(VIEW_ID
);
105 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
106 SWTBotView viewBot
= bot
.viewById(VIEW_ID
);
107 final IViewReference viewReference
= viewBot
.getViewReference();
108 IViewPart viewPart
= UIThreadRunnable
.syncExec(new Result
<IViewPart
>() {
110 public IViewPart
run() {
111 return viewReference
.getView(true);
114 assertNotNull(viewPart
);
115 if (!(viewPart
instanceof SystemCallLatencyView
)) {
116 fail("Could not instanciate view");
118 fLatencyView
= (SystemCallLatencyView
) viewPart
;
119 fTable
= fLatencyView
.getSegmentStoreViewer();
120 assertNotNull(fTable
);
127 public void closeTable() {
128 final SWTWorkbenchBot swtWorkbenchBot
= new SWTWorkbenchBot();
129 SWTBotView viewBot
= swtWorkbenchBot
.viewById(VIEW_ID
);
133 private static void switchTracingPerspective() {
134 final Exception retE
[] = new Exception
[1];
135 if (!UIThreadRunnable
.syncExec(new BoolResult() {
137 public Boolean
run() {
139 PlatformUI
.getWorkbench().showPerspective(TRACING_PERSPECTIVE_ID
,
140 PlatformUI
.getWorkbench().getActiveWorkbenchWindow());
141 } catch (WorkbenchException e
) {
148 fail(retE
[0].getMessage());
157 public void climbTest() {
158 List
<@NonNull SystemCall
> fixture
= new ArrayList
<>();
159 for (int i
= 0; i
< 100; i
++) {
160 fixture
.add(new SystemCall(new InitialInfo(i
, "", Collections
.EMPTY_MAP
), 2 * i
, 0));
163 assertNotNull(fTable
);
164 fTable
.updateModel(fixture
);
165 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
166 assertEquals("0", tableBot
.cell(0, 2));
167 tableBot
.header("Duration").click();
168 assertEquals("0", tableBot
.cell(0, 2));
169 tableBot
.header("Duration").click();
170 assertEquals("99", tableBot
.cell(0, 2));
177 public void decrementingTest() {
178 List
<@NonNull SystemCall
> fixture
= new ArrayList
<>();
179 for (int i
= 100; i
>= 0; i
--) {
180 fixture
.add(new SystemCall(new InitialInfo(i
, "", Collections
.EMPTY_MAP
), 2 * i
, 0));
182 assertNotNull(fTable
);
183 fTable
.updateModel(fixture
);
184 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
185 assertEquals("100", tableBot
.cell(0, 2));
186 tableBot
.header("Duration").click();
187 assertEquals("0", tableBot
.cell(0, 2));
188 tableBot
.header("Duration").click();
189 assertEquals("100", tableBot
.cell(0, 2));
196 public void smallTest() {
197 List
<@NonNull SystemCall
> fixture
= new ArrayList
<>();
198 for (int i
= 1; i
>= 0; i
--) {
199 fixture
.add(new SystemCall(new InitialInfo(i
, "", Collections
.EMPTY_MAP
), 2 * i
, 0));
201 assertNotNull(fTable
);
202 fTable
.updateModel(fixture
);
203 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
204 assertEquals("1", tableBot
.cell(0, 2));
205 tableBot
.header("Duration").click();
206 assertEquals("0", tableBot
.cell(0, 2));
207 tableBot
.header("Duration").click();
208 assertEquals("1", tableBot
.cell(0, 2));
215 public void largeTest() {
216 final int size
= 1000000;
217 SystemCall
[] fixture
= new SystemCall
[size
];
218 for (int i
= 0; i
< size
; i
++) {
219 fixture
[i
] = (new SystemCall(new InitialInfo(i
, "", Collections
.EMPTY_MAP
), 2 * i
, 0));
221 assertNotNull(fTable
);
222 fTable
.updateModel(fixture
);
223 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
224 assertEquals("0", tableBot
.cell(0, 2));
225 tableBot
.header("Duration").click();
226 assertEquals("0", tableBot
.cell(0, 2));
227 tableBot
.header("Duration").click();
228 assertEquals("999999", tableBot
.cell(0, 2));
235 public void noiseTest() {
236 Random rnd
= new Random();
238 final int size
= 1000000;
239 SystemCall
[] fixture
= new SystemCall
[size
];
240 for (int i
= 0; i
< size
; i
++) {
241 int start
= Math
.abs(rnd
.nextInt(100000000));
242 int end
= start
+ Math
.abs(rnd
.nextInt(1000000));
243 fixture
[i
] = (new SystemCall(new InitialInfo(start
, "", Collections
.EMPTY_MAP
), end
, 0));
245 assertNotNull(fTable
);
246 fTable
.updateModel(fixture
);
247 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
248 assertEquals("894633", tableBot
.cell(0, 2));
249 tableBot
.header("Duration").click();
250 assertEquals("0", tableBot
.cell(0, 2));
251 tableBot
.header("Duration").click();
252 assertEquals("999999", tableBot
.cell(0, 2));
256 * Test gaussian noise
259 public void gaussianNoiseTest() {
260 Random rnd
= new Random();
262 List
<@NonNull SystemCall
> fixture
= new ArrayList
<>();
263 for (int i
= 1; i
<= 1000000; i
++) {
264 int start
= Math
.abs(rnd
.nextInt(100000000));
265 final int delta
= Math
.abs(rnd
.nextInt(1000));
266 int end
= start
+ delta
* delta
;
267 fixture
.add(new SystemCall(new InitialInfo(start
, "", Collections
.EMPTY_MAP
), end
, 0));
269 assertNotNull(fTable
);
270 fTable
.updateModel(fixture
);
271 SWTBotTable tableBot
= new SWTBotTable(fTable
.getTableViewer().getTable());
272 assertEquals("400689", tableBot
.cell(0, 2));
273 tableBot
.header("Duration").click();
274 assertEquals("0", tableBot
.cell(0, 2));
275 tableBot
.header("Duration").click();
276 assertEquals("998001", tableBot
.cell(0, 2));