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
|
import time
import xml.dom.minidom
from common import ApkTestRunner
class ApkRunnerImpl(ApkTestRunner):
def __init__(self, config):
self.config = config
self.config['apk_file_name'] = 'GLBenchmark_2.5.1.apk'
self.config['apk_package'] = 'com.glbenchmark.glbenchmark25'
self.config['activity'] = 'com.glbenchmark.glbenchmark25/com.glbenchmark.activities.GLBenchmarkDownloaderActivity'
super(ApkRunnerImpl, self).__init__(self.config)
def setUp(self):
self.download_apk('main.1.com.glbenchmark.glbenchmark25.obb')
self.uninstall_apk(self.config['apk_package'])
self.install_apk(self.config['apk_file_name'])
# Push data and config files.
self.logger.info('Pushing main.1.com.glbenchmark.glbenchmark25.obb to target...')
self.call_adb('push %s/main.1.com.glbenchmark.glbenchmark25.obb /sdcard/Android/obb/com.glbenchmark.glbenchmark25/main.1.com.glbenchmark.glbenchmark25.obb' % self.config['apk_dir'])
self.logger.info('Pushing glbenchmark25-preferences.xml to target...')
self.call_adb('push ./glbenchmark25-preferences.xml /data/data/com.glbenchmark.glbenchmark25/shared_prefs/com.glbenchmark.glbenchmark25_preferences.xml')
# Clear logcat buffer.
self.call_adb("logcat -c")
self.call_adb("logcat -b events -c")
time.sleep(3)
# Start intent.
self.logger.info('Starting %s' % self.config['apk_package'])
self.call_adb("shell am start -W -S %s" % self.config['activity'])
def execute(self):
time.sleep(2)
self.vc.dump(window='-1')
test_type = self.vc.findViewWithText("Performance Tests")
if test_type:
test_type.touch()
time.sleep(2)
# By some reason in order to select all test, a back step is required
self.dump_always()
test_selection = self.vc.findViewByIdOrRaise("com.glbenchmark.glbenchmark25:id/buttonAll")
self.device.press('KEYCODE_BACK')
time.sleep(3)
test_type.touch()
time.sleep(2)
test_selection.touch()
self.logger.info("All selected!")
time.sleep(3)
# Disable crashed test suites
self.vc.dump(window='-1')
crashed_test_name = "C24Z24MS4"
self.logger.info('Test suite %s is going to be disabled!' % crashed_test_name)
crashed_test = self.vc.findViewWithText(crashed_test_name)
if crashed_test is not None:
crashed_test.touch()
self.logger.info('Test suite %s has been excluded!' % crashed_test_name)
time.sleep(2)
else:
self.logger.info('Can not find test suite %s, please check the screen!' % crashed_test_name)
# Start selected test suites
start_button = self.vc.findViewByIdOrRaise("com.glbenchmark.glbenchmark25:id/buttonStart")
start_button.touch()
time.sleep(2)
finished = False
while not finished:
time.sleep(120)
self.dump_always()
flag = self.vc.findViewWithText("Result processing")
if flag is not None:
self.logger.info('GLBenchmark Test Finished.')
finished = True
# Give up the result upload
cancel_button = self.vc.findViewWithText("Cancel")
if cancel_button is not None:
cancel_button.touch()
time.sleep(5)
else:
self.logger.error('Can not find cancel button! Please check the pop up window!')
else:
self.logger.info('GLBenchmark Test is still in progress...')
def getText(self, node):
children = node.childNodes
rc = []
for node in children:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
return ''.join(rc)
def logparser(self, cached_result_file):
run_result = 'pass'
dom = xml.dom.minidom.parse(cached_result_file)
results = dom.getElementsByTagName('test_result')
for test in results:
title = self.getText(test.getElementsByTagName('title')[0])
test_type = self.getText(test.getElementsByTagName('type')[0])
score_number = self.getText(test.getElementsByTagName('score')[0])
fps = self.getText(test.getElementsByTagName('fps')[0])
score_unit = self.getText(test.getElementsByTagName('uom')[0])
benchmark_name = title.replace(" ", "-").replace(":", "") + "-" + test_type.replace(" ", "-").replace(":", "")
self.report_result(benchmark_name, run_result, score_number, score_unit)
if fps != "":
score_number = fps.split(" ")[0]
score_unit = fps.split(" ")[1]
self.report_result(benchmark_name, run_result, score_number, score_unit)
def parseResult(self):
cached_result_file = '%s/last-results-2.5.1-itr%s.xml' % (self.config['output'], self.config['itr'])
self.logger.info('pull /data/data/com.glbenchmark.glbenchmark25/cache/last_results_2.5.1.xml to output directory...')
self.call_adb('pull /data/data/com.glbenchmark.glbenchmark25/cache/last_results_2.5.1.xml %s' % cached_result_file)
self.logparser(cached_result_file)
|