Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | |
michael@0 | 5 | from optparse import OptionParser |
michael@0 | 6 | import os |
michael@0 | 7 | import re |
michael@0 | 8 | import sys |
michael@0 | 9 | import unittest |
michael@0 | 10 | |
michael@0 | 11 | import mozlog |
michael@0 | 12 | |
michael@0 | 13 | import dmunit |
michael@0 | 14 | import genfiles |
michael@0 | 15 | |
michael@0 | 16 | |
michael@0 | 17 | def main(ip, port, heartbeat_port, scripts, directory, isTestDevice, verbose): |
michael@0 | 18 | dmunit.ip = ip |
michael@0 | 19 | dmunit.port = port |
michael@0 | 20 | dmunit.heartbeat_port = heartbeat_port |
michael@0 | 21 | if verbose: |
michael@0 | 22 | dmunit.log_level = mozlog.DEBUG |
michael@0 | 23 | |
michael@0 | 24 | suite = unittest.TestSuite() |
michael@0 | 25 | |
michael@0 | 26 | genfiles.gen_test_files() |
michael@0 | 27 | |
michael@0 | 28 | if scripts: |
michael@0 | 29 | # Ensure the user didn't include the .py on the name of the test file |
michael@0 | 30 | # (and get rid of it if they did) |
michael@0 | 31 | scripts = map(lambda x: x.split('.')[0], scripts) |
michael@0 | 32 | else: |
michael@0 | 33 | # Go through the directory and pick up everything |
michael@0 | 34 | # named test_*.py and run it |
michael@0 | 35 | testfile = re.compile('^test_.*\.py$') |
michael@0 | 36 | files = os.listdir(directory) |
michael@0 | 37 | |
michael@0 | 38 | for f in files: |
michael@0 | 39 | if testfile.match(f): |
michael@0 | 40 | scripts.append(f.split('.')[0]) |
michael@0 | 41 | |
michael@0 | 42 | testLoader = dmunit.DeviceManagerTestLoader(isTestDevice) |
michael@0 | 43 | for s in scripts: |
michael@0 | 44 | suite.addTest(testLoader.loadTestsFromModuleName(s)) |
michael@0 | 45 | unittest.TextTestRunner(verbosity=2).run(suite) |
michael@0 | 46 | |
michael@0 | 47 | genfiles.clean_test_files() |
michael@0 | 48 | |
michael@0 | 49 | |
michael@0 | 50 | if __name__ == "__main__": |
michael@0 | 51 | |
michael@0 | 52 | default_ip = '127.0.0.1' |
michael@0 | 53 | default_port = 20701 |
michael@0 | 54 | |
michael@0 | 55 | env_ip, _, env_port = os.getenv('TEST_DEVICE', '').partition(':') |
michael@0 | 56 | if env_port: |
michael@0 | 57 | try: |
michael@0 | 58 | env_port = int(env_port) |
michael@0 | 59 | except ValueError: |
michael@0 | 60 | print >> sys.stderr, "Port in TEST_DEVICE should be an integer." |
michael@0 | 61 | sys.exit(1) |
michael@0 | 62 | |
michael@0 | 63 | # Deal with the options |
michael@0 | 64 | parser = OptionParser() |
michael@0 | 65 | parser.add_option("--ip", action="store", type="string", dest="ip", |
michael@0 | 66 | help="IP address for device running SUTAgent, defaults " |
michael@0 | 67 | "to what's provided in $TEST_DEVICE or 127.0.0.1", |
michael@0 | 68 | default=(env_ip or default_ip)) |
michael@0 | 69 | |
michael@0 | 70 | parser.add_option("--port", action="store", type="int", dest="port", |
michael@0 | 71 | help="Port of SUTAgent on device, defaults to " |
michael@0 | 72 | "what's provided in $TEST_DEVICE or 20701", |
michael@0 | 73 | default=(env_port or default_port)) |
michael@0 | 74 | |
michael@0 | 75 | parser.add_option("--heartbeat", action="store", type="int", |
michael@0 | 76 | dest="heartbeat_port", help="Port for heartbeat/data " |
michael@0 | 77 | "channel, defaults to 20700", default=20700) |
michael@0 | 78 | |
michael@0 | 79 | parser.add_option("--script", action="append", type="string", |
michael@0 | 80 | dest="scripts", help="Name of test script to run, " |
michael@0 | 81 | "can be specified multiple times", default=[]) |
michael@0 | 82 | |
michael@0 | 83 | parser.add_option("--directory", action="store", type="string", dest="dir", |
michael@0 | 84 | help="Directory to look for tests in, defaults to " |
michael@0 | 85 | "current directory", default=os.getcwd()) |
michael@0 | 86 | |
michael@0 | 87 | parser.add_option("--testDevice", action="store_true", dest="isTestDevice", |
michael@0 | 88 | help="Specifies that the device is a local test agent", |
michael@0 | 89 | default=False) |
michael@0 | 90 | |
michael@0 | 91 | parser.add_option("-v", "--verbose", action="store_true", dest="verbose", |
michael@0 | 92 | help="Verbose DeviceManager output", default=False) |
michael@0 | 93 | |
michael@0 | 94 | (options, args) = parser.parse_args() |
michael@0 | 95 | |
michael@0 | 96 | main(options.ip, options.port, options.heartbeat_port, options.scripts, |
michael@0 | 97 | options.dir, options.isTestDevice, options.verbose) |