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
|
import re
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'] = 'CF-Bench-Pro-1.3.apk'
self.config['apk_package'] = 'eu.chainfire.cfbench'
self.config['activity'] = 'eu.chainfire.cfbench/.MainActivity'
super(ApkRunnerImpl, self).__init__(self.config)
def execute(self):
find_start_btn = False
while not find_start_btn:
time.sleep(2)
self.dump_always()
warn_msg = self.vc.findViewWithText(u'This app was built for an older version of Android and may not work properly. Try checking for updates, or contact the developer.')
if warn_msg:
self.logger.info("Older version warning popped up")
warning_ok_btn = self.vc.findViewWithTextOrRaise(u'OK')
warning_ok_btn.touch()
else:
# Start test button
start_button = self.vc.findViewWithTextOrRaise("Full Benchmark")
start_button.touch()
find_start_btn = True
# Wait while cf-bench running
finished = False
while not finished:
try:
time.sleep(5)
self.dump_always()
self.vc.findViewByIdOrRaise("eu.chainfire.cfbench:id/admob_preference_layout")
finished = True
except ViewNotFoundException:
pass
except RuntimeError:
pass
except ValueError:
pass
print("Benchmark Finished")
def __get_score_with_content_desc(self, content_desc, offset=1):
try:
found_score_view = False
while not found_score_view:
score_view = self.vc.findViewWithText(content_desc)
if not score_view:
self.device.press('DPAD_DOWN')
time.sleep(2)
try:
self.dump_always()
except RuntimeError:
pass
except ValueError:
pass
else:
found_score_view = True
score_uid = score_view.getUniqueId()
uid = int(re.search("id/no_id/(?P<uid>\d+)", score_uid).group('uid'))
score = self.vc.findViewByIdOrRaise("id/no_id/%s" % (uid + offset))
score_text = score.getText()
if score_text.find("%") > 0:
score_value, units = score_text.split(" ")
self.report_result("cfbench-" + content_desc.replace(" ", "-"), 'pass', score_value, units)
else:
self.report_result("cfbench-" + content_desc.replace(" ", "-"), 'pass', score_text, 'points')
except ViewNotFoundException:
self.logger.error("%s not found" % content_desc)
pass
def parseResult(self):
# Fetch Scores
self.__get_score_with_content_desc("Native MIPS")
self.__get_score_with_content_desc("Java MIPS")
self.__get_score_with_content_desc("Native MSFLOPS")
self.__get_score_with_content_desc("Java MSFLOPS")
self.__get_score_with_content_desc("Native MDFLOPS")
self.__get_score_with_content_desc("Java MDFLOPS")
self.__get_score_with_content_desc("Native MALLOCS")
self.__get_score_with_content_desc("Native Memory Read")
self.__get_score_with_content_desc("Java Memory Read")
self.__get_score_with_content_desc("Native Memory Write")
self.__get_score_with_content_desc("Java Memory Write")
self.__get_score_with_content_desc("Native Disk Read")
self.__get_score_with_content_desc("Native Disk Write")
self.__get_score_with_content_desc("Java Efficiency MIPS")
self.__get_score_with_content_desc("Java Efficiency MSFLOPS")
self.__get_score_with_content_desc("Java Efficiency MDFLOPS")
self.__get_score_with_content_desc("Java Efficiency Memory Read")
self.__get_score_with_content_desc("Java Efficiency Memory Write")
self.__get_score_with_content_desc("Native Score")
self.__get_score_with_content_desc("Java Score")
self.__get_score_with_content_desc("Overall Score")
|