summaryrefslogtreecommitdiff
path: root/automated/android/apk-automation/test.py
blob: 28b7df22ccfac7360fe82a43e8ace29554703235 (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
import re
import sys
import os
import time
from subprocess import call

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


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 get_score_with_text(vc, text):
    found_score_view = False

    while not found_score_view:
        linear_layout = vc.findViewByIdOrRaise("com.redlicense.benchmark.sqlite:id/stats")
        for ch in linear_layout.children:
            subitem = vc.findViewWithText(text, ch)
            if subitem:
                subitem_result = vc.findViewByIdOrRaise("com.redlicense.benchmark.sqlite:id/test_result", ch)
                score = subitem_result.getText().replace("sec", "").strip()
                score_in_ms = float(score) * 1000
                print "RL_sqlite_%s %s %s ms" % (text.replace(" ", "_"), 'pass', str(score_in_ms))
                found_score_view = True
                break
        else:
            print("%s not found, need to pageup" % text)
            dump_always()
            device.press('DPAD_UP')
            time.sleep(2)
            dump_always()
            device.press('DPAD_UP')
            time.sleep(2)
            dump_always()

dump_always()
vc.findViewWithTextOrRaise(u'Overall').touch()
get_score_with_text(vc, "Overall")
get_score_with_text(vc, "DROP TABLE")
get_score_with_text(vc, "DELETE with an index")
get_score_with_text(vc, "DELETE without an index")
get_score_with_text(vc, "INSERTs from a SELECT")
get_score_with_text(vc, "25000 UPDATEs with an index")
get_score_with_text(vc, "1000 UPDATEs without an index")
get_score_with_text(vc, "5000 SELECTs with an index")
get_score_with_text(vc, "Creating an index")
get_score_with_text(vc, "100 SELECTs on a string comparison")
get_score_with_text(vc, "100 SELECTs without an index")
get_score_with_text(vc, "25000 INSERTs into an indexed table in a transaction")
get_score_with_text(vc, "25000 INSERTs in a transaction")
get_score_with_text(vc, "1000 INSERTs")