buildExtractTests.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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(2147483648, "exports.func_f32x4_1");
  99. check(2147483648, "exports.func_f32x4_2");
  100. check(-2147483648, "exports.func_f32x4_3");
  101. }
  102. function RunBool32x4Tests() {
  103. mod = new WebAssembly.Module(readbuffer('b32x4.wasm'));
  104. exports = new WebAssembly.Instance(mod, ffi).exports;
  105. check(false, "exports.func_b32x4_0");
  106. check(true, "exports.func_b32x4_1");
  107. check(true, "exports.func_b32x4_2");
  108. check(true, "exports.func_b32x4_3");
  109. }
  110. function RunBool16x8Tests() {
  111. mod = new WebAssembly.Module(readbuffer('b16x8.wasm'));
  112. exports = new WebAssembly.Instance(mod, ffi).exports;
  113. check(true, "exports.func_b16x8_0");
  114. check(false, "exports.func_b16x8_1");
  115. check(true, "exports.func_b16x8_2");
  116. check(true, "exports.func_b16x8_3");
  117. check(true, "exports.func_b16x8_4");
  118. check(true, "exports.func_b16x8_5");
  119. check(true, "exports.func_b16x8_6");
  120. check(true, "exports.func_b16x8_7");
  121. }
  122. function RunBool8x16Tests() {
  123. mod = new WebAssembly.Module(readbuffer('b8x16.wasm'));
  124. exports = new WebAssembly.Instance(mod, ffi).exports;
  125. check(true, "exports.func_b8x16_0");
  126. check(false, "exports.func_b8x16_1");
  127. check(true, "exports.func_b8x16_2");
  128. check(true, "exports.func_b8x16_3");
  129. check(true, "exports.func_b8x16_4");
  130. check(true, "exports.func_b8x16_5");
  131. check(true, "exports.func_b8x16_6");
  132. check(true, "exports.func_b8x16_7");
  133. check(true, "exports.func_b8x16_8");
  134. check(true, "exports.func_b8x16_9");
  135. check(true, "exports.func_b8x16_10");
  136. check(true, "exports.func_b8x16_11");
  137. check(true, "exports.func_b8x16_12");
  138. check(true, "exports.func_b8x16_13");
  139. check(true, "exports.func_b8x16_14");
  140. check(true, "exports.func_b8x16_15");
  141. }
  142. //Tests
  143. RunInt324Tests();
  144. RunInt16x8UnsignedTests();
  145. RunInt16x8SignedTests();
  146. RunInt8x16UnsignedTests();
  147. RunInt8x16SignedTests();
  148. RunFloat32x4Tests();
  149. RunBool32x4Tests();
  150. RunBool16x8Tests();
  151. RunBool8x16Tests();
  152. if(passed) {
  153. print("Passed");
  154. }