summaryrefslogtreecommitdiffstats
blob: 84af812c529bb90b05b11ae48409d979907429cc (plain) (blame)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/python
###
### Copyright (C) 2011 Texas Instruments
###
### Licensed under the Apache License, Version 2.0 (the "License");
### you may not use this file except in compliance with the License.
### You may obtain a copy of the License at
###
###      http://www.apache.org/licenses/LICENSE-2.0
###
### Unless required by applicable law or agreed to in writing, software
### distributed under the License is distributed on an "AS IS" BASIS,
### WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
### See the License for the specific language governing permissions and
### limitations under the License.
###

#
# TI Android Audio team master test runner script.
#

import sys, os, os.path, time
import signal
import TestFlinger

###
### Configure tests here
###
### Each element is a dict that will be passed to the TestCase
### constructor.  See the documentation for TestCase.__init__()
### for key/value pair documentation.
###

g_tests = [
    # These first tests are simply to verify that the test
    # framework is working.
    { 'filename': '/bin/true',
      'args':     None,
      'timeout':  None,
      'expect-fail': False, },
    { 'filename': '/bin/false',
      'args':     None,
      'timeout':  None,
      'expect-fail': True, },
    { 'filename': 'test-signal',
      'args':     None,
      'timeout':  None,
      'expect-signal': True, },

    # Actual product tests here

    { 'filename': 'music-monkey.py',
      'timeout':  60*30, },
    ]

# These executables are known to be needed for the tests.
# They must be available explicitly or in the current PATH.

g_required_executables = [
    '/bin/bash',
    '/bin/false',
    '/bin/sh',
    '/bin/true',
    'adb',
    'bash',
    'monkeyrunner',
    'pgrep',
    'python',
    'sh',
    ]

# These are files that
g_required_files = [
    ]

###
### Signal handler
###

g_tcase = None
def sigint_handler(signum, stack_frame):
    global g_tcase
    print
    print "Received SIGINT, aborting current test..."
    if g_tcase is not None:
        g_tcase.kill()
    sys.exit(signum)

###
### Utility functions
###

def check_for_executable(name):
    """Checks that executable is available (either explicitly or in the PATH
    returns True if so, False if not.
    """
    err = os.system("which %s > /dev/null" % (name,))
    return (err == 0)

def check_for_file(name):
    return os.path.exists(name)

def check_adb_server_running():
    """Checks that the ADB server is currently running.  Returns  True if
    so, False otherwise.  Uses the pgrep command.
    """
    err = os.system("pgrep adb > /dev/null")
    return (err == 0)

def sanity_check():
    """Checks that required binaries are available and functioning in a sane manner,
    returns True if so, False if something is missing.  It checks that things like
    adb and monkeyrunner are in the path
    """

    rv = True
    for F in g_required_executables:
        ok = check_for_executable(F)
        if not ok:
            print "ERROR: cannot find the executable '%s'" % (F,)
            rv = False
    for F in g_required_files:
        ok = check_for_file(F)
        if not ok:
            print "ERROR: cannot find the file '%s'" % (F,)
            rv = False

    ok = check_adb_server_running()
    if not ok:
        print "ERROR: the adb server must be running before starting tests"
        rv = False

    return rv

###
### Main test script
###

def main(argv = []):
    global g_tests, g_tcase

    g_tcase = None
    signal.signal(signal.SIGINT, sigint_handler)

    if not sanity_check():
        return 1

    err = os.system("adb root")
    if err != 0:
        print "ERROR: could not set adb to run as root.  Aborting."
        return 1

    time.sleep(2.0) # Wait for device to restart its server

    log = TestFlinger.setup_logfile()

    for N in g_tests:
        tcase = TestFlinger.TestCase(N, log)
        g_tcase = tcase

        ok = tcase.start()
        if not ok:
            print "ERROR: could not start test '%s'.  Skipping" % (N['filename'],)

        if ok:
            tcase.wait()
            verdict = tcase.verdict()
            verdict = N['filename'] + ": " + verdict
        else:
            verdict = N['filename'] + ": FAIL"

        print verdict
        log.write("\n" + verdict + "\n")
        log.flush()

    TestFlinger.close_logfile(log)

    return 0

if __name__ == "__main__":
    rv = main(sys.argv)
    sys.exit(rv)