OLD | NEW |
---|---|
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 21 matching lines...) Expand all Loading... | |
32 SECTION(FUNCTION_SIGNATURES, 1 + (count)), U32V_1(count), __VA_ARGS__ | 32 SECTION(FUNCTION_SIGNATURES, 1 + (count)), U32V_1(count), __VA_ARGS__ |
33 | 33 |
34 #define FOO_STRING 3, 'f', 'o', 'o' | 34 #define FOO_STRING 3, 'f', 'o', 'o' |
35 #define NO_LOCAL_NAMES 0 | 35 #define NO_LOCAL_NAMES 0 |
36 | 36 |
37 #define EMPTY_SIGNATURES_SECTION SECTION(SIGNATURES, 1), 0 | 37 #define EMPTY_SIGNATURES_SECTION SECTION(SIGNATURES, 1), 0 |
38 #define EMPTY_FUNCTION_SIGNATURES_SECTION SECTION(FUNCTION_SIGNATURES, 1), 0 | 38 #define EMPTY_FUNCTION_SIGNATURES_SECTION SECTION(FUNCTION_SIGNATURES, 1), 0 |
39 #define EMPTY_FUNCTION_BODIES_SECTION SECTION(FUNCTION_BODIES, 1), 0 | 39 #define EMPTY_FUNCTION_BODIES_SECTION SECTION(FUNCTION_BODIES, 1), 0 |
40 #define EMPTY_NAMES_SECTION SECTION(NAMES, 1), 0 | 40 #define EMPTY_NAMES_SECTION SECTION(NAMES, 1), 0 |
41 | 41 |
42 #define X1(...) __VA_ARGS__ | |
43 #define X2(...) __VA_ARGS__, __VA_ARGS__ | |
44 #define X3(...) __VA_ARGS__, __VA_ARGS__, __VA_ARGS__ | |
45 #define X4(...) __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__ | |
46 | |
47 #define ONE_EMPTY_FUNCTION WASM_SECTION_FUNCTION_SIGNATURES, 1 + 1 * 1, 1, X1(0) | |
48 | |
49 #define TWO_EMPTY_FUNCTIONS \ | |
50 WASM_SECTION_FUNCTION_SIGNATURES, 1 + 2 * 1, 2, X2(0) | |
51 | |
52 #define THREE_EMPTY_FUNCTIONS \ | |
53 WASM_SECTION_FUNCTION_SIGNATURES, 1 + 3 * 1, 3, X3(0) | |
54 | |
55 #define FOUR_EMPTY_FUNCTIONS \ | |
56 WASM_SECTION_FUNCTION_SIGNATURES, 1 + 4 * 1, 4, X4(0) | |
57 | |
58 #define ONE_EMPTY_BODY \ | |
59 WASM_SECTION_FUNCTION_BODIES, 1 + 1 * (1 + SIZEOF_EMPTY_BODY), 1, \ | |
60 X1(SIZEOF_EMPTY_BODY, EMPTY_BODY) | |
61 | |
62 #define TWO_EMPTY_BODIES \ | |
63 WASM_SECTION_FUNCTION_BODIES, 1 + 2 * (1 + SIZEOF_EMPTY_BODY), 2, \ | |
64 X2(SIZEOF_EMPTY_BODY, EMPTY_BODY) | |
65 | |
66 #define THREE_EMPTY_BODIES \ | |
67 WASM_SECTION_FUNCTION_BODIES, 1 + 3 * (1 + SIZEOF_EMPTY_BODY), 3, \ | |
68 X3(SIZEOF_EMPTY_BODY, EMPTY_BODY) | |
69 | |
70 #define FOUR_EMPTY_BODIES \ | |
71 WASM_SECTION_FUNCTION_BODIES, 1 + 4 * (1 + SIZEOF_EMPTY_BODY), 4, \ | |
72 X4(SIZEOF_EMPTY_BODY, EMPTY_BODY) | |
73 | |
42 #define SIGNATURES_SECTION_VOID_VOID \ | 74 #define SIGNATURES_SECTION_VOID_VOID \ |
43 SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_v_v), 1, SIG_ENTRY_v_v | 75 SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_v_v), 1, SIG_ENTRY_v_v |
44 | 76 |
45 #define EXPECT_VERIFIES(data) \ | 77 #define EXPECT_VERIFIES(data) \ |
46 do { \ | 78 do { \ |
47 ModuleResult result = DecodeModule(data, data + arraysize(data)); \ | 79 ModuleResult result = DecodeModule(data, data + arraysize(data)); \ |
48 EXPECT_TRUE(result.ok()); \ | 80 EXPECT_TRUE(result.ok()); \ |
49 if (result.val) delete result.val; \ | 81 if (result.val) delete result.val; \ |
50 } while (false) | 82 } while (false) |
51 | 83 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 | 346 |
315 EXPECT_EQ(0, result.val->signatures[0]->parameter_count()); | 347 EXPECT_EQ(0, result.val->signatures[0]->parameter_count()); |
316 EXPECT_EQ(1, result.val->signatures[1]->parameter_count()); | 348 EXPECT_EQ(1, result.val->signatures[1]->parameter_count()); |
317 EXPECT_EQ(2, result.val->signatures[2]->parameter_count()); | 349 EXPECT_EQ(2, result.val->signatures[2]->parameter_count()); |
318 } | 350 } |
319 if (result.val) delete result.val; | 351 if (result.val) delete result.val; |
320 | 352 |
321 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); | 353 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); |
322 } | 354 } |
323 | 355 |
324 TEST_F(WasmModuleVerifyTest, FunctionWithoutSig) { | |
bradnelson
2016/05/25 14:51:23
Why drop these, as they're brittle?
| |
325 static const byte data[] = { | |
326 SECTION(OLD_FUNCTIONS, 25), 1, | |
327 // func#0 ------------------------------------------------------ | |
328 SIG_INDEX(0), // signature index | |
329 NO_NAME, // name length | |
330 U32_LE(0), // code start offset | |
331 U32_LE(0), // code end offset | |
332 U16_LE(899), // local int32 count | |
333 U16_LE(799), // local int64 count | |
334 U16_LE(699), // local float32 count | |
335 U16_LE(599), // local float64 count | |
336 0, // exported | |
337 0 // external | |
338 }; | |
339 | |
340 ModuleResult result = DecodeModule(data, data + arraysize(data)); | |
341 EXPECT_FALSE(result.ok()); | |
342 if (result.val) delete result.val; | |
343 } | |
344 | |
345 TEST_F(WasmModuleVerifyTest, OneEmptyVoidVoidFunction) { | |
346 const int kCodeStartOffset = 41; | |
347 const int kCodeEndOffset = kCodeStartOffset + 1; | |
348 | |
349 static const byte data[] = { | |
350 // signatures | |
351 SIGNATURES_SECTION_VOID_VOID, | |
352 // func#0 ------------------------------------------------------ | |
353 SECTION(OLD_FUNCTIONS, 10), 1, kDeclFunctionExport | kDeclFunctionName, | |
354 SIG_INDEX(0), // signature index | |
355 NAME_LENGTH(2), 'h', 'i', // name | |
356 1, 0, // size | |
357 kExprNop, | |
358 }; | |
359 | |
360 { | |
361 // Should decode to exactly one function. | |
362 ModuleResult result = DecodeModule(data, data + arraysize(data)); | |
363 EXPECT_OK(result); | |
364 EXPECT_EQ(0, result.val->globals.size()); | |
365 EXPECT_EQ(1, result.val->signatures.size()); | |
366 EXPECT_EQ(1, result.val->functions.size()); | |
367 EXPECT_EQ(0, result.val->data_segments.size()); | |
368 EXPECT_EQ(0, result.val->function_table.size()); | |
369 | |
370 const WasmFunction* function = &result.val->functions.back(); | |
371 | |
372 EXPECT_EQ(37, function->name_offset); | |
373 EXPECT_EQ(2, function->name_length); | |
374 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); | |
375 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); | |
376 | |
377 EXPECT_TRUE(function->exported); | |
378 | |
379 if (result.val) delete result.val; | |
380 } | |
381 | |
382 EXPECT_OFF_END_FAILURE(data, 16, sizeof(data)); | |
383 } | |
384 | |
385 TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody) { | |
386 static const byte kCodeStartOffset = 38; | |
387 static const byte kCodeEndOffset = kCodeStartOffset + 1; | |
388 | |
389 static const byte data[] = { | |
390 SIGNATURES_SECTION_VOID_VOID, // -- | |
391 SECTION(OLD_FUNCTIONS, 7), 1, | |
392 // func#0 ------------------------------------------------------ | |
393 0, // no name, no locals | |
394 0, 0, // signature index | |
395 1, 0, // body size | |
396 kExprNop // body | |
397 }; | |
398 | |
399 ModuleResult result = DecodeModule(data, data + arraysize(data)); | |
400 EXPECT_OK(result); | |
401 EXPECT_EQ(1, result.val->functions.size()); | |
402 const WasmFunction* function = &result.val->functions.back(); | |
403 | |
404 EXPECT_EQ(0, function->name_length); | |
405 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); | |
406 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); | |
407 | |
408 EXPECT_FALSE(function->exported); | |
409 | |
410 if (result.val) delete result.val; | |
411 } | |
412 | |
413 TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) { | |
414 static const byte kNameOffset = 49; | |
415 static const byte kCodeStartOffset = 53; | |
416 static const byte kCodeEndOffset = kCodeStartOffset + 3; | |
417 static const byte kDataSegmentSourceOffset = kCodeEndOffset + 22; | |
418 | |
419 static const byte data[] = { | |
420 // global#0 -------------------------------------------------- | |
421 SECTION(GLOBALS, 4), 1, | |
422 0, // name length | |
423 kMemU8, // memory type | |
424 0, // exported | |
425 // sig#0 ----------------------------------------------------- | |
426 SIGNATURES_SECTION_VOID_VOID, | |
427 // func#0 ---------------------------------------------------- | |
428 SECTION(OLD_FUNCTIONS, 12), 1, | |
429 kDeclFunctionName, // -- | |
430 SIG_INDEX(0), // signature index | |
431 2, 'h', 'i', // name | |
432 3, 0, // body size | |
433 kExprNop, // func#0 body | |
434 kExprNop, // func#0 body | |
435 kExprNop, // func#0 body | |
436 // memory section -------------------------------------------- | |
437 SECTION(MEMORY, 3), 28, 28, 1, | |
438 // segment#0 ------------------------------------------------- | |
439 SECTION(DATA_SEGMENTS, 10), 1, | |
440 U32V_3(0x8b3ae), // dest addr | |
441 U32V_1(5), // source size | |
442 0, 1, 2, 3, 4, // data bytes | |
443 // rest ------------------------------------------------------ | |
444 SECTION(END, 0), | |
445 }; | |
446 | |
447 { | |
448 ModuleResult result = DecodeModule(data, data + arraysize(data)); | |
449 EXPECT_OK(result); | |
450 EXPECT_EQ(1, result.val->globals.size()); | |
451 EXPECT_EQ(1, result.val->functions.size()); | |
452 EXPECT_EQ(1, result.val->data_segments.size()); | |
453 | |
454 const WasmGlobal* global = &result.val->globals.back(); | |
455 | |
456 EXPECT_EQ(0, global->name_length); | |
457 EXPECT_EQ(MachineType::Uint8(), global->type); | |
458 EXPECT_EQ(0, global->offset); | |
459 EXPECT_FALSE(global->exported); | |
460 | |
461 const WasmFunction* function = &result.val->functions.back(); | |
462 | |
463 EXPECT_EQ(kNameOffset, function->name_offset); | |
464 EXPECT_EQ(2, function->name_length); | |
465 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); | |
466 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); | |
467 | |
468 EXPECT_FALSE(function->exported); | |
469 | |
470 const WasmDataSegment* segment = &result.val->data_segments.back(); | |
471 | |
472 EXPECT_EQ(0x8b3ae, segment->dest_addr); | |
473 EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset); | |
474 EXPECT_EQ(5, segment->source_size); | |
475 EXPECT_TRUE(segment->init); | |
476 | |
477 if (result.val) delete result.val; | |
478 } | |
479 } | |
480 | |
481 TEST_F(WasmModuleVerifyTest, OneDataSegment) { | 356 TEST_F(WasmModuleVerifyTest, OneDataSegment) { |
482 const byte kDataSegmentSourceOffset = 30; | 357 const byte kDataSegmentSourceOffset = 30; |
483 const byte data[] = { | 358 const byte data[] = { |
484 SECTION(MEMORY, 3), | 359 SECTION(MEMORY, 3), |
485 28, | 360 28, |
486 28, | 361 28, |
487 1, | 362 1, |
488 SECTION(DATA_SEGMENTS, 8), | 363 SECTION(DATA_SEGMENTS, 8), |
489 1, | 364 1, |
490 U32V_3(0x9bbaa), // dest addr | 365 U32V_3(0x9bbaa), // dest addr |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
598 EXPECT_FAILURE(data); | 473 EXPECT_FAILURE(data); |
599 } | 474 } |
600 } | 475 } |
601 } | 476 } |
602 } | 477 } |
603 | 478 |
604 TEST_F(WasmModuleVerifyTest, OneIndirectFunction) { | 479 TEST_F(WasmModuleVerifyTest, OneIndirectFunction) { |
605 static const byte data[] = { | 480 static const byte data[] = { |
606 // sig#0 ------------------------------------------------------- | 481 // sig#0 ------------------------------------------------------- |
607 SIGNATURES_SECTION_VOID_VOID, | 482 SIGNATURES_SECTION_VOID_VOID, |
608 // func#0 ------------------------------------------------------ | 483 // funcs ------------------------------------------------------ |
609 SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), 1, // -- | 484 ONE_EMPTY_FUNCTION, |
610 EMPTY_FUNCTION(0), | |
611 // indirect table ---------------------------------------------- | 485 // indirect table ---------------------------------------------- |
612 SECTION(FUNCTION_TABLE, 2), 1, U32V_1(0)}; | 486 SECTION(FUNCTION_TABLE, 2), 1, U32V_1(0)}; |
613 | 487 |
614 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 488 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
615 EXPECT_OK(result); | 489 EXPECT_OK(result); |
616 if (result.ok()) { | 490 if (result.ok()) { |
617 EXPECT_EQ(1, result.val->signatures.size()); | 491 EXPECT_EQ(1, result.val->signatures.size()); |
618 EXPECT_EQ(1, result.val->functions.size()); | 492 EXPECT_EQ(1, result.val->functions.size()); |
619 EXPECT_EQ(1, result.val->function_table.size()); | 493 EXPECT_EQ(1, result.val->function_table.size()); |
620 EXPECT_EQ(0, result.val->function_table[0]); | 494 EXPECT_EQ(0, result.val->function_table[0]); |
621 } | 495 } |
622 if (result.val) delete result.val; | 496 if (result.val) delete result.val; |
623 } | 497 } |
624 | 498 |
625 TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { | 499 TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { |
626 static const byte data[] = { | 500 static const byte data[] = { |
627 // sig#0 ------------------------------------------------------- | 501 // sig#0 ------------------------------------------------------- |
628 SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_v_x), | 502 SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_v_x), |
629 2, // -- | 503 2, // -- |
630 SIG_ENTRY_v_v, // void -> void | 504 SIG_ENTRY_v_v, // void -> void |
631 SIG_ENTRY_v_x(kLocalI32), // void -> i32 | 505 SIG_ENTRY_v_x(kLocalI32), // void -> i32 |
632 // func#0 ------------------------------------------------------ | 506 // funcs ------------------------------------------------------ |
633 SECTION(OLD_FUNCTIONS, 1 + 4 * SIZEOF_EMPTY_FUNCTION), 4, // -- | 507 FOUR_EMPTY_FUNCTIONS, |
634 EMPTY_FUNCTION(0), // -- | |
635 EMPTY_FUNCTION(1), // -- | |
636 EMPTY_FUNCTION(0), // -- | |
637 EMPTY_FUNCTION(1), // -- | |
638 // indirect table ---------------------------------------------- | 508 // indirect table ---------------------------------------------- |
639 SECTION(FUNCTION_TABLE, 9), 8, | 509 SECTION(FUNCTION_TABLE, 9), 8, |
640 U32V_1(0), // -- | 510 U32V_1(0), // -- |
641 U32V_1(1), // -- | 511 U32V_1(1), // -- |
642 U32V_1(2), // -- | 512 U32V_1(2), // -- |
643 U32V_1(3), // -- | 513 U32V_1(3), // -- |
644 U32V_1(0), // -- | 514 U32V_1(0), // -- |
645 U32V_1(1), // -- | 515 U32V_1(1), // -- |
646 U32V_1(2), // -- | 516 U32V_1(2), // -- |
647 U32V_1(3), // -- | 517 U32V_1(3), // -- |
648 }; | 518 FOUR_EMPTY_BODIES}; |
649 | 519 |
650 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 520 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
651 EXPECT_OK(result); | 521 EXPECT_OK(result); |
652 if (result.ok()) { | 522 if (result.ok()) { |
653 EXPECT_EQ(2, result.val->signatures.size()); | 523 EXPECT_EQ(2, result.val->signatures.size()); |
654 EXPECT_EQ(4, result.val->functions.size()); | 524 EXPECT_EQ(4, result.val->functions.size()); |
655 EXPECT_EQ(8, result.val->function_table.size()); | 525 EXPECT_EQ(8, result.val->function_table.size()); |
656 for (int i = 0; i < 8; i++) { | 526 for (int i = 0; i < 8; i++) { |
657 EXPECT_EQ(i & 3, result.val->function_table[i]); | 527 EXPECT_EQ(i & 3, result.val->function_table[i]); |
658 } | 528 } |
(...skipping 10 matching lines...) Expand all Loading... | |
669 }; | 539 }; |
670 | 540 |
671 EXPECT_FAILURE(data); | 541 EXPECT_FAILURE(data); |
672 } | 542 } |
673 | 543 |
674 TEST_F(WasmModuleVerifyTest, IndirectFunctionInvalidIndex) { | 544 TEST_F(WasmModuleVerifyTest, IndirectFunctionInvalidIndex) { |
675 static const byte data[] = { | 545 static const byte data[] = { |
676 // sig#0 ------------------------------------------------------- | 546 // sig#0 ------------------------------------------------------- |
677 SIGNATURES_SECTION_VOID_VOID, | 547 SIGNATURES_SECTION_VOID_VOID, |
678 // functions --------------------------------------------------- | 548 // functions --------------------------------------------------- |
679 SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), 1, // -- | 549 ONE_EMPTY_FUNCTION, |
680 EMPTY_FUNCTION(0), | |
681 // indirect table ---------------------------------------------- | 550 // indirect table ---------------------------------------------- |
682 SECTION(FUNCTION_TABLE, 3), 1, 1, 0, | 551 SECTION(FUNCTION_TABLE, 3), 1, 1, 0, |
683 }; | 552 }; |
684 | 553 |
685 EXPECT_FAILURE(data); | 554 EXPECT_FAILURE(data); |
686 } | 555 } |
687 | 556 |
688 class WasmSignatureDecodeTest : public TestWithZone {}; | 557 class WasmSignatureDecodeTest : public TestWithZone {}; |
689 | 558 |
690 TEST_F(WasmSignatureDecodeTest, Ok_v_v) { | 559 TEST_F(WasmSignatureDecodeTest, Ok_v_v) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
832 EXPECT_OK(result); | 701 EXPECT_OK(result); |
833 | 702 |
834 if (result.val && result.ok()) { | 703 if (result.val && result.ok()) { |
835 WasmFunction* function = result.val; | 704 WasmFunction* function = result.val; |
836 EXPECT_EQ(0, function->sig->parameter_count()); | 705 EXPECT_EQ(0, function->sig->parameter_count()); |
837 EXPECT_EQ(0, function->sig->return_count()); | 706 EXPECT_EQ(0, function->sig->return_count()); |
838 EXPECT_EQ(0, function->name_offset); | 707 EXPECT_EQ(0, function->name_offset); |
839 EXPECT_EQ(SIZEOF_SIG_ENTRY_v_v, function->code_start_offset); | 708 EXPECT_EQ(SIZEOF_SIG_ENTRY_v_v, function->code_start_offset); |
840 EXPECT_EQ(arraysize(data), function->code_end_offset); | 709 EXPECT_EQ(arraysize(data), function->code_end_offset); |
841 // TODO(titzer): verify encoding of local declarations | 710 // TODO(titzer): verify encoding of local declarations |
842 EXPECT_FALSE(function->exported); | |
843 } | 711 } |
844 | 712 |
845 if (result.val) delete result.val; | 713 if (result.val) delete result.val; |
846 } | 714 } |
847 | 715 |
848 TEST_F(WasmModuleVerifyTest, SectionWithoutNameLength) { | 716 TEST_F(WasmModuleVerifyTest, SectionWithoutNameLength) { |
849 const byte data[] = {1}; | 717 const byte data[] = {1}; |
850 EXPECT_FAILURE(data); | 718 EXPECT_FAILURE(data); |
851 } | 719 } |
852 | 720 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1064 NAME_LENGTH(1), | 932 NAME_LENGTH(1), |
1065 'm', // module name | 933 'm', // module name |
1066 NAME_LENGTH(1), | 934 NAME_LENGTH(1), |
1067 'f', // function name | 935 'f', // function name |
1068 }; | 936 }; |
1069 | 937 |
1070 EXPECT_OFF_END_FAILURE(data, 16, sizeof(data)); | 938 EXPECT_OFF_END_FAILURE(data, 16, sizeof(data)); |
1071 } | 939 } |
1072 | 940 |
1073 TEST_F(WasmModuleVerifyTest, ExportTable_empty1) { | 941 TEST_F(WasmModuleVerifyTest, ExportTable_empty1) { |
1074 static const byte data[] = { | 942 static const byte data[] = {// signatures |
1075 // signatures | 943 SIGNATURES_SECTION_VOID_VOID, ONE_EMPTY_FUNCTION, |
1076 SIGNATURES_SECTION_VOID_VOID, | 944 SECTION(EXPORT_TABLE, 1), |
1077 SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), | 945 0, // -- |
1078 1, | 946 ONE_EMPTY_BODY}; |
1079 EMPTY_FUNCTION(0), | 947 |
1080 SECTION(EXPORT_TABLE, 1), | 948 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
1081 0 // -- | 949 EXPECT_OK(result); |
1082 }; | 950 |
1083 EXPECT_VERIFIES(data); | 951 EXPECT_EQ(1, result.val->functions.size()); |
952 EXPECT_EQ(0, result.val->export_table.size()); | |
953 | |
954 if (result.val) delete result.val; | |
1084 } | 955 } |
1085 | 956 |
1086 TEST_F(WasmModuleVerifyTest, ExportTable_empty2) { | 957 TEST_F(WasmModuleVerifyTest, ExportTable_empty2) { |
1087 static const byte data[] = { | 958 static const byte data[] = { |
1088 SECTION(SIGNATURES, 1), 0, SECTION(OLD_FUNCTIONS, 1), 0, | 959 SECTION(SIGNATURES, 1), 0, SECTION(EXPORT_TABLE, 1), 0 // -- |
1089 SECTION(EXPORT_TABLE, 1), 0 // -- | |
1090 }; | 960 }; |
1091 // TODO(titzer): current behavior treats empty functions section as missing. | 961 // TODO(titzer): current behavior treats empty functions section as missing. |
1092 EXPECT_FAILURE(data); | 962 EXPECT_FAILURE(data); |
1093 } | 963 } |
1094 | 964 |
1095 TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions1) { | 965 TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions1) { |
1096 static const byte data[] = { | 966 static const byte data[] = { |
1097 SECTION(SIGNATURES, 1), 0, SECTION(EXPORT_TABLE, 1), 0 // -- | 967 SECTION(SIGNATURES, 1), 0, SECTION(EXPORT_TABLE, 1), 0 // -- |
1098 }; | 968 }; |
1099 EXPECT_FAILURE(data); | 969 EXPECT_FAILURE(data); |
1100 } | 970 } |
1101 | 971 |
1102 TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions2) { | 972 TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions2) { |
1103 static const byte data[] = {SECTION(EXPORT_TABLE, 1), 0}; | 973 static const byte data[] = {SECTION(EXPORT_TABLE, 1), 0}; |
1104 EXPECT_FAILURE(data); | 974 EXPECT_FAILURE(data); |
1105 } | 975 } |
1106 | 976 |
1107 TEST_F(WasmModuleVerifyTest, ExportTableOne) { | 977 TEST_F(WasmModuleVerifyTest, ExportTableOne) { |
1108 static const byte data[] = { | 978 static const byte data[] = {// signatures |
1109 // signatures | 979 SIGNATURES_SECTION_VOID_VOID, |
1110 SIGNATURES_SECTION_VOID_VOID, | 980 ONE_EMPTY_FUNCTION, |
1111 SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), | 981 SECTION(EXPORT_TABLE, 3), |
1112 1, // functions | 982 1, // exports |
1113 EMPTY_FUNCTION(0), // -- | 983 FUNC_INDEX(0), // -- |
1114 SECTION(EXPORT_TABLE, 3), | 984 NO_NAME, // -- |
1115 1, // exports | 985 ONE_EMPTY_BODY}; |
1116 FUNC_INDEX(0), // -- | 986 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
1117 NO_NAME // -- | 987 EXPECT_OK(result); |
1118 }; | 988 |
1119 EXPECT_VERIFIES(data); | 989 EXPECT_EQ(1, result.val->functions.size()); |
990 EXPECT_EQ(1, result.val->export_table.size()); | |
991 | |
992 if (result.val) delete result.val; | |
1120 } | 993 } |
1121 | 994 |
1122 TEST_F(WasmModuleVerifyTest, ExportTableTwo) { | 995 TEST_F(WasmModuleVerifyTest, ExportTableTwo) { |
1123 static const byte data[] = { | 996 static const byte data[] = {// signatures |
1124 // signatures | 997 SIGNATURES_SECTION_VOID_VOID, |
1125 SIGNATURES_SECTION_VOID_VOID, | 998 ONE_EMPTY_FUNCTION, |
1126 SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), | 999 SECTION(EXPORT_TABLE, 12), |
1127 1, // functions | 1000 2, // exports |
1128 EMPTY_FUNCTION(0), // -- | 1001 FUNC_INDEX(0), // -- |
1129 SECTION(EXPORT_TABLE, 12), | 1002 NAME_LENGTH(4), |
1130 2, // exports | 1003 'n', |
1131 FUNC_INDEX(0), // -- | 1004 'a', |
1132 NAME_LENGTH(4), | 1005 'm', |
1133 'n', | 1006 'e', // -- |
1134 'a', | 1007 FUNC_INDEX(0), // -- |
1135 'm', | 1008 NAME_LENGTH(3), |
1136 'e', // -- | 1009 'n', |
1137 FUNC_INDEX(0), // -- | 1010 'o', |
1138 NAME_LENGTH(3), | 1011 'm', // -- |
1139 'n', | 1012 ONE_EMPTY_BODY}; |
1140 'o', | 1013 |
1141 'm' // -- | 1014 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
1142 }; | 1015 EXPECT_OK(result); |
1143 EXPECT_VERIFIES(data); | 1016 |
1017 EXPECT_EQ(1, result.val->functions.size()); | |
1018 EXPECT_EQ(2, result.val->export_table.size()); | |
1019 | |
1020 if (result.val) delete result.val; | |
1144 } | 1021 } |
1145 | 1022 |
1146 TEST_F(WasmModuleVerifyTest, ExportTableThree) { | 1023 TEST_F(WasmModuleVerifyTest, ExportTableThree) { |
1147 static const byte data[] = { | 1024 static const byte data[] = {// signatures |
1148 // signatures | 1025 SIGNATURES_SECTION_VOID_VOID, |
1149 SIGNATURES_SECTION_VOID_VOID, | 1026 THREE_EMPTY_FUNCTIONS, |
1150 SECTION(OLD_FUNCTIONS, 1 + 3 * SIZEOF_EMPTY_FUNCTION), | 1027 SECTION(EXPORT_TABLE, 10), |
1151 3, // functions | 1028 3, // exports |
1152 EMPTY_FUNCTION(0), // -- | 1029 FUNC_INDEX(0), // -- |
1153 EMPTY_FUNCTION(0), // -- | 1030 NAME_LENGTH(1), |
1154 EMPTY_FUNCTION(0), // -- | 1031 'a', // -- |
1155 SECTION(EXPORT_TABLE, 10), | 1032 FUNC_INDEX(1), // -- |
1156 3, // exports | 1033 NAME_LENGTH(1), |
1157 FUNC_INDEX(0), // -- | 1034 'b', // -- |
1158 NAME_LENGTH(1), | 1035 FUNC_INDEX(2), // -- |
1159 'a', // -- | 1036 NAME_LENGTH(1), |
1160 FUNC_INDEX(1), // -- | 1037 'c', // -- |
1161 NAME_LENGTH(1), | 1038 THREE_EMPTY_BODIES}; |
1162 'b', // -- | 1039 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
1163 FUNC_INDEX(2), // -- | 1040 EXPECT_OK(result); |
1164 NAME_LENGTH(1), | 1041 |
1165 'c' // -- | 1042 EXPECT_EQ(3, result.val->functions.size()); |
1166 }; | 1043 EXPECT_EQ(3, result.val->export_table.size()); |
1167 EXPECT_VERIFIES(data); | 1044 |
1045 if (result.val) delete result.val; | |
1168 } | 1046 } |
1169 | 1047 |
1170 TEST_F(WasmModuleVerifyTest, ExportTableThreeOne) { | 1048 TEST_F(WasmModuleVerifyTest, ExportTableThreeOne) { |
1171 for (int i = 0; i < 6; i++) { | 1049 for (int i = 0; i < 6; i++) { |
1172 const byte data[] = { | 1050 const byte data[] = {// signatures |
1173 // signatures | 1051 SIGNATURES_SECTION_VOID_VOID, |
1174 SIGNATURES_SECTION_VOID_VOID, | 1052 THREE_EMPTY_FUNCTIONS, |
1175 SECTION(OLD_FUNCTIONS, 1 + 3 * SIZEOF_EMPTY_FUNCTION), | 1053 SECTION(EXPORT_TABLE, 5), |
1176 3, // functions | 1054 1, // exports |
1177 EMPTY_FUNCTION(0), // -- | 1055 FUNC_INDEX(i), // -- |
1178 EMPTY_FUNCTION(0), // -- | 1056 NAME_LENGTH(2), |
1179 EMPTY_FUNCTION(0), // -- | 1057 'e', |
1180 SECTION(EXPORT_TABLE, 5), | 1058 'x', // -- |
1181 1, // exports | 1059 THREE_EMPTY_BODIES}; |
1182 FUNC_INDEX(i), // -- | |
1183 NAME_LENGTH(2), | |
1184 'e', | |
1185 'x', // -- | |
1186 }; | |
1187 | 1060 |
1188 if (i < 3) { | 1061 if (i < 3) { |
1189 EXPECT_VERIFIES(data); | 1062 EXPECT_VERIFIES(data); |
1190 } else { | 1063 } else { |
1191 EXPECT_FAILURE(data); | 1064 EXPECT_FAILURE(data); |
1192 } | 1065 } |
1193 } | 1066 } |
1194 } | 1067 } |
1195 | 1068 |
1196 TEST_F(WasmModuleVerifyTest, ExportTableOne_off_end) { | 1069 TEST_F(WasmModuleVerifyTest, ExportTableOne_off_end) { |
1197 static const byte data[] = { | 1070 static const byte data[] = { |
1198 // signatures | 1071 // signatures |
1199 SIGNATURES_SECTION_VOID_VOID, | 1072 SIGNATURES_SECTION_VOID_VOID, |
1200 SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), | 1073 ONE_EMPTY_FUNCTION, |
1201 1, // functions | |
1202 EMPTY_FUNCTION(0), // -- | |
1203 SECTION(EXPORT_TABLE, 1 + 6), | 1074 SECTION(EXPORT_TABLE, 1 + 6), |
1204 1, // exports | 1075 1, // exports |
1205 FUNC_INDEX(0), // -- | 1076 FUNC_INDEX(0), // -- |
1206 NO_NAME // -- | 1077 NO_NAME // -- |
1207 }; | 1078 }; |
1208 | 1079 |
1209 for (int length = 33; length < sizeof(data); length++) { | 1080 for (int length = 33; length < sizeof(data); length++) { |
1210 ModuleResult result = DecodeModule(data, data + length); | 1081 ModuleResult result = DecodeModule(data, data + length); |
1211 EXPECT_FALSE(result.ok()); | 1082 EXPECT_FALSE(result.ok()); |
1212 if (result.val) delete result.val; | 1083 if (result.val) delete result.val; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1314 NO_LOCAL_NAMES, // -- | 1185 NO_LOCAL_NAMES, // -- |
1315 FOO_STRING, | 1186 FOO_STRING, |
1316 NO_LOCAL_NAMES, // -- | 1187 NO_LOCAL_NAMES, // -- |
1317 }; | 1188 }; |
1318 EXPECT_VERIFIES(data); | 1189 EXPECT_VERIFIES(data); |
1319 } | 1190 } |
1320 | 1191 |
1321 } // namespace wasm | 1192 } // namespace wasm |
1322 } // namespace internal | 1193 } // namespace internal |
1323 } // namespace v8 | 1194 } // namespace v8 |
OLD | NEW |