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
|
# Author: Botao Sun <botao.sun@linaro.org>
import sys
import time
from subprocess import call
from com.dtmilano.android.viewclient import ViewClient, ViewNotFoundException
def collect_score(benchmark_name, run_result, score_number, score_unit):
call(['lava-test-case', benchmark_name, '--result', run_result, '--measurement', score_number, '--units', score_unit])
benchmark_name = "BenchmarkPi"
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)
time.sleep(2)
vc.dump(window='-1')
start_button = vc.findViewByIdOrRaise("gr.androiddev.BenchmarkPi:id/Button01")
start_button.touch()
finished = False
while (not finished):
time.sleep(1)
try:
vc.dump(window='-1')
vc.findViewByIdOrRaise("android:id/message")
finished = True
except ViewNotFoundException:
pass
except RuntimeError as e:
print e
print "benchmark finished"
return_text = vc.findViewByIdOrRaise("android:id/message").getText().split(" ")
flagwordA = "calculated"
flagwordB = "Pi"
if flagwordA in return_text and flagwordB in return_text:
if return_text.index(flagwordB) == return_text.index(flagwordA) + 1:
print "This is an valid test result"
score_number = return_text[return_text.index(flagwordA) + 3]
score_unit = return_text[return_text.index(flagwordA) + 4].split("!")[0]
print score_number + " " + score_unit
run_result = "pass"
else:
print "Output string changed, parser need to be updated!"
sys.exit(1)
else:
print "Can not find keyword which is supposed to show up!"
sys.exit(1)
# Submit the test result to LAVA
collect_score(benchmark_name, run_result, score_number, score_unit)
# Exit the app
vc.dump(window='-1')
exit_button = vc.findViewByIdOrRaise("android:id/button2")
exit_button.touch()
|