Commit | Line | Data |
---|---|---|
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 | ||
13 | package org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests.latency; | |
14 | ||
94d1ce7d MK |
15 | import static org.junit.Assert.assertEquals; |
16 | import static org.junit.Assert.assertNotNull; | |
17 | import static org.junit.Assert.fail; | |
b70c55af | 18 | |
94d1ce7d MK |
19 | import java.util.ArrayList; |
20 | import java.util.Collections; | |
21 | import java.util.List; | |
22 | import java.util.Random; | |
23 | ||
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; | |
b70c55af | 31 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
94d1ce7d MK |
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; | |
b70c55af MK |
49 | import org.junit.Test; |
50 | import org.junit.runner.RunWith; | |
51 | ||
52 | /** | |
53 | * Tests of the latency table | |
94d1ce7d | 54 | * |
b70c55af MK |
55 | * @author Matthew Khouzam |
56 | */ | |
57 | @RunWith(SWTBotJunit4ClassRunner.class) | |
58 | public class SystemCallLatencyTableAnalysisTest { | |
59 | ||
94d1ce7d MK |
60 | private static final String VIEW_ID = SystemCallLatencyView.ID; |
61 | private static final String TRACING_PERSPECTIVE_ID = "org.eclipse.linuxtools.tmf.ui.perspective"; | |
62 | ||
63 | /** The Log4j logger instance. */ | |
64 | private static final Logger fLogger = Logger.getRootLogger(); | |
65 | private SystemCallLatencyView fLatencyView; | |
66 | private AbstractSegmentStoreTableViewer fTable; | |
67 | ||
68 | /** | |
69 | * Things to setup | |
70 | */ | |
71 | @BeforeClass | |
72 | public static void beforeClass() { | |
73 | ||
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")) { | |
85 | view.close(); | |
86 | bot.waitUntil(ConditionHelpers.ViewIsClosed(view)); | |
87 | } | |
88 | } | |
89 | /* Switch perspectives */ | |
90 | switchTracingPerspective(); | |
91 | /* Finish waiting for eclipse to load */ | |
92 | SWTBotUtils.waitForJobs(); | |
93 | ||
94 | } | |
95 | ||
96 | /** | |
97 | * Opens a latency table | |
98 | */ | |
99 | @Before | |
100 | public void createTable() { | |
101 | /* | |
102 | * Open latency view | |
103 | */ | |
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>() { | |
109 | @Override | |
110 | public IViewPart run() { | |
111 | return viewReference.getView(true); | |
112 | } | |
113 | }); | |
114 | assertNotNull(viewPart); | |
115 | if (!(viewPart instanceof SystemCallLatencyView)) { | |
116 | fail("Could not instanciate view"); | |
117 | } | |
118 | fLatencyView = (SystemCallLatencyView) viewPart; | |
119 | fTable = fLatencyView.getSegmentStoreViewer(); | |
120 | assertNotNull(fTable); | |
121 | } | |
122 | ||
123 | /** | |
124 | * Closes the view | |
125 | */ | |
126 | @After | |
127 | public void closeTable() { | |
128 | final SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot(); | |
129 | SWTBotView viewBot = swtWorkbenchBot.viewById(VIEW_ID); | |
130 | viewBot.close(); | |
131 | } | |
132 | ||
133 | private static void switchTracingPerspective() { | |
134 | final Exception retE[] = new Exception[1]; | |
135 | if (!UIThreadRunnable.syncExec(new BoolResult() { | |
136 | @Override | |
137 | public Boolean run() { | |
138 | try { | |
139 | PlatformUI.getWorkbench().showPerspective(TRACING_PERSPECTIVE_ID, | |
140 | PlatformUI.getWorkbench().getActiveWorkbenchWindow()); | |
141 | } catch (WorkbenchException e) { | |
142 | retE[0] = e; | |
143 | return false; | |
144 | } | |
145 | return true; | |
146 | } | |
147 | })) { | |
148 | fail(retE[0].getMessage()); | |
149 | } | |
150 | ||
151 | } | |
152 | ||
153 | /** | |
154 | * Test incrementing | |
155 | */ | |
156 | @Test | |
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)); | |
161 | } | |
162 | ||
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)); | |
171 | } | |
172 | ||
173 | /** | |
174 | * Test decrementing | |
175 | */ | |
176 | @Test | |
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)); | |
181 | } | |
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)); | |
190 | } | |
191 | ||
192 | /** | |
193 | * Test small table | |
194 | */ | |
195 | @Test | |
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)); | |
200 | } | |
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)); | |
209 | } | |
210 | ||
211 | /** | |
212 | * Test large | |
213 | */ | |
214 | @Test | |
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)); | |
220 | } | |
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)); | |
229 | } | |
230 | ||
231 | /** | |
232 | * Test noise | |
233 | */ | |
234 | @Test | |
235 | public void noiseTest() { | |
236 | Random rnd = new Random(); | |
237 | rnd.setSeed(1234); | |
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)); | |
244 | } | |
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)); | |
253 | } | |
254 | ||
b70c55af | 255 | /** |
94d1ce7d | 256 | * Test gaussian noise |
b70c55af MK |
257 | */ |
258 | @Test | |
94d1ce7d MK |
259 | public void gaussianNoiseTest() { |
260 | Random rnd = new Random(); | |
261 | rnd.setSeed(1234); | |
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)); | |
268 | } | |
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)); | |
b70c55af MK |
277 | } |
278 | ||
279 | } |