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

Side by Side Diff: test/unittests/wasm/module-decoder-unittest.cc

Issue 1980483002: [wasm] Remove legacy encoding of local variables from asm->wasm. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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/unittests/wasm/ast-decoder-unittest.cc ('k') | 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 "test/unittests/test-utils.h" 5 #include "test/unittests/test-utils.h"
6 6
7 #include "src/wasm/module-decoder.h" 7 #include "src/wasm/module-decoder.h"
8 #include "src/wasm/wasm-macro-gen.h" 8 #include "src/wasm/wasm-macro-gen.h"
9 #include "src/wasm/wasm-opcodes.h" 9 #include "src/wasm/wasm-opcodes.h"
10 10
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 0, // exported 336 0, // exported
337 0 // external 337 0 // external
338 }; 338 };
339 339
340 ModuleResult result = DecodeModule(data, data + arraysize(data)); 340 ModuleResult result = DecodeModule(data, data + arraysize(data));
341 EXPECT_FALSE(result.ok()); 341 EXPECT_FALSE(result.ok());
342 if (result.val) delete result.val; 342 if (result.val) delete result.val;
343 } 343 }
344 344
345 TEST_F(WasmModuleVerifyTest, OneEmptyVoidVoidFunction) { 345 TEST_F(WasmModuleVerifyTest, OneEmptyVoidVoidFunction) {
346 const int kCodeStartOffset = 49; 346 const int kCodeStartOffset = 41;
347 const int kCodeEndOffset = kCodeStartOffset + 1; 347 const int kCodeEndOffset = kCodeStartOffset + 1;
348 348
349 static const byte data[] = { 349 static const byte data[] = {
350 // signatures 350 // signatures
351 SIGNATURES_SECTION_VOID_VOID, 351 SIGNATURES_SECTION_VOID_VOID,
352 // func#0 ------------------------------------------------------ 352 // func#0 ------------------------------------------------------
353 SECTION(OLD_FUNCTIONS, 18), 1, 353 SECTION(OLD_FUNCTIONS, 10), 1, kDeclFunctionExport | kDeclFunctionName,
354 kDeclFunctionLocals | kDeclFunctionExport | kDeclFunctionName,
355 SIG_INDEX(0), // signature index 354 SIG_INDEX(0), // signature index
356 NAME_LENGTH(2), 'h', 'i', // name 355 NAME_LENGTH(2), 'h', 'i', // name
357 U16_LE(1466), // local int32 count
358 U16_LE(1355), // local int64 count
359 U16_LE(1244), // local float32 count
360 U16_LE(1133), // local float64 count
361 1, 0, // size 356 1, 0, // size
362 kExprNop, 357 kExprNop,
363 }; 358 };
364 359
365 { 360 {
366 // Should decode to exactly one function. 361 // Should decode to exactly one function.
367 ModuleResult result = DecodeModule(data, data + arraysize(data)); 362 ModuleResult result = DecodeModule(data, data + arraysize(data));
368 EXPECT_OK(result); 363 EXPECT_OK(result);
369 EXPECT_EQ(0, result.val->globals.size()); 364 EXPECT_EQ(0, result.val->globals.size());
370 EXPECT_EQ(1, result.val->signatures.size()); 365 EXPECT_EQ(1, result.val->signatures.size());
371 EXPECT_EQ(1, result.val->functions.size()); 366 EXPECT_EQ(1, result.val->functions.size());
372 EXPECT_EQ(0, result.val->data_segments.size()); 367 EXPECT_EQ(0, result.val->data_segments.size());
373 EXPECT_EQ(0, result.val->function_table.size()); 368 EXPECT_EQ(0, result.val->function_table.size());
374 369
375 WasmFunction* function = &result.val->functions.back(); 370 WasmFunction* function = &result.val->functions.back();
376 371
377 EXPECT_EQ(37, function->name_offset); 372 EXPECT_EQ(37, function->name_offset);
378 EXPECT_EQ(2, function->name_length); 373 EXPECT_EQ(2, function->name_length);
379 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); 374 EXPECT_EQ(kCodeStartOffset, function->code_start_offset);
380 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); 375 EXPECT_EQ(kCodeEndOffset, function->code_end_offset);
381 376
382 EXPECT_EQ(1466, function->local_i32_count);
383 EXPECT_EQ(1355, function->local_i64_count);
384 EXPECT_EQ(1244, function->local_f32_count);
385 EXPECT_EQ(1133, function->local_f64_count);
386
387 EXPECT_TRUE(function->exported); 377 EXPECT_TRUE(function->exported);
388 378
389 if (result.val) delete result.val; 379 if (result.val) delete result.val;
390 } 380 }
391 381
392 EXPECT_OFF_END_FAILURE(data, 16, sizeof(data)); 382 EXPECT_OFF_END_FAILURE(data, 16, sizeof(data));
393 } 383 }
394 384
395 TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody) { 385 TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody) {
396 static const byte kCodeStartOffset = 38; 386 static const byte kCodeStartOffset = 38;
(...skipping 11 matching lines...) Expand all
408 398
409 ModuleResult result = DecodeModule(data, data + arraysize(data)); 399 ModuleResult result = DecodeModule(data, data + arraysize(data));
410 EXPECT_OK(result); 400 EXPECT_OK(result);
411 EXPECT_EQ(1, result.val->functions.size()); 401 EXPECT_EQ(1, result.val->functions.size());
412 WasmFunction* function = &result.val->functions.back(); 402 WasmFunction* function = &result.val->functions.back();
413 403
414 EXPECT_EQ(0, function->name_length); 404 EXPECT_EQ(0, function->name_length);
415 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); 405 EXPECT_EQ(kCodeStartOffset, function->code_start_offset);
416 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); 406 EXPECT_EQ(kCodeEndOffset, function->code_end_offset);
417 407
418 EXPECT_EQ(0, function->local_i32_count);
419 EXPECT_EQ(0, function->local_i64_count);
420 EXPECT_EQ(0, function->local_f32_count);
421 EXPECT_EQ(0, function->local_f64_count);
422
423 EXPECT_FALSE(function->exported); 408 EXPECT_FALSE(function->exported);
424 409
425 if (result.val) delete result.val; 410 if (result.val) delete result.val;
426 }
427
428 TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody_WithLocals) {
429 static const byte kCodeStartOffset = 46;
430 static const byte kCodeEndOffset = kCodeStartOffset + 1;
431
432 static const byte data[] = {
433 SIGNATURES_SECTION_VOID_VOID, // --
434 SECTION(OLD_FUNCTIONS, 15), 1,
435 // func#0 ------------------------------------------------------
436 kDeclFunctionLocals, 0, 0, // signature index
437 1, 2, // local int32 count
438 3, 4, // local int64 count
439 5, 6, // local float32 count
440 7, 8, // local float64 count
441 1, 0, // body size
442 kExprNop // body
443 };
444
445 ModuleResult result = DecodeModule(data, data + arraysize(data));
446 EXPECT_OK(result);
447 EXPECT_EQ(1, result.val->functions.size());
448 WasmFunction* function = &result.val->functions.back();
449
450 EXPECT_EQ(0, function->name_length);
451 EXPECT_EQ(kCodeStartOffset, function->code_start_offset);
452 EXPECT_EQ(kCodeEndOffset, function->code_end_offset);
453
454 EXPECT_EQ(513, function->local_i32_count);
455 EXPECT_EQ(1027, function->local_i64_count);
456 EXPECT_EQ(1541, function->local_f32_count);
457 EXPECT_EQ(2055, function->local_f64_count);
458
459 EXPECT_FALSE(function->exported);
460
461 if (result.val) delete result.val;
462 } 411 }
463 412
464 TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) { 413 TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) {
465 static const byte kNameOffset = 49; 414 static const byte kNameOffset = 49;
466 static const byte kCodeStartOffset = 61; 415 static const byte kCodeStartOffset = 53;
467 static const byte kCodeEndOffset = kCodeStartOffset + 3; 416 static const byte kCodeEndOffset = kCodeStartOffset + 3;
468 static const byte kDataSegmentSourceOffset = kCodeEndOffset + 22; 417 static const byte kDataSegmentSourceOffset = kCodeEndOffset + 22;
469 418
470 static const byte data[] = { 419 static const byte data[] = {
471 // global#0 -------------------------------------------------- 420 // global#0 --------------------------------------------------
472 SECTION(GLOBALS, 4), 1, 421 SECTION(GLOBALS, 4), 1,
473 0, // name length 422 0, // name length
474 kMemU8, // memory type 423 kMemU8, // memory type
475 0, // exported 424 0, // exported
476 // sig#0 ----------------------------------------------------- 425 // sig#0 -----------------------------------------------------
477 SIGNATURES_SECTION_VOID_VOID, 426 SIGNATURES_SECTION_VOID_VOID,
478 // func#0 ---------------------------------------------------- 427 // func#0 ----------------------------------------------------
479 SECTION(OLD_FUNCTIONS, 20), 1, 428 SECTION(OLD_FUNCTIONS, 12), 1,
480 kDeclFunctionLocals | kDeclFunctionName, // -- 429 kDeclFunctionName, // --
481 SIG_INDEX(0), // signature index 430 SIG_INDEX(0), // signature index
482 2, 'h', 'i', // name 431 2, 'h', 'i', // name
483 1, 2, // local int32 count 432 3, 0, // body size
484 3, 4, // local int64 count 433 kExprNop, // func#0 body
485 5, 6, // local float32 count 434 kExprNop, // func#0 body
486 7, 8, // local float64 count 435 kExprNop, // func#0 body
487 3, 0, // body size
488 kExprNop, // func#0 body
489 kExprNop, // func#0 body
490 kExprNop, // func#0 body
491 // memory section -------------------------------------------- 436 // memory section --------------------------------------------
492 SECTION(MEMORY, 3), 28, 28, 1, 437 SECTION(MEMORY, 3), 28, 28, 1,
493 // segment#0 ------------------------------------------------- 438 // segment#0 -------------------------------------------------
494 SECTION(DATA_SEGMENTS, 10), 1, 439 SECTION(DATA_SEGMENTS, 10), 1,
495 U32V_3(0x8b3ae), // dest addr 440 U32V_3(0x8b3ae), // dest addr
496 U32V_1(5), // source size 441 U32V_1(5), // source size
497 0, 1, 2, 3, 4, // data bytes 442 0, 1, 2, 3, 4, // data bytes
498 // rest ------------------------------------------------------ 443 // rest ------------------------------------------------------
499 SECTION(END, 0), 444 SECTION(END, 0),
500 }; 445 };
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 NO_LOCAL_NAMES, // -- 1314 NO_LOCAL_NAMES, // --
1370 FOO_STRING, 1315 FOO_STRING,
1371 NO_LOCAL_NAMES, // -- 1316 NO_LOCAL_NAMES, // --
1372 }; 1317 };
1373 EXPECT_VERIFIES(data); 1318 EXPECT_VERIFIES(data);
1374 } 1319 }
1375 1320
1376 } // namespace wasm 1321 } // namespace wasm
1377 } // namespace internal 1322 } // namespace internal
1378 } // namespace v8 1323 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/wasm/ast-decoder-unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698