OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-wasm --expose-gc --stress-compaction | 5 // Flags: --expose-wasm --expose-gc --stress-compaction |
6 | 6 |
7 load("test/mjsunit/wasm/wasm-constants.js"); | 7 load("test/mjsunit/wasm/wasm-constants.js"); |
8 load("test/mjsunit/wasm/wasm-module-builder.js"); | 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
9 | 9 |
10 var kPageSize = 0x10000; | 10 var kPageSize = 0x10000; |
11 | 11 |
12 function genGrowMemoryBuilder() { | 12 function genGrowMemoryBuilder() { |
13 var builder = new WasmModuleBuilder(); | 13 var builder = new WasmModuleBuilder(); |
14 builder.addFunction("grow_memory", kSig_i_i) | 14 builder.addFunction("grow_memory", kSig_i_i) |
15 .addBody([kExprGetLocal, 0, kExprGrowMemory]) | 15 .addBody([kExprGetLocal, 0, kExprGrowMemory]) |
16 .exportFunc(); | 16 .exportFunc(); |
17 builder.addFunction("load", kSig_i_i) | 17 builder.addFunction("load", kSig_i_i) |
18 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) | 18 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) |
19 .exportFunc(); | 19 .exportFunc(); |
20 builder.addFunction("store", kSig_i_ii) | 20 builder.addFunction("store", kSig_i_ii) |
21 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem, 0, 0, | 21 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem, 0, 0]) |
22 kExprGetLocal, 1]) | |
23 .exportFunc(); | 22 .exportFunc(); |
24 builder.addFunction("load16", kSig_i_i) | 23 builder.addFunction("load16", kSig_i_i) |
25 .addBody([kExprGetLocal, 0, kExprI32LoadMem16U, 0, 0]) | 24 .addBody([kExprGetLocal, 0, kExprI32LoadMem16U, 0, 0]) |
26 .exportFunc(); | 25 .exportFunc(); |
27 builder.addFunction("store16", kSig_i_ii) | 26 builder.addFunction("store16", kSig_i_ii) |
28 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem16, 0, 0, | 27 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem16, 0, 0]) |
29 kExprGetLocal, 1]) | |
30 .exportFunc(); | 28 .exportFunc(); |
31 builder.addFunction("load8", kSig_i_i) | 29 builder.addFunction("load8", kSig_i_i) |
32 .addBody([kExprGetLocal, 0, kExprI32LoadMem8U, 0, 0]) | 30 .addBody([kExprGetLocal, 0, kExprI32LoadMem8U, 0, 0]) |
33 .exportFunc(); | 31 .exportFunc(); |
34 builder.addFunction("store8", kSig_i_ii) | 32 builder.addFunction("store8", kSig_i_ii) |
35 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem8, 0, 0, | 33 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem8, 0, 0]) |
36 kExprGetLocal, 1]) | |
37 .exportFunc(); | 34 .exportFunc(); |
38 return builder; | 35 return builder; |
39 } | 36 } |
40 | 37 |
41 function testGrowMemoryReadWrite32() { | 38 function testGrowMemoryReadWrite32() { |
42 var builder = genGrowMemoryBuilder(); | 39 var builder = genGrowMemoryBuilder(); |
43 builder.addMemory(1, 1, false); | 40 builder.addMemory(1, 1, false); |
44 var module = builder.instantiate(); | 41 var module = builder.instantiate(); |
45 var offset; | 42 var offset; |
46 function peek() { return module.exports.load(offset); } | 43 function peek() { return module.exports.load(offset); } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 237 |
241 function testGrowMemoryCurrentMemory() { | 238 function testGrowMemoryCurrentMemory() { |
242 var builder = genGrowMemoryBuilder(); | 239 var builder = genGrowMemoryBuilder(); |
243 builder.addMemory(1, 1, false); | 240 builder.addMemory(1, 1, false); |
244 builder.addFunction("memory_size", kSig_i_v) | 241 builder.addFunction("memory_size", kSig_i_v) |
245 .addBody([kExprMemorySize]) | 242 .addBody([kExprMemorySize]) |
246 .exportFunc(); | 243 .exportFunc(); |
247 var module = builder.instantiate(); | 244 var module = builder.instantiate(); |
248 function growMem(pages) { return module.exports.grow_memory(pages); } | 245 function growMem(pages) { return module.exports.grow_memory(pages); } |
249 function MemSize() { return module.exports.memory_size(); } | 246 function MemSize() { return module.exports.memory_size(); } |
250 assertEquals(1, MemSize()); | 247 assertEquals(65536, MemSize()); |
251 assertEquals(1, growMem(1)); | 248 assertEquals(1, growMem(1)); |
252 assertEquals(2, MemSize()); | 249 assertEquals(131072, MemSize()); |
253 } | 250 } |
254 | 251 |
255 testGrowMemoryCurrentMemory(); | 252 testGrowMemoryCurrentMemory(); |
256 | 253 |
257 function testGrowMemoryPreservesDataMemOp32() { | 254 function testGrowMemoryPreservesDataMemOp32() { |
258 var builder = genGrowMemoryBuilder(); | 255 var builder = genGrowMemoryBuilder(); |
259 builder.addMemory(1, 1, false); | 256 builder.addMemory(1, 1, false); |
260 var module = builder.instantiate(); | 257 var module = builder.instantiate(); |
261 var offset, val; | 258 var offset, val; |
262 function peek() { return module.exports.load(offset); } | 259 function peek() { return module.exports.load(offset); } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 316 |
320 val = 0; | 317 val = 0; |
321 | 318 |
322 for(offset = 0; offset <= (kPageSize - 1); offset++, val++) { | 319 for(offset = 0; offset <= (kPageSize - 1); offset++, val++) { |
323 assertEquals(val, peek()); | 320 assertEquals(val, peek()); |
324 if (val == 255) val = 0; | 321 if (val == 255) val = 0; |
325 } | 322 } |
326 } | 323 } |
327 | 324 |
328 testGrowMemoryPreservesDataMemOp8(); | 325 testGrowMemoryPreservesDataMemOp8(); |
OLD | NEW |