浏览代码

Add test for int64 comparison operators

Michael Ferris 8 年之前
父节点
当前提交
2e8dd2e301

+ 3 - 3
test/wasm/baselines/cse.baseline

@@ -1,3 +1,3 @@
- --- CSE (foo_i32[0]): Add_I4
- --- CSE (foo_i64[0]): Add_I4
-PASSED
+ --- CSE (foo_i32[0]): Add_I4
+ --- CSE (foo_i64[0]): Add_I4
+PASSED

+ 3 - 3
test/wasm/baselines/global.baseline

@@ -8,8 +8,8 @@ impInit: 234
 
 Print all i64
 exported i64: undefined
-basic: 0x0000422000800040
-mutable: 0x0000000000000000
+basic: 0x422000800040
+mutable: 0x0
 
 Print all f32
 exported f32: -54.869998931884766
@@ -38,7 +38,7 @@ impInit: 234
 
 Print all i64
 exported i64: undefined
-basic: 0x0000422000800040
+basic: 0x422000800040
 mutable: 0xfff2d5f870000000
 
 Print all f32

+ 3 - 3
test/wasm/baselines/table_imports.baseline

@@ -1,7 +1,7 @@
 3
 custom add (+5.42)
 8
-0x0000000000000003
+0x3
 3
 custom add (+5.42)
 8.420000076293945
@@ -13,8 +13,8 @@ custom add (+5.42)
  Rerun tests with new instance using previous module's imports
 3
 3
-0x0000000000000003
-0x0000000000000003
+0x3
+0x3
 3
 3
 3

+ 23 - 23
test/wasm/baselines/unsigned.baseline

@@ -1,23 +1,23 @@
-0: Running arguments tests for i32.lt_u. Module #1
-1: Running arguments tests for i32.gt_u. Module #149
-2: Running arguments tests for i32.le_u. Module #297
-3: Running arguments tests for i32.ge_u. Module #445
-4: Running arguments tests for i64.lt_u. Module #593
-5: Running arguments tests for i64.gt_u. Module #837
-6: Running arguments tests for i64.le_u. Module #1081
-7: Running arguments tests for i64.ge_u. Module #1325
-8: Running arguments tests for i32.div_u. Module #1569
-9: Running arguments tests for i32.rem_u. Module #1717
-10: Running arguments tests for i32.shr_u. Module #1865
-11: Running arguments tests for i64.div_u. Module #2013
-12: Running arguments tests for i64.rem_u. Module #2257
-13: Running arguments tests for i64.shr_u. Module #2501
-14: Running arguments tests for i32.trunc_u/f32. Module #2745
-15: Running arguments tests for i32.trunc_u/f64. Module #2753
-16: Running arguments tests for i64.extend_u/i32. Module #2761
-17: Running arguments tests for i64.trunc_u/f32. Module #2769
-18: Running arguments tests for i64.trunc_u/f64. Module #2777
-19: Running arguments tests for f32.convert_u/i32. Module #2785
-20: Running arguments tests for f32.convert_u/i64. Module #2793
-21: Running arguments tests for f64.convert_u/i32. Module #2803
-22: Running arguments tests for f64.convert_u/i64. Module #2811
+0: Running arguments tests for i32.lt_u. Module #1
+1: Running arguments tests for i32.gt_u. Module #149
+2: Running arguments tests for i32.le_u. Module #297
+3: Running arguments tests for i32.ge_u. Module #445
+4: Running arguments tests for i64.lt_u. Module #593
+5: Running arguments tests for i64.gt_u. Module #837
+6: Running arguments tests for i64.le_u. Module #1081
+7: Running arguments tests for i64.ge_u. Module #1325
+8: Running arguments tests for i32.div_u. Module #1569
+9: Running arguments tests for i32.rem_u. Module #1717
+10: Running arguments tests for i32.shr_u. Module #1865
+11: Running arguments tests for i64.div_u. Module #2013
+12: Running arguments tests for i64.rem_u. Module #2257
+13: Running arguments tests for i64.shr_u. Module #2501
+14: Running arguments tests for i32.trunc_u/f32. Module #2745
+15: Running arguments tests for i32.trunc_u/f64. Module #2753
+16: Running arguments tests for i64.extend_u/i32. Module #2761
+17: Running arguments tests for i64.trunc_u/f32. Module #2769
+18: Running arguments tests for i64.trunc_u/f64. Module #2777
+19: Running arguments tests for f32.convert_u/i32. Module #2785
+20: Running arguments tests for f32.convert_u/i64. Module #2793
+21: Running arguments tests for f64.convert_u/i32. Module #2803
+22: Running arguments tests for f64.convert_u/i64. Module #2811

+ 143 - 0
test/wasm/i64.js

@@ -0,0 +1,143 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+/* global assert,testRunner */ // eslint rule
+WScript.LoadScriptFile("../UnitTestFrameWork/UnitTestFrameWork.js");
+WScript.LoadScriptFile("wasmutils.js");
+WScript.LoadScriptFile("../wasmspec/testsuite/harness/wasm-constants.js");
+WScript.LoadScriptFile("../wasmspec/testsuite/harness/wasm-module-builder.js");
+WScript.Flag("-wasmI64");
+
+const comparisonOperators = [
+  {name: "i64.eqz", op: kExprI64Eqz, arity: 1, check({high, low}) {return high === 0 && low === 0;}},
+  {name: "i64.eq", op: kExprI64Eq, arity: 2, check(a, b) {return a.high === b.high && a.low === b.low;}},
+  {name: "i64.ne", op: kExprI64Ne, arity: 2, check(a, b) {return a.high !== b.high || a.low !== b.low;}},
+  {name: "i64.lt_s", op: kExprI64LtS, arity: 2, check(a, b) {
+    if (a.high !== b.high) {
+      return a.high < b.high;
+    }
+    return (a.low>>>0) < (b.low>>>0);
+  }},
+  {name: "i64.lt_u", op: kExprI64LtU, arity: 2, check(a, b) {
+    if (a.high !== b.high) {
+      return (a.high>>>0) < (b.high>>>0);
+    }
+    return (a.low>>>0) < (b.low>>>0);
+  }},
+  {name: "i64.gt_s", op: kExprI64GtS, arity: 2, check(a, b) {
+    if (a.high !== b.high) {
+      return a.high > b.high;
+    }
+    return (a.low>>>0) > (b.low>>>0);
+  }},
+  {name: "i64.gt_u", op: kExprI64GtU, arity: 2, check(a, b) {
+    if (a.high !== b.high) {
+      return (a.high>>>0) > (b.high>>>0);
+    }
+    return (a.low>>>0) > (b.low>>>0);
+  }},
+  {name: "i64.le_s", op: kExprI64LeS, arity: 2, check(a, b) {
+    if (a.high !== b.high) {
+      return a.high < b.high;
+    }
+    return (a.low>>>0) <= (b.low>>>0);
+  }},
+  {name: "i64.le_u", op: kExprI64LeU, arity: 2, check(a, b) {
+    if (a.high !== b.high) {
+      return (a.high>>>0) < (b.high>>>0);
+    }
+    return (a.low>>>0) <= (b.low>>>0);
+  }},
+  {name: "i64.ge_s", op: kExprI64GeS, arity: 2, check(a, b) {
+    if (a.high !== b.high) {
+      return a.high > b.high;
+    }
+    return (a.low>>>0) >= (b.low>>>0);
+  }},
+  {name: "i64.ge_u", op: kExprI64GeU, arity: 2, check(a, b) {
+    if (a.high !== b.high) {
+      return (a.high>>>0) > (b.high>>>0);
+    }
+    return (a.low>>>0) >= (b.low>>>0);
+  }},
+];
+function makeFunction(builder, name, op, type, arity) {
+  const params = [];
+  const body = [];
+  for (let i = 0; i < arity; ++i) {
+    params.push(type);
+    body.push(kExprGetLocal, i);
+  }
+  body.push(op)
+  builder
+    .addFunction(name, makeSig(params, [kWasmI32]))
+    .addBody(body)
+    .exportFunc();
+}
+const I32values = [0, 1, 10, -1, -5, 5,
+                124, -1026, 98768, -88754,
+                1<<32, -(1<<32), (1<<32)-1, 1<<31, -(1<<31), 1<<25, -1<<25];
+
+const comparisonTests = comparisonOperators.map(({name, op, arity, check}) => ({
+  name: `test ${name}`,
+  body() {
+    const builder = new WasmModuleBuilder();
+    makeFunction(builder, "i64", op, kWasmI64, arity);
+    const {exports: {i64}} = builder.instantiate();
+    const tested = {};
+
+    for (let i = 0; i < I32values.length; ++i) {
+      const secondLoopIt = arity == 1 ? i : I32values.length;
+      for (let j = i; j < secondLoopIt; ++j) {
+        const v0 = I32values[i];
+        const v1 = I32values[j];
+
+        const test = (a, b, c, d) => {
+          const left = {high: a, low: b};
+          const right = {high: c, low: d};
+          const key = i64ToString(left) + i64ToString(right);
+          if (tested[key]) {
+            return;
+          }
+          tested[key] = true;
+          const i64Res = i64(left, right) === 1;
+          const checkRes = check(left, right);
+          const msg = `${name}(${i64ToString(left)}, ${i64ToString(right)})`;
+          if (argv.verbose > 1) {
+            console.log(`${msg} = ${i64Res}`);
+          }
+          assert.areEqual(checkRes, i64Res, msg);
+        };
+
+        // Try all possible combinations
+        for (let iShuffle = 0; iShuffle < (1 << 4); ++iShuffle) {
+          const a = (iShuffle & 1) ? v1 : v0;
+          const b = (iShuffle & 2) ? v1 : v0;
+          const c = (iShuffle & 4) ? v1 : v0;
+          const d = (iShuffle & 8) ? v1 : v0;
+          test(a, b, c, d);
+        }
+      }
+    }
+  }
+}))
+
+const tests = [
+  ...comparisonTests,
+];
+
+WScript.LoadScriptFile("../UnitTestFrameWork/yargs.js");
+const argv = yargsParse(WScript.Arguments, {
+  number: ["start", "end", "verbose"],
+  default: {
+    verbose: 1,
+    start: 0,
+    end: tests.length
+  }
+}).argv;
+
+const todoTests = tests.slice(argv.start, argv.end);
+
+testRunner.run(todoTests, {verbose: argv.verbose > 0});

+ 1 - 2
test/wasm/limits.js

@@ -291,8 +291,7 @@ const argv = yargsParse(WScript.Arguments, {
 
 const todoTests = tests
   .slice(argv.start, argv.end)
-  .filter(test => (!test.slow || argv.slow) &&
-                  (!test.invalidTest || argv.invalid) &&
+  .filter(test => (!test.invalidTest || argv.invalid) &&
                   (!test.validTest || argv.valid));
 
 testRunner.run(todoTests, {verbose: argv.verbose});

+ 10 - 9
test/wasm/math.js

@@ -3,6 +3,7 @@
 // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 //-------------------------------------------------------------------------------------------------------
 var {fixupI64Return} = WScript.LoadScriptFile("./wasmutils.js");
+WScript.Flag("-wasmI64");
 
 let passed = true;
 function check(expected, funName, ...args)
@@ -54,16 +55,16 @@ check("Division by zero","exports.i64_div_u", 5, 0);
 check("Division by zero","exports.i64_rem_s", 5, 0);
 check("Division by zero","exports.i64_rem_u", 5, 0);
 check("0xfffffffffffffffe","exports.i64_div_s", 5, -2);
-check("0x0000000000000002","exports.i64_div_u", 5, 2);
-check("0x0000000000000000","exports.i64_rem_s", 5, -1);
-check("0x000000000000000c","exports.i64_rem_u", -4, 16);
+check("0x2","exports.i64_div_u", 5, 2);
+check("0x0","exports.i64_rem_s", 5, -1);
+check("0xc","exports.i64_rem_u", -4, 16);
 
-check("0x0000000000000040", "exports.ctzI64", 0);
-check("0x0000000000000040", "exports.ctzI64", "0");
-check("0x0000000000000000", "exports.ctzI64", "1");
-check("0x000000000000001f", "exports.ctzI64", "" + -Math.pow(2,31));
-check("0x000000000000003a", "exports.ctzI64", "0x3400000000000000");
-check("0x000000000000003f", "exports.ctzI64", "-9223372036854775808");
+check("0x40", "exports.ctzI64", 0);
+check("0x40", "exports.ctzI64", "0");
+check("0x0", "exports.ctzI64", "1");
+check("0x1f", "exports.ctzI64", "" + -Math.pow(2,31));
+check("0x3a", "exports.ctzI64", "0x3400000000000000");
+check("0x3f", "exports.ctzI64", "-9223372036854775808");
 
 if(passed) {
   print("Passed");

+ 7 - 0
test/wasm/rlexe.xml

@@ -215,6 +215,13 @@
     <tags>exclude_jshost,exclude_win7,exclude_xplat</tags>
   </default>
 </test>
+<test>
+  <default>
+    <files>i64.js</files>
+    <compile-flags>-wasm -args --no-verbose -endargs</compile-flags>
+    <tags>exclude_xplat</tags>
+  </default>
+</test>
 <test>
   <default>
     <files>i64cf.js</files>

+ 20 - 3
test/wasm/wasmutils.js

@@ -3,9 +3,26 @@
 // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 //-------------------------------------------------------------------------------------------------------
 
-function i64ToString({high, low}) {
-  const convert = a => (a >>> 0).toString(16).padStart(8, "0");
-  return `0x${convert(high)}${convert(low)}`;
+function i64ToString(val, optHigh = 0) {
+  let high, low;
+  if (typeof val === "object") {
+    high = val.high;
+    low = val.low;
+  } else {
+    low = val;
+    high = optHigh;
+  }
+  const convert = (a, doPad) => {
+    let s = (a >>> 0).toString(16);
+    if (doPad) {
+      s = s.padStart(8, "0");
+    }
+    return s;
+  }
+  if (high !== 0) {
+    return `0x${convert(high)}${convert(low, true)}`;
+  }
+  return `0x${convert(low)}`;
 }
 
 function fixupI64Return(exports, fnNames) {