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

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

Issue 2630553002: [wasm] Enforce that function bodies end with the \"end\" opcode. (Closed)
Patch Set: Collapse some tests together Created 3 years, 11 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
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/snapshot/code-serializer.h" 8 #include "src/snapshot/code-serializer.h"
9 #include "src/version.h" 9 #include "src/version.h"
10 #include "src/wasm/module-decoder.h" 10 #include "src/wasm/module-decoder.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 testing::SetupIsolateForWasmModule(isolate); 56 testing::SetupIsolateForWasmModule(isolate);
57 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate)); 57 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
58 testing::CompileAndRunWasmModule(isolate, buffer.begin(), buffer.end(), 58 testing::CompileAndRunWasmModule(isolate, buffer.begin(), buffer.end(),
59 ModuleOrigin::kWasmOrigin); 59 ModuleOrigin::kWasmOrigin);
60 CHECK(try_catch.HasCaught()); 60 CHECK(try_catch.HasCaught());
61 isolate->clear_pending_exception(); 61 isolate->clear_pending_exception();
62 } 62 }
63 63
64 void ExportAsMain(WasmFunctionBuilder* f) { f->ExportAs(CStrVector("main")); } 64 void ExportAsMain(WasmFunctionBuilder* f) { f->ExportAs(CStrVector("main")); }
65 65
66 #define EMIT_CODE_WITH_END(f, code) \
67 do { \
68 f->EmitCode(code, sizeof(code)); \
69 f->Emit(kExprEnd); \
70 } while (false)
71
66 } // namespace 72 } // namespace
67 73
68 TEST(Run_WasmModule_Return114) { 74 TEST(Run_WasmModule_Return114) {
69 { 75 {
70 static const int32_t kReturnValue = 114; 76 static const int32_t kReturnValue = 114;
71 TestSignatures sigs; 77 TestSignatures sigs;
72 v8::internal::AccountingAllocator allocator; 78 v8::internal::AccountingAllocator allocator;
73 Zone zone(&allocator, ZONE_NAME); 79 Zone zone(&allocator, ZONE_NAME);
74 80
75 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 81 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
76 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); 82 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
77 ExportAsMain(f); 83 ExportAsMain(f);
78 byte code[] = {WASM_I32V_2(kReturnValue)}; 84 byte code[] = {WASM_I32V_2(kReturnValue)};
79 f->EmitCode(code, sizeof(code)); 85 EMIT_CODE_WITH_END(f, code);
80 TestModule(&zone, builder, kReturnValue); 86 TestModule(&zone, builder, kReturnValue);
81 } 87 }
82 Cleanup(); 88 Cleanup();
83 } 89 }
84 90
85 TEST(Run_WasmModule_CallAdd) { 91 TEST(Run_WasmModule_CallAdd) {
86 { 92 {
87 v8::internal::AccountingAllocator allocator; 93 v8::internal::AccountingAllocator allocator;
88 Zone zone(&allocator, ZONE_NAME); 94 Zone zone(&allocator, ZONE_NAME);
89 TestSignatures sigs; 95 TestSignatures sigs;
90 96
91 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 97 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
92 98
93 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_ii()); 99 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_ii());
94 uint16_t param1 = 0; 100 uint16_t param1 = 0;
95 uint16_t param2 = 1; 101 uint16_t param2 = 1;
96 byte code1[] = { 102 byte code1[] = {
97 WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))}; 103 WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))};
98 f1->EmitCode(code1, sizeof(code1)); 104 EMIT_CODE_WITH_END(f1, code1);
99 105
100 WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); 106 WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v());
101 107
102 ExportAsMain(f2); 108 ExportAsMain(f2);
103 byte code2[] = { 109 byte code2[] = {
104 WASM_CALL_FUNCTION(f1->func_index(), WASM_I32V_2(77), WASM_I32V_1(22))}; 110 WASM_CALL_FUNCTION(f1->func_index(), WASM_I32V_2(77), WASM_I32V_1(22))};
105 f2->EmitCode(code2, sizeof(code2)); 111 EMIT_CODE_WITH_END(f2, code2);
106 TestModule(&zone, builder, 99); 112 TestModule(&zone, builder, 99);
107 } 113 }
108 Cleanup(); 114 Cleanup();
109 } 115 }
110 116
111 TEST(Run_WasmModule_ReadLoadedDataSegment) { 117 TEST(Run_WasmModule_ReadLoadedDataSegment) {
112 { 118 {
113 static const byte kDataSegmentDest0 = 12; 119 static const byte kDataSegmentDest0 = 12;
114 v8::internal::AccountingAllocator allocator; 120 v8::internal::AccountingAllocator allocator;
115 Zone zone(&allocator, ZONE_NAME); 121 Zone zone(&allocator, ZONE_NAME);
116 TestSignatures sigs; 122 TestSignatures sigs;
117 123
118 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 124 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
119 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); 125 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
120 126
121 ExportAsMain(f); 127 ExportAsMain(f);
122 byte code[] = { 128 byte code[] = {
123 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(kDataSegmentDest0))}; 129 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(kDataSegmentDest0))};
124 f->EmitCode(code, sizeof(code)); 130 EMIT_CODE_WITH_END(f, code);
125 byte data[] = {0xaa, 0xbb, 0xcc, 0xdd}; 131 byte data[] = {0xaa, 0xbb, 0xcc, 0xdd};
126 builder->AddDataSegment(data, sizeof(data), kDataSegmentDest0); 132 builder->AddDataSegment(data, sizeof(data), kDataSegmentDest0);
127 TestModule(&zone, builder, 0xddccbbaa); 133 TestModule(&zone, builder, 0xddccbbaa);
128 } 134 }
129 Cleanup(); 135 Cleanup();
130 } 136 }
131 137
132 TEST(Run_WasmModule_CheckMemoryIsZero) { 138 TEST(Run_WasmModule_CheckMemoryIsZero) {
133 { 139 {
134 static const int kCheckSize = 16 * 1024; 140 static const int kCheckSize = 16 * 1024;
135 v8::internal::AccountingAllocator allocator; 141 v8::internal::AccountingAllocator allocator;
136 Zone zone(&allocator, ZONE_NAME); 142 Zone zone(&allocator, ZONE_NAME);
137 TestSignatures sigs; 143 TestSignatures sigs;
138 144
139 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 145 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
140 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); 146 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
141 147
142 uint16_t localIndex = f->AddLocal(kWasmI32); 148 uint16_t localIndex = f->AddLocal(kWasmI32);
143 ExportAsMain(f); 149 ExportAsMain(f);
144 byte code[] = {WASM_BLOCK_I( 150 byte code[] = {WASM_BLOCK_I(
145 WASM_WHILE( 151 WASM_WHILE(
146 WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)), 152 WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)),
147 WASM_IF_ELSE( 153 WASM_IF_ELSE(
148 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)), 154 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)),
149 WASM_BRV(3, WASM_I32V_1(-1)), 155 WASM_BRV(3, WASM_I32V_1(-1)),
150 WASM_INC_LOCAL_BY(localIndex, 4))), 156 WASM_INC_LOCAL_BY(localIndex, 4))),
151 WASM_I32V_1(11))}; 157 WASM_I32V_1(11))};
152 f->EmitCode(code, sizeof(code)); 158 EMIT_CODE_WITH_END(f, code);
153 TestModule(&zone, builder, 11); 159 TestModule(&zone, builder, 11);
154 } 160 }
155 Cleanup(); 161 Cleanup();
156 } 162 }
157 163
158 TEST(Run_WasmModule_CallMain_recursive) { 164 TEST(Run_WasmModule_CallMain_recursive) {
159 { 165 {
160 v8::internal::AccountingAllocator allocator; 166 v8::internal::AccountingAllocator allocator;
161 Zone zone(&allocator, ZONE_NAME); 167 Zone zone(&allocator, ZONE_NAME);
162 TestSignatures sigs; 168 TestSignatures sigs;
163 169
164 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 170 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
165 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); 171 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
166 172
167 uint16_t localIndex = f->AddLocal(kWasmI32); 173 uint16_t localIndex = f->AddLocal(kWasmI32);
168 ExportAsMain(f); 174 ExportAsMain(f);
169 byte code[] = { 175 byte code[] = {
170 WASM_SET_LOCAL(localIndex, 176 WASM_SET_LOCAL(localIndex,
171 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), 177 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
172 WASM_IF_ELSE_I(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_1(5)), 178 WASM_IF_ELSE_I(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_1(5)),
173 WASM_SEQ(WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, 179 WASM_SEQ(WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO,
174 WASM_INC_LOCAL(localIndex)), 180 WASM_INC_LOCAL(localIndex)),
175 WASM_CALL_FUNCTION0(0)), 181 WASM_CALL_FUNCTION0(0)),
176 WASM_I32V_1(55))}; 182 WASM_I32V_1(55))};
177 f->EmitCode(code, sizeof(code)); 183 EMIT_CODE_WITH_END(f, code);
178 TestModule(&zone, builder, 55); 184 TestModule(&zone, builder, 55);
179 } 185 }
180 Cleanup(); 186 Cleanup();
181 } 187 }
182 188
183 TEST(Run_WasmModule_Global) { 189 TEST(Run_WasmModule_Global) {
184 { 190 {
185 v8::internal::AccountingAllocator allocator; 191 v8::internal::AccountingAllocator allocator;
186 Zone zone(&allocator, ZONE_NAME); 192 Zone zone(&allocator, ZONE_NAME);
187 TestSignatures sigs; 193 TestSignatures sigs;
188 194
189 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 195 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
190 uint32_t global1 = builder->AddGlobal(kWasmI32, 0); 196 uint32_t global1 = builder->AddGlobal(kWasmI32, 0);
191 uint32_t global2 = builder->AddGlobal(kWasmI32, 0); 197 uint32_t global2 = builder->AddGlobal(kWasmI32, 0);
192 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); 198 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v());
193 byte code1[] = { 199 byte code1[] = {
194 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; 200 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))};
195 f1->EmitCode(code1, sizeof(code1)); 201 EMIT_CODE_WITH_END(f1, code1);
196 WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); 202 WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v());
197 ExportAsMain(f2); 203 ExportAsMain(f2);
198 byte code2[] = {WASM_SET_GLOBAL(global1, WASM_I32V_1(56)), 204 byte code2[] = {WASM_SET_GLOBAL(global1, WASM_I32V_1(56)),
199 WASM_SET_GLOBAL(global2, WASM_I32V_1(41)), 205 WASM_SET_GLOBAL(global2, WASM_I32V_1(41)),
200 WASM_RETURN1(WASM_CALL_FUNCTION0(f1->func_index()))}; 206 WASM_RETURN1(WASM_CALL_FUNCTION0(f1->func_index()))};
201 f2->EmitCode(code2, sizeof(code2)); 207 EMIT_CODE_WITH_END(f2, code2);
202 TestModule(&zone, builder, 97); 208 TestModule(&zone, builder, 97);
203 } 209 }
204 Cleanup(); 210 Cleanup();
205 } 211 }
206 212
207 // Approximate gtest TEST_F style, in case we adopt gtest. 213 // Approximate gtest TEST_F style, in case we adopt gtest.
208 class WasmSerializationTest { 214 class WasmSerializationTest {
209 public: 215 public:
210 WasmSerializationTest() : zone_(&allocator_, ZONE_NAME) { 216 WasmSerializationTest() : zone_(&allocator_, ZONE_NAME) {
211 // Don't call here if we move to gtest. 217 // Don't call here if we move to gtest.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 292 }
287 293
288 v8::Isolate* current_isolate_v8() { return current_isolate_v8_; } 294 v8::Isolate* current_isolate_v8() { return current_isolate_v8_; }
289 295
290 void SetUp() { 296 void SetUp() {
291 WasmModuleBuilder* builder = new (zone()) WasmModuleBuilder(zone()); 297 WasmModuleBuilder* builder = new (zone()) WasmModuleBuilder(zone());
292 TestSignatures sigs; 298 TestSignatures sigs;
293 299
294 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); 300 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i());
295 byte code[] = {WASM_GET_LOCAL(0), kExprI32Const, 1, kExprI32Add}; 301 byte code[] = {WASM_GET_LOCAL(0), kExprI32Const, 1, kExprI32Add};
296 f->EmitCode(code, sizeof(code)); 302 EMIT_CODE_WITH_END(f, code);
297 f->ExportAs(CStrVector(kFunctionName)); 303 f->ExportAs(CStrVector(kFunctionName));
298 304
299 ZoneBuffer buffer(&zone_); 305 ZoneBuffer buffer(&zone_);
300 builder->WriteTo(buffer); 306 builder->WriteTo(buffer);
301 307
302 Isolate* serialization_isolate = CcTest::InitIsolateOnce(); 308 Isolate* serialization_isolate = CcTest::InitIsolateOnce();
303 ErrorThrower thrower(serialization_isolate, ""); 309 ErrorThrower thrower(serialization_isolate, "");
304 uint8_t* bytes = nullptr; 310 uint8_t* bytes = nullptr;
305 size_t bytes_size = 0; 311 size_t bytes_size = 0;
306 { 312 {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 // Initial memory size is 16, see wasm-module-builder.cc 424 // Initial memory size is 16, see wasm-module-builder.cc
419 static const int kExpectedValue = 16; 425 static const int kExpectedValue = 16;
420 TestSignatures sigs; 426 TestSignatures sigs;
421 v8::internal::AccountingAllocator allocator; 427 v8::internal::AccountingAllocator allocator;
422 Zone zone(&allocator, ZONE_NAME); 428 Zone zone(&allocator, ZONE_NAME);
423 429
424 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 430 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
425 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); 431 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
426 ExportAsMain(f); 432 ExportAsMain(f);
427 byte code[] = {WASM_MEMORY_SIZE}; 433 byte code[] = {WASM_MEMORY_SIZE};
428 f->EmitCode(code, sizeof(code)); 434 EMIT_CODE_WITH_END(f, code);
429 TestModule(&zone, builder, kExpectedValue); 435 TestModule(&zone, builder, kExpectedValue);
430 } 436 }
431 Cleanup(); 437 Cleanup();
432 } 438 }
433 439
434 TEST(Run_WasmModule_MemSize_GrowMem) { 440 TEST(Run_WasmModule_MemSize_GrowMem) {
435 { 441 {
436 // Initial memory size = 16 + GrowMemory(10) 442 // Initial memory size = 16 + GrowMemory(10)
437 static const int kExpectedValue = 26; 443 static const int kExpectedValue = 26;
438 TestSignatures sigs; 444 TestSignatures sigs;
439 v8::internal::AccountingAllocator allocator; 445 v8::internal::AccountingAllocator allocator;
440 Zone zone(&allocator, ZONE_NAME); 446 Zone zone(&allocator, ZONE_NAME);
441 447
442 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 448 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
443 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); 449 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
444 ExportAsMain(f); 450 ExportAsMain(f);
445 byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(10)), WASM_DROP, 451 byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(10)), WASM_DROP,
446 WASM_MEMORY_SIZE}; 452 WASM_MEMORY_SIZE};
447 f->EmitCode(code, sizeof(code)); 453 EMIT_CODE_WITH_END(f, code);
448 TestModule(&zone, builder, kExpectedValue); 454 TestModule(&zone, builder, kExpectedValue);
449 } 455 }
450 Cleanup(); 456 Cleanup();
451 } 457 }
452 458
453 TEST(GrowMemoryZero) { 459 TEST(GrowMemoryZero) {
454 { 460 {
455 // Initial memory size is 16, see wasm-module-builder.cc 461 // Initial memory size is 16, see wasm-module-builder.cc
456 static const int kExpectedValue = 16; 462 static const int kExpectedValue = 16;
457 TestSignatures sigs; 463 TestSignatures sigs;
458 v8::internal::AccountingAllocator allocator; 464 v8::internal::AccountingAllocator allocator;
459 Zone zone(&allocator, ZONE_NAME); 465 Zone zone(&allocator, ZONE_NAME);
460 466
461 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 467 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
462 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); 468 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
463 ExportAsMain(f); 469 ExportAsMain(f);
464 byte code[] = {WASM_GROW_MEMORY(WASM_I32V(0))}; 470 byte code[] = {WASM_GROW_MEMORY(WASM_I32V(0))};
465 f->EmitCode(code, sizeof(code)); 471 EMIT_CODE_WITH_END(f, code);
466 TestModule(&zone, builder, kExpectedValue); 472 TestModule(&zone, builder, kExpectedValue);
467 } 473 }
468 Cleanup(); 474 Cleanup();
469 } 475 }
470 476
471 class InterruptThread : public v8::base::Thread { 477 class InterruptThread : public v8::base::Thread {
472 public: 478 public:
473 explicit InterruptThread(Isolate* isolate, int32_t* memory) 479 explicit InterruptThread(Isolate* isolate, int32_t* memory)
474 : Thread(Options("TestInterruptLoop")), 480 : Thread(Options("TestInterruptLoop")),
475 isolate_(isolate), 481 isolate_(isolate),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 ExportAsMain(f); 532 ExportAsMain(f);
527 byte code[] = { 533 byte code[] = {
528 WASM_LOOP( 534 WASM_LOOP(
529 WASM_IFB(WASM_NOT(WASM_LOAD_MEM( 535 WASM_IFB(WASM_NOT(WASM_LOAD_MEM(
530 MachineType::Int32(), 536 MachineType::Int32(),
531 WASM_I32V(InterruptThread::interrupt_location_ * 4))), 537 WASM_I32V(InterruptThread::interrupt_location_ * 4))),
532 WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, 538 WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO,
533 WASM_I32V(InterruptThread::signal_value_)), 539 WASM_I32V(InterruptThread::signal_value_)),
534 WASM_BR(1))), 540 WASM_BR(1))),
535 WASM_I32V(121)}; 541 WASM_I32V(121)};
536 f->EmitCode(code, sizeof(code)); 542 EMIT_CODE_WITH_END(f, code);
537 ZoneBuffer buffer(&zone); 543 ZoneBuffer buffer(&zone);
538 builder->WriteTo(buffer); 544 builder->WriteTo(buffer);
539 545
540 HandleScope scope(isolate); 546 HandleScope scope(isolate);
541 testing::SetupIsolateForWasmModule(isolate); 547 testing::SetupIsolateForWasmModule(isolate);
542 ErrorThrower thrower(isolate, "Test"); 548 ErrorThrower thrower(isolate, "Test");
543 const Handle<WasmInstanceObject> instance = 549 const Handle<WasmInstanceObject> instance =
544 testing::CompileInstantiateWasmModuleForTesting( 550 testing::CompileInstantiateWasmModuleForTesting(
545 isolate, &thrower, buffer.begin(), buffer.end(), 551 isolate, &thrower, buffer.begin(), buffer.end(),
546 ModuleOrigin::kWasmOrigin); 552 ModuleOrigin::kWasmOrigin);
(...skipping 18 matching lines...) Expand all
565 TEST(Run_WasmModule_GrowMemoryInIf) { 571 TEST(Run_WasmModule_GrowMemoryInIf) {
566 { 572 {
567 TestSignatures sigs; 573 TestSignatures sigs;
568 v8::internal::AccountingAllocator allocator; 574 v8::internal::AccountingAllocator allocator;
569 Zone zone(&allocator, ZONE_NAME); 575 Zone zone(&allocator, ZONE_NAME);
570 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 576 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
571 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); 577 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
572 ExportAsMain(f); 578 ExportAsMain(f);
573 byte code[] = {WASM_IF_ELSE_I(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), 579 byte code[] = {WASM_IF_ELSE_I(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)),
574 WASM_I32V(12))}; 580 WASM_I32V(12))};
575 f->EmitCode(code, sizeof(code)); 581 EMIT_CODE_WITH_END(f, code);
576 TestModule(&zone, builder, 12); 582 TestModule(&zone, builder, 12);
577 } 583 }
578 Cleanup(); 584 Cleanup();
579 } 585 }
580 586
581 TEST(Run_WasmModule_GrowMemOobOffset) { 587 TEST(Run_WasmModule_GrowMemOobOffset) {
582 { 588 {
583 static const int kPageSize = 0x10000; 589 static const int kPageSize = 0x10000;
584 // Initial memory size = 16 + GrowMemory(10) 590 // Initial memory size = 16 + GrowMemory(10)
585 static const int index = kPageSize * 17 + 4; 591 static const int index = kPageSize * 17 + 4;
586 int value = 0xaced; 592 int value = 0xaced;
587 TestSignatures sigs; 593 TestSignatures sigs;
588 v8::internal::AccountingAllocator allocator; 594 v8::internal::AccountingAllocator allocator;
589 Zone zone(&allocator, ZONE_NAME); 595 Zone zone(&allocator, ZONE_NAME);
590 596
591 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 597 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
592 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); 598 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
593 ExportAsMain(f); 599 ExportAsMain(f);
594 byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)), 600 byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)),
595 WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), 601 WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index),
596 WASM_I32V(value))}; 602 WASM_I32V(value))};
597 f->EmitCode(code, sizeof(code)); 603 EMIT_CODE_WITH_END(f, code);
598 TestModuleException(&zone, builder); 604 TestModuleException(&zone, builder);
599 } 605 }
600 Cleanup(); 606 Cleanup();
601 } 607 }
602 608
603 TEST(Run_WasmModule_GrowMemOobFixedIndex) { 609 TEST(Run_WasmModule_GrowMemOobFixedIndex) {
604 { 610 {
605 static const int kPageSize = 0x10000; 611 static const int kPageSize = 0x10000;
606 // Initial memory size = 16 + GrowMemory(10) 612 // Initial memory size = 16 + GrowMemory(10)
607 static const int index = kPageSize * 26 + 4; 613 static const int index = kPageSize * 26 + 4;
608 int value = 0xaced; 614 int value = 0xaced;
609 TestSignatures sigs; 615 TestSignatures sigs;
610 Isolate* isolate = CcTest::InitIsolateOnce(); 616 Isolate* isolate = CcTest::InitIsolateOnce();
611 Zone zone(isolate->allocator(), ZONE_NAME); 617 Zone zone(isolate->allocator(), ZONE_NAME);
612 618
613 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 619 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
614 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); 620 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i());
615 ExportAsMain(f); 621 ExportAsMain(f);
616 byte code[] = {WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP, 622 byte code[] = {WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP,
617 WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), 623 WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index),
618 WASM_I32V(value)), 624 WASM_I32V(value)),
619 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index))}; 625 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index))};
620 f->EmitCode(code, sizeof(code)); 626 EMIT_CODE_WITH_END(f, code);
621 627
622 HandleScope scope(isolate); 628 HandleScope scope(isolate);
623 ZoneBuffer buffer(&zone); 629 ZoneBuffer buffer(&zone);
624 builder->WriteTo(buffer); 630 builder->WriteTo(buffer);
625 testing::SetupIsolateForWasmModule(isolate); 631 testing::SetupIsolateForWasmModule(isolate);
626 632
627 ErrorThrower thrower(isolate, "Test"); 633 ErrorThrower thrower(isolate, "Test");
628 Handle<JSObject> instance = testing::CompileInstantiateWasmModuleForTesting( 634 Handle<JSObject> instance = testing::CompileInstantiateWasmModuleForTesting(
629 isolate, &thrower, buffer.begin(), buffer.end(), 635 isolate, &thrower, buffer.begin(), buffer.end(),
630 ModuleOrigin::kWasmOrigin); 636 ModuleOrigin::kWasmOrigin);
(...skipping 27 matching lines...) Expand all
658 v8::internal::AccountingAllocator allocator; 664 v8::internal::AccountingAllocator allocator;
659 Zone zone(&allocator, ZONE_NAME); 665 Zone zone(&allocator, ZONE_NAME);
660 666
661 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 667 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
662 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); 668 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i());
663 ExportAsMain(f); 669 ExportAsMain(f);
664 byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)), WASM_DROP, 670 byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)), WASM_DROP,
665 WASM_STORE_MEM(MachineType::Int32(), WASM_GET_LOCAL(0), 671 WASM_STORE_MEM(MachineType::Int32(), WASM_GET_LOCAL(0),
666 WASM_I32V(value)), 672 WASM_I32V(value)),
667 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))}; 673 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))};
668 f->EmitCode(code, sizeof(code)); 674 EMIT_CODE_WITH_END(f, code);
669 675
670 HandleScope scope(isolate); 676 HandleScope scope(isolate);
671 ZoneBuffer buffer(&zone); 677 ZoneBuffer buffer(&zone);
672 builder->WriteTo(buffer); 678 builder->WriteTo(buffer);
673 testing::SetupIsolateForWasmModule(isolate); 679 testing::SetupIsolateForWasmModule(isolate);
674 680
675 ErrorThrower thrower(isolate, "Test"); 681 ErrorThrower thrower(isolate, "Test");
676 Handle<JSObject> instance = testing::CompileInstantiateWasmModuleForTesting( 682 Handle<JSObject> instance = testing::CompileInstantiateWasmModuleForTesting(
677 isolate, &thrower, buffer.begin(), buffer.end(), 683 isolate, &thrower, buffer.begin(), buffer.end(),
678 ModuleOrigin::kWasmOrigin); 684 ModuleOrigin::kWasmOrigin);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 TestSignatures sigs; 723 TestSignatures sigs;
718 724
719 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 725 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
720 uint32_t global1 = 726 uint32_t global1 =
721 builder->AddGlobal(kWasmI32, false, false, WasmInitExpr(777777)); 727 builder->AddGlobal(kWasmI32, false, false, WasmInitExpr(777777));
722 uint32_t global2 = 728 uint32_t global2 =
723 builder->AddGlobal(kWasmI32, false, false, WasmInitExpr(222222)); 729 builder->AddGlobal(kWasmI32, false, false, WasmInitExpr(222222));
724 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); 730 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v());
725 byte code[] = { 731 byte code[] = {
726 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; 732 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))};
727 f1->EmitCode(code, sizeof(code)); 733 EMIT_CODE_WITH_END(f1, code);
728 ExportAsMain(f1); 734 ExportAsMain(f1);
729 TestModule(&zone, builder, 999999); 735 TestModule(&zone, builder, 999999);
730 } 736 }
731 Cleanup(); 737 Cleanup();
732 } 738 }
733 739
734 template <typename CType> 740 template <typename CType>
735 static void RunWasmModuleGlobalInitTest(ValueType type, CType expected) { 741 static void RunWasmModuleGlobalInitTest(ValueType type, CType expected) {
736 { 742 {
737 v8::internal::AccountingAllocator allocator; 743 v8::internal::AccountingAllocator allocator;
(...skipping 11 matching lines...) Expand all
749 builder->AddGlobal(kWasmI32, false, false, WasmInitExpr(i + 20000)); 755 builder->AddGlobal(kWasmI32, false, false, WasmInitExpr(i + 20000));
750 } 756 }
751 uint32_t global = 757 uint32_t global =
752 builder->AddGlobal(type, false, false, WasmInitExpr(expected)); 758 builder->AddGlobal(type, false, false, WasmInitExpr(expected));
753 for (int i = 0; i < padding; i++) { // pad global after 759 for (int i = 0; i < padding; i++) { // pad global after
754 builder->AddGlobal(kWasmI32, false, false, WasmInitExpr(i + 30000)); 760 builder->AddGlobal(kWasmI32, false, false, WasmInitExpr(i + 30000));
755 } 761 }
756 762
757 WasmFunctionBuilder* f1 = builder->AddFunction(&sig); 763 WasmFunctionBuilder* f1 = builder->AddFunction(&sig);
758 byte code[] = {WASM_GET_GLOBAL(global)}; 764 byte code[] = {WASM_GET_GLOBAL(global)};
759 f1->EmitCode(code, sizeof(code)); 765 EMIT_CODE_WITH_END(f1, code);
760 ExportAsMain(f1); 766 ExportAsMain(f1);
761 TestModule(&zone, builder, expected); 767 TestModule(&zone, builder, expected);
762 } 768 }
763 } 769 }
764 Cleanup(); 770 Cleanup();
765 } 771 }
766 772
767 TEST(Run_WasmModule_Global_i32) { 773 TEST(Run_WasmModule_Global_i32) {
768 RunWasmModuleGlobalInitTest<int32_t>(kWasmI32, -983489); 774 RunWasmModuleGlobalInitTest<int32_t>(kWasmI32, -983489);
769 RunWasmModuleGlobalInitTest<int32_t>(kWasmI32, 11223344); 775 RunWasmModuleGlobalInitTest<int32_t>(kWasmI32, 11223344);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 }; 917 };
912 918
913 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, 919 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data,
914 data + arraysize(data), 920 data + arraysize(data),
915 ModuleOrigin::kWasmOrigin); 921 ModuleOrigin::kWasmOrigin);
916 // It should be possible to instantiate this module. 922 // It should be possible to instantiate this module.
917 CHECK(!thrower.error()); 923 CHECK(!thrower.error());
918 } 924 }
919 Cleanup(); 925 Cleanup();
920 } 926 }
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-run-wasm-interpreter.cc ('k') | test/cctest/wasm/test-wasm-breakpoints.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698