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

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

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