| 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/wasm/encoder.h" | 8 #include "src/wasm/encoder.h" |
| 9 #include "src/wasm/wasm-macro-gen.h" | 9 #include "src/wasm/wasm-macro-gen.h" |
| 10 #include "src/wasm/wasm-module.h" | 10 #include "src/wasm/wasm-module.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kDataSegmentDest0))}; | 105 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kDataSegmentDest0))}; |
| 106 f->EmitCode(code, sizeof(code)); | 106 f->EmitCode(code, sizeof(code)); |
| 107 byte data[] = {0xaa, 0xbb, 0xcc, 0xdd}; | 107 byte data[] = {0xaa, 0xbb, 0xcc, 0xdd}; |
| 108 builder->AddDataSegment(new (&zone) WasmDataSegmentEncoder( | 108 builder->AddDataSegment(new (&zone) WasmDataSegmentEncoder( |
| 109 &zone, data, sizeof(data), kDataSegmentDest0)); | 109 &zone, data, sizeof(data), kDataSegmentDest0)); |
| 110 WasmModuleWriter* writer = builder->Build(&zone); | 110 WasmModuleWriter* writer = builder->Build(&zone); |
| 111 TestModule(writer->WriteTo(&zone), 0xddccbbaa); | 111 TestModule(writer->WriteTo(&zone), 0xddccbbaa); |
| 112 } | 112 } |
| 113 | 113 |
| 114 | 114 |
| 115 #if defined(__has_feature) |
| 116 #if __has_feature(address_sanitizer) |
| 117 #define V8_WITH_ASAN 1 |
| 118 #endif |
| 119 #endif |
| 120 |
| 121 |
| 122 #if !defined(V8_WITH_ASAN) |
| 123 // TODO(bradnelson): Figure out why this crashes under asan. |
| 115 TEST(Run_WasmModule_CheckMemoryIsZero) { | 124 TEST(Run_WasmModule_CheckMemoryIsZero) { |
| 116 static const int kCheckSize = 16 * 1024; | 125 static const int kCheckSize = 16 * 1024; |
| 117 Zone zone; | 126 Zone zone; |
| 118 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 127 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 119 uint16_t f_index = builder->AddFunction(); | 128 uint16_t f_index = builder->AddFunction(); |
| 120 WasmFunctionBuilder* f = builder->FunctionAt(f_index); | 129 WasmFunctionBuilder* f = builder->FunctionAt(f_index); |
| 121 f->ReturnType(kAstI32); | 130 f->ReturnType(kAstI32); |
| 122 uint16_t localIndex = f->AddLocal(kAstI32); | 131 uint16_t localIndex = f->AddLocal(kAstI32); |
| 123 f->Exported(1); | 132 f->Exported(1); |
| 124 byte code[] = {WASM_BLOCK( | 133 byte code[] = {WASM_BLOCK( |
| 125 2, | 134 2, |
| 126 WASM_WHILE( | 135 WASM_WHILE( |
| 127 WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32(kCheckSize)), | 136 WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32(kCheckSize)), |
| 128 WASM_IF_ELSE( | 137 WASM_IF_ELSE( |
| 129 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)), | 138 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)), |
| 130 WASM_BRV(2, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))), | 139 WASM_BRV(2, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))), |
| 131 WASM_I8(11))}; | 140 WASM_I8(11))}; |
| 132 uint32_t local_indices[] = {7, 19, 25, 28}; | 141 uint32_t local_indices[] = {7, 19, 25, 28}; |
| 133 f->EmitCode(code, sizeof(code), local_indices, sizeof(local_indices) / 4); | 142 f->EmitCode(code, sizeof(code), local_indices, sizeof(local_indices) / 4); |
| 134 WasmModuleWriter* writer = builder->Build(&zone); | 143 WasmModuleWriter* writer = builder->Build(&zone); |
| 135 TestModule(writer->WriteTo(&zone), 11); | 144 TestModule(writer->WriteTo(&zone), 11); |
| 136 } | 145 } |
| 146 #endif |
| 137 | 147 |
| 138 | 148 |
| 149 #if !defined(V8_WITH_ASAN) |
| 150 // TODO(bradnelson): Figure out why this crashes under asan. |
| 139 TEST(Run_WasmModule_CallMain_recursive) { | 151 TEST(Run_WasmModule_CallMain_recursive) { |
| 140 Zone zone; | 152 Zone zone; |
| 141 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 153 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 142 uint16_t f_index = builder->AddFunction(); | 154 uint16_t f_index = builder->AddFunction(); |
| 143 WasmFunctionBuilder* f = builder->FunctionAt(f_index); | 155 WasmFunctionBuilder* f = builder->FunctionAt(f_index); |
| 144 f->ReturnType(kAstI32); | 156 f->ReturnType(kAstI32); |
| 145 uint16_t localIndex = f->AddLocal(kAstI32); | 157 uint16_t localIndex = f->AddLocal(kAstI32); |
| 146 f->Exported(1); | 158 f->Exported(1); |
| 147 byte code[] = {WASM_BLOCK( | 159 byte code[] = {WASM_BLOCK( |
| 148 2, WASM_SET_LOCAL(localIndex, | 160 2, WASM_SET_LOCAL(localIndex, |
| 149 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), | 161 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), |
| 150 WASM_IF_ELSE(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I8(5)), | 162 WASM_IF_ELSE(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I8(5)), |
| 151 WASM_BLOCK(2, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, | 163 WASM_BLOCK(2, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, |
| 152 WASM_INC_LOCAL(localIndex)), | 164 WASM_INC_LOCAL(localIndex)), |
| 153 WASM_BRV(1, WASM_CALL_FUNCTION0(0))), | 165 WASM_BRV(1, WASM_CALL_FUNCTION0(0))), |
| 154 WASM_BRV(0, WASM_I8(55))))}; | 166 WASM_BRV(0, WASM_I8(55))))}; |
| 155 uint32_t local_indices[] = {3, 11, 21, 24}; | 167 uint32_t local_indices[] = {3, 11, 21, 24}; |
| 156 f->EmitCode(code, sizeof(code), local_indices, sizeof(local_indices) / 4); | 168 f->EmitCode(code, sizeof(code), local_indices, sizeof(local_indices) / 4); |
| 157 WasmModuleWriter* writer = builder->Build(&zone); | 169 WasmModuleWriter* writer = builder->Build(&zone); |
| 158 TestModule(writer->WriteTo(&zone), 55); | 170 TestModule(writer->WriteTo(&zone), 55); |
| 159 } | 171 } |
| 172 #endif |
| 160 | 173 |
| 161 | 174 |
| 175 #if !defined(V8_WITH_ASAN) |
| 176 // TODO(bradnelson): Figure out why this crashes under asan. |
| 162 TEST(Run_WasmModule_Global) { | 177 TEST(Run_WasmModule_Global) { |
| 163 Zone zone; | 178 Zone zone; |
| 164 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 179 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 165 uint32_t global1 = builder->AddGlobal(MachineType::Int32(), 0); | 180 uint32_t global1 = builder->AddGlobal(MachineType::Int32(), 0); |
| 166 uint32_t global2 = builder->AddGlobal(MachineType::Int32(), 0); | 181 uint32_t global2 = builder->AddGlobal(MachineType::Int32(), 0); |
| 167 uint16_t f1_index = builder->AddFunction(); | 182 uint16_t f1_index = builder->AddFunction(); |
| 168 WasmFunctionBuilder* f = builder->FunctionAt(f1_index); | 183 WasmFunctionBuilder* f = builder->FunctionAt(f1_index); |
| 169 f->ReturnType(kAstI32); | 184 f->ReturnType(kAstI32); |
| 170 byte code1[] = { | 185 byte code1[] = { |
| 171 WASM_I32_ADD(WASM_LOAD_GLOBAL(global1), WASM_LOAD_GLOBAL(global2))}; | 186 WASM_I32_ADD(WASM_LOAD_GLOBAL(global1), WASM_LOAD_GLOBAL(global2))}; |
| 172 f->EmitCode(code1, sizeof(code1)); | 187 f->EmitCode(code1, sizeof(code1)); |
| 173 uint16_t f2_index = builder->AddFunction(); | 188 uint16_t f2_index = builder->AddFunction(); |
| 174 f = builder->FunctionAt(f2_index); | 189 f = builder->FunctionAt(f2_index); |
| 175 f->ReturnType(kAstI32); | 190 f->ReturnType(kAstI32); |
| 176 f->Exported(1); | 191 f->Exported(1); |
| 177 byte code2[] = {WASM_STORE_GLOBAL(global1, WASM_I32(56)), | 192 byte code2[] = {WASM_STORE_GLOBAL(global1, WASM_I32(56)), |
| 178 WASM_STORE_GLOBAL(global2, WASM_I32(41)), | 193 WASM_STORE_GLOBAL(global2, WASM_I32(41)), |
| 179 WASM_RETURN(WASM_CALL_FUNCTION0(f1_index))}; | 194 WASM_RETURN(WASM_CALL_FUNCTION0(f1_index))}; |
| 180 f->EmitCode(code2, sizeof(code2)); | 195 f->EmitCode(code2, sizeof(code2)); |
| 181 WasmModuleWriter* writer = builder->Build(&zone); | 196 WasmModuleWriter* writer = builder->Build(&zone); |
| 182 TestModule(writer->WriteTo(&zone), 97); | 197 TestModule(writer->WriteTo(&zone), 97); |
| 183 } | 198 } |
| 199 #endif |
| OLD | NEW |