aboutsummaryrefslogtreecommitdiff
path: root/tests/run.py
blob: b816d7b3a13e06ab001889eb9aada3153fd570e6 (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
#!/usr/bin/python

import getopt
import os
import platform
import subprocess
import sys

root = os.path.dirname(__file__)
report_path = None

def usage():
    print "Usage: run.py [options]"

# parse options
try:
    opts, args = getopt.getopt(sys.argv[1:], 'hx:')
except getopt.GetoptError, err:
    print err
    usage()
    sys.exit(2)

for opt, optarg in opts:
    if opt == '-h':
        usage()
        sys.exit()
    elif opt == '-x':
        report_path = optarg
        if not os.path.exists(report_path):
            os.mkdir(report_path)

# set library path
path = os.path.join(root, '..', 'src')
if platform.system() == 'Darwin':
    os.environ['DYLD_LIBRARY_PATH'] = path
else:
    os.environ['LD_LIBRARY_PATH'] = path

# run tests
failed = False
for test in os.listdir(root):
    test_path = os.path.join(root, test)
    if os.path.isdir(test_path):
        if platform.system() == 'Darwin':
            prog = os.path.join(test_path, 'tst_' + test + '.app', 'Contents', 'MacOS', 'tst_' + test)
        elif platform.system() == 'Windows':
            prog = os.path.join(test_path, 'tst_' + test + '.exe')
        else:
            prog = os.path.join(test_path, 'tst_' + test)
        if not os.path.exists(prog):
            continue

        cmd = [ prog ]
        if report_path:
            cmd += ['-xunitxml', '-o',  os.path.join(report_path, test + '.xml') ]
        try:
            subprocess.check_call(cmd)
        except subprocess.CalledProcessError:
            failed = True

# check for failure
if failed:
    sys.exit(1)