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

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

Issue 2583543002: Revert of [wasm] Make WasmRunner the central test structure (Closed)
Patch Set: Created 4 years 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 <stdint.h> 5 #include <stdint.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "src/wasm/wasm-macro-gen.h" 10 #include "src/wasm/wasm-macro-gen.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 void EXPECT_CALL(double expected, Handle<JSFunction> jsfunc, double a, 90 void EXPECT_CALL(double expected, Handle<JSFunction> jsfunc, double a,
91 double b) { 91 double b) {
92 Isolate* isolate = jsfunc->GetIsolate(); 92 Isolate* isolate = jsfunc->GetIsolate();
93 Handle<Object> buffer[] = {isolate->factory()->NewNumber(a), 93 Handle<Object> buffer[] = {isolate->factory()->NewNumber(a),
94 isolate->factory()->NewNumber(b)}; 94 isolate->factory()->NewNumber(b)};
95 EXPECT_CALL(expected, jsfunc, buffer, 2); 95 EXPECT_CALL(expected, jsfunc, buffer, 2);
96 } 96 }
97 } // namespace 97 } // namespace
98 98
99 TEST(Run_Int32Sub_jswrapped) { 99 TEST(Run_Int32Sub_jswrapped) {
100 WasmRunner<int, int, int> r(kExecuteCompiled); 100 CcTest::InitializeVM();
101 BUILD(r, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 101 TestSignatures sigs;
102 Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index); 102 TestingModule module;
103 WasmFunctionCompiler t(sigs.i_ii(), &module);
104 BUILD(t, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
105 Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
103 106
104 EXPECT_CALL(33, jsfunc, 44, 11); 107 EXPECT_CALL(33, jsfunc, 44, 11);
105 EXPECT_CALL(-8723487, jsfunc, -8000000, 723487); 108 EXPECT_CALL(-8723487, jsfunc, -8000000, 723487);
106 } 109 }
107 110
108 TEST(Run_Float32Div_jswrapped) { 111 TEST(Run_Float32Div_jswrapped) {
109 WasmRunner<float, float, float> r(kExecuteCompiled); 112 CcTest::InitializeVM();
110 BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 113 TestSignatures sigs;
111 Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index); 114 TestingModule module;
115 WasmFunctionCompiler t(sigs.f_ff(), &module);
116 BUILD(t, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
117 Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
112 118
113 EXPECT_CALL(92, jsfunc, 46, 0.5); 119 EXPECT_CALL(92, jsfunc, 46, 0.5);
114 EXPECT_CALL(64, jsfunc, -16, -0.25); 120 EXPECT_CALL(64, jsfunc, -16, -0.25);
115 } 121 }
116 122
117 TEST(Run_Float64Add_jswrapped) { 123 TEST(Run_Float64Add_jswrapped) {
118 WasmRunner<double, double, double> r(kExecuteCompiled); 124 CcTest::InitializeVM();
119 BUILD(r, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 125 TestSignatures sigs;
120 Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index); 126 TestingModule module;
127 WasmFunctionCompiler t(sigs.d_dd(), &module);
128 BUILD(t, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
129 Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
121 130
122 EXPECT_CALL(3, jsfunc, 2, 1); 131 EXPECT_CALL(3, jsfunc, 2, 1);
123 EXPECT_CALL(-5.5, jsfunc, -5.25, -0.25); 132 EXPECT_CALL(-5.5, jsfunc, -5.25, -0.25);
124 } 133 }
125 134
126 TEST(Run_I32Popcount_jswrapped) { 135 TEST(Run_I32Popcount_jswrapped) {
127 WasmRunner<int, int> r(kExecuteCompiled); 136 CcTest::InitializeVM();
128 BUILD(r, WASM_I32_POPCNT(WASM_GET_LOCAL(0))); 137 TestSignatures sigs;
129 Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index); 138 TestingModule module;
139 WasmFunctionCompiler t(sigs.i_i(), &module);
140 BUILD(t, WASM_I32_POPCNT(WASM_GET_LOCAL(0)));
141 Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
130 142
131 EXPECT_CALL(2, jsfunc, 9, 0); 143 EXPECT_CALL(2, jsfunc, 9, 0);
132 EXPECT_CALL(3, jsfunc, 11, 0); 144 EXPECT_CALL(3, jsfunc, 11, 0);
133 EXPECT_CALL(6, jsfunc, 0x3F, 0); 145 EXPECT_CALL(6, jsfunc, 0x3F, 0);
134 } 146 }
135 147
136 TEST(Run_CallJS_Add_jswrapped) { 148 TEST(Run_CallJS_Add_jswrapped) {
137 WasmRunner<int, int> r(kExecuteCompiled); 149 CcTest::InitializeVM();
138 TestSignatures sigs; 150 TestSignatures sigs;
151 TestingModule module;
152 WasmFunctionCompiler t(sigs.i_i(), &module);
139 uint32_t js_index = 153 uint32_t js_index =
140 r.module().AddJsFunction(sigs.i_i(), "(function(a) { return a + 99; })"); 154 module.AddJsFunction(sigs.i_i(), "(function(a) { return a + 99; })");
141 BUILD(r, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0))); 155 BUILD(t, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0)));
142 156
143 Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index); 157 Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
144 158
145 EXPECT_CALL(101, jsfunc, 2, -8); 159 EXPECT_CALL(101, jsfunc, 2, -8);
146 EXPECT_CALL(199, jsfunc, 100, -1); 160 EXPECT_CALL(199, jsfunc, 100, -1);
147 EXPECT_CALL(-666666801, jsfunc, -666666900, -1); 161 EXPECT_CALL(-666666801, jsfunc, -666666900, -1);
148 } 162 }
149 163
150 void RunJSSelectTest(int which) { 164 void RunJSSelectTest(int which) {
151 const int kMaxParams = 8; 165 const int kMaxParams = 8;
152 PredictableInputValues inputs(0x100); 166 PredictableInputValues inputs(0x100);
153 LocalType type = kAstF64; 167 LocalType type = kAstF64;
154 LocalType types[kMaxParams + 1] = {type, type, type, type, type, 168 LocalType types[kMaxParams + 1] = {type, type, type, type, type,
155 type, type, type, type}; 169 type, type, type, type};
156 for (int num_params = which + 1; num_params < kMaxParams; num_params++) { 170 for (int num_params = which + 1; num_params < kMaxParams; num_params++) {
157 HandleScope scope(CcTest::InitIsolateOnce()); 171 HandleScope scope(CcTest::InitIsolateOnce());
158 FunctionSig sig(1, num_params, types); 172 FunctionSig sig(1, num_params, types);
159 173
160 WasmRunner<void> r(kExecuteCompiled); 174 TestingModule module;
161 uint32_t js_index = AddJSSelector(&r.module(), &sig, which); 175 uint32_t js_index = AddJSSelector(&module, &sig, which);
162 WasmFunctionCompiler& t = r.NewFunction(&sig); 176 WasmFunctionCompiler t(&sig, &module);
163 177
164 { 178 {
165 std::vector<byte> code; 179 std::vector<byte> code;
166 180
167 for (int i = 0; i < num_params; i++) { 181 for (int i = 0; i < num_params; i++) {
168 ADD_CODE(code, WASM_F64(inputs.arg_d(i))); 182 ADD_CODE(code, WASM_F64(inputs.arg_d(i)));
169 } 183 }
170 184
171 ADD_CODE(code, kExprCallFunction, static_cast<byte>(js_index)); 185 ADD_CODE(code, kExprCallFunction, static_cast<byte>(js_index));
172 186
173 size_t end = code.size(); 187 size_t end = code.size();
174 code.push_back(0); 188 code.push_back(0);
175 t.Build(&code[0], &code[end]); 189 t.Build(&code[0], &code[end]);
176 } 190 }
177 191
178 Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index()); 192 Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
179 double expected = inputs.arg_d(which); 193 double expected = inputs.arg_d(which);
180 EXPECT_CALL(expected, jsfunc, 0.0, 0.0); 194 EXPECT_CALL(expected, jsfunc, 0.0, 0.0);
181 } 195 }
182 } 196 }
183 197
184 TEST(Run_JSSelect_0) { 198 TEST(Run_JSSelect_0) {
185 CcTest::InitializeVM(); 199 CcTest::InitializeVM();
186 RunJSSelectTest(0); 200 RunJSSelectTest(0);
187 } 201 }
188 202
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 void RunWASMSelectTest(int which) { 238 void RunWASMSelectTest(int which) {
225 PredictableInputValues inputs(0x200); 239 PredictableInputValues inputs(0x200);
226 Isolate* isolate = CcTest::InitIsolateOnce(); 240 Isolate* isolate = CcTest::InitIsolateOnce();
227 const int kMaxParams = 8; 241 const int kMaxParams = 8;
228 for (int num_params = which + 1; num_params < kMaxParams; num_params++) { 242 for (int num_params = which + 1; num_params < kMaxParams; num_params++) {
229 LocalType type = kAstF64; 243 LocalType type = kAstF64;
230 LocalType types[kMaxParams + 1] = {type, type, type, type, type, 244 LocalType types[kMaxParams + 1] = {type, type, type, type, type,
231 type, type, type, type}; 245 type, type, type, type};
232 FunctionSig sig(1, num_params, types); 246 FunctionSig sig(1, num_params, types);
233 247
234 WasmRunner<void> r(kExecuteCompiled); 248 TestingModule module;
235 WasmFunctionCompiler& t = r.NewFunction(&sig); 249 WasmFunctionCompiler t(&sig, &module);
236 BUILD(t, WASM_GET_LOCAL(which)); 250 BUILD(t, WASM_GET_LOCAL(which));
237 Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index()); 251 Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
238 252
239 Handle<Object> args[] = { 253 Handle<Object> args[] = {
240 isolate->factory()->NewNumber(inputs.arg_d(0)), 254 isolate->factory()->NewNumber(inputs.arg_d(0)),
241 isolate->factory()->NewNumber(inputs.arg_d(1)), 255 isolate->factory()->NewNumber(inputs.arg_d(1)),
242 isolate->factory()->NewNumber(inputs.arg_d(2)), 256 isolate->factory()->NewNumber(inputs.arg_d(2)),
243 isolate->factory()->NewNumber(inputs.arg_d(3)), 257 isolate->factory()->NewNumber(inputs.arg_d(3)),
244 isolate->factory()->NewNumber(inputs.arg_d(4)), 258 isolate->factory()->NewNumber(inputs.arg_d(4)),
245 isolate->factory()->NewNumber(inputs.arg_d(5)), 259 isolate->factory()->NewNumber(inputs.arg_d(5)),
246 isolate->factory()->NewNumber(inputs.arg_d(6)), 260 isolate->factory()->NewNumber(inputs.arg_d(6)),
247 isolate->factory()->NewNumber(inputs.arg_d(7)), 261 isolate->factory()->NewNumber(inputs.arg_d(7)),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 PredictableInputValues inputs(0x300); 310 PredictableInputValues inputs(0x300);
297 Isolate* isolate = CcTest::InitIsolateOnce(); 311 Isolate* isolate = CcTest::InitIsolateOnce();
298 const int kMaxParams = 10; 312 const int kMaxParams = 10;
299 DCHECK_LE(num_args, kMaxParams); 313 DCHECK_LE(num_args, kMaxParams);
300 LocalType type = kAstF64; 314 LocalType type = kAstF64;
301 LocalType types[kMaxParams + 1] = {type, type, type, type, type, type, 315 LocalType types[kMaxParams + 1] = {type, type, type, type, type, type,
302 type, type, type, type, type}; 316 type, type, type, type, type};
303 FunctionSig sig(1, num_params, types); 317 FunctionSig sig(1, num_params, types);
304 318
305 for (int which = 0; which < num_params; which++) { 319 for (int which = 0; which < num_params; which++) {
306 WasmRunner<void> r(kExecuteCompiled); 320 TestingModule module;
307 WasmFunctionCompiler& t = r.NewFunction(&sig); 321 WasmFunctionCompiler t(&sig, &module);
308 BUILD(t, WASM_GET_LOCAL(which)); 322 BUILD(t, WASM_GET_LOCAL(which));
309 Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index()); 323 Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
310 324
311 Handle<Object> args[] = {isolate->factory()->NewNumber(inputs.arg_d(0)), 325 Handle<Object> args[] = {isolate->factory()->NewNumber(inputs.arg_d(0)),
312 isolate->factory()->NewNumber(inputs.arg_d(1)), 326 isolate->factory()->NewNumber(inputs.arg_d(1)),
313 isolate->factory()->NewNumber(inputs.arg_d(2)), 327 isolate->factory()->NewNumber(inputs.arg_d(2)),
314 isolate->factory()->NewNumber(inputs.arg_d(3)), 328 isolate->factory()->NewNumber(inputs.arg_d(3)),
315 isolate->factory()->NewNumber(inputs.arg_d(4)), 329 isolate->factory()->NewNumber(inputs.arg_d(4)),
316 isolate->factory()->NewNumber(inputs.arg_d(5)), 330 isolate->factory()->NewNumber(inputs.arg_d(5)),
317 isolate->factory()->NewNumber(inputs.arg_d(6)), 331 isolate->factory()->NewNumber(inputs.arg_d(6)),
318 isolate->factory()->NewNumber(inputs.arg_d(7)), 332 isolate->factory()->NewNumber(inputs.arg_d(7)),
319 isolate->factory()->NewNumber(inputs.arg_d(8)), 333 isolate->factory()->NewNumber(inputs.arg_d(8)),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 PredictableInputValues inputs(0x400); 404 PredictableInputValues inputs(0x400);
391 Isolate* isolate = CcTest::InitIsolateOnce(); 405 Isolate* isolate = CcTest::InitIsolateOnce();
392 Factory* factory = isolate->factory(); 406 Factory* factory = isolate->factory();
393 const int kMaxParams = 10; 407 const int kMaxParams = 10;
394 CHECK_LE(num_args, kMaxParams); 408 CHECK_LE(num_args, kMaxParams);
395 CHECK_LE(num_params, kMaxParams); 409 CHECK_LE(num_params, kMaxParams);
396 LocalType type = kAstF64; 410 LocalType type = kAstF64;
397 LocalType types[kMaxParams + 1] = {type, type, type, type, type, type, 411 LocalType types[kMaxParams + 1] = {type, type, type, type, type, type,
398 type, type, type, type, type}; 412 type, type, type, type, type};
399 FunctionSig sig(1, num_params, types); 413 FunctionSig sig(1, num_params, types);
400 i::AccountingAllocator allocator;
401 Zone zone(&allocator, ZONE_NAME);
402 414
403 // Build the calling code. 415 // Build the calling code.
404 std::vector<byte> code; 416 std::vector<byte> code;
405 417
406 for (int i = 0; i < num_params; i++) { 418 for (int i = 0; i < num_params; i++) {
407 ADD_CODE(code, WASM_GET_LOCAL(i)); 419 ADD_CODE(code, WASM_GET_LOCAL(i));
408 } 420 }
409 421
410 uint8_t predicted_js_index = 1; 422 ADD_CODE(code, kExprCallFunction, 0);
411 ADD_CODE(code, kExprCallFunction, predicted_js_index);
412 423
413 size_t end = code.size(); 424 size_t end = code.size();
414 code.push_back(0); 425 code.push_back(0);
415 426
416 // Call different select JS functions. 427 // Call different select JS functions.
417 for (int which = 0; which < num_params; which++) { 428 for (int which = 0; which < num_params; which++) {
418 WasmRunner<void> r(kExecuteCompiled); 429 HandleScope scope(isolate);
419 uint32_t js_index = AddJSSelector(&r.module(), &sig, which); 430 TestingModule module;
420 CHECK_EQ(predicted_js_index, js_index); 431 uint32_t js_index = AddJSSelector(&module, &sig, which);
421 WasmFunctionCompiler& t = r.NewFunction(&sig); 432 CHECK_EQ(0u, js_index);
433 WasmFunctionCompiler t(&sig, &module);
422 t.Build(&code[0], &code[end]); 434 t.Build(&code[0], &code[end]);
423 435
424 Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index()); 436 Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
425 437
426 Handle<Object> args[] = { 438 Handle<Object> args[] = {
427 factory->NewNumber(inputs.arg_d(0)), 439 factory->NewNumber(inputs.arg_d(0)),
428 factory->NewNumber(inputs.arg_d(1)), 440 factory->NewNumber(inputs.arg_d(1)),
429 factory->NewNumber(inputs.arg_d(2)), 441 factory->NewNumber(inputs.arg_d(2)),
430 factory->NewNumber(inputs.arg_d(3)), 442 factory->NewNumber(inputs.arg_d(3)),
431 factory->NewNumber(inputs.arg_d(4)), 443 factory->NewNumber(inputs.arg_d(4)),
432 factory->NewNumber(inputs.arg_d(5)), 444 factory->NewNumber(inputs.arg_d(5)),
433 factory->NewNumber(inputs.arg_d(6)), 445 factory->NewNumber(inputs.arg_d(6)),
434 factory->NewNumber(inputs.arg_d(7)), 446 factory->NewNumber(inputs.arg_d(7)),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 RunJSSelectAlignTest(9, 9); 508 RunJSSelectAlignTest(9, 9);
497 } 509 }
498 510
499 TEST(Run_JSSelectAlign_10) { 511 TEST(Run_JSSelectAlign_10) {
500 CcTest::InitializeVM(); 512 CcTest::InitializeVM();
501 RunJSSelectAlignTest(10, 7); 513 RunJSSelectAlignTest(10, 7);
502 RunJSSelectAlignTest(10, 8); 514 RunJSSelectAlignTest(10, 8);
503 RunJSSelectAlignTest(10, 9); 515 RunJSSelectAlignTest(10, 9);
504 RunJSSelectAlignTest(10, 10); 516 RunJSSelectAlignTest(10, 10);
505 } 517 }
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-run-wasm-interpreter.cc ('k') | test/cctest/wasm/test-run-wasm-relocation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698