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

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

Issue 1571703002: [wasm] Fix MSAN failures for some WASM tests. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h> 5 #include <stdint.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "src/base/utils/random-number-generator.h" 9 #include "src/base/utils/random-number-generator.h"
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 class TestingModule : public ModuleEnv { 64 class TestingModule : public ModuleEnv {
65 public: 65 public:
66 TestingModule() : mem_size(0), global_offset(0) { 66 TestingModule() : mem_size(0), global_offset(0) {
67 globals_area = 0; 67 globals_area = 0;
68 mem_start = 0; 68 mem_start = 0;
69 mem_end = 0; 69 mem_end = 0;
70 module = nullptr; 70 module = nullptr;
71 linker = nullptr; 71 linker = nullptr;
72 function_code = nullptr; 72 function_code = nullptr;
73 asm_js = false; 73 asm_js = false;
74 memset(global_data, 0, sizeof(global_data));
74 } 75 }
75 76
76 ~TestingModule() { 77 ~TestingModule() {
77 if (mem_start) { 78 if (mem_start) {
78 free(raw_mem_start<byte>()); 79 free(raw_mem_start<byte>());
79 } 80 }
80 if (function_code) delete function_code; 81 if (function_code) delete function_code;
81 if (module) delete module; 82 if (module) delete module;
82 } 83 }
83 84
(...skipping 2034 matching lines...) Expand 10 before | Expand all | Expand 10 after
2118 BUILD(r, kExprBlock, 2, kExprLoop, 1, kExprIf, kExprGetLocal, 0, kExprBr, 0, 2119 BUILD(r, kExprBlock, 2, kExprLoop, 1, kExprIf, kExprGetLocal, 0, kExprBr, 0,
2119 kExprIfElse, kExprI32LoadMem, 0, kExprGetLocal, 0, kExprBr, 2, 2120 kExprIfElse, kExprI32LoadMem, 0, kExprGetLocal, 0, kExprBr, 2,
2120 kExprI8Const, 255, kExprSetLocal, 0, kExprI32Sub, kExprGetLocal, 0, 2121 kExprI8Const, 255, kExprSetLocal, 0, kExprI32Sub, kExprGetLocal, 0,
2121 kExprI8Const, 4, kExprI8Const, 0); 2122 kExprI8Const, 4, kExprI8Const, 0);
2122 2123
2123 module.BlankMemory(); 2124 module.BlankMemory();
2124 CHECK_EQ(0, r.Call((kNumElems - 1) * 4)); 2125 CHECK_EQ(0, r.Call((kNumElems - 1) * 4));
2125 } 2126 }
2126 2127
2127 2128
2128 // TODO(titzer): Fix for msan and re-enable.
2129 #if 0
2130
2131 TEST(Run_Wasm_MemF32_Sum) { 2129 TEST(Run_Wasm_MemF32_Sum) {
2132 WasmRunner<int32_t> r(MachineType::Int32()); 2130 WasmRunner<int32_t> r(MachineType::Int32());
2133 const byte kSum = r.AllocateLocal(kAstF32); 2131 const byte kSum = r.AllocateLocal(kAstF32);
2134 ModuleEnv module;
2135 const int kSize = 5; 2132 const int kSize = 5;
2136 float buffer[kSize] = {-99.25, -888.25, -77.25, 66666.25, 5555.25}; 2133 TestingModule module;
2137 module.mem_start = reinterpret_cast<uintptr_t>(&buffer); 2134 module.AddMemoryElems<float>(kSize);
2138 module.mem_end = reinterpret_cast<uintptr_t>(&buffer[kSize]); 2135 float* buffer = module.raw_mem_start<float>();
2136 buffer[0] = -99.25;
2137 buffer[1] = -888.25;
2138 buffer[2] = -77.25;
2139 buffer[3] = 66666.25;
2140 buffer[4] = 5555.25;
2139 r.env()->module = &module; 2141 r.env()->module = &module;
2140 2142
2141 BUILD(r, WASM_BLOCK( 2143 BUILD(r, WASM_BLOCK(
2142 3, WASM_WHILE( 2144 3, WASM_WHILE(
2143 WASM_GET_LOCAL(0), 2145 WASM_GET_LOCAL(0),
2144 WASM_BLOCK( 2146 WASM_BLOCK(
2145 2, WASM_SET_LOCAL( 2147 2, WASM_SET_LOCAL(
2146 kSum, WASM_F32_ADD( 2148 kSum, WASM_F32_ADD(
2147 WASM_GET_LOCAL(kSum), 2149 WASM_GET_LOCAL(kSum),
2148 WASM_LOAD_MEM(MachineType::Float32(), 2150 WASM_LOAD_MEM(MachineType::Float32(),
2149 WASM_GET_LOCAL(0)))), 2151 WASM_GET_LOCAL(0)))),
2150 WASM_SET_LOCAL( 2152 WASM_SET_LOCAL(
2151 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), 2153 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))),
2152 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, 2154 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO,
2153 WASM_GET_LOCAL(kSum)), 2155 WASM_GET_LOCAL(kSum)),
2154 WASM_GET_LOCAL(0))); 2156 WASM_GET_LOCAL(0)));
2155 2157
2156 CHECK_EQ(0, r.Call(4 * (kSize - 1))); 2158 CHECK_EQ(0, r.Call(4 * (kSize - 1)));
2157 CHECK_NE(-99.25, buffer[0]); 2159 CHECK_NE(-99.25, buffer[0]);
2158 CHECK_EQ(71256.0f, buffer[0]); 2160 CHECK_EQ(71256.0f, buffer[0]);
2159 } 2161 }
2160 2162
2161 #endif
2162
2163 2163
2164 #if WASM_64 2164 #if WASM_64
2165 TEST(Run_Wasm_MemI64_Sum) { 2165 TEST(Run_Wasm_MemI64_Sum) {
2166 WasmRunner<uint64_t> r(MachineType::Int32()); 2166 WasmRunner<uint64_t> r(MachineType::Int32());
2167 const int kNumElems = 20; 2167 const int kNumElems = 20;
2168 const byte kSum = r.AllocateLocal(kAstI64); 2168 const byte kSum = r.AllocateLocal(kAstI64);
2169 TestingModule module; 2169 TestingModule module;
2170 uint64_t* memory = module.AddMemoryElems<uint64_t>(kNumElems); 2170 uint64_t* memory = module.AddMemoryElems<uint64_t>(kNumElems);
2171 r.env()->module = &module; 2171 r.env()->module = &module;
2172 2172
(...skipping 17 matching lines...) Expand all
2190 for (size_t j = kNumElems - 1; j > 0; j--) { 2190 for (size_t j = kNumElems - 1; j > 0; j--) {
2191 expected += memory[j]; 2191 expected += memory[j];
2192 } 2192 }
2193 uint64_t result = r.Call(8 * (kNumElems - 1)); 2193 uint64_t result = r.Call(8 * (kNumElems - 1));
2194 CHECK_EQ(expected, result); 2194 CHECK_EQ(expected, result);
2195 } 2195 }
2196 } 2196 }
2197 #endif 2197 #endif
2198 2198
2199 2199
2200 // TODO(titzer): Fix for msan and re-enable.
2201 #if 0
2202
2203 template <typename T> 2200 template <typename T>
2204 void GenerateAndRunFold(WasmOpcode binop, T* buffer, size_t size, 2201 T GenerateAndRunFold(WasmOpcode binop, T* buffer, size_t size,
2205 LocalType astType, MachineType memType) { 2202 LocalType astType, MachineType memType) {
2206 WasmRunner<int32_t> r(MachineType::Int32()); 2203 WasmRunner<int32_t> r(MachineType::Int32());
2207 const byte kAccum = r.AllocateLocal(astType); 2204 const byte kAccum = r.AllocateLocal(astType);
2208 ModuleEnv module; 2205 TestingModule module;
2209 module.mem_start = reinterpret_cast<uintptr_t>(buffer); 2206 module.AddMemoryElems<T>(size);
2210 module.mem_end = reinterpret_cast<uintptr_t>(buffer + size); 2207 for (size_t i = 0; i < size; i++) {
2208 module.raw_mem_start<T>()[i] = buffer[i];
2209 }
2211 r.env()->module = &module; 2210 r.env()->module = &module;
2212 2211
2213 BUILD( 2212 BUILD(
2214 r, 2213 r,
2215 WASM_BLOCK( 2214 WASM_BLOCK(
2216 4, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)), 2215 4, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)),
2217 WASM_WHILE( 2216 WASM_WHILE(
2218 WASM_GET_LOCAL(0), 2217 WASM_GET_LOCAL(0),
2219 WASM_BLOCK( 2218 WASM_BLOCK(
2220 2, WASM_SET_LOCAL( 2219 2, WASM_SET_LOCAL(
2221 kAccum, 2220 kAccum,
2222 WASM_BINOP(binop, WASM_GET_LOCAL(kAccum), 2221 WASM_BINOP(binop, WASM_GET_LOCAL(kAccum),
2223 WASM_LOAD_MEM(memType, WASM_GET_LOCAL(0)))), 2222 WASM_LOAD_MEM(memType, WASM_GET_LOCAL(0)))),
2224 WASM_SET_LOCAL( 2223 WASM_SET_LOCAL(
2225 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(sizeof(T)))))), 2224 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(sizeof(T)))))),
2226 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)), 2225 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)),
2227 WASM_GET_LOCAL(0))); 2226 WASM_GET_LOCAL(0)));
2228 r.Call(static_cast<int>(sizeof(T) * (size - 1))); 2227 r.Call(static_cast<int>(sizeof(T) * (size - 1)));
2228 return module.raw_mem_at<double>(0);
2229 } 2229 }
2230 2230
2231 2231
2232 TEST(Run_Wasm_MemF64_Mul) { 2232 TEST(Run_Wasm_MemF64_Mul) {
2233 const size_t kSize = 6; 2233 const size_t kSize = 6;
2234 double buffer[kSize] = {1, 2, 2, 2, 2, 2}; 2234 double buffer[kSize] = {1, 2, 2, 2, 2, 2};
2235 GenerateAndRunFold<double>(kExprF64Mul, buffer, kSize, kAstF64, 2235 double result = GenerateAndRunFold<double>(kExprF64Mul, buffer, kSize,
2236 MachineType::Float64()); 2236 kAstF64, MachineType::Float64());
2237 CHECK_EQ(32, buffer[0]); 2237 CHECK_EQ(32, result);
2238 } 2238 }
2239 2239
2240 #endif
2241
2242 2240
2243 TEST(Build_Wasm_Infinite_Loop) { 2241 TEST(Build_Wasm_Infinite_Loop) {
2244 WasmRunner<int32_t> r(MachineType::Int32()); 2242 WasmRunner<int32_t> r(MachineType::Int32());
2245 // Only build the graph and compile, don't run. 2243 // Only build the graph and compile, don't run.
2246 BUILD(r, WASM_INFINITE_LOOP); 2244 BUILD(r, WASM_INFINITE_LOOP);
2247 } 2245 }
2248 2246
2249 2247
2250 TEST(Build_Wasm_Infinite_Loop_effect) { 2248 TEST(Build_Wasm_Infinite_Loop_effect) {
2251 WasmRunner<int32_t> r(MachineType::Int32()); 2249 WasmRunner<int32_t> r(MachineType::Int32());
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2459 2457
2460 *global = 116; 2458 *global = 116;
2461 for (int i = 9; i < 444444; i += 111111) { 2459 for (int i = 9; i < 444444; i += 111111) {
2462 int32_t expected = *global + i; 2460 int32_t expected = *global + i;
2463 r.Call(i); 2461 r.Call(i);
2464 CHECK_EQ(expected, *global); 2462 CHECK_EQ(expected, *global);
2465 } 2463 }
2466 } 2464 }
2467 2465
2468 2466
2469 // TODO(titzer): Fix for msan and re-enable.
2470 #if 0
2471
2472 TEST(Run_WasmInt32Globals_DontAlias) { 2467 TEST(Run_WasmInt32Globals_DontAlias) {
2473 const int kNumGlobals = 3; 2468 const int kNumGlobals = 3;
2474 TestingModule module; 2469 TestingModule module;
2475 int32_t* globals[] = {module.AddGlobal<int32_t>(MachineType::Int32()), 2470 int32_t* globals[] = {module.AddGlobal<int32_t>(MachineType::Int32()),
2476 module.AddGlobal<int32_t>(MachineType::Int32()), 2471 module.AddGlobal<int32_t>(MachineType::Int32()),
2477 module.AddGlobal<int32_t>(MachineType::Int32())}; 2472 module.AddGlobal<int32_t>(MachineType::Int32())};
2478 2473
2479 for (int g = 0; g < kNumGlobals; g++) { 2474 for (int g = 0; g < kNumGlobals; g++) {
2480 // global = global + p0 2475 // global = global + p0
2481 WasmRunner<int32_t> r(MachineType::Int32()); 2476 WasmRunner<int32_t> r(MachineType::Int32());
2482 r.env()->module = &module; 2477 r.env()->module = &module;
2483 BUILD(r, WASM_STORE_GLOBAL( 2478 BUILD(r, WASM_STORE_GLOBAL(
2484 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0)))); 2479 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0))));
2485 2480
2486 // Check that reading/writing global number {g} doesn't alter the others. 2481 // Check that reading/writing global number {g} doesn't alter the others.
2487 *globals[g] = 116 * g; 2482 *globals[g] = 116 * g;
2488 int32_t before[kNumGlobals]; 2483 int32_t before[kNumGlobals];
2489 for (int i = 9; i < 444444; i += 111113) { 2484 for (int i = 9; i < 444444; i += 111113) {
2490 int32_t sum = *globals[g] + i; 2485 int32_t sum = *globals[g] + i;
2491 for (int j = 0; j < kNumGlobals; j++) before[j] = *globals[j]; 2486 for (int j = 0; j < kNumGlobals; j++) before[j] = *globals[j];
2492 r.Call(i); 2487 r.Call(i);
2493 for (int j = 0; j < kNumGlobals; j++) { 2488 for (int j = 0; j < kNumGlobals; j++) {
2494 int32_t expected = j == g ? sum : before[j]; 2489 int32_t expected = j == g ? sum : before[j];
2495 CHECK_EQ(expected, *globals[j]); 2490 CHECK_EQ(expected, *globals[j]);
2496 } 2491 }
2497 } 2492 }
2498 } 2493 }
2499 } 2494 }
2500 2495
2501 #endif
2502
2503 2496
2504 #if WASM_64 2497 #if WASM_64
2505 TEST(Run_WasmInt64Global) { 2498 TEST(Run_WasmInt64Global) {
2506 TestingModule module; 2499 TestingModule module;
2507 int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64()); 2500 int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64());
2508 WasmRunner<int32_t> r(MachineType::Int32()); 2501 WasmRunner<int32_t> r(MachineType::Int32());
2509 r.env()->module = &module; 2502 r.env()->module = &module;
2510 // global = global + p0 2503 // global = global + p0
2511 BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL( 2504 BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL(
2512 0, WASM_I64_ADD( 2505 0, WASM_I64_ADD(
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3616 TEST(Run_Wasm_F32CopySign) { 3609 TEST(Run_Wasm_F32CopySign) {
3617 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); 3610 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32());
3618 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 3611 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
3619 3612
3620 FOR_FLOAT32_INPUTS(i) { 3613 FOR_FLOAT32_INPUTS(i) {
3621 FOR_FLOAT32_INPUTS(j) { CheckFloatEq(copysign(*i, *j), r.Call(*i, *j)); } 3614 FOR_FLOAT32_INPUTS(j) { CheckFloatEq(copysign(*i, *j), r.Call(*i, *j)); }
3622 } 3615 }
3623 } 3616 }
3624 3617
3625 #endif 3618 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698