Bug 1221285 - Part 2: Test harness support for --test-reflect-stringify. r=efaust.
authorJason Orendorff <jorendorff@mozilla.com>
Mon, 02 Nov 2015 11:29:31 -0600
changeset 272947 8969b317c0462dddeb5b9557107c4c278bf0187d
parent 272946 b459ff7821b1b30a3cee11747b4bb3cf6fb0886c
child 272948 5580050d54bdb1d447929f27e2c4b817f7b3fe69
push id29688
push userkwierso@gmail.com
push dateTue, 17 Nov 2015 21:10:09 +0000
treeherdermozilla-central@eed903a7e4e7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersefaust
bugs1221285
milestone45.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 1221285 - Part 2: Test harness support for --test-reflect-stringify. r=efaust.
js/src/jit-test/jit_test.py
js/src/tests/jstests.py
js/src/tests/lib/jittests.py
js/src/tests/lib/tests.py
--- a/js/src/jit-test/jit_test.py
+++ b/js/src/jit-test/jit_test.py
@@ -133,16 +133,19 @@ def main(argv):
     op.add_option('--repeat', type=int, default=1,
                   help='Repeat tests the given number of times.')
     op.add_option('--this-chunk', type=int, default=1,
                   help='The test chunk to run.')
     op.add_option('--total-chunks', type=int, default=1,
                   help='The total number of test chunks.')
     op.add_option('--ignore-timeouts', dest='ignore_timeouts', metavar='FILE',
                   help='Ignore timeouts of tests listed in [FILE]')
+    op.add_option('--test-reflect-stringify', dest="test_reflect_stringify",
+                  help="instead of running tests, use them to test the "
+                  "Reflect.stringify code in specified file")
 
     options, args = op.parse_args(argv)
     if len(args) < 1:
         op.error('missing JS_SHELL argument')
     js_shell = which(args[0])
     test_args = args[1:]
     test_environment = get_environment_overlay(js_shell)
 
@@ -203,16 +206,20 @@ def main(argv):
               file=sys.stderr)
         sys.exit(0)
 
     test_list = [jittests.JitTest.from_file(_, options) for _ in test_list]
 
     if not options.run_slow:
         test_list = [_ for _ in test_list if not _.slow]
 
+    if options.test_reflect_stringify is not None:
+        for test in test_list:
+            test.test_reflect_stringify = options.test_reflect_stringify
+
     # If chunking is enabled, determine which tests are part of this chunk.
     # This code was adapted from testing/mochitest/runtestsremote.py.
     if options.total_chunks > 1:
         total_tests = len(test_list)
         tests_per_chunk = math.ceil(total_tests / float(options.total_chunks))
         start = int(round((options.this_chunk - 1) * tests_per_chunk))
         end = int(round(options.this_chunk * tests_per_chunk))
         test_list = test_list[start:end]
--- a/js/src/tests/jstests.py
+++ b/js/src/tests/jstests.py
@@ -78,16 +78,19 @@ def parse_args():
                           help='Run a test in debugger.')
     harness_og.add_option('--debugger', default='gdb -q --args',
                           help='Debugger command.')
     harness_og.add_option('-J', '--jorendb', action='store_true',
                           help='Run under JS debugger.')
     harness_og.add_option('--passthrough', action='store_true',
                           help='Run tests with stdin/stdout attached to'
                           ' caller.')
+    harness_og.add_option('--test-reflect-stringify', dest="test_reflect_stringify",
+                          help="instead of running tests, use them to test the "
+                          "Reflect.stringify code in specified file")
     harness_og.add_option('--valgrind', action='store_true',
                           help='Run tests in valgrind.')
     harness_og.add_option('--valgrind-args', default='',
                           help='Extra args to pass to valgrind.')
     harness_og.add_option('--rr', action='store_true',
                           help='Run tests under RR record-and-replay debugger.')
     op.add_option_group(harness_og)
 
@@ -245,16 +248,28 @@ def load_tests(options, requested_paths,
             xul_info = manifest.XULInfo(xul_abi, xul_os, xul_debug)
         xul_tester = manifest.XULInfoTester(xul_info, options.js_shell)
 
     test_dir = dirname(abspath(__file__))
     test_count = manifest.count_tests(test_dir, requested_paths, excluded_paths)
     test_gen = manifest.load_reftests(test_dir, requested_paths, excluded_paths,
                                       xul_tester)
 
+    if options.test_reflect_stringify is not None:
+        def trs_gen(tests):
+            for test in tests:
+                test.test_reflect_stringify = options.test_reflect_stringify
+                # Even if the test is not normally expected to pass, we still
+                # expect reflect-stringify to be able to handle it.
+                test.expect = True
+                test.random = False
+                test.slow = False
+                yield test
+        test_gen = trs_gen(test_gen)
+
     if options.make_manifests:
         manifest.make_manifests(options.make_manifests, test_gen)
         sys.exit()
 
     # Create a new test list. Apply each TBPL configuration to every test.
     flags_list = None
     if options.tbpl:
         flags_list = get_jitflags('all')
--- a/js/src/tests/lib/jittests.py
+++ b/js/src/tests/lib/jittests.py
@@ -114,16 +114,17 @@ class JitTest:
         self.tz_pacific = False # True means force Pacific time for the test
         self.test_also_noasmjs = False # True means run with and without asm.js
                                        # enabled.
         self.test_also = [] # List of other configurations to test with.
         self.test_join = [] # List of other configurations to test with all existing variants.
         self.expect_error = '' # Errors to expect and consider passing
         self.expect_status = 0 # Exit status to expect from shell
         self.is_module = False
+        self.test_reflect_stringify = None  # Reflect.stringify implementation to test
 
         # Expected by the test runner. Always true for jit-tests.
         self.enable = True
 
     def copy(self):
         t = JitTest(self.path)
         t.jitflags = self.jitflags[:]
         t.slow = self.slow
@@ -132,16 +133,17 @@ class JitTest:
         t.allow_overrecursed = self.allow_overrecursed
         t.valgrind = self.valgrind
         t.tz_pacific = self.tz_pacific
         t.test_also_noasmjs = self.test_also_noasmjs
         t.test_also = self.test_also
         t.test_join = self.test_join
         t.expect_error = self.expect_error
         t.expect_status = self.expect_status
+        t.test_reflect_stringify = self.test_reflect_stringify
         t.enable = True
         t.is_module = self.is_module
         return t
 
     def copy_and_extend_jitflags(self, variant):
         t = self.copy()
         t.jitflags.extend(variant)
         return t
@@ -230,16 +232,20 @@ class JitTest:
                         test.jitflags.append(name)
                     else:
                         print('{}: warning: unrecognized |jit-test| attribute'
                               ' {}'.format(path, part))
 
         if options.valgrind_all:
             test.valgrind = True
 
+        if options.test_reflect_stringify is not None:
+            test.expect_error = ''
+            test.expect_status = 0
+
         return test
 
     def command(self, prefix, libdir, moduledir, remote_prefix=None):
         path = self.path
         if remote_prefix:
             path = self.path.replace(TEST_DIR, remote_prefix)
 
         scriptdir_var = os.path.dirname(path)
@@ -261,18 +267,20 @@ class JitTest:
 
         # We may have specified '-a' or '-d' twice: once via --jitflags, once
         # via the "|jit-test|" line.  Remove dups because they are toggles.
         cmd = prefix + ['--js-cache', JitTest.CacheDir]
         cmd += list(set(self.jitflags)) + ['-e', expr]
         if self.is_module:
             cmd += ['--module-load-path', moduledir]
             cmd += ['--module', path]
+        elif self.test_reflect_stringify is None:
+            cmd += ['-f', path]
         else:
-            cmd += ['-f', path]
+            cmd += ['--', self.test_reflect_stringify, "--check", path]
         if self.valgrind:
             cmd = self.VALGRIND_CMD + cmd
         return cmd
 
     # The test runner expects this to be set to give to get_command.
     js_cmd_prefix = None
     def get_command(self, prefix):
         """Shim for the test runner."""
@@ -293,16 +301,18 @@ def find_tests(substring=None):
                 continue
             test = os.path.join(dirpath, filename)
             if substring is None \
                or substring in os.path.relpath(test, TEST_DIR):
                 ans.append(test)
     return ans
 
 def run_test_remote(test, device, prefix, options):
+    if options.test_reflect_stringify:
+        raise ValueError("can't run Reflect.stringify tests remotely")
     cmd = test.command(prefix,
                        posixpath.join(options.remote_test_root, 'lib/'),
                        posixpath.join(options.remote_test_root, 'modules/'),
                        posixpath.join(options.remote_test_root, 'tests'))
     if options.show_cmd:
         print(subprocess.list2cmdline(cmd))
 
     env = {}
--- a/js/src/tests/lib/tests.py
+++ b/js/src/tests/lib/tests.py
@@ -128,31 +128,38 @@ def get_cpu_count():
 
 
 class RefTest(object):
     """A runnable test."""
     def __init__(self, path):
         self.path = path     # str:  path of JS file relative to tests root dir
         self.options = []    # [str]: Extra options to pass to the shell
         self.jitflags = []   # [str]: JIT flags to pass to the shell
+        self.test_reflect_stringify = None  # str or None: path to
+                                            # reflect-stringify.js file to test
+                                            # instead of actually running tests
 
     @staticmethod
     def prefix_command(path):
         """Return the '-f shell.js' options needed to run a test with the given
         path."""
         if path == '':
             return ['-f', 'shell.js']
         head, base = os.path.split(path)
         return RefTest.prefix_command(head) \
             + ['-f', os.path.join(path, 'shell.js')]
 
     def get_command(self, prefix):
         dirname, filename = os.path.split(self.path)
         cmd = prefix + self.jitflags + self.options \
-              + RefTest.prefix_command(dirname) + ['-f', self.path]
+              + RefTest.prefix_command(dirname)
+        if self.test_reflect_stringify is not None:
+            cmd += [self.test_reflect_stringify, "--check", self.path]
+        else:
+            cmd += ["-f", self.path]
         return cmd
 
 
 class RefTestCase(RefTest):
     """A test case consisting of a test and an expected result."""
     def __init__(self, path):
         RefTest.__init__(self, path)
         self.enable = True   # bool: True => run test, False => don't run