2017-02-14 18:25:32 +00:00
|
|
|
// Copyright 2017 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.
|
2017-04-06 09:49:38 +00:00
|
|
|
//
|
2017-02-14 18:25:32 +00:00
|
|
|
// TODO(eholk): Once we have stable test IDs, use those as the key instead.
|
|
|
|
// See https://github.com/WebAssembly/spec/issues/415
|
2017-04-06 09:49:38 +00:00
|
|
|
//
|
|
|
|
// Flags: --expose-wasm --allow-natives-syntax
|
|
|
|
|
2017-02-14 18:25:32 +00:00
|
|
|
const known_failures = {
|
2017-08-03 16:13:47 +00:00
|
|
|
// Enter failing tests like follows:
|
|
|
|
// "'WebAssembly.Instance.prototype.exports' accessor property":
|
|
|
|
// 'https://bugs.chromium.org/p/v8/issues/detail?id=5507',
|
2017-02-14 18:25:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let failures = [];
|
2017-02-27 21:03:35 +00:00
|
|
|
let unexpected_successes = [];
|
2017-02-14 18:25:32 +00:00
|
|
|
|
|
|
|
let last_promise = new Promise((resolve, reject) => { resolve(); });
|
|
|
|
|
|
|
|
function test(func, description) {
|
|
|
|
let maybeErr;
|
|
|
|
try { func(); }
|
|
|
|
catch(e) { maybeErr = e; }
|
|
|
|
if (typeof maybeErr !== 'undefined') {
|
2017-02-27 21:03:35 +00:00
|
|
|
var known = "";
|
|
|
|
if (known_failures[description]) {
|
|
|
|
known = " (known)";
|
|
|
|
}
|
|
|
|
print(`${description}: FAIL${known}. ${maybeErr}`);
|
2017-02-14 18:25:32 +00:00
|
|
|
failures.push(description);
|
|
|
|
} else {
|
2017-02-27 21:03:35 +00:00
|
|
|
if (known_failures[description]) {
|
|
|
|
unexpected_successes.push(description);
|
|
|
|
}
|
2017-02-14 18:25:32 +00:00
|
|
|
print(`${description}: PASS.`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function promise_test(func, description) {
|
|
|
|
last_promise = last_promise.then(func)
|
2017-02-27 21:03:35 +00:00
|
|
|
.then(_ => {
|
|
|
|
if (known_failures[description]) {
|
|
|
|
unexpected_successes.push(description);
|
|
|
|
}
|
|
|
|
print(`${description}: PASS.`);
|
|
|
|
})
|
2017-02-14 18:25:32 +00:00
|
|
|
.catch(err => {
|
2017-02-27 21:03:35 +00:00
|
|
|
var known = "";
|
|
|
|
if (known_failures[description]) {
|
|
|
|
known = " (known)";
|
|
|
|
}
|
|
|
|
print(`${description}: FAIL${known}. ${err}`);
|
2017-02-14 18:25:32 +00:00
|
|
|
failures.push(description);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let assert_true = assertEquals.bind(null, true);
|
|
|
|
let assert_false = assertEquals.bind(null, false);
|
|
|
|
|
2017-08-02 17:30:58 +00:00
|
|
|
function same_value(x, y) {
|
|
|
|
if (y !== y) {
|
|
|
|
// NaN case
|
|
|
|
return x!==x;
|
|
|
|
}
|
|
|
|
if (x === 0 && y === 0) {
|
|
|
|
// Distinguish +0 and -0
|
|
|
|
return 1/x === 1/y;
|
|
|
|
}
|
|
|
|
return x === y;
|
|
|
|
}
|
|
|
|
|
|
|
|
let assert_equals = function(expected, found, description) {
|
|
|
|
if (typeof found != typeof expected) {
|
|
|
|
assert_true(false, "assert_equals", description,
|
|
|
|
"expected (" + typeof expected + ") ${expected} but got (" +
|
|
|
|
typeof found + ") ${found}", {expected:expected, found:found});
|
|
|
|
}
|
|
|
|
assert_true(same_value(found, expected), "assert_equals", description,
|
|
|
|
"expected ${expected} but got ${found}",
|
|
|
|
{expected:expected, found:found});
|
|
|
|
}
|
|
|
|
|
|
|
|
let assert_not_equals = function(expected, found, description) {
|
|
|
|
assert_true(!same_value(found, expected), "assert_not_equals", description,
|
|
|
|
"got disallowed value ${found}", {found:found});
|
|
|
|
}
|
|
|
|
|
2017-02-14 18:25:32 +00:00
|
|
|
function assert_unreached(description) {
|
|
|
|
throw new Error(`unreachable:\n${description}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
function assertErrorMessage(f, ctor, test) {
|
|
|
|
try { f(); }
|
|
|
|
catch (e) {
|
|
|
|
assert_true(e instanceof ctor, "expected exception " + ctor.name + ", got " + e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert_true(false, "expected exception " + ctor.name + ", no exception thrown");
|
|
|
|
};
|
|
|
|
|
|
|
|
load("test/wasm-js/test/harness/wasm-constants.js");
|
|
|
|
load("test/wasm-js/test/harness/wasm-module-builder.js");
|
|
|
|
load("test/wasm-js/test/js-api/jsapi.js");
|
|
|
|
|
2017-10-25 14:12:49 +00:00
|
|
|
assertPromiseResult(last_promise, _ => {
|
|
|
|
if (failures.length > 0) {
|
|
|
|
let unexpected = false;
|
|
|
|
print("Some tests FAILED:");
|
|
|
|
for (let i in failures) {
|
|
|
|
if (known_failures[failures[i]]) {
|
|
|
|
print(` ${failures[i]} [KNOWN: ${known_failures[failures[i]]}]`);
|
|
|
|
} else {
|
|
|
|
print(` ${failures[i]}`);
|
2017-02-14 18:25:32 +00:00
|
|
|
unexpected = true;
|
|
|
|
}
|
2017-10-25 14:12:49 +00:00
|
|
|
}
|
|
|
|
if (unexpected_successes.length > 0) {
|
|
|
|
unexpected = true;
|
|
|
|
print("");
|
|
|
|
print("Unexpected successes:");
|
|
|
|
for(let i in unexpected_successes) {
|
|
|
|
print(` ${unexpected_successes[i]}`);
|
2017-02-27 21:03:35 +00:00
|
|
|
}
|
2017-10-25 14:12:49 +00:00
|
|
|
print("Some tests SUCCEEDED but were known failures. If you've fixed " +
|
|
|
|
"the bug, please remove the test from the known failures list.")
|
2017-02-27 21:03:35 +00:00
|
|
|
}
|
2017-10-25 14:12:49 +00:00
|
|
|
if (unexpected) {
|
|
|
|
print("\n");
|
|
|
|
print(" #############################################################");
|
|
|
|
print(" # #");
|
|
|
|
print(" # Unexpected outcome. Did you forget to run 'gclient sync'? #");
|
|
|
|
print(" # #");
|
|
|
|
print(" #############################################################");
|
|
|
|
print("\n");
|
|
|
|
assertUnreachable("Unexpected outcome");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|