1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-18 12:06:08 +00:00

Force speedometer to use chrome and change to ApkUiAutoWorkload

* Workload was failing when chrome was not set as default broser so
  altered to use chrome every time.

* Changed workload to an ApkuiAutoWorkload since chrome is now a
  dependency.

* Refactored opening speedometer to new method.

* Added wait time for scores to show up when test finished.
This commit is contained in:
Rob Freeman 2020-03-30 10:24:58 +01:00 committed by Marc Bonnici
parent c9ddee761a
commit 5049e3663b
3 changed files with 68 additions and 24 deletions

View File

@ -15,29 +15,30 @@
import os
import re
from wa import UiautoWorkload, Parameter
from wa import ApkUiautoWorkload, Parameter
from wa.framework.exception import ValidationError, WorkloadError
from wa.utils.types import list_of_strs
from wa.utils.misc import unique
class Speedometer(UiautoWorkload):
class Speedometer(ApkUiautoWorkload):
name = 'speedometer'
package_names = ['com.android.chrome']
regex = re.compile(r'Speedometer Score ([\d.]+)')
versions = ['1.0', '2.0']
description = '''
A workload to execute the speedometer web based benchmark
Test description:
1. Open browser application
1. Open chrome
2. Navigate to the speedometer website - http://browserbench.org/Speedometer/
3. Execute the benchmark
known working chrome version 80.0.3987.149
'''
parameters = [
Parameter('version', allowed_values=versions, kind=str, default='2.0',
Parameter('speedometer_version', allowed_values=versions, kind=str, default='2.0',
description='''
The speedometer version to be used.
''')
@ -48,14 +49,7 @@ class Speedometer(UiautoWorkload):
def __init__(self, target, **kwargs):
super(Speedometer, self).__init__(target, **kwargs)
self.gui.timeout = 1500
self.gui.uiauto_params['version'] = self.version
def setup(self, context):
super(Speedometer, self).setup(context)
url = 'am start -a android.intent.action.VIEW -d http://browserbench.org/Speedometer' + self.version
if self.version == '1.0':
url = 'am start -a android.intent.action.VIEW -d http://browserbench.org/Speedometer'
self.target.execute(url)
self.gui.uiauto_params['version'] = self.speedometer_version
def update_output(self, context):
super(Speedometer, self).update_output(context)
@ -71,3 +65,4 @@ class Speedometer(UiautoWorkload):
context.add_metric('Speedometer Score', result, 'Runs per minute', lower_is_better=False)
else:
raise WorkloadError("The Speedometer workload has failed. No score was obtainable.")

View File

@ -38,9 +38,12 @@ public class UiAutomation extends BaseUiAutomation {
private long networkTimeout = TimeUnit.SECONDS.toMillis(networkTimeoutSecs);
public static String TAG = "UXPERF";
public boolean textenabled = false;
private String speedometerVersion;
@Before
public void initialize(){
Bundle params = getParams();
speedometerVersion = params.getString("version");
initialize_instrumentation();
}
@ -48,6 +51,7 @@ public class UiAutomation extends BaseUiAutomation {
public void setup() throws Exception{
setScreenOrientation(ScreenOrientation.NATURAL);
dismissChromePopup();
openSpeedometer();
}
@Test
@ -64,22 +68,67 @@ public class UiAutomation extends BaseUiAutomation {
public void runBenchmark() throws Exception {
UiObject start =
mDevice.findObject(new UiSelector().description("Start Test")
.className("android.widget.Button"));
if (start.waitForExists(2000)){
start.click();
} else {
UiObject starttext =
mDevice.findObject(new UiSelector().text("Start Test")
.className("android.widget.Button"));
starttext.click();
}
.className("android.widget.Button"));
UiObject starttext =
mDevice.findObject(new UiSelector().text("Start Test")
.className("android.widget.Button"));
// Run speedometer test
if (start.waitForExists(10000)) {
start.click();
} else {
starttext.click();
}
UiObject scores =
mDevice.findObject(new UiSelector().resourceId("result-number")
.className("android.view.View"));
scores.waitForExists(2100000);
getScores(scores);
}
public void openSpeedometer() throws Exception {
UiObject urlBar =
mDevice.findObject(new UiSelector().resourceId("com.android.chrome:id/url_bar"));
UiObject searchBox = mDevice.findObject(new UiSelector().resourceId("com.android.chrome:id/search_box_text"));
if (!urlBar.waitForExists(5000)) {
searchBox.click();
}
String url = "http://browserbench.org/Speedometer" + speedometerVersion;
if (speedometerVersion.equals("1.0")) {
url = "http://browserbench.org/Speedometer";
}
// Clicking search box turns it into url bar on some deivces
if(urlBar.waitForExists(2000)) {
urlBar.click();
sleep(2);
urlBar.setText(url);
} else {
searchBox.setText(url);
}
pressEnter();
}
public void getScores(UiObject scores) throws Exception {
boolean isScoreAvailable = false;
int waitAttempts = 0;
while (!isScoreAvailable && waitAttempts < 10) {
sleep(1);
if (!scores.getText().isEmpty() || !scores.getContentDescription().isEmpty()) {
isScoreAvailable = true;
}
waitAttempts++;
}
String textScore = scores.getText();
Log.d(TAG, "Speedometer Score " + textScore);
Log.d(TAG, "Speedometer Score " + scores.getContentDescription());
String descScore = scores.getContentDescription();
// Chrome throws loads of errors on some devices clogging up logcat so clear tabs before saving score.
clearTabs();
Log.i(TAG, "Speedometer Score " + textScore);
Log.i(TAG, "Speedometer Score " + descScore);
}
public void clearTabs() throws Exception {