1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-03-13 22:28:36 +00:00

Merge pull request #31 from jimboatarm/discover_view

Add logic to dumpsys helpers to discover present view
This commit is contained in:
jimboatarm 2016-05-26 12:58:54 +01:00
commit aa7029d074
16 changed files with 122 additions and 54 deletions

View File

@ -19,6 +19,8 @@ import android.os.Build;
import android.os.SystemClock;
import android.os.Bundle;
import android.util.Pair;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiScrollable;
@ -35,6 +37,7 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -75,15 +78,46 @@ public class UxPerfUiAutomation extends BaseUiAutomation {
}
}
public void initDumpsysSurfaceFlinger(String appPackage, String view) {
String packageView = String.format(appPackage + "/" + view);
List<String> command = Arrays.asList("dumpsys", "SurfaceFlinger", "--latency-clear"
, packageView);
initDumpsys(command);
public String getSurfaceFlingerView(String appPackage) {
BufferedReader bufferedReader = null;
List<String> surfaceFlingerList = new ArrayList<String>();
String packageView = "";
try {
List<String> command =
Arrays.asList("dumpsys", "SurfaceFlinger", "--list");
ProcessBuilder builder = new ProcessBuilder();
builder.command(command);
Process process = builder.start();
process.waitFor();
bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
if (line.startsWith(appPackage)) {
surfaceFlingerList.add(line);
}
}
if (surfaceFlingerList.size() != 0) {
packageView = surfaceFlingerList.get(surfaceFlingerList.size() - 1);
}
} catch (Exception exception) {
logger.log(Level.SEVERE, "Unable to list SurfaceFlinger views in dumpsys", exception);
}
return packageView;
}
public void exitDumpsysSurfaceFlinger(String appPackage, String view, File filename) {
String packageView = String.format(appPackage + "/" + view);
public void initDumpsysSurfaceFlinger(String appPackage) {
String packageView = getSurfaceFlingerView(appPackage);
List<String> command = Arrays.asList("dumpsys", "SurfaceFlinger", "--latency-clear",
packageView);
executeCommand(command);
}
public void exitDumpsysSurfaceFlinger(String appPackage, File filename) {
String packageView = getSurfaceFlingerView(appPackage);
List<String> command = Arrays.asList("dumpsys", "SurfaceFlinger", "--latency", packageView);
exitDumpsys(command, filename);
}
@ -95,7 +129,7 @@ public class UxPerfUiAutomation extends BaseUiAutomation {
} else {
command = Arrays.asList("dumpsys", "gfxinfo", appPackage, "reset");
}
initDumpsys(command);
executeCommand(command);
}
public void exitDumpsysGfxInfo(String appPackage, File filename) {
@ -108,15 +142,49 @@ public class UxPerfUiAutomation extends BaseUiAutomation {
exitDumpsys(command, filename);
}
public void initDumpsys(List<String> command) {
public Pair<Integer, String> executeCommand(List<String> command) {
return executeCommand(command, false);
}
public Pair<Integer, String> executeCommand(List<String> command, boolean readOutput)
{
StringBuilder stringBuilder = new StringBuilder();
ProcessBuilder processBuilder = new ProcessBuilder();
BufferedReader bufferedReader = null;
int exitValue = -1;
String output = "Unable to execute command\n" + Arrays.toString(command.toArray());
try {
ProcessBuilder builder = new ProcessBuilder();
builder.command(command);
Process process = builder.start();
process.waitFor();
processBuilder.command(command);
Process process = processBuilder.start();
exitValue = process.waitFor();
if (readOutput) {
bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
String lineSeparator = System.getProperty("line.separator");
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append(lineSeparator);
}
}
output = stringBuilder.toString();
} catch (Exception exception) {
logger.log(Level.SEVERE, "Unable to reset dumpsys", exception);
logger.log(Level.SEVERE, "Unable to execute command", exception);
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return Pair.create(exitValue, output);
}
public void exitDumpsys(List<String> command, File filename) {
@ -271,23 +339,25 @@ public class UxPerfUiAutomation extends BaseUiAutomation {
// First time run requires confirmation to allow access to local files
UiObject allowButton = new UiObject(new UiSelector().textContains("Allow")
.className("android.widget.Button"));
// Some devices request multiple permisson rights so clear them all here
while (allowButton.waitForExists(timeout)) {
allowButton.clickAndWaitForNewWindow(timeout);
if (allowButton.exists()) {
// Some devices request multiple permisson rights so clear them all here
do {
allowButton.clickAndWaitForNewWindow(timeout);
} while (allowButton.waitForExists(TimeUnit.SECONDS.toMillis(1)));
}
}
public void startDumpsysSurfaceFlinger(Bundle parameters, String view) {
public void startDumpsysSurfaceFlinger(Bundle parameters) {
if (Boolean.parseBoolean(parameters.getString("dumpsys_enabled"))) {
initDumpsysSurfaceFlinger(parameters.getString("package"), view);
initDumpsysSurfaceFlinger(parameters.getString("package"));
}
}
public void stopDumpsysSurfaceFlinger(Bundle parameters, String view,
String filename) throws Exception {
public void stopDumpsysSurfaceFlinger(Bundle parameters, 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);
exitDumpsysSurfaceFlinger(parameters.getString("package"), out_file);
}
}

View File

@ -116,8 +116,6 @@ public class UiAutomation extends UxPerfUiAutomation {
// Select first photograph
selectPhoto(0);
String viewName = "com.google.android.apps.photos.localmedia.ui.LocalPhotosActivity";
while (it.hasNext()) {
Map.Entry<String, GestureTestParams> pair = it.next();
GestureType type = pair.getValue().gestureType;
@ -137,7 +135,7 @@ public class UiAutomation extends UxPerfUiAutomation {
}
startDumpsysGfxInfo(parameters);
startDumpsysSurfaceFlinger(parameters, viewName);
startDumpsysSurfaceFlinger(parameters);
Timer result = new Timer();
@ -155,7 +153,7 @@ public class UiAutomation extends UxPerfUiAutomation {
break;
}
stopDumpsysSurfaceFlinger(parameters, viewName, surfFlingerlogName);
stopDumpsysSurfaceFlinger(parameters, surfFlingerlogName);
stopDumpsysGfxInfo(parameters, gfxInfologName);
timingResults.put(runName, result);
@ -214,8 +212,6 @@ public class UiAutomation extends UxPerfUiAutomation {
UiObject seekBar = getUiObjectByResourceId("com.google.android.apps.photos:id/cpe_strength_seek_bar",
"android.widget.SeekBar");
String viewName = "com.google.android.apps.consumerphotoeditor.fragments.ConsumerPhotoEditorActivity";
while (it.hasNext()) {
Map.Entry<String, SeekBarTestParams> pair = it.next();
Position pos = pair.getValue().seekBarPosition;
@ -227,12 +223,12 @@ public class UiAutomation extends UxPerfUiAutomation {
String surfFlingerlogName = String.format(runName + "_surfFlinger.log");
startDumpsysGfxInfo(parameters);
startDumpsysSurfaceFlinger(parameters, viewName);
startDumpsysSurfaceFlinger(parameters);
Timer result = new Timer();
result = seekBarTest(seekBar, pos, steps);
stopDumpsysSurfaceFlinger(parameters, viewName, surfFlingerlogName);
stopDumpsysSurfaceFlinger(parameters, surfFlingerlogName);
stopDumpsysGfxInfo(parameters, gfxInfologName);
timingResults.put(runName, result);
@ -268,8 +264,6 @@ public class UiAutomation extends UxPerfUiAutomation {
UiObject straightenSlider = getUiObjectByResourceId("com.google.android.apps.photos:id/cpe_straighten_slider",
"android.view.View");
String viewName = "com.google.android.apps.consumerphotoeditor.fragments.ConsumerPhotoEditorActivity";
while (it.hasNext()) {
Map.Entry<String, Position> pair = it.next();
Position pos = pair.getValue();
@ -279,12 +273,12 @@ public class UiAutomation extends UxPerfUiAutomation {
String surfFlingerlogName = String.format(runName + "_surfFlinger.log");
startDumpsysGfxInfo(parameters);
startDumpsysSurfaceFlinger(parameters, viewName);
startDumpsysSurfaceFlinger(parameters);
Timer result = new Timer();
result = slideBarTest(straightenSlider, pos, steps);
stopDumpsysSurfaceFlinger(parameters, viewName, surfFlingerlogName);
stopDumpsysSurfaceFlinger(parameters, surfFlingerlogName);
stopDumpsysGfxInfo(parameters, gfxInfologName);
timingResults.put(runName, result);
@ -311,22 +305,20 @@ public class UiAutomation extends UxPerfUiAutomation {
UiObject rotate = getUiObjectByResourceId("com.google.android.apps.photos:id/cpe_rotate_90",
"android.widget.ImageView");
String viewName = "com.google.android.apps.consumerphotoeditor.fragments.ConsumerPhotoEditorActivity";
for (String subTest : subTests) {
String runName = String.format(testTag + "_" + subTest);
String gfxInfologName = String.format(runName + "_gfxInfo.log");
String surfFlingerlogName = String.format(runName + "_surfFlinger.log");
startDumpsysGfxInfo(parameters);
startDumpsysSurfaceFlinger(parameters, viewName);
startDumpsysSurfaceFlinger(parameters);
Timer result = new Timer();
result.start();
rotate.click();
result.end();
stopDumpsysSurfaceFlinger(parameters, viewName, surfFlingerlogName);
stopDumpsysSurfaceFlinger(parameters, surfFlingerlogName);
stopDumpsysGfxInfo(parameters, gfxInfologName);
timingResults.put(runName, result);

View File

@ -51,9 +51,10 @@ public class UiAutomation extends UxPerfUiAutomation {
confirmAccess();
gesturesTest("Getting Started.pdf");
String[] searchStrings = {"Glossary", "cortex"};
searchPdfTest("cortex_m4", searchStrings);
String filename = "Getting Started.pdf";
gesturesTest(filename);
String[] searchStrings = {"read", "the"};
searchPdfTest(filename, searchStrings);
unsetScreenOrientation();
@ -61,8 +62,14 @@ public class UiAutomation extends UxPerfUiAutomation {
}
private void dismissWelcomeView() throws Exception {
UiObject welcomeView = getUiObjectByDescription("Acrobat - First Time Experience",
"android.webkit.WebView");
UiObject welcomeView;
try {
welcomeView = getUiObjectByDescription("Acrobat - First Time Experience",
"android.webkit.WebView");
} catch (UiObjectNotFoundException e) {
welcomeView = new UiObject(new UiSelector().className("android.webkit.WebView"));
}
// Click through the first two pages and wait for pages to transition.
// These pages are webkit views so clickAndWaitForNewWindow or waitForExists cannot be used
tapDisplayCentre();
@ -73,13 +80,13 @@ public class UiAutomation extends UxPerfUiAutomation {
// Get the box coords for the webView window
Rect webViewCoords = welcomeView.getBounds();
// Iterate up from the bottom middle of the webView until we hit these
// Continue button and change view
// Iterate up from the bottom of the webView until we hit the continue
// button and change view
int i = 0;
do {
i += 10;
tapDisplay(webViewCoords.centerX(), webViewCoords.centerY() + i);
} while (welcomeView.exists() || i < webViewCoords.top);
tapDisplay(webViewCoords.centerX(), webViewCoords.bottom - i);
} while (welcomeView.exists() && i < webViewCoords.top);
}
private void signInOnline(Bundle parameters) throws Exception {
@ -147,6 +154,7 @@ public class UiAutomation extends UxPerfUiAutomation {
String file = filename.replaceAll("\\.", "_").replaceAll("\\s+", "_");
timingResults.put(String.format(TestTag + "_" + "selectLocalFilesList" + "_" + file), selectLocalFilesList());
// On some devices permissions to access local files occurs here rather than the earlier step
confirmAccess();
timingResults.put(String.format(TestTag + "_" + "selectSearchDuration" + "_" + file), selectSearchFileButton());
@ -165,7 +173,7 @@ public class UiAutomation extends UxPerfUiAutomation {
UiObject localButton = getUiObjectByText("LOCAL", "android.widget.TextView");
Timer result = new Timer();
result.start();
localButton.clickAndWaitForNewWindow(timeout);
localButton.click();
long finish = SystemClock.elapsedRealtime();
result.end();
return result;
@ -239,12 +247,11 @@ public class UiAutomation extends UxPerfUiAutomation {
String runName = String.format(TestTag + "_" + pair.getKey());
String gfxInfologName = String.format(runName + "_gfxInfo.log");
String surfFlingerlogName = String.format(runName + "_surfFlinger.log");
String viewName = new String("com.adobe.reader.viewer.ARViewerActivity");
UiObject view = new UiObject(new UiSelector().resourceId("com.adobe.reader:id/viewPager"));
startDumpsysGfxInfo(parameters);
startDumpsysSurfaceFlinger(parameters, viewName);
startDumpsysSurfaceFlinger(parameters);
Timer results = new Timer();
@ -262,7 +269,7 @@ public class UiAutomation extends UxPerfUiAutomation {
break;
}
stopDumpsysSurfaceFlinger(parameters, viewName, surfFlingerlogName);
stopDumpsysSurfaceFlinger(parameters, surfFlingerlogName);
stopDumpsysGfxInfo(parameters, gfxInfologName);
timingResults.put(runName, results);

View File

@ -157,10 +157,9 @@ public class UiAutomation extends UxPerfUiAutomation {
}
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);
initDumpsysSurfaceFlinger(PACKAGE);
initDumpsysGfxInfo(PACKAGE);
}
@ -170,7 +169,7 @@ public class UiAutomation extends UxPerfUiAutomation {
sleep(duration);
if (video && dumpsysEnabled) {
exitDumpsysSurfaceFlinger(PACKAGE, viewName, new File(outputDir, dumpsysTag + "_surfFlinger.log"));
exitDumpsysSurfaceFlinger(PACKAGE, new File(outputDir, dumpsysTag + "_surfFlinger.log"));
exitDumpsysGfxInfo(PACKAGE, new File(outputDir, dumpsysTag + "_gfxInfo.log"));
}
}