Skip to content

Commit a8d1a56

Browse files
Benjamin Coetargos
authored andcommitted
test: make it easier to run tests for subsystems
You can now run suites for subsystem using shorthand, e.g., http. Switch to black-list of default test folders from white-list. Tests run by 'make test', 'make coverage', etc., now configurable. Stop running known_issues suite when collecting test coverage. PR-URL: #15450 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 415821c commit a8d1a56

File tree

4 files changed

+84
-31
lines changed

4 files changed

+84
-31
lines changed

CONTRIBUTING.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,13 @@ If you are updating tests and just want to run a single test to check it:
405405
$ python tools/test.py -J --mode=release parallel/test-stream2-transform
406406
```
407407

408+
You can execute the entire suite of tests for a given subsystem
409+
by providing the name of a subsystem:
410+
411+
```text
412+
$ python tools/test.py -J --mode=release child-process
413+
```
414+
408415
If you want to check the other options, please refer to the help by using
409416
the `--help` option
410417

@@ -421,6 +428,38 @@ $ ./node ./test/parallel/test-stream2-transform.js
421428
Remember to recompile with `make -j4` in between test runs if you change code in
422429
the `lib` or `src` directories.
423430

431+
##### Test Coverage
432+
433+
It's good practice to ensure any code you add or change is covered by tests.
434+
You can do so by running the test suite with coverage enabled:
435+
436+
```text
437+
$ ./configure --coverage && make coverage
438+
```
439+
440+
A detailed coverage report will be written to `coverage/index.html` for
441+
JavaScript coverage and to `coverage/cxxcoverage.html` for C++ coverage.
442+
443+
_Note that generating a test coverage report can take several minutes._
444+
445+
To collect coverage for a subset of tests you can set the `CI_JS_SUITES` and
446+
`CI_NATIVE_SUITES` variables:
447+
448+
```text
449+
$ CI_JS_SUITES=child-process CI_NATIVE_SUITES= make coverage
450+
```
451+
452+
The above command executes tests for the `child-process` subsystem and
453+
outputs the resulting coverage report.
454+
455+
Running tests with coverage will create and modify several directories
456+
and files. To clean up afterwards, run:
457+
458+
```text
459+
make coverage-clean
460+
./configure && make -j4.
461+
```
462+
424463
#### Step 7: Push
425464

426465
Once you are sure your commits are ready to go, with passing tests and linting,

Makefile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TEST_CI_ARGS ?=
1010
STAGINGSERVER ?= node-www
1111
LOGLEVEL ?= silent
1212
OSTYPE := $(shell uname -s | tr '[A-Z]' '[a-z]')
13-
COVTESTS ?= test
13+
COVTESTS ?= test-cov
1414
GTEST_FILTER ?= "*"
1515
GNUMAKEFLAGS += --no-print-directory
1616

@@ -204,10 +204,20 @@ test: all
204204
$(PYTHON) tools/test.py --mode=release -J \
205205
$(CI_ASYNC_HOOKS) \
206206
$(CI_JS_SUITES) \
207-
$(CI_NATIVE_SUITES)
207+
$(CI_NATIVE_SUITES) \
208+
known_issues
208209
$(MAKE) lint
209210
endif
210211

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+
211221
test-parallel: all
212222
$(PYTHON) tools/test.py --mode=release parallel -J
213223

@@ -336,7 +346,7 @@ test-all-valgrind: test-build
336346

337347
CI_NATIVE_SUITES := addons addons-napi
338348
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
340350

341351
# Build and test addons without building anything else
342352
test-ci-native: LOGLEVEL := info
@@ -349,7 +359,7 @@ test-ci-native: | test/addons/.buildstamp test/addons-napi/.buildstamp
349359
test-ci-js: | clear-stalled
350360
$(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \
351361
--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
353363
# Clean up any leftover processes, error if found.
354364
ps awwx | grep Release/node | grep -v grep | cat
355365
@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
362372
out/Release/cctest --gtest_output=tap:cctest.tap
363373
$(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \
364374
--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
366376
# Clean up any leftover processes, error if found.
367377
ps awwx | grep Release/node | grep -v grep | cat
368378
@PS_OUT=`ps awwx | grep Release/node | grep -v grep | awk '{print $$1}'`; \

tools/test.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,23 +1531,6 @@ def ExpandCommand(args):
15311531
return prefix + args + suffix
15321532
return ExpandCommand
15331533

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-
15511534
def GetSuites(test_root):
15521535
def IsSuite(path):
15531536
return isdir(path) and exists(join(path, 'testcfg.py'))
@@ -1566,6 +1549,32 @@ def PrintCrashed(code):
15661549
return "CRASHED (Signal: %d)" % -code
15671550

15681551

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+
15691578
def Main():
15701579
parser = BuildOptions()
15711580
(options, args) = parser.parse_args()
@@ -1581,18 +1590,13 @@ def Main():
15811590
logger.addHandler(fh)
15821591

15831592
workspace = abspath(join(dirname(sys.argv[0]), '..'))
1584-
suites = GetSuites(join(workspace, 'test'))
1593+
test_root = join(workspace, 'test')
1594+
suites = GetSuites(test_root)
15851595
repositories = [TestRepository(join(workspace, 'test', name)) for name in suites]
15861596
repositories += [TestRepository(a) for a in options.suite]
15871597

15881598
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)
15961600

15971601
# Check for --valgrind option. If enabled, we overwrite the special
15981602
# command flag with a command that uses the run-valgrind.py script.

vcbuild.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ set enable_static=
4646
set build_addons_napi=
4747
set test_node_inspect=
4848
set test_check_deopts=
49-
set js_test_suites=abort async-hooks es-module inspector known_issues message parallel sequential
49+
set js_test_suites=default async-hooks known_issues
5050
set v8_test_options=
5151
set v8_build_options=
5252
set "common_test_suites=%js_test_suites% doctool addons addons-napi&set build_addons=1&set build_addons_napi=1"

0 commit comments

Comments
 (0)