Commit 85776893 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm][tests] Sync testharness of wasm-js tests with wpt

Recently the test harness of the js-api spec tests got updated
to the test harness of wpt. With this CL we import the wpt test
harness into V8.

Some adjustments to the test harness had to be made. These additions
are in the new files report.js and testharness-additions.js

Bug: v8:10556
Change-Id: Ia5f7dec3f40ba8fc639135fb2b2078b9220eccf7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2235116
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarEmanuel Ziegler <ecmziegler@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68355}
parent 24d34c17
W3C 3-clause BSD License
http://www.w3.org/Consortium/Legal/2008/03-bsd-license.html
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of works must retain the original copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the original copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the W3C nor the names of its contributors may be
used to endorse or promote products derived from this work without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Copyright 2020 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.
// Tell the test harness that we are done with all tests.
done();
// Copyright 2020 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.
function check_test_results(tests, status) {
let failed_counter = 0;
for (let test of tests) {
const PASS = 0;
const FAIL = 1;
const TIMEOUT = 2;
const NOTRUN = 3;
const PRECONDITION_FAILED = 4;
if (test.status !== PASS) {
console.log();
if (test.status === FAIL) {
console.log("Test failed");
} else if(test.status === TIMEOUT) {
console.log("Timeout");
} else if(test.status === NOTRUN) {
console.log("Test did not run");
} else if (test.status === PRECONDITION_FAILED) {
console.log("Test precondition failed");
} else {
console.log("Unknown error code:", test.status);
}
console.log("Message:");
console.log(test.message);
console.log("Stack trace:");
console.log(test.stack);
failed_counter++;
}
}
setTimeout(() => assertEquals(0, failed_counter));
}
add_completion_callback(check_test_results);
setup(() => {}, {'explicit_done': true});
......@@ -16,20 +16,24 @@ META_TIMEOUT_REGEXP = re.compile(r"META:\s*timeout=(.*)")
proposal_flags = [{
'name': 'reference-types',
'flags': ['--experimental-wasm-reftypes',
'--no-experimental-wasm-bulk-memory']
'--no-experimental-wasm-bulk-memory',
'--wasm-staging']
},
{
'name': 'bulk-memory-operations',
'flags': ['--experimental-wasm-bulk-memory']
'flags': ['--experimental-wasm-bulk-memory',
'--wasm-staging']
},
{
'name': 'js-types',
'flags': ['--experimental-wasm-type-reflection',
'--no-experimental-wasm-bulk-memory']
'--no-experimental-wasm-bulk-memory',
'--wasm-staging']
},
{
'name': 'JS-BigInt-integration',
'flags': ['--experimental-wasm-bigint']
'flags': ['--experimental-wasm-bigint',
'--wasm-staging']
},
]
......@@ -73,7 +77,9 @@ class TestCase(testcase.D8TestCase):
def _get_files_params(self):
files = [self.suite.mjsunit_js,
os.path.join(self.suite.root, "testharness.js")]
os.path.join(self.suite.root, "third_party", "testharness.js"),
os.path.join(self.suite.root, "testharness-additions.js"),
os.path.join(self.suite.root, "report.js")]
source = self.get_source()
current_dir = os.path.dirname(self._get_source_path())
......@@ -98,17 +104,15 @@ class TestCase(testcase.D8TestCase):
files.append(script)
files.extend([
self._get_source_path(),
os.path.join(self.suite.root, "testharness-after.js")
])
files.extend([self._get_source_path(),
os.path.join(self.suite.root, "after.js")])
return files
def _get_source_flags(self):
for proposal in proposal_flags:
if get_proposal_path_identifier(proposal) in self.path:
return proposal['flags']
return []
return ['--wasm-staging']
def _get_source_path(self):
# All tests are named `path/name.any.js`
......
// Copyright 2020 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.
function assert_throws(code, func, description) {
try {
func();
} catch (e) {
assert_true(
e.name === code.name,
'expected exception ' + code.name + ', got ' + e.name);
return;
}
assert_true(
false, 'expected exception ' + code.name + ', no exception thrown');
}
function promise_rejects(test, expected, promise, description) {
return promise
.then(() => assert_unreached('Should have rejected: ' + description))
.catch(function(e) {
assert_throws(expected, function() {
throw e;
}, description);
});
}
// 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.
// Uses lastPromise defined in testharness.js
assertPromiseResult(lastPromise, _ => {
if (failures.length > 0) {
let message = 'Some tests FAILED:\n';
for (const failure of failures) {
message += ` ${failure}\n`;
}
failWithMessage(message);
}
});
// 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.
// Implementations of some functions from testharness.js
// See https://github.com/web-platform-tests/wpt/blob/master/resources/testharness.js
// Licensed as follows:
//
// Distributed under both the W3C Test Suite License [1] and the W3C
// 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
// policies and contribution forms [3].
// [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
// [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
// [3] http://www.w3.org/2004/10/27-testcases
const failures = [];
let lastPromise = Promise.resolve();
function test(func, description) {
let maybeErr;
try { func({unreached_func: unreached_func}); }
catch(e) { maybeErr = e; }
if (typeof maybeErr !== 'undefined') {
console.log(`${description}: FAIL. ${maybeErr}`);
failures.push(description);
} else {
console.log(`${description}: PASS.`);
}
}
function promise_test(func, description) {
lastPromise = lastPromise.then(func)
.then(_ => {
console.log(`${description}: PASS.`);
})
.catch(err => {
console.log(`${description}: FAIL. ${err}`);
failures.push(description);
});
}
const assert_true = assertEquals.bind(null, true);
const assert_false = assertEquals.bind(null, false);
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;
}
function assert_equals(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});
}
function assert_not_equals(expected, found, description) {
assert_true(!same_value(found, expected), "assert_not_equals", description,
"got disallowed value ${found}", {found:found});
}
function assert_array_equals(actual, expected, description) {
assert_true(
typeof actual === 'object' && actual !== null && 'length' in actual,
'assert_array_equals', description, 'value is ${actual}, expected array',
{actual: actual});
assert_true(
actual.length === expected.length, 'assert_array_equals', description,
'lengths differ, expected ${expected} got ${actual}',
{expected: expected.length, actual: actual.length});
for (let i = 0; i < actual.length; i++) {
assert_true(
actual.hasOwnProperty(i) === expected.hasOwnProperty(i),
'assert_array_equals', description,
'property ${i}, property expected to be ${expected} but was ${actual}',
{
i: i,
expected: expected.hasOwnProperty(i) ? 'present' : 'missing',
actual: actual.hasOwnProperty(i) ? 'present' : 'missing'
});
assert_true(
same_value(expected[i], actual[i]), 'assert_array_equals', description,
'property ${i}, expected ${expected} but got ${actual}',
{i: i, expected: expected[i], actual: actual[i]});
}
}
function unreached_func(msg) {
return function trap() {
assert_unreached(msg);
};
}
function assert_unreached(description) {
throw new Error(`unreachable:\n${description}`);
}
function format_value(s) {
// TODO
try {
return String(s);
} catch(e) {
return `<String(e) for type ${typeof(e)} threw>`;
}
}
function promise_rejects(test, expected, promise, description) {
return promise
.then(() => assert_unreached('Should have rejected: ' + description))
.catch(function(e) {
assert_throws(expected, function() {
throw e;
}, description);
});
}
function assert_class_string(object, class_string, description) {
assert_equals(
{}.toString.call(object), '[object ' + class_string + ']', description);
}
function assert_throws(code, func, description) {
try {
func();
} catch (e) {
assert_true(e.name === code.name, "expected exception " + code.name + ", got " + e.name);
return;
}
assert_true(false, "expected exception " + code.name + ", no exception thrown");
}
function setup(func) {
// TODO need to do anything fancier here?
func();
}
# The 3-Clause BSD License
Copyright 2019 web-platform-tests contributors
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -6,40 +6,16 @@
[ALWAYS, {
# TODO(v8:10556): Remove sub-typing in the reference-types implementation
'constructor/compile': [FAIL],
'constructor/instantiate-bad-imports': [FAIL],
'constructor/instantiate': [FAIL],
'constructor/multi-value': [FAIL],
'constructor/validate': [FAIL],
'global/constructor': [FAIL],
'global/value-get-set': [FAIL],
'global/valueOf': [FAIL],
'global/toString': [FAIL],
'instance/constructor-bad-imports': [FAIL],
'instance/constructor-caching': [FAIL],
'instance/constructor': [FAIL],
'instance/exports': [FAIL],
'instance/toString': [FAIL],
'interface': [FAIL],
'memory/toString': [FAIL],
'memory/grow': [FAIL],
'memory/buffer': [FAIL],
'memory/constructor': [FAIL],
'module/constructor': [FAIL],
'module/customSections': [FAIL],
'module/exports': [FAIL],
'module/imports': [FAIL],
'module/toString': [FAIL],
'proposals/JS-BigInt-integration/global/value-get-set': [FAIL],
'proposals/JS-BigInt-integration/global/constructor': [FAIL],
'proposals/js-types/constructor/instantiate': [FAIL],
'proposals/js-types/global/constructor': [FAIL],
'proposals/js-types/global/value-get-set': [FAIL],
'proposals/js-types/instance/constructor': [FAIL],
'prototypes': [FAIL],
'table/constructor': [FAIL],
'table/get-set': [FAIL],
'table/grow': [FAIL],
'table/length': [FAIL],
'table/toString': [FAIL],
# These are slow, and not useful to run for the proposals:
'proposals/reference-types/limits': [SKIP],
......
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