testing/tps/tps/cli.py

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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 import json
     6 import optparse
     7 import os
     8 import re
     9 import sys
    10 from threading import RLock
    12 from tps import TPSTestRunner
    15 def main():
    16     parser = optparse.OptionParser()
    17     parser.add_option('--binary',
    18                       action='store',
    19                       type='string',
    20                       dest='binary',
    21                       default=None,
    22                       help='path to the Firefox binary, specified either as '
    23                            'a local file or a url; if omitted, the PATH '
    24                            'will be searched;')
    25     parser.add_option('--configfile',
    26                       action='store',
    27                       type='string',
    28                       dest='configfile',
    29                       default=None,
    30                       help='path to the config file to use default: %default]')
    31     parser.add_option('--debug',
    32                       action='store_true',
    33                       dest='debug',
    34                       default=False,
    35                       help='run in debug mode')
    36     parser.add_option('--ignore-unused-engines',
    37                        default=False,
    38                        action='store_true',
    39                        dest='ignore_unused_engines',
    40                        help='If defined, do not load unused engines in individual tests.'
    41                             ' Has no effect for pulse monitor.')
    42     parser.add_option('--logfile',
    43                       action='store',
    44                       type='string',
    45                       dest='logfile',
    46                       default='tps.log',
    47                       help='path to the log file [default: %default]')
    48     parser.add_option('--mobile',
    49                       action='store_true',
    50                       dest='mobile',
    51                       default=False,
    52                       help='run with mobile settings')
    53     parser.add_option('--pulsefile',
    54                       action='store',
    55                       type='string',
    56                       dest='pulsefile',
    57                       default=None,
    58                       help='path to file containing a pulse message in '
    59                            'json format that you want to inject into the monitor')
    60     parser.add_option('--resultfile',
    61                       action='store',
    62                       type='string',
    63                       dest='resultfile',
    64                       default='tps_result.json',
    65                       help='path to the result file [default: %default]')
    66     parser.add_option('--testfile',
    67                       action='store',
    68                       type='string',
    69                       dest='testfile',
    70                       default='all_tests.json',
    71                       help='path to the test file to run [default: %default]')
    72     (options, args) = parser.parse_args()
    74     configfile = options.configfile
    75     if configfile is None:
    76         virtual_env = os.environ.get('VIRTUAL_ENV')
    77         if virtual_env:
    78             configfile = os.path.join(virtual_env, 'config.json')
    79         if configfile is None or not os.access(configfile, os.F_OK):
    80             raise Exception('Unable to find config.json in a VIRTUAL_ENV; you must '
    81                             'specify a config file using the --configfile option')
    83     # load the config file
    84     f = open(configfile, 'r')
    85     configcontent = f.read()
    86     f.close()
    87     config = json.loads(configcontent)
    88     testfile = os.path.join(config.get('testdir', ''), options.testfile)
    90     rlock = RLock()
    92     print 'using result file', options.resultfile
    94     extensionDir = config.get('extensiondir')
    95     if not extensionDir or extensionDir == '__EXTENSIONDIR__':
    96         extensionDir = os.path.join(os.getcwd(), '..', '..',
    97                                     'services', 'sync', 'tps', 'extensions')
    98     else:
    99         if sys.platform == 'win32':
   100             # replace msys-style paths with proper Windows paths
   101             m = re.match('^\/\w\/', extensionDir)
   102             if m:
   103                 extensionDir = '%s:/%s' % (m.group(0)[1:2], extensionDir[3:])
   104                 extensionDir = extensionDir.replace('/', '\\')
   106     TPS = TPSTestRunner(extensionDir,
   107                         binary=options.binary,
   108                         config=config,
   109                         debug=options.debug,
   110                         ignore_unused_engines=options.ignore_unused_engines,
   111                         logfile=options.logfile,
   112                         mobile=options.mobile,
   113                         resultfile=options.resultfile,
   114                         rlock=rlock,
   115                         testfile=testfile,
   116                       )
   117     TPS.run_tests()
   119 if __name__ == '__main__':
   120     main()

mercurial