1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-03-21 01:59:13 +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.SystemClock;
import android.os.Bundle; import android.os.Bundle;
import android.util.Pair;
import com.android.uiautomator.core.UiObject; import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException; import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiScrollable; import com.android.uiautomator.core.UiScrollable;
@ -35,6 +37,7 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.Arrays; import java.util.Arrays;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -75,15 +78,46 @@ public class UxPerfUiAutomation extends BaseUiAutomation {
} }
} }
public void initDumpsysSurfaceFlinger(String appPackage, String view) { public String getSurfaceFlingerView(String appPackage) {
String packageView = String.format(appPackage + "/" + view); BufferedReader bufferedReader = null;
List<String> command = Arrays.asList("dumpsys", "SurfaceFlinger", "--latency-clear" List<String> surfaceFlingerList = new ArrayList<String>();
, packageView); String packageView = "";
initDumpsys(command); 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) { public void initDumpsysSurfaceFlinger(String appPackage) {
String packageView = String.format(appPackage + "/" + view); 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); List<String> command = Arrays.asList("dumpsys", "SurfaceFlinger", "--latency", packageView);
exitDumpsys(command, filename); exitDumpsys(command, filename);
} }
@ -95,7 +129,7 @@ public class UxPerfUiAutomation extends BaseUiAutomation {
} else { } else {
command = Arrays.asList("dumpsys", "gfxinfo", appPackage, "reset"); command = Arrays.asList("dumpsys", "gfxinfo", appPackage, "reset");
} }
initDumpsys(command); executeCommand(command);
} }
public void exitDumpsysGfxInfo(String appPackage, File filename) { public void exitDumpsysGfxInfo(String appPackage, File filename) {
@ -108,15 +142,49 @@ public class UxPerfUiAutomation extends BaseUiAutomation {
exitDumpsys(command, filename); 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 { try {
ProcessBuilder builder = new ProcessBuilder(); processBuilder.command(command);
builder.command(command); Process process = processBuilder.start();
Process process = builder.start(); exitValue = process.waitFor();
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) { } 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) { 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 // First time run requires confirmation to allow access to local files
UiObject allowButton = new UiObject(new UiSelector().textContains("Allow") UiObject allowButton = new UiObject(new UiSelector().textContains("Allow")
.className("android.widget.Button")); .className("android.widget.Button"));
// Some devices request multiple permisson rights so clear them all here
while (allowButton.waitForExists(timeout)) { if (allowButton.exists()) {
allowButton.clickAndWaitForNewWindow(timeout); // 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"))) { if (Boolean.parseBoolean(parameters.getString("dumpsys_enabled"))) {
initDumpsysSurfaceFlinger(parameters.getString("package"), view); initDumpsysSurfaceFlinger(parameters.getString("package"));
} }
} }
public void stopDumpsysSurfaceFlinger(Bundle parameters, String view, public void stopDumpsysSurfaceFlinger(Bundle parameters, String filename) throws Exception {
String filename) throws Exception {
if (Boolean.parseBoolean(parameters.getString("dumpsys_enabled"))) { if (Boolean.parseBoolean(parameters.getString("dumpsys_enabled"))) {
File out_file = new File(parameters.getString("output_dir"), filename); 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 // Select first photograph
selectPhoto(0); selectPhoto(0);
String viewName = "com.google.android.apps.photos.localmedia.ui.LocalPhotosActivity";
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry<String, GestureTestParams> pair = it.next(); Map.Entry<String, GestureTestParams> pair = it.next();
GestureType type = pair.getValue().gestureType; GestureType type = pair.getValue().gestureType;
@ -137,7 +135,7 @@ public class UiAutomation extends UxPerfUiAutomation {
} }
startDumpsysGfxInfo(parameters); startDumpsysGfxInfo(parameters);
startDumpsysSurfaceFlinger(parameters, viewName); startDumpsysSurfaceFlinger(parameters);
Timer result = new Timer(); Timer result = new Timer();
@ -155,7 +153,7 @@ public class UiAutomation extends UxPerfUiAutomation {
break; break;
} }
stopDumpsysSurfaceFlinger(parameters, viewName, surfFlingerlogName); stopDumpsysSurfaceFlinger(parameters, surfFlingerlogName);
stopDumpsysGfxInfo(parameters, gfxInfologName); stopDumpsysGfxInfo(parameters, gfxInfologName);
timingResults.put(runName, result); 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", UiObject seekBar = getUiObjectByResourceId("com.google.android.apps.photos:id/cpe_strength_seek_bar",
"android.widget.SeekBar"); "android.widget.SeekBar");
String viewName = "com.google.android.apps.consumerphotoeditor.fragments.ConsumerPhotoEditorActivity";
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry<String, SeekBarTestParams> pair = it.next(); Map.Entry<String, SeekBarTestParams> pair = it.next();
Position pos = pair.getValue().seekBarPosition; Position pos = pair.getValue().seekBarPosition;
@ -227,12 +223,12 @@ public class UiAutomation extends UxPerfUiAutomation {
String surfFlingerlogName = String.format(runName + "_surfFlinger.log"); String surfFlingerlogName = String.format(runName + "_surfFlinger.log");
startDumpsysGfxInfo(parameters); startDumpsysGfxInfo(parameters);
startDumpsysSurfaceFlinger(parameters, viewName); startDumpsysSurfaceFlinger(parameters);
Timer result = new Timer(); Timer result = new Timer();
result = seekBarTest(seekBar, pos, steps); result = seekBarTest(seekBar, pos, steps);
stopDumpsysSurfaceFlinger(parameters, viewName, surfFlingerlogName); stopDumpsysSurfaceFlinger(parameters, surfFlingerlogName);
stopDumpsysGfxInfo(parameters, gfxInfologName); stopDumpsysGfxInfo(parameters, gfxInfologName);
timingResults.put(runName, result); 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", UiObject straightenSlider = getUiObjectByResourceId("com.google.android.apps.photos:id/cpe_straighten_slider",
"android.view.View"); "android.view.View");
String viewName = "com.google.android.apps.consumerphotoeditor.fragments.ConsumerPhotoEditorActivity";
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry<String, Position> pair = it.next(); Map.Entry<String, Position> pair = it.next();
Position pos = pair.getValue(); Position pos = pair.getValue();
@ -279,12 +273,12 @@ public class UiAutomation extends UxPerfUiAutomation {
String surfFlingerlogName = String.format(runName + "_surfFlinger.log"); String surfFlingerlogName = String.format(runName + "_surfFlinger.log");
startDumpsysGfxInfo(parameters); startDumpsysGfxInfo(parameters);
startDumpsysSurfaceFlinger(parameters, viewName); startDumpsysSurfaceFlinger(parameters);
Timer result = new Timer(); Timer result = new Timer();
result = slideBarTest(straightenSlider, pos, steps); result = slideBarTest(straightenSlider, pos, steps);
stopDumpsysSurfaceFlinger(parameters, viewName, surfFlingerlogName); stopDumpsysSurfaceFlinger(parameters, surfFlingerlogName);
stopDumpsysGfxInfo(parameters, gfxInfologName); stopDumpsysGfxInfo(parameters, gfxInfologName);
timingResults.put(runName, result); 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", UiObject rotate = getUiObjectByResourceId("com.google.android.apps.photos:id/cpe_rotate_90",
"android.widget.ImageView"); "android.widget.ImageView");
String viewName = "com.google.android.apps.consumerphotoeditor.fragments.ConsumerPhotoEditorActivity";
for (String subTest : subTests) { for (String subTest : subTests) {
String runName = String.format(testTag + "_" + subTest); String runName = String.format(testTag + "_" + subTest);
String gfxInfologName = String.format(runName + "_gfxInfo.log"); String gfxInfologName = String.format(runName + "_gfxInfo.log");
String surfFlingerlogName = String.format(runName + "_surfFlinger.log"); String surfFlingerlogName = String.format(runName + "_surfFlinger.log");
startDumpsysGfxInfo(parameters); startDumpsysGfxInfo(parameters);
startDumpsysSurfaceFlinger(parameters, viewName); startDumpsysSurfaceFlinger(parameters);
Timer result = new Timer(); Timer result = new Timer();
result.start(); result.start();
rotate.click(); rotate.click();
result.end(); result.end();
stopDumpsysSurfaceFlinger(parameters, viewName, surfFlingerlogName); stopDumpsysSurfaceFlinger(parameters, surfFlingerlogName);
stopDumpsysGfxInfo(parameters, gfxInfologName); stopDumpsysGfxInfo(parameters, gfxInfologName);
timingResults.put(runName, result); timingResults.put(runName, result);

View File

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