buildExtractTests.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. let passed = true;
  6. function check(expected, funName, ...args)
  7. {
  8. let fun = eval(funName);
  9. let result;
  10. try {
  11. result = fun(...args);
  12. } catch (e) {
  13. result = e.message;
  14. }
  15. if(result != expected) {
  16. passed = false;
  17. print(`${funName}(${[...args]}) produced ${result}, expected ${expected}`);
  18. }
  19. }
  20. let ffi = {};
  21. let mod, exports;
  22. function RunInt324Tests() {
  23. mod = new WebAssembly.Module(readbuffer('i32x4.wasm'));
  24. exports = new WebAssembly.Instance(mod, ffi).exports;
  25. check(2147483647, "exports.func_i32x4_0");
  26. check(0, "exports.func_i32x4_1");
  27. check(-2147483648, "exports.func_i32x4_2");
  28. check(-100, "exports.func_i32x4_3");
  29. }
  30. function RunInt16x8UnsignedTests() {
  31. mod = new WebAssembly.Module(readbuffer('i16x8_u.wasm'));
  32. exports = new WebAssembly.Instance(mod, ffi).exports;
  33. check(1, "exports.func_i16x8_u_0");
  34. check(2, "exports.func_i16x8_u_1");
  35. check(32768, "exports.func_i16x8_u_2");
  36. check(0, "exports.func_i16x8_u_3");
  37. check(32767, "exports.func_i16x8_u_4");
  38. check(6, "exports.func_i16x8_u_5");
  39. check(65535, "exports.func_i16x8_u_6");
  40. check(65526, "exports.func_i16x8_u_7");
  41. }
  42. function RunInt16x8SignedTests() {
  43. mod = new WebAssembly.Module(readbuffer('i16x8_s.wasm'));
  44. exports = new WebAssembly.Instance(mod, ffi).exports;
  45. check(1, "exports.func_i16x8_s_0");
  46. check(2, "exports.func_i16x8_s_1");
  47. check(-32768, "exports.func_i16x8_s_2");
  48. check(0, "exports.func_i16x8_s_3");
  49. check(32767, "exports.func_i16x8_s_4");
  50. check(6, "exports.func_i16x8_s_5");
  51. check(7, "exports.func_i16x8_s_6");
  52. check(-10, "exports.func_i16x8_s_7");
  53. }
  54. function RunInt8x16UnsignedTests() {
  55. mod = new WebAssembly.Module(readbuffer('i8x16_u.wasm'));
  56. exports = new WebAssembly.Instance(mod, ffi).exports;
  57. check(1, "exports.func_i8x16_u_0");
  58. check(2, "exports.func_i8x16_u_1");
  59. check(128, "exports.func_i8x16_u_2");
  60. check(4, "exports.func_i8x16_u_3");
  61. check(127, "exports.func_i8x16_u_4");
  62. check(6, "exports.func_i8x16_u_5");
  63. check(7, "exports.func_i8x16_u_6");
  64. check(8, "exports.func_i8x16_u_7");
  65. check(9, "exports.func_i8x16_u_8");
  66. check(255, "exports.func_i8x16_u_9");
  67. check(11, "exports.func_i8x16_u_10");
  68. check(12, "exports.func_i8x16_u_11");
  69. check(13, "exports.func_i8x16_u_12");
  70. check(14, "exports.func_i8x16_u_13");
  71. check(15, "exports.func_i8x16_u_14");
  72. check(236, "exports.func_i8x16_u_15");
  73. }
  74. function RunInt8x16SignedTests() {
  75. mod = new WebAssembly.Module(readbuffer('i8x16_s.wasm'));
  76. exports = new WebAssembly.Instance(mod, ffi).exports;
  77. check(1, "exports.func_i8x16_s_0");
  78. check(2, "exports.func_i8x16_s_1");
  79. check(-128, "exports.func_i8x16_s_2");
  80. check(4, "exports.func_i8x16_s_3");
  81. check(127, "exports.func_i8x16_s_4");
  82. check(6, "exports.func_i8x16_s_5");
  83. check(7, "exports.func_i8x16_s_6");
  84. check(8, "exports.func_i8x16_s_7");
  85. check(9, "exports.func_i8x16_s_8");
  86. check(10, "exports.func_i8x16_s_9");
  87. check(11, "exports.func_i8x16_s_10");
  88. check(12, "exports.func_i8x16_s_11");
  89. check(13, "exports.func_i8x16_s_12");
  90. check(14, "exports.func_i8x16_s_13");
  91. check(15, "exports.func_i8x16_s_14");
  92. check(-20, "exports.func_i8x16_s_15");
  93. }
  94. function RunFloat32x4Tests() {
  95. mod = new WebAssembly.Module(readbuffer('f32x4.wasm'));
  96. exports = new WebAssembly.Instance(mod, ffi).exports;
  97. check(1.0, "exports.func_f32x4_0");
  98. check(3.4028234663852886e+38, "exports.func_f32x4_1");
  99. check(2147483648, "exports.func_f32x4_2");
  100. check(-2147483648, "exports.func_f32x4_3");
  101. }
  102. //Tests
  103. RunInt324Tests();
  104. RunInt16x8UnsignedTests();
  105. RunInt16x8SignedTests();
  106. RunInt8x16UnsignedTests();
  107. RunInt8x16SignedTests();
  108. RunFloat32x4Tests();
  109. if(passed) {
  110. print("Passed");
  111. }