Commit 8d889e39 authored by Michael Achenbach's avatar Michael Achenbach Committed by Commit Bot

[foozzie] Migrate mjsunit harness adjustments to V8 repo

This migrates harness adjustments, to be loaded after mjsunit.js on
fuzzers for correctness fuzzing.

This is the first step adding deeper pretty printing. Other
adjustments will be added in follow ups.

Bug: chromium:813833
Change-Id: I51168a31e733d54808cb8853a1c90e897acf3791
Reviewed-on: https://chromium-review.googlesource.com/930565
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51481}
parent 22fb961b
......@@ -178,6 +178,8 @@ var testAsync;
// Monkey-patchable all-purpose failure handler.
var failWithMessage;
// Returns a pretty-printed string representation of the passed value.
var prettyPrinted;
(function () { // Scope for utility functions.
......@@ -224,7 +226,7 @@ var failWithMessage;
}
function PrettyPrint(value) {
prettyPrinted = function prettyPrinted(value) {
switch (typeof value) {
case "string":
return JSON.stringify(value);
......@@ -247,11 +249,12 @@ var failWithMessage;
case "String":
case "Boolean":
case "Date":
return objectClass + "(" + PrettyPrint(ValueOf(value)) + ")";
return objectClass + "(" + prettyPrinted(ValueOf(value)) + ")";
case "RegExp":
return RegExpPrototypeToString.call(value);
case "Array":
var mapped = ArrayPrototypeMap.call(value, PrettyPrintArrayElement);
var mapped = ArrayPrototypeMap.call(
value, prettyPrintedArrayElement);
var joined = ArrayPrototypeJoin.call(mapped, ",");
return "[" + joined + "]";
case "Uint8Array":
......@@ -279,9 +282,9 @@ var failWithMessage;
}
function PrettyPrintArrayElement(value, index, array) {
function prettyPrintedArrayElement(value, index, array) {
if (value === undefined && !(index in array)) return "";
return PrettyPrint(value);
return prettyPrinted(value);
}
......@@ -296,7 +299,7 @@ var failWithMessage;
message += " (" + name_opt + ")";
}
var foundText = PrettyPrint(found);
var foundText = prettyPrinted(found);
if (expectedText.length <= 40 && foundText.length <= 40) {
message += ": expected <" + expectedText + "> found <" + foundText + ">";
} else {
......@@ -372,7 +375,7 @@ var failWithMessage;
} else if ((expected !== expected) && (found !== found)) {
return;
}
fail(PrettyPrint(expected), found, name_opt);
fail(prettyPrinted(expected), found, name_opt);
};
assertNotSame = function assertNotSame(expected, found, name_opt) {
......@@ -383,18 +386,18 @@ var failWithMessage;
} else if (!((expected !== expected) && (found !== found))) {
return;
}
fail(PrettyPrint(expected), found, name_opt);
fail(prettyPrinted(expected), found, name_opt);
}
assertEquals = function assertEquals(expected, found, name_opt) {
if (!deepEquals(found, expected)) {
fail(PrettyPrint(expected), found, name_opt);
fail(prettyPrinted(expected), found, name_opt);
}
};
assertNotEquals = function assertNotEquals(expected, found, name_opt) {
if (deepEquals(found, expected)) {
fail("not equals to " + PrettyPrint(expected), found, name_opt);
fail("not equals to " + prettyPrinted(expected), found, name_opt);
}
};
......@@ -402,7 +405,7 @@ var failWithMessage;
assertEqualsDelta =
function assertEqualsDelta(expected, found, delta, name_opt) {
if (Math.abs(expected - found) > delta) {
fail(PrettyPrint(expected) + " +- " + PrettyPrint(delta), found, name_opt);
fail(prettyPrinted(expected) + " +- " + prettyPrinted(delta), found, name_opt);
}
};
......@@ -509,7 +512,7 @@ var failWithMessage;
if (typeof actualConstructor === "function") {
actualTypeName = actualConstructor.name || String(actualConstructor);
}
failWithMessage("Object <" + PrettyPrint(obj) + "> is not an instance of <" +
failWithMessage("Object <" + prettyPrinted(obj) + "> is not an instance of <" +
(type.name || type) + ">" +
(actualTypeName ? " but of <" + actualTypeName + ">" : ""));
}
......@@ -781,7 +784,7 @@ var failWithMessage;
equals(expected, found, name_opt) {
this.actualAsserts_++;
if (!deepEquals(expected, found)) {
this.fail(PrettyPrint(expected), found, name_opt);
this.fail(prettyPrinted(expected), found, name_opt);
}
}
......
......@@ -9,6 +9,7 @@ if (v8_correctness_fuzzer) {
sources = [
"v8_commands.py",
"v8_foozzie.py",
"v8_foozzie_harness_adjust.js",
"v8_fuzz_config.py",
"v8_mock.js",
"v8_mock_archs.js",
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Extensions to mjsunit and other test harnesses added between harness and
// fuzzing code.
try {
// Scope for utility functions.
(function() {
// Same as in mjsunit.js.
function classOf(object) {
// Argument must not be null or undefined.
var string = Object.prototype.toString.call(object);
// String has format [object <ClassName>].
return string.substring(8, string.length - 1);
}
// Override prettyPrinted with a version that also recusively prints object
// properties (with a depth of 3).
let origPrettyPrinted = this.prettyPrinted;
this.prettyPrinted = function prettyPrinted(value, depth=3) {
if (depth == 0) {
return "...";
}
switch (typeof value) {
case "object":
if (value === null) return "null";
var objectClass = classOf(value);
switch (objectClass) {
case "Object":
var name = value.constructor.name;
if (!name)
name = "Object";
return name + "{" + Object.keys(value).map(function(key, index) {
return (
prettyPrinted(key, depth - 1) +
": " +
prettyPrinted(value[key], depth - 1)
);
}).join(",") + "}";
}
}
// Fall through to original version for all other types.
return origPrettyPrinted(value);
}
})();
} catch(e) { }
......@@ -10,7 +10,7 @@
// This will be overridden in the test cases. The override can be minimized.
var __PrettyPrint = function __PrettyPrint(msg) { print(msg); };
var prettyPrinted = function prettyPrinted(msg) { return msg; };
// Mock Math.random.
(function () {
......@@ -121,16 +121,16 @@ Object.defineProperty(
];
Worker = function(code){
try {
__PrettyPrint(eval(code));
print(prettyPrinted(eval(code)));
} catch(e) {
__PrettyPrint(e);
print(prettyPrinted(e));
}
this.getMessage = function(){
index = (index + 1) % 10;
return workerMessages[index];
}
this.postMessage = function(msg){
__PrettyPrint(msg);
print(prettyPrinted(msg));
}
};
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment