mirror of
				https://github.com/ARM-software/workload-automation.git
				synced 2025-11-04 00:52:08 +00:00 
			
		
		
		
	antutu: Updated to support Antutu v6
This commit is contained in:
		@@ -16,7 +16,8 @@
 | 
			
		||||
import os
 | 
			
		||||
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):
 | 
			
		||||
@@ -46,7 +47,7 @@ class Antutu(AndroidUiAutoBenchmark):
 | 
			
		||||
    activity = ".ABenchMarkStart"
 | 
			
		||||
    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_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
 | 
			
		||||
        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['times'] = self.times
 | 
			
		||||
        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):
 | 
			
		||||
        super(Antutu, self).update_result(context)
 | 
			
		||||
        with open(self.logcat_log) as fh:
 | 
			
		||||
            if self.version == '4.0.3':
 | 
			
		||||
                metrics = extract_version4_metrics(fh)
 | 
			
		||||
            if self.version == '3.3.2':
 | 
			
		||||
                metrics = extract_older_version_metrics(fh)
 | 
			
		||||
            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():
 | 
			
		||||
            key = key.replace(' ', '_')
 | 
			
		||||
            context.result.add_metric(key, value)
 | 
			
		||||
@@ -87,7 +96,7 @@ class Antutu(AndroidUiAutoBenchmark):
 | 
			
		||||
 | 
			
		||||
# Utility functions
 | 
			
		||||
 | 
			
		||||
def extract_version4_metrics(fh):
 | 
			
		||||
def extract_metrics(fh):
 | 
			
		||||
    metrics = OrderedDict()
 | 
			
		||||
    metric_counts = defaultdict(int)
 | 
			
		||||
    for line in fh:
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							@@ -34,36 +34,60 @@ import com.android.uiautomator.testrunner.UiAutomatorTestCase;
 | 
			
		||||
 | 
			
		||||
import com.arm.wlauto.uiauto.BaseUiAutomation;
 | 
			
		||||
 | 
			
		||||
public class UiAutomation extends BaseUiAutomation {   
 | 
			
		||||
public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
 | 
			
		||||
    public void runUiAutomation() throws Exception{
 | 
			
		||||
        Bundle parameters = getParams();
 | 
			
		||||
 | 
			
		||||
        String version = parameters.getString("version");
 | 
			
		||||
        boolean enableSdTests = Boolean.parseBoolean(parameters.getString("enable_sd_tests")); 
 | 
			
		||||
        boolean enableSdTests = Boolean.parseBoolean(parameters.getString("enable_sd_tests"));
 | 
			
		||||
 | 
			
		||||
        int times = Integer.parseInt(parameters.getString("times"));
 | 
			
		||||
        if (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;
 | 
			
		||||
            dismissNewVersionNotificationIfNecessary();
 | 
			
		||||
            hitTestButton();
 | 
			
		||||
            while (true) {
 | 
			
		||||
                    if (version.equals("5.3.0"))
 | 
			
		||||
                        hitTestButtonVersion5();
 | 
			
		||||
                    if(version.equals("6.0.1"))
 | 
			
		||||
                        hitTestButtonVersion5(TestButton6);
 | 
			
		||||
                    else if (version.equals("5.3.0")) {
 | 
			
		||||
                        hitTestButton();
 | 
			
		||||
                        hitTestButtonVersion5(TestButton5);
 | 
			
		||||
                    }
 | 
			
		||||
                    else if (version.equals("4.0.3")) {
 | 
			
		||||
                        hitTestButton();
 | 
			
		||||
                        hitTestButton();
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                        hitTestButton();
 | 
			
		||||
 | 
			
		||||
                    waitForVersion4Results();
 | 
			
		||||
                    viewDetails();
 | 
			
		||||
                    extractResults();
 | 
			
		||||
                    if(version.equals("6.0.1"))
 | 
			
		||||
                    {
 | 
			
		||||
                        waitForVersion6Results();
 | 
			
		||||
                        extractResults6();
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        waitForVersion4Results();
 | 
			
		||||
                        viewDetails();
 | 
			
		||||
                        extractResults();
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    iteration++;
 | 
			
		||||
                    if (iteration >= times) {
 | 
			
		||||
@@ -74,13 +98,6 @@ public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
                    dismissRateDialogIfNecessary();
 | 
			
		||||
                    testAgain();
 | 
			
		||||
            }
 | 
			
		||||
        } else { // version earlier than 4.0.3
 | 
			
		||||
            dismissReleaseNotesDialogIfNecessary();
 | 
			
		||||
            if(!enableSdTests){
 | 
			
		||||
               disableSdCardTests();
 | 
			
		||||
            }
 | 
			
		||||
            hitStart();
 | 
			
		||||
            waitForAndViewResults();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Bundle status = new Bundle();
 | 
			
		||||
@@ -98,7 +115,7 @@ public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    public boolean dismissReleaseNotesDialogIfNecessary() throws Exception {
 | 
			
		||||
        UiSelector selector = new UiSelector();
 | 
			
		||||
        UiObject closeButton = new UiObject(selector.text("Close"));
 | 
			
		||||
@@ -118,11 +135,11 @@ public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
        // Sometimes, dismissing the dialog the first time does not work properly --
 | 
			
		||||
        // it starts to disappear but is then immediately re-created; so may need to
 | 
			
		||||
        // dismiss it as long as keeps popping up.
 | 
			
		||||
        while (closeButton.waitForExists(2)) { 
 | 
			
		||||
        while (closeButton.waitForExists(2)) {
 | 
			
		||||
            closeButton.click();
 | 
			
		||||
            sleep(1); // diaglog dismissal
 | 
			
		||||
            dismissed = true;
 | 
			
		||||
        } 
 | 
			
		||||
        }
 | 
			
		||||
        return dismissed;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -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 */
 | 
			
		||||
 | 
			
		||||
   public void hitTestButtonVersion5() throws Exception {
 | 
			
		||||
   public void hitTestButtonVersion5(String id) throws Exception {
 | 
			
		||||
        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"));
 | 
			
		||||
        test.waitForExists(initialTimeoutSeconds);
 | 
			
		||||
        test.click();
 | 
			
		||||
        sleep(1); // possible tab transtion
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public void hitTest() throws Exception {
 | 
			
		||||
        UiSelector selector = new UiSelector();
 | 
			
		||||
        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 {
 | 
			
		||||
        UiSelector selector = new UiSelector();
 | 
			
		||||
        UiObject detailsButton = new UiObject(new UiSelector().className("android.widget.Button")
 | 
			
		||||
@@ -200,6 +229,30 @@ public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
        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 {
 | 
			
		||||
        extractOverallResult();
 | 
			
		||||
        extractSectionResults();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user