mirror of
				https://github.com/ARM-software/workload-automation.git
				synced 2025-10-31 07:04:17 +00:00 
			
		
		
		
	Change workload name to skype
This commit is contained in:
		
							
								
								
									
										128
									
								
								wlauto/workloads/skype/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										128
									
								
								wlauto/workloads/skype/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,128 @@ | ||||
| #    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. | ||||
| # | ||||
|  | ||||
| import os.path as op | ||||
| import time | ||||
|  | ||||
| from wlauto import AndroidUiAutoBenchmark, Parameter | ||||
|  | ||||
|  | ||||
| SKYPE_ACTION_URIS = { | ||||
|     'call': 'call', | ||||
|     'video': 'call&video=true', | ||||
| } | ||||
|  | ||||
|  | ||||
| class Skype(AndroidUiAutoBenchmark): | ||||
|  | ||||
|     name = 'skype' | ||||
|     description = ''' | ||||
|     Workload that makes Skype calls | ||||
|  | ||||
|     It allows for the agenda to decide whether to make a voice call or a video call. | ||||
|     Credentials for the user account used to log into the Skype app have to be provided | ||||
|     in the agenda, as well as the display name and skype ID of the contact to call. | ||||
|  | ||||
|     Other optional arguments allow controlling the duration of the call, whether the | ||||
|     call includes video or voice only, and whether to collect sys dumps. | ||||
|  | ||||
|     For reliable testing, this workload requires a good and stable internet connection, | ||||
|     preferably on Wi-Fi. | ||||
|     ''' | ||||
|     package = 'com.skype.raider' | ||||
|     activity = '' | ||||
|     # Skype has no default 'main' activity | ||||
|     launch_main = False # overrides extended class | ||||
|  | ||||
|     instrumentation_log = '{}_instrumentation.log'.format(name) | ||||
|  | ||||
|     parameters = [ | ||||
|         Parameter('login_name', kind=str, mandatory=True, | ||||
|                   description=''' | ||||
|                   Account to use when logging into the device from which the call will be made | ||||
|                   '''), | ||||
|         Parameter('login_pass', kind=str, mandatory=True, | ||||
|                   description='Password associated with the account to log into the device'), | ||||
|         Parameter('contact_skypeid', kind=str, mandatory=True, | ||||
|                   description='This is the Skype ID of the contact to call from the device'), | ||||
|         Parameter('contact_name', kind=str, mandatory=True, | ||||
|                   description='This is the contact display name as it appears in the people list'), | ||||
|         Parameter('duration', kind=int, default=60, | ||||
|                   description='This is the duration of the call in seconds'), | ||||
|         Parameter('action', kind=str, allowed_values=['voice', 'video'], default='video', | ||||
|                   description='Action to take - either video (default) or voice call'), | ||||
|         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. | ||||
|                   '''), | ||||
|     ] | ||||
|  | ||||
|     def __init__(self, device, **kwargs): | ||||
|         super(Skype, self).__init__(device, **kwargs) | ||||
|         self.output_file = op.join(self.device.working_directory, self.instrumentation_log) | ||||
|         self.run_timeout = self.duration + 60 | ||||
|  | ||||
|     def validate(self): | ||||
|         super(Skype, self).validate() | ||||
|         self.uiauto_params['results_file'] = self.output_file | ||||
|         self.uiauto_params['dumpsys_enabled'] = self.dumpsys_enabled | ||||
|         self.uiauto_params['output_dir'] = self.device.working_directory | ||||
|         self.uiauto_params['my_id'] = self.login_name | ||||
|         self.uiauto_params['my_pwd'] = self.login_pass | ||||
|         self.uiauto_params['skypeid'] = self.contact_skypeid | ||||
|         self.uiauto_params['name'] = self.contact_name.replace(' ', '_') | ||||
|         self.uiauto_params['duration'] = self.duration | ||||
|         self.uiauto_params['action'] = self.action | ||||
|  | ||||
|     def setup(self, context): | ||||
|         self.logger.info('===== setup() ======') | ||||
|         super(Skype, self).setup(context) | ||||
|         self.device.execute('am force-stop {}'.format(self.package)) | ||||
|         self.device.execute('am start -W -a android.intent.action.VIEW -d skype:dummy?dummy') | ||||
|         time.sleep(1) | ||||
|  | ||||
|     def run(self, context): | ||||
|         self.logger.info('===== run() ======') | ||||
|         super(Skype, self).run(context) | ||||
|  | ||||
|     def update_result(self, context): | ||||
|         self.logger.info('===== update_result() ======') | ||||
|         super(Skype, self).update_result(context) | ||||
|         if not self.dumpsys_enabled: | ||||
|             return | ||||
|  | ||||
|         self.device.pull_file(self.output_file, context.output_directory) | ||||
|         results_file = op.join(context.output_directory, self.instrumentation_log) | ||||
|  | ||||
|         # process results and add them using | ||||
|         # context.result.add_metric | ||||
|         with open(results_file, 'r') as lines: | ||||
|             for line in lines: | ||||
|                 if line.startswith('timer:'): | ||||
|                     res = line.split(' ') | ||||
|                     context.result.add_metric(res[1] + '_start', res[2]) | ||||
|                     context.result.add_metric(res[1] + '_finish', res[3]) | ||||
|                     context.result.add_metric(res[1] + '_duration', res[4]) | ||||
|  | ||||
|     def teardown(self, context): | ||||
|         self.logger.info('===== teardown() ======') | ||||
|         super(Skype, self).teardown(context) | ||||
|         # Pull log files | ||||
|         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)) | ||||
							
								
								
									
										
											BIN
										
									
								
								wlauto/workloads/skype/com.arm.wlauto.uiauto.skype.jar
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								wlauto/workloads/skype/com.arm.wlauto.uiauto.skype.jar
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										13
									
								
								wlauto/workloads/skype/template-agenda.mustache
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								wlauto/workloads/skype/template-agenda.mustache
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| global: | ||||
|     iterations: 1 | ||||
| workloads: | ||||
|     -   id: {{workload_id}} | ||||
|         name: skype | ||||
|         params: | ||||
|             login_name: {{login_name}} | ||||
|             login_pass: {{login_pass}} | ||||
|             contact_skypeid: {{contact_skypeid}} | ||||
|             contact_name: {{contact_name}} | ||||
|             duration: {{duration}} | ||||
|             action: {{action}} | ||||
|             dumpsys_enabled: {{dumpsys_enabled}} | ||||
							
								
								
									
										17
									
								
								wlauto/workloads/skype/uiauto/build.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										17
									
								
								wlauto/workloads/skype/uiauto/build.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| #!/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 | ||||
|  | ||||
| exit_code=$? | ||||
| if [[ $exit_code -ne 0 ]]; then | ||||
|     echo "ERROR: ant build exited with code $exit_code" && exit $exit_code | ||||
| fi | ||||
|  | ||||
| if [[ -f bin/com.arm.wlauto.uiauto.skype.jar ]]; then | ||||
|     cp bin/com.arm.wlauto.uiauto.skype.jar .. | ||||
| fi | ||||
							
								
								
									
										92
									
								
								wlauto/workloads/skype/uiauto/build.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								wlauto/workloads/skype/uiauto/build.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,92 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project name="com.arm.wlauto.uiauto.skype" 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/skype/uiauto/project.properties
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								wlauto/workloads/skype/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,163 @@ | ||||
| package com.arm.wlauto.uiauto.skype; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.io.BufferedWriter; | ||||
| import java.io.FileWriter; | ||||
| import java.util.TreeMap; | ||||
| import java.util.Map; | ||||
| import java.util.Map.Entry; | ||||
|  | ||||
| import android.app.Activity; | ||||
| import android.os.Bundle; | ||||
| import android.os.Handler; | ||||
| import android.os.Looper; | ||||
| import android.util.Log; | ||||
| import android.view.KeyEvent; | ||||
|  | ||||
| // 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; | ||||
|  | ||||
| public class UiAutomation extends UxPerfUiAutomation { | ||||
|  | ||||
|     public static final String TAG = "skype"; | ||||
|     public static final String PACKAGE = "com.skype.raider"; | ||||
|     public static final String PACKAGE_ID = "com.skype.raider:id/"; | ||||
|     public static final String TEXT_VIEW = "android.widget.TextView"; | ||||
|  | ||||
|     public static String noContactMessage = "Could not find contact \"%s\" in the contacts list."; | ||||
|  | ||||
|     private Map<String, Timer> results = new TreeMap<String, Timer>(); | ||||
|     private boolean dumpsysEnabled; | ||||
|     private String outputDir; | ||||
|  | ||||
|     public void runUiAutomation() throws Exception { | ||||
|         // Override superclass value | ||||
|         this.waitTimeout = 10000; | ||||
|  | ||||
|         // Get Params | ||||
|         Bundle parameters = getParams(); | ||||
|         String loginName = parameters.getString("my_id"); | ||||
|         String loginPass = parameters.getString("my_pwd"); | ||||
|         String contactSkypeId = parameters.getString("skypeid"); | ||||
|         String contactName = parameters.getString("name").replace("_", " "); | ||||
|         int callDuration = Integer.parseInt(parameters.getString("duration")); | ||||
|         String callType = parameters.getString("action"); | ||||
|         String resultsFile = parameters.getString("results_file"); | ||||
|         outputDir = parameters.getString("output_dir", "/sdcard/wa-working"); | ||||
|         dumpsysEnabled = Boolean.parseBoolean(parameters.getString("dumpsys_enabled")); | ||||
|  | ||||
|         // Run tests | ||||
|         handleLoginScreen(loginName, loginPass); | ||||
|         selectContact(contactName, contactSkypeId); | ||||
|         if ("video".equalsIgnoreCase(callType)) { | ||||
|             videoCallTest(callDuration); | ||||
|         } else if ("voice".equalsIgnoreCase(callType)) { | ||||
|             voiceCallTest(callDuration); | ||||
|         } | ||||
|  | ||||
|         // Save results | ||||
|         saveResults(results, resultsFile); | ||||
|     } | ||||
|  | ||||
|     private void saveResults(Map<String, Timer> results, String file) throws Exception { | ||||
|         BufferedWriter out = new BufferedWriter(new FileWriter(file)); | ||||
|         long start, finish, duration; | ||||
|         Timer timer; | ||||
|         for (Map.Entry<String, Timer> entry : results.entrySet()) { | ||||
|             timer = entry.getValue(); | ||||
|             start = timer.getStart(); | ||||
|             finish = timer.getFinish(); | ||||
|             duration = timer.getDuration(); | ||||
|             // Format used to parse out results in workload's update_result function | ||||
|             out.write(String.format("timer: %s %d %d %d\n", entry.getKey(), start, finish, duration)); | ||||
|         } | ||||
|         out.close(); | ||||
|     } | ||||
|  | ||||
|     private void handleLoginScreen(String username, String password) throws Exception { | ||||
|         String useridResoureId = PACKAGE_ID + "sign_in_userid"; | ||||
|         String nextButtonResourceId = PACKAGE_ID + "sign_in_next_btn"; | ||||
|         UiObject useridField = new UiObject(new UiSelector().resourceId(useridResoureId)); | ||||
|         UiObject nextButton = new UiObject(new UiSelector().resourceId(nextButtonResourceId)); | ||||
|         useridField.setText(username); | ||||
|         nextButton.clickAndWaitForNewWindow(); | ||||
|  | ||||
|         String passwordResoureId = PACKAGE_ID + "signin_password"; | ||||
|         String signinButtonResourceId = PACKAGE_ID + "sign_in_btn"; | ||||
|         UiObject passwordField = new UiObject(new UiSelector().resourceId(passwordResoureId)); | ||||
|         UiObject signinButton = new UiObject(new UiSelector().resourceId(signinButtonResourceId)); | ||||
|         passwordField.setText(password); | ||||
|         signinButton.clickAndWaitForNewWindow(); | ||||
|     } | ||||
|  | ||||
|     private void selectContact(String name, String id) throws Exception { | ||||
|         Timer timer = new Timer(); | ||||
|         timer.start(); | ||||
|         UiObject peopleTab; | ||||
|         // Open the 'People' tab aka contacts view | ||||
|         // On phones, it is represented by an image with description | ||||
|         // On tablets, the full text is shown without a description | ||||
|         try { | ||||
|             peopleTab = getUiObjectByDescription("People", TEXT_VIEW); | ||||
|         } catch (UiObjectNotFoundException e) { | ||||
|             peopleTab = getUiObjectByText("People", TEXT_VIEW); | ||||
|         } | ||||
|         peopleTab.click(); | ||||
|  | ||||
|         // On first startup, the app may take a while to load the display name, | ||||
|         // so try twice before declaring failure | ||||
|         UiObject contactCard; | ||||
|         try { | ||||
|             contactCard = getUiObjectByText(name, TEXT_VIEW); | ||||
|         } catch (UiObjectNotFoundException e) { | ||||
|             contactCard = getUiObjectByText(name, TEXT_VIEW); | ||||
|         } | ||||
|         contactCard.clickAndWaitForNewWindow(); | ||||
|         timer.end(); | ||||
|         results.put("select_contact", timer); | ||||
|     } | ||||
|  | ||||
|     private void voiceCallTest(int duration) throws Exception { | ||||
|         String testTag = "voice_call"; | ||||
|         Timer timer = new Timer(); | ||||
|         timer.start(); | ||||
|         makeCall(duration, false, testTag); | ||||
|         timer.end(); | ||||
|         results.put(testTag, timer); | ||||
|     } | ||||
|  | ||||
|     private void videoCallTest(int duration) throws Exception { | ||||
|         String testTag = "video_call"; | ||||
|         Timer timer = new Timer(); | ||||
|         timer.start(); | ||||
|         makeCall(duration, true, testTag); | ||||
|         timer.end(); | ||||
|         results.put(testTag, timer); | ||||
|     } | ||||
|  | ||||
|     private void makeCall(int duration, boolean video, String testTag) throws Exception { | ||||
|         String viewName = "com.skype.android.app.calling.CallActivity"; | ||||
|         String dumpsysTag = TAG + "_" + testTag; | ||||
|         if (video && dumpsysEnabled) { | ||||
|             initDumpsysSurfaceFlinger(PACKAGE, viewName); | ||||
|             initDumpsysGfxInfo(PACKAGE); | ||||
|         } | ||||
|  | ||||
|         String description = video ? "Video call" : "Call options"; | ||||
|         UiObject callButton = new UiObject(new UiSelector().descriptionContains(description)); | ||||
|         callButton.click(); | ||||
|         sleep(duration); | ||||
|  | ||||
|         if (video && dumpsysEnabled) { | ||||
|             exitDumpsysSurfaceFlinger(PACKAGE, viewName, new File(outputDir, dumpsysTag + "_surface_flinger.log")); | ||||
|             exitDumpsysGfxInfo(PACKAGE, new File(outputDir, dumpsysTag + "_gfxinfo.log")); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user