regress.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. WScript.LoadScriptFile("../UnitTestFramework/UnitTestFramework.js");
  6. WScript.LoadScriptFile("../WasmSpec/testsuite/harness/wasm-constants.js");
  7. WScript.LoadScriptFile("../WasmSpec/testsuite/harness/wasm-module-builder.js");
  8. const tests = [{
  9. name: "polymorphic operators regression",
  10. usesWabt: true,
  11. body() {
  12. const toValidate = {
  13. "stack-polymorphic-yield": `
  14. (module
  15. (func (result i32)
  16. (block (result i32)
  17. (loop (br 0))
  18. unreachable
  19. drop
  20. )
  21. )
  22. )`,
  23. "stack-polymorphic-br_table": `
  24. (module
  25. (func (result i32)
  26. (block (result i32)
  27. unreachable
  28. drop
  29. (br_table 0 0)
  30. )
  31. )
  32. )`,
  33. "stack-polymorphic-br": `
  34. (module
  35. (func (result i32)
  36. unreachable
  37. drop
  38. br 0
  39. )
  40. )`,
  41. "stack-polymorphic-return": `
  42. (module
  43. (func (result i32)
  44. unreachable
  45. drop
  46. return
  47. )
  48. )`,
  49. };
  50. for (const key in toValidate) {
  51. assert.isTrue(WebAssembly.validate(WebAssembly.wabt.convertWast2Wasm(toValidate[key])), `Module ${key} should be valid`);
  52. }
  53. }
  54. }, {
  55. name: "tracing regression test",
  56. usesWabt: false,
  57. body() {
  58. const tracingPrefix = 0xf0;
  59. const builder = new WasmModuleBuilder();
  60. const typeIndex = builder.addType(kSig_v_v);
  61. builder.addFunction("foo", typeIndex).addBody([
  62. tracingPrefix, 0x0,
  63. ]).exportFunc();
  64. try {
  65. const {exports: {foo}} = new WebAssembly.Instance(new WebAssembly.Module(builder.toBuffer()));
  66. foo();
  67. assert.fail("Failed: Tracing prefix should not be accepted");
  68. } catch (e) {
  69. if (!e.message.includes("Tracing opcodes not allowed")) {
  70. assert.fail("Wrong error: " + e);
  71. }
  72. }
  73. }
  74. }, {
  75. name: "Error message truncation test",
  76. usesWabt: false,
  77. body() {
  78. const tracingPrefix = 0xf0;
  79. const builder = new WasmModuleBuilder();
  80. const typeIndex = builder.addType(kSig_v_v);
  81. const exportedName = Array(5000).fill("").map((_, i) => i.toString()).join("");
  82. builder.addFunction(exportedName, typeIndex).addBody([
  83. // Use the same body as the test above to trigger an exception
  84. tracingPrefix, 0x0,
  85. ]).exportFunc();
  86. try {
  87. const {exports} = new WebAssembly.Instance(new WebAssembly.Module(builder.toBuffer()));
  88. exports[exportedName]();
  89. assert.fail("Failed: Compilation error expected");
  90. } catch (e) {
  91. // Make sure all platforms correctly truncate the error message to the expected length
  92. const marker = "function ";
  93. const index = e.message.indexOf(marker);
  94. assert.isTrue(index !== -1);
  95. assert.isTrue(e.message.length - index === 2047);
  96. const sub = e.message.substring(index + marker.length, e.message.length);
  97. const funcNameLengthUsed = 2047 - marker.length;
  98. const funcNameUsed = exportedName.substring(0, funcNameLengthUsed);
  99. assert.areEqual(funcNameUsed, sub, "Error message truncation unexpected result");
  100. }
  101. }
  102. }];
  103. WScript.LoadScriptFile("../UnitTestFramework/yargs.js");
  104. const argv = yargsParse(WScript.Arguments, {
  105. boolean: ["verbose", "wabt"],
  106. number: ["start", "end"],
  107. default: {
  108. verbose: true,
  109. wabt: true,
  110. start: 0,
  111. end: tests.length
  112. }
  113. }).argv;
  114. let todoTests = tests
  115. .slice(argv.start, argv.end);
  116. if (!argv.wabt) {
  117. todoTests = todoTests.filter(t => !t.usesWabt);
  118. }
  119. testRunner.run(todoTests, {verbose: argv.verbose});