| OLD | NEW |
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 } | 51 } |
| 52 | 52 |
| 53 void ExportAsMain(WasmFunctionBuilder* f) { f->ExportAs(CStrVector("main")); } | 53 void ExportAsMain(WasmFunctionBuilder* f) { f->ExportAs(CStrVector("main")); } |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 TEST(Run_WasmModule_Return114) { | 57 TEST(Run_WasmModule_Return114) { |
| 58 static const int32_t kReturnValue = 114; | 58 static const int32_t kReturnValue = 114; |
| 59 TestSignatures sigs; | 59 TestSignatures sigs; |
| 60 v8::internal::AccountingAllocator allocator; | 60 v8::internal::AccountingAllocator allocator; |
| 61 Zone zone(&allocator); | 61 Zone zone(&allocator, ZONE_NAME); |
| 62 | 62 |
| 63 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 63 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 64 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 64 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 65 ExportAsMain(f); | 65 ExportAsMain(f); |
| 66 byte code[] = {WASM_I8(kReturnValue)}; | 66 byte code[] = {WASM_I8(kReturnValue)}; |
| 67 f->EmitCode(code, sizeof(code)); | 67 f->EmitCode(code, sizeof(code)); |
| 68 TestModule(&zone, builder, kReturnValue); | 68 TestModule(&zone, builder, kReturnValue); |
| 69 } | 69 } |
| 70 | 70 |
| 71 TEST(Run_WasmModule_CallAdd) { | 71 TEST(Run_WasmModule_CallAdd) { |
| 72 v8::internal::AccountingAllocator allocator; | 72 v8::internal::AccountingAllocator allocator; |
| 73 Zone zone(&allocator); | 73 Zone zone(&allocator, ZONE_NAME); |
| 74 TestSignatures sigs; | 74 TestSignatures sigs; |
| 75 | 75 |
| 76 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 76 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 77 | 77 |
| 78 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_ii()); | 78 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_ii()); |
| 79 uint16_t param1 = 0; | 79 uint16_t param1 = 0; |
| 80 uint16_t param2 = 1; | 80 uint16_t param2 = 1; |
| 81 byte code1[] = {WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))}; | 81 byte code1[] = {WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))}; |
| 82 f1->EmitCode(code1, sizeof(code1)); | 82 f1->EmitCode(code1, sizeof(code1)); |
| 83 | 83 |
| 84 WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); | 84 WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); |
| 85 | 85 |
| 86 ExportAsMain(f2); | 86 ExportAsMain(f2); |
| 87 byte code2[] = { | 87 byte code2[] = { |
| 88 WASM_CALL_FUNCTION(f1->func_index(), WASM_I8(77), WASM_I8(22))}; | 88 WASM_CALL_FUNCTION(f1->func_index(), WASM_I8(77), WASM_I8(22))}; |
| 89 f2->EmitCode(code2, sizeof(code2)); | 89 f2->EmitCode(code2, sizeof(code2)); |
| 90 TestModule(&zone, builder, 99); | 90 TestModule(&zone, builder, 99); |
| 91 } | 91 } |
| 92 | 92 |
| 93 TEST(Run_WasmModule_ReadLoadedDataSegment) { | 93 TEST(Run_WasmModule_ReadLoadedDataSegment) { |
| 94 static const byte kDataSegmentDest0 = 12; | 94 static const byte kDataSegmentDest0 = 12; |
| 95 v8::internal::AccountingAllocator allocator; | 95 v8::internal::AccountingAllocator allocator; |
| 96 Zone zone(&allocator); | 96 Zone zone(&allocator, ZONE_NAME); |
| 97 TestSignatures sigs; | 97 TestSignatures sigs; |
| 98 | 98 |
| 99 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 99 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 100 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 100 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 101 | 101 |
| 102 ExportAsMain(f); | 102 ExportAsMain(f); |
| 103 byte code[] = { | 103 byte code[] = { |
| 104 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kDataSegmentDest0))}; | 104 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kDataSegmentDest0))}; |
| 105 f->EmitCode(code, sizeof(code)); | 105 f->EmitCode(code, sizeof(code)); |
| 106 byte data[] = {0xaa, 0xbb, 0xcc, 0xdd}; | 106 byte data[] = {0xaa, 0xbb, 0xcc, 0xdd}; |
| 107 builder->AddDataSegment(data, sizeof(data), kDataSegmentDest0); | 107 builder->AddDataSegment(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::internal::AccountingAllocator allocator; | 113 v8::internal::AccountingAllocator allocator; |
| 114 Zone zone(&allocator); | 114 Zone zone(&allocator, ZONE_NAME); |
| 115 TestSignatures sigs; | 115 TestSignatures sigs; |
| 116 | 116 |
| 117 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 117 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 118 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 118 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 119 | 119 |
| 120 uint16_t localIndex = f->AddLocal(kAstI32); | 120 uint16_t localIndex = f->AddLocal(kAstI32); |
| 121 ExportAsMain(f); | 121 ExportAsMain(f); |
| 122 byte code[] = {WASM_BLOCK_I( | 122 byte code[] = {WASM_BLOCK_I( |
| 123 WASM_WHILE( | 123 WASM_WHILE( |
| 124 WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)), | 124 WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)), |
| 125 WASM_IF_ELSE( | 125 WASM_IF_ELSE( |
| 126 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)), | 126 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)), |
| 127 WASM_BRV(3, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))), | 127 WASM_BRV(3, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))), |
| 128 WASM_I8(11))}; | 128 WASM_I8(11))}; |
| 129 f->EmitCode(code, sizeof(code)); | 129 f->EmitCode(code, sizeof(code)); |
| 130 TestModule(&zone, builder, 11); | 130 TestModule(&zone, builder, 11); |
| 131 } | 131 } |
| 132 | 132 |
| 133 TEST(Run_WasmModule_CallMain_recursive) { | 133 TEST(Run_WasmModule_CallMain_recursive) { |
| 134 v8::internal::AccountingAllocator allocator; | 134 v8::internal::AccountingAllocator allocator; |
| 135 Zone zone(&allocator); | 135 Zone zone(&allocator, ZONE_NAME); |
| 136 TestSignatures sigs; | 136 TestSignatures sigs; |
| 137 | 137 |
| 138 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 138 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 139 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 139 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 140 | 140 |
| 141 uint16_t localIndex = f->AddLocal(kAstI32); | 141 uint16_t localIndex = f->AddLocal(kAstI32); |
| 142 ExportAsMain(f); | 142 ExportAsMain(f); |
| 143 byte code[] = { | 143 byte code[] = { |
| 144 WASM_SET_LOCAL(localIndex, | 144 WASM_SET_LOCAL(localIndex, |
| 145 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), | 145 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), |
| 146 WASM_IF_ELSE_I(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I8(5)), | 146 WASM_IF_ELSE_I(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I8(5)), |
| 147 WASM_SEQ(WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, | 147 WASM_SEQ(WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, |
| 148 WASM_INC_LOCAL(localIndex)), | 148 WASM_INC_LOCAL(localIndex)), |
| 149 WASM_CALL_FUNCTION0(0)), | 149 WASM_CALL_FUNCTION0(0)), |
| 150 WASM_I8(55))}; | 150 WASM_I8(55))}; |
| 151 f->EmitCode(code, sizeof(code)); | 151 f->EmitCode(code, sizeof(code)); |
| 152 TestModule(&zone, builder, 55); | 152 TestModule(&zone, builder, 55); |
| 153 } | 153 } |
| 154 | 154 |
| 155 TEST(Run_WasmModule_Global) { | 155 TEST(Run_WasmModule_Global) { |
| 156 v8::internal::AccountingAllocator allocator; | 156 v8::internal::AccountingAllocator allocator; |
| 157 Zone zone(&allocator); | 157 Zone zone(&allocator, ZONE_NAME); |
| 158 TestSignatures sigs; | 158 TestSignatures sigs; |
| 159 | 159 |
| 160 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 160 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 161 uint32_t global1 = builder->AddGlobal(kAstI32, 0); | 161 uint32_t global1 = builder->AddGlobal(kAstI32, 0); |
| 162 uint32_t global2 = builder->AddGlobal(kAstI32, 0); | 162 uint32_t global2 = builder->AddGlobal(kAstI32, 0); |
| 163 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); | 163 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); |
| 164 byte code1[] = { | 164 byte code1[] = { |
| 165 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; | 165 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; |
| 166 f1->EmitCode(code1, sizeof(code1)); | 166 f1->EmitCode(code1, sizeof(code1)); |
| 167 WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); | 167 WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); |
| 168 ExportAsMain(f2); | 168 ExportAsMain(f2); |
| 169 byte code2[] = {WASM_SET_GLOBAL(global1, WASM_I32V_1(56)), | 169 byte code2[] = {WASM_SET_GLOBAL(global1, WASM_I32V_1(56)), |
| 170 WASM_SET_GLOBAL(global2, WASM_I32V_1(41)), | 170 WASM_SET_GLOBAL(global2, WASM_I32V_1(41)), |
| 171 WASM_RETURN1(WASM_CALL_FUNCTION0(f1->func_index()))}; | 171 WASM_RETURN1(WASM_CALL_FUNCTION0(f1->func_index()))}; |
| 172 f2->EmitCode(code2, sizeof(code2)); | 172 f2->EmitCode(code2, sizeof(code2)); |
| 173 TestModule(&zone, builder, 97); | 173 TestModule(&zone, builder, 97); |
| 174 } | 174 } |
| 175 | 175 |
| 176 TEST(Run_WasmModule_Serialization) { | 176 TEST(Run_WasmModule_Serialization) { |
| 177 static const char* kFunctionName = "increment"; | 177 static const char* kFunctionName = "increment"; |
| 178 v8::internal::AccountingAllocator allocator; | 178 v8::internal::AccountingAllocator allocator; |
| 179 Zone zone(&allocator); | 179 Zone zone(&allocator, ZONE_NAME); |
| 180 | 180 |
| 181 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 181 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 182 TestSignatures sigs; | 182 TestSignatures sigs; |
| 183 | 183 |
| 184 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); | 184 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); |
| 185 byte code[] = {WASM_GET_LOCAL(0), kExprI32Const, 1, kExprI32Add}; | 185 byte code[] = {WASM_GET_LOCAL(0), kExprI32Const, 1, kExprI32Add}; |
| 186 f->EmitCode(code, sizeof(code)); | 186 f->EmitCode(code, sizeof(code)); |
| 187 f->ExportAs(CStrVector(kFunctionName)); | 187 f->ExportAs(CStrVector(kFunctionName)); |
| 188 | 188 |
| 189 ZoneBuffer buffer(&zone); | 189 ZoneBuffer buffer(&zone); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 } | 272 } |
| 273 v8_isolate->Dispose(); | 273 v8_isolate->Dispose(); |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 | 276 |
| 277 TEST(MemorySize) { | 277 TEST(MemorySize) { |
| 278 // Initial memory size is 16, see wasm-module-builder.cc | 278 // Initial memory size is 16, see wasm-module-builder.cc |
| 279 static const int kExpectedValue = 16; | 279 static const int kExpectedValue = 16; |
| 280 TestSignatures sigs; | 280 TestSignatures sigs; |
| 281 v8::internal::AccountingAllocator allocator; | 281 v8::internal::AccountingAllocator allocator; |
| 282 Zone zone(&allocator); | 282 Zone zone(&allocator, ZONE_NAME); |
| 283 | 283 |
| 284 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 284 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 285 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 285 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 286 ExportAsMain(f); | 286 ExportAsMain(f); |
| 287 byte code[] = {WASM_MEMORY_SIZE}; | 287 byte code[] = {WASM_MEMORY_SIZE}; |
| 288 f->EmitCode(code, sizeof(code)); | 288 f->EmitCode(code, sizeof(code)); |
| 289 TestModule(&zone, builder, kExpectedValue); | 289 TestModule(&zone, builder, kExpectedValue); |
| 290 } | 290 } |
| 291 | 291 |
| 292 TEST(Run_WasmModule_MemSize_GrowMem) { | 292 TEST(Run_WasmModule_MemSize_GrowMem) { |
| 293 // Initial memory size = 16 + GrowMemory(10) | 293 // Initial memory size = 16 + GrowMemory(10) |
| 294 static const int kExpectedValue = 26; | 294 static const int kExpectedValue = 26; |
| 295 TestSignatures sigs; | 295 TestSignatures sigs; |
| 296 v8::internal::AccountingAllocator allocator; | 296 v8::internal::AccountingAllocator allocator; |
| 297 Zone zone(&allocator); | 297 Zone zone(&allocator, ZONE_NAME); |
| 298 | 298 |
| 299 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 299 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 300 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 300 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 301 ExportAsMain(f); | 301 ExportAsMain(f); |
| 302 byte code[] = {WASM_GROW_MEMORY(WASM_I8(10)), WASM_DROP, WASM_MEMORY_SIZE}; | 302 byte code[] = {WASM_GROW_MEMORY(WASM_I8(10)), WASM_DROP, WASM_MEMORY_SIZE}; |
| 303 f->EmitCode(code, sizeof(code)); | 303 f->EmitCode(code, sizeof(code)); |
| 304 TestModule(&zone, builder, kExpectedValue); | 304 TestModule(&zone, builder, kExpectedValue); |
| 305 } | 305 } |
| 306 | 306 |
| 307 TEST(GrowMemoryZero) { | 307 TEST(GrowMemoryZero) { |
| 308 // Initial memory size is 16, see wasm-module-builder.cc | 308 // Initial memory size is 16, see wasm-module-builder.cc |
| 309 static const int kExpectedValue = 16; | 309 static const int kExpectedValue = 16; |
| 310 TestSignatures sigs; | 310 TestSignatures sigs; |
| 311 v8::internal::AccountingAllocator allocator; | 311 v8::internal::AccountingAllocator allocator; |
| 312 Zone zone(&allocator); | 312 Zone zone(&allocator, ZONE_NAME); |
| 313 | 313 |
| 314 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 314 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 315 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 315 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 316 ExportAsMain(f); | 316 ExportAsMain(f); |
| 317 byte code[] = {WASM_GROW_MEMORY(WASM_I32V(0))}; | 317 byte code[] = {WASM_GROW_MEMORY(WASM_I32V(0))}; |
| 318 f->EmitCode(code, sizeof(code)); | 318 f->EmitCode(code, sizeof(code)); |
| 319 TestModule(&zone, builder, kExpectedValue); | 319 TestModule(&zone, builder, kExpectedValue); |
| 320 } | 320 } |
| 321 | 321 |
| 322 class InterruptThread : public v8::base::Thread { | 322 class InterruptThread : public v8::base::Thread { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // Test setup: | 354 // Test setup: |
| 355 // The main thread executes a WebAssembly function with a loop. In the loop | 355 // The main thread executes a WebAssembly function with a loop. In the loop |
| 356 // {signal_value_} is written to memory to signal a helper thread that the | 356 // {signal_value_} is written to memory to signal a helper thread that the |
| 357 // main thread reached the loop in the WebAssembly program. When the helper | 357 // main thread reached the loop in the WebAssembly program. When the helper |
| 358 // thread reads {signal_value_} from memory, it registers the | 358 // thread reads {signal_value_} from memory, it registers the |
| 359 // InterruptCallback. Upon exeution, the InterruptCallback write into the | 359 // InterruptCallback. Upon exeution, the InterruptCallback write into the |
| 360 // WebAssemblyMemory to end the loop in the WebAssembly program. | 360 // WebAssemblyMemory to end the loop in the WebAssembly program. |
| 361 TestSignatures sigs; | 361 TestSignatures sigs; |
| 362 Isolate* isolate = CcTest::InitIsolateOnce(); | 362 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 363 v8::internal::AccountingAllocator allocator; | 363 v8::internal::AccountingAllocator allocator; |
| 364 Zone zone(&allocator); | 364 Zone zone(&allocator, ZONE_NAME); |
| 365 | 365 |
| 366 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 366 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 367 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 367 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 368 ExportAsMain(f); | 368 ExportAsMain(f); |
| 369 byte code[] = {WASM_LOOP(WASM_IFB( | 369 byte code[] = {WASM_LOOP(WASM_IFB( |
| 370 WASM_NOT(WASM_LOAD_MEM( | 370 WASM_NOT(WASM_LOAD_MEM( |
| 371 MachineType::Int32(), | 371 MachineType::Int32(), |
| 372 WASM_I32V(InterruptThread::interrupt_location_ * 4))), | 372 WASM_I32V(InterruptThread::interrupt_location_ * 4))), |
| 373 WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, | 373 WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, |
| 374 WASM_I32V(InterruptThread::signal_value_)), | 374 WASM_I32V(InterruptThread::signal_value_)), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 396 thread.Start(); | 396 thread.Start(); |
| 397 testing::RunWasmModuleForTesting(isolate, instance, 0, nullptr, | 397 testing::RunWasmModuleForTesting(isolate, instance, 0, nullptr, |
| 398 ModuleOrigin::kWasmOrigin); | 398 ModuleOrigin::kWasmOrigin); |
| 399 CHECK_EQ(InterruptThread::interrupt_value_, | 399 CHECK_EQ(InterruptThread::interrupt_value_, |
| 400 memory_array[InterruptThread::interrupt_location_]); | 400 memory_array[InterruptThread::interrupt_location_]); |
| 401 } | 401 } |
| 402 | 402 |
| 403 TEST(Run_WasmModule_GrowMemoryInIf) { | 403 TEST(Run_WasmModule_GrowMemoryInIf) { |
| 404 TestSignatures sigs; | 404 TestSignatures sigs; |
| 405 v8::internal::AccountingAllocator allocator; | 405 v8::internal::AccountingAllocator allocator; |
| 406 Zone zone(&allocator); | 406 Zone zone(&allocator, ZONE_NAME); |
| 407 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 407 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 408 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 408 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 409 ExportAsMain(f); | 409 ExportAsMain(f); |
| 410 byte code[] = {WASM_IF_ELSE_I(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), | 410 byte code[] = {WASM_IF_ELSE_I(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), |
| 411 WASM_I32V(12))}; | 411 WASM_I32V(12))}; |
| 412 f->EmitCode(code, sizeof(code)); | 412 f->EmitCode(code, sizeof(code)); |
| 413 TestModule(&zone, builder, 12); | 413 TestModule(&zone, builder, 12); |
| 414 } | 414 } |
| 415 | 415 |
| 416 TEST(Run_WasmModule_GrowMemOobOffset) { | 416 TEST(Run_WasmModule_GrowMemOobOffset) { |
| 417 static const int kPageSize = 0x10000; | 417 static const int kPageSize = 0x10000; |
| 418 // Initial memory size = 16 + GrowMemory(10) | 418 // Initial memory size = 16 + GrowMemory(10) |
| 419 static const int index = kPageSize * 17 + 4; | 419 static const int index = kPageSize * 17 + 4; |
| 420 int value = 0xaced; | 420 int value = 0xaced; |
| 421 TestSignatures sigs; | 421 TestSignatures sigs; |
| 422 v8::internal::AccountingAllocator allocator; | 422 v8::internal::AccountingAllocator allocator; |
| 423 Zone zone(&allocator); | 423 Zone zone(&allocator, ZONE_NAME); |
| 424 | 424 |
| 425 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 425 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 426 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 426 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
| 427 ExportAsMain(f); | 427 ExportAsMain(f); |
| 428 byte code[] = { | 428 byte code[] = { |
| 429 WASM_GROW_MEMORY(WASM_I8(1)), | 429 WASM_GROW_MEMORY(WASM_I8(1)), |
| 430 WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), WASM_I32V(value))}; | 430 WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), WASM_I32V(value))}; |
| 431 f->EmitCode(code, sizeof(code)); | 431 f->EmitCode(code, sizeof(code)); |
| 432 TestModuleException(&zone, builder); | 432 TestModuleException(&zone, builder); |
| 433 } | 433 } |
| 434 | 434 |
| 435 TEST(Run_WasmModule_GrowMemOobFixedIndex) { | 435 TEST(Run_WasmModule_GrowMemOobFixedIndex) { |
| 436 static const int kPageSize = 0x10000; | 436 static const int kPageSize = 0x10000; |
| 437 // Initial memory size = 16 + GrowMemory(10) | 437 // Initial memory size = 16 + GrowMemory(10) |
| 438 static const int index = kPageSize * 26 + 4; | 438 static const int index = kPageSize * 26 + 4; |
| 439 int value = 0xaced; | 439 int value = 0xaced; |
| 440 TestSignatures sigs; | 440 TestSignatures sigs; |
| 441 Isolate* isolate = CcTest::InitIsolateOnce(); | 441 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 442 Zone zone(isolate->allocator()); | 442 Zone zone(isolate->allocator(), ZONE_NAME); |
| 443 | 443 |
| 444 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 444 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 445 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); | 445 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); |
| 446 ExportAsMain(f); | 446 ExportAsMain(f); |
| 447 byte code[] = { | 447 byte code[] = { |
| 448 WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP, | 448 WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP, |
| 449 WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), WASM_I32V(value)), | 449 WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), WASM_I32V(value)), |
| 450 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index))}; | 450 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index))}; |
| 451 f->EmitCode(code, sizeof(code)); | 451 f->EmitCode(code, sizeof(code)); |
| 452 | 452 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 477 isolate, instance, 1, params, ModuleOrigin::kWasmOrigin); | 477 isolate, instance, 1, params, ModuleOrigin::kWasmOrigin); |
| 478 CHECK(result == 0xaced); | 478 CHECK(result == 0xaced); |
| 479 } | 479 } |
| 480 | 480 |
| 481 TEST(Run_WasmModule_GrowMemOobVariableIndex) { | 481 TEST(Run_WasmModule_GrowMemOobVariableIndex) { |
| 482 static const int kPageSize = 0x10000; | 482 static const int kPageSize = 0x10000; |
| 483 int value = 0xaced; | 483 int value = 0xaced; |
| 484 TestSignatures sigs; | 484 TestSignatures sigs; |
| 485 Isolate* isolate = CcTest::InitIsolateOnce(); | 485 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 486 v8::internal::AccountingAllocator allocator; | 486 v8::internal::AccountingAllocator allocator; |
| 487 Zone zone(&allocator); | 487 Zone zone(&allocator, ZONE_NAME); |
| 488 | 488 |
| 489 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 489 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 490 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); | 490 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); |
| 491 ExportAsMain(f); | 491 ExportAsMain(f); |
| 492 byte code[] = { | 492 byte code[] = { |
| 493 WASM_GROW_MEMORY(WASM_I8(1)), WASM_DROP, | 493 WASM_GROW_MEMORY(WASM_I8(1)), WASM_DROP, |
| 494 WASM_STORE_MEM(MachineType::Int32(), WASM_GET_LOCAL(0), WASM_I32V(value)), | 494 WASM_STORE_MEM(MachineType::Int32(), WASM_GET_LOCAL(0), WASM_I32V(value)), |
| 495 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))}; | 495 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))}; |
| 496 f->EmitCode(code, sizeof(code)); | 496 f->EmitCode(code, sizeof(code)); |
| 497 | 497 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 Handle<Object> params[1] = { | 531 Handle<Object> params[1] = { |
| 532 Handle<Object>(Smi::FromInt(25 * kPageSize), isolate)}; | 532 Handle<Object>(Smi::FromInt(25 * kPageSize), isolate)}; |
| 533 testing::RunWasmModuleForTesting(isolate, instance, 1, params, | 533 testing::RunWasmModuleForTesting(isolate, instance, 1, params, |
| 534 ModuleOrigin::kWasmOrigin); | 534 ModuleOrigin::kWasmOrigin); |
| 535 CHECK(try_catch.HasCaught()); | 535 CHECK(try_catch.HasCaught()); |
| 536 isolate->clear_pending_exception(); | 536 isolate->clear_pending_exception(); |
| 537 } | 537 } |
| 538 | 538 |
| 539 TEST(Run_WasmModule_Global_init) { | 539 TEST(Run_WasmModule_Global_init) { |
| 540 v8::internal::AccountingAllocator allocator; | 540 v8::internal::AccountingAllocator allocator; |
| 541 Zone zone(&allocator); | 541 Zone zone(&allocator, ZONE_NAME); |
| 542 TestSignatures sigs; | 542 TestSignatures sigs; |
| 543 | 543 |
| 544 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 544 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 545 uint32_t global1 = | 545 uint32_t global1 = |
| 546 builder->AddGlobal(kAstI32, false, false, WasmInitExpr(777777)); | 546 builder->AddGlobal(kAstI32, false, false, WasmInitExpr(777777)); |
| 547 uint32_t global2 = | 547 uint32_t global2 = |
| 548 builder->AddGlobal(kAstI32, false, false, WasmInitExpr(222222)); | 548 builder->AddGlobal(kAstI32, false, false, WasmInitExpr(222222)); |
| 549 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); | 549 WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); |
| 550 byte code[] = { | 550 byte code[] = { |
| 551 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; | 551 WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; |
| 552 f1->EmitCode(code, sizeof(code)); | 552 f1->EmitCode(code, sizeof(code)); |
| 553 ExportAsMain(f1); | 553 ExportAsMain(f1); |
| 554 TestModule(&zone, builder, 999999); | 554 TestModule(&zone, builder, 999999); |
| 555 } | 555 } |
| 556 | 556 |
| 557 template <typename CType> | 557 template <typename CType> |
| 558 static void RunWasmModuleGlobalInitTest(LocalType type, CType expected) { | 558 static void RunWasmModuleGlobalInitTest(LocalType type, CType expected) { |
| 559 v8::internal::AccountingAllocator allocator; | 559 v8::internal::AccountingAllocator allocator; |
| 560 Zone zone(&allocator); | 560 Zone zone(&allocator, ZONE_NAME); |
| 561 TestSignatures sigs; | 561 TestSignatures sigs; |
| 562 | 562 |
| 563 LocalType types[] = {type}; | 563 LocalType types[] = {type}; |
| 564 FunctionSig sig(1, 0, types); | 564 FunctionSig sig(1, 0, types); |
| 565 | 565 |
| 566 for (int padding = 0; padding < 5; padding++) { | 566 for (int padding = 0; padding < 5; padding++) { |
| 567 // Test with a simple initializer | 567 // Test with a simple initializer |
| 568 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 568 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 569 | 569 |
| 570 for (int i = 0; i < padding; i++) { // pad global before | 570 for (int i = 0; i < padding; i++) { // pad global before |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 | 619 |
| 620 TEST(Run_WasmModule_Global_f32) { | 620 TEST(Run_WasmModule_Global_f32) { |
| 621 RunWasmModuleGlobalInitTest<float>(kAstF32, -983.9f); | 621 RunWasmModuleGlobalInitTest<float>(kAstF32, -983.9f); |
| 622 RunWasmModuleGlobalInitTest<float>(kAstF32, 1122.99f); | 622 RunWasmModuleGlobalInitTest<float>(kAstF32, 1122.99f); |
| 623 } | 623 } |
| 624 | 624 |
| 625 TEST(Run_WasmModule_Global_f64) { | 625 TEST(Run_WasmModule_Global_f64) { |
| 626 RunWasmModuleGlobalInitTest<double>(kAstF64, -833.9); | 626 RunWasmModuleGlobalInitTest<double>(kAstF64, -833.9); |
| 627 RunWasmModuleGlobalInitTest<double>(kAstF64, 86374.25); | 627 RunWasmModuleGlobalInitTest<double>(kAstF64, 86374.25); |
| 628 } | 628 } |
| OLD | NEW |