Skip to content

Commit f73164a

Browse files
committed
Handle SIGINT on Windows
Signal handling in Node.js on Windows is only rudimentary supported. Specifically using `process.kill`, like the test does to interrupt itself, will unconditionally terminate the process. The signal processing works in manual tests, though.
1 parent f3f5bca commit f73164a

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

packages/core/core.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ function buildFuzzerOptions(options: Options): string[] {
405405
}
406406
const inSeconds = Math.ceil(options.timeout / 1000);
407407
opts = opts.concat(`-timeout=${inSeconds}`);
408+
409+
// libFuzzer has to ignore SIGINT and SIGTERM, as it interferes
410+
// with the Node.js signal handling.
411+
opts = opts.concat("-handle_int=0", "-handle_term=0");
412+
408413
return [prepareLibFuzzerArg0(opts), ...opts];
409414
}
410415

tests/helpers.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const path = require("path");
2323
// eslint-disable-next-line @typescript-eslint/no-var-requires
2424
const assert = require("assert");
2525

26-
// This is used to distinguish an error thrown during fuzzing from other errors, such as wrong
27-
// `fuzzEntryPoint` (which would return a "1")
26+
// This is used to distinguish an error thrown during fuzzing from other errors,
27+
// such as wrong `fuzzEntryPoint`, which would return a "1".
2828
const FuzzingExitCode = "77";
2929
const JestRegressionExitCode = "1";
3030
const WindowsExitCode = "1";
@@ -321,9 +321,19 @@ function callWithTimeout(fn, timeout) {
321321
});
322322
}
323323

324+
/**
325+
* Returns a Jest describe function that is skipped if the current platform is not the given one.
326+
* @param platform
327+
* @returns describe(.skip) function
328+
*/
329+
function describeSkipOnPlatform(platform) {
330+
return process.platform === platform ? global.describe.skip : global.describe;
331+
}
332+
324333
module.exports.FuzzTestBuilder = FuzzTestBuilder;
325334
module.exports.FuzzingExitCode = FuzzingExitCode;
326335
module.exports.JestRegressionExitCode = JestRegressionExitCode;
327336
module.exports.WindowsExitCode = WindowsExitCode;
328337
module.exports.makeFnCalledOnce = makeFnCalledOnce;
329338
module.exports.callWithTimeout = callWithTimeout;
339+
module.exports.describeSkipOnPlatform = describeSkipOnPlatform;

tests/signal_handlers/signal_handlers.test.js

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@
1717
/* eslint no-undef: 0 */
1818
const {
1919
FuzzTestBuilder,
20+
describeSkipOnPlatform,
2021
// eslint-disable-next-line @typescript-eslint/no-var-requires
2122
} = require("../helpers.js");
2223
// eslint-disable-next-line @typescript-eslint/no-var-requires
2324
const path = require("path");
2425

26+
// Signal handling in Node.js on Windows is only rudimentary supported.
27+
// Specifically using `process.kill`, like the test does to interrupt itself,
28+
// will unconditionally terminate the process. The signal processing works in
29+
// manual tests, though.
30+
const describe = describeSkipOnPlatform("win32");
31+
2532
describe("SIGINT handlers", () => {
2633
let fuzzTestBuilder;
2734

@@ -35,13 +42,6 @@ describe("SIGINT handlers", () => {
3542

3643
describe("in standalone fuzzing mode", () => {
3744
it("stop sync fuzzing on SIGINT", () => {
38-
// TODO: make the SIGINT handling produce coverage reports on Windows on exit too.
39-
if (process.platform === "win32") {
40-
console.log(
41-
"// TODO: make the SIGINT handling produce coverage reports on Windows on exit too.",
42-
);
43-
return;
44-
}
4545
const fuzzTest = fuzzTestBuilder
4646
.sync(true)
4747
.fuzzEntryPoint("SIGINT_SYNC")
@@ -50,13 +50,6 @@ describe("SIGINT handlers", () => {
5050
assertSigintMessagesLogged(fuzzTest);
5151
});
5252
it("stop async fuzzing on SIGINT", () => {
53-
// TODO: make the SIGINT handling produce coverage reports on Windows on exit too.
54-
if (process.platform === "win32") {
55-
console.log(
56-
"// TODO: make the SIGINT handling produce coverage reports on Windows on exit too.",
57-
);
58-
return;
59-
}
6053
const fuzzTest = fuzzTestBuilder
6154
.sync(false)
6255
.fuzzEntryPoint("SIGINT_ASYNC")
@@ -68,13 +61,6 @@ describe("SIGINT handlers", () => {
6861

6962
describe("in Jest fuzzing mode", () => {
7063
it("stop sync fuzzing on SIGINT", () => {
71-
// TODO: make the SIGINT handling produce coverage reports on Windows on exit too.
72-
if (process.platform === "win32") {
73-
console.log(
74-
"// TODO: make the SIGINT handling produce coverage reports on Windows on exit too.",
75-
);
76-
return;
77-
}
7864
const fuzzTest = fuzzTestBuilder
7965
.jestTestFile("tests.fuzz.js")
8066
.jestTestName("^Jest Sync$")
@@ -84,13 +70,6 @@ describe("SIGINT handlers", () => {
8470
assertSigintMessagesLogged(fuzzTest);
8571
});
8672
it("stop async fuzzing on SIGINT", () => {
87-
// TODO: make the SIGINT handling produce coverage reports on Windows on exit too.
88-
if (process.platform === "win32") {
89-
console.log(
90-
"// TODO: make the SIGINT handling produce coverage reports on Windows on exit too.",
91-
);
92-
return;
93-
}
9473
const fuzzTest = fuzzTestBuilder
9574
.jestTestFile("tests.fuzz.js")
9675
.jestTestName("^Jest Async$")

0 commit comments

Comments
 (0)