MCPcopy Create free account
hub / github.com/nodejs/node / main

Function main

deps/v8/tools/clusterfuzz/js_fuzzer/test_db.js:21–64  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19const sandbox = sinon.createSandbox();
20
21function main() {
22 program
23 .version('0.0.1')
24 .option('-i, --input_dir <path>', 'DB directory.')
25 .parse(process.argv);
26
27 if (!program.input_dir) {
28 console.log('Need to specify DB dir.');
29 return;
30 }
31
32 const mutateDb = new db.MutateDb(program.input_dir);
33 const mutator = new crossOverMutator.CrossOverMutator(
34 { MUTATE_CROSSOVER_INSERT: 1.0, testing: true }, mutateDb);
35
36 let nPass = 0;
37 let nFail = 0;
38 // Iterate over all statements saved in the DB.
39 for (const statementPath of mutateDb.index.all) {
40 const expression = JSON.parse(fs.readFileSync(
41 fsPath.join(program.input_dir, statementPath)), 'utf-8');
42 // Stub out choosing random variables in cross-over mutator.
43 sandbox.stub(random, 'single').callsFake((a) => { return a[0]; });
44 // Ensure we are selecting the statement of the current iteration.
45 sandbox.stub(mutateDb, 'getRandomStatement').callsFake(
46 () => { return expression; });
47 // Use a source that will try to insert one statement, allowing
48 // super.
49 const source = sourceHelpers.loadSource(
50 sourceHelpers.BASE_CORPUS,
51 'test_data/cross_over_mutator_class_input.js');
52 try {
53 mutator.mutate(source);
54 nPass++;
55 } catch (e) {
56 console.log('******************************************************')
57 console.log(expression);
58 console.log(e.message);
59 nFail++;
60 }
61 sandbox.restore();
62 }
63 console.log(`Result: ${nPass} passed, ${nFail} failed.`)
64}
65
66main();

Callers 1

test_db.jsFile · 0.70

Calls 7

parseMethod · 0.65
versionMethod · 0.45
logMethod · 0.45
readFileSyncMethod · 0.45
joinMethod · 0.45
mutateMethod · 0.45
restoreMethod · 0.45

Tested by

no test coverage detected