1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-03-14 14:48:53 +00:00

Merge commit 'cde0b12c5dda9cc7d8d0ae5421df4a03f65a0df3' into develop

This commit is contained in:
James Hartley 2016-05-05 23:39:34 +01:00
commit c624979caa
17 changed files with 440 additions and 18 deletions

View File

@ -127,6 +127,11 @@ class ApkWorkload(Workload):
:view: The class of the main view pane of the app. This needs to be defined in order
to collect SurfaceFlinger-derived statistics (such as FPS) for the app, but
may otherwise be left as ``None``.
:launch_main: If ``False``, the default activity will not be launched (during setup),
allowing workloads to start the app with an intent of their choice in
the run step. This is useful for apps without a launchable default/main
activity or those where it cannot be launched without intent data (which
is provided at the run phase).
:install_timeout: Timeout for the installation of the APK. This may vary wildly based on
the size and nature of a specific APK, and so should be defined on
per-workload basis.
@ -144,6 +149,7 @@ class ApkWorkload(Workload):
activity = None
view = None
supported_platforms = ['android']
launch_main = True
parameters = [
Parameter('install_timeout', kind=int, default=300,
@ -160,6 +166,11 @@ class ApkWorkload(Workload):
'''),
Parameter('uninstall_apk', kind=boolean, default=False,
description='If ``True``, will uninstall workload\'s APK as part of teardown.'),
Parameter('clear_data_on_reset', kind=bool, default=True,
description='''
If set to ``False``, this will prevent WA from clearing package
data for this workload prior to running it.
'''),
]
def __init__(self, device, _call_super=True, **kwargs):
@ -184,7 +195,8 @@ class ApkWorkload(Workload):
def setup(self, context):
self.initialize_package(context)
self.launch_package()
if self.launch_main:
self.launch_package() # launch default activity without intent data
self.device.execute('am kill-all') # kill all *background* activities
self.device.clear_logcat()
@ -239,13 +251,14 @@ class ApkWorkload(Workload):
else:
output = self.device.execute('am start -W -n {}/{}'.format(self.package, self.activity))
if 'Error:' in output:
self.device.execute('am force-stop {}'.format(self.package)) # this will dismiss any erro dialogs
self.device.execute('am force-stop {}'.format(self.package)) # this will dismiss any error dialogs
raise WorkloadError(output)
self.logger.debug(output)
def reset(self, context): # pylint: disable=W0613
self.device.execute('am force-stop {}'.format(self.package))
self.device.execute('pm clear {}'.format(self.package))
if self.clear_data_on_reset:
self.device.execute('pm clear {}'.format(self.package))
# As of android API level 23, apps can request permissions at runtime,
# this will grant all of them so requests do not pop up when running the app
@ -434,7 +447,7 @@ class GameWorkload(ApkWorkload, ReventWorkload):
Parameter('install_timeout', default=500, override=True),
Parameter('assets_push_timeout', kind=int, default=500,
description='Timeout used during deployment of the assets package (if there is one).'),
Parameter('clear_data_on_reset', kind=bool, default=True,
Parameter('clear_data_on_reset', kind=bool, default=True, override=True,
description="""
If set to ``False``, this will prevent WA from clearing package
data for this workload prior to running it.

View File

@ -36,8 +36,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Arrays;
import java.util.List;
import java.util.LinkedHashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
@ -253,19 +251,18 @@ public class UxPerfUiAutomation extends BaseUiAutomation {
}
}
public void writeResultsToFile(LinkedHashMap timingResults, String file) throws Exception {
public void writeResultsToFile(Map<String, Timer> results, String file) throws Exception {
// Write out the key/value pairs to the instrumentation log file
FileWriter fstream = new FileWriter(file);
BufferedWriter out = new BufferedWriter(fstream);
Iterator<Entry<String, Timer>> it = timingResults.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Timer> pairs = it.next();
Timer results = pairs.getValue();
long start = results.getStart();
long finish = results.getFinish();
long duration = results.getDuration();
out.write(String.format(pairs .getKey() + " " + start + " " + finish + " " + duration + "\n"));
BufferedWriter out = new BufferedWriter(new FileWriter(file));
long start, finish, duration;
Timer timer;
for (Map.Entry<String, Timer> entry : results.entrySet()) {
timer = entry.getValue();
start = timer.getStart();
finish = timer.getFinish();
duration = timer.getDuration();
// Format used to parse out results in workload's update_result function
out.write(String.format("%s %d %d %d\n", entry.getKey(), start, finish, duration));
}
out.close();
}

3
wlauto/workloads/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.yaml
*.apk
*.json

View File

@ -0,0 +1,130 @@
# Copyright 2014-2016 ARM Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os.path as op
import re
import time
from wlauto import AndroidUiAutoBenchmark, Parameter
SKYPE_ACTION_URIS = {
'call': 'call',
'video': 'call&video=true',
}
class Skype(AndroidUiAutoBenchmark):
name = 'skype'
description = '''
Workload that makes Skype calls
It allows for the agenda to decide whether to make a voice call or a video call.
Credentials for the user account used to log into the Skype app have to be provided
in the agenda, as well as the display name and skype ID of the contact to call.
Other optional arguments allow controlling the duration of the call, whether the
call includes video or voice only, and whether to collect sys dumps.
For reliable testing, this workload requires a good and stable internet connection,
preferably on Wi-Fi.
'''
package = 'com.skype.raider'
activity = ''
# Skype has no default 'main' activity
launch_main = False # overrides extended class
instrumentation_log = '{}_instrumentation.log'.format(name)
parameters = [
Parameter('login_name', kind=str, mandatory=True,
description='''
Account to use when logging into the device from which the call will be made
'''),
Parameter('login_pass', kind=str, mandatory=True,
description='Password associated with the account to log into the device'),
Parameter('contact_skypeid', kind=str, mandatory=True,
description='This is the Skype ID of the contact to call from the device'),
Parameter('contact_name', kind=str, mandatory=True,
description='This is the contact display name as it appears in the people list'),
Parameter('duration', kind=int, default=60,
description='This is the duration of the call in seconds'),
Parameter('action', kind=str, allowed_values=['voice', 'video'], default='video',
description='Action to take - either video (default) or voice call'),
Parameter('dumpsys_enabled', kind=bool, default=True,
description='''
If ``True``, dumpsys captures will be carried out during the test run.
The output is piped to log files which are then pulled from the phone.
'''),
]
def __init__(self, device, **kwargs):
super(Skype, self).__init__(device, **kwargs)
self.output_file = op.join(self.device.working_directory, self.instrumentation_log)
self.run_timeout = self.duration + 60
def validate(self):
super(Skype, self).validate()
self.uiauto_params['results_file'] = self.output_file
self.uiauto_params['dumpsys_enabled'] = self.dumpsys_enabled
self.uiauto_params['output_dir'] = self.device.working_directory
self.uiauto_params['my_id'] = self.login_name
self.uiauto_params['my_pwd'] = self.login_pass
self.uiauto_params['skypeid'] = self.contact_skypeid
self.uiauto_params['name'] = self.contact_name.replace(' ', '_')
self.uiauto_params['duration'] = self.duration
self.uiauto_params['action'] = self.action
def setup(self, context):
self.logger.info('===== setup() ======')
super(Skype, self).setup(context)
self.device.execute('am force-stop {}'.format(self.package))
self.device.execute('am start -W -a android.intent.action.VIEW -d skype:dummy?dummy')
time.sleep(1)
def run(self, context):
self.logger.info('===== run() ======')
super(Skype, self).run(context)
def update_result(self, context):
self.logger.info('===== update_result() ======')
super(Skype, self).update_result(context)
if not self.dumpsys_enabled:
return
self.device.pull_file(self.output_file, context.output_directory)
results_file = op.join(context.output_directory, self.instrumentation_log)
# process results and add them using
# context.result.add_metric
with open(results_file, 'r') as wfh:
regex = re.compile(r'(\w+)\s+(\d+)\s+(\d+)\s+(\d+)')
for line in wfh:
match = regex.search(line)
if match:
context.result.add_metric((match.group(1) + "_start"), match.group(2))
context.result.add_metric((match.group(1) + "_finish"), match.group(3))
context.result.add_metric((match.group(1) + "_duration"), match.group(4))
def teardown(self, context):
self.logger.info('===== teardown() ======')
super(Skype, self).teardown(context)
# Pull log files
wd = self.device.working_directory
for entry in self.device.listdir(wd):
if entry.startswith(self.name) and entry.endswith(".log"):
self.device.pull_file(op.join(wd, entry), context.output_directory)
self.device.delete_file(op.join(wd, entry))

Binary file not shown.

View File

@ -0,0 +1,13 @@
global:
iterations: 1
workloads:
- id: {{workload_id}}
name: skype
params:
login_name: {{login_name}}
login_pass: {{login_pass}}
contact_skypeid: {{contact_skypeid}}
contact_name: {{contact_name}}
duration: {{duration}}
action: {{action}}
dumpsys_enabled: {{dumpsys_enabled}}

View File

@ -0,0 +1,17 @@
#!/bin/bash
class_dir=bin/classes/com/arm/wlauto/uiauto
base_classes=`python -c "import os, wlauto; print os.path.join(os.path.dirname(wlauto.__file__), 'common', 'android', '*.class')"`
mkdir -p $class_dir
cp $base_classes $class_dir
ant build
exit_code=$?
if [[ $exit_code -ne 0 ]]; then
echo "ERROR: ant build exited with code $exit_code" && exit $exit_code
fi
if [[ -f bin/com.arm.wlauto.uiauto.skype.jar ]]; then
cp bin/com.arm.wlauto.uiauto.skype.jar ..
fi

View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="com.arm.wlauto.uiauto.skype" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: VERSION_TAG -->
<import file="${sdk.dir}/tools/ant/uibuild.xml" />
</project>

View File

@ -0,0 +1,14 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-18

View File

@ -0,0 +1,143 @@
package com.arm.wlauto.uiauto.skype;
import java.io.File;
import java.util.TreeMap;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.KeyEvent;
// Import the uiautomator libraries
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiScrollable;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import com.arm.wlauto.uiauto.UxPerfUiAutomation;
public class UiAutomation extends UxPerfUiAutomation {
public static final String TAG = "skype";
public static final String PACKAGE = "com.skype.raider";
public static final String PACKAGE_ID = "com.skype.raider:id/";
public static final String TEXT_VIEW = "android.widget.TextView";
private Map<String, Timer> results = new TreeMap<String, Timer>();
private boolean dumpsysEnabled;
private String outputDir;
public void runUiAutomation() throws Exception {
// Override superclass value
this.waitTimeout = 10000;
// Get Params
Bundle parameters = getParams();
String loginName = parameters.getString("my_id");
String loginPass = parameters.getString("my_pwd");
String contactSkypeId = parameters.getString("skypeid");
String contactName = parameters.getString("name").replace("_", " ");
int callDuration = Integer.parseInt(parameters.getString("duration"));
String callType = parameters.getString("action");
String resultsFile = parameters.getString("results_file");
outputDir = parameters.getString("output_dir", "/sdcard/wa-working");
dumpsysEnabled = Boolean.parseBoolean(parameters.getString("dumpsys_enabled"));
// Run tests
handleLoginScreen(loginName, loginPass);
selectContact(contactName, contactSkypeId);
if ("video".equalsIgnoreCase(callType)) {
videoCallTest(callDuration);
} else if ("voice".equalsIgnoreCase(callType)) {
voiceCallTest(callDuration);
}
// Save results
writeResultsToFile(results, resultsFile);
}
private void handleLoginScreen(String username, String password) throws Exception {
String useridResoureId = PACKAGE_ID + "sign_in_userid";
String nextButtonResourceId = PACKAGE_ID + "sign_in_next_btn";
UiObject useridField = new UiObject(new UiSelector().resourceId(useridResoureId));
UiObject nextButton = new UiObject(new UiSelector().resourceId(nextButtonResourceId));
useridField.setText(username);
nextButton.clickAndWaitForNewWindow();
String passwordResoureId = PACKAGE_ID + "signin_password";
String signinButtonResourceId = PACKAGE_ID + "sign_in_btn";
UiObject passwordField = new UiObject(new UiSelector().resourceId(passwordResoureId));
UiObject signinButton = new UiObject(new UiSelector().resourceId(signinButtonResourceId));
passwordField.setText(password);
signinButton.clickAndWaitForNewWindow();
}
private void selectContact(String name, String id) throws Exception {
Timer timer = new Timer();
timer.start();
UiObject peopleTab;
// Open the 'People' tab aka contacts view
// On phones, it is represented by an image with description
// On tablets, the full text is shown without a description
try {
peopleTab = getUiObjectByDescription("People", TEXT_VIEW);
} catch (UiObjectNotFoundException e) {
peopleTab = getUiObjectByText("People", TEXT_VIEW);
}
peopleTab.click();
// On first startup, the app may take a while to load the display name,
// so try twice before declaring failure
UiObject contactCard;
try {
contactCard = getUiObjectByText(name, TEXT_VIEW);
} catch (UiObjectNotFoundException e) {
contactCard = getUiObjectByText(name, TEXT_VIEW);
}
contactCard.clickAndWaitForNewWindow();
timer.end();
results.put("select_contact", timer);
}
private void voiceCallTest(int duration) throws Exception {
String testTag = "voice_call";
Timer timer = new Timer();
timer.start();
makeCall(duration, false, testTag);
timer.end();
results.put(testTag, timer);
}
private void videoCallTest(int duration) throws Exception {
String testTag = "video_call";
Timer timer = new Timer();
timer.start();
makeCall(duration, true, testTag);
timer.end();
results.put(testTag, timer);
}
private void makeCall(int duration, boolean video, String testTag) throws Exception {
String viewName = "com.skype.android.app.calling.CallActivity";
String dumpsysTag = TAG + "_" + testTag;
if (video && dumpsysEnabled) {
initDumpsysSurfaceFlinger(PACKAGE, viewName);
initDumpsysGfxInfo(PACKAGE);
}
String description = video ? "Video call" : "Call options";
UiObject callButton = new UiObject(new UiSelector().descriptionContains(description));
callButton.click();
sleep(duration);
if (video && dumpsysEnabled) {
exitDumpsysSurfaceFlinger(PACKAGE, viewName, new File(outputDir, dumpsysTag + "_surfFlinger.log"));
exitDumpsysGfxInfo(PACKAGE, new File(outputDir, dumpsysTag + "_gfxInfo.log"));
}
}
}