Running Automated JavaScript Tests

  • Revision slug: SpiderMonkey/Running_Automated_JavaScript_Tests
  • Revision title: Running Automated JavaScript Tests
  • Revision id: 75970
  • Created:
  • Creator: syssgx
  • Is current revision? No
  • Comment one or more formatting changes

Revision Content

There are two test suites, affectionately called "jstests" and "jit-tests".
Sometimes jstests are called JS reftests because of how they are run in the browser. Both sets of tests can be used from a normal build of the JS shell.

Running jstests

Running jstests on a JS shell

The jstests shell harness is js/src/tests/jstests.py. Basic usage is:

jstests.py PATH_TO_JS_SHELL

Developers will usually want to run something like this, where NPROC is the number of processors on your system:

jstests.py -d -j NPROC PATH_TO_JS_SHELL

The -d option skips tests that are marked as randomly failing; random failures are usually just noise when being run for day-to-day developer testing. The -j option runs the suite in parallel (the default is 2, so if you have a 2-core machine you don't need that option); on a fast 8-core machine, the entire suite runs in under a minute.

Another common use case is to run just one test, or all the tests in just one directory:

jstests.py PATH_TO_JS_SHELL TEST_PATH_SUBSTRING [ TEST_PATH_SUBSTRING_2 ... ]

This runs all the tests whose paths contain TEST_PATH_SUBSTRING. Thus, you can run one test by giving its filename, or any substring that is a substring of that test filename only. You can run all tests in a directory by giving the directory path. You can run 3 specific tests by giving the 3 names.

Other options allow you to show the test command lines being run, command output and return codes, run tests named in a given file, exclude tests named in a given file, hide the progress bar, change the timeout, run skipped tests, print output in Tinderbox format, run a test in the debugger, or run tests in valgrind. Run with the -h option to see all the options.

Running JSTest in a browser

[TBA]

Running jstests on TinderBox

When viewing the TinderboxPushLog after a push to the mozilla repositories, jstests are shown as R(J) meaning "Javascript Reftests".

 

Running jit-tests

The jit-test suite uses a Python harness that is similar to the jstests shell harness, but with some minor differences. Basic usage is the same:

jit_test.py PATH_TO_JS_SHELL

Developers will usually want to run like this to skip the slow tests and cover the most important options:

jit_test.py --no-slow PATH_TO_JS_SHELL --jitflags=mjp,m,mj,mja 

You can select specific tests to run in the same way as the jstests shell harness. Most of the options in the jstests harness are also available for this one, but a few have different names, and -j is omitted. Use -h to see all the options.

The --jitflags option allows you test the JS executable with different flags. The flags are used to control which features are run: mjp represents the same flags the browser uses when it's run. You can combine different sets of options with a comma, for example mjp,m,j,mj runs each test 4 times, once with each set of options.

One helpful option specific to jit-tests is -R filename (or --retest filename). The first time this is run, it runs the suite and writes a list of tests that failed to the given filename. The next time it is run, it will run only the tests in the given filename, and then will write the list of tests that failed when it is done. Thus, you can keep retesting as you fix bugs and only the tests that failed the last time will run, speeding things up a bit.

Running jit-tests on TinderBox

When viewing the TinderboxPushLog after a push to the mozilla repositories, jit-tests are run by calling make check, and appear under B.

Creating new tests for jit-tests

Creating new tests for jit-tests is easy. Just add a new JS file to the tests/basic directory (or any appropriate directory under 'tests'). The test harness will automatically find the test and run it. The test is considered to pass if the exit code of the JS shell is zero (i.e., JS didn't crash and there were no JS errors). Use the assertEq function to verify values in your test.

There are some advanced options for tests. See the README (in js/src/jit-tests) for details.

Revision Source

<p>There are two test suites, affectionately called "<strong>jstests</strong>" and "<strong>jit-tests</strong>". <br>
Sometimes jstests are called JS reftests because of how they are run in the browser. Both sets of tests can be used from a normal build of the JS shell.</p>
<h2 id="Running_jstests">Running jstests</h2>
<h4 id="Running_jstests_on_a_JS_shell">Running jstests on a JS shell</h4>
<p>The jstests shell harness is <em>js/src/tests/jstests.py</em>. Basic usage is:</p>
<pre class="brush: shell"><code>jstests.py PATH_TO_JS_SHELL</code></pre>
<p>Developers will usually want to run something like this, where NPROC is the number of processors on your system:</p>
<pre class="brush: shell"><code>jstests.py -d -j NPROC PATH_TO_JS_SHELL</code></pre>
<p>The -d option skips tests that are marked as randomly failing; random failures are usually just noise when being run for day-to-day developer testing. The -j option runs the suite in parallel (the default is 2, so if you have a 2-core machine you don't need that option); on a fast 8-core machine, the entire suite runs in under a minute.</p>
<p>Another common use case is to run just one test, or all the tests in just one directory:</p>
<pre class="brush: shell"><code>jstests.py PATH_TO_JS_SHELL TEST_PATH_SUBSTRING [ TEST_PATH_SUBSTRING_2 ... ]</code></pre>
<p>This runs all the tests whose paths contain TEST_PATH_SUBSTRING. Thus, you can run one test by giving its filename, or any substring that is a substring of that test filename only. You can run all tests in a directory by giving the directory path. You can run 3 specific tests by giving the 3 names.</p>
<p>Other options allow you to show the test command lines being run, command output and return codes, run tests named in a given file, exclude tests named in a given file, hide the progress bar, change the timeout, run skipped tests, print output in Tinderbox format, run a test in the debugger, or run tests in valgrind. Run with the -h option to see all the options.</p>
<h4 id="Running_JSTest_in_a_browser">Running JSTest in a browser</h4>
<p>[TBA]</p>
<h4 id="Running_jstests_on_TinderBox">Running jstests on TinderBox</h4>
<p>When viewing the <a class=" external" href="http://tree.mozilla.org/?tree=TraceMonkey" title="http://tree.mozilla.org/?tree=TraceMonkey">TinderboxPushLog</a> after a push to the mozilla repositories, jstests are shown as R(J) meaning "Javascript Reftests".</p>
<p> </p>
<h2 id="Running_jit-tests">Running jit-tests</h2>
<p>The jit-test suite uses a Python harness that is similar to the jstests shell harness, but with some minor differences. Basic usage is the same:</p>
<pre class="brush: shell"><code>jit_test.py PATH_TO_JS_SHELL</code></pre>
<p>Developers will usually want to run like this to skip the slow tests and cover the most important options:</p>
<pre class="brush: shell"><code>jit_test.py --no-slow PATH_TO_JS_SHELL --jitflags=mjp,m,mj,mja </code></pre>
<p>You can select specific tests to run in the same way as the jstests shell harness. Most of the options in the jstests harness are also available for this one, but a few have different names, and -j is omitted. Use -h to see all the options.</p>
<p>The <code>--jitflags option </code>allows you test the JS executable with different flags. The flags are used to control which features are run: <code>mjp </code>represents the same flags the browser uses when it's run. You can combine different sets of options with a comma, for example <code>mjp,m,j,mj</code> runs each test 4 times, once with each set of options.</p>
<p>One helpful option specific to jit-tests is -R filename (or --retest filename). The first time this is run, it runs the suite and writes a list of tests that failed to the given filename. The next time it is run, it will run only the tests in the given filename, and then will write the list of tests that failed when it is done. Thus, you can keep retesting as you fix bugs and only the tests that failed the last time will run, speeding things up a bit.</p>
<h4 id="Running_jit-tests_on_TinderBox">Running jit-tests on TinderBox</h4>
<p>When viewing the <a class=" external" href="http://tree.mozilla.org/?tree=TraceMonkey" title="http://tree.mozilla.org/?tree=TraceMonkey">TinderboxPushLog</a> after a push to the mozilla repositories, jit-tests are run by calling <code>make check</code>, and appear under B.<br>
</p>
<h3 id="Creating_new_tests_for_jit-tests">Creating new tests for jit-tests</h3>
<p>Creating new tests for jit-tests is easy. Just add a new JS file to the tests/basic directory (or any appropriate directory under 'tests'). The test harness will automatically find the test and run it. The test is considered to pass if the exit code of the JS shell is zero (i.e., JS didn't crash and there were no JS errors). Use the assertEq function to verify values in your test.</p>
<p>There are some advanced options for tests. See the README (in js/src/jit-tests) for details.</p>
Revert to this revision