v8/test/mjsunit/wasm/adapter-frame.js
Sven Sauleau 5bdb13297f [wasm] merge js constants file in module-builder
We noticed that almost every call site were loading both files,
the split isn't necessary anymore.

In some message tests, removed the absolute line number to allow future
changes.

Bug: v8:8726
Change-Id: I8527f0a1ecfa685aa01a5e2f5f47ddf1cb13a545
Reviewed-on: https://chromium-review.googlesource.com/c/1446452
Commit-Queue: Sven Sauleau <ssauleau@igalia.com>
Reviewed-by: Ben Titzer <titzer@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59220}
2019-01-30 22:10:34 +00:00

320 lines
8.4 KiB
JavaScript

// Copyright 2015 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.
// Flags: --expose-wasm
load("test/mjsunit/wasm/wasm-module-builder.js");
const JS = false; // for testing the tests.
const WRONG1 = 0x0DEDFACE;
const WRONG2 = 0x0DEDBABE;
const WRONG3 = 0x0DEDD011
function makeSelect(type, args, which) {
if (JS) {
// For testing the tests.
return function() {
var val = +arguments[which];
print(" " + val);
if (type == kWasmI32) return val | 0;
if (type == kWasmF32) return Math.fround(val);
if (type == kWasmF64) return val;
return undefined;
}
}
var builder = new WasmModuleBuilder();
var params = [];
for (var i = 0; i < args; i++) params.push(type);
builder.addFunction("select", makeSig(params, [type]))
.addBody([kExprGetLocal, which])
.exportFunc();
return builder.instantiate().exports.select;
}
const inputs = [
-1, 0, 2.2, 3.3, 3000.11, Infinity, -Infinity, NaN
];
(function TestInt1() {
print("i32 1(0)...");
var C = function(v) { return v | 0; }
var select1 = makeSelect(kWasmI32, 1, 0);
for (val of inputs) {
assertEquals(C(val), select1(val));
// under args
assertEquals(C(undefined), select1());
// over args
assertEquals(C(val), select1(val, WRONG1));
assertEquals(C(val), select1(val, WRONG1, WRONG2));
}
})();
(function TestInt2() {
print("i32 2(0)...");
var C = function(v) { return v | 0; }
var select = makeSelect(kWasmI32, 2, 0);
for (val of inputs) {
assertEquals(C(val), select(val, WRONG1));
// under args
assertEquals(C(undefined), select());
assertEquals(C(val), select(val));
// over args
assertEquals(C(val), select(val, WRONG1, WRONG2));
assertEquals(C(val), select(val, WRONG1, WRONG2, WRONG3));
}
print("i32 2(1)...");
var select = makeSelect(kWasmI32, 2, 1);
for (val of inputs) {
assertEquals(C(val), select(WRONG1, val));
// under args
assertEquals(C(undefined), select());
assertEquals(C(undefined), select(val));
// over args
assertEquals(C(val), select(WRONG1, val));
assertEquals(C(val), select(WRONG1, val, WRONG2));
assertEquals(C(val), select(WRONG1, val, WRONG2, WRONG3));
}
})();
(function TestInt3() {
print("i32 3(0)...");
var C = function(v) { return v | 0; }
var select = makeSelect(kWasmI32, 3, 0);
for (val of inputs) {
assertEquals(C(val), select(val, WRONG1, WRONG2));
// under args
assertEquals(C(undefined), select());
assertEquals(C(val), select(val));
assertEquals(C(val), select(val, WRONG1));
// over args
assertEquals(C(val), select(val, WRONG1, WRONG2, WRONG3));
}
print("i32 3(1)...");
var select = makeSelect(kWasmI32, 3, 1);
for (val of inputs) {
assertEquals(val | 0, select(WRONG1, val, WRONG2));
// under args
assertEquals(C(undefined), select());
assertEquals(C(undefined), select(0xDEDFACE));
assertEquals(C(val), select(WRONG1, val));
// over args
assertEquals(C(val), select(WRONG1, val, WRONG2, WRONG3));
}
print("i32 3(2)...");
var select = makeSelect(kWasmI32, 3, 2);
for (val of inputs) {
assertEquals(C(val), select(WRONG1, WRONG2, val));
// under args
assertEquals(C(undefined), select());
assertEquals(C(undefined), select(0xDEDFACE));
assertEquals(C(undefined), select(WRONG1, WRONG2));
// over args
assertEquals(C(val), select(WRONG1, WRONG2, val, WRONG3));
}
})();
(function TestFloat32_1() {
print("f32 1(0)...");
var C = function(v) { return Math.fround(v); }
var select1 = makeSelect(kWasmF32, 1, 0);
for (val of inputs) {
assertEquals(C(val), select1(val));
// under args
assertEquals(C(undefined), select1());
// over args
assertEquals(C(val), select1(val, WRONG1));
assertEquals(C(val), select1(val, WRONG1, WRONG2));
}
})();
(function TestFloat32_2() {
print("f32 2(0)...");
var C = function(v) { return Math.fround(v); }
var select = makeSelect(kWasmF32, 2, 0);
for (val of inputs) {
assertEquals(C(val), select(val, WRONG1));
// under args
assertEquals(C(undefined), select());
assertEquals(C(val), select(val));
// over args
assertEquals(C(val), select(val, WRONG1, WRONG2));
assertEquals(C(val), select(val, WRONG1, WRONG2, WRONG3));
}
print("f32 2(1)...");
var select = makeSelect(kWasmF32, 2, 1);
for (val of inputs) {
assertEquals(C(val), select(WRONG1, val));
// under args
assertEquals(C(undefined), select());
assertEquals(C(undefined), select(val));
// over args
assertEquals(C(val), select(WRONG1, val));
assertEquals(C(val), select(WRONG1, val, WRONG2));
assertEquals(C(val), select(WRONG1, val, WRONG2, WRONG3));
}
})();
(function TestFloat32_2() {
print("f32 3(0)...");
var C = function(v) { return Math.fround(v); }
var select = makeSelect(kWasmF32, 3, 0);
for (val of inputs) {
assertEquals(C(val), select(val, WRONG1, WRONG2));
// under args
assertEquals(C(undefined), select());
assertEquals(C(val), select(val));
assertEquals(C(val), select(val, WRONG1));
// over args
assertEquals(C(val), select(val, WRONG1, WRONG2, WRONG3));
}
print("f32 3(1)...");
var select = makeSelect(kWasmF32, 3, 1);
for (val of inputs) {
assertEquals(C(val), select(WRONG1, val, WRONG2));
// under args
assertEquals(C(undefined), select());
assertEquals(C(undefined), select(0xDEDFACE));
assertEquals(C(val), select(WRONG1, val));
// over args
assertEquals(C(val), select(WRONG1, val, WRONG2, WRONG3));
}
print("f32 3(2)...");
var select = makeSelect(kWasmF32, 3, 2);
for (val of inputs) {
assertEquals(C(val), select(WRONG1, WRONG2, val));
// under args
assertEquals(C(undefined), select());
assertEquals(C(undefined), select(0xDEDFACE));
assertEquals(C(undefined), select(WRONG1, WRONG2));
// over args
assertEquals(C(val), select(WRONG1, WRONG2, val, WRONG3));
}
})();
(function TestFloat64_1() {
print("f64 1(0)...");
var C = function(v) { return +v; }
var select1 = makeSelect(kWasmF64, 1, 0);
for (val of inputs) {
assertEquals(C(val), select1(val));
// under args
assertEquals(C(undefined), select1());
// over args
assertEquals(C(val), select1(val, WRONG1));
assertEquals(C(val), select1(val, WRONG1, WRONG2));
}
})();
(function TestFloat64_2() {
print("f64 2(0)...");
var C = function(v) { return +v; }
var select = makeSelect(kWasmF64, 2, 0);
for (val of inputs) {
assertEquals(C(val), select(val, WRONG1));
// under args
assertEquals(C(undefined), select());
assertEquals(C(val), select(val));
// over args
assertEquals(C(val), select(val, WRONG1, WRONG2));
assertEquals(C(val), select(val, WRONG1, WRONG2, WRONG3));
}
print("f64 2(1)...");
var select = makeSelect(kWasmF64, 2, 1);
for (val of inputs) {
assertEquals(C(val), select(WRONG1, val));
// under args
assertEquals(C(undefined), select());
assertEquals(C(undefined), select(val));
// over args
assertEquals(C(val), select(WRONG1, val));
assertEquals(C(val), select(WRONG1, val, WRONG2));
assertEquals(C(val), select(WRONG1, val, WRONG2, WRONG3));
}
})();
(function TestFloat64_2() {
print("f64 3(0)...");
var C = function(v) { return +v; }
var select = makeSelect(kWasmF64, 3, 0);
for (val of inputs) {
assertEquals(C(val), select(val, WRONG1, WRONG2));
// under args
assertEquals(C(undefined), select());
assertEquals(C(val), select(val));
assertEquals(C(val), select(val, WRONG1));
// over args
assertEquals(C(val), select(val, WRONG1, WRONG2, WRONG3));
}
print("f64 3(1)...");
var select = makeSelect(kWasmF64, 3, 1);
for (val of inputs) {
assertEquals(C(val), select(WRONG1, val, WRONG2));
// under args
assertEquals(C(undefined), select());
assertEquals(C(undefined), select(0xDEDFACE));
assertEquals(C(val), select(WRONG1, val));
// over args
assertEquals(C(val), select(WRONG1, val, WRONG2, WRONG3));
}
print("f64 3(2)...");
var select = makeSelect(kWasmF64, 3, 2);
for (val of inputs) {
assertEquals(C(val), select(WRONG1, WRONG2, val));
// under args
assertEquals(C(undefined), select());
assertEquals(C(undefined), select(0xDEDFACE));
assertEquals(C(undefined), select(WRONG1, WRONG2));
// over args
assertEquals(C(val), select(WRONG1, WRONG2, val, WRONG3));
}
})();