aboutsummaryrefslogtreecommitdiff
path: root/automated/android/apk-automation/geekbench4.py
blob: 5e532192c51b767974dcc09ff63438187bee9e94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import glob
import json
import os
import sys
import shutil
import time
from common import ApkTestRunner
from com.dtmilano.android.viewclient import ViewNotFoundException

## geekbench-3-4-2-0.apk
## Version is 4.2.0
## size: 100171060
## md5sum: 6df73d9b5c3f9fe7383683856985a153
## Url:
##   https://geekbench-3.en.uptodown.com/android
##   https://play.google.com/store/apps/details?id=com.primatelabs.geekbench


class ApkRunnerImpl(ApkTestRunner):
    def __init__(self, config):
        self.config = config
        self.config['apk_file_name'] = "geekbench-3-4-2-0.apk"
        self.config['apk_package'] = "com.primatelabs.geekbench"
        self.config['activity'] = "com.primatelabs.geekbench/.HomeActivity"
        super(ApkRunnerImpl, self).__init__(self.config)

    def all_fail(self):
        self.report_result('geekbench-run', 'fail')
        self.report_result('geekbench-single-core', 'skip')
        self.report_result('geekbench-multi-core', 'skip')

    def execute(self):
        find_run_btn = False
        while not find_run_btn:
            time.sleep(5)
            self.dump_always()
            agreement = self.vc.findViewWithText(u'By using Geekbench you are agreeing to the terms of the Geekbench End User License Agreement and Privacy Policy.')
            if agreement:
                accept_btn = self.vc.findViewWithTextOrRaise(u'ACCEPT')
                accept_btn.touch()
                continue

            no_internet = self.vc.findViewWithText(u'Geekbench encountered an error communicating with the Geekbench Browser. Geekbench requires an active internet connection in order to run benchmarks.')
            if no_internet:
                self.logger.info("Geekbench requires an active internet connection in order to run benchmarks!")
                self.all_fail()
                sys.exit(1)

            runBench = self.vc.findViewWithText(u'RUN CPU BENCHMARK')
            if runBench:
                runBench.touch()
                find_run_btn = True
                self.logger.info("Geekbench 4 Test Started!")

        finished = False
        while (not finished):
            time.sleep(10)
            self.dump_always()
            progress = self.vc.findViewById("android:id/progress")
            progress_percent = self.vc.findViewById("android:id/progress_percent")
            if progress or progress_percent:
                self.logger.info("Geekbench 4 Test is still in progress...")
                continue

            geekbench_score = self.vc.findViewWithText(u'Geekbench Score')
            if geekbench_score:
                self.logger.info("Geekbench 4 Test Finished!")
                finished = True
                continue

            self.logger.error("Something goes wrong! It is unusual that the test has not been started after 10+ seconds! Please manually check it!")
            #self.all_fail()
            #sys.exit(1)

    def parseResult(self):
        raw_output_file = '%s/geekbench3-result-itr%s.json' % (self.config['output'], self.config['itr'])
        self.logger.info('Pulling /data/user/0/com.primatelabs.geekbench/files to output directory...')
        self.call_adb('pull /data/user/0/com.primatelabs.geekbench/files %s/files' % self.config['output'])
        db_file_list = glob.glob('%s/files/*.gb4' % self.config['output'])
        if len(db_file_list) > 1:
            self.logger.error('More then one db file found...')
            sys.exit(1)
        db_file = db_file_list[0]
        os.rename(db_file, raw_output_file)

        if os.path.exists(raw_output_file):
            with open(raw_output_file, "r") as read_file:
                res_data = json.load(read_file)
                for sec in res_data['sections']:
                    self.report_result("Geekbench4-%s" % sec["name"], "pass", sec["score"], 'points')
                    sub_testcases = sec['workloads']
                    for sub_testcase in sub_testcases:
                        self.report_result("Geekbench4-%s-%s" % (sec["name"], sub_testcase["name"].replace(' ', '_')), "pass", sub_testcase["score"], 'points')
        else:
            self.logger.error("Result file does not exist: %s" % raw_output_file)
            sys.exit(1)

    def tearDown(self):
        super(ApkRunnerImpl, self).tearDown()
        shutil.rmtree('%s/files/' % self.config['output'])