summaryrefslogtreecommitdiff
path: root/automated/android/apk-automation/geekbench3.py
blob: 211107d6614f75a4ac0326255962e8ca80e963c2 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import glob
import os
import sys
import shutil
import time
from common import ApkTestRunner
from com.dtmilano.android.viewclient import ViewNotFoundException


class ApkRunnerImpl(ApkTestRunner):
    def __init__(self, config):
        self.config = config
        self.config['apk_file_name'] = "com.primatelabs.geekbench3.apk"
        self.config['apk_package'] = "com.primatelabs.geekbench3"
        self.config['activity'] = "com.primatelabs.geekbench3/.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):
        try:
            time.sleep(2)
            self.dump_always()
            trigger = self.vc.findViewByIdOrRaise(self.config['apk_package'] + ":id/runBenchmarks")
            trigger.touch()
            self.logger.info("Geekbench 3 Test Started!")
        except ViewNotFoundException:
            self.logger.error("Can not find the start button! Please check the screen!")
            self.all_fail()
            sys.exit(1)

        time.sleep(10)
        self.dump_always()

        try:
            self.vc.findViewByIdOrRaise("android:id/progress")
        except ViewNotFoundException:
            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)

        finished = False
        while (not finished):
            time.sleep(45)
            self.dump_always()
            flag = self.vc.findViewWithText("RESULT")
            if flag is not None:
                self.logger.info("Geekbench 3 Test Finished!")
                finished = True
            else:
                self.logger.info("Geekbench 3 Test is still in progress...")

        # Generate the .gb3 file
        self.device.press('KEYCODE_MENU')
        time.sleep(1)
        self.dump_always()
        share_button = self.vc.findViewWithText("Share")
        if share_button is not None:
            share_button.touch()
            time.sleep(5)
        else:
            self.logger.error("Can not find the Share button to generate .gb3 file! Please check the screen!")
            sys.exit(1)

    def parseResult(self):
        raw_output_file = '%s/geekbench3-result-itr%s.gb3' % (self.config['output'], self.config['itr'])
        self.logger.info('Pulling /data/user/0/com.primatelabs.geekbench3/files to output directory...')
        self.call_adb('pull /data/user/0/com.primatelabs.geekbench3/files %s/files' % self.config['output'])
        db_file_list = glob.glob('%s/files/*.gb3' % 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)

        singlecore_keyword = "score"
        singlecore_result = {}
        multicore_keyword = "multicore_score"
        multicore_result = {}
        endpoint_keyword = "multicore_rate"

        if os.path.exists(raw_output_file):
            logfile = open(raw_output_file, "r")
            for line in logfile:
                # Can't believe this is an one line file!
                # Find the ending point with the information we want
                endpoint = line.find(endpoint_keyword)
                if endpoint == -1:
                    self.logger.error("Can not find %s in log file! Please manually check it!" % endpoint_keyword)
                    self.all_fail()
                    sys.exit(1)
                else:
                    self.report_result("geekbench-run", "pass")
                    result_cut = line[0:endpoint].split(",")
                    result_cut = [element.replace('"', '').replace(' ', '') for element in result_cut]
                    for item in result_cut:
                        if singlecore_keyword == item.split(":")[0]:
                            singlecore_result[singlecore_keyword] = item.split(":")[1]
                        if multicore_keyword == item.split(":")[0]:
                            multicore_result[multicore_keyword] = item.split(":")[1]
                    if len(singlecore_result) != 1:
                        run_result = "fail"
                        self.logger.error("Incorrect value for single core test result! Please check the test result file!")
                        self.report_result('geekbench-single-core', run_result)
                    else:
                        run_result = "pass"
                        self.report_result('geekbench-single-core', run_result, singlecore_result[singlecore_keyword])
                    if len(multicore_result) != 1:
                        run_result = "fail"
                        self.logger.error("Incorrect value for multi core test result! Please check the test result file!")
                        self.report_result('geekbench-multi-core', run_result)
                    else:
                        run_result = "pass"
                        self.report_result('geekbench-multi-core', run_result, multicore_result[multicore_keyword])

            logfile.close()
        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'])