Skip to content

Commit 666f20e

Browse files
author
Benjamin Coe
committed
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.
1 parent 2f2f1cf commit 666f20e

File tree

4 files changed

+83
-31
lines changed

4 files changed

+83
-31
lines changed

CONTRIBUTING.md

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

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+
407414
If you want to check the other options, please refer to the help by using
408415
the `--help` option
409416

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

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+
423462
#### Step 7: Push
424463

425464
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: 28 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,31 @@ 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+
'timers'
1563+
]
1564+
1565+
1566+
def ArgsToTestPaths(test_root, args, suites):
1567+
if len(args) == 0 or 'default' in args:
1568+
def_suites = filter(lambda s: s not in IGNORED_SUITES, suites)
1569+
args = filter(lambda a: a != 'default', args) + def_suites
1570+
subsystem_regex = re.compile(r'^[a-zA-Z-]*$')
1571+
check = lambda arg: subsystem_regex.match(arg) and (arg not in suites)
1572+
mapped_args = ["*/test*-%s-*" % arg if check(arg) else arg for arg in args]
1573+
paths = [SplitPath(NormalizePath(a)) for a in mapped_args]
1574+
return paths
1575+
1576+
15691577
def Main():
15701578
parser = BuildOptions()
15711579
(options, args) = parser.parse_args()
@@ -1581,18 +1589,13 @@ def Main():
15811589
logger.addHandler(fh)
15821590

15831591
workspace = abspath(join(dirname(sys.argv[0]), '..'))
1584-
suites = GetSuites(join(workspace, 'test'))
1592+
test_root = join(workspace, 'test')
1593+
suites = GetSuites(test_root)
15851594
repositories = [TestRepository(join(workspace, 'test', name)) for name in suites]
15861595
repositories += [TestRepository(a) for a in options.suite]
15871596

15881597
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)
1598+
paths = ArgsToTestPaths(test_root, args, suites)
15961599

15971600
# Check for --valgrind option. If enabled, we overwrite the special
15981601
# 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
@@ -44,7 +44,7 @@ set enable_static=
4444
set build_addons_napi=
4545
set test_node_inspect=
4646
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
4848
set v8_test_options=
4949
set v8_build_options=
5050
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)