1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
// Tests for JS library compile time helpers defined in parseTools.js
addToLibrary({
test_receiveI64ParamAsI53__deps: i53ConversionDeps,
test_receiveI64ParamAsI53: function({{{ defineI64Param('arg1') }}},
{{{ defineI64Param('arg2') }}}) {
out('\ntest_receiveI64ParamAsI53:');
{{{ receiveI64ParamAsI53('arg1', '-1') }}};
out('arg1: ' + arg1);
{{{ receiveI64ParamAsI53('arg2', '-2') }}};
out('arg2: ' + arg2);
return 0;
},
// receiveI64ParamAsDoulbe is a legacy function that is no longer
// used within emscripten, but we continue to test it in case
// there are external users.
test_receiveI64ParamAsDouble: function({{{ defineI64Param('arg1') }}},
{{{ defineI64Param('arg2') }}}) {
out('\ntest_receiveI64ParamAsDouble:');
{{{ receiveI64ParamAsDouble('arg1') }}};
out('arg1: ' + arg1);
{{{ receiveI64ParamAsDouble('arg2') }}};
out('arg2: ' + arg2);
return 0;
},
test_makeGetValue__deps: ['$readI53FromI64', '$readI53FromU64'],
test_makeGetValue: function(ptr) {
out('\ntest_makeGetValue:');
let val;
// i53
val = {{{ makeGetValue('ptr', '0', 'i53') }}};
out('i53: ' + val.toString(16))
assert(val == -0xaabb12345678);
// u53
// When interpreted as an unsigned value that bytes stored at in the linear
// memory represent a number outside of the i53 range so we get some
// rounding here.
// readI53FromU64 doesn't currently have any kind of range checkes, even in
// debug mode.
val = {{{ makeGetValue('ptr', '0', 'u53') }}};
out('u53: ' + val.toString(16))
assert(val == 0xffff5544edcba800);
// i32
val = {{{ makeGetValue('ptr', '0', 'i32') }}};
out('i32: ' + val.toString(16))
assert(val == -0x12345678);
// u32
val = {{{ makeGetValue('ptr', '0', 'u32') }}};
out('u32: ' + val.toString(16))
assert(val == 0xedcba988);
// unsigned i32 (legacy)
val = {{{ makeGetValue('ptr', '0', 'i32', undefined, /*unsigned=*/true) }}};
out('u32 legacy: ' + val.toString(16))
assert(val == 0xedcba988);
// i16
val = {{{ makeGetValue('ptr', '0', 'i16') }}};
out('i16: ' + val.toString(16))
assert(val == -0x5678);
// u16
val = {{{ makeGetValue('ptr', '0', 'u16') }}};
out('u16: ' + val.toString(16))
assert(val == 43400);
// unsigned i16 (legacy)
val = {{{ makeGetValue('ptr', '0', 'i16', undefined, /*unsigned=*/true) }}};
out('u16 legacy: ' + val.toString(16))
assert(val == 43400);
// i8
val = {{{ makeGetValue('ptr', '0', 'i8') }}};
out('i8: ' + val.toString(16))
assert(val == -0x78);
// u8
val = {{{ makeGetValue('ptr', '0', 'u8') }}};
out('u8: ' + val.toString(16))
assert(val == 0x88);
// unsigned i8 (legacy)
val = {{{ makeGetValue('ptr', '0', 'i8', undefined, /*unsigned=*/true) }}};
out('u8 legacy: ' + val.toString(16))
assert(val == 0x88);
// pointer
val = {{{ makeGetValue('ptr', '0', 'void*') }}};
out('ptr: ' + val.toString(16))
assert(val == 0xedcba988);
val = {{{ makeGetValue('ptr', '0', 'i32*') }}};
out('ptr: ' + val.toString(16))
assert(val == 0xedcba988);
},
test_makeSetValue__deps: ['$writeI53ToI64'],
test_makeSetValue: function(ptr) {
out('\ntest_makeSetValue:');
_clearI64(ptr);
{{{ makeSetValue('ptr', '0', 0x12345678AB, 'i64') }}};
_printI64(ptr);
// This value doesn't fit into i64. The current behaviour truncate (i.e.
// ignore the upper bits), in the same way that `BigInt64Array[X] = Y` does.
// (see splitI16 in parseTools.js)
_clearI64(ptr);
{{{ makeSetValue('ptr', '0', 0x1122334455667788AA, 'i64') }}};
_printI64(ptr);
_clearI64(ptr);
{{{ makeSetValue('ptr', '0', -0x1122334455667788AA, 'i64') }}};
_printI64(ptr);
_clearI64(ptr);
{{{ makeSetValue('ptr', '0', 0x12345678AB, 'i53') }}};
_printI64(ptr);
_clearI64(ptr);
{{{ makeSetValue('ptr', '0', -1, 'i53') }}};
_printI64(ptr);
_clearI64(ptr);
{{{ makeSetValue('ptr', '0', 0xff, 'i32') }}};
_printI64(ptr);
_clearI64(ptr);
{{{ makeSetValue('ptr', '0', 0x12345678ab, 'i32') }}};
_printI64(ptr);
},
});
|