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

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

Issue 2345593003: [wasm] Master CL for Binary 0xC changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test failures and TSAN races. Created 4 years, 2 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 | « test/cctest/wasm/test-run-wasm-64.cc ('k') | test/cctest/wasm/test-run-wasm-js.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 <memory> 9 #include <memory>
10 10
(...skipping 18 matching lines...) Expand all
29 TEST(Run_WasmInt8Const_i) { 29 TEST(Run_WasmInt8Const_i) {
30 WasmRunner<int32_t> r(kExecuteInterpreted); 30 WasmRunner<int32_t> r(kExecuteInterpreted);
31 const byte kExpectedValue = 109; 31 const byte kExpectedValue = 109;
32 // return(kExpectedValue) 32 // return(kExpectedValue)
33 BUILD(r, WASM_I8(kExpectedValue)); 33 BUILD(r, WASM_I8(kExpectedValue));
34 CHECK_EQ(kExpectedValue, r.Call()); 34 CHECK_EQ(kExpectedValue, r.Call());
35 } 35 }
36 36
37 TEST(Run_WasmIfElse) { 37 TEST(Run_WasmIfElse) {
38 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32()); 38 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32());
39 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(10))); 39 BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(10)));
40 CHECK_EQ(10, r.Call(0)); 40 CHECK_EQ(10, r.Call(0));
41 CHECK_EQ(9, r.Call(1)); 41 CHECK_EQ(9, r.Call(1));
42 } 42 }
43 43
44 TEST(Run_WasmIfReturn) { 44 TEST(Run_WasmIfReturn) {
45 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32()); 45 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32());
46 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I8(77))), WASM_I8(65)); 46 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I8(77))), WASM_I8(65));
47 CHECK_EQ(65, r.Call(0)); 47 CHECK_EQ(65, r.Call(0));
48 CHECK_EQ(77, r.Call(1)); 48 CHECK_EQ(77, r.Call(1));
49 } 49 }
50 50
51 TEST(Run_WasmNopsN) { 51 TEST(Run_WasmNopsN) {
52 const int kMaxNops = 10; 52 const int kMaxNops = 10;
53 byte code[kMaxNops + 2]; 53 byte code[kMaxNops + 2];
54 for (int nops = 0; nops < kMaxNops; nops++) { 54 for (int nops = 0; nops < kMaxNops; nops++) {
55 byte expected = static_cast<byte>(20 + nops); 55 byte expected = static_cast<byte>(20 + nops);
56 memset(code, kExprNop, sizeof(code)); 56 memset(code, kExprNop, sizeof(code));
57 code[nops] = kExprI8Const; 57 code[nops] = kExprI8Const;
58 code[nops + 1] = expected; 58 code[nops + 1] = expected;
59 59
60 WasmRunner<int32_t> r(kExecuteInterpreted); 60 WasmRunner<int32_t> r(kExecuteInterpreted);
61 r.Build(code, code + nops + 2); 61 r.Build(code, code + nops + 2);
62 CHECK_EQ(expected, r.Call()); 62 CHECK_EQ(expected, r.Call());
63 } 63 }
64 } 64 }
65 65
66 TEST(Run_WasmConstsN) { 66 TEST(Run_WasmConstsN) {
67 const int kMaxConsts = 10; 67 const int kMaxConsts = 10;
68 byte code[kMaxConsts * 2]; 68 byte code[kMaxConsts * 3];
69 int32_t expected = 0;
69 for (int count = 1; count < kMaxConsts; count++) { 70 for (int count = 1; count < kMaxConsts; count++) {
70 for (int i = 0; i < count; i++) { 71 for (int i = 0; i < count; i++) {
71 code[i * 2] = kExprI8Const; 72 byte val = static_cast<byte>(count * 10 + i);
72 code[i * 2 + 1] = static_cast<byte>(count * 10 + i); 73 code[i * 3] = kExprI8Const;
74 code[i * 3 + 1] = val;
75 if (i == (count - 1)) {
76 code[i * 3 + 2] = kExprNop;
77 expected = val;
78 } else {
79 code[i * 3 + 2] = kExprDrop;
80 }
73 } 81 }
74 byte expected = static_cast<byte>(count * 11 - 1);
75 82
76 WasmRunner<int32_t> r(kExecuteInterpreted); 83 WasmRunner<int32_t> r(kExecuteInterpreted);
77 r.Build(code, code + (count * 2)); 84 r.Build(code, code + (count * 3));
78 CHECK_EQ(expected, r.Call()); 85 CHECK_EQ(expected, r.Call());
79 } 86 }
80 } 87 }
81 88
82 TEST(Run_WasmBlocksN) { 89 TEST(Run_WasmBlocksN) {
83 const int kMaxNops = 10; 90 const int kMaxNops = 10;
84 const int kExtra = 4; 91 const int kExtra = 5;
85 byte code[kMaxNops + kExtra]; 92 byte code[kMaxNops + kExtra];
86 for (int nops = 0; nops < kMaxNops; nops++) { 93 for (int nops = 0; nops < kMaxNops; nops++) {
87 byte expected = static_cast<byte>(30 + nops); 94 byte expected = static_cast<byte>(30 + nops);
88 memset(code, kExprNop, sizeof(code)); 95 memset(code, kExprNop, sizeof(code));
89 code[0] = kExprBlock; 96 code[0] = kExprBlock;
90 code[1 + nops] = kExprI8Const; 97 code[1] = kLocalI32;
91 code[1 + nops + 1] = expected; 98 code[2 + nops] = kExprI8Const;
92 code[1 + nops + 2] = kExprEnd; 99 code[2 + nops + 1] = expected;
100 code[2 + nops + 2] = kExprEnd;
93 101
94 WasmRunner<int32_t> r(kExecuteInterpreted); 102 WasmRunner<int32_t> r(kExecuteInterpreted);
95 r.Build(code, code + nops + kExtra); 103 r.Build(code, code + nops + kExtra);
96 CHECK_EQ(expected, r.Call()); 104 CHECK_EQ(expected, r.Call());
97 } 105 }
98 } 106 }
99 107
100 TEST(Run_WasmBlockBreakN) { 108 TEST(Run_WasmBlockBreakN) {
101 const int kMaxNops = 10; 109 const int kMaxNops = 10;
102 const int kExtra = 6; 110 const int kExtra = 6;
103 byte code[kMaxNops + kExtra]; 111 byte code[kMaxNops + kExtra];
104 for (int nops = 0; nops < kMaxNops; nops++) { 112 for (int nops = 0; nops < kMaxNops; nops++) {
105 // Place the break anywhere within the block. 113 // Place the break anywhere within the block.
106 for (int index = 0; index < nops; index++) { 114 for (int index = 0; index < nops; index++) {
107 memset(code, kExprNop, sizeof(code)); 115 memset(code, kExprNop, sizeof(code));
108 code[0] = kExprBlock; 116 code[0] = kExprBlock;
117 code[1] = kLocalI32;
109 code[sizeof(code) - 1] = kExprEnd; 118 code[sizeof(code) - 1] = kExprEnd;
110 119
111 int expected = nops * 11 + index; 120 int expected = nops * 11 + index;
112 code[1 + index + 0] = kExprI8Const; 121 code[2 + index + 0] = kExprI8Const;
113 code[1 + index + 1] = static_cast<byte>(expected); 122 code[2 + index + 1] = static_cast<byte>(expected);
114 code[1 + index + 2] = kExprBr; 123 code[2 + index + 2] = kExprBr;
115 code[1 + index + 3] = ARITY_1; 124 code[2 + index + 3] = 0;
116 code[1 + index + 4] = 0;
117 125
118 WasmRunner<int32_t> r(kExecuteInterpreted); 126 WasmRunner<int32_t> r(kExecuteInterpreted);
119 r.Build(code, code + kMaxNops + kExtra); 127 r.Build(code, code + kMaxNops + kExtra);
120 CHECK_EQ(expected, r.Call()); 128 CHECK_EQ(expected, r.Call());
121 } 129 }
122 } 130 }
123 } 131 }
124 132
125 TEST(Run_Wasm_nested_ifs_i) { 133 TEST(Run_Wasm_nested_ifs_i) {
126 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32(), 134 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32(),
127 MachineType::Int32()); 135 MachineType::Int32());
128 136
129 BUILD(r, WASM_IF_ELSE( 137 BUILD(r, WASM_IF_ELSE_I(
130 WASM_GET_LOCAL(0), 138 WASM_GET_LOCAL(0),
131 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)), 139 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)),
132 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14)))); 140 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14))));
133 141
134 CHECK_EQ(11, r.Call(1, 1)); 142 CHECK_EQ(11, r.Call(1, 1));
135 CHECK_EQ(12, r.Call(1, 0)); 143 CHECK_EQ(12, r.Call(1, 0));
136 CHECK_EQ(13, r.Call(0, 1)); 144 CHECK_EQ(13, r.Call(0, 1));
137 CHECK_EQ(14, r.Call(0, 0)); 145 CHECK_EQ(14, r.Call(0, 0));
138 } 146 }
139 147
140 // Make tests more robust by not hard-coding offsets of various operations. 148 // Make tests more robust by not hard-coding offsets of various operations.
141 // The {Find} method finds the offsets for the given bytecodes, returning 149 // The {Find} method finds the offsets for the given bytecodes, returning
142 // the offsets in an array. 150 // the offsets in an array.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0))); 301 BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
294 CHECK_EQ(1, r.Call(1)); 302 CHECK_EQ(1, r.Call(1));
295 } 303 }
296 304
297 TEST(GrowMemoryPreservesData) { 305 TEST(GrowMemoryPreservesData) {
298 int32_t index = 16; 306 int32_t index = 16;
299 int32_t value = 2335; 307 int32_t value = 2335;
300 TestingModule module(kExecuteInterpreted); 308 TestingModule module(kExecuteInterpreted);
301 WasmRunner<int32_t> r(&module, MachineType::Uint32()); 309 WasmRunner<int32_t> r(&module, MachineType::Uint32());
302 module.AddMemory(WasmModule::kPageSize); 310 module.AddMemory(WasmModule::kPageSize);
303 BUILD(r, WASM_BLOCK(WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), 311 BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index),
304 WASM_I32V(value)), 312 WASM_I32V(value)),
305 WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), 313 WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP,
306 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index)))); 314 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index)));
307 CHECK_EQ(value, r.Call(1)); 315 CHECK_EQ(value, r.Call(1));
308 } 316 }
309 317
310 TEST(GrowMemoryInvalidSize) { 318 TEST(GrowMemoryInvalidSize) {
311 { 319 {
312 // Grow memory by an invalid amount without initial memory. 320 // Grow memory by an invalid amount without initial memory.
313 TestingModule module(kExecuteInterpreted); 321 TestingModule module(kExecuteInterpreted);
314 WasmRunner<int32_t> r(&module, MachineType::Uint32()); 322 WasmRunner<int32_t> r(&module, MachineType::Uint32());
315 BUILD(r, WASM_BLOCK(WASM_GROW_MEMORY(WASM_GET_LOCAL(0)))); 323 BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
316 CHECK_EQ(-1, r.Call(1048575)); 324 CHECK_EQ(-1, r.Call(1048575));
317 } 325 }
318 { 326 {
319 // Grow memory by an invalid amount without initial memory. 327 // Grow memory by an invalid amount without initial memory.
320 TestingModule module(kExecuteInterpreted); 328 TestingModule module(kExecuteInterpreted);
321 WasmRunner<int32_t> r(&module, MachineType::Uint32()); 329 WasmRunner<int32_t> r(&module, MachineType::Uint32());
322 module.AddMemory(WasmModule::kPageSize); 330 module.AddMemory(WasmModule::kPageSize);
323 BUILD(r, WASM_BLOCK(WASM_GROW_MEMORY(WASM_GET_LOCAL(0)))); 331 BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
324 CHECK_EQ(-1, r.Call(1048575)); 332 CHECK_EQ(-1, r.Call(1048575));
325 } 333 }
326 } 334 }
327 335
328 } // namespace wasm 336 } // namespace wasm
329 } // namespace internal 337 } // namespace internal
330 } // namespace v8 338 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-run-wasm-64.cc ('k') | test/cctest/wasm/test-run-wasm-js.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698