Bug 1215063 - Add jit-tests support for running a test as a module and add some tests r=shu
authorJon Coppeard <jcoppeard@mozilla.com>
Tue, 10 Nov 2015 09:44:53 +0000
changeset 308028 e3d2cb194e984a2cb96486b9db92de60ae697ff1
parent 308027 26f84ff40db55f203fe0e5b322d5819fa1892671
child 308029 8ff488cc4d44be89c932cc9534fd6f7d3705b275
push id7422
push userpehrsons@gmail.com
push dateWed, 11 Nov 2015 04:19:53 +0000
reviewersshu
bugs1215063
milestone45.0a1
Bug 1215063 - Add jit-tests support for running a test as a module and add some tests r=shu
js/src/jit-test/jit_test.py
js/src/jit-test/modules/isEven.js
js/src/jit-test/modules/isOdd.js
js/src/jit-test/modules/module1.js
js/src/jit-test/modules/module2.js
js/src/jit-test/modules/module3.js
js/src/jit-test/modules/module4.js
js/src/jit-test/tests/modules/cyclic-function-import.js
js/src/jit-test/tests/modules/simple-imports.js
js/src/tests/lib/jittests.py
--- a/js/src/jit-test/jit_test.py
+++ b/js/src/jit-test/jit_test.py
@@ -269,17 +269,17 @@ def main(argv):
         elif options.debugger == 'lldb':
             debug_cmd = ['lldb', '--']
         elif options.debugger == 'rr':
             debug_cmd = ['rr', 'record']
         else:
             debug_cmd = options.debugger.split()
 
         with change_env(test_environment):
-            subprocess.call(debug_cmd + tc.command(prefix, jittests.LIB_DIR))
+            subprocess.call(debug_cmd + tc.command(prefix, jittests.LIB_DIR, jittests.MODULE_DIR))
             if options.debugger == 'rr':
                 subprocess.call(['rr', 'replay'])
         sys.exit()
 
     try:
         ok = None
         if options.remote:
             ok = jittests.run_tests_remote(job_list, prefix, options)
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/modules/isEven.js
@@ -0,0 +1,12 @@
+import { isOdd } from "isOdd.js"
+
+export function isEven(x) {
+    if (x < 0)
+        throw "negative";
+    if (x == 0)
+        return true;
+    return isOdd(x - 1);
+}
+
+assertEq(isEven(4), true);
+assertEq(isOdd(5), true);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/modules/isOdd.js
@@ -0,0 +1,12 @@
+import { isEven } from "isEven.js"
+
+export function isOdd(x) {
+    if (x < 0)
+        throw "negative";
+    if (x == 0)
+        return false;
+    return isEven(x - 1);
+}
+
+assertEq(isEven(4), true);
+assertEq(isOdd(5), true);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/modules/module1.js
@@ -0,0 +1,1 @@
+export const a = 1;
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/modules/module2.js
@@ -0,0 +1,1 @@
+export let b = 2;
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/modules/module3.js
@@ -0,0 +1,1 @@
+export var c = 3;
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/modules/module4.js
@@ -0,0 +1,1 @@
+export default 4;
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/modules/cyclic-function-import.js
@@ -0,0 +1,7 @@
+// |jit-test| module
+
+import { isOdd } from "isOdd.js"
+import { isEven } from "isEven.js"
+
+assertEq(isEven(4), true);
+assertEq(isOdd(5), true);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/modules/simple-imports.js
@@ -0,0 +1,11 @@
+// |jit-test| module
+
+import { a } from "module1.js";
+import { b } from "module2.js";
+import { c } from "module3.js";
+import d from "module4.js";
+
+assertEq(a, 1);
+assertEq(b, 2);
+assertEq(c, 3);
+assertEq(d, 4);
--- a/js/src/tests/lib/jittests.py
+++ b/js/src/tests/lib/jittests.py
@@ -20,16 +20,17 @@ else:
 from progressbar import ProgressBar, NullProgressBar
 from results import TestOutput
 
 TESTS_LIB_DIR = os.path.dirname(os.path.abspath(__file__))
 JS_DIR = os.path.dirname(os.path.dirname(TESTS_LIB_DIR))
 TOP_SRC_DIR = os.path.dirname(os.path.dirname(JS_DIR))
 TEST_DIR = os.path.join(JS_DIR, 'jit-test', 'tests')
 LIB_DIR = os.path.join(JS_DIR, 'jit-test', 'lib') + os.path.sep
+MODULE_DIR = os.path.join(JS_DIR, 'jit-test', 'modules') + os.path.sep
 JS_CACHE_DIR = os.path.join(JS_DIR, 'jit-test', '.js-cache')
 JS_TESTS_DIR = posixpath.join(JS_DIR, 'tests')
 
 # Backported from Python 3.1 posixpath.py
 def _relpath(path, start=None):
     """Return a relative version of a path"""
 
     if not path:
@@ -112,16 +113,17 @@ class JitTest:
         self.valgrind = False  # True means run under valgrind
         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
 
         # 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
@@ -131,16 +133,17 @@ class JitTest:
         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.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
 
     def copy_variants(self, variants):
@@ -215,29 +218,31 @@ class JitTest:
                     elif name.startswith('test-join='):
                         test.test_join.append([name[len('test-join='):]])
                     elif name == 'ion-eager':
                         test.jitflags.append('--ion-eager')
                     elif name == 'baseline-eager':
                         test.jitflags.append('--baseline-eager')
                     elif name == 'dump-bytecode':
                         test.jitflags.append('--dump-bytecode')
+                    elif name == 'module':
+                        test.is_module = True
                     elif name.startswith('--'):
                         # // |jit-test| --ion-gvn=off; --no-sse4
                         test.jitflags.append(name)
                     else:
                         print('{}: warning: unrecognized |jit-test| attribute'
                               ' {}'.format(path, part))
 
         if options.valgrind_all:
             test.valgrind = True
 
         return test
 
-    def command(self, prefix, libdir, remote_prefix=None):
+    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)
         if not scriptdir_var.endswith('/'):
             scriptdir_var += '/'
 
@@ -252,26 +257,31 @@ class JitTest:
         expr = "const platform={}; const libdir={}; const scriptdir={}".format(
             js_quote(quotechar, sys.platform),
             js_quote(quotechar, libdir),
             js_quote(quotechar, 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 = prefix + ['--js-cache', JitTest.CacheDir]
-        cmd += list(set(self.jitflags)) + ['-e', expr, '-f', path]
+        cmd += list(set(self.jitflags)) + ['-e', expr]
+        if self.is_module:
+            cmd += ['--module-load-path', moduledir]
+            cmd += ['--module', path]
+        else:
+            cmd += ['-f', 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."""
-        return self.command(prefix, LIB_DIR)
+        return self.command(prefix, LIB_DIR, MODULE_DIR)
 
 
 def find_tests(substring=None):
     ans = []
     for dirpath, dirnames, filenames in os.walk(TEST_DIR):
         dirnames.sort()
         filenames.sort()
         if dirpath == '.':
@@ -285,16 +295,17 @@ def find_tests(substring=None):
             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):
     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 = {}
     if test.tz_pacific:
         env['TZ'] = 'PST8PDT'