control: add swtbot test for testing load and save feature
[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
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
13package org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests.latency;
14
94d1ce7d
MK
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertNotNull;
17import static org.junit.Assert.fail;
b70c55af 18
94d1ce7d
MK
19import java.util.ArrayList;
20import java.util.Collections;
21import java.util.List;
22import java.util.Random;
23
24import org.apache.log4j.ConsoleAppender;
25import org.apache.log4j.Logger;
26import org.apache.log4j.SimpleLayout;
27import org.eclipse.jdt.annotation.NonNull;
28import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
29import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
30import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
b70c55af 31import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
94d1ce7d
MK
32import org.eclipse.swtbot.swt.finder.results.BoolResult;
33import org.eclipse.swtbot.swt.finder.results.Result;
34import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
35import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
36import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCall;
37import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCall.InitialInfo;
38import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.AbstractSegmentStoreTableViewer;
39import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.SystemCallLatencyView;
40import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
41import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
42import org.eclipse.ui.IViewPart;
43import org.eclipse.ui.IViewReference;
44import org.eclipse.ui.PlatformUI;
45import org.eclipse.ui.WorkbenchException;
46import org.junit.After;
47import org.junit.Before;
48import org.junit.BeforeClass;
b70c55af
MK
49import org.junit.Test;
50import 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)
58public 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}
This page took 0.0363 seconds and 5 git commands to generate.