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

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

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