testing/mozbase/mozdevice/sut_tests/runtests.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial