mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-03-21 01:59:13 +00:00
Add to google slides workloads
- support for creating new PPT - parameterised local files - added helper functions
This commit is contained in:
parent
f2ff559805
commit
b096c11ec9
@ -17,6 +17,7 @@ import os
|
|||||||
import os.path as path
|
import os.path as path
|
||||||
import re
|
import re
|
||||||
from wlauto import AndroidUiAutoBenchmark, Parameter
|
from wlauto import AndroidUiAutoBenchmark, Parameter
|
||||||
|
from wlauto.utils.types import list_of_strings
|
||||||
|
|
||||||
|
|
||||||
def not_implemented(workload, text):
|
def not_implemented(workload, text):
|
||||||
@ -34,8 +35,9 @@ class GoogleSlides(AndroidUiAutoBenchmark):
|
|||||||
|
|
||||||
# Views for FPS instrumentation
|
# Views for FPS instrumentation
|
||||||
view = [
|
view = [
|
||||||
"com.google.android.apps.docs.editors.slides/com.google.android.apps.docs.app.DocListActivity",
|
package + '/com.google.android.apps.docs.app.DocListActivity',
|
||||||
"com.google.android.apps.docs.editors.slides/com.google.android.apps.docs.welcome.warmwelcome.TrackingWelcomeActivity",
|
package + '/com.google.android.apps.docs.welcome.warmwelcome.TrackingWelcomeActivity',
|
||||||
|
package + '/com.google.android.apps.docs.app.NewMainProxyActivity',
|
||||||
]
|
]
|
||||||
|
|
||||||
parameters = [
|
parameters = [
|
||||||
@ -44,7 +46,8 @@ class GoogleSlides(AndroidUiAutoBenchmark):
|
|||||||
If ``True``, dumpsys captures will be carried out during the test run.
|
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.
|
The output is piped to log files which are then pulled from the phone.
|
||||||
'''),
|
'''),
|
||||||
Parameter('local_files', kind=bool, default=True,
|
# Parameter('local_files', kind=list_of_strings, default=['Slides_Album.pptx', 'Slides_Pitch.pptx'],
|
||||||
|
Parameter('local_files', kind=list_of_strings,
|
||||||
description='''
|
description='''
|
||||||
If ``True``, the workload will push PowerPoint files to be used for testing on
|
If ``True``, the workload will push PowerPoint files to be used for testing on
|
||||||
the device. Otherwise, the files will be created from template inside the app.
|
the device. Otherwise, the files will be created from template inside the app.
|
||||||
@ -59,7 +62,7 @@ class GoogleSlides(AndroidUiAutoBenchmark):
|
|||||||
def __init__(self, device, **kwargs):
|
def __init__(self, device, **kwargs):
|
||||||
super(GoogleSlides, self).__init__(device, **kwargs)
|
super(GoogleSlides, self).__init__(device, **kwargs)
|
||||||
self.output_file = path.join(self.device.working_directory, self.instrumentation_log)
|
self.output_file = path.join(self.device.working_directory, self.instrumentation_log)
|
||||||
self.run_timeout = 60
|
self.run_timeout = 120
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
log_method(self, 'validate')
|
log_method(self, 'validate')
|
||||||
@ -67,6 +70,8 @@ class GoogleSlides(AndroidUiAutoBenchmark):
|
|||||||
self.uiauto_params['dumpsys_enabled'] = self.dumpsys_enabled
|
self.uiauto_params['dumpsys_enabled'] = self.dumpsys_enabled
|
||||||
self.uiauto_params['output_dir'] = self.device.working_directory
|
self.uiauto_params['output_dir'] = self.device.working_directory
|
||||||
self.uiauto_params['results_file'] = self.output_file
|
self.uiauto_params['results_file'] = self.output_file
|
||||||
|
if self.local_files:
|
||||||
|
self.uiauto_params['local_files'] = '::'.join(self.local_files)
|
||||||
|
|
||||||
def initialize(self, context):
|
def initialize(self, context):
|
||||||
log_method(self, 'initialize')
|
log_method(self, 'initialize')
|
||||||
@ -75,12 +80,12 @@ class GoogleSlides(AndroidUiAutoBenchmark):
|
|||||||
# push local PPT files
|
# push local PPT files
|
||||||
for entry in os.listdir(self.local_dir):
|
for entry in os.listdir(self.local_dir):
|
||||||
wa_file = self.file_prefix + entry
|
wa_file = self.file_prefix + entry
|
||||||
if entry.endswith(".pptx"):
|
if entry.endswith('.pptx'):
|
||||||
self.device.push_file(path.join(self.local_dir, entry),
|
self.device.push_file(path.join(self.local_dir, entry),
|
||||||
path.join(self.device_dir, wa_file),
|
path.join(self.device_dir, wa_file),
|
||||||
timeout=60)
|
timeout=60)
|
||||||
# Force a re-index of the mediaserver cache to pick up new files
|
# Force a re-index of the mediaserver cache to pick up new files
|
||||||
self.device.execute('am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///sdcard')
|
# self.device.execute('am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///sdcard')
|
||||||
|
|
||||||
def setup(self, context):
|
def setup(self, context):
|
||||||
log_method(self, 'setup')
|
log_method(self, 'setup')
|
||||||
@ -93,8 +98,7 @@ class GoogleSlides(AndroidUiAutoBenchmark):
|
|||||||
def update_result(self, context):
|
def update_result(self, context):
|
||||||
log_method(self, 'update_result')
|
log_method(self, 'update_result')
|
||||||
super(GoogleSlides, self).update_result(context)
|
super(GoogleSlides, self).update_result(context)
|
||||||
if self.dumpsys_enabled:
|
not_implemented(self, 'get_metrics(context)')
|
||||||
not_implemented(self, 'get_metrics(context)')
|
|
||||||
|
|
||||||
def teardown(self, context):
|
def teardown(self, context):
|
||||||
log_method(self, 'teardown')
|
log_method(self, 'teardown')
|
||||||
@ -108,10 +112,10 @@ class GoogleSlides(AndroidUiAutoBenchmark):
|
|||||||
# delete pushed PPT files
|
# delete pushed PPT files
|
||||||
for entry in os.listdir(self.local_dir):
|
for entry in os.listdir(self.local_dir):
|
||||||
wa_file = self.file_prefix + entry
|
wa_file = self.file_prefix + entry
|
||||||
if entry.endswith(".pptx"):
|
if entry.endswith('.pptx'):
|
||||||
self.device.delete_file(path.join(self.device_dir, wa_file))
|
self.device.delete_file(path.join(self.device_dir, wa_file))
|
||||||
# Force a re-index of the mediaserver cache to pick up new files
|
# Force a re-index of the mediaserver cache to pick up new files
|
||||||
self.device.execute('am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///sdcard')
|
# self.device.execute('am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///sdcard')
|
||||||
|
|
||||||
def get_metrics(self, context):
|
def get_metrics(self, context):
|
||||||
self.device.pull_file(self.output_file, context.output_directory)
|
self.device.pull_file(self.output_file, context.output_directory)
|
||||||
|
Binary file not shown.
@ -23,6 +23,7 @@ import android.app.Activity;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
@ -51,21 +52,21 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
public static final int DOCTYPE_PPT = 2;
|
public static final int DOCTYPE_PPT = 2;
|
||||||
public static final int DOCTYPE_SLIDES = 3;
|
public static final int DOCTYPE_SLIDES = 3;
|
||||||
|
|
||||||
private Map<String, Timer> results = new LinkedHashMap<String, Timer>();
|
protected Map<String, Timer> results = new LinkedHashMap<String, Timer>();
|
||||||
|
|
||||||
private Bundle parameters;
|
protected Bundle parameters;
|
||||||
private boolean dumpsysEnabled;
|
protected boolean dumpsysEnabled;
|
||||||
private String outputDir;
|
protected String outputDir;
|
||||||
private String documentName;
|
protected String[] documents;
|
||||||
private boolean useLocalFiles;
|
protected boolean useLocalFiles;
|
||||||
|
protected String resultsFile;
|
||||||
private static final String[] DEFAULT_DOCS = { "wa_test_Slides_Album.pptx", "wa_test_Slides_Pitch.pptx" };
|
|
||||||
|
|
||||||
public void parseParams(Bundle parameters) throws Exception {
|
public void parseParams(Bundle parameters) throws Exception {
|
||||||
dumpsysEnabled = Boolean.parseBoolean(parameters.getString("dumpsys_enabled"));
|
dumpsysEnabled = Boolean.parseBoolean(parameters.getString("dumpsys_enabled"));
|
||||||
outputDir = parameters.getString("output_dir", "/sdcard/wa-working");
|
outputDir = parameters.getString("output_dir");
|
||||||
documentName = parameters.getString("local_files", DEFAULT_DOCS[0]);
|
resultsFile = parameters.getString("results_file");
|
||||||
useLocalFiles = true;
|
documents = parameters.getString("local_files", "::").split("::");
|
||||||
|
useLocalFiles = documents.length != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runUiAutomation() throws Exception {
|
public void runUiAutomation() throws Exception {
|
||||||
@ -73,28 +74,31 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
parseParams(parameters);
|
parseParams(parameters);
|
||||||
skipWelcomeScreen();
|
skipWelcomeScreen();
|
||||||
enablePowerpointCompat();
|
enablePowerpointCompat();
|
||||||
if (useLocalFiles) { // TODO currently unused
|
if (useLocalFiles) {
|
||||||
openFromStorage(documentName);
|
openFromStorage(documents[0]);
|
||||||
} else {
|
} else {
|
||||||
createNewDoc(DOCTYPE_TEMPLATE);
|
// createNewDoc(DOCTYPE_TEMPLATE);
|
||||||
|
createNewDoc(DOCTYPE_PPT);
|
||||||
}
|
}
|
||||||
setWifiStatus(false);
|
|
||||||
tapDisplayNormalised(0.99, 0.99);
|
// toggleWifiState(false);
|
||||||
|
// tapDisplayNormalised(0.99, 0.99); // dismiss help overlay
|
||||||
sleep(5);
|
sleep(5);
|
||||||
getUiDevice().pressBack();
|
getUiDevice().pressBack();
|
||||||
|
deleteDocument();
|
||||||
|
|
||||||
if (false) { // TODO currently unused
|
if (false) { // TODO currently unused
|
||||||
writeResultsToFile(results, parameters.getString("results_file"));
|
writeResultsToFile(results, parameters.getString("results_file"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void skipWelcomeScreen() throws Exception {
|
protected void skipWelcomeScreen() throws Exception {
|
||||||
UiObject skipButton = getUiObjectByText("Skip", CLASS_BUTTON);
|
UiObject skipButton = getUiObjectByText("Skip", CLASS_BUTTON);
|
||||||
skipButton.clickAndWaitForNewWindow();
|
skipButton.clickAndWaitForNewWindow();
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enablePowerpointCompat() throws Exception {
|
protected void enablePowerpointCompat() throws Exception {
|
||||||
uiDeviceEdgeSwipeFromLeft(10);
|
uiDeviceEdgeSwipeFromLeft(10);
|
||||||
UiObject settings = getUiObjectByText("Settings", CLASS_TEXT_VIEW);
|
UiObject settings = getUiObjectByText("Settings", CLASS_TEXT_VIEW);
|
||||||
settings.clickAndWaitForNewWindow();
|
settings.clickAndWaitForNewWindow();
|
||||||
@ -104,7 +108,7 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openFromStorage(String document) throws Exception {
|
protected void openFromStorage(String document) throws Exception {
|
||||||
// UiObject newButton = getUiObjectByResourceId(PACKAGE_ID + "menu_open_with_picker", CLASS_TEXT_VIEW);
|
// UiObject newButton = getUiObjectByResourceId(PACKAGE_ID + "menu_open_with_picker", CLASS_TEXT_VIEW);
|
||||||
UiObject openButton = getUiObjectByDescription("Open presentation", CLASS_TEXT_VIEW);
|
UiObject openButton = getUiObjectByDescription("Open presentation", CLASS_TEXT_VIEW);
|
||||||
openButton.click();
|
openButton.click();
|
||||||
@ -120,11 +124,9 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewDoc(int docType) throws Exception {
|
protected void createNewDoc(int docType) throws Exception {
|
||||||
// UiObject newButton = getUiObjectByResourceId(PACKAGE_ID + "fab_base_button", CLASS_IMAGE_BUTTON);
|
|
||||||
UiObject newButton = getUiObjectByDescription("New presentation", CLASS_IMAGE_BUTTON);
|
UiObject newButton = getUiObjectByDescription("New presentation", CLASS_IMAGE_BUTTON);
|
||||||
newButton.click();
|
newButton.click();
|
||||||
// UiObject fromTemplate = getUiObjectByDescription("Choose template", CLASS_IMAGE_BUTTON);
|
|
||||||
UiObject fromTemplate = getUiObjectByText("Choose template", CLASS_TEXT_VIEW);
|
UiObject fromTemplate = getUiObjectByText("Choose template", CLASS_TEXT_VIEW);
|
||||||
|
|
||||||
// UiObject newPowerpoint = getUiObjectByDescription("New PowerPoint", CLASS_IMAGE_BUTTON);
|
// UiObject newPowerpoint = getUiObjectByDescription("New PowerPoint", CLASS_IMAGE_BUTTON);
|
||||||
@ -143,6 +145,22 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
|
|
||||||
case DOCTYPE_PPT:
|
case DOCTYPE_PPT:
|
||||||
newPowerpoint.clickAndWaitForNewWindow();
|
newPowerpoint.clickAndWaitForNewWindow();
|
||||||
|
enterTextInSlide("Title", "WORKLOAD AUTOMATION");
|
||||||
|
enterTextInSlide("Subtitle", "Measuring perfomance of different productivity apps on Android OS");
|
||||||
|
UiObject view = getViewByDesc("Insert slide");
|
||||||
|
view.clickAndWaitForNewWindow();
|
||||||
|
view = getViewByText("Title and Content");
|
||||||
|
view.clickAndWaitForNewWindow();
|
||||||
|
enterTextInSlide("title", "INTRODUCTION");
|
||||||
|
enterTextInSlide("Text placeholder", "Welcome to Documentation for Workload Automation");
|
||||||
|
view = getViewByDesc("Undo");
|
||||||
|
view.click();
|
||||||
|
sleep(1);
|
||||||
|
enterTextInSlide("Text placeholder", "Workload Automation (WA) is a framework for running workloads on real hardware devices. "
|
||||||
|
+ "WA supports a number of output formats as well as additional instrumentation "
|
||||||
|
+ "(such as Streamline traces). A number of workloads are included with the framework.");
|
||||||
|
view = getViewByDesc("Done");
|
||||||
|
view.clickAndWaitForNewWindow();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DOCTYPE_SLIDES:
|
case DOCTYPE_SLIDES:
|
||||||
@ -153,6 +171,54 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UiObject enterTextInSlide(String viewName, String textToEnter) throws Exception {
|
||||||
|
UiObject view = getViewByDesc(viewName);
|
||||||
|
view.click();
|
||||||
|
SystemClock.sleep(100);
|
||||||
|
view.click(); // double click
|
||||||
|
view.setText(textToEnter);
|
||||||
|
getUiDevice().pressBack();
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteDocument() throws Exception {
|
||||||
|
UiObject moreOptions = getUiObjectByResourceId(PACKAGE_ID + "more_actions_button", CLASS_IMAGE_BUTTON);
|
||||||
|
moreOptions.click();
|
||||||
|
UiObject deleteButton = getUiObjectByText("Remove", CLASS_TEXT_VIEW);
|
||||||
|
deleteButton.click();
|
||||||
|
try {
|
||||||
|
deleteButton = getUiObjectByText("Remove", CLASS_BUTTON);
|
||||||
|
} catch (UiObjectNotFoundException e) {
|
||||||
|
deleteButton = getUiObjectByText("Ok", CLASS_BUTTON);
|
||||||
|
}
|
||||||
|
deleteButton.clickAndWaitForNewWindow();
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UiObject getViewByText(String text) throws Exception {
|
||||||
|
UiObject object = new UiObject(new UiSelector().textContains(text));
|
||||||
|
if (!object.waitForExists(waitTimeout)) {
|
||||||
|
throw new UiObjectNotFoundException("Could not find view with text: " + text);
|
||||||
|
};
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UiObject getViewByDesc(String desc) throws Exception {
|
||||||
|
UiObject object = new UiObject(new UiSelector().descriptionContains(desc));
|
||||||
|
if (!object.waitForExists(waitTimeout)) {
|
||||||
|
throw new UiObjectNotFoundException("Could not find view with description: " + desc);
|
||||||
|
};
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UiObject getViewById(String id) throws Exception {
|
||||||
|
UiObject object = new UiObject(new UiSelector().resourceId(id));
|
||||||
|
if (!object.waitForExists(waitTimeout)) {
|
||||||
|
throw new UiObjectNotFoundException("Could not find view with resource ID: " + id);
|
||||||
|
};
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
public void uiDeviceEdgeSwipeFromLeft(int steps) {
|
public void uiDeviceEdgeSwipeFromLeft(int steps) {
|
||||||
int height = getDisplayHeight();
|
int height = getDisplayHeight();
|
||||||
int width = getDisplayWidth();
|
int width = getDisplayWidth();
|
||||||
@ -167,25 +233,33 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
getUiDevice().click(tapX, tapY);
|
getUiDevice().click(tapX, tapY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWifiStatus(boolean flag) throws Exception {
|
public void toggleWifiState(boolean flag) throws Exception {
|
||||||
|
int exitValue = -1;
|
||||||
// To enable, check for "UninitializedState"
|
// To enable, check for "UninitializedState"
|
||||||
String checkFor = flag ? "UninitializedState" : "ConnectedState";
|
// String checkFor = flag ? "UninitializedState" : "ConnectedState";
|
||||||
String adbCommand =
|
// exitValue = runShellCommand("dumpsys wifi | grep curState=" + checkFor);
|
||||||
"dumpsys wifi | grep curState=" + checkFor + ";"
|
// if (0 == exitValue) { // toggle state
|
||||||
+ "exit_code=$?;"
|
String statusString = flag ? "ConnectedState" : "UninitializedState";
|
||||||
+ "if [ $exit_code = 0 ]; then"
|
exitValue = runShellCommand("dumpsys wifi | grep curState=" + statusString);
|
||||||
+ " am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings;"
|
if (0 != exitValue) { // not in the expected so toggle it
|
||||||
+ " input keyevent 20;"
|
String[] adbCommands = {
|
||||||
+ " input keyevent 23;"
|
"am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings;",
|
||||||
+ " sleep 1;"
|
"input keyevent 20;",
|
||||||
+ " input keyevent 4;"
|
"input keyevent 23;",
|
||||||
+ "fi";
|
"sleep 1;",
|
||||||
runShellCommand(adbCommand);
|
"input keyevent 4;",
|
||||||
// runShellCommand("dumpsys wifi | grep curState=ConnectedState");
|
};
|
||||||
|
for (String command : adbCommands) {
|
||||||
|
exitValue = runShellCommand(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runShellCommand(String command) throws Exception {
|
public int runShellCommand(String command) throws Exception {
|
||||||
Process proc = Runtime.getRuntime().exec(command);
|
Process proc = Runtime.getRuntime().exec(command);
|
||||||
|
Log.d(TAG, String.format("Command:\n%s\nExit value:%d\n", command, proc.exitValue()));
|
||||||
|
proc.waitFor();
|
||||||
|
return proc.exitValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user