mirror of
				https://github.com/ARM-software/workload-automation.git
				synced 2025-11-04 09:02:12 +00:00 
			
		
		
		
	Update google slides workload
- support for pushing local PPT files to device for testing
This commit is contained in:
		
				
					committed by
					
						
						muendelezaji
					
				
			
			
				
	
			
			
			
						parent
						
							ceb6677274
						
					
				
				
					commit
					f2ff559805
				
			@@ -13,16 +13,17 @@
 | 
			
		||||
# limitations under the License.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
import os.path as op
 | 
			
		||||
import os
 | 
			
		||||
import os.path as path
 | 
			
		||||
import re
 | 
			
		||||
import time
 | 
			
		||||
 | 
			
		||||
from wlauto import AndroidUiAutoBenchmark, Parameter
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def not_implemented(workload, text):
 | 
			
		||||
    workload.logger.info('## ++ NOT IMPLEMENTED ++ ##\n## {}\n## -- NOT IMPLEMENTED -- ##'.format(text))
 | 
			
		||||
 | 
			
		||||
def log_method(workload, name):
 | 
			
		||||
    workload.logger.info('===== {}() ======'.format(name))
 | 
			
		||||
 | 
			
		||||
class GoogleSlides(AndroidUiAutoBenchmark):
 | 
			
		||||
 | 
			
		||||
@@ -30,10 +31,12 @@ class GoogleSlides(AndroidUiAutoBenchmark):
 | 
			
		||||
    package = 'com.google.android.apps.docs.editors.slides'
 | 
			
		||||
    description = 'Creates a Google Slides presentation with some commonly used features'
 | 
			
		||||
    activity = ''
 | 
			
		||||
    # com.google.android.apps.docs.editors.slides/com.google.android.apps.docs.app.DocListActivity
 | 
			
		||||
    # com.google.android.apps.docs.editors.slides/com.google.android.apps.docs.welcome.warmwelcome.TrackingWelcomeActivity
 | 
			
		||||
 | 
			
		||||
    instrumentation_log = '{}_instrumentation.log'.format(name)
 | 
			
		||||
    # Views for FPS instrumentation
 | 
			
		||||
    view = [
 | 
			
		||||
        "com.google.android.apps.docs.editors.slides/com.google.android.apps.docs.app.DocListActivity",
 | 
			
		||||
        "com.google.android.apps.docs.editors.slides/com.google.android.apps.docs.welcome.warmwelcome.TrackingWelcomeActivity",
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    parameters = [
 | 
			
		||||
        Parameter('dumpsys_enabled', kind=bool, default=True,
 | 
			
		||||
@@ -41,42 +44,78 @@ class GoogleSlides(AndroidUiAutoBenchmark):
 | 
			
		||||
                  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.
 | 
			
		||||
                  '''),
 | 
			
		||||
        Parameter('local_files', kind=bool, default=True,
 | 
			
		||||
                  description='''
 | 
			
		||||
                  If ``True``, the workload will push PowerPoint files to be used for testing on
 | 
			
		||||
                  the device. Otherwise, the files will be created from template inside the app.
 | 
			
		||||
                  '''),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    instrumentation_log = '{}_instrumentation.log'.format(name)
 | 
			
		||||
    file_prefix = 'wa_test_'
 | 
			
		||||
    local_dir = '.' # self.dependencies_directory
 | 
			
		||||
    device_dir = '/sdcard/Download' # self.device.working_directory
 | 
			
		||||
 | 
			
		||||
    def __init__(self, device, **kwargs):
 | 
			
		||||
        super(GoogleSlides, self).__init__(device, **kwargs)
 | 
			
		||||
        self.output_file = op.join(self.device.working_directory, self.instrumentation_log)
 | 
			
		||||
        self.output_file = path.join(self.device.working_directory, self.instrumentation_log)
 | 
			
		||||
        self.run_timeout = 60
 | 
			
		||||
 | 
			
		||||
    def validate(self):
 | 
			
		||||
        self.logger.info('===== validate() ======')
 | 
			
		||||
        log_method(self, 'validate')
 | 
			
		||||
        super(GoogleSlides, self).validate()
 | 
			
		||||
        self.uiauto_params['dumpsys_enabled'] = self.dumpsys_enabled
 | 
			
		||||
        self.uiauto_params['output_dir'] = self.device.working_directory
 | 
			
		||||
        self.uiauto_params['results_file'] = self.output_file
 | 
			
		||||
 | 
			
		||||
    def initialize(self, context):
 | 
			
		||||
        log_method(self, 'initialize')
 | 
			
		||||
        super(GoogleSlides, self).initialize(context)
 | 
			
		||||
        if self.local_files:
 | 
			
		||||
            # push local PPT files
 | 
			
		||||
            for entry in os.listdir(self.local_dir):
 | 
			
		||||
                wa_file = self.file_prefix + entry
 | 
			
		||||
                if entry.endswith(".pptx"):
 | 
			
		||||
                    self.device.push_file(path.join(self.local_dir, entry),
 | 
			
		||||
                                          path.join(self.device_dir, wa_file),
 | 
			
		||||
                                          timeout=60)
 | 
			
		||||
            # 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 setup(self, context):
 | 
			
		||||
        self.logger.info('===== setup() ======')
 | 
			
		||||
        log_method(self, 'setup')
 | 
			
		||||
        super(GoogleSlides, self).setup(context)
 | 
			
		||||
 | 
			
		||||
    def run(self, context):
 | 
			
		||||
        self.logger.info('===== run() ======')
 | 
			
		||||
        log_method(self, 'run')
 | 
			
		||||
        super(GoogleSlides, self).run(context)
 | 
			
		||||
 | 
			
		||||
    def update_result(self, context):
 | 
			
		||||
        self.logger.info('===== update_result() ======')
 | 
			
		||||
        log_method(self, 'update_result')
 | 
			
		||||
        super(GoogleSlides, self).update_result(context)
 | 
			
		||||
        if self.dumpsys_enabled:
 | 
			
		||||
            not_implemented(self, 'get_metrics(context)')
 | 
			
		||||
 | 
			
		||||
    def teardown(self, context):
 | 
			
		||||
        self.logger.info('===== teardown() ======')
 | 
			
		||||
        log_method(self, 'teardown')
 | 
			
		||||
        super(GoogleSlides, self).teardown(context)
 | 
			
		||||
        not_implemented(self, 'pull_logs(context)')
 | 
			
		||||
 | 
			
		||||
    def finalize(self, context):
 | 
			
		||||
        log_method(self, 'finalize')
 | 
			
		||||
        super(GoogleSlides, self).finalize(context)
 | 
			
		||||
        if self.local_files:
 | 
			
		||||
            # delete pushed PPT files
 | 
			
		||||
            for entry in os.listdir(self.local_dir):
 | 
			
		||||
                wa_file = self.file_prefix + entry
 | 
			
		||||
                if entry.endswith(".pptx"):
 | 
			
		||||
                    self.device.delete_file(path.join(self.device_dir, wa_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')
 | 
			
		||||
 | 
			
		||||
    def get_metrics(self, context):
 | 
			
		||||
        self.device.pull_file(self.output_file, context.output_directory)
 | 
			
		||||
        metrics_file = op.join(context.output_directory, self.instrumentation_log)
 | 
			
		||||
        metrics_file = path.join(context.output_directory, self.instrumentation_log)
 | 
			
		||||
        with open(metrics_file, 'r') as wfh:
 | 
			
		||||
            regex = re.compile(r'(\w+)\s+(\d+)\s+(\d+)\s+(\d+)')
 | 
			
		||||
            for line in wfh:
 | 
			
		||||
@@ -90,5 +129,5 @@ class GoogleSlides(AndroidUiAutoBenchmark):
 | 
			
		||||
        wd = self.device.working_directory
 | 
			
		||||
        for entry in self.device.listdir(wd):
 | 
			
		||||
            if entry.startswith(self.name) and entry.endswith('.log'):
 | 
			
		||||
                self.device.pull_file(op.join(wd, entry), context.output_directory)
 | 
			
		||||
                self.device.delete_file(op.join(wd, entry))
 | 
			
		||||
                self.device.pull_file(path.join(wd, entry), context.output_directory)
 | 
			
		||||
                self.device.delete_file(path.join(wd, entry))
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							@@ -1,3 +1,18 @@
 | 
			
		||||
/*    Copyright 2014-2016 ARM Limited
 | 
			
		||||
 *
 | 
			
		||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 *
 | 
			
		||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.arm.wlauto.uiauto.googleslides;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
@@ -22,7 +37,7 @@ import com.arm.wlauto.uiauto.UxPerfUiAutomation;
 | 
			
		||||
 | 
			
		||||
public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
 | 
			
		||||
    public static String TAG = "googleslides";
 | 
			
		||||
    public static final String TAG = "googleslides";
 | 
			
		||||
    public static final String PACKAGE = "com.google.android.apps.docs.editors.slides";
 | 
			
		||||
    public static final String PACKAGE_ID = PACKAGE + ":id/";
 | 
			
		||||
 | 
			
		||||
@@ -32,37 +47,47 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
    public static final String CLASS_IMAGE_BUTTON = "android.widget.ImageButton";
 | 
			
		||||
    public static final String CLASS_TABLE_ROW = "android.widget.TableRow";
 | 
			
		||||
 | 
			
		||||
    public Bundle parameters;
 | 
			
		||||
    private Map<String, Timer> results = new LinkedHashMap<String, Timer>();
 | 
			
		||||
    private boolean dumpsysEnabled;
 | 
			
		||||
    private String outputDir;
 | 
			
		||||
 | 
			
		||||
    public static final int DOCTYPE_TEMPLATE = 1;
 | 
			
		||||
    public static final int DOCTYPE_PPT = 2;
 | 
			
		||||
    public static final int DOCTYPE_SLIDES = 3;
 | 
			
		||||
 | 
			
		||||
    private Map<String, Timer> results = new LinkedHashMap<String, Timer>();
 | 
			
		||||
 | 
			
		||||
    private Bundle parameters;
 | 
			
		||||
    private boolean dumpsysEnabled;
 | 
			
		||||
    private String outputDir;
 | 
			
		||||
    private String documentName;
 | 
			
		||||
    private boolean useLocalFiles;
 | 
			
		||||
 | 
			
		||||
    private static final String[] DEFAULT_DOCS = { "wa_test_Slides_Album.pptx", "wa_test_Slides_Pitch.pptx" };
 | 
			
		||||
 | 
			
		||||
    public void parseParams(Bundle parameters) throws Exception {
 | 
			
		||||
        dumpsysEnabled = Boolean.parseBoolean(parameters.getString("dumpsys_enabled"));
 | 
			
		||||
        outputDir = parameters.getString("output_dir", "/sdcard/wa-working");
 | 
			
		||||
        documentName = parameters.getString("local_files", DEFAULT_DOCS[0]);
 | 
			
		||||
        useLocalFiles = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void runUiAutomation() throws Exception {
 | 
			
		||||
        parameters = getParams();
 | 
			
		||||
        parseParams(parameters);
 | 
			
		||||
        skipWelcomeScreen();
 | 
			
		||||
        enablePowerpointCompat();
 | 
			
		||||
        if (false) { // TODO currently unused
 | 
			
		||||
            openFromStorage();
 | 
			
		||||
        if (useLocalFiles) { // TODO currently unused
 | 
			
		||||
            openFromStorage(documentName);
 | 
			
		||||
        } else {
 | 
			
		||||
            createNewDoc(DOCTYPE_TEMPLATE);
 | 
			
		||||
        }
 | 
			
		||||
        createNewDoc(DOCTYPE_TEMPLATE);
 | 
			
		||||
        setWifiStatus(false);
 | 
			
		||||
        tapDisplayNormalised(0.99, 0.99);
 | 
			
		||||
        sleep(5);
 | 
			
		||||
        getUiDevice().pressBack();
 | 
			
		||||
 | 
			
		||||
        if (false) { // TODO currently unused
 | 
			
		||||
            writeResultsToFile(results, parameters.getString("results_file"));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void parseParams(Bundle parameters) throws Exception {
 | 
			
		||||
        dumpsysEnabled = Boolean.parseBoolean(parameters.getString("dumpsys_enabled"));
 | 
			
		||||
        outputDir = parameters.getString("output_dir", "/sdcard/wa-working");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void skipWelcomeScreen() throws Exception {
 | 
			
		||||
        UiObject skipButton = getUiObjectByText("Skip", CLASS_BUTTON);
 | 
			
		||||
        skipButton.clickAndWaitForNewWindow();
 | 
			
		||||
@@ -79,12 +104,18 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
        sleep(1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void openFromStorage() throws Exception {
 | 
			
		||||
    private void openFromStorage(String document) throws Exception {
 | 
			
		||||
        // UiObject newButton = getUiObjectByResourceId(PACKAGE_ID + "menu_open_with_picker", CLASS_TEXT_VIEW);
 | 
			
		||||
        UiObject openButton = getUiObjectByDescription("Open presentation", CLASS_TEXT_VIEW);
 | 
			
		||||
        openButton.click();
 | 
			
		||||
        openButton = getUiObjectByText("Device storage", CLASS_TEXT_VIEW);
 | 
			
		||||
        openButton.clickAndWaitForNewWindow();
 | 
			
		||||
 | 
			
		||||
        UiObject selectDoc = getUiObjectByText(document, CLASS_TEXT_VIEW);
 | 
			
		||||
        selectDoc.click();
 | 
			
		||||
        openButton = getUiObjectByText("Open", CLASS_BUTTON);
 | 
			
		||||
        openButton.clickAndWaitForNewWindow();
 | 
			
		||||
 | 
			
		||||
        getUiDevice().pressBack();
 | 
			
		||||
        sleep(1);
 | 
			
		||||
    }
 | 
			
		||||
@@ -93,28 +124,33 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
        // UiObject newButton = getUiObjectByResourceId(PACKAGE_ID + "fab_base_button", CLASS_IMAGE_BUTTON);
 | 
			
		||||
        UiObject newButton = getUiObjectByDescription("New presentation", CLASS_IMAGE_BUTTON);
 | 
			
		||||
        newButton.click();
 | 
			
		||||
        // UiObject fromTemplate = getUiObjectByDescription("Choose template", CLASS_IMAGE_BUTTON);
 | 
			
		||||
        UiObject fromTemplate = getUiObjectByText("Choose template", CLASS_TEXT_VIEW);
 | 
			
		||||
 | 
			
		||||
        UiObject newPowerpoint = getUiObjectByDescription("New PowerPoint", CLASS_IMAGE_BUTTON);
 | 
			
		||||
        UiObject newSlidesFile = getUiObjectByDescription("New Slides", CLASS_IMAGE_BUTTON);
 | 
			
		||||
        UiObject fromTemplate = getUiObjectByDescription("Choose template", CLASS_IMAGE_BUTTON);
 | 
			
		||||
        // UiObject newPowerpoint = getUiObjectByText("New PowerPoint", CLASS_TEXT_VIEW);
 | 
			
		||||
        // UiObject newSlidesFile = getUiObjectByText("New Slides", CLASS_TEXT_VIEW);
 | 
			
		||||
        // UiObject fromTemplate = getUiObjectByText("Choose template", CLASS_TEXT_VIEW);
 | 
			
		||||
        // UiObject newPowerpoint = getUiObjectByDescription("New PowerPoint", CLASS_IMAGE_BUTTON);
 | 
			
		||||
        // UiObject newSlidesFile = getUiObjectByDescription("New Slides", CLASS_IMAGE_BUTTON);
 | 
			
		||||
        UiObject newPowerpoint = getUiObjectByText("New PowerPoint", CLASS_TEXT_VIEW);
 | 
			
		||||
        UiObject newSlidesFile = getUiObjectByText("New Slides", CLASS_TEXT_VIEW);
 | 
			
		||||
 | 
			
		||||
        switch (docType) {
 | 
			
		||||
            case DOCTYPE_TEMPLATE:
 | 
			
		||||
                String[] templateNames = { "Lesson plan", "Book report", " Field trip", "Science project" };
 | 
			
		||||
                fromTemplate.clickAndWaitForNewWindow();
 | 
			
		||||
                // UiObject template = getUiObjectByText(templateNames[1], CLASS_TEXT_VIEW);
 | 
			
		||||
                UiObject template = new UiObject(new UiSelector().resourceId(PACKAGE_ID + "template_item").instance(2));
 | 
			
		||||
                template.clickAndWaitForNewWindow();
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
            case DOCTYPE_PPT:
 | 
			
		||||
                newPowerpoint.clickAndWaitForNewWindow();
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
            case DOCTYPE_SLIDES:
 | 
			
		||||
            default:
 | 
			
		||||
                newSlidesFile.clickAndWaitForNewWindow();
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
        sleep(1);
 | 
			
		||||
        getUiDevice().pressBack();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void uiDeviceEdgeSwipeFromLeft(int steps) {
 | 
			
		||||
@@ -144,8 +180,8 @@ public class UiAutomation extends UxPerfUiAutomation {
 | 
			
		||||
            + "    sleep 1;"
 | 
			
		||||
            + "    input keyevent 4;"
 | 
			
		||||
            + "fi";
 | 
			
		||||
        // runShellCommand(adbCommand);
 | 
			
		||||
        runShellCommand("dumpsys wifi | grep curState=ConnectedState");
 | 
			
		||||
        runShellCommand(adbCommand);
 | 
			
		||||
        // runShellCommand("dumpsys wifi | grep curState=ConnectedState");
 | 
			
		||||
        sleep(1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user