constTests.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 assertEquals(expected, actual) {
  7. if (expected != actual) {
  8. passed = false;
  9. throw `Expected ${expected}, received ${actual}`;
  10. }
  11. }
  12. const INITIAL_SIZE = 1;
  13. const memObj = new WebAssembly.Memory({initial:INITIAL_SIZE});
  14. const arr = new Uint32Array (memObj.buffer);
  15. const module = new WebAssembly.Module(readbuffer('const.wasm'));
  16. const instance = new WebAssembly.Instance(module, { "dummy" : { "memory" : memObj } }).exports;
  17. let testIntLogicalOps = function (funcname, resultArr) {
  18. const len = 4
  19. instance[funcname]();
  20. for (let i = 0; i < len; i++) {
  21. assertEquals(arr[i], resultArr[i]);
  22. }
  23. }
  24. testIntLogicalOps("m128_const_1", [0, 0xFF00ABCC, 0, 0]);
  25. testIntLogicalOps("m128_const_2", [0xA100BC00, 0xFFFFFFFF, 0xFF00, 0x1]);
  26. testIntLogicalOps("m128_const_3", [0xFFFFFFFF, 0xFFFFFFFF, 0, 0xFFFFFFFF]);
  27. testIntLogicalOps("m128_const_4", [0, 0, 0, 0]);
  28. if (passed) {
  29. print("Passed");
  30. }