Skip to content

Commit d646c1f

Browse files
author
434b
committed
chore(merge): main
2 parents b060e54 + bac019a commit d646c1f

File tree

7 files changed

+76
-43
lines changed

7 files changed

+76
-43
lines changed

docs/fuzz-settings.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ directories are executed during startup.
2020
**Example invocation:**
2121

2222
```shell
23-
npx jazzer fuzzTarget corpusDir otherCorupsDir
23+
npx jazzer target corpus_dir other_corpus
2424
```
2525

2626
## Reproducing errors
@@ -32,7 +32,7 @@ This input can then be used to reproduce the issue by specifying it as last
3232
parameter in the CLI call:
3333

3434
```shell
35-
npx jazzer fuzzTarget crash-abcdef0123456789
35+
npx jazzer target crash-abcdef0123456789
3636
```
3737

3838
## Value profile
@@ -49,7 +49,7 @@ An example of using value profiling can be found at
4949
**Example invocation:**
5050

5151
```shell
52-
npx jazzer fuzzTarget -- -use_value_profile=1
52+
npx jazzer target -- -use_value_profile=1
5353
```
5454

5555
## Timeout
@@ -64,7 +64,7 @@ Timeouts work in the sync- and asynchronous fuzzing mode.
6464
**Example invocation:**
6565

6666
```shell
67-
npx jazzer fuzzTarget --timeout=10000
67+
npx jazzer target --timeout=10000
6868
```
6969

7070
**Example output:**
@@ -113,7 +113,7 @@ definitions.
113113
### Defining Custom Hooks
114114

115115
Import the functions `registerBeforeHook`, `registerReplaceHook`,
116-
`registerAfterHook` from jazzer.js:
116+
`registerAfterHook` from Jazzer.js:
117117

118118
```javascript
119119
const {

docs/fuzz-targets.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,19 @@ flag, so that only the most important parameters are discussed here.
176176

177177
## Coverage report generation
178178

179-
To generate a coverage report, add the `--coverage` flag to the Jazzer.js CLI.
180-
In this example, the `--coverage` flag is combined with the dry run flag `-d`
181-
that disables internal instrumentation used by the fuzzer.
179+
To generate a coverage report, add the `--cov`/`--coverage` flag to the
180+
Jazzer.js CLI. In the following example, the `--cov` flag is combined with the
181+
dry run flag `-d` that disables internal instrumentation used by the fuzzer.
182182

183183
```shell
184-
npx jazzer -d <fuzzer parameters> --corpus <corpus directories> --coverage -- <libFuzzer parameters>
184+
npx jazzer -d <fuzzer parameters> --corpus <corpus directories> --cov -- <libFuzzer parameters>
185185
```
186186

187-
Alternatively, you can add a new script to your package.json:
187+
Alternatively, you can add a new script to your `package.json`:
188188

189189
```json
190190
"scripts": {
191-
"coverage": "jazzer -d -i target -i another_target <fuzzer parameters> --corpus <corpus directories> --coverage -- <libFuzzer parameters>"
191+
"coverage": "jazzer -d -i target -i another_target <fuzzer parameters> --corpus <corpus directories> --cov -- <libFuzzer parameters>"
192192
}
193193
```
194194

@@ -201,11 +201,13 @@ fuzzing, because of the substantial overhead that it adds.
201201

202202
By default, the coverage reports can be found in the `./coverage` directory.
203203
This default directory can be changed by setting the flag
204-
`--coverageDirectory=<another coverage directory>`.
204+
`--cov_dir=<another coverage directory>`. A longer flag of the form
205+
`--coverage_directory` also exists.
205206

206207
### Coverage reporters
207208

208-
The desired report format can be set by the flag `--coverageReports`, which by
209-
default is set to `--coverageReports clover json lcov text`. See
209+
The desired report format can be set by the flags
210+
`--cov_reporters`/`--coverage_reporters`, which by default is set to
211+
`--coverage_reporters clover json lcov text`. See
210212
[here](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-reports/lib)
211213
for a list of supported coverage reporters.

docs/jest-integration.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,14 @@ To generate a coverage report, run jest with the `--coverage` flag:
299299
npx jest --coverage
300300
```
301301
302+
Note that unlike for the Jazzer.js CLI Jest only accepts the long flag of
303+
`--coverage`!
304+
302305
Additional options for coverage report generation are described in the
303306
[fuzz targets documentation](./fuzz-targets.md#coverage-report-generation).
304307
305-
The desired report format can be set by the flag `--coverageReports`, which by
306-
default is set to `--coverageReports clover json lcov text`. See
308+
The desired report format can be set by the flag `--coverage_reporters`, which
309+
by default is set to `--coverage_reporters clover json lcov text`. See
307310
[here](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-reports/lib)
308311
for a list of supported coverage reporters.
309312

examples/custom-hooks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"fuzz": "jazzer fuzz -i jpeg-js -h custom-hooks --sync",
1111
"dryRun": "jazzer fuzz -i jpeg-js --sync -h custom-hooks -- -runs=100 -seed=123456789",
12-
"coverage": "jazzer fuzz -i jpeg-js -i fuzz.js -i custom-hooks.js -h custom-hooks --sync --coverage -- -max_total_time=10"
12+
"coverage": "jazzer fuzz -i jpeg-js -i fuzz.js -i custom-hooks.js -h custom-hooks --sync --cov -- -max_total_time=10"
1313
},
1414
"devDependencies": {
1515
"@jazzer.js/core": "file:../../packages/core"

examples/jpeg/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"scripts": {
1212
"fuzz": "jazzer fuzz -i jpeg-js --sync",
1313
"dryRun": "jazzer fuzz -i jpeg-js --sync -- -runs=100 -seed=123456789",
14-
"coverage": "jazzer fuzz -i jpeg-js/lib -i fuzz.js --sync --coverage -- -max_total_time=1 -seed=123456789"
14+
"coverage": "jazzer fuzz -i jpeg-js/lib -i fuzz.js --sync --cov -- -max_total_time=1 -seed=123456789"
1515
},
1616
"devDependencies": {
1717
"@jazzer.js/core": "file:../../packages/core"

packages/core/cli.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ yargs(process.argv.slice(2))
2727
"greedy-arrays": false,
2828
})
2929
.example(
30-
"$0 package/fuzzTarget -i packages/foo -i packages/bar",
31-
'Start a fuzzing run using the "fuzz" function exported by "fuzzTarget" ' +
30+
"$0 package/target -i packages/foo -i packages/bar",
31+
'Start a fuzzing run using the "fuzz" function exported by "target" ' +
3232
'and only instrument code in the "packages/a" and "packages/b" modules.'
3333
)
3434
.example(
35-
"$0 package/fuzzTarget corpus -- -max_total_time=60",
36-
'Start a fuzzing run using the "fuzz" function exported by "fuzzTarget" ' +
35+
"$0 package/target corpus -- -max_total_time=60",
36+
'Start a fuzzing run using the "fuzz" function exported by "target" ' +
3737
'and use the directory "corpus" to store newly generated inputs. ' +
3838
'Also pass the "-max_total_time" flag to the internal fuzzing engine ' +
3939
"(libFuzzer) to stop the fuzzing run after 60 seconds."
4040
)
4141
.command(
42-
"$0 <fuzzTarget> [corpus..]",
42+
"$0 <target> [corpus..]",
4343
"Coverage-guided, in-process fuzzer for the Node.js platform. \n\n" +
44-
'The "fuzzTarget" module has to export a function "fuzz" which accepts ' +
44+
'The "target" module has to export a function "fuzz" which accepts ' +
4545
"a byte array as first parameter and uses that to invoke the actual " +
4646
"function to fuzz.\n\n" +
4747
'The "corpus" directory is optional and can be used to provide initial ' +
@@ -52,11 +52,11 @@ yargs(process.argv.slice(2))
5252
"An example is shown in the examples section of this help message.",
5353
(yargs: Argv) => {
5454
yargs
55-
.positional("fuzzTarget", {
55+
.positional("target", {
5656
describe: "Name of the module that exports the fuzz target function.",
5757
type: "string",
5858
})
59-
.demandOption("fuzzTarget")
59+
.demandOption("target")
6060

6161
.array("corpus")
6262
.positional("corpus", {
@@ -162,22 +162,25 @@ yargs(process.argv.slice(2))
162162
group: "Fuzzer:",
163163
default: false,
164164
})
165-
.boolean("coverage")
166-
.option("coverage", {
165+
.boolean("cov")
166+
.option("cov", {
167167
describe: "Enable code coverage.",
168+
alias: "coverage",
168169
type: "boolean",
169170
group: "Fuzzer:",
170171
default: false,
171172
})
172-
.option("coverageDirectory", {
173+
.option("cov_dir", {
173174
describe: "Directory for storing coverage reports.",
175+
alias: "coverage_directory",
174176
type: "string",
175177
default: "coverage",
176178
group: "Fuzzer:",
177179
})
178-
.array("coverageReporters")
179-
.option("coverageReporters", {
180+
.array("cov_reporters")
181+
.option("cov_reporters", {
180182
describe: "A list of reporter names for writing coverage reports.",
183+
alias: "coverage_reporters",
181184
type: "string",
182185
group: "Fuzzer:",
183186
default: ["json", "text", "lcov", "clover"],
@@ -188,8 +191,8 @@ yargs(process.argv.slice(2))
188191
group: "Fuzzer:",
189192
default: 5000,
190193
})
191-
.array("bugDetectors")
192-
.option("bugDetectors", {
194+
.array("bug_detectors")
195+
.option("bug_detectors", {
193196
describe: "A list of bug detectors to use. By default all are used.",
194197
type: "string",
195198
group: "Fuzzer:",
@@ -203,7 +206,7 @@ yargs(process.argv.slice(2))
203206
}
204207
// noinspection JSIgnoredPromiseFromCall
205208
startFuzzing({
206-
fuzzTarget: ensureFilepath(args.fuzzTarget),
209+
fuzzTarget: ensureFilepath(args.target),
207210
fuzzEntryPoint: args.fuzz_function,
208211
includes: args.instrumentation_includes,
209212
excludes: args.instrumentation_excludes,
@@ -214,10 +217,10 @@ yargs(process.argv.slice(2))
214217
customHooks: args.custom_hooks,
215218
expectedErrors: args.expected_errors,
216219
idSyncFile: args.id_sync_file,
217-
coverage: args.coverage,
218-
coverageDirectory: args.coverageDirectory,
219-
coverageReporters: args.coverageReporters,
220-
bugDetectors: args.bugDetectors,
220+
coverage: args.cov,
221+
coverageDirectory: args.cov_dir,
222+
coverageReporters: args.cov_reporters,
223+
bugDetectors: args.bug_detectors,
221224
});
222225
}
223226
)

tests/code_coverage/coverage.test.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,30 @@ describe("Source code coverage reports for our custom Jest runner", () => {
190190
});
191191
});
192192

193+
/**
194+
* @param {string} coverageDirectory
195+
*/
193196
function readCoverageJson(coverageDirectory) {
194197
return JSON.parse(
195-
fs.readFileSync(path.join(coverageDirectory, "coverage-final.json"))
198+
fs
199+
.readFileSync(path.join(coverageDirectory, "coverage-final.json"))
200+
.toString()
196201
);
197202
}
198203

204+
/**
205+
* @param {string} name
206+
*/
199207
function readExpectedCoverage(name) {
200208
return JSON.parse(
201-
fs.readFileSync(path.join(expectedCoverageDirectory, name))
209+
fs.readFileSync(path.join(expectedCoverageDirectory, name)).toString()
202210
);
203211
}
204212

213+
/**
214+
* @param {{ statementMap: any; s: any; fnMap: any; f: any; branchMap: any; b: any; }} coverage
215+
* @param {{ statementMap: any; s: any; fnMap: any; f: any; branchMap: any; b: any; }} expectedCoverage
216+
*/
205217
function expectEqualCoverage(coverage, expectedCoverage) {
206218
expect(coverage.statementMap).toStrictEqual(expectedCoverage.statementMap);
207219
expect(coverage.s).toStrictEqual(expectedCoverage.s);
@@ -211,11 +223,17 @@ function expectEqualCoverage(coverage, expectedCoverage) {
211223
expect(coverage.b).toStrictEqual(expectedCoverage.b);
212224
}
213225

226+
/**
227+
* @param {boolean} includeLib
228+
* @param {boolean} includeTarget
229+
* @param {boolean} useCustomHooks
230+
* @param {boolean} _coverage
231+
*/
214232
function executeJestRunner(
215233
includeLib,
216234
includeTarget,
217235
useCustomHooks,
218-
coverage,
236+
_coverage,
219237
coverageOutputDir = "coverage",
220238
excludePattern = ["nothing"],
221239
verbose = false
@@ -256,6 +274,13 @@ function executeJestRunner(
256274
if (verbose) console.log(process.output.toString());
257275
}
258276

277+
/**
278+
* @param {boolean} dryRun
279+
* @param {boolean} includeLib
280+
* @param {boolean} includeTarget
281+
* @param {boolean} useCustomHooks
282+
* @param {boolean} coverage
283+
*/
259284
function executeFuzzTest(
260285
dryRun,
261286
includeLib,
@@ -296,10 +321,10 @@ function executeFuzzTest(
296321
options.push("custom-hooks");
297322
}
298323
if (coverage) {
299-
options.push("--coverage");
324+
options.push("--cov");
300325
}
301326
if (coverageOutputDir) {
302-
options.push("--coverageDirectory");
327+
options.push("--cov_dir");
303328
options.push(coverageOutputDir);
304329
}
305330
options.push("--");

0 commit comments

Comments
 (0)