GeezerVison is showing github.com — test: make it easier to run tests for subsystems · sclarson/node@5be4dfa
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: CONTRIBUTING.md +39Lines changed: 39 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -404,6 +404,13 @@ If you are updating tests and just want to run a single test to check it: | 404 | 404 | $ python tools/test.py -J --mode=release parallel/test-stream2-transform | 405 | 405 | ``` | 406 | 406 |
| | 407 | +You can execute the entire suite of tests for a given subsystem | | 408 | +by providing the name of a subsystem: | | 409 | + | | 410 | +```text | | 411 | +$ python tools/test.py -J --mode=release child-process | | 412 | +``` | | 413 | + | 407 | 414 | If you want to check the other options, please refer to the help by using | 408 | 415 | the `--help` option | 409 | 416 |
| @@ -420,6 +427,38 @@ $ ./node ./test/parallel/test-stream2-transform.js | 420 | 427 | Remember to recompile with `make -j4` in between test runs if you change code in | 421 | 428 | the `lib` or `src` directories. | 422 | 429 |
| | 430 | +##### Test Coverage | | 431 | + | | 432 | +It's good practice to ensure any code you add or change is covered by tests. | | 433 | +You can do so by running the test suite with coverage enabled: | | 434 | + | | 435 | +```text | | 436 | +$ ./configure --coverage && make coverage | | 437 | +``` | | 438 | + | | 439 | +A detailed coverage report will be written to `coverage/index.html` for | | 440 | +JavaScript coverage and to `coverage/cxxcoverage.html` for C++ coverage. | | 441 | + | | 442 | +_Note that generating a test coverage report can take several minutes._ | | 443 | + | | 444 | +To collect coverage for a subset of tests you can set the `CI_JS_SUITES` and | | 445 | +`CI_NATIVE_SUITES` variables: | | 446 | + | | 447 | +```text | | 448 | +$ CI_JS_SUITES=child-process CI_NATIVE_SUITES= make coverage | | 449 | +``` | | 450 | + | | 451 | +The above command executes tests for the `child-process` subsystem and | | 452 | +outputs the resulting coverage report. | | 453 | + | | 454 | +Running tests with coverage will create and modify several directories | | 455 | +and files. To clean up afterwards, run: | | 456 | + | | 457 | +```text | | 458 | +make coverage-clean | | 459 | +./configure && make -j4. | | 460 | +``` | | 461 | + | 423 | 462 | #### Step 7: Push | 424 | 463 |
| 425 | 464 | Once you are sure your commits are ready to go, with passing tests and linting, | |
Collapse file Copy file name to clipboardExpand all lines: Makefile +15-5Lines changed: 15 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,7 +10,7 @@ TEST_CI_ARGS ?= | 10 | 10 | STAGINGSERVER ?= node-www | 11 | 11 | LOGLEVEL ?= silent | 12 | 12 | OSTYPE := $(shell uname -s | tr '[A-Z]' '[a-z]') | 13 | | -COVTESTS ?= test | | 13 | +COVTESTS ?= test-cov | 14 | 14 | GTEST_FILTER ?= "*" | 15 | 15 | GNUMAKEFLAGS += --no-print-directory | 16 | 16 |
| @@ -204,10 +204,20 @@ test: all | 204 | 204 | $(PYTHON) tools/test.py --mode=release -J \ | 205 | 205 | $(CI_ASYNC_HOOKS) \ | 206 | 206 | $(CI_JS_SUITES) \ | 207 | | - $(CI_NATIVE_SUITES) | | 207 | + $(CI_NATIVE_SUITES) \ | | 208 | + known_issues | 208 | 209 | $(MAKE) lint | 209 | 210 | endif | 210 | 211 |
| | 212 | +test-cov: all | | 213 | + $(MAKE) build-addons | | 214 | + $(MAKE) build-addons-napi | | 215 | + # $(MAKE) cctest | | 216 | + $(PYTHON) tools/test.py --mode=release -J \ | | 217 | + $(CI_JS_SUITES) \ | | 218 | + $(CI_NATIVE_SUITES) | | 219 | + $(MAKE) lint | | 220 | + | 211 | 221 | test-parallel: all | 212 | 222 | $(PYTHON) tools/test.py --mode=release parallel -J | 213 | 223 |
| @@ -336,7 +346,7 @@ test-all-valgrind: test-build | 336 | 346 |
| 337 | 347 | CI_NATIVE_SUITES := addons addons-napi | 338 | 348 | CI_ASYNC_HOOKS := async-hooks | 339 | | -CI_JS_SUITES := abort doctool es-module inspector known_issues message parallel pseudo-tty sequential | | 349 | +CI_JS_SUITES ?= default | 340 | 350 |
| 341 | 351 | # Build and test addons without building anything else | 342 | 352 | test-ci-native: LOGLEVEL := info | @@ -349,7 +359,7 @@ test-ci-native: | test/addons/.buildstamp test/addons-napi/.buildstamp | 349 | 359 | test-ci-js: | clear-stalled | 350 | 360 | $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ | 351 | 361 | --mode=release --flaky-tests=$(FLAKY_TESTS) \ | 352 | | - $(TEST_CI_ARGS) $(CI_ASYNC_HOOKS) $(CI_JS_SUITES) | | 362 | + $(TEST_CI_ARGS) $(CI_ASYNC_HOOKS) known_issues | 353 | 363 | # Clean up any leftover processes, error if found. | 354 | 364 | ps awwx | grep Release/node | grep -v grep | cat | 355 | 365 | @PS_OUT=`ps awwx | grep Release/node | grep -v grep | awk '{print $$1}'`; \ | @@ -362,7 +372,7 @@ test-ci: | clear-stalled build-addons build-addons-napi | 362 | 372 | out/Release/cctest --gtest_output=tap:cctest.tap | 363 | 373 | $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ | 364 | 374 | --mode=release --flaky-tests=$(FLAKY_TESTS) \ | 365 | | - $(TEST_CI_ARGS) $(CI_ASYNC_HOOKS) $(CI_JS_SUITES) $(CI_NATIVE_SUITES) | | 375 | + $(TEST_CI_ARGS) $(CI_ASYNC_HOOKS) $(CI_JS_SUITES) known_issues | 366 | 376 | # Clean up any leftover processes, error if found. | 367 | 377 | ps awwx | grep Release/node | grep -v grep | cat | 368 | 378 | @PS_OUT=`ps awwx | grep Release/node | grep -v grep | awk '{print $$1}'`; \ | |
Collapse file Copy file name to clipboardExpand all lines: tools/test.py +29-25Lines changed: 29 additions & 25 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1531,23 +1531,6 @@ def ExpandCommand(args): | 1531 | 1531 | return prefix + args + suffix | 1532 | 1532 | return ExpandCommand | 1533 | 1533 |
| 1534 | | - | 1535 | | -BUILT_IN_TESTS = [ | 1536 | | - 'sequential', | 1537 | | - 'parallel', | 1538 | | - 'pummel', | 1539 | | - 'message', | 1540 | | - 'internet', | 1541 | | - 'addons', | 1542 | | - 'addons-napi', | 1543 | | - 'gc', | 1544 | | - 'debugger', | 1545 | | - 'doctool', | 1546 | | - 'inspector', | 1547 | | - 'async-hooks', | 1548 | | -] | 1549 | | - | 1550 | | - | 1551 | 1534 | def GetSuites(test_root): | 1552 | 1535 | def IsSuite(path): | 1553 | 1536 | return isdir(path) and exists(join(path, 'testcfg.py')) | @@ -1566,6 +1549,32 @@ def PrintCrashed(code): | 1566 | 1549 | return "CRASHED (Signal: %d)" % -code | 1567 | 1550 |
| 1568 | 1551 |
| | 1552 | +# these suites represent special cases that should not be run as part of the | | 1553 | +# default JavaScript test-run, e.g., internet/ requires a network connection, | | 1554 | +# addons/ requires compilation. | | 1555 | +IGNORED_SUITES = [ | | 1556 | + 'addons', | | 1557 | + 'addons-napi', | | 1558 | + 'gc', | | 1559 | + 'internet', | | 1560 | + 'pummel', | | 1561 | + 'test-known-issues', | | 1562 | + 'tick-processor', | | 1563 | + 'timers' | | 1564 | +] | | 1565 | + | | 1566 | + | | 1567 | +def ArgsToTestPaths(test_root, args, suites): | | 1568 | + if len(args) == 0 or 'default' in args: | | 1569 | + def_suites = filter(lambda s: s not in IGNORED_SUITES, suites) | | 1570 | + args = filter(lambda a: a != 'default', args) + def_suites | | 1571 | + subsystem_regex = re.compile(r'^[a-zA-Z-]*$') | | 1572 | + check = lambda arg: subsystem_regex.match(arg) and (arg not in suites) | | 1573 | + mapped_args = ["*/test*-%s-*" % arg if check(arg) else arg for arg in args] | | 1574 | + paths = [SplitPath(NormalizePath(a)) for a in mapped_args] | | 1575 | + return paths | | 1576 | + | | 1577 | + | 1569 | 1578 | def Main(): | 1570 | 1579 | parser = BuildOptions() | 1571 | 1580 | (options, args) = parser.parse_args() | @@ -1581,18 +1590,13 @@ def Main(): | 1581 | 1590 | logger.addHandler(fh) | 1582 | 1591 |
| 1583 | 1592 | workspace = abspath(join(dirname(sys.argv[0]), '..')) | 1584 | | - suites = GetSuites(join(workspace, 'test')) | | 1593 | + test_root = join(workspace, 'test') | | 1594 | + suites = GetSuites(test_root) | 1585 | 1595 | repositories = [TestRepository(join(workspace, 'test', name)) for name in suites] | 1586 | 1596 | repositories += [TestRepository(a) for a in options.suite] | 1587 | 1597 |
| 1588 | 1598 | root = LiteralTestSuite(repositories) | 1589 | | - if len(args) == 0: | 1590 | | - paths = [SplitPath(t) for t in BUILT_IN_TESTS] | 1591 | | - else: | 1592 | | - paths = [ ] | 1593 | | - for arg in args: | 1594 | | - path = SplitPath(NormalizePath(arg)) | 1595 | | - paths.append(path) | | 1599 | + paths = ArgsToTestPaths(test_root, args, suites) | 1596 | 1600 |
| 1597 | 1601 | # Check for --valgrind option. If enabled, we overwrite the special | 1598 | 1602 | # command flag with a command that uses the run-valgrind.py script. | |
Collapse file Copy file name to clipboardExpand all lines: vcbuild.bat +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -44,7 +44,7 @@ set enable_static= | 44 | 44 | set build_addons_napi= | 45 | 45 | set test_node_inspect= | 46 | 46 | set test_check_deopts= | 47 | | -set js_test_suites=abort async-hooks es-module inspector known_issues message parallel sequential | | 47 | +set js_test_suites=default async-hooks known_issues | 48 | 48 | set v8_test_options= | 49 | 49 | set v8_build_options= | 50 | 50 | set "common_test_suites=%js_test_suites% doctool addons addons-napi&set build_addons=1&set build_addons_napi=1" | |
|