1f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen#!/usr/bin/env python
2f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen
3f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen"""
4f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny ChenRun the test suite using a separate process for each test file.
5f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen"""
6f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen
74e7965ae9fb816aff4a1852035e78b58c1edfc54Daniel Maleaimport os, sys, platform
8f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chenfrom optparse import OptionParser
9f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen
10f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen# Command template of the invocation of the test driver.
11f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chentemplate = '%s/dotest.py %s -p %s %s'
12f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen
13f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chendef walk_and_invoke(test_root, dotest_options):
14f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen    """Look for matched file and invoke test driver on it."""
15361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea    failed = []
16361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea    passed = []
17f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen    for root, dirs, files in os.walk(test_root, topdown=False):
18f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen        for name in files:
19f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen            path = os.path.join(root, name)
20f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen
21f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen            # We're only interested in the test file with the "Test*.py" naming pattern.
22f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen            if not name.startswith("Test") or not name.endswith(".py"):
23f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen                continue
24f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen
25f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen            # Neither a symbolically linked file.
26f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen            if os.path.islink(path):
27f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen                continue
28f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen
29f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen            command = template % (test_root, dotest_options if dotest_options else "", name, root)
30361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea            if 0 != os.system(command):
31361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea                failed.append(name) 
32361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea            else:
33361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea                passed.append(name)
34361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea    return (failed, passed)
35f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen
36f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chendef main():
37f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen    test_root = sys.path[0]
38f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen
39f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen    parser = OptionParser(usage="""\
40f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny ChenRun lldb test suite using a separate process for each test file.
41f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen""")
42f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen    parser.add_option('-o', '--options',
43f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen                      type='string', action='store',
44f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen                      dest='dotest_options',
45f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen                      help="""The options passed to 'dotest.py' if specified.""")
46f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen
47f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen    opts, args = parser.parse_args()
48f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen    dotest_options = opts.dotest_options
49f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen
504e7965ae9fb816aff4a1852035e78b58c1edfc54Daniel Malea    system_info = " ".join(platform.uname())
51361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea    (failed, passed) = walk_and_invoke(test_root, dotest_options)
52361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea    num_tests = len(failed) + len(passed)
534e7965ae9fb816aff4a1852035e78b58c1edfc54Daniel Malea
54361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea    print "Ran %d tests." % num_tests
55361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea    if len(failed) > 0:
56361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea        print "Failing Tests (%d)" % len(failed)
57361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea        for f in failed:
584e7965ae9fb816aff4a1852035e78b58c1edfc54Daniel Malea          print "FAIL: LLDB (suite) :: %s (%s)" % (f, system_info)
59361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea        sys.exit(1)
60361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea    sys.exit(0)
61f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen
62f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chenif __name__ == '__main__':
63f35a112038c12fa3ea1168f1a25c1699d4e443b0Johnny Chen    main()
64