summaryrefslogtreecommitdiff
path: root/antutu2/vc.py
blob: ef3f25800d612ac60d637d1e2467b0c3c3ce2538 (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
import re
import sys
import os
import time
from subprocess import call

from com.dtmilano.android.viewclient import ViewClient, ViewNotFoundException

parent_dir = os.path.realpath(os.path.dirname(__file__))
f_output_result="%s/../common/output-test-result.sh"  % parent_dir

default_unit = 'points'

kwargs1 = {'verbose': False, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False}
vc = ViewClient(device, serialno, **kwargs2)


def dump_always():
    success = False
    while not success:
        try:
            vc.dump()
            success = True
        except RuntimeError:
            print("Got RuntimeError when call vc.dump()")
            time.sleep(5)
        except ValueError:
            print("Got ValueError when call vc.dump()")
            time.sleep(5)


def output_result(test_name, measurement):
    call([f_output_result, "antutu282_" + test_name, 'pass',  measurement, default_unit])


time.sleep(5)
dump_always()
# release info and upgrade dialog are not presented
# if there is no connection to Internet
try:
    button_cancel = vc.findViewByIdOrRaise("android:id/button2")
    button_cancel.touch()
except ViewNotFoundException:
    pass

try:
    dump_always()
    time.sleep(2)
    button_ok = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/button_ok")
    button_ok.touch()
except ViewNotFoundException:
    pass

time.sleep(2)
dump_always()
button_test = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/btn_test")
button_test.touch()

time.sleep(2)
dump_always()
button_start_test = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/button_test")
button_start_test.touch()

finished = False
while(not finished):
    time.sleep(1)
    try:
        dump_always()
        if vc.findViewById("com.antutu.ABenchMark:id/layoutScoresHeader"):
            finished = True
    except RuntimeError as e:
        print e
    except ValueError as ve:
        print ve
print "benchmark finished"

# close unnecessary windows if they appear
for index in range(0, 3):
    time.sleep(1)
    dump_always()
    if vc.findViewById("com.antutu.ABenchMark:id/num_1"):
        break
    else:
        device.press('KEYCODE_BACK')

time.sleep(2)
dump_always()
header = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/layoutScoresHeader")
if not vc.findViewById("com.antutu.ABenchMark:id/layoutScores"):
    header.touch()

time.sleep(2)
dump_always()
mem_score = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/text_mem")
cpu_int_score = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/text_int")
cpu_float_score = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/text_float")
twod_score = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/text_2d")
threed_score = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/text_3d")
db_score = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/text_db")
sd_write_score = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/text_sdw")
sd_read_score = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/text_sdr")

output_result("CPU_Integer_Score", cpu_int_score.getText())
output_result("CPU_Float_Score", cpu_float_score.getText())
output_result("2D_Score", twod_score.getText())
output_result("3D_Score", threed_score.getText())
output_result("Mem_Score", mem_score.getText())
output_result("DB_Score", db_score.getText())
output_result("SD_Write_Score", sd_write_score.getText().strip().split(' ').pop())
output_result("SD_Read_Score", sd_read_score.getText().strip().split(' ').pop())

total_score = int(cpu_int_score.getText().strip()) + int(cpu_float_score.getText().strip()) + int(twod_score.getText().strip())
total_score = total_score + int(threed_score.getText().strip()) + int(mem_score.getText().strip()) + int(db_score.getText().strip())
total_score = total_score + int(sd_write_score.getText().strip().split(' ').pop()) + int(sd_read_score.getText().strip().split(' ').pop())
output_result("total_score", str(total_score))