1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-09-02 11:22:41 +01:00

Extended BaseUiAutomation and UxPerfUiAutomation

Moved common functionality to base classes for code reuse. Refactored
googlephotos, reader and gmail workloads to take advantage of the new
base class methods and removed total test time metric.

New methods for BaseUiAutomation:
uiDeviceVertPinchIn, uiDeviceVertPinchOut

New methods for UxPerfUiAutomation:
uiObjectVertPinchTest, writeResultsToFile, startDumpsysSurfaceFlinger,
startDumpsysSurfaceFlinger, startDumpsysGfxInfo, stopDumpsysGfxInfo

New class for UxPerfUiAutomation:
GestureTestParams
This commit is contained in:
John Richardson
2016-05-04 11:10:07 +01:00
parent c2a68074be
commit 31cf06b62a
9 changed files with 167 additions and 257 deletions

View File

@@ -22,13 +22,13 @@ import java.io.InputStreamReader;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit;
import android.app.Activity;
import android.os.Bundle;
import android.graphics.Point;
import android.graphics.Rect;
// 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;
@@ -207,4 +207,48 @@ public class BaseUiAutomation extends UiAutomatorTestCase {
getDisplayCentreHeight(),
steps);
}
public void uiDeviceVertPinchIn(UiObject view, int steps, int percent) throws Exception {
final int FINGER_TOUCH_HALF_WIDTH = 20;
// Make value between 1 and 100
percent = (percent < 0) ? 1 : (percent > 100) ? 100 : percent;
float percentage = percent / 100f;
Rect rect = view.getVisibleBounds();
if (rect.width() <= FINGER_TOUCH_HALF_WIDTH * 2)
throw new IllegalStateException("Object width is too small for operation");
// Start at the top-center and bottom-center of the control
Point startPoint1 = new Point(rect.centerX(), rect.centerY() + (int) ((rect.height() / 2) * percentage));
Point startPoint2 = new Point(rect.centerX(), rect.centerY() - (int) ((rect.height() / 2) * percentage));
// End at the same point at the center of the control
Point endPoint1 = new Point(rect.centerX(), rect.centerY() + FINGER_TOUCH_HALF_WIDTH);
Point endPoint2 = new Point(rect.centerX(), rect.centerY() - FINGER_TOUCH_HALF_WIDTH);
view.performTwoPointerGesture(startPoint1, startPoint2, endPoint1, endPoint2, steps);
}
public void uiDeviceVertPinchOut(UiObject view, int steps, int percent) throws Exception {
final int FINGER_TOUCH_HALF_WIDTH = 20;
// Make value between 1 and 100
percent = (percent < 0) ? 1 : (percent > 100) ? 100 : percent;
float percentage = percent / 100f;
Rect rect = view.getVisibleBounds();
if (rect.width() <= FINGER_TOUCH_HALF_WIDTH * 2)
throw new IllegalStateException("Object width is too small for operation");
// Start from the same point at the center of the control
Point startPoint1 = new Point(rect.centerX(), rect.centerY() + FINGER_TOUCH_HALF_WIDTH);
Point startPoint2 = new Point(rect.centerX(), rect.centerY() - FINGER_TOUCH_HALF_WIDTH);
// End at the top-center and bottom-center of the control
Point endPoint1 = new Point(rect.centerX(), rect.centerY() + (int) ((rect.height() / 2) * percentage));
Point endPoint2 = new Point(rect.centerX(), rect.centerY() - (int) ((rect.height() / 2) * percentage));
view.performTwoPointerGesture(startPoint1, startPoint2, endPoint1, endPoint2, steps);
}
}

View File

@@ -17,6 +17,7 @@ package com.arm.wlauto.uiauto;
import android.os.Build;
import android.os.SystemClock;
import android.os.Bundle;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
@@ -26,6 +27,7 @@ import com.android.uiautomator.core.UiSelector;
import com.arm.wlauto.uiauto.BaseUiAutomation;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
@@ -34,6 +36,10 @@ 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;
public class UxPerfUiAutomation extends BaseUiAutomation {
@@ -209,4 +215,85 @@ public class UxPerfUiAutomation extends BaseUiAutomation {
results.end();
return results;
}
public Timer uiObjectVertPinchTest(UiObject view, PinchType direction,
int steps, int percent) throws Exception {
Timer results = new Timer();
results.start();
if (direction.equals(PinchType.IN)) {
uiDeviceVertPinchIn(view, steps, percent);
} else if (direction.equals(PinchType.OUT)) {
uiDeviceVertPinchOut(view, steps, percent);
}
results.end();
return results;
}
public class GestureTestParams {
public GestureType gestureType;
public Direction gestureDirection;
public PinchType pinchType;
public int percent;
public int steps;
public GestureTestParams(GestureType gesture, Direction direction, int steps) {
this.gestureType = gesture;
this.gestureDirection = direction;
this.pinchType = PinchType.NULL;
this.steps = steps;
this.percent = 0;
}
public GestureTestParams(GestureType gesture, PinchType pinchType, int steps, int percent) {
this.gestureType = gesture;
this.gestureDirection = Direction.NULL;
this.pinchType = pinchType;
this.steps = steps;
this.percent = percent;
}
}
public void writeResultsToFile(LinkedHashMap timingResults, 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"));
}
out.close();
}
public void startDumpsysSurfaceFlinger(Bundle parameters, String view) {
if (Boolean.parseBoolean(parameters.getString("dumpsys_enabled"))) {
initDumpsysSurfaceFlinger(parameters.getString("package"), view);
}
}
public void stopDumpsysSurfaceFlinger(Bundle parameters, String view,
String filename) throws Exception {
if (Boolean.parseBoolean(parameters.getString("dumpsys_enabled"))) {
File out_file = new File(parameters.getString("output_dir"), filename);
exitDumpsysSurfaceFlinger(parameters.getString("package"), view, out_file);
}
}
public void startDumpsysGfxInfo(Bundle parameters) {
if (Boolean.parseBoolean(parameters.getString("dumpsys_enabled"))) {
initDumpsysGfxInfo(parameters.getString("package"));
}
}
public void stopDumpsysGfxInfo(Bundle parameters, String filename) throws Exception {
if (Boolean.parseBoolean(parameters.getString("dumpsys_enabled"))) {
File out_file = new File(parameters.getString("output_dir"), filename);
exitDumpsysGfxInfo(parameters.getString("package"), out_file);
}
}
}