Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(702)

Side by Side Diff: test/mjsunit/wasm/grow-memory.js

Issue 2216443002: [wasm] Grow memory should return -1 on failure. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Review comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | test/mjsunit/wasm/wasm-constants.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
(...skipping 16 matching lines...) Expand all
27 var builder = genGrowMemoryBuilder(); 27 var builder = genGrowMemoryBuilder();
28 builder.addMemory(1, 1, false); 28 builder.addMemory(1, 1, false);
29 var module = builder.instantiate(); 29 var module = builder.instantiate();
30 var offset; 30 var offset;
31 function peek() { return module.exports.load(offset); } 31 function peek() { return module.exports.load(offset); }
32 function poke(value) { return module.exports.store(offset, value); } 32 function poke(value) { return module.exports.store(offset, value); }
33 function growMem(pages) { return module.exports.grow_memory(pages); } 33 function growMem(pages) { return module.exports.grow_memory(pages); }
34 34
35 for(offset = 0; offset <= (kPageSize - 4); offset++) { 35 for(offset = 0; offset <= (kPageSize - 4); offset++) {
36 poke(20); 36 poke(20);
37 assertEquals(peek(), 20); 37 assertEquals(20, peek());
38 } 38 }
39 for (offset = kPageSize - 3; offset < kPageSize + 4; offset++) { 39 for (offset = kPageSize - 3; offset < kPageSize + 4; offset++) {
40 assertTraps(kTrapMemOutOfBounds, poke); 40 assertTraps(kTrapMemOutOfBounds, poke);
41 assertTraps(kTrapMemOutOfBounds, peek); 41 assertTraps(kTrapMemOutOfBounds, peek);
42 } 42 }
43 43
44 try { 44 assertEquals(1, growMem(3));
45 assertEquals(growMem(3), 1);
46 } catch (e) {
47 assertEquals("object", typeof e);
48 assertEquals(e.message, kTrapMsgs[kTrapMemAllocationFail]);
49 return;
50 }
51 45
52 for (offset = kPageSize; offset <= 4*kPageSize -4; offset++) { 46 for (offset = kPageSize; offset <= 4*kPageSize -4; offset++) {
53 poke(20); 47 poke(20);
54 assertEquals(peek(), 20); 48 assertEquals(20, peek());
55 } 49 }
56 for (offset = 4*kPageSize - 3; offset < 4*kPageSize + 4; offset++) { 50 for (offset = 4*kPageSize - 3; offset < 4*kPageSize + 4; offset++) {
57 assertTraps(kTrapMemOutOfBounds, poke); 51 assertTraps(kTrapMemOutOfBounds, poke);
58 assertTraps(kTrapMemOutOfBounds, peek); 52 assertTraps(kTrapMemOutOfBounds, peek);
59 } 53 }
60 54
61 try { 55 assertEquals(4, growMem(15));
62 assertEquals(growMem(15), 4);
63 } catch (e) {
64 assertEquals("object", typeof e);
65 assertEquals(e.message, kTrapMsgs[kTrapMemAllocationFail]);
66 return;
67 }
68 56
69 for (offset = 4*kPageSize - 3; offset <= 4*kPageSize + 4; offset++) { 57 for (offset = 4*kPageSize - 3; offset <= 4*kPageSize + 4; offset++) {
70 poke(20); 58 poke(20);
71 assertEquals(peek(), 20); 59 assertEquals(20, peek());
72 } 60 }
73 for (offset = 19*kPageSize - 10; offset <= 19*kPageSize - 4; offset++) { 61 for (offset = 19*kPageSize - 10; offset <= 19*kPageSize - 4; offset++) {
74 poke(20); 62 poke(20);
75 assertEquals(peek(), 20); 63 assertEquals(20, peek());
76 } 64 }
77 for (offset = 19*kPageSize - 3; offset < 19*kPageSize + 5; offset++) { 65 for (offset = 19*kPageSize - 3; offset < 19*kPageSize + 5; offset++) {
78 assertTraps(kTrapMemOutOfBounds, poke); 66 assertTraps(kTrapMemOutOfBounds, poke);
79 assertTraps(kTrapMemOutOfBounds, peek); 67 assertTraps(kTrapMemOutOfBounds, peek);
80 } 68 }
81 } 69 }
82 70
83 testGrowMemoryReadWrite(); 71 testGrowMemoryReadWrite();
84 72
85 function testGrowMemoryZeroInitialSize() { 73 function testGrowMemoryZeroInitialSize() {
86 var builder = genGrowMemoryBuilder(); 74 var builder = genGrowMemoryBuilder();
87 var module = builder.instantiate(); 75 var module = builder.instantiate();
88 var offset; 76 var offset;
89 function peek() { return module.exports.load(offset); } 77 function peek() { return module.exports.load(offset); }
90 function poke(value) { return module.exports.store(offset, value); } 78 function poke(value) { return module.exports.store(offset, value); }
91 function growMem(pages) { return module.exports.grow_memory(pages); } 79 function growMem(pages) { return module.exports.grow_memory(pages); }
92 80
93 assertTraps(kTrapMemOutOfBounds, peek); 81 assertTraps(kTrapMemOutOfBounds, peek);
94 assertTraps(kTrapMemOutOfBounds, poke); 82 assertTraps(kTrapMemOutOfBounds, poke);
95 83
96 try { 84 assertEquals(0, growMem(1));
97 assertEquals(growMem(1), 0);
98 } catch (e) {
99 assertEquals("object", typeof e);
100 assertEquals(e.message, kTrapMsgs[kTrapMemAllocationFail]);
101 return;
102 }
103 85
104 for(offset = 0; offset <= kPageSize - 4; offset++) { 86 for(offset = 0; offset <= kPageSize - 4; offset++) {
105 poke(20); 87 poke(20);
106 assertEquals(peek(), 20); 88 assertEquals(20, peek());
107 } 89 }
108 90
109 //TODO(gdeepti): Fix tests with correct write boundaries 91 //TODO(gdeepti): Fix tests with correct write boundaries
110 //when runtime function is fixed. 92 //when runtime function is fixed.
111 for(offset = kPageSize; offset <= kPageSize + 5; offset++) { 93 for(offset = kPageSize; offset <= kPageSize + 5; offset++) {
112 assertTraps(kTrapMemOutOfBounds, peek); 94 assertTraps(kTrapMemOutOfBounds, peek);
113 } 95 }
114 } 96 }
115 97
116 testGrowMemoryZeroInitialSize(); 98 testGrowMemoryZeroInitialSize();
117 99
118 function testGrowMemoryTrapMaxPagesZeroInitialMemory() { 100 function testGrowMemoryTrapMaxPagesZeroInitialMemory() {
119 var builder = genGrowMemoryBuilder(); 101 var builder = genGrowMemoryBuilder();
120 var module = builder.instantiate(); 102 var module = builder.instantiate();
121 var maxPages = 16385; 103 var maxPages = 16385;
122 function growMem() { return module.exports.grow_memory(maxPages); } 104 function growMem(pages) { return module.exports.grow_memory(pages); }
123 assertTraps(kTrapMemOutOfBounds, growMem); 105 assertEquals(-1, growMem(maxPages));
124 } 106 }
125 107
126 testGrowMemoryTrapMaxPagesZeroInitialMemory(); 108 testGrowMemoryTrapMaxPagesZeroInitialMemory();
127 109
128 function testGrowMemoryTrapMaxPages() { 110 function testGrowMemoryTrapMaxPages() {
129 var builder = genGrowMemoryBuilder(); 111 var builder = genGrowMemoryBuilder();
130 builder.addMemory(1, 1, false); 112 builder.addMemory(1, 1, false);
131 var module = builder.instantiate(); 113 var module = builder.instantiate();
132 var maxPages = 16384; 114 var maxPages = 16384;
133 function growMem() { return module.exports.grow_memory(maxPages); } 115 function growMem(pages) { return module.exports.grow_memory(pages); }
134 assertTraps(kTrapMemOutOfBounds, growMem); 116 assertEquals(-1, growMem(maxPages));
135 } 117 }
136 118
137 testGrowMemoryTrapMaxPages(); 119 testGrowMemoryTrapMaxPages();
OLDNEW
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | test/mjsunit/wasm/wasm-constants.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698