mirror of
				https://github.com/ARM-software/workload-automation.git
				synced 2025-11-04 09:02:12 +00:00 
			
		
		
		
	Merge remote-tracking branch 'upstream/master' into wl-skype
This commit is contained in:
		
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								wlauto/common/android/UxPerfUiAutomation$GestureTestParams.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								wlauto/common/android/UxPerfUiAutomation$GestureTestParams.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -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;
 | 
			
		||||
 | 
			
		||||
@@ -142,6 +142,12 @@ public class BaseUiAutomation extends UiAutomatorTestCase {
 | 
			
		||||
        return object;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void clickUiObject(UiObject uiobject, long timeout) throws Exception {
 | 
			
		||||
        if (!uiobject.clickAndWaitForNewWindow(timeout)) {
 | 
			
		||||
            throw new UiObjectNotFoundException(String.format("Timeout waiting for New Window"));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getDisplayHeight () {
 | 
			
		||||
        return getUiDevice().getInstance().getDisplayHeight();
 | 
			
		||||
    }
 | 
			
		||||
@@ -201,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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
          }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,7 @@ class Gmail(AndroidUiAutoBenchmark):
 | 
			
		||||
    description = """
 | 
			
		||||
    A workload to perform standard productivity tasks within Gmail.
 | 
			
		||||
 | 
			
		||||
    The workload carries out various tasks, such as creatign new emails and
 | 
			
		||||
    The workload carries out various tasks, such as creating new emails and
 | 
			
		||||
    sending them, whilst also producing metrics for action completion times.
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
@@ -45,13 +45,12 @@ class Gmail(AndroidUiAutoBenchmark):
 | 
			
		||||
    def setup(self, context):
 | 
			
		||||
        super(Gmail, self).setup(context)
 | 
			
		||||
 | 
			
		||||
        self.camera_dir = self.device.path.join(self.device.external_storage_directory,
 | 
			
		||||
                                                      'DCIM/Camera/')
 | 
			
		||||
        self.storage_dir = self.device.path.join(self.device.working_directory)
 | 
			
		||||
 | 
			
		||||
        for file in os.listdir(self.dependencies_directory):
 | 
			
		||||
            if file.endswith(".jpg"):
 | 
			
		||||
                self.device.push_file(os.path.join(self.dependencies_directory, file),
 | 
			
		||||
                                      os.path.join(self.camera_dir, file), timeout=300)
 | 
			
		||||
                                      os.path.join(self.storage_dir, file), timeout=300)
 | 
			
		||||
 | 
			
		||||
        # 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')
 | 
			
		||||
@@ -67,26 +66,30 @@ class Gmail(AndroidUiAutoBenchmark):
 | 
			
		||||
    def update_result(self, context):
 | 
			
		||||
        super(Gmail, self).update_result(context)
 | 
			
		||||
 | 
			
		||||
        if self.dumpsys_enabled:
 | 
			
		||||
            self.device.pull_file(self.output_file, context.output_directory)
 | 
			
		||||
            result_file = os.path.join(context.output_directory, self.instrumentation_log)
 | 
			
		||||
        self.device.pull_file(self.output_file, context.output_directory)
 | 
			
		||||
        result_file = os.path.join(context.output_directory, self.instrumentation_log)
 | 
			
		||||
 | 
			
		||||
            with open(result_file, 'r') as wfh:
 | 
			
		||||
                regex = re.compile(r'(?P<key>\w+)\s+(?P<value1>\d+)\s+(?P<value2>\d+)\s+(?P<value3>\d+)')
 | 
			
		||||
                for line in wfh:
 | 
			
		||||
                    match = regex.search(line)
 | 
			
		||||
                    if match:
 | 
			
		||||
                        context.result.add_metric((match.group('key') + "_start"),
 | 
			
		||||
                                                  match.group('value1'))
 | 
			
		||||
                        context.result.add_metric((match.group('key') + "_finish"),
 | 
			
		||||
                                                  match.group('value2'))
 | 
			
		||||
                        context.result.add_metric((match.group('key') + "_duration"),
 | 
			
		||||
                                                  match.group('value3'))
 | 
			
		||||
        with open(result_file, 'r') as wfh:
 | 
			
		||||
            regex = re.compile(r'(?P<key>\w+)\s+(?P<value1>\d+)\s+(?P<value2>\d+)\s+(?P<value3>\d+)')
 | 
			
		||||
            for line in wfh:
 | 
			
		||||
                match = regex.search(line)
 | 
			
		||||
                if match:
 | 
			
		||||
                    context.result.add_metric((match.group('key') + "_start"),
 | 
			
		||||
                                              match.group('value1'))
 | 
			
		||||
                    context.result.add_metric((match.group('key') + "_finish"),
 | 
			
		||||
                                              match.group('value2'))
 | 
			
		||||
                    context.result.add_metric((match.group('key') + "_duration"),
 | 
			
		||||
                                              match.group('value3'))
 | 
			
		||||
 | 
			
		||||
    def teardown(self, context):
 | 
			
		||||
        super(Gmail, self).teardown(context)
 | 
			
		||||
 | 
			
		||||
        for file in self.device.listdir(self.device.working_directory):
 | 
			
		||||
            if file.startswith (self.name) and file.endswith(".log"):
 | 
			
		||||
            if file.endswith(".log"):
 | 
			
		||||
                self.device.pull_file(os.path.join(self.device.working_directory, file), context.output_directory)
 | 
			
		||||
                self.device.delete_file(os.path.join(self.device.working_directory, file))
 | 
			
		||||
            if file.endswith(".jpg"):
 | 
			
		||||
                self.device.delete_file(os.path.join(self.device.working_directory, file))
 | 
			
		||||
 | 
			
		||||
        # 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')
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							@@ -1,24 +1,16 @@
 | 
			
		||||
package com.arm.wlauto.uiauto.gmail;
 | 
			
		||||
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.os.SystemClock;
 | 
			
		||||
 | 
			
		||||
// 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;
 | 
			
		||||
 | 
			
		||||
import java.io.BufferedWriter;
 | 
			
		||||
import java.io.FileWriter;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.LinkedHashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Map.Entry;
 | 
			
		||||
 | 
			
		||||
public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
 | 
			
		||||
@@ -31,21 +23,15 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
    public void runUiAutomation() throws Exception {
 | 
			
		||||
        parameters = getParams();
 | 
			
		||||
 | 
			
		||||
        Timer result = new Timer();
 | 
			
		||||
        result.start();
 | 
			
		||||
 | 
			
		||||
        clearFirstRunDialogues();
 | 
			
		||||
 | 
			
		||||
        clickNewMail();
 | 
			
		||||
        attachFiles();
 | 
			
		||||
        setToField();
 | 
			
		||||
        setSubjectField();
 | 
			
		||||
        setComposeField();
 | 
			
		||||
        attachFiles();
 | 
			
		||||
        clickSendButton();
 | 
			
		||||
 | 
			
		||||
        result.end();
 | 
			
		||||
        timingResults.put("Total", result);
 | 
			
		||||
 | 
			
		||||
        writeResultsToFile(timingResults, parameters.getString("output_file"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -53,22 +39,22 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
        // Enter search text into the file searchBox.  This will automatically filter the list.
 | 
			
		||||
        UiObject gotItBox = getUiObjectByResourceId("com.google.android.gm:id/welcome_tour_got_it",
 | 
			
		||||
                                                     "android.widget.TextView");
 | 
			
		||||
        gotItBox.clickAndWaitForNewWindow();
 | 
			
		||||
        clickUiObject(gotItBox, timeout);
 | 
			
		||||
        UiObject takeMeToBox = getUiObjectByText("Take me to Gmail", "android.widget.TextView");
 | 
			
		||||
        takeMeToBox.clickAndWaitForNewWindow();
 | 
			
		||||
        clickUiObject(takeMeToBox, timeout);
 | 
			
		||||
        UiObject converationView = new UiObject(new UiSelector()
 | 
			
		||||
                                            .resourceId("com.google.android.gm:id/conversation_list_view")
 | 
			
		||||
                                            .className("android.widget.ListView"));
 | 
			
		||||
        if (!converationView.waitForExists(networkTimeout)) {
 | 
			
		||||
            throw new UiObjectNotFoundException("Could not find \"converationView\".");
 | 
			
		||||
        };
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void clickNewMail() throws Exception {
 | 
			
		||||
        Timer result = new Timer();
 | 
			
		||||
        UiObject newMailButton = getUiObjectByDescription("Compose", "android.widget.ImageButton");
 | 
			
		||||
        result.start();
 | 
			
		||||
        newMailButton.clickAndWaitForNewWindow(timeout);
 | 
			
		||||
        clickUiObject(newMailButton, timeout);
 | 
			
		||||
        result.end();
 | 
			
		||||
        timingResults.put("newMail", result);
 | 
			
		||||
    }
 | 
			
		||||
@@ -108,7 +94,7 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
        Timer result = new Timer();
 | 
			
		||||
        UiObject sendButton = getUiObjectByDescription("Send", "android.widget.TextView");
 | 
			
		||||
        result.start();
 | 
			
		||||
        sendButton.clickAndWaitForNewWindow(timeout);
 | 
			
		||||
        clickUiObject(sendButton, timeout);
 | 
			
		||||
        result.end();
 | 
			
		||||
        timingResults.put("Send", result);
 | 
			
		||||
    }
 | 
			
		||||
@@ -118,45 +104,66 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
        UiObject attachIcon = getUiObjectByResourceId("com.google.android.gm:id/add_attachment",
 | 
			
		||||
                                                      "android.widget.TextView");
 | 
			
		||||
 | 
			
		||||
        String [] imageFiles = {"1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"};
 | 
			
		||||
        String[] imageFiles = {"1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"};
 | 
			
		||||
 | 
			
		||||
        result.start();
 | 
			
		||||
        for ( int i = 0; i < imageFiles.length; i++) {
 | 
			
		||||
            result.start();
 | 
			
		||||
 | 
			
		||||
        for ( int i=0; i < imageFiles.length; i++) {
 | 
			
		||||
            attachIcon.clickAndWaitForNewWindow(timeout);
 | 
			
		||||
            clickUiObject(attachIcon, timeout);
 | 
			
		||||
            UiObject attachFile = getUiObjectByText("Attach file", "android.widget.TextView");
 | 
			
		||||
            attachFile.clickAndWaitForNewWindow(timeout);
 | 
			
		||||
            UiObject imagesEntry = getUiObjectByText("Images", "android.widget.TextView");
 | 
			
		||||
            imagesEntry.clickAndWaitForNewWindow(timeout);
 | 
			
		||||
            UiObject listView = new UiObject(new UiSelector().textContains("List view")
 | 
			
		||||
                                                             .className("android.webkit.WebView"));
 | 
			
		||||
            if (listView.exists()) {
 | 
			
		||||
                listView.clickAndWaitForNewWindow(timeout);
 | 
			
		||||
            clickUiObject(attachFile, timeout);
 | 
			
		||||
 | 
			
		||||
            UiObject titleIsWaWorking = new UiObject(new UiSelector()
 | 
			
		||||
                                                .className("android.widget.TextView")
 | 
			
		||||
                                                .textContains("wa-working"));
 | 
			
		||||
            UiObject titleIsImages = new UiObject(new UiSelector()
 | 
			
		||||
                                                .className("android.widget.TextView")
 | 
			
		||||
                                                .textContains("Images"));
 | 
			
		||||
            UiObject frameLayout = new UiObject(new UiSelector()
 | 
			
		||||
                                                .className("android.widget.FrameLayout")
 | 
			
		||||
                                                .resourceId("android:id/action_bar_container"));
 | 
			
		||||
            UiObject rootMenu = new UiObject(new UiSelector()
 | 
			
		||||
                                                .className("android.widget.ImageButton")
 | 
			
		||||
                                                .descriptionContains("Show roots"));
 | 
			
		||||
            UiObject imagesEntry = new UiObject(new UiSelector()
 | 
			
		||||
                                                .className("android.widget.TextView")
 | 
			
		||||
                                                .textContains("Images"));
 | 
			
		||||
            UiObject waFolder =  new UiObject(new UiSelector()
 | 
			
		||||
                                                .className("android.widget.TextView")
 | 
			
		||||
                                                .textContains("wa-working"));
 | 
			
		||||
 | 
			
		||||
            // Some devices use a FrameLayout as oppoised to a view Group so treat them differently
 | 
			
		||||
            if (frameLayout.exists()) {
 | 
			
		||||
                imagesEntry.click();
 | 
			
		||||
                waitObject(titleIsImages, 4);
 | 
			
		||||
                waFolder.click();
 | 
			
		||||
                waitObject(titleIsWaWorking, 4);
 | 
			
		||||
            } else {
 | 
			
		||||
                // Portrait devices will roll the menu up so click the root menu icon
 | 
			
		||||
                if (!titleIsWaWorking.exists()) {
 | 
			
		||||
                    if (rootMenu.exists()) {
 | 
			
		||||
                       rootMenu.click();
 | 
			
		||||
                    }
 | 
			
		||||
                    imagesEntry.click();
 | 
			
		||||
                    waitObject(titleIsImages, 4);
 | 
			
		||||
                    waFolder.click();
 | 
			
		||||
                    waitObject(titleIsWaWorking, 4);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            UiObject cameraEntry = getUiObjectByText("Camera", "android.widget.TextView");
 | 
			
		||||
            cameraEntry.clickAndWaitForNewWindow(timeout);
 | 
			
		||||
            UiObject oneJpg = getUiObjectByText(imageFiles[i], "android.widget.TextView");
 | 
			
		||||
            oneJpg.clickAndWaitForNewWindow(timeout);
 | 
			
		||||
 | 
			
		||||
            UiObject imageFileButton = new UiObject(new UiSelector()
 | 
			
		||||
                                                .resourceId("com.android.documentsui:id/grid")
 | 
			
		||||
                                                .className("android.widget.GridView")
 | 
			
		||||
                                                .childSelector(new UiSelector()
 | 
			
		||||
                                                .index(i).className("android.widget.FrameLayout")));
 | 
			
		||||
 | 
			
		||||
            clickUiObject(imageFileButton, timeout);
 | 
			
		||||
 | 
			
		||||
            result.end();
 | 
			
		||||
 | 
			
		||||
            // Replace whitespace and full stops within the filename
 | 
			
		||||
            String file = imageFiles[i].replaceAll("\\.", "_").replaceAll("\\s+", "_");
 | 
			
		||||
            timingResults.put(String.format("AttachFiles" + "_" + file), result);
 | 
			
		||||
        }
 | 
			
		||||
        result.end();
 | 
			
		||||
        timingResults.put("AttachFiles", result);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private 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();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										96
									
								
								wlauto/workloads/googlephotos/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								wlauto/workloads/googlephotos/__init__.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,96 @@
 | 
			
		||||
import os
 | 
			
		||||
import re
 | 
			
		||||
 | 
			
		||||
from wlauto import AndroidUiAutoBenchmark, Parameter
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Googlephotos(AndroidUiAutoBenchmark):
 | 
			
		||||
 | 
			
		||||
    name = 'googlephotos'
 | 
			
		||||
    package = 'com.google.android.apps.photos'
 | 
			
		||||
    activity = 'com.google.android.apps.photos.home.HomeActivity'
 | 
			
		||||
 | 
			
		||||
    description = """
 | 
			
		||||
    A workload to perform standard productivity tasks with googlephotos.
 | 
			
		||||
 | 
			
		||||
    The workload carries out various tasks, such as browsing images, performing zooms,
 | 
			
		||||
    postprocessing and saving a selected image to file.
 | 
			
		||||
 | 
			
		||||
    NOTE: This workload requires four jpeg files to be placed in the
 | 
			
		||||
    dependencies directory to run.
 | 
			
		||||
 | 
			
		||||
    Although this workload attempts to be network independent it requires a
 | 
			
		||||
    network connection (ideally, wifi) to run. This is because the welcome
 | 
			
		||||
    screen UI is dependent on an existing connection.
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    parameters = [
 | 
			
		||||
        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.
 | 
			
		||||
                  """),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    instrumentation_log = ''.join([name, '_instrumentation.log'])
 | 
			
		||||
    file_prefix = 'wa_test_'
 | 
			
		||||
 | 
			
		||||
    def __init__(self, device, **kwargs):
 | 
			
		||||
        super(Googlephotos, self).__init__(device, **kwargs)
 | 
			
		||||
        self.output_file = os.path.join(self.device.working_directory, self.instrumentation_log)
 | 
			
		||||
 | 
			
		||||
    def validate(self):
 | 
			
		||||
        super(Googlephotos, self).validate()
 | 
			
		||||
        self.uiauto_params['package'] = self.package
 | 
			
		||||
        self.uiauto_params['output_dir'] = self.device.working_directory
 | 
			
		||||
        self.uiauto_params['output_file'] = self.output_file
 | 
			
		||||
        self.uiauto_params['dumpsys_enabled'] = self.dumpsys_enabled
 | 
			
		||||
 | 
			
		||||
    def setup(self, context):
 | 
			
		||||
        super(Googlephotos, self).setup(context)
 | 
			
		||||
 | 
			
		||||
        for entry in os.listdir(self.dependencies_directory):
 | 
			
		||||
            wa_file = ''.join([self.file_prefix, entry])
 | 
			
		||||
            if entry.endswith(".jpg"):
 | 
			
		||||
                self.device.push_file(os.path.join(self.dependencies_directory, entry),
 | 
			
		||||
                                      os.path.join(self.device.working_directory, wa_file),
 | 
			
		||||
                                      timeout=300)
 | 
			
		||||
 | 
			
		||||
        # 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')
 | 
			
		||||
 | 
			
		||||
    def update_result(self, context):
 | 
			
		||||
        super(Googlephotos, self).update_result(context)
 | 
			
		||||
 | 
			
		||||
        if self.dumpsys_enabled:
 | 
			
		||||
            self.device.pull_file(self.output_file, context.output_directory)
 | 
			
		||||
            result_file = os.path.join(context.output_directory, self.instrumentation_log)
 | 
			
		||||
 | 
			
		||||
            with open(result_file, 'r') as wfh:
 | 
			
		||||
                pattern = r'(?P<key>\w+)\s+(?P<value1>\d+)\s+(?P<value2>\d+)\s+(?P<value3>\d+)'
 | 
			
		||||
                regex = re.compile(pattern)
 | 
			
		||||
                for line in wfh:
 | 
			
		||||
                    match = regex.search(line)
 | 
			
		||||
                    if match:
 | 
			
		||||
                        context.result.add_metric((match.group('key') + "_start"),
 | 
			
		||||
                                                  match.group('value1'))
 | 
			
		||||
                        context.result.add_metric((match.group('key') + "_finish"),
 | 
			
		||||
                                                  match.group('value2'))
 | 
			
		||||
                        context.result.add_metric((match.group('key') + "_duration"),
 | 
			
		||||
                                                  match.group('value3'))
 | 
			
		||||
 | 
			
		||||
    def teardown(self, context):
 | 
			
		||||
        super(Googlephotos, self).teardown(context)
 | 
			
		||||
 | 
			
		||||
        for entry in self.device.listdir(self.device.working_directory):
 | 
			
		||||
            if entry.startswith(self.name) and entry.endswith(".log"):
 | 
			
		||||
                self.device.pull_file(os.path.join(self.device.working_directory, entry),
 | 
			
		||||
                                      context.output_directory)
 | 
			
		||||
                self.device.delete_file(os.path.join(self.device.working_directory, entry))
 | 
			
		||||
 | 
			
		||||
            if entry.startswith(self.file_prefix) and entry.endswith(".jpg"):
 | 
			
		||||
                self.device.delete_file(os.path.join(self.device.working_directory, entry))
 | 
			
		||||
 | 
			
		||||
        # Force a re-index of the mediaserver cache to removed cached files
 | 
			
		||||
        self.device.execute('am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///sdcard')
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										12
									
								
								wlauto/workloads/googlephotos/uiauto/build.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										12
									
								
								wlauto/workloads/googlephotos/uiauto/build.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
#!/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
 | 
			
		||||
 | 
			
		||||
if [[ -f bin/com.arm.wlauto.uiauto.googlephotos.jar ]]; then
 | 
			
		||||
    cp bin/com.arm.wlauto.uiauto.googlephotos.jar ..
 | 
			
		||||
fi
 | 
			
		||||
							
								
								
									
										92
									
								
								wlauto/workloads/googlephotos/uiauto/build.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								wlauto/workloads/googlephotos/uiauto/build.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,92 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project name="com.arm.wlauto.uiauto.googlephotos" 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>
 | 
			
		||||
							
								
								
									
										14
									
								
								wlauto/workloads/googlephotos/uiauto/project.properties
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								wlauto/workloads/googlephotos/uiauto/project.properties
									
									
									
									
									
										Normal 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
 | 
			
		||||
@@ -0,0 +1,196 @@
 | 
			
		||||
package com.arm.wlauto.uiauto.googlephotos;
 | 
			
		||||
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
 | 
			
		||||
// Import the uiautomator libraries
 | 
			
		||||
import com.android.uiautomator.core.UiObject;
 | 
			
		||||
import com.android.uiautomator.core.UiObjectNotFoundException;
 | 
			
		||||
import com.android.uiautomator.core.UiSelector;
 | 
			
		||||
 | 
			
		||||
import com.arm.wlauto.uiauto.UxPerfUiAutomation;
 | 
			
		||||
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
import java.util.LinkedHashMap;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Map.Entry;
 | 
			
		||||
 | 
			
		||||
public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
 | 
			
		||||
    public static String TAG = "uxperf_googlephotos";
 | 
			
		||||
 | 
			
		||||
    public Bundle parameters;
 | 
			
		||||
    private int viewTimeoutSecs = 10;
 | 
			
		||||
    private long viewTimeout =  TimeUnit.SECONDS.toMillis(viewTimeoutSecs);
 | 
			
		||||
    private LinkedHashMap<String, Timer> timingResults = new LinkedHashMap<String, Timer>();
 | 
			
		||||
 | 
			
		||||
    public void runUiAutomation() throws Exception {
 | 
			
		||||
        parameters = getParams();
 | 
			
		||||
 | 
			
		||||
        confirmLocalFileAccess();
 | 
			
		||||
        dismissWelcomeView();
 | 
			
		||||
        gesturesTest();
 | 
			
		||||
        editPhotoTest();
 | 
			
		||||
 | 
			
		||||
        writeResultsToFile(timingResults, parameters.getString("output_file"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void confirmLocalFileAccess() throws Exception {
 | 
			
		||||
        // First time run requires confirmation to allow access to local files
 | 
			
		||||
        UiObject allowButton = new UiObject(new UiSelector().textContains("Allow")
 | 
			
		||||
                                                            .className("android.widget.Button"));
 | 
			
		||||
        if (allowButton.waitForExists(timeout)) {
 | 
			
		||||
            allowButton.clickAndWaitForNewWindow(timeout);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private void dismissWelcomeView() throws Exception {
 | 
			
		||||
 | 
			
		||||
        // Click through the first two pages and make sure that we don't sign
 | 
			
		||||
        // in to our google account. This ensures the same set of photographs
 | 
			
		||||
        // are placed in the camera directory for each run.
 | 
			
		||||
 | 
			
		||||
        sleep(5); // Pause while splash screen loads
 | 
			
		||||
 | 
			
		||||
        UiObject getStartedButton =
 | 
			
		||||
            new UiObject (new UiSelector().textContains("Get started")
 | 
			
		||||
                                          .className("android.widget.Button"));
 | 
			
		||||
 | 
			
		||||
        tapDisplayCentre();
 | 
			
		||||
        waitObject(getStartedButton, 10);
 | 
			
		||||
 | 
			
		||||
        getStartedButton.clickAndWaitForNewWindow();
 | 
			
		||||
 | 
			
		||||
        UiObject welcomeButton =
 | 
			
		||||
            getUiObjectByResourceId("com.google.android.apps.photos:id/name",
 | 
			
		||||
                                    "android.widget.TextView");
 | 
			
		||||
        welcomeButton.clickAndWaitForNewWindow();
 | 
			
		||||
 | 
			
		||||
        UiObject useWithoutAccount =
 | 
			
		||||
            getUiObjectByText("Use without an account", "android.widget.TextView");
 | 
			
		||||
        useWithoutAccount.clickAndWaitForNewWindow();
 | 
			
		||||
 | 
			
		||||
        // Dismiss welcome views promoting app features
 | 
			
		||||
        sleep(1);
 | 
			
		||||
        uiDeviceSwipeLeft(10);
 | 
			
		||||
        sleep(1);
 | 
			
		||||
        uiDeviceSwipeLeft(10);
 | 
			
		||||
        sleep(1);
 | 
			
		||||
        uiDeviceSwipeLeft(10);
 | 
			
		||||
        sleep(1);
 | 
			
		||||
 | 
			
		||||
        UiObject nextButton =
 | 
			
		||||
            getUiObjectByResourceId("com.google.android.apps.photos:id/next_button",
 | 
			
		||||
                                    "android.widget.ImageView");
 | 
			
		||||
        nextButton.clickAndWaitForNewWindow();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void gesturesTest() throws Exception {
 | 
			
		||||
        String testTag = "gestures";
 | 
			
		||||
 | 
			
		||||
        // Perform a range of swipe tests while browsing photo gallery
 | 
			
		||||
        LinkedHashMap<String, GestureTestParams> testParams = new LinkedHashMap<String, GestureTestParams>();
 | 
			
		||||
        testParams.put("swipe_left", new GestureTestParams(GestureType.UIDEVICE_SWIPE, Direction.LEFT, 10));
 | 
			
		||||
        testParams.put("pinch_out", new GestureTestParams(GestureType.PINCH, PinchType.OUT, 100, 50));
 | 
			
		||||
        testParams.put("pinch_in", new GestureTestParams(GestureType.PINCH, PinchType.IN, 100, 50));
 | 
			
		||||
        testParams.put("swipe_right", new GestureTestParams(GestureType.UIDEVICE_SWIPE, Direction.RIGHT, 10));
 | 
			
		||||
 | 
			
		||||
        Iterator<Entry<String, GestureTestParams>> it = testParams.entrySet().iterator();
 | 
			
		||||
 | 
			
		||||
        // Select third photograph
 | 
			
		||||
        selectPhoto(2);
 | 
			
		||||
 | 
			
		||||
        while (it.hasNext()) {
 | 
			
		||||
            Map.Entry<String, GestureTestParams> pair = it.next();
 | 
			
		||||
            GestureType type = pair.getValue().gestureType;
 | 
			
		||||
            Direction dir = pair.getValue().gestureDirection;
 | 
			
		||||
            PinchType pinch = pair.getValue().pinchType;
 | 
			
		||||
            int steps = pair.getValue().steps;
 | 
			
		||||
            int percent = pair.getValue().percent;
 | 
			
		||||
 | 
			
		||||
            String runName = String.format(testTag + "_" + pair.getKey());
 | 
			
		||||
            String gfxInfologName =  String.format(TAG + "_" + runName + "_gfxInfo.log");
 | 
			
		||||
            String surfFlingerlogName =  String.format(runName + "_surfFlinger.log");
 | 
			
		||||
            String viewName = new String("com.google.android.apps.photos.home.HomeActivity");
 | 
			
		||||
 | 
			
		||||
            UiObject view = new UiObject(new UiSelector().enabled(true));
 | 
			
		||||
 | 
			
		||||
            if (!view.waitForExists(viewTimeout)) {
 | 
			
		||||
                throw new UiObjectNotFoundException("Could not find \"photo view\".");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            startDumpsysGfxInfo(parameters);
 | 
			
		||||
            startDumpsysSurfaceFlinger(parameters, viewName);
 | 
			
		||||
 | 
			
		||||
            Timer results = new Timer();
 | 
			
		||||
 | 
			
		||||
            switch (type) {
 | 
			
		||||
                case UIDEVICE_SWIPE:
 | 
			
		||||
                    results = uiDeviceSwipeTest(dir, steps);
 | 
			
		||||
                    break;
 | 
			
		||||
                case UIOBJECT_SWIPE:
 | 
			
		||||
                    results = uiObjectSwipeTest(view, dir, steps);
 | 
			
		||||
                    break;
 | 
			
		||||
                case PINCH:
 | 
			
		||||
                    results = uiObjectVertPinchTest(view, pinch, steps, percent);
 | 
			
		||||
                    break;
 | 
			
		||||
                default:
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            stopDumpsysSurfaceFlinger(parameters, viewName, surfFlingerlogName);
 | 
			
		||||
            stopDumpsysGfxInfo(parameters, gfxInfologName);
 | 
			
		||||
 | 
			
		||||
            timingResults.put(runName, results);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        UiObject navigateUpButton =
 | 
			
		||||
            getUiObjectByDescription("Navigate Up", "android.widget.ImageButton");
 | 
			
		||||
        navigateUpButton.click();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void editPhotoTest() throws Exception {
 | 
			
		||||
        String testTag = "edit_photo";
 | 
			
		||||
 | 
			
		||||
        Timer result = new Timer();
 | 
			
		||||
        result.start();
 | 
			
		||||
 | 
			
		||||
        // Select first photograph
 | 
			
		||||
        selectPhoto(0);
 | 
			
		||||
        UiObject editView = getUiObjectByResourceId("com.google.android.apps.photos:id/edit",
 | 
			
		||||
                                                    "android.widget.ImageView");
 | 
			
		||||
        editView.click();
 | 
			
		||||
 | 
			
		||||
        UiObject editColor = getUiObjectByText("Colour", "android.widget.RadioButton");
 | 
			
		||||
        editColor.click();
 | 
			
		||||
 | 
			
		||||
        UiObject seekBar = getUiObjectByResourceId("com.google.android.apps.photos:id/cpe_strength_seek_bar",
 | 
			
		||||
                                                   "android.widget.SeekBar");
 | 
			
		||||
        seekBar.swipeLeft(10);
 | 
			
		||||
 | 
			
		||||
        UiObject accept = getUiObjectByDescription("Accept", "android.widget.ImageView");
 | 
			
		||||
        accept.click();
 | 
			
		||||
 | 
			
		||||
        UiObject save = getUiObjectByText("SAVE", "android.widget.TextView");
 | 
			
		||||
        save.click();
 | 
			
		||||
 | 
			
		||||
        // Return to application home screen
 | 
			
		||||
        getUiDevice().pressBack();
 | 
			
		||||
 | 
			
		||||
        result.end();
 | 
			
		||||
        timingResults.put(testTag, result);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Helper to click on an individual photographs based on index in wa-working gallery.
 | 
			
		||||
    private void selectPhoto(final int index) throws Exception {
 | 
			
		||||
        UiObject cameraHeading = new UiObject(new UiSelector().text("wa-working"));
 | 
			
		||||
        cameraHeading.clickAndWaitForNewWindow();
 | 
			
		||||
 | 
			
		||||
        UiObject photo =
 | 
			
		||||
            new UiObject(new UiSelector().resourceId("com.google.android.apps.photos:id/recycler_view")
 | 
			
		||||
                                         .childSelector(new UiSelector()
 | 
			
		||||
                                         .index(index)));
 | 
			
		||||
        photo.click();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -65,21 +65,20 @@ class Reader(AndroidUiAutoBenchmark):
 | 
			
		||||
    def update_result(self, context):
 | 
			
		||||
        super(Reader, self).update_result(context)
 | 
			
		||||
 | 
			
		||||
        if self.dumpsys_enabled:
 | 
			
		||||
            self.device.pull_file(self.output_file, context.output_directory)
 | 
			
		||||
            result_file = os.path.join(context.output_directory, self.instrumentation_log)
 | 
			
		||||
        self.device.pull_file(self.output_file, context.output_directory)
 | 
			
		||||
        result_file = os.path.join(context.output_directory, self.instrumentation_log)
 | 
			
		||||
 | 
			
		||||
            with open(result_file, 'r') as wfh:
 | 
			
		||||
                regex = re.compile(r'(?P<key>\w+)\s+(?P<value1>\d+)\s+(?P<value2>\d+)\s+(?P<value3>\d+)')
 | 
			
		||||
                for line in wfh:
 | 
			
		||||
                    match = regex.search(line)
 | 
			
		||||
                    if match:
 | 
			
		||||
                        context.result.add_metric((match.group('key') + "_start"),
 | 
			
		||||
                                                  match.group('value1'))
 | 
			
		||||
                        context.result.add_metric((match.group('key') + "_finish"),
 | 
			
		||||
                                                  match.group('value2'))
 | 
			
		||||
                        context.result.add_metric((match.group('key') + "_duration"),
 | 
			
		||||
                                                  match.group('value3'))
 | 
			
		||||
        with open(result_file, 'r') as wfh:
 | 
			
		||||
            regex = re.compile(r'(?P<key>\w+)\s+(?P<value1>\d+)\s+(?P<value2>\d+)\s+(?P<value3>\d+)')
 | 
			
		||||
            for line in wfh:
 | 
			
		||||
                match = regex.search(line)
 | 
			
		||||
                if match:
 | 
			
		||||
                    context.result.add_metric((match.group('key') + "_start"),
 | 
			
		||||
                                              match.group('value1'))
 | 
			
		||||
                    context.result.add_metric((match.group('key') + "_finish"),
 | 
			
		||||
                                              match.group('value2'))
 | 
			
		||||
                    context.result.add_metric((match.group('key') + "_duration"),
 | 
			
		||||
                                              match.group('value3'))
 | 
			
		||||
 | 
			
		||||
    def teardown(self, context):
 | 
			
		||||
        super(Reader, self).teardown(context)
 | 
			
		||||
@@ -88,6 +87,6 @@ class Reader(AndroidUiAutoBenchmark):
 | 
			
		||||
                self.device.delete_file(os.path.join(self.reader_local_dir, file))
 | 
			
		||||
 | 
			
		||||
        for file in self.device.listdir(self.device.working_directory):
 | 
			
		||||
            if file.startswith (self.name) and file.endswith(".log"):
 | 
			
		||||
            if file.endswith(".log"):
 | 
			
		||||
                self.device.pull_file(os.path.join(self.device.working_directory, file), context.output_directory)
 | 
			
		||||
                self.device.delete_file(os.path.join(self.device.working_directory, file))
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							@@ -7,19 +7,13 @@ import android.os.SystemClock;
 | 
			
		||||
// 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.core.UiCollection;
 | 
			
		||||
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
 | 
			
		||||
 | 
			
		||||
import com.arm.wlauto.uiauto.UxPerfUiAutomation;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.FileWriter;
 | 
			
		||||
import java.io.BufferedWriter;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
import java.util.LinkedHashMap;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.LinkedHashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Map.Entry;
 | 
			
		||||
 | 
			
		||||
@@ -33,8 +27,6 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
    private LinkedHashMap<String, Timer> timingResults = new LinkedHashMap<String, Timer>();
 | 
			
		||||
 | 
			
		||||
    public void runUiAutomation() throws Exception {
 | 
			
		||||
        Timer result = new Timer();
 | 
			
		||||
        result.start();
 | 
			
		||||
        parameters = getParams();
 | 
			
		||||
 | 
			
		||||
        dismissWelcomeView();
 | 
			
		||||
@@ -45,12 +37,9 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
 | 
			
		||||
        gesturesTest("Getting Started.pdf");
 | 
			
		||||
 | 
			
		||||
        String [] searchStrings = {"Glossary", "cortex"};
 | 
			
		||||
        String[] searchStrings = {"Glossary", "cortex"};
 | 
			
		||||
        searchPdfTest("cortex_m4", searchStrings);
 | 
			
		||||
 | 
			
		||||
        result.end();
 | 
			
		||||
        timingResults.put("Total", result);
 | 
			
		||||
 | 
			
		||||
        writeResultsToFile(timingResults, parameters.getString("output_file"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -72,8 +61,8 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
        int i = 0;
 | 
			
		||||
        do {
 | 
			
		||||
            i += 10;
 | 
			
		||||
            tapDisplay(webViewCoords.centerX(), webViewCoords.bottom - i);
 | 
			
		||||
        } while ( welcomeView.exists() || i < webViewCoords.top  );
 | 
			
		||||
            tapDisplay(webViewCoords.centerX(), webViewCoords.centerY() + i);
 | 
			
		||||
        } while (welcomeView.exists() || i < webViewCoords.top);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void signInOnline(Bundle parameters) throws Exception {
 | 
			
		||||
@@ -139,17 +128,20 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
                                                            .className("android.widget.Button"));
 | 
			
		||||
        if (allowButton.waitForExists(timeout)) {
 | 
			
		||||
            allowButton.clickAndWaitForNewWindow(timeout);
 | 
			
		||||
        };
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void openFile(String filename) throws Exception {
 | 
			
		||||
    private void openFile(final String filename) throws Exception {
 | 
			
		||||
 | 
			
		||||
        String TestTag = "openfile";
 | 
			
		||||
 | 
			
		||||
        // Replace whitespace and full stops within the filename
 | 
			
		||||
        String file = filename.replaceAll("\\.", "_").replaceAll("\\s+", "_");
 | 
			
		||||
 | 
			
		||||
        timingResults.put(String.format("selectLocalFilesList" + "_" + file), selectLocalFilesList());
 | 
			
		||||
        timingResults.put(String.format("selectSearchDuration" + "_" + file), selectSearchFileButton());
 | 
			
		||||
        timingResults.put(String.format("searchFileList" + "_" + file), searchFileList(filename));
 | 
			
		||||
        timingResults.put(String.format("openFileFromList" + "_" + file), openFileFromList(filename));
 | 
			
		||||
        timingResults.put(String.format(TestTag + "_" + "selectLocalFilesList" + "_" + file), selectLocalFilesList());
 | 
			
		||||
        timingResults.put(String.format(TestTag + "_" + "selectSearchDuration" + "_" + file), selectSearchFileButton());
 | 
			
		||||
        timingResults.put(String.format(TestTag + "_" + "searchFileList" + "_" + file), searchFileList(filename));
 | 
			
		||||
        timingResults.put(String.format(TestTag + "_" + "openFileFromList" + "_" + file), openFileFromList(filename));
 | 
			
		||||
 | 
			
		||||
        // Cludge to get rid of the first time run help dialogue boxes
 | 
			
		||||
        tapDisplayCentre();
 | 
			
		||||
@@ -181,7 +173,7 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Timer searchFileList(String searchText) throws Exception {
 | 
			
		||||
    private Timer searchFileList(final String searchText) throws Exception {
 | 
			
		||||
        // Enter search text into the file searchBox.  This will automatically filter the list.
 | 
			
		||||
        UiObject searchBox = getUiObjectByResourceId("android:id/search_src_text",
 | 
			
		||||
                                                     "android.widget.EditText");
 | 
			
		||||
@@ -193,7 +185,7 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Timer openFileFromList(String file) throws Exception {
 | 
			
		||||
    private Timer openFileFromList(final String file) throws Exception {
 | 
			
		||||
        // Open a file from a file list view by searching for UiObjects containing the doc title.
 | 
			
		||||
        UiObject fileObject = getUiObjectByText(file, "android.widget.TextView");
 | 
			
		||||
        Timer result = new Timer();
 | 
			
		||||
@@ -209,31 +201,7 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private class GestureTestParams {
 | 
			
		||||
        GestureType gestureType;
 | 
			
		||||
        Direction gestureDirection;
 | 
			
		||||
        PinchType pinchType;
 | 
			
		||||
        int percent;
 | 
			
		||||
        int steps;
 | 
			
		||||
 | 
			
		||||
        GestureTestParams(GestureType gesture, Direction direction, int steps) {
 | 
			
		||||
            this.gestureType = gesture;
 | 
			
		||||
            this.gestureDirection = direction;
 | 
			
		||||
            this.pinchType = PinchType.NULL;
 | 
			
		||||
            this.steps = steps;
 | 
			
		||||
            this.percent = 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void gesturesTest (String filename) throws Exception {
 | 
			
		||||
    private void gesturesTest(final String filename) throws Exception {
 | 
			
		||||
 | 
			
		||||
        String TestTag = "gestures";
 | 
			
		||||
 | 
			
		||||
@@ -259,14 +227,14 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
            int percent = pair.getValue().percent;
 | 
			
		||||
 | 
			
		||||
            String runName = String.format(TestTag + "_" + pair.getKey());
 | 
			
		||||
            String gfxInfologName =  String.format(TAG + "_" + runName + "_gfxInfo.log");
 | 
			
		||||
            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();
 | 
			
		||||
            startDumpsysSurfaceFlinger(viewName);
 | 
			
		||||
            startDumpsysGfxInfo(parameters);
 | 
			
		||||
            startDumpsysSurfaceFlinger(parameters, viewName);
 | 
			
		||||
 | 
			
		||||
            Timer results = new Timer();
 | 
			
		||||
 | 
			
		||||
@@ -284,8 +252,8 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            stopDumpsysSurfaceFlinger(viewName, surfFlingerlogName);
 | 
			
		||||
            stopDumpsysGfxInfo(gfxInfologName);
 | 
			
		||||
            stopDumpsysSurfaceFlinger(parameters, viewName, surfFlingerlogName);
 | 
			
		||||
            stopDumpsysGfxInfo(parameters, gfxInfologName);
 | 
			
		||||
 | 
			
		||||
            timingResults.put(runName, results);
 | 
			
		||||
        }
 | 
			
		||||
@@ -293,7 +261,7 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
        exitDocument();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void searchPdfTest (String filename, String [] searchStrings) throws Exception {
 | 
			
		||||
    private void searchPdfTest(final String filename, final String[] searchStrings) throws Exception {
 | 
			
		||||
 | 
			
		||||
        String TestTag = "search";
 | 
			
		||||
 | 
			
		||||
@@ -302,7 +270,7 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
        // Get the page view for the opened document which we can use for pinch actions
 | 
			
		||||
        UiObject pageView = getUiObjectByResourceId("com.adobe.reader:id/pageView",
 | 
			
		||||
                                                    "android.widget.RelativeLayout");
 | 
			
		||||
        for ( int i=0; i < searchStrings.length; i++) {
 | 
			
		||||
        for (int i = 0; i < searchStrings.length; i++) {
 | 
			
		||||
            timingResults.put(String.format(TestTag + "_" + i),
 | 
			
		||||
                                            searchTest(searchStrings[i]));
 | 
			
		||||
        }
 | 
			
		||||
@@ -310,7 +278,7 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
        exitDocument();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Timer searchTest(String searchText) throws Exception {
 | 
			
		||||
    private Timer searchTest(final String searchText) throws Exception {
 | 
			
		||||
        // Click on the search button icon and enter text in the box.  This closes the keyboad
 | 
			
		||||
        // so click the box again and press Enter to start the search.
 | 
			
		||||
        UiObject searchButton = getUiObjectByResourceId("com.adobe.reader:id/document_view_search_icon",
 | 
			
		||||
@@ -353,47 +321,4 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
        UiObject upButton = getUiObjectByResourceId("android:id/up", "android.widget.ImageView" );
 | 
			
		||||
        upButton.clickAndWaitForNewWindow();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private 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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void startDumpsysSurfaceFlinger(String view) {
 | 
			
		||||
        if (Boolean.parseBoolean(parameters.getString("dumpsys_enabled"))) {
 | 
			
		||||
            initDumpsysSurfaceFlinger(parameters.getString("package"), view);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void stopDumpsysSurfaceFlinger(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);
 | 
			
		||||
          }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void startDumpsysGfxInfo() {
 | 
			
		||||
        if (Boolean.parseBoolean(parameters.getString("dumpsys_enabled"))) {
 | 
			
		||||
            initDumpsysGfxInfo(parameters.getString("package"));
 | 
			
		||||
          }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void stopDumpsysGfxInfo(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);
 | 
			
		||||
          }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user