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

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

Issue 1707403002: [wasm] Refactor WASM test usage of TestingModule. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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.cc ('k') | test/cctest/wasm/wasm-run-utils.h » ('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 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 Isolate* isolate = jsfunc->GetIsolate(); 115 Isolate* isolate = jsfunc->GetIsolate();
116 Handle<Object> buffer[] = {isolate->factory()->NewNumber(a), 116 Handle<Object> buffer[] = {isolate->factory()->NewNumber(a),
117 isolate->factory()->NewNumber(b)}; 117 isolate->factory()->NewNumber(b)};
118 EXPECT_CALL(expected, jsfunc, buffer, 2); 118 EXPECT_CALL(expected, jsfunc, buffer, 2);
119 } 119 }
120 } // namespace 120 } // namespace
121 121
122 TEST(Run_Int32Sub_jswrapped) { 122 TEST(Run_Int32Sub_jswrapped) {
123 TestSignatures sigs; 123 TestSignatures sigs;
124 TestingModule module; 124 TestingModule module;
125 WasmFunctionCompiler t(sigs.i_ii()); 125 WasmFunctionCompiler t(sigs.i_ii(), &module);
126 BUILD(t, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 126 BUILD(t, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
127 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); 127 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
128 128
129 EXPECT_CALL(33, jsfunc, 44, 11); 129 EXPECT_CALL(33, jsfunc, 44, 11);
130 EXPECT_CALL(-8723487, jsfunc, -8000000, 723487); 130 EXPECT_CALL(-8723487, jsfunc, -8000000, 723487);
131 } 131 }
132 132
133 133
134 TEST(Run_Float32Div_jswrapped) { 134 TEST(Run_Float32Div_jswrapped) {
135 TestSignatures sigs; 135 TestSignatures sigs;
136 TestingModule module; 136 TestingModule module;
137 WasmFunctionCompiler t(sigs.f_ff()); 137 WasmFunctionCompiler t(sigs.f_ff(), &module);
138 BUILD(t, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 138 BUILD(t, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
139 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); 139 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
140 140
141 EXPECT_CALL(92, jsfunc, 46, 0.5); 141 EXPECT_CALL(92, jsfunc, 46, 0.5);
142 EXPECT_CALL(64, jsfunc, -16, -0.25); 142 EXPECT_CALL(64, jsfunc, -16, -0.25);
143 } 143 }
144 144
145 145
146 TEST(Run_Float64Add_jswrapped) { 146 TEST(Run_Float64Add_jswrapped) {
147 TestSignatures sigs; 147 TestSignatures sigs;
148 TestingModule module; 148 TestingModule module;
149 WasmFunctionCompiler t(sigs.d_dd()); 149 WasmFunctionCompiler t(sigs.d_dd(), &module);
150 BUILD(t, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 150 BUILD(t, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
151 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); 151 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
152 152
153 EXPECT_CALL(3, jsfunc, 2, 1); 153 EXPECT_CALL(3, jsfunc, 2, 1);
154 EXPECT_CALL(-5.5, jsfunc, -5.25, -0.25); 154 EXPECT_CALL(-5.5, jsfunc, -5.25, -0.25);
155 } 155 }
156 156
157 157
158 TEST(Run_I32Popcount_jswrapped) { 158 TEST(Run_I32Popcount_jswrapped) {
159 TestSignatures sigs; 159 TestSignatures sigs;
160 TestingModule module; 160 TestingModule module;
161 WasmFunctionCompiler t(sigs.i_i()); 161 WasmFunctionCompiler t(sigs.i_i(), &module);
162 BUILD(t, WASM_I32_POPCNT(WASM_GET_LOCAL(0))); 162 BUILD(t, WASM_I32_POPCNT(WASM_GET_LOCAL(0)));
163 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); 163 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
164 164
165 EXPECT_CALL(2, jsfunc, 9, 0); 165 EXPECT_CALL(2, jsfunc, 9, 0);
166 EXPECT_CALL(3, jsfunc, 11, 0); 166 EXPECT_CALL(3, jsfunc, 11, 0);
167 EXPECT_CALL(6, jsfunc, 0x3F, 0); 167 EXPECT_CALL(6, jsfunc, 0x3F, 0);
168 168
169 USE(AddJsFunction); 169 USE(AddJsFunction);
170 } 170 }
171 171
172 172
173 #if !V8_TARGET_ARCH_ARM64 173 #if !V8_TARGET_ARCH_ARM64
174 // TODO(titzer): dynamic frame alignment on arm64 174 // TODO(titzer): dynamic frame alignment on arm64
175 TEST(Run_CallJS_Add_jswrapped) { 175 TEST(Run_CallJS_Add_jswrapped) {
176 TestSignatures sigs; 176 TestSignatures sigs;
177 TestingModule module; 177 TestingModule module;
178 WasmFunctionCompiler t(sigs.i_i(), &module); 178 WasmFunctionCompiler t(sigs.i_i(), &module);
179 uint32_t js_index = 179 uint32_t js_index =
180 AddJsFunction(&module, sigs.i_i(), "(function(a) { return a + 99; })"); 180 AddJsFunction(&module, sigs.i_i(), "(function(a) { return a + 99; })");
181 BUILD(t, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0))); 181 BUILD(t, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0)));
182 182
183 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); 183 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
184 184
185 EXPECT_CALL(101, jsfunc, 2, -8); 185 EXPECT_CALL(101, jsfunc, 2, -8);
186 EXPECT_CALL(199, jsfunc, 100, -1); 186 EXPECT_CALL(199, jsfunc, 100, -1);
187 EXPECT_CALL(-666666801, jsfunc, -666666900, -1); 187 EXPECT_CALL(-666666801, jsfunc, -666666900, -1);
188 } 188 }
189 #endif 189 #endif
190 190
191 191
192 void RunJSSelectTest(int which) { 192 void RunJSSelectTest(int which) {
193 #if !V8_TARGET_ARCH_ARM 193 #if !V8_TARGET_ARCH_ARM
(...skipping 17 matching lines...) Expand all
211 211
212 for (int i = 0; i < num_params; i++) { 212 for (int i = 0; i < num_params; i++) {
213 ADD_CODE(code, WASM_F64(inputs.arg_d(i))); 213 ADD_CODE(code, WASM_F64(inputs.arg_d(i)));
214 } 214 }
215 215
216 size_t end = code.size(); 216 size_t end = code.size();
217 code.push_back(0); 217 code.push_back(0);
218 t.Build(&code[0], &code[end]); 218 t.Build(&code[0], &code[end]);
219 } 219 }
220 220
221 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); 221 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
222 double expected = inputs.arg_d(which); 222 double expected = inputs.arg_d(which);
223 EXPECT_CALL(expected, jsfunc, 0.0, 0.0); 223 EXPECT_CALL(expected, jsfunc, 0.0, 0.0);
224 } 224 }
225 #endif 225 #endif
226 } 226 }
227 227
228 228
229 TEST(Run_JSSelect_0) { RunJSSelectTest(0); } 229 TEST(Run_JSSelect_0) { RunJSSelectTest(0); }
230 230
231 TEST(Run_JSSelect_1) { RunJSSelectTest(1); } 231 TEST(Run_JSSelect_1) { RunJSSelectTest(1); }
(...skipping 17 matching lines...) Expand all
249 const int kMaxParams = 8; 249 const int kMaxParams = 8;
250 for (int num_params = which + 1; num_params < kMaxParams; num_params++) { 250 for (int num_params = which + 1; num_params < kMaxParams; num_params++) {
251 LocalType type = kAstF64; 251 LocalType type = kAstF64;
252 LocalType types[kMaxParams + 1] = {type, type, type, type, type, 252 LocalType types[kMaxParams + 1] = {type, type, type, type, type,
253 type, type, type, type}; 253 type, type, type, type};
254 FunctionSig sig(1, num_params, types); 254 FunctionSig sig(1, num_params, types);
255 255
256 TestingModule module; 256 TestingModule module;
257 WasmFunctionCompiler t(&sig, &module); 257 WasmFunctionCompiler t(&sig, &module);
258 BUILD(t, WASM_GET_LOCAL(which)); 258 BUILD(t, WASM_GET_LOCAL(which));
259 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); 259 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
260 260
261 Handle<Object> args[] = { 261 Handle<Object> args[] = {
262 isolate->factory()->NewNumber(inputs.arg_d(0)), 262 isolate->factory()->NewNumber(inputs.arg_d(0)),
263 isolate->factory()->NewNumber(inputs.arg_d(1)), 263 isolate->factory()->NewNumber(inputs.arg_d(1)),
264 isolate->factory()->NewNumber(inputs.arg_d(2)), 264 isolate->factory()->NewNumber(inputs.arg_d(2)),
265 isolate->factory()->NewNumber(inputs.arg_d(3)), 265 isolate->factory()->NewNumber(inputs.arg_d(3)),
266 isolate->factory()->NewNumber(inputs.arg_d(4)), 266 isolate->factory()->NewNumber(inputs.arg_d(4)),
267 isolate->factory()->NewNumber(inputs.arg_d(5)), 267 isolate->factory()->NewNumber(inputs.arg_d(5)),
268 isolate->factory()->NewNumber(inputs.arg_d(6)), 268 isolate->factory()->NewNumber(inputs.arg_d(6)),
269 isolate->factory()->NewNumber(inputs.arg_d(7)), 269 isolate->factory()->NewNumber(inputs.arg_d(7)),
(...skipping 28 matching lines...) Expand all
298 const int kMaxParams = 4; 298 const int kMaxParams = 4;
299 DCHECK_LE(num_args, kMaxParams); 299 DCHECK_LE(num_args, kMaxParams);
300 LocalType type = kAstF64; 300 LocalType type = kAstF64;
301 LocalType types[kMaxParams + 1] = {type, type, type, type, type}; 301 LocalType types[kMaxParams + 1] = {type, type, type, type, type};
302 FunctionSig sig(1, num_params, types); 302 FunctionSig sig(1, num_params, types);
303 303
304 for (int which = 0; which < num_params; which++) { 304 for (int which = 0; which < num_params; which++) {
305 TestingModule module; 305 TestingModule module;
306 WasmFunctionCompiler t(&sig, &module); 306 WasmFunctionCompiler t(&sig, &module);
307 BUILD(t, WASM_GET_LOCAL(which)); 307 BUILD(t, WASM_GET_LOCAL(which));
308 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); 308 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
309 309
310 Handle<Object> args[] = { 310 Handle<Object> args[] = {
311 isolate->factory()->NewNumber(inputs.arg_d(0)), 311 isolate->factory()->NewNumber(inputs.arg_d(0)),
312 isolate->factory()->NewNumber(inputs.arg_d(1)), 312 isolate->factory()->NewNumber(inputs.arg_d(1)),
313 isolate->factory()->NewNumber(inputs.arg_d(2)), 313 isolate->factory()->NewNumber(inputs.arg_d(2)),
314 isolate->factory()->NewNumber(inputs.arg_d(3)), 314 isolate->factory()->NewNumber(inputs.arg_d(3)),
315 }; 315 };
316 316
317 double nan = std::numeric_limits<double>::quiet_NaN(); 317 double nan = std::numeric_limits<double>::quiet_NaN();
318 double expected = which < num_args ? inputs.arg_d(which) : nan; 318 double expected = which < num_args ? inputs.arg_d(which) : nan;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 375
376 // Call different select JS functions. 376 // Call different select JS functions.
377 for (int which = 0; which < num_params; which++) { 377 for (int which = 0; which < num_params; which++) {
378 HandleScope scope(isolate); 378 HandleScope scope(isolate);
379 TestingModule module; 379 TestingModule module;
380 uint32_t js_index = AddJSSelector(&module, &sig, which); 380 uint32_t js_index = AddJSSelector(&module, &sig, which);
381 CHECK_EQ(0, js_index); 381 CHECK_EQ(0, js_index);
382 WasmFunctionCompiler t(&sig, &module); 382 WasmFunctionCompiler t(&sig, &module);
383 t.Build(&code[0], &code[end]); 383 t.Build(&code[0], &code[end]);
384 384
385 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); 385 Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
386 386
387 Handle<Object> args[] = { 387 Handle<Object> args[] = {
388 factory->NewNumber(inputs.arg_d(0)), 388 factory->NewNumber(inputs.arg_d(0)),
389 factory->NewNumber(inputs.arg_d(1)), 389 factory->NewNumber(inputs.arg_d(1)),
390 factory->NewNumber(inputs.arg_d(2)), 390 factory->NewNumber(inputs.arg_d(2)),
391 factory->NewNumber(inputs.arg_d(3)), 391 factory->NewNumber(inputs.arg_d(3)),
392 }; 392 };
393 393
394 double nan = std::numeric_limits<double>::quiet_NaN(); 394 double nan = std::numeric_limits<double>::quiet_NaN();
395 double expected = which < num_args ? inputs.arg_d(which) : nan; 395 double expected = which < num_args ? inputs.arg_d(which) : nan;
(...skipping 26 matching lines...) Expand all
422 RunJSSelectAlignTest(1, 2); 422 RunJSSelectAlignTest(1, 2);
423 RunJSSelectAlignTest(1, 3); 423 RunJSSelectAlignTest(1, 3);
424 } 424 }
425 425
426 426
427 TEST(Run_JSSelectAlign_3) { 427 TEST(Run_JSSelectAlign_3) {
428 RunJSSelectAlignTest(3, 3); 428 RunJSSelectAlignTest(3, 3);
429 RunJSSelectAlignTest(3, 4); 429 RunJSSelectAlignTest(3, 4);
430 } 430 }
431 #endif 431 #endif
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-run-wasm.cc ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698