Skip to content

Commit

Permalink
suppress false positives from fuzzer (#3638)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Dec 16, 2019
1 parent 74396ac commit 3ff0fed
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
21 changes: 19 additions & 2 deletions test/ufuzz/index.js
Expand Up @@ -1089,6 +1089,19 @@ function log(options) {
}
}

function fuzzy_match(original, uglified) {
original = original.split(" ", 5);
uglified = uglified.split(" ", 5);
for (var i = 0; i < 5; i++) {
if (original[i] === uglified[i]) continue;
var a = +original[i];
var b = +uglified[i];
if (Math.abs((b - a) / a) < 1e-10) continue;
return false;
}
return true;
}

var fallback_options = [ JSON.stringify({
compress: false,
mangle: false
Expand All @@ -1111,8 +1124,12 @@ for (var round = 1; round <= num_iterations; round++) {
uglify_code = uglify_code.code;
uglify_result = sandbox.run_code(uglify_code, o.toplevel);
ok = sandbox.same_stdout(original_result, uglify_result);
if (!ok && o.compress.unsafe_math) {
ok = sandbox.same_stdout(sandbox.run_code(original_code.replace(/( - 0\.1){3}/g, " - 0.3")), uglify_result, o.toplevel);
if (!ok && typeof uglify_result == "string" && o.compress.unsafe_math) {
ok = fuzzy_match(original_result, uglify_result);
if (!ok) {
var fuzzy_result = sandbox.run_code(original_code.replace(/( - 0\.1){3}/g, " - 0.3"));
ok = sandbox.same_stdout(fuzzy_result, uglify_result, o.toplevel);
}
}
} else {
uglify_code = uglify_code.error;
Expand Down
25 changes: 16 additions & 9 deletions test/ufuzz/job.js
Expand Up @@ -12,17 +12,16 @@ function spawn(endTime) {
], {
stdio: [ "ignore", "pipe", "pipe" ]
}).on("exit", respawn);
var line = "";
var stdout = "";
child.stdout.on("data", function(data) {
line += data;
stdout += data;
});
child.stderr.once("data", function() {
process.exitCode = 1;
}).pipe(process.stdout);
var stderr = "";
child.stderr.on("data", trap).pipe(process.stdout);
var keepAlive = setInterval(function() {
var end = line.lastIndexOf("\r");
console.log(line.slice(line.lastIndexOf("\r", end - 1) + 1, end));
line = line.slice(end + 1);
var end = stdout.lastIndexOf("\r");
console.log(stdout.slice(stdout.lastIndexOf("\r", end - 1) + 1, end));
stdout = stdout.slice(end + 1);
}, ping);
var timer = setTimeout(function() {
clearInterval(keepAlive);
Expand All @@ -31,9 +30,17 @@ function spawn(endTime) {
}, endTime - Date.now());

function respawn() {
console.log(line);
console.log(stdout.replace(/[^\r\n]*\r/g, ""));
clearInterval(keepAlive);
clearTimeout(timer);
spawn(endTime);
}

function trap(data) {
stderr += data;
if (~stderr.indexOf("\nminify(options):\n")) {
process.exitCode = 1;
child.stderr.removeListener("data", trap);
}
}
}

0 comments on commit 3ff0fed

Please sign in to comment.