mirror of
				https://github.com/ARM-software/workload-automation.git
				synced 2025-11-04 09:02:12 +00:00 
			
		
		
		
	@@ -236,6 +236,11 @@ class ApkWorkload(Workload):
 | 
				
			|||||||
        self.device.execute('am force-stop {}'.format(self.package))
 | 
					        self.device.execute('am force-stop {}'.format(self.package))
 | 
				
			||||||
        self.device.execute('pm clear {}'.format(self.package))
 | 
					        self.device.execute('pm clear {}'.format(self.package))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # As of android API level 23, apps can request permissions at runtime,
 | 
				
			||||||
 | 
					        # this will grant all of them so requests do not pop up when running the app
 | 
				
			||||||
 | 
					        if self.device.get_sdk_version() >= 23:
 | 
				
			||||||
 | 
					            self._grant_requested_permissions()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def install_apk(self, context):
 | 
					    def install_apk(self, context):
 | 
				
			||||||
        output = self.device.install(self.apk_file, self.install_timeout)
 | 
					        output = self.device.install(self.apk_file, self.install_timeout)
 | 
				
			||||||
        if 'Failure' in output:
 | 
					        if 'Failure' in output:
 | 
				
			||||||
@@ -247,6 +252,23 @@ class ApkWorkload(Workload):
 | 
				
			|||||||
            self.logger.debug(output)
 | 
					            self.logger.debug(output)
 | 
				
			||||||
        self.do_post_install(context)
 | 
					        self.do_post_install(context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def _grant_requested_permissions(self):
 | 
				
			||||||
 | 
					        dumpsys_output = self.device.execute(command="dumpsys package {}".format(self.package))
 | 
				
			||||||
 | 
					        permissions = []
 | 
				
			||||||
 | 
					        lines = iter(dumpsys_output.splitlines())
 | 
				
			||||||
 | 
					        for line in lines:
 | 
				
			||||||
 | 
					            if "requested permissions:" in line:
 | 
				
			||||||
 | 
					                break
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for line in lines:
 | 
				
			||||||
 | 
					            if "android.permission." in line:
 | 
				
			||||||
 | 
					                permissions.append(line.split(":")[0].strip())
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                break
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for permission in permissions:
 | 
				
			||||||
 | 
					            self.device.execute("pm grant {} {}".format(self.package, permission))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def do_post_install(self, context):
 | 
					    def do_post_install(self, context):
 | 
				
			||||||
        """ May be overwritten by dervied classes."""
 | 
					        """ May be overwritten by dervied classes."""
 | 
				
			||||||
        pass
 | 
					        pass
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,7 +16,8 @@
 | 
				
			|||||||
import os
 | 
					import os
 | 
				
			||||||
from collections import defaultdict, OrderedDict
 | 
					from collections import defaultdict, OrderedDict
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from wlauto import AndroidUiAutoBenchmark, Parameter
 | 
					from wlauto import AndroidUiAutoBenchmark, Parameter, File
 | 
				
			||||||
 | 
					from wlauto.utils.android import ApkInfo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Antutu(AndroidUiAutoBenchmark):
 | 
					class Antutu(AndroidUiAutoBenchmark):
 | 
				
			||||||
@@ -46,7 +47,7 @@ class Antutu(AndroidUiAutoBenchmark):
 | 
				
			|||||||
    activity = ".ABenchMarkStart"
 | 
					    activity = ".ABenchMarkStart"
 | 
				
			||||||
    summary_metrics = ['score', 'Overall_Score']
 | 
					    summary_metrics = ['score', 'Overall_Score']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    valid_versions = ['3.3.2', '4.0.3', '5.3.0']
 | 
					    valid_versions = ['3.3.2', '4.0.3', '5.3.0', '6.0.1']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    device_prefs_directory = '/data/data/com.antutu.ABenchMark/shared_prefs'
 | 
					    device_prefs_directory = '/data/data/com.antutu.ABenchMark/shared_prefs'
 | 
				
			||||||
    device_prefs_file = '/'.join([device_prefs_directory, 'com.antutu.ABenchMark_preferences.xml'])
 | 
					    device_prefs_file = '/'.join([device_prefs_directory, 'com.antutu.ABenchMark_preferences.xml'])
 | 
				
			||||||
@@ -68,18 +69,26 @@ class Antutu(AndroidUiAutoBenchmark):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def __init__(self, device, **kwargs):  # pylint: disable=W0613
 | 
					    def __init__(self, device, **kwargs):  # pylint: disable=W0613
 | 
				
			||||||
        super(Antutu, self).__init__(device, **kwargs)
 | 
					        super(Antutu, self).__init__(device, **kwargs)
 | 
				
			||||||
        self.run_timeout = 6 * 60 * self.times
 | 
					        self.run_timeout = 10 * 60 * self.times
 | 
				
			||||||
        self.uiauto_params['version'] = self.version
 | 
					        self.uiauto_params['version'] = self.version
 | 
				
			||||||
        self.uiauto_params['times'] = self.times
 | 
					        self.uiauto_params['times'] = self.times
 | 
				
			||||||
        self.uiauto_params['enable_sd_tests'] = self.enable_sd_tests
 | 
					        self.uiauto_params['enable_sd_tests'] = self.enable_sd_tests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def setup(self, context):
 | 
				
			||||||
 | 
					        if self.version == "6.0.1":
 | 
				
			||||||
 | 
					            antutu_3d = context.resolver.get(File(self, "com.antutu.benchmark.full-1.apk"))
 | 
				
			||||||
 | 
					            info = ApkInfo(antutu_3d)
 | 
				
			||||||
 | 
					            if not context.device.is_installed(info.package):
 | 
				
			||||||
 | 
					                self.device.install_apk(antutu_3d, timeout=120)
 | 
				
			||||||
 | 
					        super(Antutu, self).setup(context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def update_result(self, context):
 | 
					    def update_result(self, context):
 | 
				
			||||||
        super(Antutu, self).update_result(context)
 | 
					        super(Antutu, self).update_result(context)
 | 
				
			||||||
        with open(self.logcat_log) as fh:
 | 
					        with open(self.logcat_log) as fh:
 | 
				
			||||||
            if self.version == '4.0.3':
 | 
					            if self.version == '3.3.2':
 | 
				
			||||||
                metrics = extract_version4_metrics(fh)
 | 
					                metrics = extract_older_version_metrics(fh)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                metrics = extract_older_version_metrics(fh)  # pylint: disable=redefined-variable-type
 | 
					                metrics = extract_metrics(fh)  # pylint: disable=redefined-variable-type
 | 
				
			||||||
        for key, value in metrics.iteritems():
 | 
					        for key, value in metrics.iteritems():
 | 
				
			||||||
            key = key.replace(' ', '_')
 | 
					            key = key.replace(' ', '_')
 | 
				
			||||||
            context.result.add_metric(key, value)
 | 
					            context.result.add_metric(key, value)
 | 
				
			||||||
@@ -87,7 +96,7 @@ class Antutu(AndroidUiAutoBenchmark):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# Utility functions
 | 
					# Utility functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def extract_version4_metrics(fh):
 | 
					def extract_metrics(fh):
 | 
				
			||||||
    metrics = OrderedDict()
 | 
					    metrics = OrderedDict()
 | 
				
			||||||
    metric_counts = defaultdict(int)
 | 
					    metric_counts = defaultdict(int)
 | 
				
			||||||
    for line in fh:
 | 
					    for line in fh:
 | 
				
			||||||
 
 | 
				
			|||||||
										
											Binary file not shown.
										
									
								
							@@ -37,7 +37,8 @@ import com.arm.wlauto.uiauto.BaseUiAutomation;
 | 
				
			|||||||
public class UiAutomation extends BaseUiAutomation {
 | 
					public class UiAutomation extends BaseUiAutomation {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static String TAG = "antutu";
 | 
					    public static String TAG = "antutu";
 | 
				
			||||||
 | 
					    public static String TestButton5 = "com.antutu.ABenchMark:id/start_test_region";
 | 
				
			||||||
 | 
					    public static String TestButton6 = "com.antutu.ABenchMark:id/start_test_text";
 | 
				
			||||||
    private static int initialTimeoutSeconds = 20;
 | 
					    private static int initialTimeoutSeconds = 20;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void runUiAutomation() throws Exception{
 | 
					    public void runUiAutomation() throws Exception{
 | 
				
			||||||
@@ -51,19 +52,42 @@ public class UiAutomation extends BaseUiAutomation {
 | 
				
			|||||||
                times = 1;
 | 
					                times = 1;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (version.equals("4.0.3") || version.equals("5.3.0")){
 | 
					        if (version.equals("3.3.2")) { // version earlier than 4.0.3
 | 
				
			||||||
 | 
					            dismissReleaseNotesDialogIfNecessary();
 | 
				
			||||||
 | 
					            if(!enableSdTests){
 | 
				
			||||||
 | 
					               disableSdCardTests();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            hitStart();
 | 
				
			||||||
 | 
					            waitForAndViewResults();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
            int iteration = 0;
 | 
					            int iteration = 0;
 | 
				
			||||||
            dismissNewVersionNotificationIfNecessary();
 | 
					            dismissNewVersionNotificationIfNecessary();
 | 
				
			||||||
            hitTestButton();
 | 
					 | 
				
			||||||
            while (true) {
 | 
					            while (true) {
 | 
				
			||||||
                    if (version.equals("5.3.0"))
 | 
					                    if(version.equals("6.0.1"))
 | 
				
			||||||
                        hitTestButtonVersion5();
 | 
					                        hitTestButtonVersion5(TestButton6);
 | 
				
			||||||
 | 
					                    else if (version.equals("5.3.0")) {
 | 
				
			||||||
 | 
					                        hitTestButton();
 | 
				
			||||||
 | 
					                        hitTestButtonVersion5(TestButton5);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    else if (version.equals("4.0.3")) {
 | 
				
			||||||
 | 
					                        hitTestButton();
 | 
				
			||||||
 | 
					                        hitTestButton();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                    else
 | 
					                    else
 | 
				
			||||||
                        hitTestButton();
 | 
					                        hitTestButton();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    waitForVersion4Results();
 | 
					                    if(version.equals("6.0.1"))
 | 
				
			||||||
                    viewDetails();
 | 
					                    {
 | 
				
			||||||
                    extractResults();
 | 
					                        waitForVersion6Results();
 | 
				
			||||||
 | 
					                        extractResults6();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    else
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        waitForVersion4Results();
 | 
				
			||||||
 | 
					                        viewDetails();
 | 
				
			||||||
 | 
					                        extractResults();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    iteration++;
 | 
					                    iteration++;
 | 
				
			||||||
                    if (iteration >= times) {
 | 
					                    if (iteration >= times) {
 | 
				
			||||||
@@ -74,13 +98,6 @@ public class UiAutomation extends BaseUiAutomation {
 | 
				
			|||||||
                    dismissRateDialogIfNecessary();
 | 
					                    dismissRateDialogIfNecessary();
 | 
				
			||||||
                    testAgain();
 | 
					                    testAgain();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else { // version earlier than 4.0.3
 | 
					 | 
				
			||||||
            dismissReleaseNotesDialogIfNecessary();
 | 
					 | 
				
			||||||
            if(!enableSdTests){
 | 
					 | 
				
			||||||
               disableSdCardTests();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            hitStart();
 | 
					 | 
				
			||||||
            waitForAndViewResults();
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Bundle status = new Bundle();
 | 
					        Bundle status = new Bundle();
 | 
				
			||||||
@@ -137,15 +154,16 @@ public class UiAutomation extends BaseUiAutomation {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
   /* In version 5 of antutu, the test has been changed from a button widget to a textview */
 | 
					   /* In version 5 of antutu, the test has been changed from a button widget to a textview */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   public void hitTestButtonVersion5() throws Exception {
 | 
					   public void hitTestButtonVersion5(String id) throws Exception {
 | 
				
			||||||
        UiSelector selector = new UiSelector();
 | 
					        UiSelector selector = new UiSelector();
 | 
				
			||||||
        UiObject test = new UiObject(selector.resourceId("com.antutu.ABenchMark:id/start_test_region")
 | 
					        UiObject test = new UiObject(selector.resourceId(id)
 | 
				
			||||||
                                             .className("android.widget.TextView"));
 | 
					                                             .className("android.widget.TextView"));
 | 
				
			||||||
        test.waitForExists(initialTimeoutSeconds);
 | 
					        test.waitForExists(initialTimeoutSeconds);
 | 
				
			||||||
        test.click();
 | 
					        test.click();
 | 
				
			||||||
        sleep(1); // possible tab transtion
 | 
					        sleep(1); // possible tab transtion
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void hitTest() throws Exception {
 | 
					    public void hitTest() throws Exception {
 | 
				
			||||||
        UiSelector selector = new UiSelector();
 | 
					        UiSelector selector = new UiSelector();
 | 
				
			||||||
        UiObject test = new UiObject(selector.text("Test"));
 | 
					        UiObject test = new UiObject(selector.text("Test"));
 | 
				
			||||||
@@ -193,6 +211,17 @@ public class UiAutomation extends BaseUiAutomation {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void waitForVersion6Results() throws Exception {
 | 
				
			||||||
 | 
					        UiObject qrText = new UiObject(new UiSelector().className("android.widget.TextView")
 | 
				
			||||||
 | 
					                                                       .text("QRCode of result"));
 | 
				
			||||||
 | 
					        for (int i = 0; i < 120; i++) {
 | 
				
			||||||
 | 
					            if (qrText.exists()) {
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            sleep(5);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void viewDetails() throws Exception {
 | 
					    public void viewDetails() throws Exception {
 | 
				
			||||||
        UiSelector selector = new UiSelector();
 | 
					        UiSelector selector = new UiSelector();
 | 
				
			||||||
        UiObject detailsButton = new UiObject(new UiSelector().className("android.widget.Button")
 | 
					        UiObject detailsButton = new UiObject(new UiSelector().className("android.widget.Button")
 | 
				
			||||||
@@ -200,6 +229,30 @@ public class UiAutomation extends BaseUiAutomation {
 | 
				
			|||||||
        detailsButton.clickAndWaitForNewWindow();
 | 
					        detailsButton.clickAndWaitForNewWindow();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void extractResults6() throws Exception {
 | 
				
			||||||
 | 
					        //Overal result
 | 
				
			||||||
 | 
					        UiObject result = new UiObject(new UiSelector().resourceId("com.antutu.ABenchMark:id/tv_score_name"));
 | 
				
			||||||
 | 
					        if (result.exists()) {
 | 
				
			||||||
 | 
					            Log.v(TAG, String.format("ANTUTU RESULT: Overall Score: %s", result.getText()));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // individual scores
 | 
				
			||||||
 | 
					        extractSectionResults6("3d");
 | 
				
			||||||
 | 
					        extractSectionResults6("ux");
 | 
				
			||||||
 | 
					        extractSectionResults6("cpu");
 | 
				
			||||||
 | 
					        extractSectionResults6("ram");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void extractSectionResults6(String section) throws Exception {
 | 
				
			||||||
 | 
					        UiSelector selector = new UiSelector();
 | 
				
			||||||
 | 
					        UiObject resultLayout = new UiObject(selector.resourceId("com.antutu.ABenchMark:id/hcf_" + section));
 | 
				
			||||||
 | 
					        UiObject result = resultLayout.getChild(selector.resourceId("com.antutu.ABenchMark:id/tv_score_value"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (result.exists()) {
 | 
				
			||||||
 | 
					            Log.v(TAG, String.format("ANTUTU RESULT: %s Score: %s", section, result.getText()));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void extractResults() throws Exception {
 | 
					    public void extractResults() throws Exception {
 | 
				
			||||||
        extractOverallResult();
 | 
					        extractOverallResult();
 | 
				
			||||||
        extractSectionResults();
 | 
					        extractSectionResults();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user