|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -const { spawnSync } = require("child_process"); |
18 | 17 | const path = require("path");
|
19 |
| -const SyncInfo = |
20 |
| - "Exclusively observed synchronous return values from fuzzed function. Fuzzing in synchronous mode seems beneficial!"; |
21 |
| -const AsyncInfo = |
22 |
| - "Observed asynchronous return values from fuzzed function. Fuzzing in asynchronous mode seems beneficial!"; |
| 18 | +const { FuzzTestBuilder } = require("../helpers.js"); |
23 | 19 |
|
24 |
| -// current working directory |
25 | 20 | const testDirectory = __dirname;
|
| 21 | +const syncInfo = |
| 22 | + "Exclusively observed synchronous return values from fuzzed function. Fuzzing in synchronous mode seems beneficial!"; |
| 23 | +const asyncInfo = |
| 24 | + "Observed asynchronous return values from fuzzed function. Fuzzing in asynchronous mode seems beneficial!"; |
26 | 25 |
|
27 | 26 | describe("Execute a sync runner", () => {
|
28 | 27 | it("Expect a hint due to async and sync return values", () => {
|
29 | 28 | const testCaseDir = path.join(testDirectory, "syncRunnerMixedReturns");
|
30 |
| - const log = executeFuzzTest(true, false, testCaseDir); |
31 |
| - expect(log).toContain(AsyncInfo.trim()); |
| 29 | + const log = executeFuzzTest(true, true, testCaseDir); |
| 30 | + expect(log).toContain(asyncInfo.trim()); |
32 | 31 | });
|
33 | 32 | it("Expect a hint due to exclusively async return values", () => {
|
34 | 33 | const testCaseDir = path.join(testDirectory, "syncRunnerAsyncReturns");
|
35 | 34 | const log = executeFuzzTest(true, false, testCaseDir);
|
36 |
| - expect(log.trim()).toContain(AsyncInfo.trim()); |
| 35 | + expect(log.trim()).toContain(asyncInfo.trim()); |
37 | 36 | });
|
38 | 37 | it("Expect no hint due to strict synchronous return values", () => {
|
39 | 38 | const testCaseDir = path.join(testDirectory, "syncRunnerSyncReturns");
|
40 | 39 | const log = executeFuzzTest(true, false, testCaseDir);
|
41 |
| - expect(log.includes(SyncInfo)).toBeFalsy(); |
42 |
| - expect(log.includes(AsyncInfo)).toBeFalsy(); |
| 40 | + expect(log.includes(syncInfo)).toBeFalsy(); |
| 41 | + expect(log.includes(asyncInfo)).toBeFalsy(); |
43 | 42 | });
|
44 | 43 | });
|
45 | 44 |
|
46 | 45 | describe("Execute a async runner", () => {
|
47 | 46 | it("Expect no hint due to async and sync return values", () => {
|
48 | 47 | const testCaseDir = path.join(testDirectory, "asyncRunnerMixedReturns");
|
49 | 48 | const log = executeFuzzTest(false, false, testCaseDir);
|
50 |
| - expect(log.includes(SyncInfo)).toBeFalsy(); |
51 |
| - expect(log.includes(AsyncInfo)).toBeFalsy(); |
| 49 | + expect(log.includes(syncInfo)).toBeFalsy(); |
| 50 | + expect(log.includes(asyncInfo)).toBeFalsy(); |
52 | 51 | });
|
53 | 52 | it("Expect a hint due to exclusively sync return values", () => {
|
54 | 53 | const testCaseDir = path.join(testDirectory, "asyncRunnerSyncReturns");
|
55 | 54 | const log = executeFuzzTest(false, false, testCaseDir);
|
56 |
| - expect(log.trim()).toContain(SyncInfo.trim()); |
| 55 | + expect(log.trim()).toContain(syncInfo.trim()); |
57 | 56 | });
|
58 | 57 | it("Expect no hint due to strict asynchronous return values", () => {
|
59 | 58 | const testCaseDir = path.join(testDirectory, "asyncRunnerAsyncReturns");
|
60 | 59 | const log = executeFuzzTest(false, false, testCaseDir);
|
61 |
| - expect(log.includes(SyncInfo)).toBeFalsy(); |
62 |
| - expect(log.includes(AsyncInfo)).toBeFalsy(); |
| 60 | + expect(log.includes(syncInfo)).toBeFalsy(); |
| 61 | + expect(log.includes(asyncInfo)).toBeFalsy(); |
63 | 62 | });
|
64 | 63 | });
|
65 | 64 |
|
66 | 65 | function executeFuzzTest(sync, verbose, dir) {
|
67 |
| - let options = ["jazzer", "fuzz"]; |
68 |
| - // Specify mode |
69 |
| - if (sync) options.push("--sync"); |
70 |
| - options.push("--"); |
71 |
| - const process = spawnSync("npx", options, { |
72 |
| - stdio: "pipe", |
73 |
| - cwd: dir, |
74 |
| - shell: true, |
75 |
| - windowsHide: true, |
76 |
| - }); |
77 |
| - let stdout = process.output.toString(); |
78 |
| - if (verbose) console.log(stdout); |
79 |
| - return stdout; |
| 66 | + const fuzzTest = new FuzzTestBuilder() |
| 67 | + .fuzzEntryPoint("fuzz") |
| 68 | + .runs(5000) |
| 69 | + .dir(dir) |
| 70 | + .sync(sync) |
| 71 | + .verbose(verbose) |
| 72 | + .expectedErrors("Error") |
| 73 | + .build(); |
| 74 | + fuzzTest.execute(); |
| 75 | + return fuzzTest.stderr; |
80 | 76 | }
|
0 commit comments