Bug 638219 - Save static paths in module-level constants; r=terrence
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Fri, 15 Feb 2013 09:01:19 +0100
changeset 134720 513464517953eb7b5cec6589fc2ccadaf2568306
parent 134719 a8d5cbaa6a46ecd2af63fc04d9c8531a6d7a4fd6
child 134721 750b5be0a25cccaf338274b81d7a21586b992bc8
push id336
push userakeybl@mozilla.com
push dateMon, 17 Jun 2013 22:53:19 +0000
treeherdermozilla-release@574a39cdf657 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs638219
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 638219 - Save static paths in module-level constants; r=terrence These paths are a little far away from the script they're referenced in, so it's a little fragile. However, since (a) these aren't expected to change that often, and (b) the code should fail conspicuously if there is a change, I don't think it's a problem.
browser/devtools/shared/Browser.jsm
browser/devtools/shared/test/browser_browser_basic.js
js/src/jit-test/jit_test.py
js/src/tests/lib/jittests.py
--- a/js/src/jit-test/jit_test.py
+++ b/js/src/jit-test/jit_test.py
@@ -13,21 +13,16 @@ def add_libdir_to_path():
     sys.path.append(join(js_src_dir, 'tests', 'lib'))
 
 add_libdir_to_path()
 
 import jittests
 
 def main(argv):
 
-    script_path = os.path.abspath(__file__)
-    script_dir = os.path.dirname(script_path)
-    test_dir = os.path.join(script_dir, 'tests')
-    lib_dir = os.path.join(script_dir, 'lib')
-
     # If no multiprocessing is available, fallback to serial test execution
     max_jobs_default = 1
     if jittests.HAVE_MULTIPROCESSING:
         try:
             max_jobs_default = jittests.cpu_count()
         except NotImplementedError:
             pass
 
@@ -101,41 +96,41 @@ def main(argv):
         options.write_failures = options.retest
 
     test_list = []
     read_all = True
 
     if test_args:
         read_all = False
         for arg in test_args:
-            test_list += jittests.find_tests(test_dir, arg)
+            test_list += jittests.find_tests(arg)
 
     if options.read_tests:
         read_all = False
         try:
             f = open(options.read_tests)
             for line in f:
-                test_list.append(os.path.join(test_dir, line.strip('\n')))
+                test_list.append(os.path.join(TEST_DIR, line.strip('\n')))
             f.close()
         except IOError:
             if options.retest:
                 read_all = True
             else:
                 sys.stderr.write("Exception thrown trying to read test file '%s'\n"%
                                  options.read_tests)
                 traceback.print_exc()
                 sys.stderr.write('---\n')
 
     if read_all:
-        test_list = jittests.find_tests(test_dir)
+        test_list = jittests.find_tests()
 
     if options.exclude:
         exclude_list = []
         for exclude in options.exclude:
-            exclude_list += jittests.find_tests(test_dir, exclude)
+            exclude_list += jittests.find_tests(exclude)
         test_list = [ test for test in test_list if test not in set(exclude_list) ]
 
     if not test_list:
         print >> sys.stderr, "No tests found matching command line arguments."
         sys.exit(0)
 
     test_list = [jittests.Test.from_file(_, options) for _ in test_list]
 
@@ -184,26 +179,26 @@ def main(argv):
     if options.debug:
         if len(job_list) > 1:
             print 'Multiple tests match command line arguments, debugger can only run one'
             for tc in job_list:
                 print '    %s' % tc.path
             sys.exit(1)
 
         tc = job_list[0]
-        cmd = [ 'gdb', '--args' ] + tc.command(options.js_shell, lib_dir, shell_args)
+        cmd = [ 'gdb', '--args' ] + tc.command(options.js_shell, shell_args)
         subprocess.call(cmd)
         sys.exit()
 
     try:
         ok = None
         if options.max_jobs > 1 and jittests.HAVE_MULTIPROCESSING:
-            ok = jittests.run_tests_parallel(job_list, test_dir, lib_dir, shell_args, options)
+            ok = jittests.run_tests_parallel(job_list, shell_args, options)
         else:
-            ok = jittests.run_tests(job_list, test_dir, lib_dir, shell_args, options)
+            ok = jittests.run_tests(job_list, shell_args, options)
         if not ok:
             sys.exit(2)
     except OSError:
         if not os.path.exists(options.js_shell):
             print >> sys.stderr, "JS shell argument: file does not exist: '%s'" % options.js_shell
             sys.exit(1)
         else:
             raise
--- a/js/src/tests/lib/jittests.py
+++ b/js/src/tests/lib/jittests.py
@@ -16,16 +16,21 @@ import signal
 try:
     from multiprocessing import Process, Manager, cpu_count
     HAVE_MULTIPROCESSING = True
 except ImportError:
     HAVE_MULTIPROCESSING = False
 
 from progressbar import ProgressBar, NullProgressBar
 
+TESTS_LIB_DIR = os.path.dirname(os.path.abspath(__file__))
+JS_DIR = os.path.dirname(os.path.dirname(TESTS_LIB_DIR))
+TEST_DIR = os.path.join(JS_DIR, 'jit-test', 'tests')
+LIB_DIR = os.path.join(JS_DIR, 'jit-test', 'lib') + os.path.sep
+
 # Backported from Python 3.1 posixpath.py
 def _relpath(path, start=None):
     """Return a relative version of a path"""
 
     if not path:
         raise ValueError("no path specified")
 
     if start is None:
@@ -134,47 +139,44 @@ class Test:
                     else:
                         print('warning: unrecognized |jit-test| attribute %s' % part)
 
         if options.valgrind_all:
             test.valgrind = True
 
         return test
 
-    def command(self, js, lib_dir, shell_args):
-        libdir_var = lib_dir
-        if not libdir_var.endswith('/'):
-            libdir_var += '/'
+    def command(self, js, shell_args):
         scriptdir_var = os.path.dirname(self.path);
         if not scriptdir_var.endswith('/'):
             scriptdir_var += '/'
         expr = ("const platform=%r; const libdir=%r; const scriptdir=%r"
-                % (sys.platform, libdir_var, scriptdir_var))
+                % (sys.platform, LIB_DIR, scriptdir_var))
         # We may have specified '-a' or '-d' twice: once via --jitflags, once
         # via the "|jit-test|" line.  Remove dups because they are toggles.
         cmd = [js] + list(set(self.jitflags)) + shell_args + ['-e', expr]
-        cmd += ['-f', os.path.join(lib_dir, 'prolog.js'), '-f', self.path]
+        cmd += ['-f', os.path.join(LIB_DIR, 'prolog.js'), '-f', self.path]
         if self.valgrind:
             cmd = self.VALGRIND_CMD + cmd
         return cmd
 
-def find_tests(dir, substring = None):
+def find_tests(substring=None):
     ans = []
-    for dirpath, dirnames, filenames in os.walk(dir):
+    for dirpath, dirnames, filenames in os.walk(TEST_DIR):
         dirnames.sort()
         filenames.sort()
         if dirpath == '.':
             continue
         for filename in filenames:
             if not filename.endswith('.js'):
                 continue
             if filename in ('shell.js', 'browser.js', 'jsref.js'):
                 continue
             test = os.path.join(dirpath, filename)
-            if substring is None or substring in os.path.relpath(test, dir):
+            if substring is None or substring in os.path.relpath(test, TEST_DIR):
                 ans.append(test)
     return ans
 
 def tmppath(token):
     fd, path = tempfile.mkstemp(prefix=token)
     os.close(fd)
     return path
 
@@ -253,18 +255,18 @@ def run_cmd(cmdline, env, timeout):
 
 def run_cmd_avoid_stdio(cmdline, env, timeout):
     stdoutPath, stderrPath = tmppath('jsstdout'), tmppath('jsstderr')
     env['JS_STDOUT'] = stdoutPath
     env['JS_STDERR'] = stderrPath
     _, __, code = run_timeout_cmd(cmdline, { 'env': env }, timeout)
     return read_and_unlink(stdoutPath), read_and_unlink(stderrPath), code
 
-def run_test(test, lib_dir, shell_args, options):
-    cmd = test.command(options.js_shell, lib_dir, shell_args)
+def run_test(test, shell_args, options):
+    cmd = test.command(options.js_shell, shell_args)
     if options.show_cmd:
         print(subprocess.list2cmdline(cmd))
 
     if options.avoid_stdio:
         run = run_cmd_avoid_stdio
     else:
         run = run_cmd
 
@@ -308,24 +310,24 @@ def print_tinderbox(label, test, message
         result = "%s | jit_test.py %-15s| %s" % (label, jitflags, test.path)
     else:
         result = "%s | jit_test.py " % label
 
     if message:
         result += ": " + message
     print(result)
 
-def wrap_parallel_run_test(test, lib_dir, shell_args, resultQueue, options):
+def wrap_parallel_run_test(test, shell_args, resultQueue, options):
     # Ignore SIGINT in the child
     signal.signal(signal.SIGINT, signal.SIG_IGN)
-    result = run_test(test, lib_dir, shell_args, options) + (test,)
+    result = run_test(test, shell_args, options) + (test,)
     resultQueue.put(result)
     return result
 
-def run_tests_parallel(tests, test_dir, lib_dir, shell_args, options):
+def run_tests_parallel(tests, shell_args, options):
     # This queue will contain the results of the various tests run.
     # We could make this queue a global variable instead of using
     # a manager to share, but this will not work on Windows.
     queue_manager = Manager()
     async_test_result_queue = queue_manager.Queue()
 
     # This queue will be used by the result process to indicate
     # that it has received a result and we can start a new process
@@ -333,17 +335,17 @@ def run_tests_parallel(tests, test_dir, 
     # check for worker completion ourselves regularly.
     notify_queue = queue_manager.Queue()
 
     # This queue will contain the return value of the function
     # processing the test results.
     result_process_return_queue = queue_manager.Queue()
     result_process = Process(target=process_test_results_parallel,
                              args=(async_test_result_queue, result_process_return_queue,
-                                   notify_queue, len(tests), options, lib_dir, shell_args))
+                                   notify_queue, len(tests), options, shell_args))
     result_process.start()
 
     # Ensure that a SIGTERM is handled the same way as SIGINT
     # to terminate all child processes.
     sigint_handler = signal.getsignal(signal.SIGINT)
     signal.signal(signal.SIGTERM, sigint_handler)
 
     worker_processes = []
@@ -363,17 +365,17 @@ def run_tests_parallel(tests, test_dir, 
         for i in range(min(options.max_jobs,len(tests))):
             notify_queue.put(True)
 
         # For every item in the notify queue, start one new worker.
         # Every completed worker adds a new item to this queue.
         while notify_queue.get():
             if (testcnt < len(tests)):
                 # Start one new worker
-                worker_process = Process(target=wrap_parallel_run_test, args=(tests[testcnt], lib_dir, shell_args, async_test_result_queue, options))
+                worker_process = Process(target=wrap_parallel_run_test, args=(tests[testcnt], shell_args, async_test_result_queue, options))
                 worker_processes.append(worker_process)
                 worker_process.start()
                 testcnt += 1
 
                 # Collect completed workers
                 worker_processes = remove_completed_workers(worker_processes)
             else:
                 break
@@ -412,46 +414,46 @@ def get_parallel_results(async_test_resu
         if (async_test_result == None):
             return
 
         # Notify parent that we got a result
         notify_queue.put(True)
 
         yield async_test_result
 
-def process_test_results_parallel(async_test_result_queue, return_queue, notify_queue, num_tests, options, lib_dir, shell_args):
+def process_test_results_parallel(async_test_result_queue, return_queue, notify_queue, num_tests, options, shell_args):
     gen = get_parallel_results(async_test_result_queue, notify_queue)
-    ok = process_test_results(gen, num_tests, options, lib_dir, shell_args)
+    ok = process_test_results(gen, num_tests, options, shell_args)
     return_queue.put(ok)
 
-def print_test_summary(failures, complete, doing, options, lib_dir, shell_args):
+def print_test_summary(failures, complete, doing, options, shell_args):
     if failures:
         if options.write_failures:
             try:
                 out = open(options.write_failures, 'w')
                 # Don't write duplicate entries when we are doing multiple failures per job.
                 written = set()
                 for test, fout, ferr, fcode, _ in failures:
                     if test.path not in written:
-                        out.write(os.path.relpath(test.path, test_dir) + '\n')
+                        out.write(os.path.relpath(test.path, TEST_DIR) + '\n')
                         if options.write_failure_output:
                             out.write(fout)
                             out.write(ferr)
                             out.write('Exit code: ' + str(fcode) + "\n")
                         written.add(test.path)
                 out.close()
             except IOError:
                 sys.stderr.write("Exception thrown trying to write failure file '%s'\n"%
                                  options.write_failures)
                 traceback.print_exc()
                 sys.stderr.write('---\n')
 
         def show_test(test):
             if options.show_failed:
-                print('    ' + subprocess.list2cmdline(test.command(options.js_shell, lib_dir, shell_args)))
+                print('    ' + subprocess.list2cmdline(test.command(options.js_shell, shell_args)))
             else:
                 print('    ' + ' '.join(test.jitflags + [test.path]))
 
         print('FAILURES:')
         for test, _, __, ___, timed_out in failures:
             if not timed_out:
                 show_test(test)
 
@@ -460,17 +462,17 @@ def print_test_summary(failures, complet
             if timed_out:
                 show_test(test)
 
         return False
     else:
         print('PASSED ALL' + ('' if complete else ' (partial run -- interrupted by user %s)' % doing))
         return True
 
-def process_test_results(results, num_tests, options, lib_dir, shell_args):
+def process_test_results(results, num_tests, options, shell_args):
     pb = NullProgressBar()
     if not options.hide_progress and not options.show_cmd and ProgressBar.conservative_isatty():
         fmt = [
             {'value': 'PASS',    'color': 'green'},
             {'value': 'FAIL',    'color': 'red'},
             {'value': 'TIMEOUT', 'color': 'blue'},
             {'value': 'SKIP',    'color': 'brightgray'},
         ]
@@ -509,27 +511,27 @@ def process_test_results(results, num_te
                 'TIMEOUT': timeouts,
                 'SKIP': 0}
             )
         complete = True
     except KeyboardInterrupt:
         print_tinderbox("TEST-UNEXPECTED-FAIL", None, "Test execution interrupted by user");
 
     pb.finish(True)
-    return print_test_summary(failures, complete, doing, options, lib_dir, shell_args)
+    return print_test_summary(failures, complete, doing, options, shell_args)
 
 
-def get_serial_results(tests, lib_dir, shell_args, options):
+def get_serial_results(tests, shell_args, options):
     for test in tests:
-        result = run_test(test, lib_dir, shell_args, options)
+        result = run_test(test, shell_args, options)
         yield result + (test,)
 
-def run_tests(tests, test_dir, lib_dir, shell_args, options):
-    gen = get_serial_results(tests, lib_dir, shell_args, options)
-    ok = process_test_results(gen, len(tests), options, lib_dir, shell_args)
+def run_tests(tests, shell_args, options):
+    gen = get_serial_results(tests, shell_args, options)
+    ok = process_test_results(gen, len(tests), options, shell_args)
     return ok
 
 def parse_jitflags(options):
     jitflags = [ [ '-' + flag for flag in flags ]
                  for flags in options.jitflags.split(',') ]
     for flags in jitflags:
         for flag in flags:
             if flag not in ('-m', '-a', '-p', '-d', '-n'):