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

Side by Side Diff: test/cctest/wasm/test-run-wasm-module.cc

Issue 2344143003: Moved zones and zone related stuff in its own directory. (Closed)
Patch Set: Merge branch 'master' into zonefolder Created 4 years, 3 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 | « test/cctest/wasm/test-run-wasm-64.cc ('k') | test/cctest/wasm/wasm-run-utils.h » ('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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include "src/wasm/encoder.h" 8 #include "src/wasm/encoder.h"
9 #include "src/wasm/module-decoder.h" 9 #include "src/wasm/module-decoder.h"
10 #include "src/wasm/wasm-macro-gen.h" 10 #include "src/wasm/wasm-macro-gen.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 void ExportAsMain(WasmFunctionBuilder* f) { 42 void ExportAsMain(WasmFunctionBuilder* f) {
43 static const char kMainName[] = "main"; 43 static const char kMainName[] = "main";
44 ExportAs(f, kMainName); 44 ExportAs(f, kMainName);
45 } 45 }
46 46
47 } // namespace 47 } // namespace
48 48
49 TEST(Run_WasmModule_Return114) { 49 TEST(Run_WasmModule_Return114) {
50 static const int32_t kReturnValue = 114; 50 static const int32_t kReturnValue = 114;
51 TestSignatures sigs; 51 TestSignatures sigs;
52 v8::base::AccountingAllocator allocator; 52 v8::internal::AccountingAllocator allocator;
53 Zone zone(&allocator); 53 Zone zone(&allocator);
54 54
55 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 55 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
56 uint16_t f_index = builder->AddFunction(); 56 uint16_t f_index = builder->AddFunction();
57 WasmFunctionBuilder* f = builder->FunctionAt(f_index); 57 WasmFunctionBuilder* f = builder->FunctionAt(f_index);
58 f->SetSignature(sigs.i_v()); 58 f->SetSignature(sigs.i_v());
59 ExportAsMain(f); 59 ExportAsMain(f);
60 byte code[] = {WASM_I8(kReturnValue)}; 60 byte code[] = {WASM_I8(kReturnValue)};
61 f->EmitCode(code, sizeof(code)); 61 f->EmitCode(code, sizeof(code));
62 TestModule(&zone, builder, kReturnValue); 62 TestModule(&zone, builder, kReturnValue);
63 } 63 }
64 64
65 TEST(Run_WasmModule_CallAdd) { 65 TEST(Run_WasmModule_CallAdd) {
66 v8::base::AccountingAllocator allocator; 66 v8::internal::AccountingAllocator allocator;
67 Zone zone(&allocator); 67 Zone zone(&allocator);
68 TestSignatures sigs; 68 TestSignatures sigs;
69 69
70 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 70 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
71 71
72 uint16_t f1_index = builder->AddFunction(); 72 uint16_t f1_index = builder->AddFunction();
73 WasmFunctionBuilder* f = builder->FunctionAt(f1_index); 73 WasmFunctionBuilder* f = builder->FunctionAt(f1_index);
74 f->SetSignature(sigs.i_ii()); 74 f->SetSignature(sigs.i_ii());
75 uint16_t param1 = 0; 75 uint16_t param1 = 0;
76 uint16_t param2 = 1; 76 uint16_t param2 = 1;
77 byte code1[] = {WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))}; 77 byte code1[] = {WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))};
78 f->EmitCode(code1, sizeof(code1)); 78 f->EmitCode(code1, sizeof(code1));
79 79
80 uint16_t f2_index = builder->AddFunction(); 80 uint16_t f2_index = builder->AddFunction();
81 f = builder->FunctionAt(f2_index); 81 f = builder->FunctionAt(f2_index);
82 f->SetSignature(sigs.i_v()); 82 f->SetSignature(sigs.i_v());
83 83
84 ExportAsMain(f); 84 ExportAsMain(f);
85 byte code2[] = {WASM_CALL_FUNCTION2(f1_index, WASM_I8(77), WASM_I8(22))}; 85 byte code2[] = {WASM_CALL_FUNCTION2(f1_index, WASM_I8(77), WASM_I8(22))};
86 f->EmitCode(code2, sizeof(code2)); 86 f->EmitCode(code2, sizeof(code2));
87 TestModule(&zone, builder, 99); 87 TestModule(&zone, builder, 99);
88 } 88 }
89 89
90 TEST(Run_WasmModule_ReadLoadedDataSegment) { 90 TEST(Run_WasmModule_ReadLoadedDataSegment) {
91 static const byte kDataSegmentDest0 = 12; 91 static const byte kDataSegmentDest0 = 12;
92 v8::base::AccountingAllocator allocator; 92 v8::internal::AccountingAllocator allocator;
93 Zone zone(&allocator); 93 Zone zone(&allocator);
94 TestSignatures sigs; 94 TestSignatures sigs;
95 95
96 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 96 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
97 uint16_t f_index = builder->AddFunction(); 97 uint16_t f_index = builder->AddFunction();
98 WasmFunctionBuilder* f = builder->FunctionAt(f_index); 98 WasmFunctionBuilder* f = builder->FunctionAt(f_index);
99 f->SetSignature(sigs.i_v()); 99 f->SetSignature(sigs.i_v());
100 100
101 ExportAsMain(f); 101 ExportAsMain(f);
102 byte code[] = { 102 byte code[] = {
103 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kDataSegmentDest0))}; 103 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kDataSegmentDest0))};
104 f->EmitCode(code, sizeof(code)); 104 f->EmitCode(code, sizeof(code));
105 byte data[] = {0xaa, 0xbb, 0xcc, 0xdd}; 105 byte data[] = {0xaa, 0xbb, 0xcc, 0xdd};
106 builder->AddDataSegment(new (&zone) WasmDataSegmentEncoder( 106 builder->AddDataSegment(new (&zone) WasmDataSegmentEncoder(
107 &zone, data, sizeof(data), kDataSegmentDest0)); 107 &zone, data, sizeof(data), kDataSegmentDest0));
108 TestModule(&zone, builder, 0xddccbbaa); 108 TestModule(&zone, builder, 0xddccbbaa);
109 } 109 }
110 110
111 TEST(Run_WasmModule_CheckMemoryIsZero) { 111 TEST(Run_WasmModule_CheckMemoryIsZero) {
112 static const int kCheckSize = 16 * 1024; 112 static const int kCheckSize = 16 * 1024;
113 v8::base::AccountingAllocator allocator; 113 v8::internal::AccountingAllocator allocator;
114 Zone zone(&allocator); 114 Zone zone(&allocator);
115 TestSignatures sigs; 115 TestSignatures sigs;
116 116
117 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 117 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
118 uint16_t f_index = builder->AddFunction(); 118 uint16_t f_index = builder->AddFunction();
119 WasmFunctionBuilder* f = builder->FunctionAt(f_index); 119 WasmFunctionBuilder* f = builder->FunctionAt(f_index);
120 f->SetSignature(sigs.i_v()); 120 f->SetSignature(sigs.i_v());
121 121
122 uint16_t localIndex = f->AddLocal(kAstI32); 122 uint16_t localIndex = f->AddLocal(kAstI32);
123 ExportAsMain(f); 123 ExportAsMain(f);
124 byte code[] = {WASM_BLOCK( 124 byte code[] = {WASM_BLOCK(
125 WASM_WHILE( 125 WASM_WHILE(
126 WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)), 126 WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)),
127 WASM_IF_ELSE( 127 WASM_IF_ELSE(
128 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)), 128 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)),
129 WASM_BRV(2, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))), 129 WASM_BRV(2, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))),
130 WASM_I8(11))}; 130 WASM_I8(11))};
131 f->EmitCode(code, sizeof(code)); 131 f->EmitCode(code, sizeof(code));
132 TestModule(&zone, builder, 11); 132 TestModule(&zone, builder, 11);
133 } 133 }
134 134
135 TEST(Run_WasmModule_CallMain_recursive) { 135 TEST(Run_WasmModule_CallMain_recursive) {
136 v8::base::AccountingAllocator allocator; 136 v8::internal::AccountingAllocator allocator;
137 Zone zone(&allocator); 137 Zone zone(&allocator);
138 TestSignatures sigs; 138 TestSignatures sigs;
139 139
140 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 140 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
141 uint16_t f_index = builder->AddFunction(); 141 uint16_t f_index = builder->AddFunction();
142 WasmFunctionBuilder* f = builder->FunctionAt(f_index); 142 WasmFunctionBuilder* f = builder->FunctionAt(f_index);
143 f->SetSignature(sigs.i_v()); 143 f->SetSignature(sigs.i_v());
144 144
145 uint16_t localIndex = f->AddLocal(kAstI32); 145 uint16_t localIndex = f->AddLocal(kAstI32);
146 ExportAsMain(f); 146 ExportAsMain(f);
147 byte code[] = {WASM_BLOCK( 147 byte code[] = {WASM_BLOCK(
148 WASM_SET_LOCAL(localIndex, 148 WASM_SET_LOCAL(localIndex,
149 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), 149 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
150 WASM_IF_ELSE(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I8(5)), 150 WASM_IF_ELSE(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I8(5)),
151 WASM_BLOCK(WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, 151 WASM_BLOCK(WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO,
152 WASM_INC_LOCAL(localIndex)), 152 WASM_INC_LOCAL(localIndex)),
153 WASM_BRV(1, WASM_CALL_FUNCTION0(0))), 153 WASM_BRV(1, WASM_CALL_FUNCTION0(0))),
154 WASM_BRV(0, WASM_I8(55))))}; 154 WASM_BRV(0, WASM_I8(55))))};
155 f->EmitCode(code, sizeof(code)); 155 f->EmitCode(code, sizeof(code));
156 TestModule(&zone, builder, 55); 156 TestModule(&zone, builder, 55);
157 } 157 }
158 158
159 TEST(Run_WasmModule_Global) { 159 TEST(Run_WasmModule_Global) {
160 v8::base::AccountingAllocator allocator; 160 v8::internal::AccountingAllocator allocator;
161 Zone zone(&allocator); 161 Zone zone(&allocator);
162 TestSignatures sigs; 162 TestSignatures sigs;
163 163
164 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 164 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
165 uint32_t global1 = builder->AddGlobal(kAstI32, 0); 165 uint32_t global1 = builder->AddGlobal(kAstI32, 0);
166 uint32_t global2 = builder->AddGlobal(kAstI32, 0); 166 uint32_t global2 = builder->AddGlobal(kAstI32, 0);
167 uint16_t f1_index = builder->AddFunction(); 167 uint16_t f1_index = builder->AddFunction();
168 WasmFunctionBuilder* f = builder->FunctionAt(f1_index); 168 WasmFunctionBuilder* f = builder->FunctionAt(f1_index);
169 f->SetSignature(sigs.i_v()); 169 f->SetSignature(sigs.i_v());
170 byte code1[] = { 170 byte code1[] = {
171 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; 171 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))};
172 f->EmitCode(code1, sizeof(code1)); 172 f->EmitCode(code1, sizeof(code1));
173 uint16_t f2_index = builder->AddFunction(); 173 uint16_t f2_index = builder->AddFunction();
174 f = builder->FunctionAt(f2_index); 174 f = builder->FunctionAt(f2_index);
175 f->SetSignature(sigs.i_v()); 175 f->SetSignature(sigs.i_v());
176 ExportAsMain(f); 176 ExportAsMain(f);
177 byte code2[] = {WASM_SET_GLOBAL(global1, WASM_I32V_1(56)), 177 byte code2[] = {WASM_SET_GLOBAL(global1, WASM_I32V_1(56)),
178 WASM_SET_GLOBAL(global2, WASM_I32V_1(41)), 178 WASM_SET_GLOBAL(global2, WASM_I32V_1(41)),
179 WASM_RETURN1(WASM_CALL_FUNCTION0(f1_index))}; 179 WASM_RETURN1(WASM_CALL_FUNCTION0(f1_index))};
180 f->EmitCode(code2, sizeof(code2)); 180 f->EmitCode(code2, sizeof(code2));
181 TestModule(&zone, builder, 97); 181 TestModule(&zone, builder, 97);
182 } 182 }
183 183
184 TEST(Run_WasmModule_Serialization) { 184 TEST(Run_WasmModule_Serialization) {
185 static const char* kFunctionName = "increment"; 185 static const char* kFunctionName = "increment";
186 v8::base::AccountingAllocator allocator; 186 v8::internal::AccountingAllocator allocator;
187 Zone zone(&allocator); 187 Zone zone(&allocator);
188 188
189 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 189 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
190 uint16_t f_index = builder->AddFunction(); 190 uint16_t f_index = builder->AddFunction();
191 TestSignatures sigs; 191 TestSignatures sigs;
192 192
193 WasmFunctionBuilder* f = builder->FunctionAt(f_index); 193 WasmFunctionBuilder* f = builder->FunctionAt(f_index);
194 f->SetSignature(sigs.i_i()); 194 f->SetSignature(sigs.i_i());
195 byte code[] = {WASM_GET_LOCAL(0), kExprI32Const, 1, kExprI32Add}; 195 byte code[] = {WASM_GET_LOCAL(0), kExprI32Const, 1, kExprI32Add};
196 f->EmitCode(code, sizeof(code)); 196 f->EmitCode(code, sizeof(code));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 CHECK(result == 42); 255 CHECK(result == 42);
256 new_ctx->Exit(); 256 new_ctx->Exit();
257 } 257 }
258 } 258 }
259 259
260 TEST(Run_WasmModule_MemSize_GrowMem) { 260 TEST(Run_WasmModule_MemSize_GrowMem) {
261 static const int kPageSize = 0x10000; 261 static const int kPageSize = 0x10000;
262 // Initial memory size = 16 + GrowMemory(10) 262 // Initial memory size = 16 + GrowMemory(10)
263 static const int kExpectedValue = kPageSize * 26; 263 static const int kExpectedValue = kPageSize * 26;
264 TestSignatures sigs; 264 TestSignatures sigs;
265 v8::base::AccountingAllocator allocator; 265 v8::internal::AccountingAllocator allocator;
266 Zone zone(&allocator); 266 Zone zone(&allocator);
267 267
268 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 268 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
269 uint16_t f_index = builder->AddFunction(); 269 uint16_t f_index = builder->AddFunction();
270 WasmFunctionBuilder* f = builder->FunctionAt(f_index); 270 WasmFunctionBuilder* f = builder->FunctionAt(f_index);
271 f->SetSignature(sigs.i_v()); 271 f->SetSignature(sigs.i_v());
272 ExportAsMain(f); 272 ExportAsMain(f);
273 byte code[] = {WASM_GROW_MEMORY(WASM_I8(10)), WASM_MEMORY_SIZE}; 273 byte code[] = {WASM_GROW_MEMORY(WASM_I8(10)), WASM_MEMORY_SIZE};
274 f->EmitCode(code, sizeof(code)); 274 f->EmitCode(code, sizeof(code));
275 TestModule(&zone, builder, kExpectedValue); 275 TestModule(&zone, builder, kExpectedValue);
276 } 276 }
277 277
278 TEST(Run_WasmModule_GrowMemoryInIf) { 278 TEST(Run_WasmModule_GrowMemoryInIf) {
279 TestSignatures sigs; 279 TestSignatures sigs;
280 v8::base::AccountingAllocator allocator; 280 v8::internal::AccountingAllocator allocator;
281 Zone zone(&allocator); 281 Zone zone(&allocator);
282 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 282 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
283 uint16_t f_index = builder->AddFunction(); 283 uint16_t f_index = builder->AddFunction();
284 WasmFunctionBuilder* f = builder->FunctionAt(f_index); 284 WasmFunctionBuilder* f = builder->FunctionAt(f_index);
285 f->SetSignature(sigs.i_v()); 285 f->SetSignature(sigs.i_v());
286 ExportAsMain(f); 286 ExportAsMain(f);
287 byte code[] = {WASM_IF_ELSE(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), 287 byte code[] = {WASM_IF_ELSE(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)),
288 WASM_I32V(12))}; 288 WASM_I32V(12))};
289 f->EmitCode(code, sizeof(code)); 289 f->EmitCode(code, sizeof(code));
290 TestModule(&zone, builder, 12); 290 TestModule(&zone, builder, 12);
291 } 291 }
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-run-wasm-64.cc ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698