summaryrefslogtreecommitdiff
path: root/vellamo3/vc.py
blob: 8756aa70c04e1c37092074a52b2ebc0169edcd26 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python
# Author:
# Milosz Wasilewski <milosz.wasilewski@linaro.org>
# Botao Sun <botao.sun@linaro.org>
import os
import sys
import time
import json
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

# Result collection for LAVA
default_unit = 'Points'

def extract_scores(filename):
    # This is one-line file, read it in a whole
    fileopen = open(filename, 'r')
    jsoncontent = json.load(fileopen)
    result_flag = 'benchmark_results'
    chapter_flag = 'chapter_name'

    total_score = 0
    for item in jsoncontent:
        if result_flag and chapter_flag in item.keys():
            chapter = item[chapter_flag]
            chapter_total = 0
            print str(len(item[result_flag])) + ' test result found in category: ' + chapter
            for elem in item[result_flag]:
                if 'failed' in elem.keys() and 'id' in elem.keys() and 'score' in elem.keys():
                    # Pick up the result
                    if False == elem['failed']:
                        result = 'pass'
                    else:
                        result = 'fail'
                    # Pick up the full test name
                    testcase = chapter + '-' + elem['id']
                    # Pick up the test score
                    score = elem['score']
                    # Submit the result to LAVA
                    call([f_output_result, "vellamo3_" + testcase, result, str(score), default_unit])
                    chapter_total = chapter_total + score
                else:
                    print 'Corrupted test result found, please check it manually.'
                    print 'A valid test result must contain id, score and pass/fail status.'

            call([f_output_result, "vellamo3_" + chapter + "_total", "pass", str(chapter_total), default_unit])
            total_score = total_score + chapter_total

        else:
            print 'Cannot find ' + result_flag + ' or ' + chapter_flag + ' in test result dictionary. Please check it manually.'
    fileopen.close()
    call([f_output_result, "vellamo3_total_score", "pass", str(total_score), default_unit])


def vc_dump(vc):
    for i in range(0, 3):
        try:
            vc.dump('-1')
            return
        except ValueError as e:
            print e
            time.sleep(1)

def choose_chapter(vc, chapter_name):
    # ToDo: scroll screen if chapter is not found on the first screen
    time.sleep(1)
    vc_dump(vc)
    chapter_tab = vc.findViewWithText(chapter_name)
    if chapter_tab is None:
        device.drag((300, 500), (300, 100), 1000, 20, 0)
        vc_dump(vc)
        chapter_tab = vc.findViewWithTextOrRaise(chapter_name)
    enclosing_tab = chapter_tab.getParent().getParent()
    for child in enclosing_tab.children:
        if child.getClass() == "android.widget.FrameLayout":
           for subchild in child.children:
               if subchild.getId() == "com.quicinc.vellamo:id/card_launcher_run_button":
                   subchild.touch()

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

vc = ViewClient(device, serialno, **kwargs2)
vc_dump(vc)

# Accept Vellamo EULA
btn_setup_1 = vc.findViewByIdOrRaise("android:id/button1")
btn_setup_1.touch()
vc_dump(vc)

# open settings
vc_dump(vc)
btn_settings = vc.findViewByIdOrRaise('com.quicinc.vellamo:id/main_toolbar_wheel')
btn_settings.touch()

# disable animations
vc_dump(vc)
btn_animations = vc.findViewWithTextOrRaise(u'Make Vellamo even more beautiful')
btn_animations.touch()

# back to the home screen
device.press("KEYCODE_BACK")
chapters = ['Browser', 'Multicore', 'Metal']

for chapter in chapters:
    choose_chapter(vc, chapter)

    # Start benchmark
    vc_dump(vc)
    btn_start = vc.findViewByIdOrRaise("com.quicinc.vellamo:id/main_toolbar_operation_button")
    btn_start.touch()

    # Wait while Vellamo is running benchmark
    finished = False
    while (not finished):
        time.sleep(1)
        try:
            vc.dump(window='-1')
            vc.findViewByIdOrRaise("com.quicinc.vellamo:id/main_toolbar_goback_title")
            btn_no = vc.findViewByIdOrRaise("com.quicinc.vellamo:id/button_no")
            btn_no.touch()
            finished = True
        except ViewNotFoundException:
            pass
        except RuntimeError as e:
            print e
        except  ValueError as ve:
            print ve

    print "Benchmark finished: %s" % chapter
    device.press("KEYCODE_BACK")
    device.press("KEYCODE_BACK")

return_value = call(['%s/get_result.sh' % parent_dir])
if return_value == 0:
    extract_scores(filename='chapterscores.json')
else:
    print 'Test result file transfer failed!'
    sys.exit(1)