xref: /AOO41X/test/testgui/source/pvt/gui/Benchmark.java (revision 57caf934cc4bd0c33eda07ea95aabaebabf812db)
1*57caf934SLiu Zhe /**************************************************************
2*57caf934SLiu Zhe  *
3*57caf934SLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4*57caf934SLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5*57caf934SLiu Zhe  * distributed with this work for additional information
6*57caf934SLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7*57caf934SLiu Zhe  * to you under the Apache License, Version 2.0 (the
8*57caf934SLiu Zhe  * "License"); you may not use this file except in compliance
9*57caf934SLiu Zhe  * with the License.  You may obtain a copy of the License at
10*57caf934SLiu Zhe  *
11*57caf934SLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12*57caf934SLiu Zhe  *
13*57caf934SLiu Zhe  * Unless required by applicable law or agreed to in writing,
14*57caf934SLiu Zhe  * software distributed under the License is distributed on an
15*57caf934SLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*57caf934SLiu Zhe  * KIND, either express or implied.  See the License for the
17*57caf934SLiu Zhe  * specific language governing permissions and limitations
18*57caf934SLiu Zhe  * under the License.
19*57caf934SLiu Zhe  *
20*57caf934SLiu Zhe  *************************************************************/
21*57caf934SLiu Zhe 
22*57caf934SLiu Zhe /**
23*57caf934SLiu Zhe  *
24*57caf934SLiu Zhe  */
25*57caf934SLiu Zhe 
26*57caf934SLiu Zhe package pvt.gui;
27*57caf934SLiu Zhe 
28*57caf934SLiu Zhe import static org.openoffice.test.common.Testspace.*;
29*57caf934SLiu Zhe import static org.openoffice.test.vcl.Tester.*;
30*57caf934SLiu Zhe import static testlib.gui.UIMap.*;
31*57caf934SLiu Zhe 
32*57caf934SLiu Zhe import java.io.File;
33*57caf934SLiu Zhe import java.io.FileOutputStream;
34*57caf934SLiu Zhe import java.io.PrintStream;
35*57caf934SLiu Zhe import java.util.HashMap;
36*57caf934SLiu Zhe 
37*57caf934SLiu Zhe import org.junit.AfterClass;
38*57caf934SLiu Zhe import org.junit.BeforeClass;
39*57caf934SLiu Zhe import org.junit.Rule;
40*57caf934SLiu Zhe import org.junit.Test;
41*57caf934SLiu Zhe import org.junit.rules.TestName;
42*57caf934SLiu Zhe import org.openoffice.test.OpenOffice;
43*57caf934SLiu Zhe import org.openoffice.test.common.Condition;
44*57caf934SLiu Zhe import org.openoffice.test.common.Logger;
45*57caf934SLiu Zhe import org.openoffice.test.common.SystemUtil;
46*57caf934SLiu Zhe import org.openoffice.test.common.Testspace;
47*57caf934SLiu Zhe 
48*57caf934SLiu Zhe 
49*57caf934SLiu Zhe public class Benchmark {
50*57caf934SLiu Zhe 	@Rule
51*57caf934SLiu Zhe 	public Logger log = Logger.getLogger(this);
52*57caf934SLiu Zhe 
53*57caf934SLiu Zhe 	@Rule
54*57caf934SLiu Zhe 	public TestName testname = new TestName();
55*57caf934SLiu Zhe 
56*57caf934SLiu Zhe 	private static PrintStream result;
57*57caf934SLiu Zhe 
58*57caf934SLiu Zhe 	private static final double INTERVAL = 0.01;
59*57caf934SLiu Zhe 
60*57caf934SLiu Zhe 	public Benchmark() {
61*57caf934SLiu Zhe 
62*57caf934SLiu Zhe 	}
63*57caf934SLiu Zhe 
64*57caf934SLiu Zhe 	@BeforeClass
65*57caf934SLiu Zhe 	public static void beforeClass() throws Exception {
66*57caf934SLiu Zhe 		File resultFile = Testspace.getFile("output/gui_benchmark.csv");
67*57caf934SLiu Zhe 		resultFile.getParentFile().mkdirs();
68*57caf934SLiu Zhe 		result = new PrintStream(new FileOutputStream(resultFile));
69*57caf934SLiu Zhe 		OpenOffice.killAll();
70*57caf934SLiu Zhe 
71*57caf934SLiu Zhe 		result.println("Scenario,Consumed Time,Memory(VSZ),Memory(RSS),Handles(Windows Only)");
72*57caf934SLiu Zhe 	}
73*57caf934SLiu Zhe 
74*57caf934SLiu Zhe 	@AfterClass
75*57caf934SLiu Zhe 	public static void afterClass() throws Exception {
76*57caf934SLiu Zhe 		result.close();
77*57caf934SLiu Zhe 		app.close();
78*57caf934SLiu Zhe 	}
79*57caf934SLiu Zhe 
80*57caf934SLiu Zhe 	private HashMap<String, Object> getPerfData() {
81*57caf934SLiu Zhe 		HashMap<String, Object> proccessInfo = SystemUtil.findProcess(".*(soffice\\.bin|soffice\\.exe .*-env).*");
82*57caf934SLiu Zhe 		String pid = (String) proccessInfo.get("pid");
83*57caf934SLiu Zhe 		return SystemUtil.getProcessPerfData(pid);
84*57caf934SLiu Zhe 	}
85*57caf934SLiu Zhe 
86*57caf934SLiu Zhe 	private void addRecord(int i, long start, long end) {
87*57caf934SLiu Zhe 		HashMap<String, Object>  perf = getPerfData();
88*57caf934SLiu Zhe 		result.println(testname.getMethodName() + i + "," + (end - start) + "," + perf.get("vsz") + "," + perf.get("rss") + "," + perf.get("handles"));
89*57caf934SLiu Zhe 	}
90*57caf934SLiu Zhe 
91*57caf934SLiu Zhe 	@Test
92*57caf934SLiu Zhe 	public void coolStartup() throws Exception {
93*57caf934SLiu Zhe 		aoo.kill();
94*57caf934SLiu Zhe 		aoo.cleanUserInstallation();
95*57caf934SLiu Zhe 		aoo.start();
96*57caf934SLiu Zhe 		long start = System.currentTimeMillis();
97*57caf934SLiu Zhe 		startcenter.waitForExistence(120, INTERVAL);
98*57caf934SLiu Zhe 		long end = System.currentTimeMillis();
99*57caf934SLiu Zhe 		sleep(2);
100*57caf934SLiu Zhe 		addRecord(0, start, end);
101*57caf934SLiu Zhe 		app.close();
102*57caf934SLiu Zhe 	}
103*57caf934SLiu Zhe 
104*57caf934SLiu Zhe 	@Test
105*57caf934SLiu Zhe 	public void warmStartup() throws Exception {
106*57caf934SLiu Zhe 		for (int i = 0; i < 8; i++) {
107*57caf934SLiu Zhe 			aoo.kill();//make sure app is closed
108*57caf934SLiu Zhe 			aoo.start();
109*57caf934SLiu Zhe 			long start = System.currentTimeMillis();
110*57caf934SLiu Zhe 			startcenter.waitForExistence(120, INTERVAL);
111*57caf934SLiu Zhe 			long end = System.currentTimeMillis();
112*57caf934SLiu Zhe 			sleep(2);
113*57caf934SLiu Zhe 			addRecord(i, start, end);
114*57caf934SLiu Zhe 			app.close();
115*57caf934SLiu Zhe 		}
116*57caf934SLiu Zhe 	}
117*57caf934SLiu Zhe 
118*57caf934SLiu Zhe 	@Test
119*57caf934SLiu Zhe 	public void newTextDocument() {
120*57caf934SLiu Zhe 		for (int i = 0; i < 8; i++) {
121*57caf934SLiu Zhe 			aoo.kill();//make sure app is closed
122*57caf934SLiu Zhe 			aoo.start();
123*57caf934SLiu Zhe 			startCenterWriterButton.waitForExistence(120, 1);
124*57caf934SLiu Zhe 			sleep(2);
125*57caf934SLiu Zhe 			startCenterWriterButton.click(0.5, 0.5);
126*57caf934SLiu Zhe 			long start = System.currentTimeMillis();
127*57caf934SLiu Zhe 			writer.waitForExistence(60, INTERVAL);
128*57caf934SLiu Zhe 			long end = System.currentTimeMillis();
129*57caf934SLiu Zhe 			sleep(2);
130*57caf934SLiu Zhe 			addRecord(i, start, end);
131*57caf934SLiu Zhe 			app.close();
132*57caf934SLiu Zhe 		}
133*57caf934SLiu Zhe 	}
134*57caf934SLiu Zhe 
135*57caf934SLiu Zhe 	@Test
136*57caf934SLiu Zhe 	public void newSpreadsheet() {
137*57caf934SLiu Zhe 		for (int i = 0; i < 8; i++) {
138*57caf934SLiu Zhe 			aoo.kill();//make sure app is closed
139*57caf934SLiu Zhe 			aoo.start();
140*57caf934SLiu Zhe 			startCenterCalcButton.waitForExistence(120, 1);
141*57caf934SLiu Zhe 			sleep(2);
142*57caf934SLiu Zhe 			startCenterCalcButton.click(0.5, 0.5);
143*57caf934SLiu Zhe 			long start = System.currentTimeMillis();
144*57caf934SLiu Zhe 			calc.waitForExistence(60, INTERVAL);
145*57caf934SLiu Zhe 			long end = System.currentTimeMillis();
146*57caf934SLiu Zhe 			sleep(2);
147*57caf934SLiu Zhe 			addRecord(i, start, end);
148*57caf934SLiu Zhe 			app.close();
149*57caf934SLiu Zhe 		}
150*57caf934SLiu Zhe 	}
151*57caf934SLiu Zhe 
152*57caf934SLiu Zhe 	@Test
153*57caf934SLiu Zhe 	public void newPresentation() {
154*57caf934SLiu Zhe 		for (int i = 0; i < 8; i++) {
155*57caf934SLiu Zhe 			aoo.kill();//make sure app is closed
156*57caf934SLiu Zhe 			aoo.start();
157*57caf934SLiu Zhe 			startCenterImpressButton.waitForExistence(120, 1);
158*57caf934SLiu Zhe 			sleep(2);
159*57caf934SLiu Zhe 			startCenterImpressButton.click(0.5, 0.5);
160*57caf934SLiu Zhe 			sleep(1);
161*57caf934SLiu Zhe 			presentationWizard.click(0.9, 0.95);
162*57caf934SLiu Zhe 			long start = System.currentTimeMillis();
163*57caf934SLiu Zhe 			impress.waitForExistence(60, INTERVAL);
164*57caf934SLiu Zhe 			long end = System.currentTimeMillis();
165*57caf934SLiu Zhe 			sleep(2);
166*57caf934SLiu Zhe 			addRecord(i, start, end);
167*57caf934SLiu Zhe 			app.close();
168*57caf934SLiu Zhe 		}
169*57caf934SLiu Zhe 	}
170*57caf934SLiu Zhe 
171*57caf934SLiu Zhe 	@Test
172*57caf934SLiu Zhe 	public void loadFinishPlainDoc() {
173*57caf934SLiu Zhe 		loadFinishTextDocument("pvt_benchmark/sw_plain_120p.doc", "Page 1 / ");
174*57caf934SLiu Zhe 	}
175*57caf934SLiu Zhe 
176*57caf934SLiu Zhe 	@Test
177*57caf934SLiu Zhe 	public void loadFinishPlainOdt() {
178*57caf934SLiu Zhe 		loadFinishTextDocument("pvt_benchmark/sw_plain_120p_odf1.2.odt", "Page 1 / ");
179*57caf934SLiu Zhe 	}
180*57caf934SLiu Zhe 
181*57caf934SLiu Zhe 	@Test
182*57caf934SLiu Zhe 	public void loadFinishComplexDoc() {
183*57caf934SLiu Zhe 		loadFinishTextDocument("pvt_benchmark/sw_complex_100p.doc", "Page 1 / ");
184*57caf934SLiu Zhe 	}
185*57caf934SLiu Zhe 
186*57caf934SLiu Zhe 	@Test
187*57caf934SLiu Zhe 	public void loadFinishComplexOdt() {
188*57caf934SLiu Zhe 		loadFinishTextDocument("pvt_benchmark/sw_complex_100p_odf1.2.odt", "Page 1 / ");
189*57caf934SLiu Zhe 	}
190*57caf934SLiu Zhe 
191*57caf934SLiu Zhe 	public void loadFinishTextDocument(String file, final String indicator) {
192*57caf934SLiu Zhe 		String path = prepareData(file);
193*57caf934SLiu Zhe 		aoo.kill();
194*57caf934SLiu Zhe 		aoo.start();
195*57caf934SLiu Zhe 		startcenter.waitForExistence(120, 1);
196*57caf934SLiu Zhe 		for (int i = 0; i < 8; i++) {
197*57caf934SLiu Zhe 			app.dispatch(".uno:Open");
198*57caf934SLiu Zhe 			filePickerPath.setText(path);
199*57caf934SLiu Zhe 			filePickerOpen.click();
200*57caf934SLiu Zhe 			long start = System.currentTimeMillis();
201*57caf934SLiu Zhe 			new Condition() {
202*57caf934SLiu Zhe 
203*57caf934SLiu Zhe 				@Override
204*57caf934SLiu Zhe 				public boolean value() {
205*57caf934SLiu Zhe 					String text = statusBar.getItemText(0);
206*57caf934SLiu Zhe 					if (text == null)
207*57caf934SLiu Zhe 						return false;
208*57caf934SLiu Zhe 					return text.startsWith(indicator);
209*57caf934SLiu Zhe 				}
210*57caf934SLiu Zhe 
211*57caf934SLiu Zhe 			}.waitForTrue("", 120, INTERVAL);
212*57caf934SLiu Zhe 			long end = System.currentTimeMillis();
213*57caf934SLiu Zhe 			sleep(2);
214*57caf934SLiu Zhe 			addRecord(i, start, end);
215*57caf934SLiu Zhe 			app.dispatch(".uno:CloseDoc");
216*57caf934SLiu Zhe 		}
217*57caf934SLiu Zhe 
218*57caf934SLiu Zhe 		app.close();
219*57caf934SLiu Zhe 	}
220*57caf934SLiu Zhe 
221*57caf934SLiu Zhe 	@Test
222*57caf934SLiu Zhe 	public void loadFinishPlainXLS() {
223*57caf934SLiu Zhe 		loadFinishTextDocument("pvt_benchmark/sc_plain_4sh_5kcell.xls", "Sheet 2 / 4");
224*57caf934SLiu Zhe 	}
225*57caf934SLiu Zhe 
226*57caf934SLiu Zhe 	@Test
227*57caf934SLiu Zhe 	public void loadFinishPlainODS() {
228*57caf934SLiu Zhe 		loadFinishTextDocument("pvt_benchmark/sc_plain_4sh_5kcell_new_odf1.2.ods", "Sheet 1 / 4");
229*57caf934SLiu Zhe 	}
230*57caf934SLiu Zhe 
231*57caf934SLiu Zhe 	@Test
232*57caf934SLiu Zhe 	public void loadFinishComplexXLS() {
233*57caf934SLiu Zhe 		loadFinishTextDocument("pvt_benchmark/sc_complex_13sh_4kcell.xls", "Sheet 2 / 13");
234*57caf934SLiu Zhe 	}
235*57caf934SLiu Zhe 
236*57caf934SLiu Zhe 	@Test
237*57caf934SLiu Zhe 	public void loadFinishComplexODS() {
238*57caf934SLiu Zhe 		loadFinishTextDocument("pvt_benchmark/sc_complex_13sh_4kcell_new_odf1.2.ods", "Sheet 6 / 13");
239*57caf934SLiu Zhe 	}
240*57caf934SLiu Zhe 
241*57caf934SLiu Zhe 
242*57caf934SLiu Zhe 	@Test
243*57caf934SLiu Zhe 	public void loadFinishPlainODP() {
244*57caf934SLiu Zhe 		loadFinishTextDocument("pvt_benchmark/sc_complex_13sh_4kcell_new_odf1.2.ods", "Sheet 6 / 13");
245*57caf934SLiu Zhe 	}
246*57caf934SLiu Zhe 
247*57caf934SLiu Zhe 	@Test
248*57caf934SLiu Zhe 	public void loadFinishPlainPPT() {
249*57caf934SLiu Zhe 		loadFinishTextDocument("pvt_benchmark/sc_complex_13sh_4kcell_new_odf1.2.ods", "Sheet 6 / 13");
250*57caf934SLiu Zhe 	}
251*57caf934SLiu Zhe 
252*57caf934SLiu Zhe 	@Test
253*57caf934SLiu Zhe 	public void loadFinishComplexODP() {
254*57caf934SLiu Zhe 		loadFinishTextDocument("pvt_benchmark/sc_complex_13sh_4kcell_new_odf1.2.ods", "Sheet 6 / 13");
255*57caf934SLiu Zhe 	}
256*57caf934SLiu Zhe 
257*57caf934SLiu Zhe 	@Test
258*57caf934SLiu Zhe 	public void loadFinishComplexPPT() {
259*57caf934SLiu Zhe 		loadFinishTextDocument("pvt_benchmark/sc_complex_13sh_4kcell_new_odf1.2.ods", "Sheet 6 / 13");
260*57caf934SLiu Zhe 	}
261*57caf934SLiu Zhe 
262*57caf934SLiu Zhe 	public void loadFinish(String file, final String indicator) {
263*57caf934SLiu Zhe 		String path = prepareData(file);
264*57caf934SLiu Zhe 		aoo.kill();
265*57caf934SLiu Zhe 		aoo.start();
266*57caf934SLiu Zhe 		startcenter.waitForExistence(120, 1);
267*57caf934SLiu Zhe 		for (int i = 0; i < 8; i++) {
268*57caf934SLiu Zhe 			app.dispatch(".uno:Open");
269*57caf934SLiu Zhe 			filePickerPath.setText(path);
270*57caf934SLiu Zhe 			filePickerOpen.click();
271*57caf934SLiu Zhe 			long start = System.currentTimeMillis();
272*57caf934SLiu Zhe 			new Condition() {
273*57caf934SLiu Zhe 
274*57caf934SLiu Zhe 				@Override
275*57caf934SLiu Zhe 				public boolean value() {
276*57caf934SLiu Zhe 					String text = statusBar.getItemText(0);
277*57caf934SLiu Zhe 					if (text == null)
278*57caf934SLiu Zhe 						return false;
279*57caf934SLiu Zhe 					return text.startsWith(indicator);
280*57caf934SLiu Zhe 				}
281*57caf934SLiu Zhe 
282*57caf934SLiu Zhe 			}.waitForTrue("", 120, INTERVAL);
283*57caf934SLiu Zhe 			long end = System.currentTimeMillis();
284*57caf934SLiu Zhe 			sleep(2);
285*57caf934SLiu Zhe 			addRecord(i, start, end);
286*57caf934SLiu Zhe 			app.dispatch(".uno:CloseDoc");
287*57caf934SLiu Zhe 		}
288*57caf934SLiu Zhe 
289*57caf934SLiu Zhe 		app.close();
290*57caf934SLiu Zhe 	}
291*57caf934SLiu Zhe 
292*57caf934SLiu Zhe 
293*57caf934SLiu Zhe }
294