Chromium Code Reviews| Index: test/mjsunit/wasm/asm-wasm.js |
| diff --git a/test/mjsunit/wasm/asm-wasm.js b/test/mjsunit/wasm/asm-wasm.js |
| index 2ceba5e6a68228b21cf84dea82dfed5bf8c08ee4..ad9050471bc0e7ef607b44b6ac0bfc550aab959a 100644 |
| --- a/test/mjsunit/wasm/asm-wasm.js |
| +++ b/test/mjsunit/wasm/asm-wasm.js |
| @@ -4,6 +4,12 @@ |
| // Flags: --expose-wasm |
| +function assertWasm(expected, func, ffi) { |
| + print("Testing " + func.name + "..."); |
| + assertEquals(expected, Wasm.instantiateModuleFromAsm( |
| + func.toString(), ffi).caller()); |
| +} |
| + |
| function EmptyTest() { |
| "use asm"; |
| function caller() { |
| @@ -15,9 +21,25 @@ function EmptyTest() { |
| return {caller: caller}; |
| } |
| -assertEquals(11, Wasm.instantiateModuleFromAsm( |
| - EmptyTest.toString()).caller()); |
| +assertWasm(11, EmptyTest); |
| + |
| + |
| +function PosIntLiteralTest() { |
|
bradnelson
2016/03/23 19:14:25
Can we wrap this in a closure like the ones at the
titzer
2016/03/23 19:53:05
I ended up moving this all together into a differe
|
| + "use asm"; |
| + function f0() { return 0; } |
| + function f1() { return 1; } |
| + function f4() { return 4; } |
| + function f64() { return 64; } |
| + function f128() { return 128; } |
| + function f256() { return 256; } |
| + function f1000() { return 1000; } |
| + function f2000000() { return 2000000; } |
| + function fmax() { return 2147483647; } |
| + return {f0: f0, f1: f1, f4: f4, f64: f64, f128: f128, f256: f256, f1000: f1000, f2000000, fmax: fmax}; |
|
bradnelson
2016/03/23 19:14:25
wrap
|
| +} |
| +var module = Wasm.instantiateModuleFromAsm( |
| + PosIntLiteralTest.toString()); |
| function IntTest() { |
| "use asm"; |
| @@ -37,8 +59,7 @@ function IntTest() { |
| return {caller: caller}; |
| } |
| -assertEquals(101, Wasm.instantiateModuleFromAsm( |
| - IntTest.toString()).caller()); |
| +assertWasm(101,IntTest); |
| function Float64Test() { |
| @@ -63,8 +84,7 @@ function Float64Test() { |
| return {caller: caller}; |
| } |
| -assertEquals(1, Wasm.instantiateModuleFromAsm( |
| - Float64Test.toString()).caller()); |
| +assertWasm(1, Float64Test); |
| function BadModule() { |
| @@ -105,8 +125,22 @@ function TestReturnInBlock() { |
| return {caller: caller}; |
| } |
| -assertEquals(1, Wasm.instantiateModuleFromAsm( |
| - TestReturnInBlock.toString()).caller()); |
| +assertWasm(1, TestReturnInBlock); |
| + |
| + |
| +function TestAddSimple() { |
| + "use asm"; |
| + |
| + function caller() { |
| + var x = 0; |
| + x = (x + 1)|0; |
| + return x|0; |
| + } |
| + |
| + return {caller: caller}; |
| +} |
| + |
| +assertWasm(1, TestAddSimple); |
| function TestWhileSimple() { |
| @@ -123,8 +157,7 @@ function TestWhileSimple() { |
| return {caller: caller}; |
| } |
| -assertEquals(5, Wasm.instantiateModuleFromAsm( |
| - TestWhileSimple.toString()).caller()); |
| +assertWasm(5, TestWhileSimple); |
| function TestWhileWithoutBraces() { |
| @@ -140,8 +173,7 @@ function TestWhileWithoutBraces() { |
| return {caller: caller}; |
| } |
| -assertEquals(4, Wasm.instantiateModuleFromAsm( |
| - TestWhileWithoutBraces.toString()).caller()); |
| +assertWasm(4, TestWhileWithoutBraces); |
| function TestReturnInWhile() { |
| @@ -159,8 +191,7 @@ function TestReturnInWhile() { |
| return {caller: caller}; |
| } |
| -assertEquals(6, Wasm.instantiateModuleFromAsm( |
| - TestReturnInWhile.toString()).caller()); |
| +assertWasm(6, TestReturnInWhile); |
| function TestReturnInWhileWithoutBraces() { |
| @@ -176,9 +207,7 @@ function TestReturnInWhileWithoutBraces() { |
| return {caller: caller}; |
| } |
| -assertEquals( |
| - 7, Wasm.instantiateModuleFromAsm( |
| - TestReturnInWhileWithoutBraces.toString()).caller()); |
| +assertWasm(7, TestReturnInWhileWithoutBraces); |
| function TestBreakInWhile() { |
| @@ -194,8 +223,7 @@ function TestBreakInWhile() { |
| return {caller: caller}; |
| } |
| -assertEquals(8, Wasm.instantiateModuleFromAsm( |
| - TestBreakInWhile.toString()).caller()); |
| +assertWasm(8, TestBreakInWhile); |
| function TestBreakInNestedWhile() { |
| @@ -218,8 +246,7 @@ function TestBreakInNestedWhile() { |
| return {caller: caller}; |
| } |
| -assertEquals(9, Wasm.instantiateModuleFromAsm( |
| - TestBreakInNestedWhile.toString()).caller()); |
| +assertWasm(9, TestBreakInNestedWhile); |
| function TestBreakInBlock() { |
| @@ -240,8 +267,7 @@ function TestBreakInBlock() { |
| return {caller: caller}; |
| } |
| -assertEquals(10, Wasm.instantiateModuleFromAsm( |
| - TestBreakInBlock.toString()).caller()); |
| +assertWasm(10, TestBreakInBlock); |
| function TestBreakInNamedWhile() { |
| @@ -261,8 +287,7 @@ function TestBreakInNamedWhile() { |
| return {caller: caller}; |
| } |
| -assertEquals(11, Wasm.instantiateModuleFromAsm( |
| - TestBreakInNamedWhile.toString()).caller()); |
| +assertWasm(11, TestBreakInNamedWhile); |
| function TestContinue() { |
| @@ -284,8 +309,7 @@ function TestContinue() { |
| return {caller: caller}; |
| } |
| -assertEquals(-5, Wasm.instantiateModuleFromAsm( |
| - TestContinue.toString()).caller()); |
| +assertWasm(-5, TestContinue); |
| function TestContinueInNamedWhile() { |
| @@ -312,8 +336,7 @@ function TestContinueInNamedWhile() { |
| return {caller: caller}; |
| } |
| -assertEquals(20, Wasm.instantiateModuleFromAsm( |
| - TestContinueInNamedWhile.toString()).caller()); |
| +assertWasm(20, TestContinueInNamedWhile); |
| function TestNot() { |
| @@ -327,8 +350,7 @@ function TestNot() { |
| return {caller:caller}; |
| } |
| -assertEquals(1, Wasm.instantiateModuleFromAsm( |
| - TestNot.toString()).caller()); |
| +assertWasm(1, TestNot); |
| function TestNotEquals() { |
| @@ -345,8 +367,7 @@ function TestNotEquals() { |
| return {caller:caller}; |
| } |
| -assertEquals(21, Wasm.instantiateModuleFromAsm( |
| - TestNotEquals.toString()).caller()); |
| +assertWasm(21, TestNotEquals); |
| function TestUnsignedComparison() { |
| @@ -363,8 +384,7 @@ function TestUnsignedComparison() { |
| return {caller:caller}; |
| } |
| -assertEquals(22, Wasm.instantiateModuleFromAsm( |
| - TestUnsignedComparison.toString()).caller()); |
| +assertWasm(22, TestUnsignedComparison); |
| function TestMixedAdd() { |
| @@ -386,8 +406,7 @@ function TestMixedAdd() { |
| return {caller:caller}; |
| } |
| -assertEquals(23, Wasm.instantiateModuleFromAsm( |
| - TestMixedAdd.toString()).caller()); |
| +assertWasm(23, TestMixedAdd); |
| function TestInt32HeapAccess(stdlib, foreign, buffer) { |
| @@ -406,8 +425,7 @@ function TestInt32HeapAccess(stdlib, foreign, buffer) { |
| return {caller: caller}; |
| } |
| -assertEquals(7, Wasm.instantiateModuleFromAsm( |
| - TestInt32HeapAccess.toString()).caller()); |
| +assertWasm(7, TestInt32HeapAccess); |
| function TestInt32HeapAccessExternal() { |
| @@ -499,8 +517,7 @@ function TestConvertI32() { |
| return {caller:caller}; |
| } |
| -assertEquals(24, Wasm.instantiateModuleFromAsm( |
| - TestConvertI32.toString()).caller()); |
| +assertWasm(24, TestConvertI32); |
| function TestConvertF64FromInt() { |
| @@ -517,8 +534,7 @@ function TestConvertF64FromInt() { |
| return {caller:caller}; |
| } |
| -assertEquals(25, Wasm.instantiateModuleFromAsm( |
| - TestConvertF64FromInt.toString()).caller()); |
| +assertWasm(25, TestConvertF64FromInt); |
| function TestConvertF64FromUnsigned() { |
| @@ -537,8 +553,7 @@ function TestConvertF64FromUnsigned() { |
| return {caller:caller}; |
| } |
| -assertEquals(26, Wasm.instantiateModuleFromAsm( |
| - TestConvertF64FromUnsigned.toString()).caller()); |
| +assertWasm(26, TestConvertF64FromUnsigned); |
| function TestModInt() { |
| @@ -553,8 +568,7 @@ function TestModInt() { |
| return {caller:caller}; |
| } |
| -assertEquals(-27, Wasm.instantiateModuleFromAsm( |
| - TestModInt.toString()).caller()); |
| +assertWasm(-27,TestModInt); |
| function TestModUnsignedInt() { |
| @@ -569,8 +583,7 @@ function TestModUnsignedInt() { |
| return {caller:caller}; |
| } |
| -assertEquals(8, Wasm.instantiateModuleFromAsm( |
| - TestModUnsignedInt.toString()).caller()); |
| +assertWasm(8, TestModUnsignedInt); |
| function TestModDouble() { |
| @@ -588,8 +601,7 @@ function TestModDouble() { |
| return {caller:caller}; |
| } |
| -assertEquals(28, Wasm.instantiateModuleFromAsm( |
| - TestModDouble.toString()).caller()); |
| +assertWasm(28, TestModDouble); |
| /* |
| @@ -610,8 +622,7 @@ function TestModDoubleNegative() { |
| return {caller:caller}; |
| } |
| -assertEquals(28, Wasm.instantiateModuleFromAsm( |
| - TestModDoubleNegative.toString()).caller()); |
| +assertWasm(28, TestModDoubleNegative); |
| */ |
| @@ -671,8 +682,7 @@ function TestForLoop() { |
| return {caller:caller}; |
| } |
| -assertEquals(54, Wasm.instantiateModuleFromAsm( |
| - TestForLoop.toString()).caller()); |
| +assertWasm(54, TestForLoop); |
| function TestForLoopWithoutInit() { |
| @@ -690,8 +700,7 @@ function TestForLoopWithoutInit() { |
| return {caller:caller}; |
| } |
| -assertEquals(100, Wasm.instantiateModuleFromAsm( |
| - TestForLoopWithoutInit.toString()).caller()); |
| +assertWasm(100,TestForLoopWithoutInit); |
| function TestForLoopWithoutCondition() { |
| @@ -712,8 +721,7 @@ function TestForLoopWithoutCondition() { |
| return {caller:caller}; |
| } |
| -assertEquals(66, Wasm.instantiateModuleFromAsm( |
| - TestForLoopWithoutCondition.toString()).caller()); |
| +assertWasm(66, TestForLoopWithoutCondition); |
| function TestForLoopWithoutNext() { |
| @@ -730,8 +738,7 @@ function TestForLoopWithoutNext() { |
| return {caller:caller}; |
| } |
| -assertEquals(41, Wasm.instantiateModuleFromAsm( |
| - TestForLoopWithoutNext.toString()).caller()); |
| +assertWasm(41, TestForLoopWithoutNext); |
| function TestForLoopWithoutBody() { |
| @@ -747,8 +754,7 @@ function TestForLoopWithoutBody() { |
| return {caller:caller}; |
| } |
| -assertEquals(45, Wasm.instantiateModuleFromAsm( |
| - TestForLoopWithoutBody.toString()).caller()); |
| +assertWasm(45, TestForLoopWithoutBody); |
| function TestDoWhile() { |
| @@ -767,8 +773,7 @@ function TestDoWhile() { |
| return {caller:caller}; |
| } |
| -assertEquals(84, Wasm.instantiateModuleFromAsm( |
| - TestDoWhile.toString()).caller()); |
| +assertWasm(84, TestDoWhile); |
| function TestConditional() { |
| @@ -782,8 +787,7 @@ function TestConditional() { |
| return {caller:caller}; |
| } |
| -assertEquals(41, Wasm.instantiateModuleFromAsm( |
| - TestConditional.toString()).caller()); |
| +assertWasm(41, TestConditional); |
| function TestSwitch() { |
| @@ -811,8 +815,7 @@ function TestSwitch() { |
| return {caller:caller}; |
| } |
| -assertEquals(23, Wasm.instantiateModuleFromAsm( |
| - TestSwitch.toString()).caller()); |
| +assertWasm(23, TestSwitch); |
| function TestSwitchFallthrough() { |
| @@ -834,8 +837,7 @@ function TestSwitchFallthrough() { |
| return {caller:caller}; |
| } |
| -assertEquals(42, Wasm.instantiateModuleFromAsm( |
| - TestSwitchFallthrough.toString()).caller()); |
| +assertWasm(42, TestSwitchFallthrough); |
| function TestNestedSwitch() { |
| @@ -861,8 +863,7 @@ function TestNestedSwitch() { |
| return {caller:caller}; |
| } |
| -assertEquals(43, Wasm.instantiateModuleFromAsm( |
| - TestNestedSwitch.toString()).caller()); |
| +assertWasm(43, TestNestedSwitch); |
| function TestInitFunctionWithNoGlobals() { |
| @@ -907,8 +908,7 @@ function TestFunctionTableSingleFunction() { |
| return {caller:caller}; |
| } |
| -assertEquals(71, Wasm.instantiateModuleFromAsm( |
| - TestFunctionTableSingleFunction.toString()).caller()); |
| +assertWasm(71, TestFunctionTableSingleFunction); |
| function TestFunctionTableMultipleFunctions() { |
| @@ -938,8 +938,7 @@ function TestFunctionTableMultipleFunctions() { |
| return {caller:caller}; |
| } |
| -assertEquals(73, Wasm.instantiateModuleFromAsm( |
| - TestFunctionTableMultipleFunctions.toString()).caller()); |
| +assertWasm(73, TestFunctionTableMultipleFunctions); |
| function TestFunctionTable() { |
| @@ -1103,6 +1102,7 @@ function TestForeignVariables() { |
| } |
| function TestCase(env, i1, f1, i2, f2) { |
| + print("Testing foreign variables..."); |
|
bradnelson
2016/03/23 19:14:25
You mean to leave this in?
titzer
2016/03/23 19:53:05
I crashed here a couple times and it was useful to
|
| var module = Wasm.instantiateModuleFromAsm( |
| AsmModule.toString(), env); |
| assertEquals(i1, module.geti1()); |
| @@ -1212,24 +1212,19 @@ TestForeignVariables(); |
| })(); |
| -(function TestGlobalBlock() { |
| - function Module(stdlib, foreign, buffer) { |
| - "use asm"; |
| - |
| - var x = foreign.x | 0, y = foreign.y | 0; |
| +function TestGlobalBlock(stdlib, foreign, buffer) { |
| + "use asm"; |
| - function test() { |
| - return (x + y) | 0; |
| - } |
| + var x = foreign.x | 0, y = foreign.y | 0; |
| - return {test: test}; |
| + function test() { |
| + return (x + y) | 0; |
| } |
| - var m = Wasm.instantiateModuleFromAsm( |
| - Module.toString(), { x: 4, y: 11 }); |
| - assertEquals(15, m.test()); |
| -})(); |
| + return {caller: test}; |
| +} |
| +assertWasm(15, TestGlobalBlock, { x: 4, y: 11 }); |
| (function TestComma() { |
| function CommaModule() { |
| @@ -1256,67 +1251,55 @@ TestForeignVariables(); |
| })(); |
| -(function TestFloatAsDouble() { |
| - function Module(stdlib) { |
| - "use asm"; |
| - var fround = stdlib.Math.fround; |
| - function func() { |
| - var x = fround(1.0); |
| - return +fround(x); |
| - } |
| - return {func:func}; |
| +function TestFloatAsDouble(stdlib) { |
| + "use asm"; |
| + var fround = stdlib.Math.fround; |
| + function func() { |
| + var x = fround(1.0); |
| + return +fround(x); |
| } |
| - var m = Wasm.instantiateModuleFromAsm(Module.toString()); |
| - assertEquals(1, m.func()); |
| -})(); |
| + return {caller: func}; |
| +} |
| +assertWasm(1, TestFloatAsDouble); |
| -(function TestOr() { |
| - function Module() { |
| - "use asm"; |
| - function func() { |
| - var x = 1; |
| - var y = 2; |
| - return (x | y) | 0; |
| - } |
| - return {func: func}; |
| +function TestOr() { |
| + "use asm"; |
| + function func() { |
| + var x = 1; |
| + var y = 2; |
| + return (x | y) | 0; |
| } |
| + return {caller: func}; |
| +} |
| - var m = Wasm.instantiateModuleFromAsm(Module.toString()); |
| - assertEquals(3, m.func()); |
| -})(); |
| +assertWasm(3, TestOr); |
| -(function TestAnd() { |
| - function Module() { |
| - "use asm"; |
| - function func() { |
| - var x = 3; |
| - var y = 2; |
| - return (x & y) | 0; |
| - } |
| - return {func: func}; |
| +function TestAnd() { |
| + "use asm"; |
| + function func() { |
| + var x = 3; |
| + var y = 2; |
| + return (x & y) | 0; |
| } |
| + return {caller: func}; |
| +} |
| - var m = Wasm.instantiateModuleFromAsm(Module.toString()); |
| - assertEquals(2, m.func()); |
| -})(); |
| +assertWasm(2, TestAnd); |
| -(function TestXor() { |
| - function Module() { |
| - "use asm"; |
| - function func() { |
| - var x = 3; |
| - var y = 2; |
| - return (x ^ y) | 0; |
| - } |
| - return {func: func}; |
| +function TestXor() { |
| + "use asm"; |
| + function func() { |
| + var x = 3; |
| + var y = 2; |
| + return (x ^ y) | 0; |
| } |
| + return {caller: func}; |
| +} |
| - var m = Wasm.instantiateModuleFromAsm(Module.toString()); |
| - assertEquals(1, m.func()); |
| -})(); |
| +assertWasm(1, TestXor); |
| (function TestIntishAssignment() { |