diff options
Diffstat (limited to 'deps/v8/test/unittests')
60 files changed, 2707 insertions, 2024 deletions
diff --git a/deps/v8/test/unittests/BUILD.gn b/deps/v8/test/unittests/BUILD.gn index 77d503c7d4..2da7849073 100644 --- a/deps/v8/test/unittests/BUILD.gn +++ b/deps/v8/test/unittests/BUILD.gn @@ -150,6 +150,7 @@ v8_source_set("unittests_sources") { "eh-frame-iterator-unittest.cc", "eh-frame-writer-unittest.cc", "heap/barrier-unittest.cc", + "heap/bitmap-test-utils.h", "heap/bitmap-unittest.cc", "heap/embedder-tracing-unittest.cc", "heap/gc-idle-time-handler-unittest.cc", @@ -198,7 +199,10 @@ v8_source_set("unittests_sources") { "test-utils.cc", "test-utils.h", "torque/earley-parser-unittest.cc", + "torque/ls-json-unittest.cc", + "torque/ls-message-unittest.cc", "torque/torque-unittest.cc", + "torque/torque-utils-unittest.cc", "unicode-unittest.cc", "utils-unittest.cc", "value-serializer-unittest.cc", @@ -214,7 +218,6 @@ v8_source_set("unittests_sources") { "wasm/wasm-macro-gen-unittest.cc", "wasm/wasm-module-builder-unittest.cc", "wasm/wasm-opcodes-unittest.cc", - "zone/segmentpool-unittest.cc", "zone/zone-allocator-unittest.cc", "zone/zone-chunk-list-unittest.cc", "zone/zone-unittest.cc", @@ -286,6 +289,7 @@ v8_source_set("unittests_sources") { ] deps = [ + "..:common_test_headers", "../..:v8_for_testing", "../..:v8_libbase", "../..:v8_libplatform", diff --git a/deps/v8/test/unittests/background-compile-task-unittest.cc b/deps/v8/test/unittests/background-compile-task-unittest.cc index 5bb6b68285..2577a974fe 100644 --- a/deps/v8/test/unittests/background-compile-task-unittest.cc +++ b/deps/v8/test/unittests/background-compile-task-unittest.cc @@ -18,6 +18,7 @@ #include "src/parsing/parser.h" #include "src/parsing/preparse-data.h" #include "src/v8.h" +#include "src/zone/zone-list-inl.h" #include "test/unittests/test-helpers.h" #include "test/unittests/test-utils.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/deps/v8/test/unittests/base/functional-unittest.cc b/deps/v8/test/unittests/base/functional-unittest.cc index 207d5cbdd7..857a9de5de 100644 --- a/deps/v8/test/unittests/base/functional-unittest.cc +++ b/deps/v8/test/unittests/base/functional-unittest.cc @@ -64,8 +64,7 @@ typedef ::testing::Types<signed char, unsigned char, int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, float, double> FunctionalTypes; -TYPED_TEST_CASE(FunctionalTest, FunctionalTypes); - +TYPED_TEST_SUITE(FunctionalTest, FunctionalTypes); TYPED_TEST(FunctionalTest, EqualToImpliesSameHashCode) { hash<TypeParam> h; diff --git a/deps/v8/test/unittests/base/template-utils-unittest.cc b/deps/v8/test/unittests/base/template-utils-unittest.cc index 42917e0ffc..0819b3de8c 100644 --- a/deps/v8/test/unittests/base/template-utils-unittest.cc +++ b/deps/v8/test/unittests/base/template-utils-unittest.cc @@ -32,7 +32,7 @@ TEST(TemplateUtilsTest, MakeArraySimple) { namespace { constexpr int doubleIntValue(int i) { return i * 2; } -}; // namespace +} // namespace TEST(TemplateUtilsTest, MakeArrayConstexpr) { constexpr auto computed_array = base::make_array<3>(doubleIntValue); diff --git a/deps/v8/test/unittests/base/utils/random-number-generator-unittest.cc b/deps/v8/test/unittests/base/utils/random-number-generator-unittest.cc index 38c14cd96c..6099cd5a59 100644 --- a/deps/v8/test/unittests/base/utils/random-number-generator-unittest.cc +++ b/deps/v8/test/unittests/base/utils/random-number-generator-unittest.cc @@ -244,9 +244,9 @@ TEST_P(RandomNumberGeneratorTest, NextSampleSlowExcludedMax2) { } } -INSTANTIATE_TEST_CASE_P(RandomSeeds, RandomNumberGeneratorTest, - ::testing::Values(INT_MIN, -1, 0, 1, 42, 100, - 1234567890, 987654321, INT_MAX)); +INSTANTIATE_TEST_SUITE_P(RandomSeeds, RandomNumberGeneratorTest, + ::testing::Values(INT_MIN, -1, 0, 1, 42, 100, + 1234567890, 987654321, INT_MAX)); } // namespace base } // namespace v8 diff --git a/deps/v8/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc b/deps/v8/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc index 0f918e3a07..1bad7fed10 100644 --- a/deps/v8/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc +++ b/deps/v8/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc @@ -20,6 +20,7 @@ #include "src/parsing/parse-info.h" #include "src/parsing/parsing.h" #include "src/v8.h" +#include "src/zone/zone-list-inl.h" #include "test/unittests/test-helpers.h" #include "test/unittests/test-utils.h" #include "testing/gtest/include/gtest/gtest.h" @@ -292,7 +293,7 @@ class MockPlatform : public v8::Platform { void PostDelayedTask(std::unique_ptr<Task> task, double delay_in_seconds) override { UNREACHABLE(); - }; + } void PostIdleTask(std::unique_ptr<IdleTask> task) override { DCHECK(IdleTasksEnabled()); @@ -301,7 +302,7 @@ class MockPlatform : public v8::Platform { platform_->idle_task_ = task.release(); } - bool IdleTasksEnabled() override { return true; }; + bool IdleTasksEnabled() override { return true; } private: MockPlatform* platform_; diff --git a/deps/v8/test/unittests/compiler/arm/instruction-selector-arm-unittest.cc b/deps/v8/test/unittests/compiler/arm/instruction-selector-arm-unittest.cc index 77a1587f0b..95be442f0e 100644 --- a/deps/v8/test/unittests/compiler/arm/instruction-selector-arm-unittest.cc +++ b/deps/v8/test/unittests/compiler/arm/instruction-selector-arm-unittest.cc @@ -530,10 +530,8 @@ TEST_P(InstructionSelectorDPITest, BranchIfNotZeroWithImmediate) { } } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorDPITest, - ::testing::ValuesIn(kDPIs)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorDPITest, + ::testing::ValuesIn(kDPIs)); // ----------------------------------------------------------------------------- // Data processing instructions with overflow. @@ -1031,10 +1029,8 @@ TEST_P(InstructionSelectorODPITest, BranchIfNotZeroWithParameters) { EXPECT_EQ(kOverflow, s[0]->flags_condition()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorODPITest, - ::testing::ValuesIn(kODPIs)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorODPITest, + ::testing::ValuesIn(kODPIs)); // ----------------------------------------------------------------------------- // Shifts. @@ -1248,10 +1244,8 @@ TEST_P(InstructionSelectorShiftTest, } } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorShiftTest, - ::testing::ValuesIn(kShifts)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorShiftTest, + ::testing::ValuesIn(kShifts)); // ----------------------------------------------------------------------------- // Memory access instructions. @@ -1400,10 +1394,9 @@ TEST_P(InstructionSelectorMemoryAccessTest, StoreWithImmediateIndex) { } } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorMemoryAccessTest, - ::testing::ValuesIn(kMemoryAccesses)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorMemoryAccessTest, + ::testing::ValuesIn(kMemoryAccesses)); TEST_F(InstructionSelectorMemoryAccessTest, LoadWithShiftedIndex) { TRACED_FORRANGE(int, immediate_shift, 1, 31) { @@ -1572,11 +1565,9 @@ TEST_P(InstructionSelectorComparisonTest, Word32EqualWithZero) { } } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorComparisonTest, - ::testing::ValuesIn(kComparisons)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorComparisonTest, + ::testing::ValuesIn(kComparisons)); // ----------------------------------------------------------------------------- // Floating point comparisons. @@ -1659,11 +1650,9 @@ TEST_P(InstructionSelectorF32ComparisonTest, WithImmediateZeroOnLeft) { EXPECT_EQ(cmp.commuted_flags_condition, s[0]->flags_condition()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorF32ComparisonTest, - ::testing::ValuesIn(kF32Comparisons)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorF32ComparisonTest, + ::testing::ValuesIn(kF32Comparisons)); namespace { @@ -1742,11 +1731,9 @@ TEST_P(InstructionSelectorF64ComparisonTest, WithImmediateZeroOnLeft) { EXPECT_EQ(cmp.commuted_flags_condition, s[0]->flags_condition()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorF64ComparisonTest, - ::testing::ValuesIn(kF64Comparisons)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorF64ComparisonTest, + ::testing::ValuesIn(kF64Comparisons)); // ----------------------------------------------------------------------------- // Floating point arithmetic. @@ -1774,10 +1761,8 @@ TEST_P(InstructionSelectorFAITest, Parameters) { EXPECT_EQ(kFlags_none, s[0]->flags_mode()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorFAITest, - ::testing::ValuesIn(kFAIs)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorFAITest, + ::testing::ValuesIn(kFAIs)); TEST_F(InstructionSelectorTest, Float32Abs) { StreamBuilder m(this, MachineType::Float32(), MachineType::Float32()); @@ -2208,9 +2193,9 @@ TEST_P(InstructionSelectorFlagSettingTest, CommuteShift) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorFlagSettingTest, - ::testing::ValuesIn(kFlagSettingInstructions)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorFlagSettingTest, + ::testing::ValuesIn(kFlagSettingInstructions)); // ----------------------------------------------------------------------------- // Miscellaneous. diff --git a/deps/v8/test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc b/deps/v8/test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc index bca04a5cf3..c5f9645766 100644 --- a/deps/v8/test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc +++ b/deps/v8/test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc @@ -496,10 +496,9 @@ TEST_P(InstructionSelectorLogicalTest, ShiftByImmediate) { } } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorLogicalTest, - ::testing::ValuesIn(kLogicalInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorLogicalTest, + ::testing::ValuesIn(kLogicalInstructions)); // ----------------------------------------------------------------------------- // Add and Sub instructions. @@ -651,10 +650,8 @@ TEST_P(InstructionSelectorAddSubTest, SignedExtendHalfword) { ASSERT_EQ(1U, s[0]->OutputCount()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorAddSubTest, - ::testing::ValuesIn(kAddSubInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorAddSubTest, + ::testing::ValuesIn(kAddSubInstructions)); TEST_F(InstructionSelectorTest, AddImmediateOnLeft) { { @@ -1010,11 +1007,9 @@ TEST_P(InstructionSelectorDPFlagSetTest, BranchWithParameters) { EXPECT_EQ(kNotEqual, s[0]->flags_condition()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorDPFlagSetTest, - ::testing::ValuesIn(kDPFlagSetInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorDPFlagSetTest, + ::testing::ValuesIn(kDPFlagSetInstructions)); TEST_F(InstructionSelectorTest, Word32AndBranchWithImmediateOnRight) { TRACED_FOREACH(int32_t, imm, kLogical32Immediates) { @@ -1282,9 +1277,9 @@ TEST_P(InstructionSelectorTestAndBranchTest, TestAndBranch32) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorTestAndBranchTest, - ::testing::ValuesIn(kTestAndBranchMatchers32)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorTestAndBranchTest, + ::testing::ValuesIn(kTestAndBranchMatchers32)); TEST_F(InstructionSelectorTest, Word64AndBranchWithOneBitMaskOnRight) { TRACED_FORRANGE(int, bit, 0, 63) { @@ -1761,10 +1756,9 @@ TEST_P(InstructionSelectorOvfAddSubTest, RORShift) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorOvfAddSubTest, - ::testing::ValuesIn(kOvfAddSubInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorOvfAddSubTest, + ::testing::ValuesIn(kOvfAddSubInstructions)); TEST_F(InstructionSelectorTest, OvfFlagAddImmediateOnLeft) { TRACED_FOREACH(int32_t, imm, kAddSubImmediates) { @@ -1879,10 +1873,8 @@ TEST_P(InstructionSelectorShiftTest, Immediate) { } } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorShiftTest, - ::testing::ValuesIn(kShiftInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorShiftTest, + ::testing::ValuesIn(kShiftInstructions)); TEST_F(InstructionSelectorTest, Word64ShlWithChangeInt32ToInt64) { TRACED_FORRANGE(int64_t, x, 32, 63) { @@ -1972,10 +1964,8 @@ TEST_P(InstructionSelectorMulDivTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorMulDivTest, - ::testing::ValuesIn(kMulDivInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorMulDivTest, + ::testing::ValuesIn(kMulDivInstructions)); namespace { @@ -2080,11 +2070,9 @@ TEST_P(InstructionSelectorIntDPWithIntMulTest, NegativeMul) { } } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorIntDPWithIntMulTest, - ::testing::ValuesIn(kMulDPInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorIntDPWithIntMulTest, + ::testing::ValuesIn(kMulDPInstructions)); TEST_F(InstructionSelectorTest, Int32MulWithImmediate) { // x * (2^k + 1) -> x + (x << k) @@ -2368,10 +2356,9 @@ TEST_P(InstructionSelectorFPArithTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorFPArithTest, - ::testing::ValuesIn(kFPArithInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorFPArithTest, + ::testing::ValuesIn(kFPArithInstructions)); typedef InstructionSelectorTestWithParam<FPCmp> InstructionSelectorFPCmpTest; @@ -2428,10 +2415,8 @@ TEST_P(InstructionSelectorFPCmpTest, WithImmediateZeroOnLeft) { EXPECT_EQ(cmp.commuted_cond, s[0]->flags_condition()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorFPCmpTest, - ::testing::ValuesIn(kFPCmpInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorFPCmpTest, + ::testing::ValuesIn(kFPCmpInstructions)); // ----------------------------------------------------------------------------- // Conversions. @@ -2455,10 +2440,9 @@ TEST_P(InstructionSelectorConversionTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorConversionTest, - ::testing::ValuesIn(kConversionInstructions)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorConversionTest, + ::testing::ValuesIn(kConversionInstructions)); typedef InstructionSelectorTestWithParam<MachInst2> InstructionSelectorElidedChangeUint32ToUint64Test; @@ -2477,9 +2461,9 @@ TEST_P(InstructionSelectorElidedChangeUint32ToUint64Test, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorElidedChangeUint32ToUint64Test, - ::testing::ValuesIn(kCanElideChangeUint32ToUint64)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorElidedChangeUint32ToUint64Test, + ::testing::ValuesIn(kCanElideChangeUint32ToUint64)); TEST_F(InstructionSelectorTest, ChangeUint32ToUint64AfterLoad) { // For each case, make sure the `ChangeUint32ToUint64` node turned into a @@ -2873,10 +2857,9 @@ TEST_P(InstructionSelectorMemoryAccessTest, StoreWithShiftedIndex) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorMemoryAccessTest, - ::testing::ValuesIn(kMemoryAccesses)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorMemoryAccessTest, + ::testing::ValuesIn(kMemoryAccesses)); // ----------------------------------------------------------------------------- // Comparison instructions. @@ -2943,10 +2926,9 @@ TEST_P(InstructionSelectorComparisonTest, WithImmediate) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorComparisonTest, - ::testing::ValuesIn(kComparisonInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorComparisonTest, + ::testing::ValuesIn(kComparisonInstructions)); TEST_F(InstructionSelectorTest, Word32EqualWithZero) { { @@ -3705,9 +3687,9 @@ TEST_P(InstructionSelectorFlagSettingTest, CommuteShift) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorFlagSettingTest, - ::testing::ValuesIn(kFlagSettingInstructions)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorFlagSettingTest, + ::testing::ValuesIn(kFlagSettingInstructions)); TEST_F(InstructionSelectorTest, TstInvalidImmediate) { // Make sure we do not generate an invalid immediate for TST. @@ -3841,10 +3823,9 @@ TEST_P(InstructionSelectorLogicalWithNotRHSTest, Parameter) { } } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorLogicalWithNotRHSTest, - ::testing::ValuesIn(kLogicalWithNotRHSs)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorLogicalWithNotRHSTest, + ::testing::ValuesIn(kLogicalWithNotRHSs)); TEST_F(InstructionSelectorTest, Word32BitwiseNotWithParameter) { StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); diff --git a/deps/v8/test/unittests/compiler/backend/instruction-selector-unittest.cc b/deps/v8/test/unittests/compiler/backend/instruction-selector-unittest.cc index 59d5dccd06..01400041a8 100644 --- a/deps/v8/test/unittests/compiler/backend/instruction-selector-unittest.cc +++ b/deps/v8/test/unittests/compiler/backend/instruction-selector-unittest.cc @@ -284,7 +284,7 @@ TARGET_TEST_P(InstructionSelectorPhiTest, Referenceness) { EXPECT_EQ(s.IsReference(phi), s.IsReference(param1)); } -INSTANTIATE_TEST_CASE_P( +INSTANTIATE_TEST_SUITE_P( InstructionSelectorTest, InstructionSelectorPhiTest, ::testing::Values(MachineType::Float64(), MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), diff --git a/deps/v8/test/unittests/compiler/common-operator-unittest.cc b/deps/v8/test/unittests/compiler/common-operator-unittest.cc index 4d66ded5f1..19e7c6c55f 100644 --- a/deps/v8/test/unittests/compiler/common-operator-unittest.cc +++ b/deps/v8/test/unittests/compiler/common-operator-unittest.cc @@ -106,10 +106,8 @@ TEST_P(CommonSharedOperatorTest, Properties) { EXPECT_EQ(sop.properties, op->properties()); } - -INSTANTIATE_TEST_CASE_P(CommonOperatorTest, CommonSharedOperatorTest, - ::testing::ValuesIn(kSharedOperators)); - +INSTANTIATE_TEST_SUITE_P(CommonOperatorTest, CommonSharedOperatorTest, + ::testing::ValuesIn(kSharedOperators)); // ----------------------------------------------------------------------------- // Other operators. diff --git a/deps/v8/test/unittests/compiler/constant-folding-reducer-unittest.cc b/deps/v8/test/unittests/compiler/constant-folding-reducer-unittest.cc index 640526bc90..6ee11be686 100644 --- a/deps/v8/test/unittests/compiler/constant-folding-reducer-unittest.cc +++ b/deps/v8/test/unittests/compiler/constant-folding-reducer-unittest.cc @@ -65,7 +65,7 @@ class ConstantFoldingReducerTest : public TypedGraphTest { : TypedGraphTest(3), broker_(isolate(), zone()), simplified_(zone()), - deps_(isolate(), zone()) {} + deps_(&broker_, zone()) {} ~ConstantFoldingReducerTest() override = default; protected: diff --git a/deps/v8/test/unittests/compiler/ia32/instruction-selector-ia32-unittest.cc b/deps/v8/test/unittests/compiler/ia32/instruction-selector-ia32-unittest.cc index 65903506ad..72c82da09e 100644 --- a/deps/v8/test/unittests/compiler/ia32/instruction-selector-ia32-unittest.cc +++ b/deps/v8/test/unittests/compiler/ia32/instruction-selector-ia32-unittest.cc @@ -313,11 +313,9 @@ TEST_P(InstructionSelectorMemoryAccessTest, StoreWithImmediateIndex) { } } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorMemoryAccessTest, - ::testing::ValuesIn(kMemoryAccesses)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorMemoryAccessTest, + ::testing::ValuesIn(kMemoryAccesses)); // ----------------------------------------------------------------------------- // AddressingMode for loads and stores. @@ -622,10 +620,8 @@ TEST_P(InstructionSelectorMultTest, MultAdd32) { } } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorMultTest, - ::testing::ValuesIn(kMultParams)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorMultTest, + ::testing::ValuesIn(kMultParams)); TEST_F(InstructionSelectorTest, Int32MulHigh) { StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(), diff --git a/deps/v8/test/unittests/compiler/js-call-reducer-unittest.cc b/deps/v8/test/unittests/compiler/js-call-reducer-unittest.cc index 171658d830..7147b6c1a7 100644 --- a/deps/v8/test/unittests/compiler/js-call-reducer-unittest.cc +++ b/deps/v8/test/unittests/compiler/js-call-reducer-unittest.cc @@ -21,7 +21,7 @@ namespace compiler { class JSCallReducerTest : public TypedGraphTest { public: JSCallReducerTest() - : TypedGraphTest(3), javascript_(zone()), deps_(isolate(), zone()) { + : TypedGraphTest(3), javascript_(zone()), deps_(broker(), zone()) { broker()->SerializeStandardObjects(); } ~JSCallReducerTest() override = default; diff --git a/deps/v8/test/unittests/compiler/js-create-lowering-unittest.cc b/deps/v8/test/unittests/compiler/js-create-lowering-unittest.cc index 41f0c180e6..dcb621ced0 100644 --- a/deps/v8/test/unittests/compiler/js-create-lowering-unittest.cc +++ b/deps/v8/test/unittests/compiler/js-create-lowering-unittest.cc @@ -32,9 +32,8 @@ class JSCreateLoweringTest : public TypedGraphTest { JSCreateLoweringTest() : TypedGraphTest(3), javascript_(zone()), - deps_(isolate(), zone()), - handle_scope_(isolate()) { - } + deps_(broker(), zone()), + handle_scope_(isolate()) {} ~JSCreateLoweringTest() override = default; protected: diff --git a/deps/v8/test/unittests/compiler/js-operator-unittest.cc b/deps/v8/test/unittests/compiler/js-operator-unittest.cc index 338232b6e0..082e81f27c 100644 --- a/deps/v8/test/unittests/compiler/js-operator-unittest.cc +++ b/deps/v8/test/unittests/compiler/js-operator-unittest.cc @@ -108,9 +108,8 @@ TEST_P(JSSharedOperatorTest, Properties) { EXPECT_EQ(sop.properties, op->properties()); } - -INSTANTIATE_TEST_CASE_P(JSOperatorTest, JSSharedOperatorTest, - ::testing::ValuesIn(kSharedOperators)); +INSTANTIATE_TEST_SUITE_P(JSOperatorTest, JSSharedOperatorTest, + ::testing::ValuesIn(kSharedOperators)); } // namespace js_operator_unittest } // namespace compiler diff --git a/deps/v8/test/unittests/compiler/load-elimination-unittest.cc b/deps/v8/test/unittests/compiler/load-elimination-unittest.cc index 042e7e6bbc..292415fed0 100644 --- a/deps/v8/test/unittests/compiler/load-elimination-unittest.cc +++ b/deps/v8/test/unittests/compiler/load-elimination-unittest.cc @@ -42,7 +42,7 @@ TEST_F(LoadEliminationTest, LoadElementAndLoadElement) { Node* effect = graph()->start(); Node* control = graph()->start(); Node* index = Parameter(Type::UnsignedSmall(), 1); - ElementAccess const access = {kTaggedBase, kPointerSize, Type::Any(), + ElementAccess const access = {kTaggedBase, kTaggedSize, Type::Any(), MachineType::AnyTagged(), kNoWriteBarrier}; StrictMock<MockAdvancedReducerEditor> editor; @@ -68,7 +68,7 @@ TEST_F(LoadEliminationTest, StoreElementAndLoadElement) { Node* control = graph()->start(); Node* index = Parameter(Type::UnsignedSmall(), 1); Node* value = Parameter(Type::Any(), 2); - ElementAccess const access = {kTaggedBase, kPointerSize, Type::Any(), + ElementAccess const access = {kTaggedBase, kTaggedSize, Type::Any(), MachineType::AnyTagged(), kNoWriteBarrier}; StrictMock<MockAdvancedReducerEditor> editor; @@ -95,7 +95,7 @@ TEST_F(LoadEliminationTest, StoreElementAndStoreFieldAndLoadElement) { Node* control = graph()->start(); Node* index = Parameter(Type::UnsignedSmall(), 1); Node* value = Parameter(Type::Any(), 2); - ElementAccess const access = {kTaggedBase, kPointerSize, Type::Any(), + ElementAccess const access = {kTaggedBase, kTaggedSize, Type::Any(), MachineType::AnyTagged(), kNoWriteBarrier}; StrictMock<MockAdvancedReducerEditor> editor; @@ -125,7 +125,7 @@ TEST_F(LoadEliminationTest, LoadFieldAndLoadField) { Node* object = Parameter(Type::Any(), 0); Node* effect = graph()->start(); Node* control = graph()->start(); - FieldAccess const access = {kTaggedBase, kPointerSize, + FieldAccess const access = {kTaggedBase, kTaggedSize, MaybeHandle<Name>(), MaybeHandle<Map>(), Type::Any(), MachineType::AnyTagged(), kNoWriteBarrier}; @@ -152,7 +152,7 @@ TEST_F(LoadEliminationTest, StoreFieldAndLoadField) { Node* value = Parameter(Type::Any(), 1); Node* effect = graph()->start(); Node* control = graph()->start(); - FieldAccess access = {kTaggedBase, kPointerSize, + FieldAccess access = {kTaggedBase, kTaggedSize, MaybeHandle<Name>(), MaybeHandle<Map>(), Type::Any(), MachineType::AnyTagged(), kNoWriteBarrier}; @@ -180,16 +180,16 @@ TEST_F(LoadEliminationTest, StoreFieldAndKillFields) { Node* effect = graph()->start(); Node* control = graph()->start(); - FieldAccess access1 = {kTaggedBase, kPointerSize, - MaybeHandle<Name>(), MaybeHandle<Map>(), - Type::Any(), MachineType::AnyTagged(), - kNoWriteBarrier}; + FieldAccess access1 = {kTaggedBase, kTaggedSize, + MaybeHandle<Name>(), MaybeHandle<Map>(), + Type::Any(), MachineType::AnyTagged(), + kNoWriteBarrier}; // Offset that out of field cache size. - FieldAccess access2 = {kTaggedBase, 2048 * kPointerSize, - MaybeHandle<Name>(), MaybeHandle<Map>(), - Type::Any(), MachineType::AnyTagged(), - kNoWriteBarrier}; + FieldAccess access2 = {kTaggedBase, 2048 * kTaggedSize, + MaybeHandle<Name>(), MaybeHandle<Map>(), + Type::Any(), MachineType::AnyTagged(), + kNoWriteBarrier}; StrictMock<MockAdvancedReducerEditor> editor; LoadElimination load_elimination(&editor, jsgraph(), zone()); @@ -220,7 +220,7 @@ TEST_F(LoadEliminationTest, StoreFieldAndStoreElementAndLoadField) { Node* index = Parameter(Type::UnsignedSmall(), 2); Node* effect = graph()->start(); Node* control = graph()->start(); - FieldAccess access = {kTaggedBase, kPointerSize, + FieldAccess access = {kTaggedBase, kTaggedSize, MaybeHandle<Name>(), MaybeHandle<Map>(), Type::Any(), MachineType::AnyTagged(), kNoWriteBarrier}; @@ -253,7 +253,7 @@ TEST_F(LoadEliminationTest, LoadElementOnTrueBranchOfDiamond) { Node* check = Parameter(Type::Boolean(), 2); Node* effect = graph()->start(); Node* control = graph()->start(); - ElementAccess const access = {kTaggedBase, kPointerSize, Type::Any(), + ElementAccess const access = {kTaggedBase, kTaggedSize, Type::Any(), MachineType::AnyTagged(), kNoWriteBarrier}; StrictMock<MockAdvancedReducerEditor> editor; @@ -288,7 +288,7 @@ TEST_F(LoadEliminationTest, LoadElementOnFalseBranchOfDiamond) { Node* check = Parameter(Type::Boolean(), 2); Node* effect = graph()->start(); Node* control = graph()->start(); - ElementAccess const access = {kTaggedBase, kPointerSize, Type::Any(), + ElementAccess const access = {kTaggedBase, kTaggedSize, Type::Any(), MachineType::AnyTagged(), kNoWriteBarrier}; StrictMock<MockAdvancedReducerEditor> editor; @@ -322,7 +322,7 @@ TEST_F(LoadEliminationTest, LoadFieldOnFalseBranchOfDiamond) { Node* check = Parameter(Type::Boolean(), 1); Node* effect = graph()->start(); Node* control = graph()->start(); - FieldAccess const access = {kTaggedBase, kPointerSize, + FieldAccess const access = {kTaggedBase, kTaggedSize, MaybeHandle<Name>(), MaybeHandle<Map>(), Type::Any(), MachineType::AnyTagged(), kNoWriteBarrier}; @@ -358,7 +358,7 @@ TEST_F(LoadEliminationTest, LoadFieldOnTrueBranchOfDiamond) { Node* check = Parameter(Type::Boolean(), 1); Node* effect = graph()->start(); Node* control = graph()->start(); - FieldAccess const access = {kTaggedBase, kPointerSize, + FieldAccess const access = {kTaggedBase, kTaggedSize, MaybeHandle<Name>(), MaybeHandle<Map>(), Type::Any(), MachineType::AnyTagged(), kNoWriteBarrier}; @@ -394,7 +394,7 @@ TEST_F(LoadEliminationTest, LoadFieldWithTypeMismatch) { Node* value = Parameter(Type::Signed32(), 1); Node* effect = graph()->start(); Node* control = graph()->start(); - FieldAccess const access = {kTaggedBase, kPointerSize, + FieldAccess const access = {kTaggedBase, kTaggedSize, MaybeHandle<Name>(), MaybeHandle<Map>(), Type::Unsigned31(), MachineType::AnyTagged(), kNoWriteBarrier}; @@ -422,7 +422,7 @@ TEST_F(LoadEliminationTest, LoadElementWithTypeMismatch) { Node* value = Parameter(Type::Signed32(), 2); Node* effect = graph()->start(); Node* control = graph()->start(); - ElementAccess const access = {kTaggedBase, kPointerSize, Type::Unsigned31(), + ElementAccess const access = {kTaggedBase, kTaggedSize, Type::Unsigned31(), MachineType::AnyTagged(), kNoWriteBarrier}; StrictMock<MockAdvancedReducerEditor> editor; @@ -446,7 +446,7 @@ TEST_F(LoadEliminationTest, AliasAnalysisForFinishRegion) { Node* value1 = Parameter(Type::Signed32(), 1); Node* effect = graph()->start(); Node* control = graph()->start(); - FieldAccess const access = {kTaggedBase, kPointerSize, + FieldAccess const access = {kTaggedBase, kTaggedSize, MaybeHandle<Name>(), MaybeHandle<Map>(), Type::Signed32(), MachineType::AnyTagged(), kNoWriteBarrier}; diff --git a/deps/v8/test/unittests/compiler/machine-operator-reducer-unittest.cc b/deps/v8/test/unittests/compiler/machine-operator-reducer-unittest.cc index cd70b3bc41..e7ff126702 100644 --- a/deps/v8/test/unittests/compiler/machine-operator-reducer-unittest.cc +++ b/deps/v8/test/unittests/compiler/machine-operator-reducer-unittest.cc @@ -315,6 +315,9 @@ const ComparisonBinaryOperator kComparisonBinaryOperators[] = { #undef OPCODE }; +// Avoid undefined behavior on signed integer overflow. +int32_t Shl(int32_t x, int32_t y) { return static_cast<uint32_t>(x) << y; } + } // namespace @@ -591,13 +594,13 @@ TEST_F(MachineOperatorReducerTest, Word32AndWithWord32ShlWithConstant) { Reduction const r1 = Reduce(graph()->NewNode( machine()->Word32And(), graph()->NewNode(machine()->Word32Shl(), p0, Int32Constant(l)), - Int32Constant(-1 << k))); + Int32Constant(Shl(-1, k)))); ASSERT_TRUE(r1.Changed()); EXPECT_THAT(r1.replacement(), IsWord32Shl(p0, IsInt32Constant(l))); // (-1 << K) & (x << L) => x << L Reduction const r2 = Reduce(graph()->NewNode( - machine()->Word32And(), Int32Constant(-1 << k), + machine()->Word32And(), Int32Constant(Shl(-1, k)), graph()->NewNode(machine()->Word32Shl(), p0, Int32Constant(l)))); ASSERT_TRUE(r2.Changed()); EXPECT_THAT(r2.replacement(), IsWord32Shl(p0, IsInt32Constant(l))); @@ -643,16 +646,16 @@ TEST_F(MachineOperatorReducerTest, Word32AndWithInt32AddAndConstant) { TRACED_FORRANGE(int32_t, l, 1, 31) { TRACED_FOREACH(int32_t, k, kInt32Values) { - if ((k << l) == 0) continue; + if (Shl(k, l) == 0) continue; // (x + (K << L)) & (-1 << L) => (x & (-1 << L)) + (K << L) Reduction const r = Reduce(graph()->NewNode( machine()->Word32And(), - graph()->NewNode(machine()->Int32Add(), p0, Int32Constant(k << l)), - Int32Constant(-1 << l))); + graph()->NewNode(machine()->Int32Add(), p0, Int32Constant(Shl(k, l))), + Int32Constant(Shl(-1, l)))); ASSERT_TRUE(r.Changed()); EXPECT_THAT(r.replacement(), - IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), - IsInt32Constant(k << l))); + IsInt32Add(IsWord32And(p0, IsInt32Constant(Shl(-1, l))), + IsInt32Constant(Shl(k, l)))); } Node* s1 = graph()->NewNode(machine()->Word32Shl(), p1, Int32Constant(l)); @@ -660,18 +663,18 @@ TEST_F(MachineOperatorReducerTest, Word32AndWithInt32AddAndConstant) { // (y << L + x) & (-1 << L) => (x & (-1 << L)) + y << L Reduction const r1 = Reduce(graph()->NewNode( machine()->Word32And(), graph()->NewNode(machine()->Int32Add(), s1, p0), - Int32Constant(-1 << l))); + Int32Constant(Shl(-1, l)))); ASSERT_TRUE(r1.Changed()); EXPECT_THAT(r1.replacement(), - IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), s1)); + IsInt32Add(IsWord32And(p0, IsInt32Constant(Shl(-1, l))), s1)); // (x + y << L) & (-1 << L) => (x & (-1 << L)) + y << L Reduction const r2 = Reduce(graph()->NewNode( machine()->Word32And(), graph()->NewNode(machine()->Int32Add(), p0, s1), - Int32Constant(-1 << l))); + Int32Constant(Shl(-1, l)))); ASSERT_TRUE(r2.Changed()); EXPECT_THAT(r2.replacement(), - IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), s1)); + IsInt32Add(IsWord32And(p0, IsInt32Constant(Shl(-1, l))), s1)); } } @@ -681,23 +684,23 @@ TEST_F(MachineOperatorReducerTest, Word32AndWithInt32MulAndConstant) { TRACED_FORRANGE(int32_t, l, 1, 31) { TRACED_FOREACH(int32_t, k, kInt32Values) { - if ((k << l) == 0) continue; + if (Shl(k, l) == 0) continue; // (x * (K << L)) & (-1 << L) => x * (K << L) Reduction const r1 = Reduce(graph()->NewNode( machine()->Word32And(), - graph()->NewNode(machine()->Int32Mul(), p0, Int32Constant(k << l)), - Int32Constant(-1 << l))); + graph()->NewNode(machine()->Int32Mul(), p0, Int32Constant(Shl(k, l))), + Int32Constant(Shl(-1, l)))); ASSERT_TRUE(r1.Changed()); - EXPECT_THAT(r1.replacement(), IsInt32Mul(p0, IsInt32Constant(k << l))); + EXPECT_THAT(r1.replacement(), IsInt32Mul(p0, IsInt32Constant(Shl(k, l)))); // ((K << L) * x) & (-1 << L) => x * (K << L) Reduction const r2 = Reduce(graph()->NewNode( machine()->Word32And(), - graph()->NewNode(machine()->Int32Mul(), Int32Constant(k << l), p0), - Int32Constant(-1 << l))); + graph()->NewNode(machine()->Int32Mul(), Int32Constant(Shl(k, l)), p0), + Int32Constant(Shl(-1, l)))); ASSERT_TRUE(r2.Changed()); - EXPECT_THAT(r2.replacement(), IsInt32Mul(p0, IsInt32Constant(k << l))); + EXPECT_THAT(r2.replacement(), IsInt32Mul(p0, IsInt32Constant(Shl(k, l)))); } } } @@ -710,31 +713,31 @@ TEST_F(MachineOperatorReducerTest, TRACED_FORRANGE(int32_t, l, 1, 31) { TRACED_FOREACH(int32_t, k, kInt32Values) { - if ((k << l) == 0) continue; + if (Shl(k, l) == 0) continue; // (y * (K << L) + x) & (-1 << L) => (x & (-1 << L)) + y * (K << L) Reduction const r1 = Reduce(graph()->NewNode( machine()->Word32And(), graph()->NewNode(machine()->Int32Add(), graph()->NewNode(machine()->Int32Mul(), p1, - Int32Constant(k << l)), + Int32Constant(Shl(k, l))), p0), - Int32Constant(-1 << l))); + Int32Constant(Shl(-1, l)))); ASSERT_TRUE(r1.Changed()); EXPECT_THAT(r1.replacement(), - IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), - IsInt32Mul(p1, IsInt32Constant(k << l)))); + IsInt32Add(IsWord32And(p0, IsInt32Constant(Shl(-1, l))), + IsInt32Mul(p1, IsInt32Constant(Shl(k, l))))); // (x + y * (K << L)) & (-1 << L) => (x & (-1 << L)) + y * (K << L) Reduction const r2 = Reduce(graph()->NewNode( machine()->Word32And(), graph()->NewNode(machine()->Int32Add(), p0, graph()->NewNode(machine()->Int32Mul(), p1, - Int32Constant(k << l))), - Int32Constant(-1 << l))); + Int32Constant(Shl(k, l)))), + Int32Constant(Shl(-1, l)))); ASSERT_TRUE(r2.Changed()); EXPECT_THAT(r2.replacement(), - IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), - IsInt32Mul(p1, IsInt32Constant(k << l)))); + IsInt32Add(IsWord32And(p0, IsInt32Constant(Shl(-1, l))), + IsInt32Mul(p1, IsInt32Constant(Shl(k, l))))); } } } @@ -1012,7 +1015,7 @@ TEST_F(MachineOperatorReducerTest, Word32ShlWithWord32Sar) { Int32Constant(x)); Reduction r = Reduce(node); ASSERT_TRUE(r.Changed()); - int32_t m = bit_cast<int32_t>(~((1U << x) - 1U)); + int32_t m = static_cast<int32_t>(~((1U << x) - 1U)); EXPECT_THAT(r.replacement(), IsWord32And(p0, IsInt32Constant(m))); } } @@ -1023,19 +1026,19 @@ TEST_F(MachineOperatorReducerTest, Node* const p0 = Parameter(0); TRACED_FOREACH(int32_t, k, kInt32Values) { TRACED_FORRANGE(int32_t, l, 1, 31) { - if ((k << l) == 0) continue; + if (Shl(k, l) == 0) continue; // (x + (K << L)) >> L << L => (x & (-1 << L)) + (K << L) Reduction const r = Reduce(graph()->NewNode( machine()->Word32Shl(), graph()->NewNode(machine()->Word32Sar(), graph()->NewNode(machine()->Int32Add(), p0, - Int32Constant(k << l)), + Int32Constant(Shl(k, l))), Int32Constant(l)), Int32Constant(l))); ASSERT_TRUE(r.Changed()); EXPECT_THAT(r.replacement(), - IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), - IsInt32Constant(k << l))); + IsInt32Add(IsWord32And(p0, IsInt32Constant(Shl(-1, l))), + IsInt32Constant(Shl(k, l)))); } } } @@ -1050,7 +1053,7 @@ TEST_F(MachineOperatorReducerTest, Word32ShlWithWord32Shr) { Int32Constant(x)); Reduction r = Reduce(node); ASSERT_TRUE(r.Changed()); - int32_t m = bit_cast<int32_t>(~((1U << x) - 1U)); + int32_t m = static_cast<int32_t>(~((1U << x) - 1U)); EXPECT_THAT(r.replacement(), IsWord32And(p0, IsInt32Constant(m))); } } @@ -1134,10 +1137,9 @@ TEST_F(MachineOperatorReducerTest, Int32DivWithConstant) { IsInt32Constant(shift))); } TRACED_FORRANGE(int32_t, shift, 2, 31) { - Reduction const r = Reduce(graph()->NewNode( - machine()->Int32Div(), p0, - Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift), - graph()->start())); + Reduction const r = Reduce(graph()->NewNode(machine()->Int32Div(), p0, + Int32Constant(Shl(-1, shift)), + graph()->start())); ASSERT_TRUE(r.Changed()); EXPECT_THAT( r.replacement(), @@ -1220,7 +1222,7 @@ TEST_F(MachineOperatorReducerTest, Uint32DivWithConstant) { Uint32Constant(1u << shift), graph()->start())); ASSERT_TRUE(r.Changed()); EXPECT_THAT(r.replacement(), - IsWord32Shr(p0, IsInt32Constant(bit_cast<int32_t>(shift)))); + IsWord32Shr(p0, IsInt32Constant(static_cast<int32_t>(shift)))); } } @@ -1296,11 +1298,10 @@ TEST_F(MachineOperatorReducerTest, Int32ModWithConstant) { graph()->start()))))); } TRACED_FORRANGE(int32_t, shift, 1, 31) { - Reduction const r = Reduce(graph()->NewNode( - machine()->Int32Mod(), p0, - Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift), - graph()->start())); - int32_t const mask = bit_cast<int32_t, uint32_t>((1U << shift) - 1); + Reduction const r = Reduce(graph()->NewNode(machine()->Int32Mod(), p0, + Int32Constant(Shl(-1, shift)), + graph()->start())); + int32_t const mask = static_cast<int32_t>((1U << shift) - 1U); ASSERT_TRUE(r.Changed()); EXPECT_THAT( r.replacement(), @@ -1378,7 +1379,7 @@ TEST_F(MachineOperatorReducerTest, Uint32ModWithConstant) { ASSERT_TRUE(r.Changed()); EXPECT_THAT(r.replacement(), IsWord32And(p0, IsInt32Constant( - bit_cast<int32_t>((1u << shift) - 1u)))); + static_cast<int32_t>((1u << shift) - 1u)))); } } @@ -1676,7 +1677,7 @@ TEST_F(MachineOperatorReducerTest, Uint32LessThanWithWord32Sar) { ASSERT_TRUE(r.Changed()); EXPECT_THAT(r.replacement(), IsUint32LessThan( - p0, IsInt32Constant(bit_cast<int32_t>(limit << shift)))); + p0, IsInt32Constant(static_cast<int32_t>(limit << shift)))); } } @@ -1958,8 +1959,9 @@ TEST_F(MachineOperatorReducerTest, Float64PowWithConstant) { Reduction const r = Reduce(graph()->NewNode( machine()->Float64Pow(), Float64Constant(x), Float64Constant(y))); ASSERT_TRUE(r.Changed()); - EXPECT_THAT(r.replacement(), - IsFloat64Constant(NanSensitiveDoubleEq(Pow(x, y)))); + EXPECT_THAT( + r.replacement(), + IsFloat64Constant(NanSensitiveDoubleEq(base::ieee754::pow(x, y)))); } } } @@ -2225,7 +2227,7 @@ TEST_F(MachineOperatorReducerTest, Float64RoundDownWithConstant) { Reduction r = Reduce(graph()->NewNode( machine()->Float64RoundDown().placeholder(), Float64Constant(x))); ASSERT_TRUE(r.Changed()); - EXPECT_THAT(r.replacement(), IsFloat64Constant(Floor(x))); + EXPECT_THAT(r.replacement(), IsFloat64Constant(std::floor(x))); } } diff --git a/deps/v8/test/unittests/compiler/machine-operator-unittest.cc b/deps/v8/test/unittests/compiler/machine-operator-unittest.cc index 9eddb1d311..c4a86afffd 100644 --- a/deps/v8/test/unittests/compiler/machine-operator-unittest.cc +++ b/deps/v8/test/unittests/compiler/machine-operator-unittest.cc @@ -89,13 +89,11 @@ TEST_P(MachineLoadOperatorTest, ParameterIsCorrect) { EXPECT_EQ(GetParam(), LoadRepresentationOf(machine.Load(GetParam()))); } - -INSTANTIATE_TEST_CASE_P( +INSTANTIATE_TEST_SUITE_P( MachineOperatorTest, MachineLoadOperatorTest, ::testing::Combine(::testing::ValuesIn(kMachineReps), ::testing::ValuesIn(kMachineTypesForAccess))); - // ----------------------------------------------------------------------------- // Store operator. @@ -149,8 +147,7 @@ TEST_P(MachineStoreOperatorTest, ParameterIsCorrect) { EXPECT_EQ(GetParam(), StoreRepresentationOf(machine.Store(GetParam()))); } - -INSTANTIATE_TEST_CASE_P( +INSTANTIATE_TEST_SUITE_P( MachineOperatorTest, MachineStoreOperatorTest, ::testing::Combine( ::testing::ValuesIn(kMachineReps), diff --git a/deps/v8/test/unittests/compiler/mips/instruction-selector-mips-unittest.cc b/deps/v8/test/unittests/compiler/mips/instruction-selector-mips-unittest.cc index 83edb6a21e..09a897a54e 100644 --- a/deps/v8/test/unittests/compiler/mips/instruction-selector-mips-unittest.cc +++ b/deps/v8/test/unittests/compiler/mips/instruction-selector-mips-unittest.cc @@ -292,9 +292,8 @@ TEST_P(InstructionSelectorFPCmpTest, Parameter) { EXPECT_EQ(cmp.cond, s[0]->flags_condition()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorFPCmpTest, - ::testing::ValuesIn(kFPCmpInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorFPCmpTest, + ::testing::ValuesIn(kFPCmpInstructions)); // ---------------------------------------------------------------------------- // Arithmetic compare instructions integers. @@ -316,10 +315,8 @@ TEST_P(InstructionSelectorCmpTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorCmpTest, - ::testing::ValuesIn(kCmpInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorCmpTest, + ::testing::ValuesIn(kCmpInstructions)); // ---------------------------------------------------------------------------- // Shift instructions. @@ -347,10 +344,8 @@ TEST_P(InstructionSelectorShiftTest, Immediate) { } } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorShiftTest, - ::testing::ValuesIn(kShiftInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorShiftTest, + ::testing::ValuesIn(kShiftInstructions)); TEST_F(InstructionSelectorTest, Word32ShrWithWord32AndWithImmediate) { // The available shift operand range is `0 <= imm < 32`, but we also test @@ -464,10 +459,9 @@ TEST_P(InstructionSelectorLogicalTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorLogicalTest, - ::testing::ValuesIn(kLogicalInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorLogicalTest, + ::testing::ValuesIn(kLogicalInstructions)); TEST_F(InstructionSelectorTest, Word32XorMinusOneWithParameter) { { @@ -601,10 +595,8 @@ TEST_P(InstructionSelectorMulDivTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorMulDivTest, - ::testing::ValuesIn(kMulDivInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorMulDivTest, + ::testing::ValuesIn(kMulDivInstructions)); // ---------------------------------------------------------------------------- // MOD instructions. @@ -626,10 +618,8 @@ TEST_P(InstructionSelectorModTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorModTest, - ::testing::ValuesIn(kModInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorModTest, + ::testing::ValuesIn(kModInstructions)); // ---------------------------------------------------------------------------- // Floating point instructions. @@ -651,10 +641,9 @@ TEST_P(InstructionSelectorFPArithTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorFPArithTest, - ::testing::ValuesIn(kFPArithInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorFPArithTest, + ::testing::ValuesIn(kFPArithInstructions)); // ---------------------------------------------------------------------------- // Integer arithmetic. @@ -677,11 +666,9 @@ TEST_P(InstructionSelectorIntArithTwoTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorIntArithTwoTest, - ::testing::ValuesIn(kAddSubInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorIntArithTwoTest, + ::testing::ValuesIn(kAddSubInstructions)); // ---------------------------------------------------------------------------- // One node. @@ -704,11 +691,9 @@ TEST_P(InstructionSelectorIntArithOneTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorIntArithOneTest, - ::testing::ValuesIn(kAddSubOneInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorIntArithOneTest, + ::testing::ValuesIn(kAddSubOneInstructions)); // ---------------------------------------------------------------------------- // Conversions. @@ -730,11 +715,9 @@ TEST_P(InstructionSelectorConversionTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorConversionTest, - ::testing::ValuesIn(kConversionInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorConversionTest, + ::testing::ValuesIn(kConversionInstructions)); typedef InstructionSelectorTestWithParam<Conversion> CombineChangeFloat64ToInt32WithRoundFloat64; @@ -753,10 +736,9 @@ TEST_P(CombineChangeFloat64ToInt32WithRoundFloat64, Parameter) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - CombineChangeFloat64ToInt32WithRoundFloat64, - ::testing::ValuesIn(kFloat64RoundInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + CombineChangeFloat64ToInt32WithRoundFloat64, + ::testing::ValuesIn(kFloat64RoundInstructions)); typedef InstructionSelectorTestWithParam<Conversion> CombineChangeFloat32ToInt32WithRoundFloat32; @@ -776,10 +758,9 @@ TEST_P(CombineChangeFloat32ToInt32WithRoundFloat32, Parameter) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - CombineChangeFloat32ToInt32WithRoundFloat32, - ::testing::ValuesIn(kFloat32RoundInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + CombineChangeFloat32ToInt32WithRoundFloat32, + ::testing::ValuesIn(kFloat32RoundInstructions)); TEST_F(InstructionSelectorTest, ChangeFloat64ToInt32OfChangeFloat32ToFloat64) { { @@ -1035,11 +1016,9 @@ TEST_P(InstructionSelectorMemoryAccessTest, StoreWithParameters) { EXPECT_EQ(kMode_MRI, s[0]->addressing_mode()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorMemoryAccessTest, - ::testing::ValuesIn(kMemoryAccesses)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorMemoryAccessTest, + ::testing::ValuesIn(kMemoryAccesses)); // ---------------------------------------------------------------------------- // Load immediate. @@ -1112,9 +1091,9 @@ TEST_P(InstructionSelectorMemoryAccessImmTest, StoreZero) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorMemoryAccessImmTest, - ::testing::ValuesIn(kMemoryAccessesImm)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorMemoryAccessImmTest, + ::testing::ValuesIn(kMemoryAccessesImm)); typedef InstructionSelectorTestWithParam<MemoryAccessImm2> InstructionSelectorMemoryAccessUnalignedImmTest; @@ -1143,9 +1122,9 @@ TEST_P(InstructionSelectorMemoryAccessUnalignedImmTest, StoreZero) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorMemoryAccessUnalignedImmTest, - ::testing::ValuesIn(kMemoryAccessesImmUnaligned)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorMemoryAccessUnalignedImmTest, + ::testing::ValuesIn(kMemoryAccessesImmUnaligned)); // ---------------------------------------------------------------------------- // Load/store offsets more than 16 bits. @@ -1190,11 +1169,9 @@ TEST_P(InstructionSelectorMemoryAccessImmMoreThan16bitTest, } } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorMemoryAccessImmMoreThan16bitTest, - ::testing::ValuesIn(kMemoryAccessImmMoreThan16bit)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorMemoryAccessImmMoreThan16bitTest, + ::testing::ValuesIn(kMemoryAccessImmMoreThan16bit)); // ---------------------------------------------------------------------------- // kMipsTst testing. diff --git a/deps/v8/test/unittests/compiler/mips64/instruction-selector-mips64-unittest.cc b/deps/v8/test/unittests/compiler/mips64/instruction-selector-mips64-unittest.cc index c6c1ff3ee8..cd73fe3c9b 100644 --- a/deps/v8/test/unittests/compiler/mips64/instruction-selector-mips64-unittest.cc +++ b/deps/v8/test/unittests/compiler/mips64/instruction-selector-mips64-unittest.cc @@ -316,8 +316,8 @@ TEST_P(InstructionSelectorFPCmpTest, Parameter) { EXPECT_EQ(cmp.cond, s[0]->flags_condition()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorFPCmpTest, - ::testing::ValuesIn(kFPCmpInstructions)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorFPCmpTest, + ::testing::ValuesIn(kFPCmpInstructions)); // ---------------------------------------------------------------------------- // Arithmetic compare instructions integers @@ -367,8 +367,8 @@ TEST_P(InstructionSelectorCmpTest, Parameter) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorCmpTest, - ::testing::ValuesIn(kCmpInstructions)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorCmpTest, + ::testing::ValuesIn(kCmpInstructions)); // ---------------------------------------------------------------------------- // Shift instructions. @@ -393,8 +393,8 @@ TEST_P(InstructionSelectorShiftTest, Immediate) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorShiftTest, - ::testing::ValuesIn(kShiftInstructions)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorShiftTest, + ::testing::ValuesIn(kShiftInstructions)); TEST_F(InstructionSelectorTest, Word32ShrWithWord32AndWithImmediate) { // The available shift operand range is `0 <= imm < 32`, but we also test @@ -549,9 +549,9 @@ TEST_P(InstructionSelectorLogicalTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorLogicalTest, - ::testing::ValuesIn(kLogicalInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorLogicalTest, + ::testing::ValuesIn(kLogicalInstructions)); TEST_F(InstructionSelectorTest, Word64XorMinusOneWithParameter) { { @@ -824,8 +824,8 @@ TEST_P(InstructionSelectorMulDivTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorMulDivTest, - ::testing::ValuesIn(kMulDivInstructions)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorMulDivTest, + ::testing::ValuesIn(kMulDivInstructions)); // ---------------------------------------------------------------------------- // MOD instructions. @@ -844,8 +844,8 @@ TEST_P(InstructionSelectorModTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorModTest, - ::testing::ValuesIn(kModInstructions)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, InstructionSelectorModTest, + ::testing::ValuesIn(kModInstructions)); // ---------------------------------------------------------------------------- // Floating point instructions. @@ -864,8 +864,9 @@ TEST_P(InstructionSelectorFPArithTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorFPArithTest, - ::testing::ValuesIn(kFPArithInstructions)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorFPArithTest, + ::testing::ValuesIn(kFPArithInstructions)); // ---------------------------------------------------------------------------- // Integer arithmetic // ---------------------------------------------------------------------------- @@ -884,10 +885,9 @@ TEST_P(InstructionSelectorIntArithTwoTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorIntArithTwoTest, - ::testing::ValuesIn(kAddSubInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorIntArithTwoTest, + ::testing::ValuesIn(kAddSubInstructions)); // ---------------------------------------------------------------------------- // One node. @@ -909,9 +909,9 @@ TEST_P(InstructionSelectorIntArithOneTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorIntArithOneTest, - ::testing::ValuesIn(kAddSubOneInstructions)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorIntArithOneTest, + ::testing::ValuesIn(kAddSubOneInstructions)); // ---------------------------------------------------------------------------- // Conversions. // ---------------------------------------------------------------------------- @@ -929,9 +929,9 @@ TEST_P(InstructionSelectorConversionTest, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorConversionTest, - ::testing::ValuesIn(kConversionInstructions)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorConversionTest, + ::testing::ValuesIn(kConversionInstructions)); TEST_F(InstructionSelectorTest, ChangesFromToSmi) { { @@ -975,9 +975,9 @@ TEST_P(CombineChangeFloat64ToInt32WithRoundFloat64, Parameter) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - CombineChangeFloat64ToInt32WithRoundFloat64, - ::testing::ValuesIn(kFloat64RoundInstructions)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + CombineChangeFloat64ToInt32WithRoundFloat64, + ::testing::ValuesIn(kFloat64RoundInstructions)); typedef InstructionSelectorTestWithParam<Conversion> CombineChangeFloat32ToInt32WithRoundFloat32; @@ -997,10 +997,9 @@ TEST_P(CombineChangeFloat32ToInt32WithRoundFloat32, Parameter) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - CombineChangeFloat32ToInt32WithRoundFloat32, - ::testing::ValuesIn(kFloat32RoundInstructions)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + CombineChangeFloat32ToInt32WithRoundFloat32, + ::testing::ValuesIn(kFloat32RoundInstructions)); TEST_F(InstructionSelectorTest, ChangeFloat64ToInt32OfChangeFloat32ToFloat64) { { @@ -1172,9 +1171,9 @@ TEST_P(InstructionSelectorElidedChangeUint32ToUint64Test, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorElidedChangeUint32ToUint64Test, - ::testing::ValuesIn(kCanElideChangeUint32ToUint64)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorElidedChangeUint32ToUint64Test, + ::testing::ValuesIn(kCanElideChangeUint32ToUint64)); TEST_F(InstructionSelectorTest, ChangeUint32ToUint64AfterLoad) { // For each case, make sure the `ChangeUint32ToUint64` node turned into a @@ -1477,10 +1476,9 @@ TEST_P(InstructionSelectorMemoryAccessTest, StoreWithParameters) { EXPECT_EQ(kMode_MRI, s[0]->addressing_mode()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorMemoryAccessTest, - ::testing::ValuesIn(kMemoryAccesses)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorMemoryAccessTest, + ::testing::ValuesIn(kMemoryAccesses)); // ---------------------------------------------------------------------------- // Load immediate. @@ -1552,9 +1550,9 @@ TEST_P(InstructionSelectorMemoryAccessImmTest, StoreZero) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorMemoryAccessImmTest, - ::testing::ValuesIn(kMemoryAccessesImm)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorMemoryAccessImmTest, + ::testing::ValuesIn(kMemoryAccessesImm)); typedef InstructionSelectorTestWithParam<MemoryAccessImm2> InstructionSelectorMemoryAccessUnalignedImmTest; @@ -1583,9 +1581,9 @@ TEST_P(InstructionSelectorMemoryAccessUnalignedImmTest, StoreZero) { } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorMemoryAccessUnalignedImmTest, - ::testing::ValuesIn(kMemoryAccessesImmUnaligned)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorMemoryAccessUnalignedImmTest, + ::testing::ValuesIn(kMemoryAccessesImmUnaligned)); // ---------------------------------------------------------------------------- // Load/store offsets more than 16 bits. @@ -1628,10 +1626,9 @@ TEST_P(InstructionSelectorMemoryAccessImmMoreThan16bitTest, } } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorMemoryAccessImmMoreThan16bitTest, - ::testing::ValuesIn(kMemoryAccessImmMoreThan16bit)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorMemoryAccessImmMoreThan16bitTest, + ::testing::ValuesIn(kMemoryAccessImmMoreThan16bit)); // ---------------------------------------------------------------------------- // kMips64Cmp with zero testing. diff --git a/deps/v8/test/unittests/compiler/node-test-utils.cc b/deps/v8/test/unittests/compiler/node-test-utils.cc index f23265e8e4..cedbfb9daf 100644 --- a/deps/v8/test/unittests/compiler/node-test-utils.cc +++ b/deps/v8/test/unittests/compiler/node-test-utils.cc @@ -1946,7 +1946,7 @@ Matcher<Node*> IsTailCall( IrOpcode::k##opcode, hint_matcher, lhs_matcher, rhs_matcher, \ effect_matcher, control_matcher)); \ } -SIMPLIFIED_SPECULATIVE_NUMBER_BINOP_LIST(DEFINE_SPECULATIVE_BINOP_MATCHER); +SIMPLIFIED_SPECULATIVE_NUMBER_BINOP_LIST(DEFINE_SPECULATIVE_BINOP_MATCHER) DEFINE_SPECULATIVE_BINOP_MATCHER(SpeculativeNumberEqual) DEFINE_SPECULATIVE_BINOP_MATCHER(SpeculativeNumberLessThan) DEFINE_SPECULATIVE_BINOP_MATCHER(SpeculativeNumberLessThanOrEqual) diff --git a/deps/v8/test/unittests/compiler/node-test-utils.h b/deps/v8/test/unittests/compiler/node-test-utils.h index 96bdbdf3be..2fdfb99e48 100644 --- a/deps/v8/test/unittests/compiler/node-test-utils.h +++ b/deps/v8/test/unittests/compiler/node-test-utils.h @@ -212,7 +212,7 @@ Matcher<Node*> IsNumberAdd(const Matcher<Node*>& lhs_matcher, const Matcher<Node*>& rhs_matcher, \ const Matcher<Node*>& effect_matcher, \ const Matcher<Node*>& control_matcher); -SIMPLIFIED_SPECULATIVE_NUMBER_BINOP_LIST(DECLARE_SPECULATIVE_BINOP_MATCHER); +SIMPLIFIED_SPECULATIVE_NUMBER_BINOP_LIST(DECLARE_SPECULATIVE_BINOP_MATCHER) DECLARE_SPECULATIVE_BINOP_MATCHER(SpeculativeNumberEqual) DECLARE_SPECULATIVE_BINOP_MATCHER(SpeculativeNumberLessThan) DECLARE_SPECULATIVE_BINOP_MATCHER(SpeculativeNumberLessThanOrEqual) @@ -499,83 +499,83 @@ Matcher<Node*> IsSpeculativeToNumber(const Matcher<Node*>& value_matcher); // Helpers static inline Matcher<Node*> IsIntPtrConstant(const intptr_t value) { - return kPointerSize == 8 ? IsInt64Constant(static_cast<int64_t>(value)) - : IsInt32Constant(static_cast<int32_t>(value)); + return kSystemPointerSize == 8 ? IsInt64Constant(static_cast<int64_t>(value)) + : IsInt32Constant(static_cast<int32_t>(value)); } static inline Matcher<Node*> IsIntPtrAdd(const Matcher<Node*>& lhs_matcher, const Matcher<Node*>& rhs_matcher) { - return kPointerSize == 8 ? IsInt64Add(lhs_matcher, rhs_matcher) - : IsInt32Add(lhs_matcher, rhs_matcher); + return kSystemPointerSize == 8 ? IsInt64Add(lhs_matcher, rhs_matcher) + : IsInt32Add(lhs_matcher, rhs_matcher); } static inline Matcher<Node*> IsIntPtrSub(const Matcher<Node*>& lhs_matcher, const Matcher<Node*>& rhs_matcher) { - return kPointerSize == 8 ? IsInt64Sub(lhs_matcher, rhs_matcher) - : IsInt32Sub(lhs_matcher, rhs_matcher); + return kSystemPointerSize == 8 ? IsInt64Sub(lhs_matcher, rhs_matcher) + : IsInt32Sub(lhs_matcher, rhs_matcher); } static inline Matcher<Node*> IsIntPtrMul(const Matcher<Node*>& lhs_matcher, const Matcher<Node*>& rhs_matcher) { - return kPointerSize == 8 ? IsInt64Mul(lhs_matcher, rhs_matcher) - : IsInt32Mul(lhs_matcher, rhs_matcher); + return kSystemPointerSize == 8 ? IsInt64Mul(lhs_matcher, rhs_matcher) + : IsInt32Mul(lhs_matcher, rhs_matcher); } static inline Matcher<Node*> IsIntPtrDiv(const Matcher<Node*>& lhs_matcher, const Matcher<Node*>& rhs_matcher) { - return kPointerSize == 8 ? IsInt64Div(lhs_matcher, rhs_matcher) - : IsInt32Div(lhs_matcher, rhs_matcher); + return kSystemPointerSize == 8 ? IsInt64Div(lhs_matcher, rhs_matcher) + : IsInt32Div(lhs_matcher, rhs_matcher); } static inline Matcher<Node*> IsWordShl(const Matcher<Node*>& lhs_matcher, const Matcher<Node*>& rhs_matcher) { - return kPointerSize == 8 ? IsWord64Shl(lhs_matcher, rhs_matcher) - : IsWord32Shl(lhs_matcher, rhs_matcher); + return kSystemPointerSize == 8 ? IsWord64Shl(lhs_matcher, rhs_matcher) + : IsWord32Shl(lhs_matcher, rhs_matcher); } static inline Matcher<Node*> IsWordShr(const Matcher<Node*>& lhs_matcher, const Matcher<Node*>& rhs_matcher) { - return kPointerSize == 8 ? IsWord64Shr(lhs_matcher, rhs_matcher) - : IsWord32Shr(lhs_matcher, rhs_matcher); + return kSystemPointerSize == 8 ? IsWord64Shr(lhs_matcher, rhs_matcher) + : IsWord32Shr(lhs_matcher, rhs_matcher); } static inline Matcher<Node*> IsWordSar(const Matcher<Node*>& lhs_matcher, const Matcher<Node*>& rhs_matcher) { - return kPointerSize == 8 ? IsWord64Sar(lhs_matcher, rhs_matcher) - : IsWord32Sar(lhs_matcher, rhs_matcher); + return kSystemPointerSize == 8 ? IsWord64Sar(lhs_matcher, rhs_matcher) + : IsWord32Sar(lhs_matcher, rhs_matcher); } static inline Matcher<Node*> IsWordAnd(const Matcher<Node*>& lhs_matcher, const Matcher<Node*>& rhs_matcher) { - return kPointerSize == 8 ? IsWord64And(lhs_matcher, rhs_matcher) - : IsWord32And(lhs_matcher, rhs_matcher); + return kSystemPointerSize == 8 ? IsWord64And(lhs_matcher, rhs_matcher) + : IsWord32And(lhs_matcher, rhs_matcher); } static inline Matcher<Node*> IsWordOr(const Matcher<Node*>& lhs_matcher, const Matcher<Node*>& rhs_matcher) { - return kPointerSize == 8 ? IsWord64Or(lhs_matcher, rhs_matcher) - : IsWord32Or(lhs_matcher, rhs_matcher); + return kSystemPointerSize == 8 ? IsWord64Or(lhs_matcher, rhs_matcher) + : IsWord32Or(lhs_matcher, rhs_matcher); } static inline Matcher<Node*> IsWordXor(const Matcher<Node*>& lhs_matcher, const Matcher<Node*>& rhs_matcher) { - return kPointerSize == 8 ? IsWord64Xor(lhs_matcher, rhs_matcher) - : IsWord32Xor(lhs_matcher, rhs_matcher); + return kSystemPointerSize == 8 ? IsWord64Xor(lhs_matcher, rhs_matcher) + : IsWord32Xor(lhs_matcher, rhs_matcher); } static inline Matcher<Node*> IsChangeInt32ToIntPtr( const Matcher<Node*>& matcher) { - return kPointerSize == 8 ? IsChangeInt32ToInt64(matcher) : matcher; + return kSystemPointerSize == 8 ? IsChangeInt32ToInt64(matcher) : matcher; } static inline Matcher<Node*> IsChangeUint32ToWord( const Matcher<Node*>& matcher) { - return kPointerSize == 8 ? IsChangeUint32ToUint64(matcher) : matcher; + return kSystemPointerSize == 8 ? IsChangeUint32ToUint64(matcher) : matcher; } static inline Matcher<Node*> IsTruncateIntPtrToInt32( const Matcher<Node*>& matcher) { - return kPointerSize == 8 ? IsTruncateInt64ToInt32(matcher) : matcher; + return kSystemPointerSize == 8 ? IsTruncateInt64ToInt32(matcher) : matcher; } } // namespace compiler diff --git a/deps/v8/test/unittests/compiler/opcodes-unittest.cc b/deps/v8/test/unittests/compiler/opcodes-unittest.cc index a0e67ecb27..5036ade61e 100644 --- a/deps/v8/test/unittests/compiler/opcodes-unittest.cc +++ b/deps/v8/test/unittests/compiler/opcodes-unittest.cc @@ -78,9 +78,6 @@ bool IsComparisonOpcode(IrOpcode::Value opcode) { } } - -const IrOpcode::Value kInvalidOpcode = static_cast<IrOpcode::Value>(123456789); - char const* const kMnemonics[] = { #define OPCODE(Opcode) #Opcode, ALL_OP_LIST(OPCODE) @@ -96,42 +93,36 @@ const IrOpcode::Value kOpcodes[] = { } // namespace TEST(IrOpcodeTest, IsCommonOpcode) { - EXPECT_FALSE(IrOpcode::IsCommonOpcode(kInvalidOpcode)); TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) { EXPECT_EQ(IsCommonOpcode(opcode), IrOpcode::IsCommonOpcode(opcode)); } } TEST(IrOpcodeTest, IsControlOpcode) { - EXPECT_FALSE(IrOpcode::IsControlOpcode(kInvalidOpcode)); TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) { EXPECT_EQ(IsControlOpcode(opcode), IrOpcode::IsControlOpcode(opcode)); } } TEST(IrOpcodeTest, IsJsOpcode) { - EXPECT_FALSE(IrOpcode::IsJsOpcode(kInvalidOpcode)); TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) { EXPECT_EQ(IsJsOpcode(opcode), IrOpcode::IsJsOpcode(opcode)); } } TEST(IrOpcodeTest, IsConstantOpcode) { - EXPECT_FALSE(IrOpcode::IsConstantOpcode(kInvalidOpcode)); TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) { EXPECT_EQ(IsConstantOpcode(opcode), IrOpcode::IsConstantOpcode(opcode)); } } TEST(IrOpcodeTest, IsComparisonOpcode) { - EXPECT_FALSE(IrOpcode::IsComparisonOpcode(kInvalidOpcode)); TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) { EXPECT_EQ(IsComparisonOpcode(opcode), IrOpcode::IsComparisonOpcode(opcode)); } } TEST(IrOpcodeTest, Mnemonic) { - EXPECT_STREQ("UnknownOpcode", IrOpcode::Mnemonic(kInvalidOpcode)); TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) { EXPECT_STREQ(kMnemonics[opcode], IrOpcode::Mnemonic(opcode)); } diff --git a/deps/v8/test/unittests/compiler/redundancy-elimination-unittest.cc b/deps/v8/test/unittests/compiler/redundancy-elimination-unittest.cc index 079cc4b99a..a9cf3260a2 100644 --- a/deps/v8/test/unittests/compiler/redundancy-elimination-unittest.cc +++ b/deps/v8/test/unittests/compiler/redundancy-elimination-unittest.cc @@ -668,16 +668,18 @@ TEST_F(RedundancyEliminationTest, CheckedUint32Bounds) { Node* effect = graph()->start(); Node* control = graph()->start(); - Node* check1 = effect = - graph()->NewNode(simplified()->CheckedUint32Bounds(feedback1), index, - length, effect, control); + Node* check1 = effect = graph()->NewNode( + simplified()->CheckedUint32Bounds( + feedback1, CheckBoundsParameters::kDeoptOnOutOfBounds), + index, length, effect, control); Reduction r1 = Reduce(check1); ASSERT_TRUE(r1.Changed()); EXPECT_EQ(r1.replacement(), check1); - Node* check2 = effect = - graph()->NewNode(simplified()->CheckedUint32Bounds(feedback2), index, - length, effect, control); + Node* check2 = effect = graph()->NewNode( + simplified()->CheckedUint32Bounds( + feedback2, CheckBoundsParameters::kDeoptOnOutOfBounds), + index, length, effect, control); Reduction r2 = Reduce(check2); ASSERT_TRUE(r2.Changed()); EXPECT_EQ(r2.replacement(), check1); diff --git a/deps/v8/test/unittests/compiler/regalloc/register-allocator-unittest.cc b/deps/v8/test/unittests/compiler/regalloc/register-allocator-unittest.cc index d77f424ef7..02ce2bcdac 100644 --- a/deps/v8/test/unittests/compiler/regalloc/register-allocator-unittest.cc +++ b/deps/v8/test/unittests/compiler/regalloc/register-allocator-unittest.cc @@ -755,7 +755,7 @@ TEST_P(SlotConstraintTest, SlotConstraint) { Allocate(); } -INSTANTIATE_TEST_CASE_P( +INSTANTIATE_TEST_SUITE_P( RegisterAllocatorTest, SlotConstraintTest, ::testing::Combine(::testing::ValuesIn(kParameterTypes), ::testing::Range(0, SlotConstraintTest::kMaxVariant))); diff --git a/deps/v8/test/unittests/compiler/simplified-operator-unittest.cc b/deps/v8/test/unittests/compiler/simplified-operator-unittest.cc index 239f19ff93..280afef4c9 100644 --- a/deps/v8/test/unittests/compiler/simplified-operator-unittest.cc +++ b/deps/v8/test/unittests/compiler/simplified-operator-unittest.cc @@ -115,9 +115,8 @@ TEST_P(SimplifiedPureOperatorTest, Properties) { EXPECT_EQ(pop.properties, op->properties() & pop.properties); } -INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest, SimplifiedPureOperatorTest, - ::testing::ValuesIn(kPureOperators)); - +INSTANTIATE_TEST_SUITE_P(SimplifiedOperatorTest, SimplifiedPureOperatorTest, + ::testing::ValuesIn(kPureOperators)); // ----------------------------------------------------------------------------- @@ -213,10 +212,9 @@ TEST_P(SimplifiedElementAccessOperatorTest, StoreElement) { EXPECT_EQ(0, op->ControlOutputCount()); } - -INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest, - SimplifiedElementAccessOperatorTest, - ::testing::ValuesIn(kElementAccesses)); +INSTANTIATE_TEST_SUITE_P(SimplifiedOperatorTest, + SimplifiedElementAccessOperatorTest, + ::testing::ValuesIn(kElementAccesses)); } // namespace simplified_operator_unittest } // namespace compiler diff --git a/deps/v8/test/unittests/compiler/typed-optimization-unittest.cc b/deps/v8/test/unittests/compiler/typed-optimization-unittest.cc index da1f3941f0..c8aaafb6dc 100644 --- a/deps/v8/test/unittests/compiler/typed-optimization-unittest.cc +++ b/deps/v8/test/unittests/compiler/typed-optimization-unittest.cc @@ -27,7 +27,7 @@ namespace typed_optimization_unittest { class TypedOptimizationTest : public TypedGraphTest { public: TypedOptimizationTest() - : TypedGraphTest(3), simplified_(zone()), deps_(isolate(), zone()) {} + : TypedGraphTest(3), simplified_(zone()), deps_(broker(), zone()) {} ~TypedOptimizationTest() override = default; protected: diff --git a/deps/v8/test/unittests/compiler/typer-unittest.cc b/deps/v8/test/unittests/compiler/typer-unittest.cc index 5954dbc638..5d712bd220 100644 --- a/deps/v8/test/unittests/compiler/typer-unittest.cc +++ b/deps/v8/test/unittests/compiler/typer-unittest.cc @@ -10,7 +10,7 @@ #include "src/compiler/operator-properties.h" #include "src/compiler/simplified-operator.h" #include "src/objects-inl.h" -#include "test/cctest/types-fuzz.h" +#include "test/common/types-fuzz.h" #include "test/unittests/compiler/graph-unittest.h" namespace v8 { @@ -303,7 +303,9 @@ class TyperTest : public TypedGraphTest { namespace { -int32_t shift_left(int32_t x, int32_t y) { return x << (y & 0x1F); } +int32_t shift_left(int32_t x, int32_t y) { + return static_cast<uint32_t>(x) << (y & 0x1F); +} int32_t shift_right(int32_t x, int32_t y) { return x >> (y & 0x1F); } int32_t bit_or(int32_t x, int32_t y) { return x | y; } int32_t bit_and(int32_t x, int32_t y) { return x & y; } @@ -506,7 +508,7 @@ TEST_MONOTONICITY(ToBoolean) TestBinaryMonotonicity(simplified_.name(), Type::Number(), \ Type::Number()); \ } -SIMPLIFIED_NUMBER_BINOP_LIST(TEST_MONOTONICITY); +SIMPLIFIED_NUMBER_BINOP_LIST(TEST_MONOTONICITY) #undef TEST_MONOTONICITY // SIMPLIFIED BINOPs without hint, without input restriction diff --git a/deps/v8/test/unittests/compiler/x64/instruction-selector-x64-unittest.cc b/deps/v8/test/unittests/compiler/x64/instruction-selector-x64-unittest.cc index f174b92731..7ba4c5ae4b 100644 --- a/deps/v8/test/unittests/compiler/x64/instruction-selector-x64-unittest.cc +++ b/deps/v8/test/unittests/compiler/x64/instruction-selector-x64-unittest.cc @@ -103,9 +103,9 @@ TEST_P(InstructionSelectorChangeInt32ToInt64Test, ChangeInt32ToInt64WithLoad) { EXPECT_EQ(extension.expected_opcode, s[0]->arch_opcode()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorChangeInt32ToInt64Test, - ::testing::ValuesIn(kLoadWithToInt64Extensions)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorChangeInt32ToInt64Test, + ::testing::ValuesIn(kLoadWithToInt64Extensions)); // ----------------------------------------------------------------------------- // Loads and stores @@ -171,11 +171,9 @@ TEST_P(InstructionSelectorMemoryAccessTest, StoreWithParameters) { EXPECT_EQ(0U, s[0]->OutputCount()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorMemoryAccessTest, - ::testing::ValuesIn(kMemoryAccesses)); - +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorMemoryAccessTest, + ::testing::ValuesIn(kMemoryAccesses)); // ----------------------------------------------------------------------------- // ChangeUint32ToUint64. @@ -237,10 +235,9 @@ TEST_P(InstructionSelectorChangeUint32ToUint64Test, ChangeUint32ToUint64) { ASSERT_EQ(1U, s.size()); } - -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorChangeUint32ToUint64Test, - ::testing::ValuesIn(kWord32BinaryOperations)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorChangeUint32ToUint64Test, + ::testing::ValuesIn(kWord32BinaryOperations)); // ----------------------------------------------------------------------------- // CanElideChangeUint32ToUint64 @@ -320,9 +317,9 @@ TEST_P(InstructionSelectorElidedChangeUint32ToUint64Test, Parameter) { EXPECT_EQ(1U, s[0]->OutputCount()); } -INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, - InstructionSelectorElidedChangeUint32ToUint64Test, - ::testing::ValuesIn(kCanElideChangeUint32ToUint64)); +INSTANTIATE_TEST_SUITE_P(InstructionSelectorTest, + InstructionSelectorElidedChangeUint32ToUint64Test, + ::testing::ValuesIn(kCanElideChangeUint32ToUint64)); // ChangeUint32ToUint64AfterLoad TEST_F(InstructionSelectorTest, ChangeUint32ToUint64AfterLoad) { diff --git a/deps/v8/test/unittests/eh-frame-writer-unittest.cc b/deps/v8/test/unittests/eh-frame-writer-unittest.cc index 0846fda2f4..52501b462e 100644 --- a/deps/v8/test/unittests/eh-frame-writer-unittest.cc +++ b/deps/v8/test/unittests/eh-frame-writer-unittest.cc @@ -43,7 +43,7 @@ TEST_F(EhFrameWriterTest, Alignment) { ASSERT_EQ(0, EhFrameConstants::kEhFrameTerminatorSize % 4); EXPECT_EQ(0, (iterator.GetBufferSize() - EhFrameConstants::kEhFrameHdrSize - EhFrameConstants::kEhFrameTerminatorSize) % - kPointerSize); + kSystemPointerSize); } TEST_F(EhFrameWriterTest, FDEHeader) { diff --git a/deps/v8/test/unittests/heap/bitmap-test-utils.h b/deps/v8/test/unittests/heap/bitmap-test-utils.h new file mode 100644 index 0000000000..b709263968 --- /dev/null +++ b/deps/v8/test/unittests/heap/bitmap-test-utils.h @@ -0,0 +1,35 @@ +// Copyright 2019 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_UNITTESTS_HEAP_BITMAP_TEST_UTILS_H_ +#define V8_UNITTESTS_HEAP_BITMAP_TEST_UTILS_H_ + +#include "testing/gtest/include/gtest/gtest.h" + +namespace v8 { +namespace internal { + +template <typename T> +class TestWithBitmap : public ::testing::Test { + public: + TestWithBitmap() : memory_(new uint8_t[Bitmap::kSize]) { + memset(memory_, 0, Bitmap::kSize); + } + + ~TestWithBitmap() override { delete[] memory_; } + + T* bitmap() { return reinterpret_cast<T*>(memory_); } + uint8_t* raw_bitmap() { return memory_; } + + private: + uint8_t* memory_; +}; + +using BitmapTypes = ::testing::Types<ConcurrentBitmap<AccessMode::NON_ATOMIC>, + ConcurrentBitmap<AccessMode::ATOMIC>>; + +} // namespace internal +} // namespace v8 + +#endif // V8_UNITTESTS_HEAP_BITMAP_TEST_UTILS_H_ diff --git a/deps/v8/test/unittests/heap/bitmap-unittest.cc b/deps/v8/test/unittests/heap/bitmap-unittest.cc index 1ecab4dd72..393f5ea303 100644 --- a/deps/v8/test/unittests/heap/bitmap-unittest.cc +++ b/deps/v8/test/unittests/heap/bitmap-unittest.cc @@ -3,40 +3,26 @@ // found in the LICENSE file. #include "src/heap/spaces.h" +#include "test/unittests/heap/bitmap-test-utils.h" #include "testing/gtest/include/gtest/gtest.h" -namespace { +namespace v8 { +namespace internal { -using v8::internal::Bitmap; +const uint32_t kBlackCell = 0xAAAAAAAA; +const uint32_t kWhiteCell = 0x00000000; +const uint32_t kBlackByte = 0xAA; +const uint32_t kWhiteByte = 0x00; -class BitmapTest : public ::testing::Test { - public: - static const uint32_t kBlackCell; - static const uint32_t kWhiteCell; - static const uint32_t kBlackByte; - static const uint32_t kWhiteByte; +template <typename T> +using BitmapTest = TestWithBitmap<T>; - BitmapTest() : memory_(new uint8_t[Bitmap::kSize]) { - memset(memory_, 0, Bitmap::kSize); - } - - ~BitmapTest() override { delete[] memory_; } - - Bitmap* bitmap() { return reinterpret_cast<Bitmap*>(memory_); } - uint8_t* raw_bitmap() { return memory_; } - - private: - uint8_t* memory_; -}; +TYPED_TEST_SUITE(BitmapTest, BitmapTypes); +using NonAtomicBitmapTest = + TestWithBitmap<ConcurrentBitmap<AccessMode::NON_ATOMIC>>; -const uint32_t BitmapTest::kBlackCell = 0xAAAAAAAA; -const uint32_t BitmapTest::kWhiteCell = 0x00000000; -const uint32_t BitmapTest::kBlackByte = 0xAA; -const uint32_t BitmapTest::kWhiteByte = 0x00; - - -TEST_F(BitmapTest, IsZeroInitialized) { +TEST_F(NonAtomicBitmapTest, IsZeroInitialized) { // We require all tests to start from a zero-initialized bitmap. Manually // verify this invariant here. for (size_t i = 0; i < Bitmap::kSize; i++) { @@ -44,9 +30,8 @@ TEST_F(BitmapTest, IsZeroInitialized) { } } - -TEST_F(BitmapTest, Cells) { - Bitmap* bm = bitmap(); +TEST_F(NonAtomicBitmapTest, Cells) { + auto bm = bitmap(); bm->cells()[1] = kBlackCell; uint8_t* raw = raw_bitmap(); int second_cell_base = Bitmap::kBytesPerCell; @@ -55,8 +40,7 @@ TEST_F(BitmapTest, Cells) { } } - -TEST_F(BitmapTest, CellsCount) { +TEST_F(NonAtomicBitmapTest, CellsCount) { int last_cell_index = bitmap()->CellsCount() - 1; bitmap()->cells()[last_cell_index] = kBlackCell; // Manually verify on raw memory. @@ -71,17 +55,34 @@ TEST_F(BitmapTest, CellsCount) { } } - -TEST_F(BitmapTest, IsClean) { - Bitmap* bm = bitmap(); +TEST_F(NonAtomicBitmapTest, IsClean) { + auto bm = bitmap(); EXPECT_TRUE(bm->IsClean()); bm->cells()[0] = kBlackCell; EXPECT_FALSE(bm->IsClean()); } +TYPED_TEST(BitmapTest, Clear) { + auto bm = this->bitmap(); + for (size_t i = 0; i < Bitmap::kSize; i++) { + this->raw_bitmap()[i] = 0xFFu; + } + bm->Clear(); + for (size_t i = 0; i < Bitmap::kSize; i++) { + EXPECT_EQ(this->raw_bitmap()[i], 0); + } +} + +TYPED_TEST(BitmapTest, MarkAllBits) { + auto bm = this->bitmap(); + bm->MarkAllBits(); + for (size_t i = 0; i < Bitmap::kSize; i++) { + EXPECT_EQ(this->raw_bitmap()[i], 0xFF); + } +} -TEST_F(BitmapTest, ClearRange1) { - Bitmap* bm = bitmap(); +TYPED_TEST(BitmapTest, ClearRange1) { + auto bm = this->bitmap(); bm->cells()[0] = kBlackCell; bm->cells()[1] = kBlackCell; bm->cells()[2] = kBlackCell; @@ -91,9 +92,8 @@ TEST_F(BitmapTest, ClearRange1) { EXPECT_EQ(bm->cells()[2], kBlackCell); } - -TEST_F(BitmapTest, ClearRange2) { - Bitmap* bm = bitmap(); +TYPED_TEST(BitmapTest, ClearRange2) { + auto bm = this->bitmap(); bm->cells()[0] = kBlackCell; bm->cells()[1] = kBlackCell; bm->cells()[2] = kBlackCell; @@ -104,4 +104,59 @@ TEST_F(BitmapTest, ClearRange2) { EXPECT_EQ(bm->cells()[2], kBlackCell); } -} // namespace +TYPED_TEST(BitmapTest, SetAndClearRange) { + auto bm = this->bitmap(); + for (int i = 0; i < 3; i++) { + bm->SetRange(i, Bitmap::kBitsPerCell + i); + CHECK_EQ(bm->cells()[0], 0xFFFFFFFFu << i); + CHECK_EQ(bm->cells()[1], (1u << i) - 1); + bm->ClearRange(i, Bitmap::kBitsPerCell + i); + CHECK_EQ(bm->cells()[0], 0x0u); + CHECK_EQ(bm->cells()[1], 0x0u); + } +} + +// AllBitsSetInRange() and AllBitsClearInRange() are only used when verifying +// the heap on the main thread so they don't have atomic implementations. +TEST_F(NonAtomicBitmapTest, ClearMultipleRanges) { + auto bm = this->bitmap(); + + bm->SetRange(0, Bitmap::kBitsPerCell * 3); + CHECK(bm->AllBitsSetInRange(0, Bitmap::kBitsPerCell)); + + bm->ClearRange(Bitmap::kBitsPerCell / 2, Bitmap::kBitsPerCell); + bm->ClearRange(Bitmap::kBitsPerCell, + Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2); + bm->ClearRange(Bitmap::kBitsPerCell * 2 + 8, Bitmap::kBitsPerCell * 2 + 16); + bm->ClearRange(Bitmap::kBitsPerCell * 2 + 24, Bitmap::kBitsPerCell * 3); + + CHECK_EQ(bm->cells()[0], 0xFFFFu); + CHECK(bm->AllBitsSetInRange(0, Bitmap::kBitsPerCell / 2)); + CHECK( + bm->AllBitsClearInRange(Bitmap::kBitsPerCell / 2, Bitmap::kBitsPerCell)); + + CHECK_EQ(bm->cells()[1], 0xFFFF0000u); + CHECK(bm->AllBitsClearInRange( + Bitmap::kBitsPerCell, Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2)); + CHECK(bm->AllBitsSetInRange(Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2, + Bitmap::kBitsPerCell * 2)); + + CHECK_EQ(bm->cells()[2], 0xFF00FFu); + CHECK(bm->AllBitsSetInRange( + Bitmap::kBitsPerCell * 2, + Bitmap::kBitsPerCell * 2 + Bitmap::kBitsPerCell / 4)); + CHECK(bm->AllBitsClearInRange( + Bitmap::kBitsPerCell * 2 + Bitmap::kBitsPerCell / 4, + Bitmap::kBitsPerCell * 2 + Bitmap::kBitsPerCell / 2)); + CHECK(bm->AllBitsSetInRange( + Bitmap::kBitsPerCell * 2 + Bitmap::kBitsPerCell / 2, + Bitmap::kBitsPerCell * 2 + Bitmap::kBitsPerCell / 2 + + Bitmap::kBitsPerCell / 4)); + CHECK(bm->AllBitsClearInRange(Bitmap::kBitsPerCell * 2 + + Bitmap::kBitsPerCell / 2 + + Bitmap::kBitsPerCell / 4, + Bitmap::kBitsPerCell * 3)); +} + +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/heap/gc-idle-time-handler-unittest.cc b/deps/v8/test/unittests/heap/gc-idle-time-handler-unittest.cc index 7063b2a280..b3901d74b0 100644 --- a/deps/v8/test/unittests/heap/gc-idle-time-handler-unittest.cc +++ b/deps/v8/test/unittests/heap/gc-idle-time-handler-unittest.cc @@ -31,7 +31,6 @@ class GCIdleTimeHandlerTest : public ::testing::Test { static const size_t kSizeOfObjects = 100 * MB; static const size_t kMarkCompactSpeed = 200 * KB; static const size_t kMarkingSpeed = 200 * KB; - static const int kMaxNotifications = 100; private: GCIdleTimeHandler handler_; @@ -95,8 +94,8 @@ TEST_F(GCIdleTimeHandlerTest, ContextDisposeLowRate) { heap_state.contexts_disposed = 1; heap_state.incremental_marking_stopped = true; double idle_time_ms = 0; - GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); - EXPECT_EQ(DO_NOTHING, action.type); + EXPECT_EQ(GCIdleTimeAction::kDone, + handler()->Compute(idle_time_ms, heap_state)); } @@ -108,8 +107,8 @@ TEST_F(GCIdleTimeHandlerTest, ContextDisposeHighRate) { GCIdleTimeHandler::kHighContextDisposalRate - 1; heap_state.incremental_marking_stopped = true; double idle_time_ms = 0; - GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); - EXPECT_EQ(DO_FULL_GC, action.type); + EXPECT_EQ(GCIdleTimeAction::kFullGC, + handler()->Compute(idle_time_ms, heap_state)); } @@ -120,8 +119,8 @@ TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeZeroIdleTime) { heap_state.contexts_disposal_rate = 1.0; heap_state.incremental_marking_stopped = true; double idle_time_ms = 0; - GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); - EXPECT_EQ(DO_FULL_GC, action.type); + EXPECT_EQ(GCIdleTimeAction::kFullGC, + handler()->Compute(idle_time_ms, heap_state)); } @@ -133,8 +132,8 @@ TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) { GCIdleTimeHandler::kHighContextDisposalRate; size_t speed = kMarkCompactSpeed; double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); - GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); - EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); + EXPECT_EQ(GCIdleTimeAction::kIncrementalStep, + handler()->Compute(idle_time_ms, heap_state)); } @@ -146,8 +145,8 @@ TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) { GCIdleTimeHandler::kHighContextDisposalRate; size_t speed = kMarkCompactSpeed; double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); - GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); - EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); + EXPECT_EQ(GCIdleTimeAction::kIncrementalStep, + handler()->Compute(idle_time_ms, heap_state)); } TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeHeap) { @@ -158,16 +157,16 @@ TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeHeap) { heap_state.incremental_marking_stopped = true; heap_state.size_of_objects = 101 * MB; double idle_time_ms = 0; - GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); - EXPECT_EQ(DO_NOTHING, action.type); + EXPECT_EQ(GCIdleTimeAction::kDone, + handler()->Compute(idle_time_ms, heap_state)); } TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) { if (!handler()->Enabled()) return; GCIdleTimeHeapState heap_state = DefaultHeapState(); double idle_time_ms = 10; - GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); - EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); + EXPECT_EQ(GCIdleTimeAction::kIncrementalStep, + handler()->Compute(idle_time_ms, heap_state)); } @@ -177,8 +176,8 @@ TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) { heap_state.incremental_marking_stopped = true; size_t speed = kMarkCompactSpeed; double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); - GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); - EXPECT_EQ(DONE, action.type); + EXPECT_EQ(GCIdleTimeAction::kDone, + handler()->Compute(idle_time_ms, heap_state)); } @@ -187,8 +186,8 @@ TEST_F(GCIdleTimeHandlerTest, DoNotStartIncrementalMarking) { GCIdleTimeHeapState heap_state = DefaultHeapState(); heap_state.incremental_marking_stopped = true; double idle_time_ms = 10.0; - GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); - EXPECT_EQ(DONE, action.type); + EXPECT_EQ(GCIdleTimeAction::kDone, + handler()->Compute(idle_time_ms, heap_state)); } @@ -197,32 +196,11 @@ TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop) { GCIdleTimeHeapState heap_state = DefaultHeapState(); heap_state.incremental_marking_stopped = true; double idle_time_ms = 10.0; - GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); - EXPECT_EQ(DONE, action.type); + EXPECT_EQ(GCIdleTimeAction::kDone, + handler()->Compute(idle_time_ms, heap_state)); heap_state.incremental_marking_stopped = false; - action = handler()->Compute(idle_time_ms, heap_state); - EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); -} - - -TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeNothingToDo) { - if (!handler()->Enabled()) return; - GCIdleTimeHeapState heap_state = DefaultHeapState(); - for (int i = 0; i < kMaxNotifications; i++) { - GCIdleTimeAction action = handler()->Compute(0, heap_state); - EXPECT_EQ(DO_NOTHING, action.type); - } -} - - -TEST_F(GCIdleTimeHandlerTest, SmallIdleTimeNothingToDo) { - if (!handler()->Enabled()) return; - GCIdleTimeHeapState heap_state = DefaultHeapState(); - heap_state.incremental_marking_stopped = true; - for (int i = 0; i < kMaxNotifications; i++) { - GCIdleTimeAction action = handler()->Compute(10, heap_state); - EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type); - } + EXPECT_EQ(GCIdleTimeAction::kIncrementalStep, + handler()->Compute(idle_time_ms, heap_state)); } @@ -235,9 +213,9 @@ TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnIncrementalMarking) { // Simulate incremental marking stopped and not eligible to start. heap_state.incremental_marking_stopped = true; double idle_time_ms = 10.0; - // We should return DONE if we cannot start incremental marking. - GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); - EXPECT_EQ(DONE, action.type); + // We should return kDone if we cannot start incremental marking. + EXPECT_EQ(GCIdleTimeAction::kDone, + handler()->Compute(idle_time_ms, heap_state)); } } // namespace internal diff --git a/deps/v8/test/unittests/heap/heap-unittest.cc b/deps/v8/test/unittests/heap/heap-unittest.cc index 53954d8178..12bd46886d 100644 --- a/deps/v8/test/unittests/heap/heap-unittest.cc +++ b/deps/v8/test/unittests/heap/heap-unittest.cc @@ -6,13 +6,10 @@ #include <iostream> #include <limits> -#include "src/objects.h" -#include "src/objects-inl.h" - -#include "src/handles.h" #include "src/handles-inl.h" - #include "src/heap/heap.h" +#include "src/heap/spaces-inl.h" +#include "src/objects-inl.h" #include "test/unittests/test-utils.h" #include "testing/gtest/include/gtest/gtest.h" @@ -23,14 +20,13 @@ typedef TestWithIsolate HeapTest; typedef TestWithIsolateAndPointerCompression HeapWithPointerCompressionTest; TEST(Heap, SemiSpaceSize) { - const size_t KB = static_cast<size_t>(i::KB); const size_t MB = static_cast<size_t>(i::MB); const size_t pm = i::Heap::kPointerMultiplier; - ASSERT_EQ(1u * pm * MB / 2, i::Heap::ComputeMaxSemiSpaceSize(0u) * KB); - ASSERT_EQ(1u * pm * MB / 2, i::Heap::ComputeMaxSemiSpaceSize(512u * MB) * KB); - ASSERT_EQ(2u * pm * MB, i::Heap::ComputeMaxSemiSpaceSize(1024u * MB) * KB); - ASSERT_EQ(5u * pm * MB, i::Heap::ComputeMaxSemiSpaceSize(2024u * MB) * KB); - ASSERT_EQ(8u * pm * MB, i::Heap::ComputeMaxSemiSpaceSize(4095u * MB) * KB); + ASSERT_EQ(512u * pm, i::Heap::ComputeMaxSemiSpaceSize(0u)); + ASSERT_EQ(512u * pm, i::Heap::ComputeMaxSemiSpaceSize(512u * MB)); + ASSERT_EQ(2048u * pm, i::Heap::ComputeMaxSemiSpaceSize(1024u * MB)); + ASSERT_EQ(5120u * pm, i::Heap::ComputeMaxSemiSpaceSize(2024u * MB)); + ASSERT_EQ(8192u * pm, i::Heap::ComputeMaxSemiSpaceSize(4095u * MB)); } TEST_F(HeapTest, ASLR) { diff --git a/deps/v8/test/unittests/heap/item-parallel-job-unittest.cc b/deps/v8/test/unittests/heap/item-parallel-job-unittest.cc index 36d99a31ba..e42f22c4e1 100644 --- a/deps/v8/test/unittests/heap/item-parallel-job-unittest.cc +++ b/deps/v8/test/unittests/heap/item-parallel-job-unittest.cc @@ -202,7 +202,7 @@ TEST_F(ItemParallelJobTest, SimpleTaskWithNoItemsRuns) { parallel_job_semaphore()); job.AddTask(new SimpleTask(i_isolate(), &did_run)); - job.Run(i_isolate()->async_counters()); + job.Run(); EXPECT_TRUE(did_run); } @@ -214,7 +214,7 @@ TEST_F(ItemParallelJobTest, SimpleTaskWithSimpleItemRuns) { job.AddItem(new ItemParallelJob::Item); - job.Run(i_isolate()->async_counters()); + job.Run(); EXPECT_TRUE(did_run); } @@ -244,7 +244,7 @@ TEST_F(ItemParallelJobTest, MoreTasksThanItems) { job.AddItem(new SimpleItem); } - job.Run(i_isolate()->async_counters()); + job.Run(); for (int i = 0; i < kNumTasks; i++) { // Only the first kNumItems tasks should have been assigned a work item. @@ -261,7 +261,7 @@ TEST_F(ItemParallelJobTest, SingleThreadProcessing) { for (int i = 0; i < kItems; i++) { job.AddItem(new SimpleItem(&was_processed[i])); } - job.Run(i_isolate()->async_counters()); + job.Run(); for (int i = 0; i < kItems; i++) { EXPECT_TRUE(was_processed[i]); } @@ -282,7 +282,7 @@ TEST_F(ItemParallelJobTest, DistributeItemsMultipleTasks) { job.AddTask( new TaskProcessingOneItem(i_isolate(), &barrier, wait_when_done)); } - job.Run(i_isolate()->async_counters()); + job.Run(); for (int i = 0; i < kItemsAndTasks; i++) { EXPECT_TRUE(was_processed[i]); } @@ -296,7 +296,7 @@ TEST_F(ItemParallelJobTest, DifferentItems) { job.AddItem(new ItemA()); job.AddItem(new ItemB()); job.AddTask(new TaskForDifferentItems(i_isolate(), &item_a, &item_b)); - job.Run(i_isolate()->async_counters()); + job.Run(); EXPECT_TRUE(item_a); EXPECT_TRUE(item_b); } diff --git a/deps/v8/test/unittests/heap/marking-unittest.cc b/deps/v8/test/unittests/heap/marking-unittest.cc index be26d4eebd..60aa28c4a9 100644 --- a/deps/v8/test/unittests/heap/marking-unittest.cc +++ b/deps/v8/test/unittests/heap/marking-unittest.cc @@ -6,15 +6,19 @@ #include "src/globals.h" #include "src/heap/marking.h" +#include "test/unittests/heap/bitmap-test-utils.h" #include "testing/gtest/include/gtest/gtest.h" namespace v8 { namespace internal { +template <typename T> +using MarkingTest = TestWithBitmap<T>; -TEST(Marking, TransitionWhiteBlackWhite) { - Bitmap* bitmap = reinterpret_cast<Bitmap*>( - calloc(Bitmap::kSize / kTaggedSize, kTaggedSize)); +TYPED_TEST_SUITE(MarkingTest, BitmapTypes); + +TYPED_TEST(MarkingTest, TransitionWhiteBlackWhite) { + auto bitmap = this->bitmap(); const int kLocationsSize = 3; int position[kLocationsSize] = { Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell}; @@ -29,12 +33,10 @@ TEST(Marking, TransitionWhiteBlackWhite) { CHECK(Marking::IsWhite(mark_bit)); CHECK(!Marking::IsImpossible(mark_bit)); } - free(bitmap); } -TEST(Marking, TransitionWhiteGreyBlack) { - Bitmap* bitmap = reinterpret_cast<Bitmap*>( - calloc(Bitmap::kSize / kTaggedSize, kTaggedSize)); +TYPED_TEST(MarkingTest, TransitionWhiteGreyBlack) { + auto bitmap = this->bitmap(); const int kLocationsSize = 3; int position[kLocationsSize] = { Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell}; @@ -55,54 +57,7 @@ TEST(Marking, TransitionWhiteGreyBlack) { CHECK(Marking::IsWhite(mark_bit)); CHECK(!Marking::IsImpossible(mark_bit)); } - free(bitmap); } -TEST(Marking, SetAndClearRange) { - Bitmap* bitmap = reinterpret_cast<Bitmap*>( - calloc(Bitmap::kSize / kTaggedSize, kTaggedSize)); - for (int i = 0; i < 3; i++) { - bitmap->SetRange(i, Bitmap::kBitsPerCell + i); - CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[0], 0xFFFFFFFFu << i); - CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[1], (1u << i) - 1); - bitmap->ClearRange(i, Bitmap::kBitsPerCell + i); - CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[0], 0x0u); - CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[1], 0x0u); - } - free(bitmap); -} - -TEST(Marking, ClearMultipleRanges) { - Bitmap* bitmap = reinterpret_cast<Bitmap*>( - calloc(Bitmap::kSize / kTaggedSize, kTaggedSize)); - CHECK(bitmap->AllBitsClearInRange(0, Bitmap::kBitsPerCell * 3)); - bitmap->SetRange(0, Bitmap::kBitsPerCell * 3); - CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[0], 0xFFFFFFFFu); - CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[1], 0xFFFFFFFFu); - CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[2], 0xFFFFFFFFu); - CHECK(bitmap->AllBitsSetInRange(0, Bitmap::kBitsPerCell * 3)); - bitmap->ClearRange(Bitmap::kBitsPerCell / 2, Bitmap::kBitsPerCell); - bitmap->ClearRange(Bitmap::kBitsPerCell, - Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2); - bitmap->ClearRange(Bitmap::kBitsPerCell * 2 + 8, - Bitmap::kBitsPerCell * 2 + 16); - bitmap->ClearRange(Bitmap::kBitsPerCell * 2 + 24, Bitmap::kBitsPerCell * 3); - CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[0], 0xFFFFu); - CHECK(bitmap->AllBitsSetInRange(0, Bitmap::kBitsPerCell / 2)); - CHECK(bitmap->AllBitsClearInRange(Bitmap::kBitsPerCell / 2, - Bitmap::kBitsPerCell)); - CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[1], 0xFFFF0000u); - CHECK( - bitmap->AllBitsSetInRange(Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2, - 2 * Bitmap::kBitsPerCell)); - CHECK(bitmap->AllBitsClearInRange( - Bitmap::kBitsPerCell, Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2)); - CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[2], 0xFF00FFu); - CHECK(bitmap->AllBitsSetInRange(2 * Bitmap::kBitsPerCell, - 2 * Bitmap::kBitsPerCell + 8)); - CHECK(bitmap->AllBitsClearInRange(2 * Bitmap::kBitsPerCell + 24, - Bitmap::kBitsPerCell * 3)); - free(bitmap); -} } // namespace internal } // namespace v8 diff --git a/deps/v8/test/unittests/heap/spaces-unittest.cc b/deps/v8/test/unittests/heap/spaces-unittest.cc index de4bd39e1e..ecfa4b964f 100644 --- a/deps/v8/test/unittests/heap/spaces-unittest.cc +++ b/deps/v8/test/unittests/heap/spaces-unittest.cc @@ -84,38 +84,38 @@ TEST_F(SpacesTest, WriteBarrierIsMarking) { EXPECT_FALSE(slim_chunk->IsMarking()); } -TEST_F(SpacesTest, WriteBarrierInNewSpaceToSpace) { +TEST_F(SpacesTest, WriteBarrierInYoungGenerationToSpace) { const size_t kSizeOfMemoryChunk = sizeof(MemoryChunk); char memory[kSizeOfMemoryChunk]; memset(&memory, 0, kSizeOfMemoryChunk); MemoryChunk* chunk = reinterpret_cast<MemoryChunk*>(&memory); heap_internals::MemoryChunk* slim_chunk = reinterpret_cast<heap_internals::MemoryChunk*>(&memory); - EXPECT_FALSE(chunk->InNewSpace()); - EXPECT_FALSE(slim_chunk->InNewSpace()); - chunk->SetFlag(MemoryChunk::IN_TO_SPACE); - EXPECT_TRUE(chunk->InNewSpace()); - EXPECT_TRUE(slim_chunk->InNewSpace()); - chunk->ClearFlag(MemoryChunk::IN_TO_SPACE); - EXPECT_FALSE(chunk->InNewSpace()); - EXPECT_FALSE(slim_chunk->InNewSpace()); + EXPECT_FALSE(chunk->InYoungGeneration()); + EXPECT_FALSE(slim_chunk->InYoungGeneration()); + chunk->SetFlag(MemoryChunk::TO_PAGE); + EXPECT_TRUE(chunk->InYoungGeneration()); + EXPECT_TRUE(slim_chunk->InYoungGeneration()); + chunk->ClearFlag(MemoryChunk::TO_PAGE); + EXPECT_FALSE(chunk->InYoungGeneration()); + EXPECT_FALSE(slim_chunk->InYoungGeneration()); } -TEST_F(SpacesTest, WriteBarrierInNewSpaceFromSpace) { +TEST_F(SpacesTest, WriteBarrierInYoungGenerationFromSpace) { const size_t kSizeOfMemoryChunk = sizeof(MemoryChunk); char memory[kSizeOfMemoryChunk]; memset(&memory, 0, kSizeOfMemoryChunk); MemoryChunk* chunk = reinterpret_cast<MemoryChunk*>(&memory); heap_internals::MemoryChunk* slim_chunk = reinterpret_cast<heap_internals::MemoryChunk*>(&memory); - EXPECT_FALSE(chunk->InNewSpace()); - EXPECT_FALSE(slim_chunk->InNewSpace()); - chunk->SetFlag(MemoryChunk::IN_FROM_SPACE); - EXPECT_TRUE(chunk->InNewSpace()); - EXPECT_TRUE(slim_chunk->InNewSpace()); - chunk->ClearFlag(MemoryChunk::IN_FROM_SPACE); - EXPECT_FALSE(chunk->InNewSpace()); - EXPECT_FALSE(slim_chunk->InNewSpace()); + EXPECT_FALSE(chunk->InYoungGeneration()); + EXPECT_FALSE(slim_chunk->InYoungGeneration()); + chunk->SetFlag(MemoryChunk::FROM_PAGE); + EXPECT_TRUE(chunk->InYoungGeneration()); + EXPECT_TRUE(slim_chunk->InYoungGeneration()); + chunk->ClearFlag(MemoryChunk::FROM_PAGE); + EXPECT_FALSE(chunk->InYoungGeneration()); + EXPECT_FALSE(slim_chunk->InYoungGeneration()); } TEST_F(SpacesTest, CodeRangeAddressReuse) { diff --git a/deps/v8/test/unittests/interpreter/bytecode-array-builder-unittest.cc b/deps/v8/test/unittests/interpreter/bytecode-array-builder-unittest.cc index ed53b8b0d2..21051c6da5 100644 --- a/deps/v8/test/unittests/interpreter/bytecode-array-builder-unittest.cc +++ b/deps/v8/test/unittests/interpreter/bytecode-array-builder-unittest.cc @@ -7,6 +7,7 @@ #include "src/v8.h" #include "src/ast/scopes.h" +#include "src/hash-seed-inl.h" #include "src/interpreter/bytecode-array-builder.h" #include "src/interpreter/bytecode-array-iterator.h" #include "src/interpreter/bytecode-jump-table.h" @@ -34,7 +35,7 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { BytecodeArrayBuilder builder(zone(), 1, 131, &feedback_spec); Factory* factory = isolate()->factory(); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); DeclarationScope scope(zone(), &ast_factory); CHECK_EQ(builder.locals_count(), 131); @@ -260,7 +261,7 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { .CompareOperation(Token::Value::GTE, reg, 6) .CompareTypeOf(TestTypeOfFlags::LiteralFlag::kNumber) .CompareOperation(Token::Value::INSTANCEOF, reg, 7) - .CompareOperation(Token::Value::IN, reg) + .CompareOperation(Token::Value::IN, reg, 8) .CompareReference(reg) .CompareUndetectable() .CompareUndefined() @@ -279,10 +280,12 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { // Short jumps with Imm8 operands { - BytecodeLabel start, after_jump1, after_jump2, after_jump3, after_jump4, + BytecodeLoopHeader loop_header; + BytecodeLabel after_jump1, after_jump2, after_jump3, after_jump4, after_jump5, after_jump6, after_jump7, after_jump8, after_jump9, - after_jump10; - builder.Bind(&start) + after_jump10, after_loop; + builder.JumpIfNull(&after_loop) + .Bind(&loop_header) .Jump(&after_jump1) .Bind(&after_jump1) .JumpIfNull(&after_jump2) @@ -303,14 +306,16 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { .Bind(&after_jump9) .JumpIfFalse(ToBooleanMode::kAlreadyBoolean, &after_jump10) .Bind(&after_jump10) - .JumpLoop(&start, 0); + .JumpLoop(&loop_header, 0) + .Bind(&after_loop); } - // Longer jumps with constant operands BytecodeLabel end[10]; { + // Longer jumps with constant operands BytecodeLabel after_jump; - builder.Jump(&end[0]) + builder.JumpIfNull(&after_jump) + .Jump(&end[0]) .Bind(&after_jump) .JumpIfTrue(ToBooleanMode::kConvertToBoolean, &end[1]) .JumpIfTrue(ToBooleanMode::kAlreadyBoolean, &end[2]) @@ -336,10 +341,9 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { // Emit throw and re-throw in it's own basic block so that the rest of the // code isn't omitted due to being dead. - BytecodeLabel after_throw; - builder.Throw().Bind(&after_throw); - BytecodeLabel after_rethrow; - builder.ReThrow().Bind(&after_rethrow); + BytecodeLabel after_throw, after_rethrow; + builder.JumpIfNull(&after_throw).Throw().Bind(&after_throw); + builder.JumpIfNull(&after_rethrow).ReThrow().Bind(&after_rethrow); builder.ForInEnumerate(reg) .ForInPrepare(triple, 1) @@ -413,10 +417,10 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { builder.Debugger(); // Emit abort bytecode. - { - BytecodeLabel after; - builder.Abort(AbortReason::kOperandIsASmi).Bind(&after); - } + BytecodeLabel after_abort; + builder.JumpIfNull(&after_abort) + .Abort(AbortReason::kOperandIsASmi) + .Bind(&after_abort); // Insert dummy ops to force longer jumps. for (int i = 0; i < 256; i++) { @@ -439,7 +443,7 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { ast_factory.Internalize(isolate()); Handle<BytecodeArray> the_array = builder.ToBytecodeArray(isolate()); CHECK_EQ(the_array->frame_size(), - builder.total_register_count() * kPointerSize); + builder.total_register_count() * kSystemPointerSize); // Build scorecard of bytecodes encountered in the BytecodeArray. std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1); @@ -504,7 +508,7 @@ TEST_F(BytecodeArrayBuilderTest, FrameSizesLookGood) { Handle<BytecodeArray> the_array = builder.ToBytecodeArray(isolate()); int total_registers = locals + temps; - CHECK_EQ(the_array->frame_size(), total_registers * kPointerSize); + CHECK_EQ(the_array->frame_size(), total_registers * kSystemPointerSize); } } } @@ -534,7 +538,7 @@ TEST_F(BytecodeArrayBuilderTest, Parameters) { TEST_F(BytecodeArrayBuilderTest, Constants) { BytecodeArrayBuilder builder(zone(), 1, 0); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); double heap_num_1 = 3.14; double heap_num_2 = 5.2; @@ -567,10 +571,11 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { Register reg(0); BytecodeLabel far0, far1, far2, far3, far4; BytecodeLabel near0, near1, near2, near3, near4; - BytecodeLabel after_jump0, after_jump1; + BytecodeLabel after_jump_near0, after_jump_far0; - builder.Jump(&near0) - .Bind(&after_jump0) + builder.JumpIfNull(&after_jump_near0) + .Jump(&near0) + .Bind(&after_jump_near0) .CompareOperation(Token::Value::EQ, reg, 1) .JumpIfTrue(ToBooleanMode::kAlreadyBoolean, &near1) .CompareOperation(Token::Value::EQ, reg, 2) @@ -584,8 +589,9 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { .Bind(&near2) .Bind(&near3) .Bind(&near4) + .JumpIfNull(&after_jump_far0) .Jump(&far0) - .Bind(&after_jump1) + .Bind(&after_jump_far0) .CompareOperation(Token::Value::EQ, reg, 3) .JumpIfTrue(ToBooleanMode::kAlreadyBoolean, &far1) .CompareOperation(Token::Value::EQ, reg, 4) @@ -601,9 +607,13 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { builder.Return(); Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate()); - DCHECK_EQ(array->length(), 44 + kFarJumpDistance - 22 + 1); + DCHECK_EQ(array->length(), 48 + kFarJumpDistance - 22 + 1); BytecodeArrayIterator iterator(array); + + // Ignore JumpIfNull operation. + iterator.Advance(); + CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); CHECK_EQ(iterator.GetUnsignedImmediateOperand(0), 22); iterator.Advance(); @@ -636,6 +646,9 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { CHECK_EQ(iterator.GetUnsignedImmediateOperand(0), 2); iterator.Advance(); + // Ignore JumpIfNull operation. + iterator.Advance(); + CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpConstant); CHECK_EQ(iterator.GetConstantForIndexOperand(0), Smi::FromInt(kFarJumpDistance)); @@ -681,11 +694,22 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) { Register reg(0); - BytecodeLabel label0; - builder.Bind(&label0).JumpLoop(&label0, 0); + BytecodeLabel end; + builder.JumpIfNull(&end); + + BytecodeLabel after_loop; + // Conditional jump to force the code after the JumpLoop to be live. + // Technically this jump is illegal because it's jumping into the middle of + // the subsequent loops, but that's ok for this unit test. + BytecodeLoopHeader loop_header; + builder.JumpIfNull(&after_loop) + .Bind(&loop_header) + .JumpLoop(&loop_header, 0) + .Bind(&after_loop); for (int i = 0; i < 42; i++) { - BytecodeLabel after_jump; - builder.JumpLoop(&label0, 0).Bind(&after_jump); + BytecodeLabel after_loop; + // Conditional jump to force the code after the JumpLoop to be live. + builder.JumpIfNull(&after_loop).JumpLoop(&loop_header, 0).Bind(&after_loop); } // Add padding to force wide backwards jumps. @@ -693,21 +717,28 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) { builder.Debugger(); } - builder.JumpLoop(&label0, 0); - BytecodeLabel end; + builder.JumpLoop(&loop_header, 0); builder.Bind(&end); builder.Return(); Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate()); BytecodeArrayIterator iterator(array); + // Ignore the JumpIfNull to the end + iterator.Advance(); + // Ignore the JumpIfNull to after the first JumpLoop + iterator.Advance(); CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); CHECK_EQ(iterator.GetUnsignedImmediateOperand(0), 0); iterator.Advance(); for (unsigned i = 0; i < 42; i++) { + // Ignore the JumpIfNull to after the JumpLoop + iterator.Advance(); + CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); - // offset of 3 (because kJumpLoop takes two immediate operands) - CHECK_EQ(iterator.GetUnsignedImmediateOperand(0), i * 3 + 3); + // offset of 5 (because kJumpLoop takes two immediate operands and + // JumpIfNull takes 1) + CHECK_EQ(iterator.GetUnsignedImmediateOperand(0), i * 5 + 5); iterator.Advance(); } // Check padding to force wide backwards jumps. @@ -717,7 +748,7 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) { } CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); - CHECK_EQ(iterator.GetUnsignedImmediateOperand(0), 386); + CHECK_EQ(iterator.GetUnsignedImmediateOperand(0), 42 * 5 + 256 + 4); iterator.Advance(); CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); iterator.Advance(); @@ -820,71 +851,6 @@ TEST_F(BytecodeArrayBuilderTest, WideSwitch) { CHECK(iterator.done()); } -TEST_F(BytecodeArrayBuilderTest, LabelReuse) { - BytecodeArrayBuilder builder(zone(), 1, 0); - - // Labels can only have 1 forward reference, but - // can be referred to mulitple times once bound. - BytecodeLabel label, after_jump0, after_jump1; - - builder.Jump(&label) - .Bind(&label) - .JumpLoop(&label, 0) - .Bind(&after_jump0) - .JumpLoop(&label, 0) - .Bind(&after_jump1) - .Return(); - - Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate()); - BytecodeArrayIterator iterator(array); - CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); - CHECK_EQ(iterator.GetUnsignedImmediateOperand(0), 2); - iterator.Advance(); - CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); - CHECK_EQ(iterator.GetUnsignedImmediateOperand(0), 0); - iterator.Advance(); - CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); - CHECK_EQ(iterator.GetUnsignedImmediateOperand(0), 3); - iterator.Advance(); - CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); - iterator.Advance(); - CHECK(iterator.done()); -} - - -TEST_F(BytecodeArrayBuilderTest, LabelAddressReuse) { - static const int kRepeats = 3; - - BytecodeArrayBuilder builder(zone(), 1, 0); - for (int i = 0; i < kRepeats; i++) { - BytecodeLabel label, after_jump0, after_jump1; - builder.Jump(&label) - .Bind(&label) - .JumpLoop(&label, 0) - .Bind(&after_jump0) - .JumpLoop(&label, 0) - .Bind(&after_jump1); - } - builder.Return(); - - Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate()); - BytecodeArrayIterator iterator(array); - for (int i = 0; i < kRepeats; i++) { - CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); - CHECK_EQ(iterator.GetUnsignedImmediateOperand(0), 2); - iterator.Advance(); - CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); - CHECK_EQ(iterator.GetUnsignedImmediateOperand(0), 0); - iterator.Advance(); - CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpLoop); - CHECK_EQ(iterator.GetUnsignedImmediateOperand(0), 3); - iterator.Advance(); - } - CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); - iterator.Advance(); - CHECK(iterator.done()); -} - } // namespace interpreter } // namespace internal } // namespace v8 diff --git a/deps/v8/test/unittests/interpreter/bytecode-array-iterator-unittest.cc b/deps/v8/test/unittests/interpreter/bytecode-array-iterator-unittest.cc index ec70605dde..0e72e2ec8d 100644 --- a/deps/v8/test/unittests/interpreter/bytecode-array-iterator-unittest.cc +++ b/deps/v8/test/unittests/interpreter/bytecode-array-iterator-unittest.cc @@ -4,6 +4,7 @@ #include "src/v8.h" +#include "src/hash-seed-inl.h" #include "src/interpreter/bytecode-array-builder.h" #include "src/interpreter/bytecode-array-iterator.h" #include "src/objects-inl.h" @@ -27,7 +28,7 @@ TEST_F(BytecodeArrayIteratorTest, IteratesBytecodeArray) { FeedbackVectorSpec feedback_spec(zone()); BytecodeArrayBuilder builder(zone(), 3, 3, &feedback_spec); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); double heap_num_0 = 2.718; double heap_num_1 = 2.0 * Smi::kMaxValue; Smi zero = Smi::zero(); diff --git a/deps/v8/test/unittests/interpreter/bytecode-array-random-iterator-unittest.cc b/deps/v8/test/unittests/interpreter/bytecode-array-random-iterator-unittest.cc index 2e2d92628f..6ec19fb726 100644 --- a/deps/v8/test/unittests/interpreter/bytecode-array-random-iterator-unittest.cc +++ b/deps/v8/test/unittests/interpreter/bytecode-array-random-iterator-unittest.cc @@ -4,6 +4,7 @@ #include "src/v8.h" +#include "src/hash-seed-inl.h" #include "src/interpreter/bytecode-array-builder.h" #include "src/interpreter/bytecode-array-random-iterator.h" #include "src/objects-inl.h" @@ -27,7 +28,7 @@ TEST_F(BytecodeArrayRandomIteratorTest, InvalidBeforeStart) { FeedbackVectorSpec feedback_spec(zone()); BytecodeArrayBuilder builder(zone(), 3, 3, &feedback_spec); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); double heap_num_0 = 2.718; double heap_num_1 = 2.0 * Smi::kMaxValue; Smi zero = Smi::zero(); @@ -81,7 +82,7 @@ TEST_F(BytecodeArrayRandomIteratorTest, InvalidAfterEnd) { FeedbackVectorSpec feedback_spec(zone()); BytecodeArrayBuilder builder(zone(), 3, 3, &feedback_spec); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); double heap_num_0 = 2.718; double heap_num_1 = 2.0 * Smi::kMaxValue; Smi zero = Smi::zero(); @@ -135,7 +136,7 @@ TEST_F(BytecodeArrayRandomIteratorTest, AccessesFirst) { FeedbackVectorSpec feedback_spec(zone()); BytecodeArrayBuilder builder(zone(), 3, 3, &feedback_spec); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); double heap_num_0 = 2.718; double heap_num_1 = 2.0 * Smi::kMaxValue; Smi zero = Smi::zero(); @@ -193,7 +194,7 @@ TEST_F(BytecodeArrayRandomIteratorTest, AccessesLast) { FeedbackVectorSpec feedback_spec(zone()); BytecodeArrayBuilder builder(zone(), 3, 3, &feedback_spec); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); double heap_num_0 = 2.718; double heap_num_1 = 2.0 * Smi::kMaxValue; Smi zero = Smi::zero(); @@ -252,7 +253,7 @@ TEST_F(BytecodeArrayRandomIteratorTest, RandomAccessValid) { FeedbackVectorSpec feedback_spec(zone()); BytecodeArrayBuilder builder(zone(), 3, 3, &feedback_spec); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); double heap_num_0 = 2.718; double heap_num_1 = 2.0 * Smi::kMaxValue; Smi zero = Smi::zero(); @@ -437,7 +438,7 @@ TEST_F(BytecodeArrayRandomIteratorTest, IteratesBytecodeArray) { FeedbackVectorSpec feedback_spec(zone()); BytecodeArrayBuilder builder(zone(), 3, 3, &feedback_spec); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); double heap_num_0 = 2.718; double heap_num_1 = 2.0 * Smi::kMaxValue; Smi zero = Smi::zero(); @@ -716,7 +717,7 @@ TEST_F(BytecodeArrayRandomIteratorTest, IteratesBytecodeArrayBackwards) { FeedbackVectorSpec feedback_spec(zone()); BytecodeArrayBuilder builder(zone(), 3, 3, &feedback_spec); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); double heap_num_0 = 2.718; double heap_num_1 = 2.0 * Smi::kMaxValue; Smi zero = Smi::zero(); diff --git a/deps/v8/test/unittests/interpreter/bytecode-array-writer-unittest.cc b/deps/v8/test/unittests/interpreter/bytecode-array-writer-unittest.cc index 7c01228936..35cc3b3c28 100644 --- a/deps/v8/test/unittests/interpreter/bytecode-array-writer-unittest.cc +++ b/deps/v8/test/unittests/interpreter/bytecode-array-writer-unittest.cc @@ -49,8 +49,8 @@ class BytecodeArrayWriterUnittest : public TestWithIsolateAndZone { void WriteJump(Bytecode bytecode, BytecodeLabel* label, BytecodeSourceInfo info = BytecodeSourceInfo()); - void WriteJumpLoop(Bytecode bytecode, BytecodeLabel* label, int depth, - BytecodeSourceInfo info = BytecodeSourceInfo()); + void WriteJumpLoop(Bytecode bytecode, BytecodeLoopHeader* loop_header, + int depth, BytecodeSourceInfo info = BytecodeSourceInfo()); BytecodeArrayWriter* writer() { return &bytecode_array_writer_; } ZoneVector<unsigned char>* bytecodes() { return writer()->bytecodes(); } @@ -105,10 +105,11 @@ void BytecodeArrayWriterUnittest::WriteJump(Bytecode bytecode, } void BytecodeArrayWriterUnittest::WriteJumpLoop(Bytecode bytecode, - BytecodeLabel* label, int depth, + BytecodeLoopHeader* loop_header, + int depth, BytecodeSourceInfo info) { BytecodeNode node(bytecode, 0, depth, info); - writer()->WriteJump(&node, label); + writer()->WriteJumpLoop(&node, loop_header); } TEST_F(BytecodeArrayWriterUnittest, SimpleExample) { @@ -195,7 +196,8 @@ TEST_F(BytecodeArrayWriterUnittest, ComplexExample) { {0, 30, false}, {1, 42, true}, {3, 42, false}, {6, 68, true}, {18, 63, true}, {32, 54, false}, {37, 85, true}, {46, 85, true}}; - BytecodeLabel back_jump, jump_for_in, jump_end_1, jump_end_2, jump_end_3; + BytecodeLoopHeader loop_header; + BytecodeLabel jump_for_in, jump_end_1, jump_end_2, jump_end_3; Write(Bytecode::kStackCheck, {30, false}); Write(Bytecode::kLdaConstant, U8(0), {42, true}); @@ -206,7 +208,7 @@ TEST_F(BytecodeArrayWriterUnittest, ComplexExample) { Write(Bytecode::kForInPrepare, R(3), U8(4)); Write(Bytecode::kLdaZero); Write(Bytecode::kStar, R(7)); - writer()->BindLabel(&back_jump); + writer()->BindLoopHeader(&loop_header); Write(Bytecode::kForInContinue, R(7), R(6), {63, true}); WriteJump(Bytecode::kJumpIfFalse, &jump_end_3); Write(Bytecode::kForInNext, R(3), R(7), R(4), U8(1)); @@ -219,7 +221,7 @@ TEST_F(BytecodeArrayWriterUnittest, ComplexExample) { writer()->BindLabel(&jump_for_in); Write(Bytecode::kForInStep, R(7)); Write(Bytecode::kStar, R(7)); - WriteJumpLoop(Bytecode::kJumpLoop, &back_jump, 0); + WriteJumpLoop(Bytecode::kJumpLoop, &loop_header, 0); writer()->BindLabel(&jump_end_1); writer()->BindLabel(&jump_end_2); writer()->BindLabel(&jump_end_3); @@ -328,7 +330,9 @@ TEST_F(BytecodeArrayWriterUnittest, DeadcodeElimination) { Write(Bytecode::kLdaSmi, 127); // Dead code. WriteJump(Bytecode::kJumpIfFalse, &after_conditional_jump); // Dead code. writer()->BindLabel(&after_jump); - writer()->BindLabel(&after_conditional_jump); + // We would bind the after_conditional_jump label here, but the jump to it is + // dead. + CHECK(!after_conditional_jump.has_referrer_jump()); Write(Bytecode::kLdaSmi, 127, {65, true}); WriteJump(Bytecode::kJumpIfFalse, &after_return); Write(Bytecode::kReturn, {75, true}); diff --git a/deps/v8/test/unittests/interpreter/bytecode-utils.h b/deps/v8/test/unittests/interpreter/bytecode-utils.h index 401884559e..912e9dcb7b 100644 --- a/deps/v8/test/unittests/interpreter/bytecode-utils.h +++ b/deps/v8/test/unittests/interpreter/bytecode-utils.h @@ -33,7 +33,7 @@ namespace interpreter { #define U8(i) static_cast<uint8_t>(i) #define REG_OPERAND(i) \ - (InterpreterFrameConstants::kRegisterFileFromFp / kPointerSize - (i)) + (InterpreterFrameConstants::kRegisterFileFromFp / kSystemPointerSize - (i)) #define R8(i) static_cast<uint8_t>(REG_OPERAND(i)) #define R16(i) U16(REG_OPERAND(i)) #define R32(i) U32(REG_OPERAND(i)) diff --git a/deps/v8/test/unittests/interpreter/bytecodes-unittest.cc b/deps/v8/test/unittests/interpreter/bytecodes-unittest.cc index 16b4e80489..6f5a11c0c7 100644 --- a/deps/v8/test/unittests/interpreter/bytecodes-unittest.cc +++ b/deps/v8/test/unittests/interpreter/bytecodes-unittest.cc @@ -89,7 +89,7 @@ TEST(OperandScaling, ScalableAndNonScalable) { 1 + 2 + 2 * scale); CHECK_EQ(Bytecodes::Size(Bytecode::kCreateObjectLiteral, operand_scale), 1 + 2 * scale + 1); - CHECK_EQ(Bytecodes::Size(Bytecode::kTestIn, operand_scale), 1 + scale); + CHECK_EQ(Bytecodes::Size(Bytecode::kTestIn, operand_scale), 1 + 2 * scale); } } diff --git a/deps/v8/test/unittests/interpreter/constant-array-builder-unittest.cc b/deps/v8/test/unittests/interpreter/constant-array-builder-unittest.cc index 55f1cacf56..894aee16a4 100644 --- a/deps/v8/test/unittests/interpreter/constant-array-builder-unittest.cc +++ b/deps/v8/test/unittests/interpreter/constant-array-builder-unittest.cc @@ -6,6 +6,7 @@ #include "src/ast/ast-value-factory.h" #include "src/handles-inl.h" +#include "src/hash-seed-inl.h" #include "src/heap/factory.h" #include "src/interpreter/constant-array-builder.h" #include "src/isolate.h" @@ -34,7 +35,7 @@ TEST_F(ConstantArrayBuilderTest, AllocateAllEntries) { CanonicalHandleScope canonical(isolate()); ConstantArrayBuilder builder(zone()); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); for (size_t i = 0; i < k16BitCapacity; i++) { builder.Insert(i + 0.5); } @@ -84,7 +85,7 @@ TEST_F(ConstantArrayBuilderTest, ToLargeFixedArrayWithReservations) { CanonicalHandleScope canonical(isolate()); ConstantArrayBuilder builder(zone()); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); static const int kNumberOfElements = 37373; for (int i = 0; i < kNumberOfElements; i++) { builder.CommitReservedEntry(builder.CreateReservedEntry(), Smi::FromInt(i)); @@ -104,7 +105,7 @@ TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) { for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) { ConstantArrayBuilder builder(zone()); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); for (size_t i = 0; i < reserved; i++) { OperandSize operand_size = builder.CreateReservedEntry(); CHECK_EQ(operand_size, OperandSize::kByte); @@ -172,7 +173,7 @@ TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithWideReservations) { for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) { ConstantArrayBuilder builder(zone()); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); for (size_t i = 0; i < k8BitCapacity; i++) { builder.CommitReservedEntry(builder.CreateReservedEntry(), Smi::FromInt(static_cast<int>(i))); @@ -217,7 +218,7 @@ TEST_F(ConstantArrayBuilderTest, GapFilledWhenLowReservationCommitted) { CanonicalHandleScope canonical(isolate()); ConstantArrayBuilder builder(zone()); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); for (size_t i = 0; i < k8BitCapacity; i++) { OperandSize operand_size = builder.CreateReservedEntry(); CHECK_EQ(OperandSize::kByte, operand_size); @@ -283,7 +284,7 @@ TEST_F(ConstantArrayBuilderTest, HolesWithUnusedReservations) { static int k8BitCapacity = ConstantArrayBuilder::k8BitCapacity; ConstantArrayBuilder builder(zone()); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); for (int i = 0; i < kNumberOfHoles; ++i) { CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte); } @@ -316,7 +317,7 @@ TEST_F(ConstantArrayBuilderTest, ReservationsAtAllScales) { CanonicalHandleScope canonical(isolate()); ConstantArrayBuilder builder(zone()); AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(), - isolate()->heap()->HashSeed()); + HashSeed(isolate())); for (int i = 0; i < 256; i++) { CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte); } diff --git a/deps/v8/test/unittests/interpreter/interpreter-assembler-unittest.cc b/deps/v8/test/unittests/interpreter/interpreter-assembler-unittest.cc index d5f84952c3..bf240e41a4 100644 --- a/deps/v8/test/unittests/interpreter/interpreter-assembler-unittest.cc +++ b/deps/v8/test/unittests/interpreter/interpreter-assembler-unittest.cc @@ -72,8 +72,9 @@ Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsStore( Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsWordNot( const Matcher<Node*>& value_matcher) { - return kPointerSize == 8 ? IsWord64Xor(value_matcher, c::IsInt64Constant(-1)) - : IsWord32Xor(value_matcher, c::IsInt32Constant(-1)); + return kSystemPointerSize == 8 + ? IsWord64Xor(value_matcher, c::IsInt64Constant(-1)) + : IsWord32Xor(value_matcher, c::IsInt32Constant(-1)); } Matcher<Node*> @@ -291,10 +292,10 @@ InterpreterAssemblerTest::InterpreterAssemblerForTest::IsLoadRegisterOperand( int offset, OperandSize operand_size) { Matcher<compiler::Node*> reg_operand = IsChangeInt32ToIntPtr( IsSignedOperand(offset, operand_size, LoadSensitivity::kSafe)); - return IsLoad( - MachineType::AnyTagged(), c::IsLoadParentFramePointer(), - c::IsWordShl(reg_operand, c::IsIntPtrConstant(kPointerSizeLog2)), - LoadSensitivity::kCritical); + return IsBitcastWordToTagged(IsLoad( + MachineType::Pointer(), c::IsLoadParentFramePointer(), + c::IsWordShl(reg_operand, c::IsIntPtrConstant(kSystemPointerSizeLog2)), + LoadSensitivity::kCritical)); } TARGET_TEST_F(InterpreterAssemblerTest, Jump) { @@ -321,7 +322,7 @@ TARGET_TEST_F(InterpreterAssemblerTest, Jump) { MachineType::Pointer(), c::IsParameter(InterpreterDispatchDescriptor::kDispatchTable), c::IsWordShl(target_bytecode_matcher, - c::IsIntPtrConstant(kPointerSizeLog2))); + c::IsIntPtrConstant(kSystemPointerSizeLog2))); EXPECT_THAT( tail_call_node, @@ -418,9 +419,10 @@ TARGET_TEST_F(InterpreterAssemblerTest, GetContext) { InterpreterAssemblerForTest m(&state, bytecode); EXPECT_THAT( m.GetContext(), - m.IsLoad(MachineType::AnyTagged(), c::IsLoadParentFramePointer(), - c::IsIntPtrConstant(Register::current_context().ToOperand() - << kPointerSizeLog2))); + IsBitcastWordToTagged(m.IsLoad( + MachineType::Pointer(), c::IsLoadParentFramePointer(), + c::IsIntPtrConstant(Register::current_context().ToOperand() * + kSystemPointerSize)))); } } @@ -457,7 +459,7 @@ TARGET_TEST_F(InterpreterAssemblerTest, LoadConstantPoolEntry) { MachineType::AnyTagged(), constant_pool_matcher, c::IsIntPtrAdd( c::IsIntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag), - c::IsWordShl(index, c::IsIntPtrConstant(kPointerSizeLog2))), + c::IsWordShl(index, c::IsIntPtrConstant(kTaggedSizeLog2))), LoadSensitivity::kCritical)); } } @@ -533,10 +535,10 @@ TARGET_TEST_F(InterpreterAssemblerTest, LoadFeedbackVector) { InterpreterAssemblerForTest m(&state, bytecode); Node* feedback_vector = m.LoadFeedbackVector(); - Matcher<Node*> load_function_matcher = - m.IsLoad(MachineType::AnyTagged(), c::IsLoadParentFramePointer(), - c::IsIntPtrConstant(Register::function_closure().ToOperand() - << kPointerSizeLog2)); + Matcher<Node*> load_function_matcher = IsBitcastWordToTagged( + m.IsLoad(MachineType::Pointer(), c::IsLoadParentFramePointer(), + c::IsIntPtrConstant(Register::function_closure().ToOperand() * + kSystemPointerSize))); Matcher<Node*> load_vector_cell_matcher = m.IsLoad( MachineType::AnyTagged(), load_function_matcher, c::IsIntPtrConstant(JSFunction::kFeedbackCellOffset - kHeapObjectTag)); diff --git a/deps/v8/test/unittests/microtask-queue-unittest.cc b/deps/v8/test/unittests/microtask-queue-unittest.cc index cc2c7f0de7..f39a1558c6 100644 --- a/deps/v8/test/unittests/microtask-queue-unittest.cc +++ b/deps/v8/test/unittests/microtask-queue-unittest.cc @@ -10,7 +10,11 @@ #include <vector> #include "src/heap/factory.h" +#include "src/objects-inl.h" #include "src/objects/foreign.h" +#include "src/objects/js-array-inl.h" +#include "src/objects/js-objects-inl.h" +#include "src/objects/promise-inl.h" #include "src/visitors.h" #include "test/unittests/test-utils.h" #include "testing/gtest/include/gtest/gtest.h" @@ -25,7 +29,29 @@ void RunStdFunction(void* data) { (*f)(); } -class MicrotaskQueueTest : public TestWithNativeContext { +template <typename TMixin> +class WithFinalizationGroupMixin : public TMixin { + public: + WithFinalizationGroupMixin() { + FLAG_harmony_weak_refs = true; + FLAG_expose_gc = true; + } + + private: + SaveFlags save_flags_; + + DISALLOW_COPY_AND_ASSIGN(WithFinalizationGroupMixin); +}; + +using TestWithNativeContextAndFinalizationGroup = // + WithInternalIsolateMixin< // + WithContextMixin< // + WithFinalizationGroupMixin< // + WithIsolateScopeMixin< // + WithSharedIsolateMixin< // + ::testing::Test>>>>>; + +class MicrotaskQueueTest : public TestWithNativeContextAndFinalizationGroup { public: template <typename F> Handle<Microtask> NewMicrotask(F&& f) { @@ -55,6 +81,11 @@ class MicrotaskQueueTest : public TestWithNativeContext { microtask_queue_ = nullptr; } + template <size_t N> + Handle<Name> NameFromChars(const char (&chars)[N]) { + return isolate()->factory()->NewStringFromStaticChars(chars); + } + private: std::unique_ptr<MicrotaskQueue> microtask_queue_; }; @@ -88,7 +119,7 @@ TEST_F(MicrotaskQueueTest, EnqueueAndRun) { })); EXPECT_EQ(MicrotaskQueue::kMinimumCapacity, microtask_queue()->capacity()); EXPECT_EQ(1, microtask_queue()->size()); - microtask_queue()->RunMicrotasks(isolate()); + EXPECT_EQ(1, microtask_queue()->RunMicrotasks(isolate())); EXPECT_TRUE(ran); EXPECT_EQ(0, microtask_queue()->size()); } @@ -100,7 +131,7 @@ TEST_F(MicrotaskQueueTest, BufferGrowth) { // Enqueue and flush the queue first to have non-zero |start_|. microtask_queue()->EnqueueMicrotask( *NewMicrotask([&count] { EXPECT_EQ(0, count++); })); - microtask_queue()->RunMicrotasks(isolate()); + EXPECT_EQ(1, microtask_queue()->RunMicrotasks(isolate())); EXPECT_LT(0, microtask_queue()->capacity()); EXPECT_EQ(0, microtask_queue()->size()); @@ -122,7 +153,8 @@ TEST_F(MicrotaskQueueTest, BufferGrowth) { EXPECT_EQ(MicrotaskQueue::kMinimumCapacity + 1, microtask_queue()->size()); // Run all pending Microtasks to ensure they run in the proper order. - microtask_queue()->RunMicrotasks(isolate()); + EXPECT_EQ(MicrotaskQueue::kMinimumCapacity + 1, + microtask_queue()->RunMicrotasks(isolate())); EXPECT_EQ(MicrotaskQueue::kMinimumCapacity + 2, count); } @@ -163,7 +195,8 @@ TEST_F(MicrotaskQueueTest, VisitRoot) { for (int i = 0; i < MicrotaskQueue::kMinimumCapacity / 2 + 1; ++i) { microtask_queue()->EnqueueMicrotask(*NewMicrotask([] {})); } - microtask_queue()->RunMicrotasks(isolate()); + EXPECT_EQ(MicrotaskQueue::kMinimumCapacity / 2 + 1, + microtask_queue()->RunMicrotasks(isolate())); std::vector<Object> expected; for (int i = 0; i < MicrotaskQueue::kMinimumCapacity / 2 + 1; ++i) { @@ -183,5 +216,287 @@ TEST_F(MicrotaskQueueTest, VisitRoot) { EXPECT_EQ(expected, actual); } +TEST_F(MicrotaskQueueTest, PromiseHandlerContext) { + Local<v8::Context> v8_context2 = v8::Context::New(v8_isolate()); + Local<v8::Context> v8_context3 = v8::Context::New(v8_isolate()); + Local<v8::Context> v8_context4 = v8::Context::New(v8_isolate()); + Handle<Context> context2 = Utils::OpenHandle(*v8_context2, isolate()); + Handle<Context> context3 = Utils::OpenHandle(*v8_context3, isolate()); + Handle<Context> context4 = Utils::OpenHandle(*v8_context3, isolate()); + context2->native_context()->set_microtask_queue(microtask_queue()); + context3->native_context()->set_microtask_queue(microtask_queue()); + context4->native_context()->set_microtask_queue(microtask_queue()); + + Handle<JSFunction> handler; + Handle<JSProxy> proxy; + Handle<JSProxy> revoked_proxy; + Handle<JSBoundFunction> bound; + + // Create a JSFunction on |context2| + { + v8::Context::Scope scope(v8_context2); + handler = RunJS<JSFunction>("()=>{}"); + EXPECT_EQ(*context2, + *JSReceiver::GetContextForMicrotask(handler).ToHandleChecked()); + } + + // Create a JSProxy on |context3|. + { + v8::Context::Scope scope(v8_context3); + ASSERT_TRUE( + v8_context3->Global() + ->Set(v8_context3, NewString("handler"), Utils::ToLocal(handler)) + .FromJust()); + proxy = RunJS<JSProxy>("new Proxy(handler, {})"); + revoked_proxy = RunJS<JSProxy>( + "let {proxy, revoke} = Proxy.revocable(handler, {});" + "revoke();" + "proxy"); + EXPECT_EQ(*context2, + *JSReceiver::GetContextForMicrotask(proxy).ToHandleChecked()); + EXPECT_TRUE(JSReceiver::GetContextForMicrotask(revoked_proxy).is_null()); + } + + // Create a JSBoundFunction on |context4|. + // Note that its CreationContext and ContextForTaskCancellation is |context2|. + { + v8::Context::Scope scope(v8_context4); + ASSERT_TRUE( + v8_context4->Global() + ->Set(v8_context4, NewString("handler"), Utils::ToLocal(handler)) + .FromJust()); + bound = RunJS<JSBoundFunction>("handler.bind()"); + EXPECT_EQ(*context2, + *JSReceiver::GetContextForMicrotask(bound).ToHandleChecked()); + } + + // Give the objects to the main context. + SetGlobalProperty("handler", Utils::ToLocal(handler)); + SetGlobalProperty("proxy", Utils::ToLocal(proxy)); + SetGlobalProperty("revoked_proxy", Utils::ToLocal(revoked_proxy)); + SetGlobalProperty("bound", Utils::ToLocal(Handle<JSReceiver>::cast(bound))); + RunJS( + "Promise.resolve().then(handler);" + "Promise.reject().catch(proxy);" + "Promise.resolve().then(revoked_proxy);" + "Promise.resolve().then(bound);"); + + ASSERT_EQ(4, microtask_queue()->size()); + Handle<Microtask> microtask1(microtask_queue()->get(0), isolate()); + ASSERT_TRUE(microtask1->IsPromiseFulfillReactionJobTask()); + EXPECT_EQ(*context2, + Handle<PromiseFulfillReactionJobTask>::cast(microtask1)->context()); + + Handle<Microtask> microtask2(microtask_queue()->get(1), isolate()); + ASSERT_TRUE(microtask2->IsPromiseRejectReactionJobTask()); + EXPECT_EQ(*context2, + Handle<PromiseRejectReactionJobTask>::cast(microtask2)->context()); + + Handle<Microtask> microtask3(microtask_queue()->get(2), isolate()); + ASSERT_TRUE(microtask3->IsPromiseFulfillReactionJobTask()); + // |microtask3| corresponds to a PromiseReaction for |revoked_proxy|. + // As |revoked_proxy| doesn't have a context, the current context should be + // used as the fallback context. + EXPECT_EQ(*native_context(), + Handle<PromiseFulfillReactionJobTask>::cast(microtask3)->context()); + + Handle<Microtask> microtask4(microtask_queue()->get(3), isolate()); + ASSERT_TRUE(microtask4->IsPromiseFulfillReactionJobTask()); + EXPECT_EQ(*context2, + Handle<PromiseFulfillReactionJobTask>::cast(microtask4)->context()); + + v8_context4->DetachGlobal(); + v8_context3->DetachGlobal(); + v8_context2->DetachGlobal(); +} + +TEST_F(MicrotaskQueueTest, DetachGlobal_Enqueue) { + EXPECT_EQ(0, microtask_queue()->size()); + + // Detach MicrotaskQueue from the current context. + context()->DetachGlobal(); + + // No microtask should be enqueued after DetachGlobal call. + EXPECT_EQ(0, microtask_queue()->size()); + RunJS("Promise.resolve().then(()=>{})"); + EXPECT_EQ(0, microtask_queue()->size()); +} + +TEST_F(MicrotaskQueueTest, DetachGlobal_Run) { + EXPECT_EQ(0, microtask_queue()->size()); + + // Enqueue microtasks to the current context. + Handle<JSArray> ran = RunJS<JSArray>( + "var ran = [false, false, false, false];" + "Promise.resolve().then(() => { ran[0] = true; });" + "Promise.reject().catch(() => { ran[1] = true; });" + "ran"); + + Handle<JSFunction> function = + RunJS<JSFunction>("(function() { ran[2] = true; })"); + Handle<CallableTask> callable = + factory()->NewCallableTask(function, Utils::OpenHandle(*context())); + microtask_queue()->EnqueueMicrotask(*callable); + + // The handler should not run at this point. + const int kNumExpectedTasks = 3; + for (int i = 0; i < kNumExpectedTasks; ++i) { + EXPECT_TRUE( + Object::GetElement(isolate(), ran, i).ToHandleChecked()->IsFalse()); + } + EXPECT_EQ(kNumExpectedTasks, microtask_queue()->size()); + + // Detach MicrotaskQueue from the current context. + context()->DetachGlobal(); + + // RunMicrotasks processes pending Microtasks, but Microtasks that are + // associated to a detached context should be cancelled and should not take + // effect. + microtask_queue()->RunMicrotasks(isolate()); + EXPECT_EQ(0, microtask_queue()->size()); + for (int i = 0; i < kNumExpectedTasks; ++i) { + EXPECT_TRUE( + Object::GetElement(isolate(), ran, i).ToHandleChecked()->IsFalse()); + } +} + +TEST_F(MicrotaskQueueTest, DetachGlobal_FinalizationGroup) { + // Enqueue an FinalizationGroupCleanupTask. + Handle<JSArray> ran = RunJS<JSArray>( + "var ran = [false];" + "var wf = new FinalizationGroup(() => { ran[0] = true; });" + "(function() { wf.register({}, {}); })();" + "gc();" + "ran"); + + EXPECT_TRUE( + Object::GetElement(isolate(), ran, 0).ToHandleChecked()->IsFalse()); + EXPECT_EQ(1, microtask_queue()->size()); + + // Detach MicrotaskQueue from the current context. + context()->DetachGlobal(); + + microtask_queue()->RunMicrotasks(isolate()); + + // RunMicrotasks processes the pending Microtask, but Microtasks that are + // associated to a detached context should be cancelled and should not take + // effect. + EXPECT_EQ(0, microtask_queue()->size()); + EXPECT_TRUE( + Object::GetElement(isolate(), ran, 0).ToHandleChecked()->IsFalse()); +} + +namespace { + +void DummyPromiseHook(PromiseHookType type, Local<Promise> promise, + Local<Value> parent) {} + +} // namespace + +TEST_F(MicrotaskQueueTest, DetachGlobal_PromiseResolveThenableJobTask) { + // Use a PromiseHook to switch the implementation to ResolvePromise runtime, + // instead of ResolvePromise builtin. + v8_isolate()->SetPromiseHook(&DummyPromiseHook); + + RunJS( + "var resolve;" + "var promise = new Promise(r => { resolve = r; });" + "promise.then(() => {});" + "resolve({});"); + + // A PromiseResolveThenableJobTask is pending in the MicrotaskQueue. + EXPECT_EQ(1, microtask_queue()->size()); + + // Detach MicrotaskQueue from the current context. + context()->DetachGlobal(); + + // RunMicrotasks processes the pending Microtask, but Microtasks that are + // associated to a detached context should be cancelled and should not take + // effect. + // As PromiseResolveThenableJobTask queues another task for resolution, + // the return value is 2 if it ran. + EXPECT_EQ(1, microtask_queue()->RunMicrotasks(isolate())); + EXPECT_EQ(0, microtask_queue()->size()); +} + +TEST_F(MicrotaskQueueTest, DetachGlobal_HandlerContext) { + // EnqueueMicrotask should use the context associated to the handler instead + // of the current context. E.g. + // // At Context A. + // let resolved = Promise.resolve(); + // // Call DetachGlobal on A, so that microtasks associated to A is + // // cancelled. + // + // // At Context B. + // let handler = () => { + // console.log("here"); + // }; + // // The microtask to run |handler| should be associated to B instead of A, + // // so that handler runs even |resolved| is on the detached context A. + // resolved.then(handler); + + Handle<JSReceiver> results = isolate()->factory()->NewJSObjectWithNullProto(); + + // These belong to a stale Context. + Handle<JSPromise> stale_resolved_promise; + Handle<JSPromise> stale_rejected_promise; + Handle<JSReceiver> stale_handler; + + Local<v8::Context> sub_context = v8::Context::New(v8_isolate()); + { + v8::Context::Scope scope(sub_context); + stale_resolved_promise = RunJS<JSPromise>("Promise.resolve()"); + stale_rejected_promise = RunJS<JSPromise>("Promise.reject()"); + stale_handler = RunJS<JSReceiver>( + "(results, label) => {" + " results[label] = true;" + "}"); + } + // DetachGlobal() cancells all microtasks associated to the context. + sub_context->DetachGlobal(); + sub_context.Clear(); + + SetGlobalProperty("results", Utils::ToLocal(results)); + SetGlobalProperty( + "stale_resolved_promise", + Utils::ToLocal(Handle<JSReceiver>::cast(stale_resolved_promise))); + SetGlobalProperty( + "stale_rejected_promise", + Utils::ToLocal(Handle<JSReceiver>::cast(stale_rejected_promise))); + SetGlobalProperty("stale_handler", Utils::ToLocal(stale_handler)); + + // Set valid handlers to stale promises. + RunJS( + "stale_resolved_promise.then(() => {" + " results['stale_resolved_promise'] = true;" + "})"); + RunJS( + "stale_rejected_promise.catch(() => {" + " results['stale_rejected_promise'] = true;" + "})"); + microtask_queue()->RunMicrotasks(isolate()); + EXPECT_TRUE( + JSReceiver::HasProperty(results, NameFromChars("stale_resolved_promise")) + .FromJust()); + EXPECT_TRUE( + JSReceiver::HasProperty(results, NameFromChars("stale_rejected_promise")) + .FromJust()); + + // Set stale handlers to valid promises. + RunJS( + "Promise.resolve(" + " stale_handler.bind(null, results, 'stale_handler_resolve'))"); + RunJS( + "Promise.reject(" + " stale_handler.bind(null, results, 'stale_handler_reject'))"); + microtask_queue()->RunMicrotasks(isolate()); + EXPECT_FALSE( + JSReceiver::HasProperty(results, NameFromChars("stale_handler_resolve")) + .FromJust()); + EXPECT_FALSE( + JSReceiver::HasProperty(results, NameFromChars("stale_handler_reject")) + .FromJust()); +} + } // namespace internal } // namespace v8 diff --git a/deps/v8/test/unittests/parser/ast-value-unittest.cc b/deps/v8/test/unittests/parser/ast-value-unittest.cc index 72e35a43a0..c30823b4b1 100644 --- a/deps/v8/test/unittests/parser/ast-value-unittest.cc +++ b/deps/v8/test/unittests/parser/ast-value-unittest.cc @@ -4,6 +4,7 @@ #include "src/ast/ast-value-factory.h" #include "src/ast/ast.h" +#include "src/hash-seed-inl.h" #include "src/heap/heap-inl.h" #include "src/isolate-inl.h" #include "src/zone/zone.h" @@ -17,7 +18,7 @@ class AstValueTest : public TestWithIsolateAndZone { protected: AstValueTest() : ast_value_factory_(zone(), i_isolate()->ast_string_constants(), - i_isolate()->heap()->HashSeed()), + HashSeed(i_isolate())), ast_node_factory_(&ast_value_factory_, zone()) {} Literal* NewBigInt(const char* str) { diff --git a/deps/v8/test/unittests/testcfg.py b/deps/v8/test/unittests/testcfg.py index 05fdd85809..a7fd6dc463 100644 --- a/deps/v8/test/unittests/testcfg.py +++ b/deps/v8/test/unittests/testcfg.py @@ -15,9 +15,10 @@ class VariantsGenerator(testsuite.VariantsGenerator): return self._standard_variant -class TestSuite(testsuite.TestSuite): - def ListTests(self): - shell = os.path.abspath(os.path.join(self.test_config.shell_dir, self.name)) +class TestLoader(testsuite.TestLoader): + def _list_test_filenames(self): + shell = os.path.abspath( + os.path.join(self.test_config.shell_dir, "unittests")) if utils.IsWindows(): shell += ".exe" @@ -30,6 +31,7 @@ class TestSuite(testsuite.TestSuite): output = cmd.execute() if output.exit_code == 0: break + print "Test executable failed to list the tests (try %d).\n\nCmd:" % i print cmd print "\nStdout:" @@ -40,17 +42,22 @@ class TestSuite(testsuite.TestSuite): else: raise Exception("Test executable failed to list the tests.") - tests = [] - test_case = '' + # TODO create an ExecutableTestLoader for refactoring this similar to + # JSTestLoader. + test_names = [] for line in output.stdout.splitlines(): test_desc = line.strip().split()[0] if test_desc.endswith('.'): test_case = test_desc elif test_case and test_desc: - test_path = test_case + test_desc - tests.append(self._create_test(test_path)) - tests.sort(key=lambda t: t.path) - return tests + test_names.append(test_case + test_desc) + + return sorted(test_names) + + +class TestSuite(testsuite.TestSuite): + def _test_loader_class(self): + return TestLoader def _test_class(self): return TestCase diff --git a/deps/v8/test/unittests/torque/ls-json-unittest.cc b/deps/v8/test/unittests/torque/ls-json-unittest.cc new file mode 100644 index 0000000000..5f0ec9252e --- /dev/null +++ b/deps/v8/test/unittests/torque/ls-json-unittest.cc @@ -0,0 +1,103 @@ +// Copyright 2019 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/torque/ls/json-parser.h" +#include "src/torque/ls/json.h" +#include "src/torque/source-positions.h" +#include "test/unittests/test-utils.h" + +namespace v8 { +namespace internal { +namespace torque { +namespace ls { + +TEST(LanguageServerJson, TestJsonPrimitives) { + const JsonValue true_result = ParseJson("true"); + ASSERT_EQ(true_result.tag, JsonValue::BOOL); + EXPECT_EQ(true_result.ToBool(), true); + + const JsonValue false_result = ParseJson("false"); + ASSERT_EQ(false_result.tag, JsonValue::BOOL); + EXPECT_EQ(false_result.ToBool(), false); + + const JsonValue null_result = ParseJson("null"); + ASSERT_EQ(null_result.tag, JsonValue::IS_NULL); + + const JsonValue number = ParseJson("42"); + ASSERT_EQ(number.tag, JsonValue::NUMBER); + EXPECT_EQ(number.ToNumber(), 42); +} + +TEST(LanguageServerJson, TestJsonStrings) { + const JsonValue basic = ParseJson("\"basic\""); + ASSERT_EQ(basic.tag, JsonValue::STRING); + EXPECT_EQ(basic.ToString(), "basic"); + + const JsonValue singleQuote = ParseJson("\"'\""); + ASSERT_EQ(singleQuote.tag, JsonValue::STRING); + EXPECT_EQ(singleQuote.ToString(), "'"); +} + +TEST(LanguageServerJson, TestJsonArrays) { + const JsonValue empty_array = ParseJson("[]"); + ASSERT_EQ(empty_array.tag, JsonValue::ARRAY); + EXPECT_EQ(empty_array.ToArray().size(), (size_t)0); + + const JsonValue number_array = ParseJson("[1, 2, 3, 4]"); + ASSERT_EQ(number_array.tag, JsonValue::ARRAY); + + const JsonArray& array = number_array.ToArray(); + ASSERT_EQ(array.size(), (size_t)4); + ASSERT_EQ(array[1].tag, JsonValue::NUMBER); + EXPECT_EQ(array[1].ToNumber(), 2); + + const JsonValue string_array_object = ParseJson("[\"a\", \"b\"]"); + ASSERT_EQ(string_array_object.tag, JsonValue::ARRAY); + + const JsonArray& string_array = string_array_object.ToArray(); + ASSERT_EQ(string_array.size(), (size_t)2); + ASSERT_EQ(string_array[1].tag, JsonValue::STRING); + EXPECT_EQ(string_array[1].ToString(), "b"); +} + +TEST(LanguageServerJson, TestJsonObjects) { + const JsonValue empty_object = ParseJson("{}"); + ASSERT_EQ(empty_object.tag, JsonValue::OBJECT); + EXPECT_EQ(empty_object.ToObject().size(), (size_t)0); + + const JsonValue primitive_fields = ParseJson("{ \"flag\": true, \"id\": 5}"); + EXPECT_EQ(primitive_fields.tag, JsonValue::OBJECT); + + const JsonValue& flag = primitive_fields.ToObject().at("flag"); + ASSERT_EQ(flag.tag, JsonValue::BOOL); + EXPECT_TRUE(flag.ToBool()); + + const JsonValue& id = primitive_fields.ToObject().at("id"); + ASSERT_EQ(id.tag, JsonValue::NUMBER); + EXPECT_EQ(id.ToNumber(), 5); + + const JsonValue& complex_fields = + ParseJson("{ \"array\": [], \"object\": { \"name\": \"torque\" } }"); + ASSERT_EQ(complex_fields.tag, JsonValue::OBJECT); + + const JsonValue& array = complex_fields.ToObject().at("array"); + ASSERT_EQ(array.tag, JsonValue::ARRAY); + EXPECT_EQ(array.ToArray().size(), (size_t)0); + + const JsonValue& object = complex_fields.ToObject().at("object"); + ASSERT_EQ(object.tag, JsonValue::OBJECT); + ASSERT_EQ(object.ToObject().at("name").tag, JsonValue::STRING); + EXPECT_EQ(object.ToObject().at("name").ToString(), "torque"); +} + +TEST(LanguageServerJsonDeathTest, SyntaxError) { + ASSERT_DEATH(ParseJson("{]"), "Parser Error: unexpected token"); + ASSERT_DEATH(ParseJson("{ noquoteskey: null }"), + "Lexer Error: unknown token"); +} + +} // namespace ls +} // namespace torque +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/torque/ls-message-unittest.cc b/deps/v8/test/unittests/torque/ls-message-unittest.cc new file mode 100644 index 0000000000..b8f7cf5864 --- /dev/null +++ b/deps/v8/test/unittests/torque/ls-message-unittest.cc @@ -0,0 +1,117 @@ +// Copyright 2019 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/torque/ls/json.h" +#include "src/torque/ls/message-handler.h" +#include "src/torque/ls/message.h" +#include "src/torque/server-data.h" +#include "src/torque/source-positions.h" +#include "test/unittests/test-utils.h" + +namespace v8 { +namespace internal { +namespace torque { +namespace ls { + +TEST(LanguageServerMessage, InitializeRequest) { + InitializeRequest request; + request.set_id(5); + request.set_method("initialize"); + request.params(); + + HandleMessage(request.GetJsonValue(), [](JsonValue& raw_response) { + InitializeResponse response(raw_response); + + // Check that the response id matches up with the request id, and that + // the language server signals its support for definitions. + EXPECT_EQ(response.id(), 5); + EXPECT_EQ(response.result().capabilities().definitionProvider(), true); + }); +} + +TEST(LanguageServerMessage, + RegisterDynamicCapabilitiesAfterInitializedNotification) { + Request<bool> notification; + notification.set_method("initialized"); + + HandleMessage(notification.GetJsonValue(), [](JsonValue& raw_request) { + RegistrationRequest request(raw_request); + + ASSERT_EQ(request.method(), "client/registerCapability"); + ASSERT_EQ(request.params().registrations_size(), (size_t)1); + + Registration registration = request.params().registrations(0); + ASSERT_EQ(registration.method(), "workspace/didChangeWatchedFiles"); + + auto options = + registration + .registerOptions<DidChangeWatchedFilesRegistrationOptions>(); + ASSERT_EQ(options.watchers_size(), (size_t)1); + }); +} + +TEST(LanguageServerMessage, GotoDefinitionUnkownFile) { + SourceFileMap::Scope source_file_map_scope; + + GotoDefinitionRequest request; + request.set_id(42); + request.set_method("textDocument/definition"); + request.params().textDocument().set_uri("file:///unknown.tq"); + + HandleMessage(request.GetJsonValue(), [](JsonValue& raw_response) { + GotoDefinitionResponse response(raw_response); + EXPECT_EQ(response.id(), 42); + EXPECT_TRUE(response.IsNull("result")); + }); +} + +TEST(LanguageServerMessage, GotoDefinition) { + SourceFileMap::Scope source_file_map_scope; + SourceId test_id = SourceFileMap::AddSource("file://test.tq"); + SourceId definition_id = SourceFileMap::AddSource("file://base.tq"); + + LanguageServerData::Scope server_data_scope; + LanguageServerData::AddDefinition({test_id, {1, 0}, {1, 10}}, + {definition_id, {4, 1}, {4, 5}}); + + // First, check a unknown definition. The result must be null. + GotoDefinitionRequest request; + request.set_id(42); + request.set_method("textDocument/definition"); + request.params().textDocument().set_uri("file://test.tq"); + request.params().position().set_line(2); + request.params().position().set_character(0); + + HandleMessage(request.GetJsonValue(), [](JsonValue& raw_response) { + GotoDefinitionResponse response(raw_response); + EXPECT_EQ(response.id(), 42); + EXPECT_TRUE(response.IsNull("result")); + }); + + // Second, check a known defintion. + request = GotoDefinitionRequest(); + request.set_id(43); + request.set_method("textDocument/definition"); + request.params().textDocument().set_uri("file://test.tq"); + request.params().position().set_line(1); + request.params().position().set_character(5); + + HandleMessage(request.GetJsonValue(), [](JsonValue& raw_response) { + GotoDefinitionResponse response(raw_response); + EXPECT_EQ(response.id(), 43); + ASSERT_FALSE(response.IsNull("result")); + + Location location = response.result(); + EXPECT_EQ(location.uri(), "file://base.tq"); + EXPECT_EQ(location.range().start().line(), 4); + EXPECT_EQ(location.range().start().character(), 1); + EXPECT_EQ(location.range().end().line(), 4); + EXPECT_EQ(location.range().end().character(), 5); + }); +} + +} // namespace ls +} // namespace torque +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/torque/torque-utils-unittest.cc b/deps/v8/test/unittests/torque/torque-utils-unittest.cc new file mode 100644 index 0000000000..ff877a3c42 --- /dev/null +++ b/deps/v8/test/unittests/torque/torque-utils-unittest.cc @@ -0,0 +1,30 @@ +// Copyright 2019 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/torque/utils.h" +#include "test/unittests/test-utils.h" + +namespace v8 { +namespace internal { +namespace torque { + +TEST(TorqueUtils, FileUriDecodeIllegal) { + EXPECT_EQ(FileUriDecode("http://wrong.scheme"), base::nullopt); + EXPECT_EQ(FileUriDecode("file://wrong-escape%"), base::nullopt); + EXPECT_EQ(FileUriDecode("file://another-wrong-escape%a"), base::nullopt); + EXPECT_EQ(FileUriDecode("file://no-hex-escape%0g"), base::nullopt); +} + +TEST(TorqueUtils, FileUriDecode) { + EXPECT_EQ(FileUriDecode("file:///some/src/file.tq").value(), + "/some/src/file.tq"); + EXPECT_EQ(FileUriDecode("file:///c%3A/torque/base.tq").value(), + "/c:/torque/base.tq"); + EXPECT_EQ(FileUriDecode("file:///d%3a/lower/hex.txt").value(), + "/d:/lower/hex.txt"); +} + +} // namespace torque +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/unicode-unittest.cc b/deps/v8/test/unittests/unicode-unittest.cc index 1bede08343..da1383c22c 100644 --- a/deps/v8/test/unittests/unicode-unittest.cc +++ b/deps/v8/test/unittests/unicode-unittest.cc @@ -50,9 +50,11 @@ void DecodeIncrementally(const std::vector<byte>& bytes, std::vector<unibrow::uchar>* output) { unibrow::Utf8::Utf8IncrementalBuffer buffer = 0; unibrow::Utf8::State state = unibrow::Utf8::State::kAccept; - for (size_t i = 0; i < bytes.size();) { + const byte* cursor = &bytes[0]; + const byte* end = &bytes[bytes.size()]; + while (cursor < end) { unibrow::uchar result = - unibrow::Utf8::ValueOfIncremental(bytes[i], &i, &state, &buffer); + unibrow::Utf8::ValueOfIncremental(&cursor, &state, &buffer); if (result != unibrow::Utf8::kIncomplete) { output->push_back(result); } diff --git a/deps/v8/test/unittests/unittests.status b/deps/v8/test/unittests/unittests.status index 7582deaedd..a105afe987 100644 --- a/deps/v8/test/unittests/unittests.status +++ b/deps/v8/test/unittests/unittests.status @@ -22,9 +22,16 @@ }], # '(arch == arm or arch == mips) and not simulator_run' ############################################################################## -['lite_mode', { +['lite_mode or variant == jitless', { # TODO(v8:7777): Re-enable once wasm is supported in jitless mode. + 'ValueSerializerTestWithSharedArrayBufferClone.RoundTripWebAssemblyMemory': [SKIP], 'ValueSerializerTestWithWasm.*': [SKIP], -}], # lite_mode + 'Parameterized/WasmCodeManagerTest.*': [SKIP], +}], # lite_mode or variant == jitless + +############################################################################## +['variant == jitless and not embedded_builtins', { + '*': [SKIP], +}], # variant == jitless and not embedded_builtins ] diff --git a/deps/v8/test/unittests/utils-unittest.cc b/deps/v8/test/unittests/utils-unittest.cc index c8032d187d..614880f2e7 100644 --- a/deps/v8/test/unittests/utils-unittest.cc +++ b/deps/v8/test/unittests/utils-unittest.cc @@ -24,7 +24,7 @@ typedef ::testing::Types<signed char, unsigned char, int64_t, uint64_t> IntegerTypes; -TYPED_TEST_CASE(UtilsTest, IntegerTypes); +TYPED_TEST_SUITE(UtilsTest, IntegerTypes); TYPED_TEST(UtilsTest, SaturateSub) { TypeParam min = std::numeric_limits<TypeParam>::min(); diff --git a/deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc b/deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc index e13816744f..13161947e8 100644 --- a/deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc +++ b/deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc @@ -6,6 +6,7 @@ #include "src/objects-inl.h" #include "src/objects.h" +#include "src/ostreams.h" #include "src/v8.h" #include "src/wasm/function-body-decoder-impl.h" #include "src/wasm/function-body-decoder.h" @@ -54,40 +55,6 @@ static const WasmOpcode kInt32BinopOpcodes[] = { #define WASM_BRV_IF_ZERO(depth, val) \ val, WASM_ZERO, kExprBrIf, static_cast<byte>(depth) -#define EXPECT_VERIFIES_C(sig, x) \ - Verify(true, sigs.sig(), ArrayVector(x), kAppendEnd) - -#define EXPECT_FAILURE_C(sig, x, ...) \ - Verify(false, sigs.sig(), ArrayVector(x), kAppendEnd, ##__VA_ARGS__) - -#define EXPECT_VERIFIES_SC(sig, x) Verify(true, sig, ArrayVector(x), kAppendEnd) - -#define EXPECT_FAILURE_SC(sig, x) Verify(false, sig, ArrayVector(x), kAppendEnd) - -#define EXPECT_VERIFIES_S(env, ...) \ - do { \ - static byte code[] = {__VA_ARGS__}; \ - Verify(true, env, ArrayVector(code), kAppendEnd); \ - } while (false) - -#define EXPECT_FAILURE_S(env, ...) \ - do { \ - static byte code[] = {__VA_ARGS__}; \ - Verify(false, env, ArrayVector(code), kAppendEnd); \ - } while (false) - -#define EXPECT_VERIFIES(sig, ...) \ - do { \ - static const byte code[] = {__VA_ARGS__}; \ - EXPECT_VERIFIES_C(sig, code); \ - } while (false) - -#define EXPECT_FAILURE(sig, ...) \ - do { \ - static const byte code[] = {__VA_ARGS__}; \ - EXPECT_FAILURE_C(sig, code); \ - } while (false) - class FunctionBodyDecoderTest : public TestWithZone { public: typedef std::pair<uint32_t, ValueType> LocalsDecl; @@ -116,7 +83,9 @@ class FunctionBodyDecoderTest : public TestWithZone { // Prepend the local decls to the code. local_decls.Emit(buffer); // Emit the code. - memcpy(buffer + locals_size, code.start(), code.size()); + if (code.size() > 0) { + memcpy(buffer + locals_size, code.start(), code.size()); + } if (append_end == kAppendEnd) { // Append an extra end opcode. buffer[total_size - 1] = kExprEnd; @@ -125,13 +94,28 @@ class FunctionBodyDecoderTest : public TestWithZone { return {buffer, total_size}; } + template <size_t N> + Vector<const byte> CodeToVector(const byte (&code)[N]) { + return ArrayVector(code); + } + + Vector<const byte> CodeToVector( + const std::initializer_list<const byte>& code) { + return VectorOf(&*code.begin(), code.size()); + } + + Vector<const byte> CodeToVector(Vector<const byte> vec) { return vec; } + // Prepends local variable declarations and renders nice error messages for // verification failures. - void Verify(bool expected_success, FunctionSig* sig, Vector<const byte> code, - AppendEnd append_end, const char* message = nullptr) { - code = PrepareBytecode(code, append_end); - - // Verify the code. + template <typename Code = std::initializer_list<const byte>> + void Validate(bool expected_success, FunctionSig* sig, Code&& raw_code, + AppendEnd append_end = kAppendEnd, + const char* message = nullptr) { + Vector<const byte> code = + PrepareBytecode(CodeToVector(std::forward<Code>(raw_code)), append_end); + + // Validate the code. FunctionBody body(sig, 0, code.start(), code.end()); WasmFeatures unused_detected_features; DecodeResult result = @@ -151,10 +135,24 @@ class FunctionBodyDecoderTest : public TestWithZone { } } + template <typename Code = std::initializer_list<const byte>> + void ExpectValidates(FunctionSig* sig, Code&& raw_code, + AppendEnd append_end = kAppendEnd, + const char* message = nullptr) { + Validate(true, sig, std::forward<Code>(raw_code), append_end, message); + } + + template <typename Code = std::initializer_list<const byte>> + void ExpectFailure(FunctionSig* sig, Code&& raw_code, + AppendEnd append_end = kAppendEnd, + const char* message = nullptr) { + Validate(false, sig, std::forward<Code>(raw_code), append_end, message); + } + void TestBinop(WasmOpcode opcode, FunctionSig* success) { // op(local[0], local[1]) byte code[] = {WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; - EXPECT_VERIFIES_SC(success, code); + ExpectValidates(success, code); // Try all combinations of return and parameter types. for (size_t i = 0; i < arraysize(kValueTypes); i++) { @@ -166,7 +164,7 @@ class FunctionBodyDecoderTest : public TestWithZone { types[2] != success->GetParam(1)) { // Test signature mismatch. FunctionSig sig(1, 2, types); - EXPECT_FAILURE_SC(&sig, code); + ExpectFailure(&sig, code); } } } @@ -183,7 +181,7 @@ class FunctionBodyDecoderTest : public TestWithZone { { ValueType types[] = {ret_type, param_type}; FunctionSig sig(1, 1, types); - EXPECT_VERIFIES_SC(&sig, code); + ExpectValidates(&sig, code); } // Try all combinations of return and parameter types. @@ -193,7 +191,7 @@ class FunctionBodyDecoderTest : public TestWithZone { if (types[0] != ret_type || types[1] != param_type) { // Test signature mismatch. FunctionSig sig(1, 1, types); - EXPECT_FAILURE_SC(&sig, code); + ExpectFailure(&sig, code); } } } @@ -254,6 +252,18 @@ class TestModuleBuilder { return static_cast<byte>(mod.exceptions.size() - 1); } + byte AddTable(ValueType type, uint32_t initial_size, bool has_maximum_size, + uint32_t maximum_size) { + CHECK(type == kWasmAnyRef || type == kWasmAnyFunc); + mod.tables.emplace_back(); + WasmTable& table = mod.tables.back(); + table.type = type; + table.initial_size = initial_size; + table.has_maximum_size = has_maximum_size; + table.maximum_size = maximum_size; + return static_cast<byte>(mod.tables.size() - 1); + } + void InitializeMemory() { mod.has_memory = true; mod.initial_pages = 1; @@ -285,49 +295,47 @@ TEST_F(FunctionBodyDecoderTest, Int32Const1) { byte code[] = {kExprI32Const, 0}; for (int i = -64; i <= 63; i++) { code[1] = static_cast<byte>(i & 0x7F); - EXPECT_VERIFIES_C(i_i, code); + ExpectValidates(sigs.i_i(), code); } } TEST_F(FunctionBodyDecoderTest, RefNull) { WASM_FEATURE_SCOPE(anyref); - byte code[] = {kExprRefNull}; - EXPECT_VERIFIES_C(r_v, code); + ExpectValidates(sigs.r_v(), {kExprRefNull}); } TEST_F(FunctionBodyDecoderTest, EmptyFunction) { - Verify(true, sigs.v_v(), {}, kAppendEnd); - Verify(false, sigs.i_i(), {}, kAppendEnd); + ExpectValidates(sigs.v_v(), {}); + ExpectFailure(sigs.i_i(), {}); } TEST_F(FunctionBodyDecoderTest, IncompleteIf1) { byte code[] = {kExprIf}; - EXPECT_FAILURE_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); + ExpectFailure(sigs.v_v(), code); + ExpectFailure(sigs.i_i(), code); } TEST_F(FunctionBodyDecoderTest, Int32Const_fallthru) { - EXPECT_VERIFIES(i_i, WASM_I32V_1(0)); + ExpectValidates(sigs.i_i(), {WASM_I32V_1(0)}); } TEST_F(FunctionBodyDecoderTest, Int32Const_fallthru2) { - EXPECT_FAILURE(i_i, WASM_I32V_1(0), WASM_I32V_1(1)); + ExpectFailure(sigs.i_i(), {WASM_I32V_1(0), WASM_I32V_1(1)}); } TEST_F(FunctionBodyDecoderTest, Int32Const) { const int kInc = 4498211; for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { // TODO(binji): expand test for other sized int32s; 1 through 5 bytes. - byte code[] = {WASM_I32V(i)}; - EXPECT_VERIFIES_C(i_i, code); + ExpectValidates(sigs.i_i(), {WASM_I32V(i)}); } } TEST_F(FunctionBodyDecoderTest, Int64Const) { const int kInc = 4498211; for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { - byte code[] = {WASM_I64V((static_cast<int64_t>(i) << 32) | i)}; - EXPECT_VERIFIES_C(l_l, code); + ExpectValidates(sigs.l_l(), + {WASM_I64V((static_cast<uint64_t>(i) << 32) | i)}); } } @@ -336,7 +344,7 @@ TEST_F(FunctionBodyDecoderTest, Float32Const) { Address ptr = reinterpret_cast<Address>(code + 1); for (int i = 0; i < 30; i++) { WriteLittleEndianValue<float>(ptr, i * -7.75f); - EXPECT_VERIFIES_C(f_ff, code); + ExpectValidates(sigs.f_ff(), code); } } @@ -345,7 +353,7 @@ TEST_F(FunctionBodyDecoderTest, Float64Const) { Address ptr = reinterpret_cast<Address>(code + 1); for (int i = 0; i < 30; i++) { WriteLittleEndianValue<double>(ptr, i * 33.45); - EXPECT_VERIFIES_C(d_dd, code); + ExpectValidates(sigs.d_dd(), code); } } @@ -353,31 +361,31 @@ TEST_F(FunctionBodyDecoderTest, Int32Const_off_end) { byte code[] = {kExprI32Const, 0xAA, 0xBB, 0xCC, 0x44}; for (size_t size = 1; size <= 4; ++size) { - Verify(false, sigs.i_i(), {code, size}, kAppendEnd); + ExpectFailure(sigs.i_i(), VectorOf(code, size), kAppendEnd); // Should also fail without the trailing 'end' opcode. - Verify(false, sigs.i_i(), {code, size}, kOmitEnd); + ExpectFailure(sigs.i_i(), VectorOf(code, size), kOmitEnd); } } TEST_F(FunctionBodyDecoderTest, GetLocal0_param) { - EXPECT_VERIFIES_C(i_i, kCodeGetLocal0); + ExpectValidates(sigs.i_i(), kCodeGetLocal0); } TEST_F(FunctionBodyDecoderTest, GetLocal0_local) { AddLocals(kWasmI32, 1); - EXPECT_VERIFIES_C(i_v, kCodeGetLocal0); + ExpectValidates(sigs.i_v(), kCodeGetLocal0); } TEST_F(FunctionBodyDecoderTest, TooManyLocals) { AddLocals(kWasmI32, 4034986500); - EXPECT_FAILURE_C(i_v, kCodeGetLocal0); + ExpectFailure(sigs.i_v(), kCodeGetLocal0); } TEST_F(FunctionBodyDecoderTest, GetLocal0_param_n) { FunctionSig* array[] = {sigs.i_i(), sigs.i_ii(), sigs.i_iii()}; for (size_t i = 0; i < arraysize(array); i++) { - EXPECT_VERIFIES_SC(array[i], kCodeGetLocal0); + ExpectValidates(array[i], kCodeGetLocal0); } } @@ -385,149 +393,143 @@ TEST_F(FunctionBodyDecoderTest, GetLocalN_local) { for (byte i = 1; i < 8; i++) { AddLocals(kWasmI32, 1); for (byte j = 0; j < i; j++) { - byte code[] = {kExprGetLocal, j}; - EXPECT_VERIFIES_C(i_v, code); + ExpectValidates(sigs.i_v(), {kExprGetLocal, j}); } } } TEST_F(FunctionBodyDecoderTest, GetLocal0_fail_no_params) { - EXPECT_FAILURE_C(i_v, kCodeGetLocal0); + ExpectFailure(sigs.i_v(), kCodeGetLocal0); } TEST_F(FunctionBodyDecoderTest, GetLocal1_fail_no_locals) { - EXPECT_FAILURE_C(i_i, kCodeGetLocal1); + ExpectFailure(sigs.i_i(), kCodeGetLocal1); } TEST_F(FunctionBodyDecoderTest, GetLocal_off_end) { - static const byte code[] = {kExprGetLocal}; - EXPECT_FAILURE_C(i_i, code); + ExpectFailure(sigs.i_i(), {kExprGetLocal}); } TEST_F(FunctionBodyDecoderTest, NumLocalBelowLimit) { AddLocals(kWasmI32, kV8MaxWasmFunctionLocals - 1); - EXPECT_VERIFIES(v_v, WASM_NOP); + ExpectValidates(sigs.v_v(), {WASM_NOP}); } TEST_F(FunctionBodyDecoderTest, NumLocalAtLimit) { AddLocals(kWasmI32, kV8MaxWasmFunctionLocals); - EXPECT_VERIFIES(v_v, WASM_NOP); + ExpectValidates(sigs.v_v(), {WASM_NOP}); } TEST_F(FunctionBodyDecoderTest, NumLocalAboveLimit) { AddLocals(kWasmI32, kV8MaxWasmFunctionLocals + 1); - EXPECT_FAILURE(v_v, WASM_NOP); + ExpectFailure(sigs.v_v(), {WASM_NOP}); } TEST_F(FunctionBodyDecoderTest, GetLocal_varint) { const int kMaxLocals = kV8MaxWasmFunctionLocals - 1; AddLocals(kWasmI32, kMaxLocals); - EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_1(66)); - EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_2(7777)); - EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_3(8888)); - EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(9999)); + ExpectValidates(sigs.i_i(), {kExprGetLocal, U32V_1(66)}); + ExpectValidates(sigs.i_i(), {kExprGetLocal, U32V_2(7777)}); + ExpectValidates(sigs.i_i(), {kExprGetLocal, U32V_3(8888)}); + ExpectValidates(sigs.i_i(), {kExprGetLocal, U32V_4(9999)}); - EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_5(kMaxLocals - 1)); + ExpectValidates(sigs.i_i(), {kExprGetLocal, U32V_5(kMaxLocals - 1)}); - EXPECT_FAILURE(i_i, kExprGetLocal, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); + ExpectFailure(sigs.i_i(), {kExprGetLocal, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}); - EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals - 1)); - EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals)); - EXPECT_FAILURE(i_i, kExprGetLocal, U32V_4(kMaxLocals + 1)); + ExpectValidates(sigs.i_i(), {kExprGetLocal, U32V_4(kMaxLocals - 1)}); + ExpectValidates(sigs.i_i(), {kExprGetLocal, U32V_4(kMaxLocals)}); + ExpectFailure(sigs.i_i(), {kExprGetLocal, U32V_4(kMaxLocals + 1)}); - EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals)); - EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals + 1)); + ExpectFailure(sigs.i_v(), {kExprGetLocal, U32V_4(kMaxLocals)}); + ExpectFailure(sigs.i_v(), {kExprGetLocal, U32V_4(kMaxLocals + 1)}); } TEST_F(FunctionBodyDecoderTest, GetLocal_toomany) { AddLocals(kWasmI32, kV8MaxWasmFunctionLocals - 100); AddLocals(kWasmI32, 100); - EXPECT_VERIFIES(i_v, kExprGetLocal, U32V_1(66)); - EXPECT_FAILURE(i_i, kExprGetLocal, U32V_1(66)); + ExpectValidates(sigs.i_v(), {kExprGetLocal, U32V_1(66)}); + ExpectFailure(sigs.i_i(), {kExprGetLocal, U32V_1(66)}); } TEST_F(FunctionBodyDecoderTest, Binops_off_end) { byte code1[] = {0}; // [opcode] for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { code1[0] = kInt32BinopOpcodes[i]; - EXPECT_FAILURE_C(i_i, code1); + ExpectFailure(sigs.i_i(), code1); } byte code3[] = {kExprGetLocal, 0, 0}; // [expr] [opcode] for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { code3[2] = kInt32BinopOpcodes[i]; - EXPECT_FAILURE_C(i_i, code3); + ExpectFailure(sigs.i_i(), code3); } byte code4[] = {kExprGetLocal, 0, 0, 0}; // [expr] [opcode] [opcode] for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { code4[2] = kInt32BinopOpcodes[i]; code4[3] = kInt32BinopOpcodes[i]; - EXPECT_FAILURE_C(i_i, code4); + ExpectFailure(sigs.i_i(), code4); } } TEST_F(FunctionBodyDecoderTest, BinopsAcrossBlock1) { - static const byte code[] = {WASM_ZERO, kExprBlock, kLocalI32, - WASM_ZERO, kExprI32Add, kExprEnd}; - EXPECT_FAILURE_C(i_i, code); + ExpectFailure(sigs.i_i(), {WASM_ZERO, kExprBlock, kLocalI32, WASM_ZERO, + kExprI32Add, kExprEnd}); } TEST_F(FunctionBodyDecoderTest, BinopsAcrossBlock2) { - static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprBlock, - kLocalI32, kExprI32Add, kExprEnd}; - EXPECT_FAILURE_C(i_i, code); + ExpectFailure(sigs.i_i(), {WASM_ZERO, WASM_ZERO, kExprBlock, kLocalI32, + kExprI32Add, kExprEnd}); } TEST_F(FunctionBodyDecoderTest, BinopsAcrossBlock3) { - static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprIf, kLocalI32, - kExprI32Add, kExprElse, kExprI32Add, kExprEnd}; - EXPECT_FAILURE_C(i_i, code); + ExpectFailure(sigs.i_i(), {WASM_ZERO, WASM_ZERO, kExprIf, kLocalI32, + kExprI32Add, kExprElse, kExprI32Add, kExprEnd}); } TEST_F(FunctionBodyDecoderTest, Nop) { - static const byte code[] = {kExprNop}; - EXPECT_VERIFIES_C(v_v, code); + ExpectValidates(sigs.v_v(), {kExprNop}); } TEST_F(FunctionBodyDecoderTest, SetLocal0_void) { - EXPECT_FAILURE(i_i, WASM_SET_LOCAL(0, WASM_ZERO)); + ExpectFailure(sigs.i_i(), {WASM_SET_LOCAL(0, WASM_ZERO)}); } TEST_F(FunctionBodyDecoderTest, SetLocal0_param) { - EXPECT_FAILURE_C(i_i, kCodeSetLocal0); - EXPECT_FAILURE_C(f_ff, kCodeSetLocal0); - EXPECT_FAILURE_C(d_dd, kCodeSetLocal0); + ExpectFailure(sigs.i_i(), kCodeSetLocal0); + ExpectFailure(sigs.f_ff(), kCodeSetLocal0); + ExpectFailure(sigs.d_dd(), kCodeSetLocal0); } TEST_F(FunctionBodyDecoderTest, TeeLocal0_param) { - EXPECT_VERIFIES_C(i_i, kCodeTeeLocal0); - EXPECT_FAILURE_C(f_ff, kCodeTeeLocal0); - EXPECT_FAILURE_C(d_dd, kCodeTeeLocal0); + ExpectValidates(sigs.i_i(), kCodeTeeLocal0); + ExpectFailure(sigs.f_ff(), kCodeTeeLocal0); + ExpectFailure(sigs.d_dd(), kCodeTeeLocal0); } TEST_F(FunctionBodyDecoderTest, SetLocal0_local) { - EXPECT_FAILURE_C(i_v, kCodeSetLocal0); - EXPECT_FAILURE_C(v_v, kCodeSetLocal0); + ExpectFailure(sigs.i_v(), kCodeSetLocal0); + ExpectFailure(sigs.v_v(), kCodeSetLocal0); AddLocals(kWasmI32, 1); - EXPECT_FAILURE_C(i_v, kCodeSetLocal0); - EXPECT_VERIFIES_C(v_v, kCodeSetLocal0); + ExpectFailure(sigs.i_v(), kCodeSetLocal0); + ExpectValidates(sigs.v_v(), kCodeSetLocal0); } TEST_F(FunctionBodyDecoderTest, TeeLocal0_local) { - EXPECT_FAILURE_C(i_v, kCodeTeeLocal0); + ExpectFailure(sigs.i_v(), kCodeTeeLocal0); AddLocals(kWasmI32, 1); - EXPECT_VERIFIES_C(i_v, kCodeTeeLocal0); + ExpectValidates(sigs.i_v(), kCodeTeeLocal0); } TEST_F(FunctionBodyDecoderTest, TeeLocalN_local) { for (byte i = 1; i < 8; i++) { AddLocals(kWasmI32, 1); for (byte j = 0; j < i; j++) { - EXPECT_FAILURE(v_v, WASM_TEE_LOCAL(j, WASM_I32V_1(i))); - EXPECT_VERIFIES(i_i, WASM_TEE_LOCAL(j, WASM_I32V_1(i))); + ExpectFailure(sigs.v_v(), {WASM_TEE_LOCAL(j, WASM_I32V_1(i))}); + ExpectValidates(sigs.i_i(), {WASM_TEE_LOCAL(j, WASM_I32V_1(i))}); } } } @@ -541,243 +543,251 @@ TEST_F(FunctionBodyDecoderTest, BlockN) { buffer[0] = kExprBlock; buffer[1] = kLocalVoid; buffer[i + 2] = kExprEnd; - Verify(true, sigs.v_i(), {buffer, i + 3}, kAppendEnd); + ExpectValidates(sigs.v_i(), VectorOf(buffer, i + 3), kAppendEnd); } } #define WASM_EMPTY_BLOCK kExprBlock, kLocalVoid, kExprEnd TEST_F(FunctionBodyDecoderTest, Block0) { - static const byte code[] = {WASM_EMPTY_BLOCK}; - EXPECT_VERIFIES_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); + ExpectValidates(sigs.v_v(), {WASM_EMPTY_BLOCK}); + ExpectFailure(sigs.i_i(), {WASM_EMPTY_BLOCK}); } TEST_F(FunctionBodyDecoderTest, Block0_fallthru1) { - static const byte code[] = {WASM_BLOCK(WASM_EMPTY_BLOCK)}; - EXPECT_VERIFIES_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); + ExpectValidates(sigs.v_v(), {WASM_BLOCK(WASM_EMPTY_BLOCK)}); + ExpectFailure(sigs.i_i(), {WASM_BLOCK(WASM_EMPTY_BLOCK)}); } TEST_F(FunctionBodyDecoderTest, Block0Block0) { - static const byte code[] = {WASM_EMPTY_BLOCK, WASM_EMPTY_BLOCK}; - EXPECT_VERIFIES_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); + ExpectValidates(sigs.v_v(), {WASM_EMPTY_BLOCK, WASM_EMPTY_BLOCK}); + ExpectFailure(sigs.i_i(), {WASM_EMPTY_BLOCK, WASM_EMPTY_BLOCK}); } TEST_F(FunctionBodyDecoderTest, Block0_end) { - EXPECT_FAILURE(v_v, WASM_EMPTY_BLOCK, kExprEnd); + ExpectFailure(sigs.v_v(), {WASM_EMPTY_BLOCK, kExprEnd}); } #undef WASM_EMPTY_BLOCK TEST_F(FunctionBodyDecoderTest, Block1) { byte code[] = {WASM_BLOCK_I(WASM_GET_LOCAL(0))}; - EXPECT_VERIFIES_C(i_i, code); - EXPECT_FAILURE_C(v_i, code); - EXPECT_FAILURE_C(d_dd, code); - EXPECT_FAILURE_C(i_f, code); - EXPECT_FAILURE_C(i_d, code); + ExpectValidates(sigs.i_i(), code); + ExpectFailure(sigs.v_i(), code); + ExpectFailure(sigs.d_dd(), code); + ExpectFailure(sigs.i_f(), code); + ExpectFailure(sigs.i_d(), code); } TEST_F(FunctionBodyDecoderTest, Block1_i) { byte code[] = {WASM_BLOCK_I(WASM_ZERO)}; - EXPECT_VERIFIES_C(i_i, code); - EXPECT_FAILURE_C(f_ff, code); - EXPECT_FAILURE_C(d_dd, code); - EXPECT_FAILURE_C(l_ll, code); + ExpectValidates(sigs.i_i(), code); + ExpectFailure(sigs.f_ff(), code); + ExpectFailure(sigs.d_dd(), code); + ExpectFailure(sigs.l_ll(), code); } TEST_F(FunctionBodyDecoderTest, Block1_f) { byte code[] = {WASM_BLOCK_F(WASM_F32(0))}; - EXPECT_FAILURE_C(i_i, code); - EXPECT_VERIFIES_C(f_ff, code); - EXPECT_FAILURE_C(d_dd, code); - EXPECT_FAILURE_C(l_ll, code); + ExpectFailure(sigs.i_i(), code); + ExpectValidates(sigs.f_ff(), code); + ExpectFailure(sigs.d_dd(), code); + ExpectFailure(sigs.l_ll(), code); } TEST_F(FunctionBodyDecoderTest, Block1_continue) { - EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); + ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_BR(0))}); } TEST_F(FunctionBodyDecoderTest, Block1_br) { - EXPECT_VERIFIES(v_v, B1(WASM_BR(0))); - EXPECT_VERIFIES(v_v, B1(WASM_BR(1))); - EXPECT_FAILURE(v_v, B1(WASM_BR(2))); + ExpectValidates(sigs.v_v(), {B1(WASM_BR(0))}); + ExpectValidates(sigs.v_v(), {B1(WASM_BR(1))}); + ExpectFailure(sigs.v_v(), {B1(WASM_BR(2))}); } TEST_F(FunctionBodyDecoderTest, Block2_br) { - EXPECT_VERIFIES(v_v, B2(WASM_NOP, WASM_BR(0))); - EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_NOP)); - EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_BR(0))); + ExpectValidates(sigs.v_v(), {B2(WASM_NOP, WASM_BR(0))}); + ExpectValidates(sigs.v_v(), {B2(WASM_BR(0), WASM_NOP)}); + ExpectValidates(sigs.v_v(), {B2(WASM_BR(0), WASM_BR(0))}); } TEST_F(FunctionBodyDecoderTest, Block2) { - EXPECT_FAILURE(i_i, WASM_BLOCK(WASM_NOP, WASM_NOP)); - EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_NOP, WASM_NOP)); - EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_NOP, WASM_ZERO)); - EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_ZERO, WASM_NOP)); - EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_ZERO, WASM_ZERO)); + ExpectFailure(sigs.i_i(), {WASM_BLOCK(WASM_NOP, WASM_NOP)}); + ExpectFailure(sigs.i_i(), {WASM_BLOCK_I(WASM_NOP, WASM_NOP)}); + ExpectValidates(sigs.i_i(), {WASM_BLOCK_I(WASM_NOP, WASM_ZERO)}); + ExpectValidates(sigs.i_i(), {WASM_BLOCK_I(WASM_ZERO, WASM_NOP)}); + ExpectFailure(sigs.i_i(), {WASM_BLOCK_I(WASM_ZERO, WASM_ZERO)}); } TEST_F(FunctionBodyDecoderTest, Block2b) { byte code[] = {WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), WASM_ZERO)}; - EXPECT_VERIFIES_C(i_i, code); - EXPECT_FAILURE_C(v_v, code); - EXPECT_FAILURE_C(f_ff, code); + ExpectValidates(sigs.i_i(), code); + ExpectFailure(sigs.v_v(), code); + ExpectFailure(sigs.f_ff(), code); } TEST_F(FunctionBodyDecoderTest, Block2_fallthru) { - EXPECT_VERIFIES( - i_i, B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_SET_LOCAL(0, WASM_ZERO)), - WASM_I32V_1(23)); + ExpectValidates(sigs.i_i(), {B2(WASM_SET_LOCAL(0, WASM_ZERO), + WASM_SET_LOCAL(0, WASM_ZERO)), + WASM_I32V_1(23)}); } TEST_F(FunctionBodyDecoderTest, Block3) { - EXPECT_VERIFIES(i_i, - WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), - WASM_SET_LOCAL(0, WASM_ZERO), WASM_I32V_1(11))); + ExpectValidates(sigs.i_i(), {WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), + WASM_SET_LOCAL(0, WASM_ZERO), + WASM_I32V_1(11))}); } TEST_F(FunctionBodyDecoderTest, Block5) { - EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO)); + ExpectFailure(sigs.v_i(), {WASM_BLOCK(WASM_ZERO)}); - EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO)); + ExpectFailure(sigs.v_i(), {WASM_BLOCK(WASM_ZERO, WASM_ZERO)}); - EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectFailure(sigs.v_i(), {WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO)}); - EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectFailure(sigs.v_i(), + {WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO)}); - EXPECT_FAILURE( - v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectFailure(sigs.v_i(), {WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, + WASM_ZERO, WASM_ZERO)}); } TEST_F(FunctionBodyDecoderTest, BlockType) { - EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_GET_LOCAL(0))); - EXPECT_VERIFIES(l_l, WASM_BLOCK_L(WASM_GET_LOCAL(0))); - EXPECT_VERIFIES(f_f, WASM_BLOCK_F(WASM_GET_LOCAL(0))); - EXPECT_VERIFIES(d_d, WASM_BLOCK_D(WASM_GET_LOCAL(0))); + ExpectValidates(sigs.i_i(), {WASM_BLOCK_I(WASM_GET_LOCAL(0))}); + ExpectValidates(sigs.l_l(), {WASM_BLOCK_L(WASM_GET_LOCAL(0))}); + ExpectValidates(sigs.f_f(), {WASM_BLOCK_F(WASM_GET_LOCAL(0))}); + ExpectValidates(sigs.d_d(), {WASM_BLOCK_D(WASM_GET_LOCAL(0))}); } TEST_F(FunctionBodyDecoderTest, BlockType_fail) { - EXPECT_FAILURE(i_i, WASM_BLOCK_L(WASM_I64V_1(0))); - EXPECT_FAILURE(i_i, WASM_BLOCK_F(WASM_F32(0.0))); - EXPECT_FAILURE(i_i, WASM_BLOCK_D(WASM_F64(1.1))); + ExpectFailure(sigs.i_i(), {WASM_BLOCK_L(WASM_I64V_1(0))}); + ExpectFailure(sigs.i_i(), {WASM_BLOCK_F(WASM_F32(0.0))}); + ExpectFailure(sigs.i_i(), {WASM_BLOCK_D(WASM_F64(1.1))}); - EXPECT_FAILURE(l_l, WASM_BLOCK_I(WASM_ZERO)); - EXPECT_FAILURE(l_l, WASM_BLOCK_F(WASM_F32(0.0))); - EXPECT_FAILURE(l_l, WASM_BLOCK_D(WASM_F64(1.1))); + ExpectFailure(sigs.l_l(), {WASM_BLOCK_I(WASM_ZERO)}); + ExpectFailure(sigs.l_l(), {WASM_BLOCK_F(WASM_F32(0.0))}); + ExpectFailure(sigs.l_l(), {WASM_BLOCK_D(WASM_F64(1.1))}); - EXPECT_FAILURE(f_ff, WASM_BLOCK_I(WASM_ZERO)); - EXPECT_FAILURE(f_ff, WASM_BLOCK_L(WASM_I64V_1(0))); - EXPECT_FAILURE(f_ff, WASM_BLOCK_D(WASM_F64(1.1))); + ExpectFailure(sigs.f_ff(), {WASM_BLOCK_I(WASM_ZERO)}); + ExpectFailure(sigs.f_ff(), {WASM_BLOCK_L(WASM_I64V_1(0))}); + ExpectFailure(sigs.f_ff(), {WASM_BLOCK_D(WASM_F64(1.1))}); - EXPECT_FAILURE(d_dd, WASM_BLOCK_I(WASM_ZERO)); - EXPECT_FAILURE(d_dd, WASM_BLOCK_L(WASM_I64V_1(0))); - EXPECT_FAILURE(d_dd, WASM_BLOCK_F(WASM_F32(0.0))); + ExpectFailure(sigs.d_dd(), {WASM_BLOCK_I(WASM_ZERO)}); + ExpectFailure(sigs.d_dd(), {WASM_BLOCK_L(WASM_I64V_1(0))}); + ExpectFailure(sigs.d_dd(), {WASM_BLOCK_F(WASM_F32(0.0))}); } TEST_F(FunctionBodyDecoderTest, BlockF32) { static const byte code[] = {WASM_BLOCK_F(kExprF32Const, 0, 0, 0, 0)}; - EXPECT_VERIFIES_C(f_ff, code); - EXPECT_FAILURE_C(i_i, code); - EXPECT_FAILURE_C(d_dd, code); + ExpectValidates(sigs.f_ff(), code); + ExpectFailure(sigs.i_i(), code); + ExpectFailure(sigs.d_dd(), code); } TEST_F(FunctionBodyDecoderTest, BlockN_off_end) { byte code[] = {WASM_BLOCK(kExprNop, kExprNop, kExprNop, kExprNop)}; - EXPECT_VERIFIES_C(v_v, code); + ExpectValidates(sigs.v_v(), code); for (size_t i = 1; i < arraysize(code); i++) { - Verify(false, sigs.v_v(), {code, i}, kAppendEnd); - Verify(false, sigs.v_v(), {code, i}, kOmitEnd); + ExpectFailure(sigs.v_v(), VectorOf(code, i), kAppendEnd); + ExpectFailure(sigs.v_v(), VectorOf(code, i), kOmitEnd); } } TEST_F(FunctionBodyDecoderTest, Block2_continue) { - EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_BR(0))); - EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_BR(1))); - EXPECT_FAILURE(v_v, WASM_LOOP(WASM_NOP, WASM_BR(2))); + ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_NOP, WASM_BR(0))}); + ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_NOP, WASM_BR(1))}); + ExpectFailure(sigs.v_v(), {WASM_LOOP(WASM_NOP, WASM_BR(2))}); } TEST_F(FunctionBodyDecoderTest, Block3_continue) { - EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(0)))); - EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(1)))); - EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(2)))); - EXPECT_FAILURE(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(3)))); + ExpectValidates(sigs.v_v(), {B1(WASM_LOOP(WASM_NOP, WASM_BR(0)))}); + ExpectValidates(sigs.v_v(), {B1(WASM_LOOP(WASM_NOP, WASM_BR(1)))}); + ExpectValidates(sigs.v_v(), {B1(WASM_LOOP(WASM_NOP, WASM_BR(2)))}); + ExpectFailure(sigs.v_v(), {B1(WASM_LOOP(WASM_NOP, WASM_BR(3)))}); } TEST_F(FunctionBodyDecoderTest, NestedBlock_return) { - EXPECT_VERIFIES(i_i, B1(B1(WASM_RETURN1(WASM_ZERO))), WASM_ZERO); + ExpectValidates(sigs.i_i(), {B1(B1(WASM_RETURN1(WASM_ZERO))), WASM_ZERO}); } TEST_F(FunctionBodyDecoderTest, BlockBrBinop) { - EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I32V_1(1))), - WASM_I32V_1(2))); + ExpectValidates(sigs.i_i(), + {WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I32V_1(1))), + WASM_I32V_1(2))}); } TEST_F(FunctionBodyDecoderTest, If_empty1) { - EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprEnd); + ExpectValidates(sigs.v_v(), {WASM_ZERO, WASM_IF_OP, kExprEnd}); } TEST_F(FunctionBodyDecoderTest, If_empty2) { - EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, kExprEnd); + ExpectValidates(sigs.v_v(), {WASM_ZERO, WASM_IF_OP, kExprElse, kExprEnd}); } TEST_F(FunctionBodyDecoderTest, If_empty3) { - EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, WASM_NOP, kExprElse, kExprEnd); - EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, WASM_ZERO, kExprElse, kExprEnd); + ExpectValidates(sigs.v_v(), + {WASM_ZERO, WASM_IF_OP, WASM_NOP, kExprElse, kExprEnd}); + ExpectFailure(sigs.v_v(), + {WASM_ZERO, WASM_IF_OP, WASM_ZERO, kExprElse, kExprEnd}); } TEST_F(FunctionBodyDecoderTest, If_empty4) { - EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_NOP, kExprEnd); - EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_ZERO, kExprEnd); + ExpectValidates(sigs.v_v(), + {WASM_ZERO, WASM_IF_OP, kExprElse, WASM_NOP, kExprEnd}); + ExpectFailure(sigs.v_v(), + {WASM_ZERO, WASM_IF_OP, kExprElse, WASM_ZERO, kExprEnd}); } TEST_F(FunctionBodyDecoderTest, If_empty_stack) { byte code[] = {kExprIf}; - EXPECT_FAILURE_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); + ExpectFailure(sigs.v_v(), code); + ExpectFailure(sigs.i_i(), code); } TEST_F(FunctionBodyDecoderTest, If_incomplete1) { byte code[] = {kExprI32Const, 0, kExprIf}; - EXPECT_FAILURE_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); + ExpectFailure(sigs.v_v(), code); + ExpectFailure(sigs.i_i(), code); } TEST_F(FunctionBodyDecoderTest, If_incomplete2) { byte code[] = {kExprI32Const, 0, kExprIf, kExprNop}; - EXPECT_FAILURE_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); + ExpectFailure(sigs.v_v(), code); + ExpectFailure(sigs.i_i(), code); } TEST_F(FunctionBodyDecoderTest, If_else_else) { byte code[] = {kExprI32Const, 0, WASM_IF_OP, kExprElse, kExprElse, kExprEnd}; - EXPECT_FAILURE_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); + ExpectFailure(sigs.v_v(), code); + ExpectFailure(sigs.i_i(), code); } TEST_F(FunctionBodyDecoderTest, IfEmpty) { - EXPECT_VERIFIES(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprEnd); + ExpectValidates(sigs.v_i(), {kExprGetLocal, 0, WASM_IF_OP, kExprEnd}); } TEST_F(FunctionBodyDecoderTest, IfSet) { - EXPECT_VERIFIES(v_i, - WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO))); - EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), - WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); + ExpectValidates(sigs.v_i(), + {WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO))}); + ExpectValidates(sigs.v_i(), + {WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), + WASM_NOP)}); } TEST_F(FunctionBodyDecoderTest, IfElseEmpty) { - EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), WASM_IF_OP, kExprElse, kExprEnd); - EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); + ExpectValidates(sigs.v_i(), + {WASM_GET_LOCAL(0), WASM_IF_OP, kExprElse, kExprEnd}); + ExpectValidates(sigs.v_i(), + {WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)}); } TEST_F(FunctionBodyDecoderTest, IfElseUnreachable1) { - EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, - WASM_GET_LOCAL(0))); - EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), - WASM_UNREACHABLE)); + ExpectValidates( + sigs.i_i(), + {WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))}); + ExpectValidates( + sigs.i_i(), + {WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE)}); } TEST_F(FunctionBodyDecoderTest, IfElseUnreachable2) { @@ -788,247 +798,258 @@ TEST_F(FunctionBodyDecoderTest, IfElseUnreachable2) { ValueType types[] = {kWasmI32, kValueTypes[i]}; FunctionSig sig(1, 1, types); - if (kValueTypes[i] == kWasmI32) { - EXPECT_VERIFIES_SC(&sig, code); - } else { - EXPECT_FAILURE_SC(&sig, code); - } + Validate(kValueTypes[i] == kWasmI32, &sig, code); } } TEST_F(FunctionBodyDecoderTest, OneArmedIfWithArity) { static const byte code[] = {WASM_ZERO, kExprIf, kLocalI32, WASM_ONE, kExprEnd}; - EXPECT_FAILURE_C(i_v, code, - "start-arity and end-arity of one-armed if must match"); + ExpectFailure(sigs.i_v(), code, kAppendEnd, + "start-arity and end-arity of one-armed if must match"); } TEST_F(FunctionBodyDecoderTest, IfBreak) { - EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(0))); - EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(1))); - EXPECT_FAILURE(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2))); + ExpectValidates(sigs.v_i(), {WASM_IF(WASM_GET_LOCAL(0), WASM_BR(0))}); + ExpectValidates(sigs.v_i(), {WASM_IF(WASM_GET_LOCAL(0), WASM_BR(1))}); + ExpectFailure(sigs.v_i(), {WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2))}); } TEST_F(FunctionBodyDecoderTest, IfElseBreak) { - EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(0))); - EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(1))); - EXPECT_FAILURE(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(2))); + ExpectValidates(sigs.v_i(), + {WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(0))}); + ExpectValidates(sigs.v_i(), + {WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(1))}); + ExpectFailure(sigs.v_i(), + {WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(2))}); } TEST_F(FunctionBodyDecoderTest, Block_else) { byte code[] = {kExprI32Const, 0, kExprBlock, kExprElse, kExprEnd}; - EXPECT_FAILURE_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); + ExpectFailure(sigs.v_v(), code); + ExpectFailure(sigs.i_i(), code); } TEST_F(FunctionBodyDecoderTest, IfNop) { - EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); - EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); + ExpectValidates(sigs.v_i(), {WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)}); + ExpectValidates(sigs.v_i(), + {WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)}); } TEST_F(FunctionBodyDecoderTest, If_end) { - EXPECT_VERIFIES(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprEnd); - EXPECT_FAILURE(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprEnd, kExprEnd); + ExpectValidates(sigs.v_i(), {kExprGetLocal, 0, WASM_IF_OP, kExprEnd}); + ExpectFailure(sigs.v_i(), {kExprGetLocal, 0, WASM_IF_OP, kExprEnd, kExprEnd}); } TEST_F(FunctionBodyDecoderTest, If_falloff1) { - EXPECT_FAILURE(v_i, kExprGetLocal, 0, kExprIf); - EXPECT_FAILURE(v_i, kExprGetLocal, 0, WASM_IF_OP); - EXPECT_FAILURE(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprNop, kExprElse); + ExpectFailure(sigs.v_i(), {kExprGetLocal, 0, kExprIf}); + ExpectFailure(sigs.v_i(), {kExprGetLocal, 0, WASM_IF_OP}); + ExpectFailure(sigs.v_i(), + {kExprGetLocal, 0, WASM_IF_OP, kExprNop, kExprElse}); } TEST_F(FunctionBodyDecoderTest, IfElseNop) { - EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), - WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); + ExpectValidates(sigs.v_i(), + {WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), + WASM_NOP)}); } TEST_F(FunctionBodyDecoderTest, IfBlock1) { - EXPECT_VERIFIES( - v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), B1(WASM_SET_LOCAL(0, WASM_ZERO)), - WASM_NOP)); + ExpectValidates(sigs.v_i(), + {WASM_IF_ELSE(WASM_GET_LOCAL(0), + B1(WASM_SET_LOCAL(0, WASM_ZERO)), WASM_NOP)}); } TEST_F(FunctionBodyDecoderTest, IfBlock1b) { - EXPECT_VERIFIES(v_i, - WASM_IF(WASM_GET_LOCAL(0), B1(WASM_SET_LOCAL(0, WASM_ZERO)))); + ExpectValidates(sigs.v_i(), {WASM_IF(WASM_GET_LOCAL(0), + B1(WASM_SET_LOCAL(0, WASM_ZERO)))}); } TEST_F(FunctionBodyDecoderTest, IfBlock2a) { - EXPECT_VERIFIES(v_i, - WASM_IF(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO), - WASM_SET_LOCAL(0, WASM_ZERO)))); + ExpectValidates(sigs.v_i(), {WASM_IF(WASM_GET_LOCAL(0), + B2(WASM_SET_LOCAL(0, WASM_ZERO), + WASM_SET_LOCAL(0, WASM_ZERO)))}); } TEST_F(FunctionBodyDecoderTest, IfBlock2b) { - EXPECT_VERIFIES( - v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO), - WASM_SET_LOCAL(0, WASM_ZERO)), - WASM_NOP)); + ExpectValidates(sigs.v_i(), {WASM_IF_ELSE(WASM_GET_LOCAL(0), + B2(WASM_SET_LOCAL(0, WASM_ZERO), + WASM_SET_LOCAL(0, WASM_ZERO)), + WASM_NOP)}); } TEST_F(FunctionBodyDecoderTest, IfElseSet) { - EXPECT_VERIFIES(v_i, - WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), - WASM_SET_LOCAL(0, WASM_I32V_1(1)))); + ExpectValidates(sigs.v_i(), + {WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), + WASM_SET_LOCAL(0, WASM_I32V_1(1)))}); } TEST_F(FunctionBodyDecoderTest, Loop0) { - EXPECT_VERIFIES(v_v, WASM_LOOP_OP, kExprEnd); + ExpectValidates(sigs.v_v(), {WASM_LOOP_OP, kExprEnd}); } TEST_F(FunctionBodyDecoderTest, Loop1) { static const byte code[] = {WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO))}; - EXPECT_VERIFIES_C(v_i, code); - EXPECT_FAILURE_C(v_v, code); - EXPECT_FAILURE_C(f_ff, code); + ExpectValidates(sigs.v_i(), code); + ExpectFailure(sigs.v_v(), code); + ExpectFailure(sigs.f_ff(), code); } TEST_F(FunctionBodyDecoderTest, Loop2) { - EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), - WASM_SET_LOCAL(0, WASM_ZERO))); + ExpectValidates(sigs.v_i(), {WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), + WASM_SET_LOCAL(0, WASM_ZERO))}); } TEST_F(FunctionBodyDecoderTest, Loop1_continue) { - EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); + ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_BR(0))}); } TEST_F(FunctionBodyDecoderTest, Loop1_break) { - EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(1))); + ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_BR(1))}); } TEST_F(FunctionBodyDecoderTest, Loop2_continue) { - EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0))); + ExpectValidates(sigs.v_i(), + {WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0))}); } TEST_F(FunctionBodyDecoderTest, Loop2_break) { - EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1))); + ExpectValidates(sigs.v_i(), + {WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1))}); } TEST_F(FunctionBodyDecoderTest, InfiniteLoop1) { - EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0)), WASM_ZERO); - EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0)), WASM_ZERO); - EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_BRV(1, WASM_ZERO))); + ExpectValidates(sigs.i_i(), {WASM_LOOP(WASM_BR(0)), WASM_ZERO}); + ExpectValidates(sigs.i_i(), {WASM_LOOP(WASM_BR(0)), WASM_ZERO}); + ExpectValidates(sigs.i_i(), {WASM_LOOP_I(WASM_BRV(1, WASM_ZERO))}); } TEST_F(FunctionBodyDecoderTest, InfiniteLoop2) { - EXPECT_FAILURE(i_i, WASM_LOOP(WASM_BR(0), WASM_ZERO), WASM_ZERO); + ExpectFailure(sigs.i_i(), {WASM_LOOP(WASM_BR(0), WASM_ZERO), WASM_ZERO}); } TEST_F(FunctionBodyDecoderTest, Loop2_unreachable) { - EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_BR(0), WASM_NOP)); + ExpectValidates(sigs.i_i(), {WASM_LOOP_I(WASM_BR(0), WASM_NOP)}); } TEST_F(FunctionBodyDecoderTest, LoopType) { - EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_GET_LOCAL(0))); - EXPECT_VERIFIES(l_l, WASM_LOOP_L(WASM_GET_LOCAL(0))); - EXPECT_VERIFIES(f_f, WASM_LOOP_F(WASM_GET_LOCAL(0))); - EXPECT_VERIFIES(d_d, WASM_LOOP_D(WASM_GET_LOCAL(0))); + ExpectValidates(sigs.i_i(), {WASM_LOOP_I(WASM_GET_LOCAL(0))}); + ExpectValidates(sigs.l_l(), {WASM_LOOP_L(WASM_GET_LOCAL(0))}); + ExpectValidates(sigs.f_f(), {WASM_LOOP_F(WASM_GET_LOCAL(0))}); + ExpectValidates(sigs.d_d(), {WASM_LOOP_D(WASM_GET_LOCAL(0))}); } TEST_F(FunctionBodyDecoderTest, LoopType_void) { - EXPECT_FAILURE(v_v, WASM_LOOP_I(WASM_ZERO)); - EXPECT_FAILURE(v_v, WASM_LOOP_L(WASM_I64V_1(0))); - EXPECT_FAILURE(v_v, WASM_LOOP_F(WASM_F32(0.0))); - EXPECT_FAILURE(v_v, WASM_LOOP_D(WASM_F64(1.1))); + ExpectFailure(sigs.v_v(), {WASM_LOOP_I(WASM_ZERO)}); + ExpectFailure(sigs.v_v(), {WASM_LOOP_L(WASM_I64V_1(0))}); + ExpectFailure(sigs.v_v(), {WASM_LOOP_F(WASM_F32(0.0))}); + ExpectFailure(sigs.v_v(), {WASM_LOOP_D(WASM_F64(1.1))}); } TEST_F(FunctionBodyDecoderTest, LoopType_fail) { - EXPECT_FAILURE(i_i, WASM_LOOP_L(WASM_I64V_1(0))); - EXPECT_FAILURE(i_i, WASM_LOOP_F(WASM_F32(0.0))); - EXPECT_FAILURE(i_i, WASM_LOOP_D(WASM_F64(1.1))); + ExpectFailure(sigs.i_i(), {WASM_LOOP_L(WASM_I64V_1(0))}); + ExpectFailure(sigs.i_i(), {WASM_LOOP_F(WASM_F32(0.0))}); + ExpectFailure(sigs.i_i(), {WASM_LOOP_D(WASM_F64(1.1))}); - EXPECT_FAILURE(l_l, WASM_LOOP_I(WASM_ZERO)); - EXPECT_FAILURE(l_l, WASM_LOOP_F(WASM_F32(0.0))); - EXPECT_FAILURE(l_l, WASM_LOOP_D(WASM_F64(1.1))); + ExpectFailure(sigs.l_l(), {WASM_LOOP_I(WASM_ZERO)}); + ExpectFailure(sigs.l_l(), {WASM_LOOP_F(WASM_F32(0.0))}); + ExpectFailure(sigs.l_l(), {WASM_LOOP_D(WASM_F64(1.1))}); - EXPECT_FAILURE(f_ff, WASM_LOOP_I(WASM_ZERO)); - EXPECT_FAILURE(f_ff, WASM_LOOP_L(WASM_I64V_1(0))); - EXPECT_FAILURE(f_ff, WASM_LOOP_D(WASM_F64(1.1))); + ExpectFailure(sigs.f_ff(), {WASM_LOOP_I(WASM_ZERO)}); + ExpectFailure(sigs.f_ff(), {WASM_LOOP_L(WASM_I64V_1(0))}); + ExpectFailure(sigs.f_ff(), {WASM_LOOP_D(WASM_F64(1.1))}); - EXPECT_FAILURE(d_dd, WASM_LOOP_I(WASM_ZERO)); - EXPECT_FAILURE(d_dd, WASM_LOOP_L(WASM_I64V_1(0))); - EXPECT_FAILURE(d_dd, WASM_LOOP_F(WASM_F32(0.0))); + ExpectFailure(sigs.d_dd(), {WASM_LOOP_I(WASM_ZERO)}); + ExpectFailure(sigs.d_dd(), {WASM_LOOP_L(WASM_I64V_1(0))}); + ExpectFailure(sigs.d_dd(), {WASM_LOOP_F(WASM_F32(0.0))}); } TEST_F(FunctionBodyDecoderTest, ReturnVoid1) { static const byte code[] = {kExprNop}; - EXPECT_VERIFIES_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); - EXPECT_FAILURE_C(i_f, code); + ExpectValidates(sigs.v_v(), code); + ExpectFailure(sigs.i_i(), code); + ExpectFailure(sigs.i_f(), code); } TEST_F(FunctionBodyDecoderTest, ReturnVoid2) { static const byte code[] = {WASM_BLOCK(WASM_BR(0))}; - EXPECT_VERIFIES_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); - EXPECT_FAILURE_C(i_f, code); + ExpectValidates(sigs.v_v(), code); + ExpectFailure(sigs.i_i(), code); + ExpectFailure(sigs.i_f(), code); } TEST_F(FunctionBodyDecoderTest, ReturnVoid3) { - EXPECT_FAILURE(v_v, kExprI32Const, 0); - EXPECT_FAILURE(v_v, kExprI64Const, 0); - EXPECT_FAILURE(v_v, kExprF32Const, 0, 0, 0, 0); - EXPECT_FAILURE(v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0); - EXPECT_FAILURE(v_v, kExprRefNull); + ExpectFailure(sigs.v_v(), {kExprI32Const, 0}); + ExpectFailure(sigs.v_v(), {kExprI64Const, 0}); + ExpectFailure(sigs.v_v(), {kExprF32Const, 0, 0, 0, 0}); + ExpectFailure(sigs.v_v(), {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0}); + ExpectFailure(sigs.v_v(), {kExprRefNull}); - EXPECT_FAILURE(v_i, kExprGetLocal, 0); + ExpectFailure(sigs.v_i(), {kExprGetLocal, 0}); } TEST_F(FunctionBodyDecoderTest, Unreachable1) { - EXPECT_VERIFIES(v_v, WASM_UNREACHABLE); - EXPECT_VERIFIES(v_v, WASM_UNREACHABLE, WASM_UNREACHABLE); - EXPECT_VERIFIES(i_i, WASM_UNREACHABLE, WASM_ZERO); + ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE}); + ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_UNREACHABLE}); + ExpectValidates(sigs.i_i(), {WASM_UNREACHABLE, WASM_ZERO}); } TEST_F(FunctionBodyDecoderTest, Unreachable2) { - EXPECT_FAILURE(v_v, B2(WASM_UNREACHABLE, WASM_ZERO)); - EXPECT_FAILURE(v_v, B2(WASM_BR(0), WASM_ZERO)); + ExpectFailure(sigs.v_v(), {B2(WASM_UNREACHABLE, WASM_ZERO)}); + ExpectFailure(sigs.v_v(), {B2(WASM_BR(0), WASM_ZERO)}); } TEST_F(FunctionBodyDecoderTest, UnreachableLoop1) { - EXPECT_FAILURE(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO)); - EXPECT_FAILURE(v_v, WASM_LOOP(WASM_BR(0), WASM_ZERO)); - EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_NOP)); - EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0), WASM_NOP)); + ExpectFailure(sigs.v_v(), {WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO)}); + ExpectFailure(sigs.v_v(), {WASM_LOOP(WASM_BR(0), WASM_ZERO)}); + ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_UNREACHABLE, WASM_NOP)}); + ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_BR(0), WASM_NOP)}); } TEST_F(FunctionBodyDecoderTest, Unreachable_binop1) { - EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE)); - EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO)); + ExpectValidates(sigs.i_i(), {WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE)}); + ExpectValidates(sigs.i_i(), {WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO)}); } TEST_F(FunctionBodyDecoderTest, Unreachable_binop2) { - EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_F32(0.0), WASM_UNREACHABLE)); - EXPECT_FAILURE(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_F32(0.0))); + ExpectValidates(sigs.i_i(), {WASM_I32_AND(WASM_F32(0.0), WASM_UNREACHABLE)}); + ExpectFailure(sigs.i_i(), {WASM_I32_AND(WASM_UNREACHABLE, WASM_F32(0.0))}); } TEST_F(FunctionBodyDecoderTest, Unreachable_select1) { - EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO)); - EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO)); - EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE)); + ExpectValidates(sigs.i_i(), + {WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO)}); + ExpectValidates(sigs.i_i(), + {WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO)}); + ExpectValidates(sigs.i_i(), + {WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE)}); } TEST_F(FunctionBodyDecoderTest, Unreachable_select2) { - EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_F32(0.0), WASM_UNREACHABLE, WASM_ZERO)); - EXPECT_FAILURE(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_F32(0.0), WASM_ZERO)); - EXPECT_FAILURE(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_F32(0.0))); + ExpectValidates(sigs.i_i(), + {WASM_SELECT(WASM_F32(0.0), WASM_UNREACHABLE, WASM_ZERO)}); + ExpectFailure(sigs.i_i(), + {WASM_SELECT(WASM_UNREACHABLE, WASM_F32(0.0), WASM_ZERO)}); + ExpectFailure(sigs.i_i(), + {WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_F32(0.0))}); } TEST_F(FunctionBodyDecoderTest, If1) { - EXPECT_VERIFIES( - i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), WASM_I32V_1(8))); - EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), - WASM_GET_LOCAL(0))); - EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), - WASM_I32V_1(8))); + ExpectValidates(sigs.i_i(), {WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), + WASM_I32V_1(8))}); + ExpectValidates(sigs.i_i(), {WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), + WASM_GET_LOCAL(0))}); + ExpectValidates( + sigs.i_i(), + {WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_I32V_1(8))}); } TEST_F(FunctionBodyDecoderTest, If_off_end) { static const byte kCode[] = { WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))}; for (size_t len = 3; len < arraysize(kCode); len++) { - Verify(false, sigs.i_i(), {kCode, len}, kAppendEnd); - Verify(false, sigs.i_i(), {kCode, len}, kOmitEnd); + ExpectFailure(sigs.i_i(), VectorOf(kCode, len), kAppendEnd); + ExpectFailure(sigs.i_i(), VectorOf(kCode, len), kOmitEnd); } } @@ -1036,56 +1057,56 @@ TEST_F(FunctionBodyDecoderTest, If_type1) { // float|double ? 1 : 2 static const byte kCode[] = { WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(0), WASM_I32V_1(2))}; - EXPECT_VERIFIES_C(i_i, kCode); - EXPECT_FAILURE_C(i_f, kCode); - EXPECT_FAILURE_C(i_d, kCode); + ExpectValidates(sigs.i_i(), kCode); + ExpectFailure(sigs.i_f(), kCode); + ExpectFailure(sigs.i_d(), kCode); } TEST_F(FunctionBodyDecoderTest, If_type2) { // 1 ? float|double : 2 static const byte kCode[] = { WASM_IF_ELSE_I(WASM_I32V_1(1), WASM_GET_LOCAL(0), WASM_I32V_1(1))}; - EXPECT_VERIFIES_C(i_i, kCode); - EXPECT_FAILURE_C(i_f, kCode); - EXPECT_FAILURE_C(i_d, kCode); + ExpectValidates(sigs.i_i(), kCode); + ExpectFailure(sigs.i_f(), kCode); + ExpectFailure(sigs.i_d(), kCode); } TEST_F(FunctionBodyDecoderTest, If_type3) { // stmt ? 0 : 1 static const byte kCode[] = { WASM_IF_ELSE_I(WASM_NOP, WASM_I32V_1(0), WASM_I32V_1(1))}; - EXPECT_FAILURE_C(i_i, kCode); - EXPECT_FAILURE_C(i_f, kCode); - EXPECT_FAILURE_C(i_d, kCode); + ExpectFailure(sigs.i_i(), kCode); + ExpectFailure(sigs.i_f(), kCode); + ExpectFailure(sigs.i_d(), kCode); } TEST_F(FunctionBodyDecoderTest, If_type4) { // 0 ? stmt : 1 static const byte kCode[] = { WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_NOP, WASM_I32V_1(1))}; - EXPECT_FAILURE_C(i_i, kCode); - EXPECT_FAILURE_C(i_f, kCode); - EXPECT_FAILURE_C(i_d, kCode); + ExpectFailure(sigs.i_i(), kCode); + ExpectFailure(sigs.i_f(), kCode); + ExpectFailure(sigs.i_d(), kCode); } TEST_F(FunctionBodyDecoderTest, If_type5) { // 0 ? 1 : stmt static const byte kCode[] = { WASM_IF_ELSE_I(WASM_ZERO, WASM_I32V_1(1), WASM_NOP)}; - EXPECT_FAILURE_C(i_i, kCode); - EXPECT_FAILURE_C(i_f, kCode); - EXPECT_FAILURE_C(i_d, kCode); + ExpectFailure(sigs.i_i(), kCode); + ExpectFailure(sigs.i_f(), kCode); + ExpectFailure(sigs.i_d(), kCode); } TEST_F(FunctionBodyDecoderTest, Int64Local_param) { - EXPECT_VERIFIES_C(l_l, kCodeGetLocal0); + ExpectValidates(sigs.l_l(), kCodeGetLocal0); } TEST_F(FunctionBodyDecoderTest, Int64Locals) { for (byte i = 1; i < 8; i++) { AddLocals(kWasmI64, 1); for (byte j = 0; j < i; j++) { - EXPECT_VERIFIES(l_v, WASM_GET_LOCAL(j)); + ExpectValidates(sigs.l_v(), {WASM_GET_LOCAL(j)}); } } } @@ -1150,47 +1171,49 @@ TEST_F(FunctionBodyDecoderTest, MacrosStmt) { TestModuleBuilder builder; module = builder.module(); builder.InitializeMemory(); - EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348))); - EXPECT_VERIFIES(v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V_1(24), - WASM_I32V_1(40))); - EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); - EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); - EXPECT_VERIFIES(v_v, WASM_NOP); - EXPECT_VERIFIES(v_v, B1(WASM_NOP)); - EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP)); - EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); + ExpectValidates(sigs.v_i(), {WASM_SET_LOCAL(0, WASM_I32V_3(87348))}); + ExpectValidates( + sigs.v_i(), + {WASM_STORE_MEM(MachineType::Int32(), WASM_I32V_1(24), WASM_I32V_1(40))}); + ExpectValidates(sigs.v_i(), {WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)}); + ExpectValidates(sigs.v_i(), + {WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)}); + ExpectValidates(sigs.v_v(), {WASM_NOP}); + ExpectValidates(sigs.v_v(), {B1(WASM_NOP)}); + ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_NOP)}); + ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_BR(0))}); } TEST_F(FunctionBodyDecoderTest, MacrosContinue) { - EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_CONTINUE(0))); + ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_CONTINUE(0))}); } TEST_F(FunctionBodyDecoderTest, MacrosVariadic) { - EXPECT_VERIFIES(v_v, B2(WASM_NOP, WASM_NOP)); - EXPECT_VERIFIES(v_v, B3(WASM_NOP, WASM_NOP, WASM_NOP)); - EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_NOP)); - EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_NOP, WASM_NOP)); + ExpectValidates(sigs.v_v(), {B2(WASM_NOP, WASM_NOP)}); + ExpectValidates(sigs.v_v(), {B3(WASM_NOP, WASM_NOP, WASM_NOP)}); + ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_NOP, WASM_NOP)}); + ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_NOP, WASM_NOP, WASM_NOP)}); } TEST_F(FunctionBodyDecoderTest, MacrosNestedBlocks) { - EXPECT_VERIFIES(v_v, B2(WASM_NOP, B2(WASM_NOP, WASM_NOP))); - EXPECT_VERIFIES(v_v, B3(WASM_NOP, // -- - B2(WASM_NOP, WASM_NOP), // -- - B2(WASM_NOP, WASM_NOP))); // -- - EXPECT_VERIFIES(v_v, B1(B1(B2(WASM_NOP, WASM_NOP)))); + ExpectValidates(sigs.v_v(), {B2(WASM_NOP, B2(WASM_NOP, WASM_NOP))}); + ExpectValidates(sigs.v_v(), {B3(WASM_NOP, // -- + B2(WASM_NOP, WASM_NOP), // -- + B2(WASM_NOP, WASM_NOP))}); // -- + ExpectValidates(sigs.v_v(), {B1(B1(B2(WASM_NOP, WASM_NOP)))}); } TEST_F(FunctionBodyDecoderTest, MultipleReturn) { static ValueType kIntTypes5[] = {kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32}; FunctionSig sig_ii_v(2, 0, kIntTypes5); - EXPECT_VERIFIES_S(&sig_ii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); - EXPECT_FAILURE_S(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO)); + ExpectValidates(&sig_ii_v, {WASM_RETURNN(2, WASM_ZERO, WASM_ONE)}); + ExpectFailure(&sig_ii_v, {WASM_RETURNN(1, WASM_ZERO)}); FunctionSig sig_iii_v(3, 0, kIntTypes5); - EXPECT_VERIFIES_S(&sig_iii_v, - WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I32V_1(44))); - EXPECT_FAILURE_S(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); + ExpectValidates(&sig_iii_v, + {WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I32V_1(44))}); + ExpectFailure(&sig_iii_v, {WASM_RETURNN(2, WASM_ZERO, WASM_ONE)}); } TEST_F(FunctionBodyDecoderTest, MultipleReturn_fallthru) { @@ -1198,74 +1221,124 @@ TEST_F(FunctionBodyDecoderTest, MultipleReturn_fallthru) { kWasmI32}; FunctionSig sig_ii_v(2, 0, kIntTypes5); - EXPECT_VERIFIES_S(&sig_ii_v, WASM_ZERO, WASM_ONE); - EXPECT_FAILURE_S(&sig_ii_v, WASM_ZERO); + ExpectValidates(&sig_ii_v, {WASM_ZERO, WASM_ONE}); + ExpectFailure(&sig_ii_v, {WASM_ZERO}); FunctionSig sig_iii_v(3, 0, kIntTypes5); - EXPECT_VERIFIES_S(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I32V_1(44)); - EXPECT_FAILURE_S(&sig_iii_v, WASM_ZERO, WASM_ONE); + ExpectValidates(&sig_iii_v, {WASM_ZERO, WASM_ONE, WASM_I32V_1(44)}); + ExpectFailure(&sig_iii_v, {WASM_ZERO, WASM_ONE}); } TEST_F(FunctionBodyDecoderTest, MacrosInt32) { - EXPECT_VERIFIES(i_i, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V_1(12))); - EXPECT_VERIFIES(i_i, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(13))); - EXPECT_VERIFIES(i_i, WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I32V_1(14))); - EXPECT_VERIFIES(i_i, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(15))); - EXPECT_VERIFIES(i_i, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(16))); - EXPECT_VERIFIES(i_i, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I32V_1(17))); - EXPECT_VERIFIES(i_i, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I32V_1(18))); - EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I32V_1(19))); - EXPECT_VERIFIES(i_i, WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I32V_1(20))); - EXPECT_VERIFIES(i_i, WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I32V_1(21))); - EXPECT_VERIFIES(i_i, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I32V_1(22))); - EXPECT_VERIFIES(i_i, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I32V_1(23))); - EXPECT_VERIFIES(i_i, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I32V_1(24))); - EXPECT_VERIFIES(i_i, WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I32V_1(24))); - EXPECT_VERIFIES(i_i, WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I32V_1(24))); - EXPECT_VERIFIES(i_i, WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(25))); - EXPECT_VERIFIES(i_i, WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I32V_1(25))); - - EXPECT_VERIFIES(i_i, WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I32V_1(26))); - EXPECT_VERIFIES(i_i, WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I32V_1(27))); - EXPECT_VERIFIES(i_i, WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I32V_1(28))); - EXPECT_VERIFIES(i_i, WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I32V_1(29))); - - EXPECT_VERIFIES(i_i, WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I32V_1(26))); - EXPECT_VERIFIES(i_i, WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I32V_1(27))); - EXPECT_VERIFIES(i_i, WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I32V_1(28))); - EXPECT_VERIFIES(i_i, WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I32V_1(29))); + ExpectValidates(sigs.i_i(), + {WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V_1(12))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(13))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I32V_1(14))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(15))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(16))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I32V_1(17))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I32V_1(18))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I32V_1(19))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I32V_1(20))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I32V_1(21))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I32V_1(22))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I32V_1(23))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I32V_1(24))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I32V_1(24))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I32V_1(24))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(25))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I32V_1(25))}); + + ExpectValidates(sigs.i_i(), + {WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I32V_1(26))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I32V_1(27))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I32V_1(28))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I32V_1(29))}); + + ExpectValidates(sigs.i_i(), + {WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I32V_1(26))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I32V_1(27))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I32V_1(28))}); + ExpectValidates(sigs.i_i(), + {WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I32V_1(29))}); } TEST_F(FunctionBodyDecoderTest, MacrosInt64) { - EXPECT_VERIFIES(l_ll, WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12))); - EXPECT_VERIFIES(l_ll, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13))); - EXPECT_VERIFIES(l_ll, WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14))); - EXPECT_VERIFIES(l_ll, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15))); - EXPECT_VERIFIES(l_ll, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16))); - EXPECT_VERIFIES(l_ll, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17))); - EXPECT_VERIFIES(l_ll, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18))); - EXPECT_VERIFIES(l_ll, WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64V_1(19))); - EXPECT_VERIFIES(l_ll, WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64V_1(20))); - EXPECT_VERIFIES(l_ll, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64V_1(21))); - - EXPECT_VERIFIES(l_ll, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(22))); - EXPECT_VERIFIES(l_ll, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(23))); - EXPECT_VERIFIES(l_ll, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(24))); - EXPECT_VERIFIES(l_ll, WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_I64V_1(24))); - EXPECT_VERIFIES(l_ll, WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_I64V_1(24))); - - EXPECT_VERIFIES(i_ll, WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))); - EXPECT_VERIFIES(i_ll, WASM_I64_LES(WASM_GET_LOCAL(0), WASM_I64V_1(27))); - EXPECT_VERIFIES(i_ll, WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))); - EXPECT_VERIFIES(i_ll, WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))); - - EXPECT_VERIFIES(i_ll, WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))); - EXPECT_VERIFIES(i_ll, WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64V_1(27))); - EXPECT_VERIFIES(i_ll, WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))); - EXPECT_VERIFIES(i_ll, WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))); - - EXPECT_VERIFIES(i_ll, WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64V_1(25))); - EXPECT_VERIFIES(i_ll, WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64V_1(25))); + ExpectValidates(sigs.l_ll(), + {WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12))}); + ExpectValidates(sigs.l_ll(), + {WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13))}); + ExpectValidates(sigs.l_ll(), + {WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14))}); + ExpectValidates(sigs.l_ll(), + {WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15))}); + ExpectValidates(sigs.l_ll(), + {WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16))}); + ExpectValidates(sigs.l_ll(), + {WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17))}); + ExpectValidates(sigs.l_ll(), + {WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18))}); + ExpectValidates(sigs.l_ll(), + {WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64V_1(19))}); + ExpectValidates(sigs.l_ll(), + {WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64V_1(20))}); + ExpectValidates(sigs.l_ll(), + {WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64V_1(21))}); + + ExpectValidates(sigs.l_ll(), + {WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(22))}); + ExpectValidates(sigs.l_ll(), + {WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(23))}); + ExpectValidates(sigs.l_ll(), + {WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(24))}); + ExpectValidates(sigs.l_ll(), + {WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_I64V_1(24))}); + ExpectValidates(sigs.l_ll(), + {WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_I64V_1(24))}); + + ExpectValidates(sigs.i_ll(), + {WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))}); + ExpectValidates(sigs.i_ll(), + {WASM_I64_LES(WASM_GET_LOCAL(0), WASM_I64V_1(27))}); + ExpectValidates(sigs.i_ll(), + {WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))}); + ExpectValidates(sigs.i_ll(), + {WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))}); + + ExpectValidates(sigs.i_ll(), + {WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))}); + ExpectValidates(sigs.i_ll(), + {WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64V_1(27))}); + ExpectValidates(sigs.i_ll(), + {WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))}); + ExpectValidates(sigs.i_ll(), + {WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))}); + + ExpectValidates(sigs.i_ll(), + {WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64V_1(25))}); + ExpectValidates(sigs.i_ll(), + {WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64V_1(25))}); } TEST_F(FunctionBodyDecoderTest, AllSimpleExpressions) { @@ -1292,8 +1365,8 @@ TEST_F(FunctionBodyDecoderTest, MemorySize) { module = builder.module(); builder.InitializeMemory(); byte code[] = {kExprMemorySize, 0}; - EXPECT_VERIFIES_C(i_i, code); - EXPECT_FAILURE_C(f_ff, code); + ExpectValidates(sigs.i_i(), code); + ExpectFailure(sigs.f_ff(), code); } TEST_F(FunctionBodyDecoderTest, LoadMemOffset) { @@ -1303,7 +1376,7 @@ TEST_F(FunctionBodyDecoderTest, LoadMemOffset) { for (int offset = 0; offset < 128; offset += 7) { byte code[] = {kExprI32Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT, static_cast<byte>(offset)}; - EXPECT_VERIFIES_C(i_i, code); + ExpectValidates(sigs.i_i(), code); } } @@ -1335,11 +1408,7 @@ TEST_F(FunctionBodyDecoderTest, LoadMemAlignment) { for (byte alignment = 0; alignment <= 4; alignment++) { byte code[] = {WASM_ZERO, static_cast<byte>(values[i].instruction), alignment, ZERO_OFFSET, WASM_DROP}; - if (static_cast<uint32_t>(alignment) <= values[i].maximum_aligment) { - EXPECT_VERIFIES_C(v_i, code); - } else { - EXPECT_FAILURE_C(v_i, code); - } + Validate(alignment <= values[i].maximum_aligment, sigs.v_i(), code); } } } @@ -1351,7 +1420,7 @@ TEST_F(FunctionBodyDecoderTest, StoreMemOffset) { for (byte offset = 0; offset < 128; offset += 7) { byte code[] = {WASM_STORE_MEM_OFFSET(MachineType::Int32(), offset, WASM_ZERO, WASM_ZERO)}; - EXPECT_VERIFIES_C(v_i, code); + ExpectValidates(sigs.v_i(), code); } } @@ -1359,8 +1428,8 @@ TEST_F(FunctionBodyDecoderTest, StoreMemOffset_void) { TestModuleBuilder builder; module = builder.module(); builder.InitializeMemory(); - EXPECT_FAILURE(i_i, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 0, WASM_ZERO, - WASM_ZERO)); + ExpectFailure(sigs.i_i(), {WASM_STORE_MEM_OFFSET(MachineType::Int32(), 0, + WASM_ZERO, WASM_ZERO)}); } #define BYTE0(x) ((x)&0x7F) @@ -1377,28 +1446,28 @@ TEST_F(FunctionBodyDecoderTest, LoadMemOffset_varint) { TestModuleBuilder builder; module = builder.module(); builder.InitializeMemory(); - EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, - VARINT1(0x45)); - EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, - VARINT2(0x3999)); - EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, - VARINT3(0x344445)); - EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, - VARINT4(0x36666667)); + ExpectValidates(sigs.i_i(), + {WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, VARINT1(0x45)}); + ExpectValidates(sigs.i_i(), {WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, + VARINT2(0x3999)}); + ExpectValidates(sigs.i_i(), {WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, + VARINT3(0x344445)}); + ExpectValidates(sigs.i_i(), {WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, + VARINT4(0x36666667)}); } TEST_F(FunctionBodyDecoderTest, StoreMemOffset_varint) { TestModuleBuilder builder; module = builder.module(); builder.InitializeMemory(); - EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, - VARINT1(0x33)); - EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, - VARINT2(0x1111)); - EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, - VARINT3(0x222222)); - EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, - VARINT4(0x44444444)); + ExpectValidates(sigs.v_i(), {WASM_ZERO, WASM_ZERO, kExprI32StoreMem, + ZERO_ALIGNMENT, VARINT1(0x33)}); + ExpectValidates(sigs.v_i(), {WASM_ZERO, WASM_ZERO, kExprI32StoreMem, + ZERO_ALIGNMENT, VARINT2(0x1111)}); + ExpectValidates(sigs.v_i(), {WASM_ZERO, WASM_ZERO, kExprI32StoreMem, + ZERO_ALIGNMENT, VARINT3(0x222222)}); + ExpectValidates(sigs.v_i(), {WASM_ZERO, WASM_ZERO, kExprI32StoreMem, + ZERO_ALIGNMENT, VARINT4(0x44444444)}); } #undef BYTE0 @@ -1421,11 +1490,7 @@ TEST_F(FunctionBodyDecoderTest, AllLoadMemCombinations) { MachineType mem_type = machineTypes[j]; byte code[] = {WASM_LOAD_MEM(mem_type, WASM_ZERO)}; FunctionSig sig(1, 0, &local_type); - if (local_type == ValueTypes::ValueTypeFor(mem_type)) { - EXPECT_VERIFIES_SC(&sig, code); - } else { - EXPECT_FAILURE_SC(&sig, code); - } + Validate(local_type == ValueTypes::ValueTypeFor(mem_type), &sig, code); } } } @@ -1440,11 +1505,7 @@ TEST_F(FunctionBodyDecoderTest, AllStoreMemCombinations) { MachineType mem_type = machineTypes[j]; byte code[] = {WASM_STORE_MEM(mem_type, WASM_ZERO, WASM_GET_LOCAL(0))}; FunctionSig sig(0, 1, &local_type); - if (local_type == ValueTypes::ValueTypeFor(mem_type)) { - EXPECT_VERIFIES_SC(&sig, code); - } else { - EXPECT_FAILURE_SC(&sig, code); - } + Validate(local_type == ValueTypes::ValueTypeFor(mem_type), &sig, code); } } } @@ -1458,10 +1519,10 @@ TEST_F(FunctionBodyDecoderTest, SimpleCalls) { builder.AddFunction(sigs.i_i()); builder.AddFunction(sigs.i_ii()); - EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(0)); - EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(1, WASM_I32V_1(27))); - EXPECT_VERIFIES_S(sig, - WASM_CALL_FUNCTION(2, WASM_I32V_1(37), WASM_I32V_2(77))); + ExpectValidates(sig, {WASM_CALL_FUNCTION0(0)}); + ExpectValidates(sig, {WASM_CALL_FUNCTION(1, WASM_I32V_1(27))}); + ExpectValidates(sig, + {WASM_CALL_FUNCTION(2, WASM_I32V_1(37), WASM_I32V_2(77))}); } TEST_F(FunctionBodyDecoderTest, CallsWithTooFewArguments) { @@ -1473,9 +1534,9 @@ TEST_F(FunctionBodyDecoderTest, CallsWithTooFewArguments) { builder.AddFunction(sigs.i_ii()); builder.AddFunction(sigs.f_ff()); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(0)); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_ZERO)); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0))); + ExpectFailure(sig, {WASM_CALL_FUNCTION0(0)}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(1, WASM_ZERO)}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0))}); } TEST_F(FunctionBodyDecoderTest, CallsWithMismatchedSigs2) { @@ -1485,9 +1546,9 @@ TEST_F(FunctionBodyDecoderTest, CallsWithMismatchedSigs2) { builder.AddFunction(sigs.i_i()); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(17))); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F32(17.1))); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(17.1))); + ExpectFailure(sig, {WASM_CALL_FUNCTION(0, WASM_I64V_1(17))}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(0, WASM_F32(17.1))}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(0, WASM_F64(17.1))}); } TEST_F(FunctionBodyDecoderTest, CallsWithMismatchedSigs3) { @@ -1497,15 +1558,167 @@ TEST_F(FunctionBodyDecoderTest, CallsWithMismatchedSigs3) { builder.AddFunction(sigs.i_f()); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I32V_1(17))); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(27))); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(37.2))); + ExpectFailure(sig, {WASM_CALL_FUNCTION(0, WASM_I32V_1(17))}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(0, WASM_I64V_1(27))}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(0, WASM_F64(37.2))}); builder.AddFunction(sigs.i_d()); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I32V_1(16))); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(16))); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6))); + ExpectFailure(sig, {WASM_CALL_FUNCTION(1, WASM_I32V_1(16))}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(1, WASM_I64V_1(16))}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(1, WASM_F32(17.6))}); +} + +TEST_F(FunctionBodyDecoderTest, SimpleReturnCalls) { + WASM_FEATURE_SCOPE(return_call); + + FunctionSig* sig = sigs.i_i(); + TestModuleBuilder builder; + module = builder.module(); + + builder.AddFunction(sigs.i_v()); + builder.AddFunction(sigs.i_i()); + builder.AddFunction(sigs.i_ii()); + + ExpectValidates(sig, {WASM_RETURN_CALL_FUNCTION0(0)}); + ExpectValidates(sig, {WASM_RETURN_CALL_FUNCTION(1, WASM_I32V_1(27))}); + ExpectValidates( + sig, {WASM_RETURN_CALL_FUNCTION(2, WASM_I32V_1(37), WASM_I32V_2(77))}); +} + +TEST_F(FunctionBodyDecoderTest, ReturnCallsWithTooFewArguments) { + WASM_FEATURE_SCOPE(return_call); + + FunctionSig* sig = sigs.i_i(); + TestModuleBuilder builder; + module = builder.module(); + + builder.AddFunction(sigs.i_i()); + builder.AddFunction(sigs.i_ii()); + builder.AddFunction(sigs.f_ff()); + + ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION0(0)}); + ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(1, WASM_ZERO)}); + ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(2, WASM_GET_LOCAL(0))}); +} + +TEST_F(FunctionBodyDecoderTest, ReturnCallsWithMismatchedSigs) { + WASM_FEATURE_SCOPE(return_call); + + FunctionSig* sig = sigs.i_i(); + TestModuleBuilder builder; + module = builder.module(); + + builder.AddFunction(sigs.i_f()); + builder.AddFunction(sigs.f_f()); + + ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(0, WASM_I32V_1(17))}); + ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(0, WASM_I64V_1(27))}); + ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(0, WASM_F64(37.2))}); + + ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(1, WASM_F64(37.2))}); + ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(1, WASM_F32(37.2))}); + ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(1, WASM_I32V_1(17))}); +} + +TEST_F(FunctionBodyDecoderTest, SimpleIndirectReturnCalls) { + WASM_FEATURE_SCOPE(return_call); + + FunctionSig* sig = sigs.i_i(); + TestModuleBuilder builder; + builder.InitializeTable(); + module = builder.module(); + + byte f0 = builder.AddSignature(sigs.i_v()); + byte f1 = builder.AddSignature(sigs.i_i()); + byte f2 = builder.AddSignature(sigs.i_ii()); + + ExpectValidates(sig, {WASM_RETURN_CALL_INDIRECT0(f0, WASM_ZERO)}); + ExpectValidates(sig, + {WASM_RETURN_CALL_INDIRECT(f1, WASM_ZERO, WASM_I32V_1(22))}); + ExpectValidates(sig, {WASM_RETURN_CALL_INDIRECT( + f2, WASM_ZERO, WASM_I32V_1(32), WASM_I32V_2(72))}); +} + +TEST_F(FunctionBodyDecoderTest, IndirectReturnCallsOutOfBounds) { + WASM_FEATURE_SCOPE(return_call); + + FunctionSig* sig = sigs.i_i(); + TestModuleBuilder builder; + builder.InitializeTable(); + module = builder.module(); + + ExpectFailure(sig, {WASM_RETURN_CALL_INDIRECT0(0, WASM_ZERO)}); + builder.AddSignature(sigs.i_v()); + ExpectValidates(sig, {WASM_RETURN_CALL_INDIRECT0(0, WASM_ZERO)}); + + ExpectFailure(sig, + {WASM_RETURN_CALL_INDIRECT(1, WASM_ZERO, WASM_I32V_1(22))}); + builder.AddSignature(sigs.i_i()); + ExpectValidates(sig, + {WASM_RETURN_CALL_INDIRECT(1, WASM_ZERO, WASM_I32V_1(27))}); + + ExpectFailure(sig, + {WASM_RETURN_CALL_INDIRECT(2, WASM_ZERO, WASM_I32V_1(27))}); +} + +TEST_F(FunctionBodyDecoderTest, IndirectReturnCallsWithMismatchedSigs3) { + WASM_FEATURE_SCOPE(return_call); + + FunctionSig* sig = sigs.i_i(); + TestModuleBuilder builder; + builder.InitializeTable(); + module = builder.module(); + + byte f0 = builder.AddFunction(sigs.i_f()); + + ExpectFailure(sig, + {WASM_RETURN_CALL_INDIRECT(f0, WASM_ZERO, WASM_I32V_1(17))}); + ExpectFailure(sig, + {WASM_RETURN_CALL_INDIRECT(f0, WASM_ZERO, WASM_I64V_1(27))}); + ExpectFailure(sig, + {WASM_RETURN_CALL_INDIRECT(f0, WASM_ZERO, WASM_F64(37.2))}); + + ExpectFailure(sig, {WASM_RETURN_CALL_INDIRECT0(f0, WASM_I32V_1(17))}); + ExpectFailure(sig, {WASM_RETURN_CALL_INDIRECT0(f0, WASM_I64V_1(27))}); + ExpectFailure(sig, {WASM_RETURN_CALL_INDIRECT0(f0, WASM_F64(37.2))}); + + byte f1 = builder.AddFunction(sigs.i_d()); + + ExpectFailure(sig, + {WASM_RETURN_CALL_INDIRECT(f1, WASM_ZERO, WASM_I32V_1(16))}); + ExpectFailure(sig, + {WASM_RETURN_CALL_INDIRECT(f1, WASM_ZERO, WASM_I64V_1(16))}); + ExpectFailure(sig, + {WASM_RETURN_CALL_INDIRECT(f1, WASM_ZERO, WASM_F32(17.6))}); +} + +TEST_F(FunctionBodyDecoderTest, IndirectReturnCallsWithoutTableCrash) { + WASM_FEATURE_SCOPE(return_call); + + FunctionSig* sig = sigs.i_i(); + TestModuleBuilder builder; + module = builder.module(); + + byte f0 = builder.AddSignature(sigs.i_v()); + byte f1 = builder.AddSignature(sigs.i_i()); + byte f2 = builder.AddSignature(sigs.i_ii()); + + ExpectFailure(sig, {WASM_RETURN_CALL_INDIRECT0(f0, WASM_ZERO)}); + ExpectFailure(sig, + {WASM_RETURN_CALL_INDIRECT(f1, WASM_ZERO, WASM_I32V_1(22))}); + ExpectFailure(sig, {WASM_RETURN_CALL_INDIRECT(f2, WASM_ZERO, WASM_I32V_1(32), + WASM_I32V_2(72))}); +} + +TEST_F(FunctionBodyDecoderTest, IncompleteIndirectReturnCall) { + FunctionSig* sig = sigs.i_i(); + TestModuleBuilder builder; + builder.InitializeTable(); + module = builder.module(); + + static byte code[] = {kExprReturnCallIndirect}; + ExpectFailure(sig, ArrayVector(code), kOmitEnd); } TEST_F(FunctionBodyDecoderTest, MultiReturn) { @@ -1519,9 +1732,9 @@ TEST_F(FunctionBodyDecoderTest, MultiReturn) { builder.AddFunction(&sig_v_ii); builder.AddFunction(&sig_ii_v); - EXPECT_VERIFIES_S(&sig_ii_v, WASM_CALL_FUNCTION0(1)); - EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), WASM_DROP, WASM_DROP); - EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), kExprCallFunction, 0); + ExpectValidates(&sig_ii_v, {WASM_CALL_FUNCTION0(1)}); + ExpectValidates(sigs.v_v(), {WASM_CALL_FUNCTION0(1), WASM_DROP, WASM_DROP}); + ExpectValidates(sigs.v_v(), {WASM_CALL_FUNCTION0(1), kExprCallFunction, 0}); } TEST_F(FunctionBodyDecoderTest, MultiReturnType) { @@ -1539,12 +1752,12 @@ TEST_F(FunctionBodyDecoderTest, MultiReturnType) { module = builder.module(); builder.AddFunction(&sig_cd_v); - EXPECT_VERIFIES_S(&sig_cd_v, WASM_CALL_FUNCTION0(0)); + ExpectValidates(&sig_cd_v, {WASM_CALL_FUNCTION0(0)}); if (a == c && b == d) { - EXPECT_VERIFIES_S(&sig_ab_v, WASM_CALL_FUNCTION0(0)); + ExpectValidates(&sig_ab_v, {WASM_CALL_FUNCTION0(0)}); } else { - EXPECT_FAILURE_S(&sig_ab_v, WASM_CALL_FUNCTION0(0)); + ExpectFailure(&sig_ab_v, {WASM_CALL_FUNCTION0(0)}); } } } @@ -1562,10 +1775,10 @@ TEST_F(FunctionBodyDecoderTest, SimpleIndirectCalls) { byte f1 = builder.AddSignature(sigs.i_i()); byte f2 = builder.AddSignature(sigs.i_ii()); - EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); - EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I32V_1(22))); - EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I32V_1(32), - WASM_I32V_2(72))); + ExpectValidates(sig, {WASM_CALL_INDIRECT0(f0, WASM_ZERO)}); + ExpectValidates(sig, {WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I32V_1(22))}); + ExpectValidates(sig, {WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I32V_1(32), + WASM_I32V_2(72))}); } TEST_F(FunctionBodyDecoderTest, IndirectCallsOutOfBounds) { @@ -1574,15 +1787,15 @@ TEST_F(FunctionBodyDecoderTest, IndirectCallsOutOfBounds) { builder.InitializeTable(); module = builder.module(); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); + ExpectFailure(sig, {WASM_CALL_INDIRECT0(0, WASM_ZERO)}); builder.AddSignature(sigs.i_v()); - EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); + ExpectValidates(sig, {WASM_CALL_INDIRECT0(0, WASM_ZERO)}); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I32V_1(22))); + ExpectFailure(sig, {WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I32V_1(22))}); builder.AddSignature(sigs.i_i()); - EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I32V_1(27))); + ExpectValidates(sig, {WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I32V_1(27))}); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I32V_1(27))); + ExpectFailure(sig, {WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I32V_1(27))}); } TEST_F(FunctionBodyDecoderTest, IndirectCallsWithMismatchedSigs3) { @@ -1593,19 +1806,19 @@ TEST_F(FunctionBodyDecoderTest, IndirectCallsWithMismatchedSigs3) { byte f0 = builder.AddFunction(sigs.i_f()); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I32V_1(17))); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27))); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2))); + ExpectFailure(sig, {WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I32V_1(17))}); + ExpectFailure(sig, {WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27))}); + ExpectFailure(sig, {WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2))}); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I32V_1(17))); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27))); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); + ExpectFailure(sig, {WASM_CALL_INDIRECT0(f0, WASM_I32V_1(17))}); + ExpectFailure(sig, {WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27))}); + ExpectFailure(sig, {WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))}); byte f1 = builder.AddFunction(sigs.i_d()); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I32V_1(16))); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16))); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6))); + ExpectFailure(sig, {WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I32V_1(16))}); + ExpectFailure(sig, {WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16))}); + ExpectFailure(sig, {WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6))}); } TEST_F(FunctionBodyDecoderTest, IndirectCallsWithoutTableCrash) { @@ -1617,10 +1830,10 @@ TEST_F(FunctionBodyDecoderTest, IndirectCallsWithoutTableCrash) { byte f1 = builder.AddSignature(sigs.i_i()); byte f2 = builder.AddSignature(sigs.i_ii()); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I32V_1(22))); - EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I32V_1(32), - WASM_I32V_2(72))); + ExpectFailure(sig, {WASM_CALL_INDIRECT0(f0, WASM_ZERO)}); + ExpectFailure(sig, {WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I32V_1(22))}); + ExpectFailure(sig, {WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I32V_1(32), + WASM_I32V_2(72))}); } TEST_F(FunctionBodyDecoderTest, IncompleteIndirectCall) { @@ -1630,7 +1843,7 @@ TEST_F(FunctionBodyDecoderTest, IncompleteIndirectCall) { module = builder.module(); static byte code[] = {kExprCallIndirect}; - Verify(false, sig, ArrayVector(code), kOmitEnd); + ExpectFailure(sig, ArrayVector(code), kOmitEnd); } TEST_F(FunctionBodyDecoderTest, IncompleteStore) { @@ -1641,7 +1854,7 @@ TEST_F(FunctionBodyDecoderTest, IncompleteStore) { module = builder.module(); static byte code[] = {kExprI32StoreMem}; - Verify(false, sig, ArrayVector(code), kOmitEnd); + ExpectFailure(sig, ArrayVector(code), kOmitEnd); } TEST_F(FunctionBodyDecoderTest, IncompleteS8x16Shuffle) { @@ -1654,7 +1867,7 @@ TEST_F(FunctionBodyDecoderTest, IncompleteS8x16Shuffle) { static byte code[] = {kSimdPrefix, static_cast<byte>(kExprS8x16Shuffle & 0xff)}; - Verify(false, sig, ArrayVector(code), kOmitEnd); + ExpectFailure(sig, ArrayVector(code), kOmitEnd); } TEST_F(FunctionBodyDecoderTest, SimpleImportCalls) { @@ -1666,10 +1879,10 @@ TEST_F(FunctionBodyDecoderTest, SimpleImportCalls) { byte f1 = builder.AddImport(sigs.i_i()); byte f2 = builder.AddImport(sigs.i_ii()); - EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(f0)); - EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f1, WASM_I32V_1(22))); - EXPECT_VERIFIES_S(sig, - WASM_CALL_FUNCTION(f2, WASM_I32V_1(32), WASM_I32V_2(72))); + ExpectValidates(sig, {WASM_CALL_FUNCTION0(f0)}); + ExpectValidates(sig, {WASM_CALL_FUNCTION(f1, WASM_I32V_1(22))}); + ExpectValidates(sig, + {WASM_CALL_FUNCTION(f2, WASM_I32V_1(32), WASM_I32V_2(72))}); } TEST_F(FunctionBodyDecoderTest, ImportCallsWithMismatchedSigs3) { @@ -1679,17 +1892,17 @@ TEST_F(FunctionBodyDecoderTest, ImportCallsWithMismatchedSigs3) { byte f0 = builder.AddImport(sigs.i_f()); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f0)); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I32V_1(17))); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I64V_1(27))); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_F64(37.2))); + ExpectFailure(sig, {WASM_CALL_FUNCTION0(f0)}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(f0, WASM_I32V_1(17))}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(f0, WASM_I64V_1(27))}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(f0, WASM_F64(37.2))}); byte f1 = builder.AddImport(sigs.i_d()); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f1)); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I32V_1(16))); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I64V_1(16))); - EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_F32(17.6))); + ExpectFailure(sig, {WASM_CALL_FUNCTION0(f1)}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(f1, WASM_I32V_1(16))}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(f1, WASM_I64V_1(16))}); + ExpectFailure(sig, {WASM_CALL_FUNCTION(f1, WASM_F32(17.6))}); } TEST_F(FunctionBodyDecoderTest, Int32Globals) { @@ -1699,9 +1912,9 @@ TEST_F(FunctionBodyDecoderTest, Int32Globals) { builder.AddGlobal(kWasmI32); - EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); - EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); - EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); + ExpectValidates(sig, {WASM_GET_GLOBAL(0)}); + ExpectFailure(sig, {WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))}); + ExpectValidates(sig, {WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO}); } TEST_F(FunctionBodyDecoderTest, ImmutableGlobal) { @@ -1712,8 +1925,8 @@ TEST_F(FunctionBodyDecoderTest, ImmutableGlobal) { uint32_t g0 = builder.AddGlobal(kWasmI32, true); uint32_t g1 = builder.AddGlobal(kWasmI32, false); - EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(g0, WASM_ZERO)); - EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(g1, WASM_ZERO)); + ExpectValidates(sig, {WASM_SET_GLOBAL(g0, WASM_ZERO)}); + ExpectFailure(sig, {WASM_SET_GLOBAL(g1, WASM_ZERO)}); } TEST_F(FunctionBodyDecoderTest, Int32Globals_fail) { @@ -1726,15 +1939,15 @@ TEST_F(FunctionBodyDecoderTest, Int32Globals_fail) { builder.AddGlobal(kWasmF32); builder.AddGlobal(kWasmF64); - EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(0)); - EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(1)); - EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(2)); - EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(3)); + ExpectFailure(sig, {WASM_GET_GLOBAL(0)}); + ExpectFailure(sig, {WASM_GET_GLOBAL(1)}); + ExpectFailure(sig, {WASM_GET_GLOBAL(2)}); + ExpectFailure(sig, {WASM_GET_GLOBAL(3)}); - EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); - EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), WASM_ZERO); - EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(2, WASM_GET_LOCAL(0)), WASM_ZERO); - EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(3, WASM_GET_LOCAL(0)), WASM_ZERO); + ExpectFailure(sig, {WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO}); + ExpectFailure(sig, {WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), WASM_ZERO}); + ExpectFailure(sig, {WASM_SET_GLOBAL(2, WASM_GET_LOCAL(0)), WASM_ZERO}); + ExpectFailure(sig, {WASM_SET_GLOBAL(3, WASM_GET_LOCAL(0)), WASM_ZERO}); } TEST_F(FunctionBodyDecoderTest, Int64Globals) { @@ -1745,13 +1958,13 @@ TEST_F(FunctionBodyDecoderTest, Int64Globals) { builder.AddGlobal(kWasmI64); builder.AddGlobal(kWasmI64); - EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); - EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(1)); + ExpectValidates(sig, {WASM_GET_GLOBAL(0)}); + ExpectValidates(sig, {WASM_GET_GLOBAL(1)}); - EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), - WASM_GET_LOCAL(0)); - EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), - WASM_GET_LOCAL(0)); + ExpectValidates(sig, + {WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_GET_LOCAL(0)}); + ExpectValidates(sig, + {WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), WASM_GET_LOCAL(0)}); } TEST_F(FunctionBodyDecoderTest, Float32Globals) { @@ -1761,9 +1974,9 @@ TEST_F(FunctionBodyDecoderTest, Float32Globals) { builder.AddGlobal(kWasmF32); - EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); - EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), - WASM_GET_LOCAL(0)); + ExpectValidates(sig, {WASM_GET_GLOBAL(0)}); + ExpectValidates(sig, + {WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_GET_LOCAL(0)}); } TEST_F(FunctionBodyDecoderTest, Float64Globals) { @@ -1773,9 +1986,9 @@ TEST_F(FunctionBodyDecoderTest, Float64Globals) { builder.AddGlobal(kWasmF64); - EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); - EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), - WASM_GET_LOCAL(0)); + ExpectValidates(sig, {WASM_GET_GLOBAL(0)}); + ExpectValidates(sig, + {WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_GET_LOCAL(0)}); } TEST_F(FunctionBodyDecoderTest, AllGetGlobalCombinations) { @@ -1787,11 +2000,7 @@ TEST_F(FunctionBodyDecoderTest, AllGetGlobalCombinations) { TestModuleBuilder builder; module = builder.module(); builder.AddGlobal(global_type); - if (local_type == global_type) { - EXPECT_VERIFIES_S(&sig, WASM_GET_GLOBAL(0)); - } else { - EXPECT_FAILURE_S(&sig, WASM_GET_GLOBAL(0)); - } + Validate(local_type == global_type, &sig, {WASM_GET_GLOBAL(0)}); } } } @@ -1805,23 +2014,113 @@ TEST_F(FunctionBodyDecoderTest, AllSetGlobalCombinations) { TestModuleBuilder builder; module = builder.module(); builder.AddGlobal(global_type); - if (local_type == global_type) { - EXPECT_VERIFIES_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); - } else { - EXPECT_FAILURE_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); - } + Validate(local_type == global_type, &sig, + {WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))}); } } } +TEST_F(FunctionBodyDecoderTest, SetTable) { + WASM_FEATURE_SCOPE(anyref); + TestModuleBuilder builder; + module = builder.module(); + byte tab_ref1 = builder.AddTable(kWasmAnyRef, 10, true, 20); + byte tab_func1 = builder.AddTable(kWasmAnyFunc, 20, true, 30); + byte tab_func2 = builder.AddTable(kWasmAnyFunc, 10, false, 20); + byte tab_ref2 = builder.AddTable(kWasmAnyRef, 10, false, 20); + ValueType sig_types[]{kWasmAnyRef, kWasmAnyFunc, kWasmI32}; + FunctionSig sig(0, 3, sig_types); + byte local_ref = 0; + byte local_func = 1; + byte local_int = 2; + ExpectValidates(&sig, {WASM_SET_TABLE(tab_ref1, WASM_I32V(6), + WASM_GET_LOCAL(local_ref))}); + ExpectValidates(&sig, {WASM_SET_TABLE(tab_func1, WASM_I32V(5), + WASM_GET_LOCAL(local_func))}); + ExpectValidates(&sig, {WASM_SET_TABLE(tab_func2, WASM_I32V(7), + WASM_GET_LOCAL(local_func))}); + ExpectValidates(&sig, {WASM_SET_TABLE(tab_ref2, WASM_I32V(8), + WASM_GET_LOCAL(local_ref))}); + + // We can store anyfunc values as anyref, but not the other way around. + ExpectValidates(&sig, {WASM_SET_TABLE(tab_ref1, WASM_I32V(4), + WASM_GET_LOCAL(local_func))}); + ExpectFailure(&sig, {WASM_SET_TABLE(tab_func1, WASM_I32V(9), + WASM_GET_LOCAL(local_ref))}); + ExpectFailure(&sig, {WASM_SET_TABLE(tab_func2, WASM_I32V(3), + WASM_GET_LOCAL(local_ref))}); + ExpectValidates(&sig, {WASM_SET_TABLE(tab_ref2, WASM_I32V(2), + WASM_GET_LOCAL(local_func))}); + ExpectFailure(&sig, {WASM_SET_TABLE(tab_ref1, WASM_I32V(9), + WASM_GET_LOCAL(local_int))}); + ExpectFailure(&sig, {WASM_SET_TABLE(tab_func1, WASM_I32V(3), + WASM_GET_LOCAL(local_int))}); + // Out-of-bounds table index should fail. + byte oob_tab = 37; + ExpectFailure( + &sig, {WASM_SET_TABLE(oob_tab, WASM_I32V(9), WASM_GET_LOCAL(local_ref))}); + ExpectFailure(&sig, {WASM_SET_TABLE(oob_tab, WASM_I32V(3), + WASM_GET_LOCAL(local_func))}); +} + +TEST_F(FunctionBodyDecoderTest, GetTable) { + WASM_FEATURE_SCOPE(anyref); + TestModuleBuilder builder; + module = builder.module(); + byte tab_ref1 = builder.AddTable(kWasmAnyRef, 10, true, 20); + byte tab_func1 = builder.AddTable(kWasmAnyFunc, 20, true, 30); + byte tab_func2 = builder.AddTable(kWasmAnyFunc, 10, false, 20); + byte tab_ref2 = builder.AddTable(kWasmAnyRef, 10, false, 20); + ValueType sig_types[]{kWasmAnyRef, kWasmAnyFunc, kWasmI32}; + FunctionSig sig(0, 3, sig_types); + byte local_ref = 0; + byte local_func = 1; + byte local_int = 2; + ExpectValidates( + &sig, + {WASM_SET_LOCAL(local_ref, WASM_GET_TABLE(tab_ref1, WASM_I32V(6)))}); + ExpectValidates( + &sig, + {WASM_SET_LOCAL(local_ref, WASM_GET_TABLE(tab_ref2, WASM_I32V(8)))}); + ExpectValidates( + &sig, + {WASM_SET_LOCAL(local_func, WASM_GET_TABLE(tab_func1, WASM_I32V(5)))}); + ExpectValidates( + &sig, + {WASM_SET_LOCAL(local_func, WASM_GET_TABLE(tab_func2, WASM_I32V(7)))}); + + // We can store anyfunc values as anyref, but not the other way around. + ExpectFailure(&sig, {WASM_SET_LOCAL(local_func, + WASM_GET_TABLE(tab_ref1, WASM_I32V(4)))}); + ExpectValidates( + &sig, + {WASM_SET_LOCAL(local_ref, WASM_GET_TABLE(tab_func1, WASM_I32V(9)))}); + ExpectValidates( + &sig, + {WASM_SET_LOCAL(local_ref, WASM_GET_TABLE(tab_func2, WASM_I32V(3)))}); + ExpectFailure(&sig, {WASM_SET_LOCAL(local_func, + WASM_GET_TABLE(tab_ref2, WASM_I32V(2)))}); + + ExpectFailure(&sig, {WASM_SET_LOCAL(local_int, + WASM_GET_TABLE(tab_ref1, WASM_I32V(9)))}); + ExpectFailure(&sig, {WASM_SET_LOCAL( + local_int, WASM_GET_TABLE(tab_func1, WASM_I32V(3)))}); + // Out-of-bounds table index should fail. + byte oob_tab = 37; + ExpectFailure( + &sig, {WASM_SET_LOCAL(local_ref, WASM_GET_TABLE(oob_tab, WASM_I32V(9)))}); + ExpectFailure(&sig, {WASM_SET_LOCAL(local_func, + WASM_GET_TABLE(oob_tab, WASM_I32V(3)))}); +} + TEST_F(FunctionBodyDecoderTest, WasmMemoryGrow) { TestModuleBuilder builder; module = builder.module(); builder.InitializeMemory(); byte code[] = {WASM_GET_LOCAL(0), kExprMemoryGrow, 0}; - EXPECT_VERIFIES_C(i_i, code); - EXPECT_FAILURE_C(i_d, code); + ExpectValidates(sigs.i_i(), code); + ExpectFailure(sigs.i_d(), code); } TEST_F(FunctionBodyDecoderTest, AsmJsMemoryGrow) { @@ -1830,7 +2129,7 @@ TEST_F(FunctionBodyDecoderTest, AsmJsMemoryGrow) { builder.InitializeMemory(); byte code[] = {WASM_GET_LOCAL(0), kExprMemoryGrow, 0}; - EXPECT_FAILURE_C(i_i, code); + ExpectFailure(sigs.i_i(), code); } TEST_F(FunctionBodyDecoderTest, AsmJsBinOpsCheckOrigin) { @@ -1870,9 +2169,9 @@ TEST_F(FunctionBodyDecoderTest, AsmJsBinOpsCheckOrigin) { module = builder.module(); builder.InitializeMemory(); for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) { - byte code[] = { - WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; - EXPECT_FAILURE_SC(AsmJsBinOps[i].sig, code); + ExpectFailure(AsmJsBinOps[i].sig, + {WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), + WASM_GET_LOCAL(1))}); } } } @@ -1918,44 +2217,48 @@ TEST_F(FunctionBodyDecoderTest, AsmJsUnOpsCheckOrigin) { module = builder.module(); builder.InitializeMemory(); for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) { - byte code[] = {WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))}; - EXPECT_FAILURE_SC(AsmJsUnOps[i].sig, code); + ExpectFailure(AsmJsUnOps[i].sig, + {WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))}); } } } TEST_F(FunctionBodyDecoderTest, BreakEnd) { - EXPECT_VERIFIES( - i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); - EXPECT_VERIFIES( - i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO)))); + ExpectValidates( + sigs.i_i(), + {WASM_BLOCK_I(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))}); + ExpectValidates( + sigs.i_i(), + {WASM_BLOCK_I(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO)))}); } TEST_F(FunctionBodyDecoderTest, BreakIfBinop) { - EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_I32_ADD( - WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), WASM_ZERO))); - EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_I32_ADD( - WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))); - EXPECT_VERIFIES_S( + ExpectValidates(sigs.i_i(), + {WASM_BLOCK_I(WASM_I32_ADD( + WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), WASM_ZERO))}); + ExpectValidates(sigs.i_i(), + {WASM_BLOCK_I(WASM_I32_ADD( + WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))}); + ExpectValidates( sigs.f_ff(), - WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))); + {WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))}); } TEST_F(FunctionBodyDecoderTest, BreakIfBinop_fail) { - EXPECT_FAILURE_S( + ExpectFailure( sigs.f_ff(), - WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))); - EXPECT_FAILURE_S( + {WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))}); + ExpectFailure( sigs.i_i(), - WASM_BLOCK_I(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))); + {WASM_BLOCK_I(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))}); } TEST_F(FunctionBodyDecoderTest, BreakIfUnrNarrow) { - EXPECT_FAILURE_S( + ExpectFailure( sigs.f_ff(), - WASM_BLOCK_I(WASM_BRV_IF(0, WASM_UNREACHABLE, WASM_UNREACHABLE), - WASM_RETURN0), - WASM_F32(0.0)); + {WASM_BLOCK_I(WASM_BRV_IF(0, WASM_UNREACHABLE, WASM_UNREACHABLE), + WASM_RETURN0), + WASM_F32(0.0)}); } TEST_F(FunctionBodyDecoderTest, BreakNesting1) { @@ -1965,22 +2268,14 @@ TEST_F(FunctionBodyDecoderTest, BreakNesting1) { WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)), WASM_SET_LOCAL(0, WASM_I32V_1(1))), WASM_ZERO)}; - if (i < 3) { - EXPECT_VERIFIES_C(i_i, code); - } else { - EXPECT_FAILURE_C(i_i, code); - } + Validate(i < 3, sigs.i_i(), code); } } TEST_F(FunctionBodyDecoderTest, BreakNesting2) { for (int i = 0; i < 7; i++) { byte code[] = {B1(WASM_LOOP(WASM_IF(WASM_ZERO, WASM_BR(i)), WASM_NOP))}; - if (i <= 3) { - EXPECT_VERIFIES_C(v_v, code); - } else { - EXPECT_FAILURE_C(v_v, code); - } + Validate(i <= 3, sigs.v_v(), code); } } @@ -1989,25 +2284,22 @@ TEST_F(FunctionBodyDecoderTest, BreakNesting3) { // (block[1] (loop[1] (block[1] (if 0 break[N]) byte code[] = { WASM_BLOCK(WASM_LOOP(B1(WASM_IF(WASM_ZERO, WASM_BR(i + 1)))))}; - if (i < 4) { - EXPECT_VERIFIES_C(v_v, code); - } else { - EXPECT_FAILURE_C(v_v, code); - } + Validate(i < 4, sigs.v_v(), code); } } TEST_F(FunctionBodyDecoderTest, BreaksWithMultipleTypes) { - EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I32V_1(7)), WASM_F32(7.7))); + ExpectFailure(sigs.i_i(), + {B2(WASM_BRV_IF_ZERO(0, WASM_I32V_1(7)), WASM_F32(7.7))}); - EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I32V_1(7)), - WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); - EXPECT_FAILURE(i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I32V_1(8)), - WASM_BRV_IF_ZERO(0, WASM_I32V_1(0)), - WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); - EXPECT_FAILURE(i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I32V_1(9)), - WASM_BRV_IF_ZERO(0, WASM_F32(7.7)), - WASM_BRV_IF_ZERO(0, WASM_I32V_1(11)))); + ExpectFailure(sigs.i_i(), {B2(WASM_BRV_IF_ZERO(0, WASM_I32V_1(7)), + WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))}); + ExpectFailure(sigs.i_i(), {B3(WASM_BRV_IF_ZERO(0, WASM_I32V_1(8)), + WASM_BRV_IF_ZERO(0, WASM_I32V_1(0)), + WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))}); + ExpectFailure(sigs.i_i(), {B3(WASM_BRV_IF_ZERO(0, WASM_I32V_1(9)), + WASM_BRV_IF_ZERO(0, WASM_F32(7.7)), + WASM_BRV_IF_ZERO(0, WASM_I32V_1(11)))}); } TEST_F(FunctionBodyDecoderTest, BreakNesting_6_levels) { @@ -2027,11 +2319,7 @@ TEST_F(FunctionBodyDecoderTest, BreakNesting_6_levels) { m >>= 1; } - if (i <= depth) { - EXPECT_VERIFIES_C(v_v, code); - } else { - EXPECT_FAILURE_C(v_v, code); - } + Validate(i <= depth, sigs.v_v(), code); } } } @@ -2044,17 +2332,19 @@ TEST_F(FunctionBodyDecoderTest, Break_TypeCheck) { byte code[] = {WASM_BLOCK_T( sig->GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), WASM_GET_LOCAL(0))}; - EXPECT_VERIFIES_SC(sig, code); + ExpectValidates(sig, code); } // unify i32 and f32 => fail - EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), - WASM_F32(1.2))); + ExpectFailure(sigs.i_i(), + {WASM_BLOCK_I(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), + WASM_F32(1.2))}); // unify f64 and f64 => OK - EXPECT_VERIFIES( - d_dd, WASM_BLOCK_D(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), - WASM_F64(1.2))); + ExpectValidates( + sigs.d_dd(), + {WASM_BLOCK_D(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), + WASM_F64(1.2))}); } TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll1) { @@ -2066,11 +2356,7 @@ TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll1) { sig.GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), WASM_GET_LOCAL(1))}; - if (i == j) { - EXPECT_VERIFIES_SC(&sig, code); - } else { - EXPECT_FAILURE_SC(&sig, code); - } + Validate(i == j, &sig, code); } } } @@ -2084,11 +2370,7 @@ TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll2) { WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)), WASM_GET_LOCAL(1))}; - if (i == j) { - EXPECT_VERIFIES_SC(&sig, code); - } else { - EXPECT_FAILURE_SC(&sig, code); - } + Validate(i == j, &sig, code); } } } @@ -2102,11 +2384,7 @@ TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll3) { WASM_GET_LOCAL(1), WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))}; - if (i == j) { - EXPECT_VERIFIES_SC(&sig, code); - } else { - EXPECT_FAILURE_SC(&sig, code); - } + Validate(i == j, &sig, code); } } } @@ -2122,11 +2400,7 @@ TEST_F(FunctionBodyDecoderTest, Break_Unify) { type, WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), WASM_GET_LOCAL(which ^ 1))}; - if (type == kWasmI32) { - EXPECT_VERIFIES_SC(&sig, code1); - } else { - EXPECT_FAILURE_SC(&sig, code1); - } + Validate(type == kWasmI32, &sig, code1); } } } @@ -2139,11 +2413,7 @@ TEST_F(FunctionBodyDecoderTest, BreakIf_cond_type) { byte code[] = {WASM_BLOCK_T( types[0], WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))}; - if (types[2] == kWasmI32) { - EXPECT_VERIFIES_SC(&sig, code); - } else { - EXPECT_FAILURE_SC(&sig, code); - } + Validate(types[2] == kWasmI32, &sig, code); } } } @@ -2158,11 +2428,7 @@ TEST_F(FunctionBodyDecoderTest, BreakIf_val_type) { types[1], WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)), WASM_DROP, WASM_GET_LOCAL(0))}; - if (i == j) { - EXPECT_VERIFIES_SC(&sig, code); - } else { - EXPECT_FAILURE_SC(&sig, code); - } + Validate(i == j, &sig, code); } } } @@ -2176,73 +2442,64 @@ TEST_F(FunctionBodyDecoderTest, BreakIf_Unify) { byte code[] = {WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), WASM_DROP, WASM_GET_LOCAL(which ^ 1))}; - if (type == kWasmI32) { - EXPECT_VERIFIES_SC(&sig, code); - } else { - EXPECT_FAILURE_SC(&sig, code); - } + Validate(type == kWasmI32, &sig, code); } } } TEST_F(FunctionBodyDecoderTest, BrTable0) { - static byte code[] = {kExprBrTable, 0, BR_TARGET(0)}; - EXPECT_FAILURE_C(v_v, code); + ExpectFailure(sigs.v_v(), {kExprBrTable, 0, BR_TARGET(0)}); } TEST_F(FunctionBodyDecoderTest, BrTable0b) { static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(0)}; - EXPECT_VERIFIES_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); + ExpectValidates(sigs.v_v(), code); + ExpectFailure(sigs.i_i(), code); } TEST_F(FunctionBodyDecoderTest, BrTable0c) { static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(1)}; - EXPECT_FAILURE_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); + ExpectFailure(sigs.v_v(), code); + ExpectFailure(sigs.i_i(), code); } TEST_F(FunctionBodyDecoderTest, BrTable1a) { - static byte code[] = {B1(WASM_BR_TABLE(WASM_I32V_2(67), 0, BR_TARGET(0)))}; - EXPECT_VERIFIES_C(v_v, code); + ExpectValidates(sigs.v_v(), + {B1(WASM_BR_TABLE(WASM_I32V_2(67), 0, BR_TARGET(0)))}); } TEST_F(FunctionBodyDecoderTest, BrTable1b) { static byte code[] = {B1(WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))}; - EXPECT_VERIFIES_C(v_v, code); - EXPECT_FAILURE_C(i_i, code); - EXPECT_FAILURE_C(f_ff, code); - EXPECT_FAILURE_C(d_dd, code); + ExpectValidates(sigs.v_v(), code); + ExpectFailure(sigs.i_i(), code); + ExpectFailure(sigs.f_ff(), code); + ExpectFailure(sigs.d_dd(), code); } TEST_F(FunctionBodyDecoderTest, BrTable2a) { - static byte code[] = { - B1(WASM_BR_TABLE(WASM_I32V_2(67), 1, BR_TARGET(0), BR_TARGET(0)))}; - EXPECT_VERIFIES_C(v_v, code); + ExpectValidates( + sigs.v_v(), + {B1(WASM_BR_TABLE(WASM_I32V_2(67), 1, BR_TARGET(0), BR_TARGET(0)))}); } TEST_F(FunctionBodyDecoderTest, BrTable2b) { - static byte code[] = {WASM_BLOCK(WASM_BLOCK( - WASM_BR_TABLE(WASM_I32V_2(67), 1, BR_TARGET(0), BR_TARGET(1))))}; - EXPECT_VERIFIES_C(v_v, code); + ExpectValidates(sigs.v_v(), + {WASM_BLOCK(WASM_BLOCK(WASM_BR_TABLE( + WASM_I32V_2(67), 1, BR_TARGET(0), BR_TARGET(1))))}); } TEST_F(FunctionBodyDecoderTest, BrTable_off_end) { static byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))}; for (size_t len = 1; len < sizeof(code); len++) { - Verify(false, sigs.i_i(), {code, len}, kAppendEnd); - Verify(false, sigs.i_i(), {code, len}, kOmitEnd); + ExpectFailure(sigs.i_i(), VectorOf(code, len), kAppendEnd); + ExpectFailure(sigs.i_i(), VectorOf(code, len), kOmitEnd); } } TEST_F(FunctionBodyDecoderTest, BrTable_invalid_br1) { for (int depth = 0; depth < 4; depth++) { byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; - if (depth <= 1) { - EXPECT_VERIFIES_C(v_i, code); - } else { - EXPECT_FAILURE_C(v_i, code); - } + Validate(depth <= 1, sigs.v_i(), code); } } @@ -2250,136 +2507,143 @@ TEST_F(FunctionBodyDecoderTest, BrTable_invalid_br2) { for (int depth = 0; depth < 7; depth++) { byte code[] = { WASM_LOOP(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; - if (depth < 2) { - EXPECT_VERIFIES_C(v_i, code); - } else { - EXPECT_FAILURE_C(v_i, code); - } + Validate(depth < 2, sigs.v_i(), code); } } TEST_F(FunctionBodyDecoderTest, BrTable_arity_mismatch1) { - EXPECT_FAILURE( - v_v, - WASM_BLOCK(WASM_BLOCK_I( - WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))); + ExpectFailure( + sigs.v_v(), + {WASM_BLOCK(WASM_BLOCK_I( + WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))}); } TEST_F(FunctionBodyDecoderTest, BrTable_arity_mismatch2) { - EXPECT_FAILURE( - v_v, - WASM_BLOCK_I(WASM_BLOCK( - WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))); + ExpectFailure( + sigs.v_v(), + {WASM_BLOCK_I(WASM_BLOCK( + WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))}); } TEST_F(FunctionBodyDecoderTest, BrTable_arity_mismatch_loop1) { - EXPECT_FAILURE( - v_v, - WASM_LOOP(WASM_BLOCK_I( - WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))); + ExpectFailure( + sigs.v_v(), + {WASM_LOOP(WASM_BLOCK_I( + WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))}); } TEST_F(FunctionBodyDecoderTest, BrTable_arity_mismatch_loop2) { - EXPECT_FAILURE( - v_v, - WASM_BLOCK_I(WASM_LOOP( - WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))); + ExpectFailure( + sigs.v_v(), + {WASM_BLOCK_I(WASM_LOOP( + WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))}); } TEST_F(FunctionBodyDecoderTest, BrTable_loop_block) { - EXPECT_VERIFIES( - v_v, - WASM_LOOP(WASM_BLOCK( - WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))); + ExpectValidates( + sigs.v_v(), + {WASM_LOOP(WASM_BLOCK( + WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))}); } TEST_F(FunctionBodyDecoderTest, BrTable_block_loop) { - EXPECT_VERIFIES( - v_v, - WASM_LOOP(WASM_BLOCK( - WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))); + ExpectValidates( + sigs.v_v(), + {WASM_LOOP(WASM_BLOCK( + WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))}); } TEST_F(FunctionBodyDecoderTest, BrTable_type_mismatch1) { - EXPECT_FAILURE( - v_v, - WASM_BLOCK_I(WASM_BLOCK_F( - WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))); + ExpectFailure( + sigs.v_v(), + {WASM_BLOCK_I(WASM_BLOCK_F( + WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))}); } TEST_F(FunctionBodyDecoderTest, BrTable_type_mismatch2) { - EXPECT_FAILURE( - v_v, - WASM_BLOCK_F(WASM_BLOCK_I( - WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))); + ExpectFailure( + sigs.v_v(), + {WASM_BLOCK_F(WASM_BLOCK_I( + WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))}); } TEST_F(FunctionBodyDecoderTest, BrTable_type_mismatch_unreachable) { - EXPECT_FAILURE(v_v, - WASM_BLOCK_F(WASM_BLOCK_I( - WASM_UNREACHABLE, - WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))); + ExpectFailure(sigs.v_v(), + {WASM_BLOCK_F(WASM_BLOCK_I( + WASM_UNREACHABLE, + WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))}); } TEST_F(FunctionBodyDecoderTest, BrUnreachable1) { - EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0)); + ExpectValidates(sigs.v_i(), + {WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0)}); } TEST_F(FunctionBodyDecoderTest, BrUnreachable2) { - EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0), - WASM_NOP); - EXPECT_FAILURE(v_i, WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0), - WASM_ZERO); + ExpectValidates(sigs.v_i(), + {WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0), WASM_NOP}); + ExpectFailure(sigs.v_i(), + {WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0), WASM_ZERO}); } TEST_F(FunctionBodyDecoderTest, Brv1) { - EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV(0, WASM_ZERO))); - EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_LOOP_I(WASM_BRV(2, WASM_ZERO)))); + ExpectValidates(sigs.i_i(), {WASM_BLOCK_I(WASM_BRV(0, WASM_ZERO))}); + ExpectValidates(sigs.i_i(), + {WASM_BLOCK_I(WASM_LOOP_I(WASM_BRV(2, WASM_ZERO)))}); } TEST_F(FunctionBodyDecoderTest, Brv1_type) { - EXPECT_VERIFIES(i_ii, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); - EXPECT_VERIFIES(l_ll, WASM_BLOCK_L(WASM_BRV(0, WASM_GET_LOCAL(0)))); - EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV(0, WASM_GET_LOCAL(0)))); - EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV(0, WASM_GET_LOCAL(0)))); + ExpectValidates(sigs.i_ii(), {WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))}); + ExpectValidates(sigs.l_ll(), {WASM_BLOCK_L(WASM_BRV(0, WASM_GET_LOCAL(0)))}); + ExpectValidates(sigs.f_ff(), {WASM_BLOCK_F(WASM_BRV(0, WASM_GET_LOCAL(0)))}); + ExpectValidates(sigs.d_dd(), {WASM_BLOCK_D(WASM_BRV(0, WASM_GET_LOCAL(0)))}); } TEST_F(FunctionBodyDecoderTest, Brv1_type_n) { - EXPECT_FAILURE(i_f, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); - EXPECT_FAILURE(i_d, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); + ExpectFailure(sigs.i_f(), {WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))}); + ExpectFailure(sigs.i_d(), {WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))}); } TEST_F(FunctionBodyDecoderTest, BrvIf1) { - EXPECT_VERIFIES(i_v, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_ZERO))); + ExpectValidates(sigs.i_v(), {WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_ZERO))}); } TEST_F(FunctionBodyDecoderTest, BrvIf1_type) { - EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); - EXPECT_VERIFIES(l_l, WASM_BLOCK_L(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); - EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); - EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); + ExpectValidates(sigs.i_i(), + {WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))}); + ExpectValidates(sigs.l_l(), + {WASM_BLOCK_L(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))}); + ExpectValidates(sigs.f_ff(), + {WASM_BLOCK_F(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))}); + ExpectValidates(sigs.d_dd(), + {WASM_BLOCK_D(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))}); } TEST_F(FunctionBodyDecoderTest, BrvIf1_type_n) { - EXPECT_FAILURE(i_f, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); - EXPECT_FAILURE(i_d, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); + ExpectFailure(sigs.i_f(), + {WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))}); + ExpectFailure(sigs.i_d(), + {WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))}); } TEST_F(FunctionBodyDecoderTest, Select) { - EXPECT_VERIFIES(i_i, - WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO)); - EXPECT_VERIFIES(f_ff, WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO)); - EXPECT_VERIFIES(d_dd, WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO)); - EXPECT_VERIFIES(l_l, WASM_SELECT(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO)); + ExpectValidates(sigs.i_i(), {WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), + WASM_ZERO)}); + ExpectValidates(sigs.f_ff(), + {WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO)}); + ExpectValidates(sigs.d_dd(), + {WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO)}); + ExpectValidates(sigs.l_l(), + {WASM_SELECT(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO)}); } TEST_F(FunctionBodyDecoderTest, Select_fail1) { - EXPECT_FAILURE( - i_i, WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); - EXPECT_FAILURE( - i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0), WASM_GET_LOCAL(0))); - EXPECT_FAILURE( - i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_F32(0.0))); + ExpectFailure(sigs.i_i(), {WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0), + WASM_GET_LOCAL(0))}); + ExpectFailure(sigs.i_i(), {WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0), + WASM_GET_LOCAL(0))}); + ExpectFailure(sigs.i_i(), {WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), + WASM_F32(0.0))}); } TEST_F(FunctionBodyDecoderTest, Select_fail2) { @@ -2390,29 +2654,29 @@ TEST_F(FunctionBodyDecoderTest, Select_fail2) { ValueType types[] = {type, kWasmI32, type}; FunctionSig sig(1, 2, types); - EXPECT_VERIFIES_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), - WASM_GET_LOCAL(0))); + ExpectValidates(&sig, {WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), + WASM_GET_LOCAL(0))}); - EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), - WASM_GET_LOCAL(0))); + ExpectFailure(&sig, {WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), + WASM_GET_LOCAL(0))}); - EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), - WASM_GET_LOCAL(0))); + ExpectFailure(&sig, {WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), + WASM_GET_LOCAL(0))}); - EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), - WASM_GET_LOCAL(1))); + ExpectFailure(&sig, {WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), + WASM_GET_LOCAL(1))}); } } TEST_F(FunctionBodyDecoderTest, Select_TypeCheck) { - EXPECT_FAILURE( - i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); + ExpectFailure(sigs.i_i(), {WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), + WASM_GET_LOCAL(0))}); - EXPECT_FAILURE( - i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), WASM_GET_LOCAL(0))); + ExpectFailure(sigs.i_i(), {WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), + WASM_GET_LOCAL(0))}); - EXPECT_FAILURE(i_i, - WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64V_1(0))); + ExpectFailure(sigs.i_i(), {WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), + WASM_I64V_1(0))}); } TEST_F(FunctionBodyDecoderTest, Throw) { @@ -2422,12 +2686,12 @@ TEST_F(FunctionBodyDecoderTest, Throw) { byte ex1 = builder.AddException(sigs.v_v()); byte ex2 = builder.AddException(sigs.v_i()); byte ex3 = builder.AddException(sigs.v_ii()); - EXPECT_VERIFIES(v_v, kExprThrow, ex1); - EXPECT_VERIFIES(v_v, WASM_I32V(0), kExprThrow, ex2); - EXPECT_FAILURE(v_v, WASM_F32(0.0), kExprThrow, ex2); - EXPECT_VERIFIES(v_v, WASM_I32V(0), WASM_I32V(0), kExprThrow, ex3); - EXPECT_FAILURE(v_v, WASM_F32(0.0), WASM_I32V(0), kExprThrow, ex3); - EXPECT_FAILURE(v_v, kExprThrow, 99); + ExpectValidates(sigs.v_v(), {kExprThrow, ex1}); + ExpectValidates(sigs.v_v(), {WASM_I32V(0), kExprThrow, ex2}); + ExpectFailure(sigs.v_v(), {WASM_F32(0.0), kExprThrow, ex2}); + ExpectValidates(sigs.v_v(), {WASM_I32V(0), WASM_I32V(0), kExprThrow, ex3}); + ExpectFailure(sigs.v_v(), {WASM_F32(0.0), WASM_I32V(0), kExprThrow, ex3}); + ExpectFailure(sigs.v_v(), {kExprThrow, 99}); } TEST_F(FunctionBodyDecoderTest, ThrowUnreachable) { @@ -2436,12 +2700,14 @@ TEST_F(FunctionBodyDecoderTest, ThrowUnreachable) { module = builder.module(); byte ex1 = builder.AddException(sigs.v_v()); byte ex2 = builder.AddException(sigs.v_i()); - EXPECT_VERIFIES(i_i, WASM_GET_LOCAL(0), kExprThrow, ex1, WASM_NOP); - EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), kExprThrow, ex2, WASM_NOP); - EXPECT_VERIFIES(i_i, WASM_GET_LOCAL(0), kExprThrow, ex1, WASM_ZERO); - EXPECT_FAILURE(v_i, WASM_GET_LOCAL(0), kExprThrow, ex2, WASM_ZERO); - EXPECT_FAILURE(i_i, WASM_GET_LOCAL(0), kExprThrow, ex1, WASM_F32(0.0)); - EXPECT_FAILURE(v_i, WASM_GET_LOCAL(0), kExprThrow, ex2, WASM_F32(0.0)); + ExpectValidates(sigs.i_i(), {WASM_GET_LOCAL(0), kExprThrow, ex1, WASM_NOP}); + ExpectValidates(sigs.v_i(), {WASM_GET_LOCAL(0), kExprThrow, ex2, WASM_NOP}); + ExpectValidates(sigs.i_i(), {WASM_GET_LOCAL(0), kExprThrow, ex1, WASM_ZERO}); + ExpectFailure(sigs.v_i(), {WASM_GET_LOCAL(0), kExprThrow, ex2, WASM_ZERO}); + ExpectFailure(sigs.i_i(), + {WASM_GET_LOCAL(0), kExprThrow, ex1, WASM_F32(0.0)}); + ExpectFailure(sigs.v_i(), + {WASM_GET_LOCAL(0), kExprThrow, ex2, WASM_F32(0.0)}); } #define WASM_TRY_OP kExprTry, kLocalVoid @@ -2452,21 +2718,22 @@ TEST_F(FunctionBodyDecoderTest, TryCatch) { WASM_FEATURE_SCOPE(eh); TestModuleBuilder builder; module = builder.module(); - EXPECT_VERIFIES(v_v, WASM_TRY_OP, kExprCatch, kExprDrop, kExprEnd); - EXPECT_FAILURE(v_v, WASM_TRY_OP, kExprCatch, kExprCatch, kExprEnd); - EXPECT_FAILURE(v_v, WASM_TRY_OP, kExprEnd); // Missing catch. - EXPECT_FAILURE(v_v, WASM_TRY_OP, kExprCatch); // Missing end. - EXPECT_FAILURE(v_v, kExprCatch, kExprEnd); // Missing try. + ExpectValidates(sigs.v_v(), {WASM_TRY_OP, kExprCatch, kExprDrop, kExprEnd}); + ExpectFailure(sigs.v_v(), {WASM_TRY_OP, kExprCatch, kExprCatch, kExprEnd}); + ExpectFailure(sigs.v_v(), {WASM_TRY_OP, kExprEnd}); // Missing catch. + ExpectFailure(sigs.v_v(), {WASM_TRY_OP, kExprCatch}); // Missing end. + ExpectFailure(sigs.v_v(), {kExprCatch, kExprEnd}); // Missing try. } TEST_F(FunctionBodyDecoderTest, Rethrow) { WASM_FEATURE_SCOPE(eh); TestModuleBuilder builder; module = builder.module(); - EXPECT_VERIFIES(v_v, WASM_TRY_OP, kExprCatch, kExprRethrow, kExprEnd); - EXPECT_FAILURE(v_v, WASM_TRY_OP, kExprRethrow, kExprCatch, kExprEnd); - EXPECT_FAILURE(v_v, WASM_BLOCK(kExprRethrow)); - EXPECT_FAILURE(v_v, kExprRethrow); + ExpectValidates(sigs.v_v(), + {WASM_TRY_OP, kExprCatch, kExprRethrow, kExprEnd}); + ExpectFailure(sigs.v_v(), {WASM_TRY_OP, kExprRethrow, kExprCatch, kExprEnd}); + ExpectFailure(sigs.v_v(), {WASM_BLOCK(kExprRethrow)}); + ExpectFailure(sigs.v_v(), {kExprRethrow}); } TEST_F(FunctionBodyDecoderTest, BrOnExn) { @@ -2475,23 +2742,24 @@ TEST_F(FunctionBodyDecoderTest, BrOnExn) { module = builder.module(); byte ex1 = builder.AddException(sigs.v_v()); byte ex2 = builder.AddException(sigs.v_i()); - EXPECT_VERIFIES(v_v, WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(0, ex1), - kExprDrop, kExprEnd); - EXPECT_VERIFIES(v_v, WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(1, ex1), - kExprDrop, kExprEnd); - EXPECT_VERIFIES(v_v, WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(0, ex1), - WASM_BR_ON_EXN(0, ex1), kExprDrop, kExprEnd); - EXPECT_VERIFIES(v_v, WASM_BLOCK(WASM_TRY_OP, kExprCatch, - WASM_BR_ON_EXN(1, ex1), kExprDrop, kExprEnd)); - EXPECT_VERIFIES(i_v, - WASM_BLOCK_I(WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(1, ex2), - kExprDrop, kExprEnd, kExprI32Const, 0)); - EXPECT_FAILURE(v_v, WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(2, ex1), - kExprDrop, kExprEnd); - EXPECT_FAILURE(v_v, WASM_TRY_OP, kExprCatch, kExprDrop, - WASM_BR_ON_EXN(0, ex1), kExprEnd); - EXPECT_FAILURE(v_v, WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(0, ex1), - kExprEnd); + ExpectValidates(sigs.v_v(), {WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(0, ex1), + kExprDrop, kExprEnd}); + ExpectValidates(sigs.v_v(), {WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(1, ex1), + kExprDrop, kExprEnd}); + ExpectValidates(sigs.v_v(), {WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(0, ex1), + WASM_BR_ON_EXN(0, ex1), kExprDrop, kExprEnd}); + ExpectValidates(sigs.v_v(), + {WASM_BLOCK(WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(1, ex1), + kExprDrop, kExprEnd)}); + ExpectValidates(sigs.i_v(), + {WASM_BLOCK_I(WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(1, ex2), + kExprDrop, kExprEnd, kExprI32Const, 0)}); + ExpectFailure(sigs.v_v(), {WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(2, ex1), + kExprDrop, kExprEnd}); + ExpectFailure(sigs.v_v(), {WASM_TRY_OP, kExprCatch, kExprDrop, + WASM_BR_ON_EXN(0, ex1), kExprEnd}); + ExpectFailure(sigs.v_v(), + {WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(0, ex1), kExprEnd}); } #undef WASM_BR_ON_EXN @@ -2502,15 +2770,19 @@ TEST_F(FunctionBodyDecoderTest, MultiValBlock1) { TestModuleBuilder builder; module = builder.module(); byte f0 = builder.AddSignature(sigs.ii_v()); - EXPECT_VERIFIES(i_ii, WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), - kExprI32Add); - EXPECT_FAILURE(i_ii, WASM_BLOCK_X(f0, WASM_NOP), kExprI32Add); - EXPECT_FAILURE(i_ii, WASM_BLOCK_X(f0, WASM_GET_LOCAL(0)), kExprI32Add); - EXPECT_FAILURE(i_ii, WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), - WASM_GET_LOCAL(0)), - kExprI32Add); - EXPECT_FAILURE(i_ii, WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), - kExprF32Add); + ExpectValidates( + sigs.i_ii(), + {WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), kExprI32Add}); + ExpectFailure(sigs.i_ii(), {WASM_BLOCK_X(f0, WASM_NOP), kExprI32Add}); + ExpectFailure(sigs.i_ii(), + {WASM_BLOCK_X(f0, WASM_GET_LOCAL(0)), kExprI32Add}); + ExpectFailure(sigs.i_ii(), + {WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), + WASM_GET_LOCAL(0)), + kExprI32Add}); + ExpectFailure( + sigs.i_ii(), + {WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), kExprF32Add}); } TEST_F(FunctionBodyDecoderTest, MultiValBlock2) { @@ -2518,17 +2790,20 @@ TEST_F(FunctionBodyDecoderTest, MultiValBlock2) { TestModuleBuilder builder; module = builder.module(); byte f0 = builder.AddSignature(sigs.ii_v()); - EXPECT_VERIFIES(i_ii, WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), - WASM_I32_ADD(WASM_NOP, WASM_NOP)); - EXPECT_FAILURE(i_ii, WASM_BLOCK_X(f0, WASM_NOP), - WASM_I32_ADD(WASM_NOP, WASM_NOP)); - EXPECT_FAILURE(i_ii, WASM_BLOCK_X(f0, WASM_GET_LOCAL(0)), - WASM_I32_ADD(WASM_NOP, WASM_NOP)); - EXPECT_FAILURE(i_ii, WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), - WASM_GET_LOCAL(0)), - WASM_I32_ADD(WASM_NOP, WASM_NOP)); - EXPECT_FAILURE(i_ii, WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), - WASM_F32_ADD(WASM_NOP, WASM_NOP)); + ExpectValidates(sigs.i_ii(), + {WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), + WASM_I32_ADD(WASM_NOP, WASM_NOP)}); + ExpectFailure(sigs.i_ii(), + {WASM_BLOCK_X(f0, WASM_NOP), WASM_I32_ADD(WASM_NOP, WASM_NOP)}); + ExpectFailure(sigs.i_ii(), {WASM_BLOCK_X(f0, WASM_GET_LOCAL(0)), + WASM_I32_ADD(WASM_NOP, WASM_NOP)}); + ExpectFailure(sigs.i_ii(), + {WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), + WASM_GET_LOCAL(0)), + WASM_I32_ADD(WASM_NOP, WASM_NOP)}); + ExpectFailure(sigs.i_ii(), + {WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), + WASM_F32_ADD(WASM_NOP, WASM_NOP)}); } TEST_F(FunctionBodyDecoderTest, MultiValBlockBr) { @@ -2536,11 +2811,11 @@ TEST_F(FunctionBodyDecoderTest, MultiValBlockBr) { TestModuleBuilder builder; module = builder.module(); byte f0 = builder.AddSignature(sigs.ii_v()); - EXPECT_FAILURE(i_ii, WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_BR(0)), - kExprI32Add); - EXPECT_VERIFIES(i_ii, WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), - WASM_GET_LOCAL(1), WASM_BR(0)), - kExprI32Add); + ExpectFailure(sigs.i_ii(), + {WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), WASM_BR(0)), kExprI32Add}); + ExpectValidates(sigs.i_ii(), {WASM_BLOCK_X(f0, WASM_GET_LOCAL(0), + WASM_GET_LOCAL(1), WASM_BR(0)), + kExprI32Add}); } TEST_F(FunctionBodyDecoderTest, MultiValLoop1) { @@ -2548,15 +2823,17 @@ TEST_F(FunctionBodyDecoderTest, MultiValLoop1) { TestModuleBuilder builder; module = builder.module(); byte f0 = builder.AddSignature(sigs.ii_v()); - EXPECT_VERIFIES(i_ii, WASM_LOOP_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), - kExprI32Add); - EXPECT_FAILURE(i_ii, WASM_LOOP_X(f0, WASM_NOP), kExprI32Add); - EXPECT_FAILURE(i_ii, WASM_LOOP_X(f0, WASM_GET_LOCAL(0)), kExprI32Add); - EXPECT_FAILURE(i_ii, WASM_LOOP_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), - WASM_GET_LOCAL(0)), - kExprI32Add); - EXPECT_FAILURE(i_ii, WASM_LOOP_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), - kExprF32Add); + ExpectValidates( + sigs.i_ii(), + {WASM_LOOP_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), kExprI32Add}); + ExpectFailure(sigs.i_ii(), {WASM_LOOP_X(f0, WASM_NOP), kExprI32Add}); + ExpectFailure(sigs.i_ii(), {WASM_LOOP_X(f0, WASM_GET_LOCAL(0)), kExprI32Add}); + ExpectFailure(sigs.i_ii(), {WASM_LOOP_X(f0, WASM_GET_LOCAL(0), + WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)), + kExprI32Add}); + ExpectFailure( + sigs.i_ii(), + {WASM_LOOP_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), kExprF32Add}); } TEST_F(FunctionBodyDecoderTest, MultiValIf) { @@ -2564,62 +2841,61 @@ TEST_F(FunctionBodyDecoderTest, MultiValIf) { TestModuleBuilder builder; module = builder.module(); byte f0 = builder.AddSignature(sigs.ii_v()); - EXPECT_VERIFIES( - i_ii, WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), - WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), - WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), - kExprI32Add); - EXPECT_FAILURE( - i_ii, WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP), - kExprI32Add); - EXPECT_FAILURE( - i_ii, WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), - WASM_NOP, - WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), - kExprI32Add); - EXPECT_FAILURE( - i_ii, WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), - WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), - WASM_NOP), - kExprI32Add); - EXPECT_FAILURE( - i_ii, WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), - WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), - kExprI32Add); - EXPECT_FAILURE( - i_ii, WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), - WASM_GET_LOCAL(0), - WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), - kExprI32Add); - EXPECT_FAILURE( - i_ii, WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), - WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), - WASM_GET_LOCAL(1)), - kExprI32Add); - EXPECT_FAILURE( - i_ii, WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), - WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), - WASM_GET_LOCAL(0)), - WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), - WASM_GET_LOCAL(0))), - kExprI32Add); - EXPECT_FAILURE( - i_ii, WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), - WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), - WASM_GET_LOCAL(0)), - WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))), - kExprI32Add); - EXPECT_FAILURE( - i_ii, WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), - WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), - WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), - WASM_GET_LOCAL(1))), - kExprI32Add); - EXPECT_FAILURE( - i_ii, WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), - WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), - WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), - kExprF32Add); + ExpectValidates( + sigs.i_ii(), + {WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), + WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), + WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), + kExprI32Add}); + ExpectFailure( + sigs.i_ii(), + {WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP), kExprI32Add}); + ExpectFailure(sigs.i_ii(), + {WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), WASM_NOP, + WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), + kExprI32Add}); + ExpectFailure( + sigs.i_ii(), + {WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), + WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_NOP), + kExprI32Add}); + ExpectFailure(sigs.i_ii(), + {WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), + WASM_GET_LOCAL(1)), + kExprI32Add}); + ExpectFailure(sigs.i_ii(), + {WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), + WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), + kExprI32Add}); + ExpectFailure(sigs.i_ii(), + {WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), + WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), + WASM_GET_LOCAL(1)), + kExprI32Add}); + ExpectFailure( + sigs.i_ii(), + {WASM_IF_ELSE_X( + f0, WASM_GET_LOCAL(0), + WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)), + WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))), + kExprI32Add}); + ExpectFailure(sigs.i_ii(), + {WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), + WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), + WASM_GET_LOCAL(0)), + WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))), + kExprI32Add}); + ExpectFailure(sigs.i_ii(), + {WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), + WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), + WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), + WASM_GET_LOCAL(1))), + kExprI32Add}); + ExpectFailure(sigs.i_ii(), + {WASM_IF_ELSE_X(f0, WASM_GET_LOCAL(0), + WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), + WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), + kExprF32Add}); } TEST_F(FunctionBodyDecoderTest, BlockParam) { @@ -2628,24 +2904,27 @@ TEST_F(FunctionBodyDecoderTest, BlockParam) { module = builder.module(); byte f1 = builder.AddSignature(sigs.i_i()); byte f2 = builder.AddSignature(sigs.i_ii()); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), - WASM_BLOCK_X(f1, WASM_GET_LOCAL(1), - WASM_I32_ADD(WASM_NOP, WASM_NOP))); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), - WASM_BLOCK_X(f2, WASM_I32_ADD(WASM_NOP, WASM_NOP))); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), - WASM_BLOCK_X(f1, WASM_NOP), - WASM_I32_ADD(WASM_NOP, WASM_NOP)); - EXPECT_FAILURE(i_ii, WASM_BLOCK_X(f1, WASM_NOP), - WASM_RETURN1(WASM_GET_LOCAL(0))); - EXPECT_FAILURE(i_ii, WASM_BLOCK_X(f1, WASM_GET_LOCAL(0)), - WASM_RETURN1(WASM_GET_LOCAL(0))); - EXPECT_FAILURE(i_ii, WASM_GET_LOCAL(0), - WASM_BLOCK_X(f2, WASM_I32_ADD(WASM_NOP, WASM_NOP)), - WASM_RETURN1(WASM_GET_LOCAL(0))); - EXPECT_FAILURE(i_ii, WASM_GET_LOCAL(0), - WASM_BLOCK_X(f1, WASM_F32_NEG(WASM_NOP)), - WASM_RETURN1(WASM_GET_LOCAL(0))); + ExpectValidates( + sigs.i_ii(), + {WASM_GET_LOCAL(0), + WASM_BLOCK_X(f1, WASM_GET_LOCAL(1), WASM_I32_ADD(WASM_NOP, WASM_NOP))}); + ExpectValidates(sigs.i_ii(), + {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), + WASM_BLOCK_X(f2, WASM_I32_ADD(WASM_NOP, WASM_NOP))}); + ExpectValidates(sigs.i_ii(), {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), + WASM_BLOCK_X(f1, WASM_NOP), + WASM_I32_ADD(WASM_NOP, WASM_NOP)}); + ExpectFailure(sigs.i_ii(), + {WASM_BLOCK_X(f1, WASM_NOP), WASM_RETURN1(WASM_GET_LOCAL(0))}); + ExpectFailure(sigs.i_ii(), {WASM_BLOCK_X(f1, WASM_GET_LOCAL(0)), + WASM_RETURN1(WASM_GET_LOCAL(0))}); + ExpectFailure( + sigs.i_ii(), + {WASM_GET_LOCAL(0), WASM_BLOCK_X(f2, WASM_I32_ADD(WASM_NOP, WASM_NOP)), + WASM_RETURN1(WASM_GET_LOCAL(0))}); + ExpectFailure(sigs.i_ii(), + {WASM_GET_LOCAL(0), WASM_BLOCK_X(f1, WASM_F32_NEG(WASM_NOP)), + WASM_RETURN1(WASM_GET_LOCAL(0))}); } TEST_F(FunctionBodyDecoderTest, LoopParam) { @@ -2654,24 +2933,25 @@ TEST_F(FunctionBodyDecoderTest, LoopParam) { module = builder.module(); byte f1 = builder.AddSignature(sigs.i_i()); byte f2 = builder.AddSignature(sigs.i_ii()); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), - WASM_LOOP_X(f1, WASM_GET_LOCAL(1), - WASM_I32_ADD(WASM_NOP, WASM_NOP))); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), - WASM_LOOP_X(f2, WASM_I32_ADD(WASM_NOP, WASM_NOP))); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), - WASM_LOOP_X(f1, WASM_NOP), - WASM_I32_ADD(WASM_NOP, WASM_NOP)); - EXPECT_FAILURE(i_ii, WASM_LOOP_X(f1, WASM_NOP), - WASM_RETURN1(WASM_GET_LOCAL(0))); - EXPECT_FAILURE(i_ii, WASM_LOOP_X(f1, WASM_GET_LOCAL(0)), - WASM_RETURN1(WASM_GET_LOCAL(0))); - EXPECT_FAILURE(i_ii, WASM_GET_LOCAL(0), - WASM_LOOP_X(f2, WASM_I32_ADD(WASM_NOP, WASM_NOP)), - WASM_RETURN1(WASM_GET_LOCAL(0))); - EXPECT_FAILURE(i_ii, WASM_GET_LOCAL(0), - WASM_LOOP_X(f1, WASM_F32_NEG(WASM_NOP)), - WASM_RETURN1(WASM_GET_LOCAL(0))); + ExpectValidates(sigs.i_ii(), {WASM_GET_LOCAL(0), + WASM_LOOP_X(f1, WASM_GET_LOCAL(1), + WASM_I32_ADD(WASM_NOP, WASM_NOP))}); + ExpectValidates(sigs.i_ii(), + {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), + WASM_LOOP_X(f2, WASM_I32_ADD(WASM_NOP, WASM_NOP))}); + ExpectValidates(sigs.i_ii(), {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), + WASM_LOOP_X(f1, WASM_NOP), + WASM_I32_ADD(WASM_NOP, WASM_NOP)}); + ExpectFailure(sigs.i_ii(), + {WASM_LOOP_X(f1, WASM_NOP), WASM_RETURN1(WASM_GET_LOCAL(0))}); + ExpectFailure(sigs.i_ii(), {WASM_LOOP_X(f1, WASM_GET_LOCAL(0)), + WASM_RETURN1(WASM_GET_LOCAL(0))}); + ExpectFailure(sigs.i_ii(), {WASM_GET_LOCAL(0), + WASM_LOOP_X(f2, WASM_I32_ADD(WASM_NOP, WASM_NOP)), + WASM_RETURN1(WASM_GET_LOCAL(0))}); + ExpectFailure(sigs.i_ii(), + {WASM_GET_LOCAL(0), WASM_LOOP_X(f1, WASM_F32_NEG(WASM_NOP)), + WASM_RETURN1(WASM_GET_LOCAL(0))}); } TEST_F(FunctionBodyDecoderTest, LoopParamBr) { @@ -2680,20 +2960,21 @@ TEST_F(FunctionBodyDecoderTest, LoopParamBr) { module = builder.module(); byte f1 = builder.AddSignature(sigs.i_i()); byte f2 = builder.AddSignature(sigs.i_ii()); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), - WASM_LOOP_X(f1, WASM_BR(0))); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), - WASM_LOOP_X(f1, WASM_BRV(0, WASM_GET_LOCAL(1)))); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), - WASM_LOOP_X(f2, WASM_BR(0))); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), - WASM_LOOP_X(f1, WASM_BLOCK_X(f1, WASM_BR(1)))); - EXPECT_FAILURE(i_ii, WASM_GET_LOCAL(0), - WASM_LOOP_X(f1, WASM_BLOCK(WASM_BR(1))), - WASM_RETURN1(WASM_GET_LOCAL(0))); - EXPECT_FAILURE(i_ii, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), - WASM_LOOP_X(f2, WASM_BLOCK_X(f1, WASM_BR(1))), - WASM_RETURN1(WASM_GET_LOCAL(0))); + ExpectValidates(sigs.i_ii(), + {WASM_GET_LOCAL(0), WASM_LOOP_X(f1, WASM_BR(0))}); + ExpectValidates( + sigs.i_ii(), + {WASM_GET_LOCAL(0), WASM_LOOP_X(f1, WASM_BRV(0, WASM_GET_LOCAL(1)))}); + ExpectValidates(sigs.i_ii(), {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), + WASM_LOOP_X(f2, WASM_BR(0))}); + ExpectValidates(sigs.i_ii(), {WASM_GET_LOCAL(0), + WASM_LOOP_X(f1, WASM_BLOCK_X(f1, WASM_BR(1)))}); + ExpectFailure(sigs.i_ii(), + {WASM_GET_LOCAL(0), WASM_LOOP_X(f1, WASM_BLOCK(WASM_BR(1))), + WASM_RETURN1(WASM_GET_LOCAL(0))}); + ExpectFailure(sigs.i_ii(), {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), + WASM_LOOP_X(f2, WASM_BLOCK_X(f1, WASM_BR(1))), + WASM_RETURN1(WASM_GET_LOCAL(0))}); } TEST_F(FunctionBodyDecoderTest, IfParam) { @@ -2702,29 +2983,32 @@ TEST_F(FunctionBodyDecoderTest, IfParam) { module = builder.module(); byte f1 = builder.AddSignature(sigs.i_i()); byte f2 = builder.AddSignature(sigs.i_ii()); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), - WASM_IF_X(f1, WASM_GET_LOCAL(0), - WASM_I32_ADD(WASM_NOP, WASM_GET_LOCAL(1)))); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), - WASM_IF_ELSE_X(f1, WASM_GET_LOCAL(0), - WASM_I32_ADD(WASM_NOP, WASM_GET_LOCAL(1)), - WASM_I32_EQZ(WASM_NOP))); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), - WASM_IF_ELSE_X(f2, WASM_GET_LOCAL(0), - WASM_I32_ADD(WASM_NOP, WASM_NOP), - WASM_I32_MUL(WASM_NOP, WASM_NOP))); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), - WASM_IF_X(f1, WASM_GET_LOCAL(0), WASM_NOP), - WASM_I32_ADD(WASM_NOP, WASM_NOP)); - EXPECT_VERIFIES(i_ii, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), - WASM_IF_ELSE_X(f1, WASM_GET_LOCAL(0), - WASM_NOP, WASM_I32_EQZ(WASM_NOP)), - WASM_I32_ADD(WASM_NOP, WASM_NOP)); + ExpectValidates(sigs.i_ii(), + {WASM_GET_LOCAL(0), + WASM_IF_X(f1, WASM_GET_LOCAL(0), + WASM_I32_ADD(WASM_NOP, WASM_GET_LOCAL(1)))}); + ExpectValidates(sigs.i_ii(), + {WASM_GET_LOCAL(0), + WASM_IF_ELSE_X(f1, WASM_GET_LOCAL(0), + WASM_I32_ADD(WASM_NOP, WASM_GET_LOCAL(1)), + WASM_I32_EQZ(WASM_NOP))}); + ExpectValidates( + sigs.i_ii(), + {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), + WASM_IF_ELSE_X(f2, WASM_GET_LOCAL(0), WASM_I32_ADD(WASM_NOP, WASM_NOP), + WASM_I32_MUL(WASM_NOP, WASM_NOP))}); + ExpectValidates(sigs.i_ii(), {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), + WASM_IF_X(f1, WASM_GET_LOCAL(0), WASM_NOP), + WASM_I32_ADD(WASM_NOP, WASM_NOP)}); + ExpectValidates(sigs.i_ii(), {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), + WASM_IF_ELSE_X(f1, WASM_GET_LOCAL(0), WASM_NOP, + WASM_I32_EQZ(WASM_NOP)), + WASM_I32_ADD(WASM_NOP, WASM_NOP)}); } TEST_F(FunctionBodyDecoderTest, Regression709741) { AddLocals(kWasmI32, kV8MaxWasmFunctionLocals - 1); - EXPECT_VERIFIES(v_v, WASM_NOP); + ExpectValidates(sigs.v_v(), {WASM_NOP}); byte code[] = {WASM_NOP, WASM_END}; for (size_t i = 0; i < arraysize(code); ++i) { @@ -2746,10 +3030,13 @@ TEST_F(FunctionBodyDecoderTest, MemoryInit) { builder.SetDataSegmentCount(1); module = builder.module(); - EXPECT_FAILURE(v_v, WASM_MEMORY_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectFailure(sigs.v_v(), + {WASM_MEMORY_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)}); WASM_FEATURE_SCOPE(bulk_memory); - EXPECT_VERIFIES(v_v, WASM_MEMORY_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)); - EXPECT_FAILURE(v_v, WASM_TABLE_INIT(1, WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectValidates(sigs.v_v(), + {WASM_MEMORY_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)}); + ExpectFailure(sigs.v_v(), + {WASM_TABLE_INIT(1, WASM_ZERO, WASM_ZERO, WASM_ZERO)}); } TEST_F(FunctionBodyDecoderTest, MemoryInitInvalid) { @@ -2762,20 +3049,20 @@ TEST_F(FunctionBodyDecoderTest, MemoryInitInvalid) { byte code[] = {WASM_MEMORY_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO), WASM_END}; for (size_t i = 0; i <= arraysize(code); ++i) { - Verify(i == arraysize(code), sigs.v_v(), {code, i}, kOmitEnd); + Validate(i == arraysize(code), sigs.v_v(), VectorOf(code, i), kOmitEnd); } } -TEST_F(FunctionBodyDecoderTest, MemoryDrop) { +TEST_F(FunctionBodyDecoderTest, DataDrop) { TestModuleBuilder builder; builder.InitializeMemory(); builder.SetDataSegmentCount(1); module = builder.module(); - EXPECT_FAILURE(v_v, WASM_MEMORY_DROP(0)); + ExpectFailure(sigs.v_v(), {WASM_DATA_DROP(0)}); WASM_FEATURE_SCOPE(bulk_memory); - EXPECT_VERIFIES(v_v, WASM_MEMORY_DROP(0)); - EXPECT_FAILURE(v_v, WASM_MEMORY_DROP(1)); + ExpectValidates(sigs.v_v(), {WASM_DATA_DROP(0)}); + ExpectFailure(sigs.v_v(), {WASM_DATA_DROP(1)}); } TEST_F(FunctionBodyDecoderTest, MemoryCopy) { @@ -2783,9 +3070,11 @@ TEST_F(FunctionBodyDecoderTest, MemoryCopy) { builder.InitializeMemory(); module = builder.module(); - EXPECT_FAILURE(v_v, WASM_MEMORY_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectFailure(sigs.v_v(), + {WASM_MEMORY_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)}); WASM_FEATURE_SCOPE(bulk_memory); - EXPECT_VERIFIES(v_v, WASM_MEMORY_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectValidates(sigs.v_v(), + {WASM_MEMORY_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)}); } TEST_F(FunctionBodyDecoderTest, MemoryFill) { @@ -2793,16 +3082,21 @@ TEST_F(FunctionBodyDecoderTest, MemoryFill) { builder.InitializeMemory(); module = builder.module(); - EXPECT_FAILURE(v_v, WASM_MEMORY_FILL(WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectFailure(sigs.v_v(), + {WASM_MEMORY_FILL(WASM_ZERO, WASM_ZERO, WASM_ZERO)}); WASM_FEATURE_SCOPE(bulk_memory); - EXPECT_VERIFIES(v_v, WASM_MEMORY_FILL(WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectValidates(sigs.v_v(), + {WASM_MEMORY_FILL(WASM_ZERO, WASM_ZERO, WASM_ZERO)}); } TEST_F(FunctionBodyDecoderTest, BulkMemoryOpsWithoutMemory) { WASM_FEATURE_SCOPE(bulk_memory); - EXPECT_FAILURE(v_v, WASM_MEMORY_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)); - EXPECT_FAILURE(v_v, WASM_MEMORY_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)); - EXPECT_FAILURE(v_v, WASM_MEMORY_FILL(WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectFailure(sigs.v_v(), + {WASM_MEMORY_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)}); + ExpectFailure(sigs.v_v(), + {WASM_MEMORY_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)}); + ExpectFailure(sigs.v_v(), + {WASM_MEMORY_FILL(WASM_ZERO, WASM_ZERO, WASM_ZERO)}); } TEST_F(FunctionBodyDecoderTest, TableInit) { @@ -2811,10 +3105,13 @@ TEST_F(FunctionBodyDecoderTest, TableInit) { builder.AddPassiveElementSegment(); module = builder.module(); - EXPECT_FAILURE(v_v, WASM_TABLE_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectFailure(sigs.v_v(), + {WASM_TABLE_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)}); WASM_FEATURE_SCOPE(bulk_memory); - EXPECT_VERIFIES(v_v, WASM_TABLE_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)); - EXPECT_FAILURE(v_v, WASM_TABLE_INIT(1, WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectValidates(sigs.v_v(), + {WASM_TABLE_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)}); + ExpectFailure(sigs.v_v(), + {WASM_TABLE_INIT(1, WASM_ZERO, WASM_ZERO, WASM_ZERO)}); } TEST_F(FunctionBodyDecoderTest, TableInitInvalid) { @@ -2826,20 +3123,20 @@ TEST_F(FunctionBodyDecoderTest, TableInitInvalid) { WASM_FEATURE_SCOPE(bulk_memory); byte code[] = {WASM_TABLE_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO), WASM_END}; for (size_t i = 0; i <= arraysize(code); ++i) { - Verify(i == arraysize(code), sigs.v_v(), {code, i}, kOmitEnd); + Validate(i == arraysize(code), sigs.v_v(), VectorOf(code, i), kOmitEnd); } } -TEST_F(FunctionBodyDecoderTest, TableDrop) { +TEST_F(FunctionBodyDecoderTest, ElemDrop) { TestModuleBuilder builder; builder.InitializeTable(); builder.AddPassiveElementSegment(); module = builder.module(); - EXPECT_FAILURE(v_v, WASM_TABLE_DROP(0)); + ExpectFailure(sigs.v_v(), {WASM_ELEM_DROP(0)}); WASM_FEATURE_SCOPE(bulk_memory); - EXPECT_VERIFIES(v_v, WASM_TABLE_DROP(0)); - EXPECT_FAILURE(v_v, WASM_TABLE_DROP(1)); + ExpectValidates(sigs.v_v(), {WASM_ELEM_DROP(0)}); + ExpectFailure(sigs.v_v(), {WASM_ELEM_DROP(1)}); } TEST_F(FunctionBodyDecoderTest, TableCopy) { @@ -2847,9 +3144,10 @@ TEST_F(FunctionBodyDecoderTest, TableCopy) { builder.InitializeTable(); module = builder.module(); - EXPECT_FAILURE(v_v, WASM_TABLE_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectFailure(sigs.v_v(), {WASM_TABLE_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)}); WASM_FEATURE_SCOPE(bulk_memory); - EXPECT_VERIFIES(v_v, WASM_TABLE_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectValidates(sigs.v_v(), + {WASM_TABLE_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)}); } TEST_F(FunctionBodyDecoderTest, BulkTableOpsWithoutTable) { @@ -2858,9 +3156,10 @@ TEST_F(FunctionBodyDecoderTest, BulkTableOpsWithoutTable) { builder.AddPassiveElementSegment(); WASM_FEATURE_SCOPE(bulk_memory); - EXPECT_FAILURE(v_v, WASM_TABLE_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)); - EXPECT_FAILURE(v_v, WASM_TABLE_DROP(0)); - EXPECT_FAILURE(v_v, WASM_TABLE_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)); + ExpectFailure(sigs.v_v(), + {WASM_TABLE_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)}); + ExpectFailure(sigs.v_v(), {WASM_ELEM_DROP(0)}); + ExpectFailure(sigs.v_v(), {WASM_TABLE_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)}); } class BranchTableIteratorTest : public TestWithZone { @@ -2926,252 +3225,146 @@ TEST_F(BranchTableIteratorTest, error0) { #undef CHECK_BR_TABLE_LENGTH #undef CHECK_BR_TABLE_ERROR +struct PrintOpcodes { + const byte* start; + const byte* end; +}; +std::ostream& operator<<(std::ostream& out, const PrintOpcodes& range) { + out << "First opcode: \"" + << WasmOpcodes::OpcodeName(static_cast<WasmOpcode>(*range.start)) + << "\"\nall bytes: ["; + for (const byte* b = range.start; b < range.end; ++b) { + out << (b == range.start ? "" : ", ") << uint32_t{*b} << "/" + << AsHex(*b, 2, true); + } + return out << "]"; +} + class WasmOpcodeLengthTest : public TestWithZone { public: WasmOpcodeLengthTest() : TestWithZone() {} -}; -#define EXPECT_LENGTH(expected, opcode) \ - { \ - static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \ - EXPECT_EQ(static_cast<unsigned>(expected), \ - OpcodeLength(code, code + sizeof(code))); \ - } - -#define EXPECT_LENGTH_N(expected, ...) \ - { \ - static const byte code[] = {__VA_ARGS__}; \ - EXPECT_EQ(static_cast<unsigned>(expected), \ - OpcodeLength(code, code + sizeof(code))); \ + template <typename... Bytes> + void ExpectLength(unsigned expected, Bytes... bytes) { + const byte code[] = {bytes..., 0, 0, 0, 0, 0, 0, 0, 0}; + EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))) + << PrintOpcodes{code, code + sizeof...(bytes)}; } +}; TEST_F(WasmOpcodeLengthTest, Statements) { - EXPECT_LENGTH(1, kExprNop); - EXPECT_LENGTH(1, kExprElse); - EXPECT_LENGTH(1, kExprEnd); - EXPECT_LENGTH(1, kExprSelect); - EXPECT_LENGTH(1, kExprCatch); - EXPECT_LENGTH(1, kExprRethrow); - EXPECT_LENGTH(2, kExprBr); - EXPECT_LENGTH(2, kExprBrIf); - EXPECT_LENGTH(2, kExprThrow); - EXPECT_LENGTH(3, kExprBrOnExn); - EXPECT_LENGTH_N(2, kExprBlock, kLocalI32); - EXPECT_LENGTH_N(2, kExprLoop, kLocalI32); - EXPECT_LENGTH_N(2, kExprIf, kLocalI32); - EXPECT_LENGTH_N(2, kExprTry, kLocalI32); + ExpectLength(1, kExprNop); + ExpectLength(1, kExprElse); + ExpectLength(1, kExprEnd); + ExpectLength(1, kExprSelect); + ExpectLength(1, kExprCatch); + ExpectLength(1, kExprRethrow); + ExpectLength(2, kExprBr); + ExpectLength(2, kExprBrIf); + ExpectLength(2, kExprThrow); + ExpectLength(3, kExprBrOnExn); + ExpectLength(2, kExprBlock, kLocalI32); + ExpectLength(2, kExprLoop, kLocalI32); + ExpectLength(2, kExprIf, kLocalI32); + ExpectLength(2, kExprTry, kLocalI32); } TEST_F(WasmOpcodeLengthTest, MiscExpressions) { - EXPECT_LENGTH(5, kExprF32Const); - EXPECT_LENGTH(9, kExprF64Const); - EXPECT_LENGTH(1, kExprRefNull); - EXPECT_LENGTH(2, kExprGetLocal); - EXPECT_LENGTH(2, kExprSetLocal); - EXPECT_LENGTH(2, kExprGetGlobal); - EXPECT_LENGTH(2, kExprSetGlobal); - EXPECT_LENGTH(2, kExprCallFunction); - EXPECT_LENGTH(3, kExprCallIndirect); + ExpectLength(5, kExprF32Const); + ExpectLength(9, kExprF64Const); + ExpectLength(1, kExprRefNull); + ExpectLength(2, kExprGetLocal); + ExpectLength(2, kExprSetLocal); + ExpectLength(2, kExprGetGlobal); + ExpectLength(2, kExprSetGlobal); + ExpectLength(2, kExprCallFunction); + ExpectLength(3, kExprCallIndirect); } TEST_F(WasmOpcodeLengthTest, I32Const) { - EXPECT_LENGTH_N(2, kExprI32Const, U32V_1(1)); - EXPECT_LENGTH_N(3, kExprI32Const, U32V_2(999)); - EXPECT_LENGTH_N(4, kExprI32Const, U32V_3(9999)); - EXPECT_LENGTH_N(5, kExprI32Const, U32V_4(999999)); - EXPECT_LENGTH_N(6, kExprI32Const, U32V_5(99999999)); + ExpectLength(2, kExprI32Const, U32V_1(1)); + ExpectLength(3, kExprI32Const, U32V_2(999)); + ExpectLength(4, kExprI32Const, U32V_3(9999)); + ExpectLength(5, kExprI32Const, U32V_4(999999)); + ExpectLength(6, kExprI32Const, U32V_5(99999999)); } TEST_F(WasmOpcodeLengthTest, I64Const) { - EXPECT_LENGTH_N(2, kExprI64Const, U32V_1(1)); - EXPECT_LENGTH_N(3, kExprI64Const, U32V_2(99)); - EXPECT_LENGTH_N(4, kExprI64Const, U32V_3(9999)); - EXPECT_LENGTH_N(5, kExprI64Const, U32V_4(99999)); - EXPECT_LENGTH_N(6, kExprI64Const, U32V_5(9999999)); - EXPECT_LENGTH_N(7, WASM_I64V_6(777777)); - EXPECT_LENGTH_N(8, WASM_I64V_7(7777777)); - EXPECT_LENGTH_N(9, WASM_I64V_8(77777777)); - EXPECT_LENGTH_N(10, WASM_I64V_9(777777777)); + ExpectLength(2, kExprI64Const, U32V_1(1)); + ExpectLength(3, kExprI64Const, U32V_2(99)); + ExpectLength(4, kExprI64Const, U32V_3(9999)); + ExpectLength(5, kExprI64Const, U32V_4(99999)); + ExpectLength(6, kExprI64Const, U32V_5(9999999)); + ExpectLength(7, WASM_I64V_6(777777)); + ExpectLength(8, WASM_I64V_7(7777777)); + ExpectLength(9, WASM_I64V_8(77777777)); + ExpectLength(10, WASM_I64V_9(777777777)); } TEST_F(WasmOpcodeLengthTest, VariableLength) { - EXPECT_LENGTH_N(2, kExprGetGlobal, U32V_1(1)); - EXPECT_LENGTH_N(3, kExprGetGlobal, U32V_2(33)); - EXPECT_LENGTH_N(4, kExprGetGlobal, U32V_3(44)); - EXPECT_LENGTH_N(5, kExprGetGlobal, U32V_4(66)); - EXPECT_LENGTH_N(6, kExprGetGlobal, U32V_5(77)); + ExpectLength(2, kExprGetGlobal, U32V_1(1)); + ExpectLength(3, kExprGetGlobal, U32V_2(33)); + ExpectLength(4, kExprGetGlobal, U32V_3(44)); + ExpectLength(5, kExprGetGlobal, U32V_4(66)); + ExpectLength(6, kExprGetGlobal, U32V_5(77)); } TEST_F(WasmOpcodeLengthTest, LoadsAndStores) { - EXPECT_LENGTH(3, kExprI32LoadMem8S); - EXPECT_LENGTH(3, kExprI32LoadMem8U); - EXPECT_LENGTH(3, kExprI32LoadMem16S); - EXPECT_LENGTH(3, kExprI32LoadMem16U); - EXPECT_LENGTH(3, kExprI32LoadMem); - EXPECT_LENGTH(3, kExprI64LoadMem8S); - EXPECT_LENGTH(3, kExprI64LoadMem8U); - EXPECT_LENGTH(3, kExprI64LoadMem16S); - EXPECT_LENGTH(3, kExprI64LoadMem16U); - EXPECT_LENGTH(3, kExprI64LoadMem32S); - EXPECT_LENGTH(3, kExprI64LoadMem32U); - EXPECT_LENGTH(3, kExprI64LoadMem); - EXPECT_LENGTH(3, kExprF32LoadMem); - EXPECT_LENGTH(3, kExprF64LoadMem); - - EXPECT_LENGTH(3, kExprI32StoreMem8); - EXPECT_LENGTH(3, kExprI32StoreMem16); - EXPECT_LENGTH(3, kExprI32StoreMem); - EXPECT_LENGTH(3, kExprI64StoreMem8); - EXPECT_LENGTH(3, kExprI64StoreMem16); - EXPECT_LENGTH(3, kExprI64StoreMem32); - EXPECT_LENGTH(3, kExprI64StoreMem); - EXPECT_LENGTH(3, kExprF32StoreMem); - EXPECT_LENGTH(3, kExprF64StoreMem); + ExpectLength(3, kExprI32LoadMem8S); + ExpectLength(3, kExprI32LoadMem8U); + ExpectLength(3, kExprI32LoadMem16S); + ExpectLength(3, kExprI32LoadMem16U); + ExpectLength(3, kExprI32LoadMem); + ExpectLength(3, kExprI64LoadMem8S); + ExpectLength(3, kExprI64LoadMem8U); + ExpectLength(3, kExprI64LoadMem16S); + ExpectLength(3, kExprI64LoadMem16U); + ExpectLength(3, kExprI64LoadMem32S); + ExpectLength(3, kExprI64LoadMem32U); + ExpectLength(3, kExprI64LoadMem); + ExpectLength(3, kExprF32LoadMem); + ExpectLength(3, kExprF64LoadMem); + + ExpectLength(3, kExprI32StoreMem8); + ExpectLength(3, kExprI32StoreMem16); + ExpectLength(3, kExprI32StoreMem); + ExpectLength(3, kExprI64StoreMem8); + ExpectLength(3, kExprI64StoreMem16); + ExpectLength(3, kExprI64StoreMem32); + ExpectLength(3, kExprI64StoreMem); + ExpectLength(3, kExprF32StoreMem); + ExpectLength(3, kExprF64StoreMem); } TEST_F(WasmOpcodeLengthTest, MiscMemExpressions) { - EXPECT_LENGTH(2, kExprMemorySize); - EXPECT_LENGTH(2, kExprMemoryGrow); + ExpectLength(2, kExprMemorySize); + ExpectLength(2, kExprMemoryGrow); } TEST_F(WasmOpcodeLengthTest, SimpleExpressions) { - EXPECT_LENGTH(1, kExprI32Add); - EXPECT_LENGTH(1, kExprI32Sub); - EXPECT_LENGTH(1, kExprI32Mul); - EXPECT_LENGTH(1, kExprI32DivS); - EXPECT_LENGTH(1, kExprI32DivU); - EXPECT_LENGTH(1, kExprI32RemS); - EXPECT_LENGTH(1, kExprI32RemU); - EXPECT_LENGTH(1, kExprI32And); - EXPECT_LENGTH(1, kExprI32Ior); - EXPECT_LENGTH(1, kExprI32Xor); - EXPECT_LENGTH(1, kExprI32Shl); - EXPECT_LENGTH(1, kExprI32ShrU); - EXPECT_LENGTH(1, kExprI32ShrS); - EXPECT_LENGTH(1, kExprI32Eq); - EXPECT_LENGTH(1, kExprI32Ne); - EXPECT_LENGTH(1, kExprI32LtS); - EXPECT_LENGTH(1, kExprI32LeS); - EXPECT_LENGTH(1, kExprI32LtU); - EXPECT_LENGTH(1, kExprI32LeU); - EXPECT_LENGTH(1, kExprI32GtS); - EXPECT_LENGTH(1, kExprI32GeS); - EXPECT_LENGTH(1, kExprI32GtU); - EXPECT_LENGTH(1, kExprI32GeU); - EXPECT_LENGTH(1, kExprI32Clz); - EXPECT_LENGTH(1, kExprI32Ctz); - EXPECT_LENGTH(1, kExprI32Popcnt); - EXPECT_LENGTH(1, kExprI32Eqz); - EXPECT_LENGTH(1, kExprI64Add); - EXPECT_LENGTH(1, kExprI64Sub); - EXPECT_LENGTH(1, kExprI64Mul); - EXPECT_LENGTH(1, kExprI64DivS); - EXPECT_LENGTH(1, kExprI64DivU); - EXPECT_LENGTH(1, kExprI64RemS); - EXPECT_LENGTH(1, kExprI64RemU); - EXPECT_LENGTH(1, kExprI64And); - EXPECT_LENGTH(1, kExprI64Ior); - EXPECT_LENGTH(1, kExprI64Xor); - EXPECT_LENGTH(1, kExprI64Shl); - EXPECT_LENGTH(1, kExprI64ShrU); - EXPECT_LENGTH(1, kExprI64ShrS); - EXPECT_LENGTH(1, kExprI64Eq); - EXPECT_LENGTH(1, kExprI64Ne); - EXPECT_LENGTH(1, kExprI64LtS); - EXPECT_LENGTH(1, kExprI64LeS); - EXPECT_LENGTH(1, kExprI64LtU); - EXPECT_LENGTH(1, kExprI64LeU); - EXPECT_LENGTH(1, kExprI64GtS); - EXPECT_LENGTH(1, kExprI64GeS); - EXPECT_LENGTH(1, kExprI64GtU); - EXPECT_LENGTH(1, kExprI64GeU); - EXPECT_LENGTH(1, kExprI64Clz); - EXPECT_LENGTH(1, kExprI64Ctz); - EXPECT_LENGTH(1, kExprI64Popcnt); - EXPECT_LENGTH(1, kExprF32Add); - EXPECT_LENGTH(1, kExprF32Sub); - EXPECT_LENGTH(1, kExprF32Mul); - EXPECT_LENGTH(1, kExprF32Div); - EXPECT_LENGTH(1, kExprF32Min); - EXPECT_LENGTH(1, kExprF32Max); - EXPECT_LENGTH(1, kExprF32Abs); - EXPECT_LENGTH(1, kExprF32Neg); - EXPECT_LENGTH(1, kExprF32CopySign); - EXPECT_LENGTH(1, kExprF32Ceil); - EXPECT_LENGTH(1, kExprF32Floor); - EXPECT_LENGTH(1, kExprF32Trunc); - EXPECT_LENGTH(1, kExprF32NearestInt); - EXPECT_LENGTH(1, kExprF32Sqrt); - EXPECT_LENGTH(1, kExprF32Eq); - EXPECT_LENGTH(1, kExprF32Ne); - EXPECT_LENGTH(1, kExprF32Lt); - EXPECT_LENGTH(1, kExprF32Le); - EXPECT_LENGTH(1, kExprF32Gt); - EXPECT_LENGTH(1, kExprF32Ge); - EXPECT_LENGTH(1, kExprF64Add); - EXPECT_LENGTH(1, kExprF64Sub); - EXPECT_LENGTH(1, kExprF64Mul); - EXPECT_LENGTH(1, kExprF64Div); - EXPECT_LENGTH(1, kExprF64Min); - EXPECT_LENGTH(1, kExprF64Max); - EXPECT_LENGTH(1, kExprF64Abs); - EXPECT_LENGTH(1, kExprF64Neg); - EXPECT_LENGTH(1, kExprF64CopySign); - EXPECT_LENGTH(1, kExprF64Ceil); - EXPECT_LENGTH(1, kExprF64Floor); - EXPECT_LENGTH(1, kExprF64Trunc); - EXPECT_LENGTH(1, kExprF64NearestInt); - EXPECT_LENGTH(1, kExprF64Sqrt); - EXPECT_LENGTH(1, kExprF64Eq); - EXPECT_LENGTH(1, kExprF64Ne); - EXPECT_LENGTH(1, kExprF64Lt); - EXPECT_LENGTH(1, kExprF64Le); - EXPECT_LENGTH(1, kExprF64Gt); - EXPECT_LENGTH(1, kExprF64Ge); - EXPECT_LENGTH(1, kExprI32SConvertF32); - EXPECT_LENGTH(1, kExprI32SConvertF64); - EXPECT_LENGTH(1, kExprI32UConvertF32); - EXPECT_LENGTH(1, kExprI32UConvertF64); - EXPECT_LENGTH(1, kExprI32ConvertI64); - EXPECT_LENGTH(1, kExprI64SConvertF32); - EXPECT_LENGTH(1, kExprI64SConvertF64); - EXPECT_LENGTH(1, kExprI64UConvertF32); - EXPECT_LENGTH(1, kExprI64UConvertF64); - EXPECT_LENGTH(1, kExprI64SConvertI32); - EXPECT_LENGTH(1, kExprI64UConvertI32); - EXPECT_LENGTH(1, kExprF32SConvertI32); - EXPECT_LENGTH(1, kExprF32UConvertI32); - EXPECT_LENGTH(1, kExprF32SConvertI64); - EXPECT_LENGTH(1, kExprF32UConvertI64); - EXPECT_LENGTH(1, kExprF32ConvertF64); - EXPECT_LENGTH(1, kExprF32ReinterpretI32); - EXPECT_LENGTH(1, kExprF64SConvertI32); - EXPECT_LENGTH(1, kExprF64UConvertI32); - EXPECT_LENGTH(1, kExprF64SConvertI64); - EXPECT_LENGTH(1, kExprF64UConvertI64); - EXPECT_LENGTH(1, kExprF64ConvertF32); - EXPECT_LENGTH(1, kExprF64ReinterpretI64); - EXPECT_LENGTH(1, kExprI32ReinterpretF32); - EXPECT_LENGTH(1, kExprI64ReinterpretF64); +#define SIMPLE_OPCODE(name, byte, sig) byte, + static constexpr uint8_t kSimpleOpcodes[] = { + FOREACH_SIMPLE_OPCODE(SIMPLE_OPCODE)}; +#undef SIMPLE_OPCODE + for (uint8_t simple_opcode : kSimpleOpcodes) { + ExpectLength(1, simple_opcode); + } } TEST_F(WasmOpcodeLengthTest, SimdExpressions) { #define TEST_SIMD(name, opcode, sig) \ - EXPECT_LENGTH_N(2, kSimdPrefix, static_cast<byte>(kExpr##name & 0xFF)); + ExpectLength(2, kSimdPrefix, static_cast<byte>(kExpr##name & 0xFF)); FOREACH_SIMD_0_OPERAND_OPCODE(TEST_SIMD) #undef TEST_SIMD #define TEST_SIMD(name, opcode, sig) \ - EXPECT_LENGTH_N(3, kSimdPrefix, static_cast<byte>(kExpr##name & 0xFF)); + ExpectLength(3, kSimdPrefix, static_cast<byte>(kExpr##name & 0xFF)); FOREACH_SIMD_1_OPERAND_OPCODE(TEST_SIMD) #undef TEST_SIMD - EXPECT_LENGTH_N(18, kSimdPrefix, static_cast<byte>(kExprS8x16Shuffle & 0xFF)); + ExpectLength(18, kSimdPrefix, static_cast<byte>(kExprS8x16Shuffle & 0xFF)); // test for bad simd opcode - EXPECT_LENGTH_N(2, kSimdPrefix, 0xFF); + ExpectLength(2, kSimdPrefix, 0xFF); } -#undef EXPECT_LENGTH -#undef EXPECT_LENGTH_N - typedef ZoneVector<ValueType> TypesOfLocals; class LocalDeclDecoderTest : public TestWithZone { @@ -3385,14 +3578,6 @@ TEST_F(BytecodeIteratorTest, WithLocalDecls) { #undef WASM_IF_OP #undef WASM_LOOP_OP #undef WASM_BRV_IF_ZERO -#undef EXPECT_VERIFIES_C -#undef EXPECT_FAILURE_C -#undef EXPECT_VERIFIES_SC -#undef EXPECT_FAILURE_SC -#undef EXPECT_VERIFIES_S -#undef EXPECT_FAILURE_S -#undef EXPECT_VERIFIES -#undef EXPECT_FAILURE } // namespace function_body_decoder_unittest } // namespace wasm diff --git a/deps/v8/test/unittests/wasm/module-decoder-unittest.cc b/deps/v8/test/unittests/wasm/module-decoder-unittest.cc index 3d99dffa72..b3b069b7cc 100644 --- a/deps/v8/test/unittests/wasm/module-decoder-unittest.cc +++ b/deps/v8/test/unittests/wasm/module-decoder-unittest.cc @@ -32,6 +32,9 @@ namespace module_decoder_unittest { #define WASM_INIT_EXPR_ANYREF WASM_REF_NULL, kExprEnd #define WASM_INIT_EXPR_GLOBAL(index) WASM_GET_GLOBAL(index), kExprEnd +#define REF_NULL_ELEMENT kExprRefNull, kExprEnd +#define REF_FUNC_ELEMENT(v) kExprRefFunc, U32V_1(v), kExprEnd + #define EMPTY_BODY 0 #define NOP_BODY 2, 0, kExprNop @@ -173,7 +176,9 @@ class WasmModuleVerifyTest : public TestWithIsolateAndZone { size_t total = sizeof(header) + size; auto temp = new byte[total]; memcpy(temp, header, sizeof(header)); - memcpy(temp + sizeof(header), module_start, size); + if (size > 0) { + memcpy(temp + sizeof(header), module_start, size); + } ModuleResult result = DecodeWasmModule( enabled_features_, temp, temp + total, false, kWasmOrigin, isolate()->counters(), isolate()->allocator()); @@ -582,7 +587,7 @@ TEST_F(WasmModuleVerifyTest, ExceptionSectionBeforeGlobal) { WASM_FEATURE_SCOPE(eh); ModuleResult result = DecodeModule(data, data + sizeof(data)); - EXPECT_NOT_OK(result, "unexpected section: Global"); + EXPECT_NOT_OK(result, "unexpected section <Global>"); } TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterMemoryBeforeGlobal) { @@ -594,7 +599,7 @@ TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterMemoryBeforeGlobal) { WASM_FEATURE_SCOPE(eh); ModuleResult result = DecodeModule(data, data + sizeof(data)); - EXPECT_NOT_OK(result, "unexpected section: Global"); + EXPECT_NOT_OK(result, "unexpected section <Global>"); } TEST_F(WasmModuleVerifyTest, ExceptionImport) { @@ -2256,8 +2261,8 @@ TEST_F(WasmModuleVerifyTest, PassiveElementSegment) { // table declaration ----------------------------------------------------- SECTION(Table, ENTRY_COUNT(1), kLocalAnyFunc, 0, 1), // element segments ----------------------------------------------------- - SECTION(Element, ENTRY_COUNT(1), PASSIVE, - ADD_COUNT(FUNC_INDEX(0), FUNC_INDEX(0))), + SECTION(Element, ENTRY_COUNT(1), PASSIVE, kLocalAnyFunc, U32V_1(3), + REF_FUNC_ELEMENT(0), REF_FUNC_ELEMENT(0), REF_NULL_ELEMENT), // code ------------------------------------------------------------------ ONE_EMPTY_BODY}; EXPECT_FAILURE(data); @@ -2266,6 +2271,22 @@ TEST_F(WasmModuleVerifyTest, PassiveElementSegment) { EXPECT_OFF_END_FAILURE(data, arraysize(data) - 5); } +TEST_F(WasmModuleVerifyTest, PassiveElementSegmentAnyRef) { + static const byte data[] = { + // sig#0 ----------------------------------------------------------------- + SIGNATURES_SECTION_VOID_VOID, + // funcs ----------------------------------------------------------------- + ONE_EMPTY_FUNCTION(SIG_INDEX(0)), + // table declaration ----------------------------------------------------- + SECTION(Table, ENTRY_COUNT(1), kLocalAnyFunc, 0, 1), + // element segments ----------------------------------------------------- + SECTION(Element, ENTRY_COUNT(1), PASSIVE, kLocalAnyRef, U32V_1(0)), + // code ------------------------------------------------------------------ + ONE_EMPTY_BODY}; + WASM_FEATURE_SCOPE(bulk_memory); + EXPECT_FAILURE(data); +} + TEST_F(WasmModuleVerifyTest, DataCountSectionCorrectPlacement) { static const byte data[] = {SECTION(Element, ENTRY_COUNT(0)), SECTION(DataCount, ENTRY_COUNT(0)), @@ -2289,7 +2310,7 @@ TEST_F(WasmModuleVerifyTest, DataCountSectionBeforeElement) { SECTION(Element, ENTRY_COUNT(0))}; WASM_FEATURE_SCOPE(bulk_memory); ModuleResult result = DecodeModule(data, data + sizeof(data)); - EXPECT_NOT_OK(result, "unexpected section: Element"); + EXPECT_NOT_OK(result, "unexpected section <Element>"); } TEST_F(WasmModuleVerifyTest, DataCountSectionAfterStartBeforeElement) { @@ -2307,7 +2328,7 @@ TEST_F(WasmModuleVerifyTest, DataCountSectionAfterStartBeforeElement) { }; WASM_FEATURE_SCOPE(bulk_memory); ModuleResult result = DecodeModule(data, data + sizeof(data)); - EXPECT_NOT_OK(result, "unexpected section: Element"); + EXPECT_NOT_OK(result, "unexpected section <Element>"); } TEST_F(WasmModuleVerifyTest, MultipleDataCountSections) { @@ -2373,6 +2394,8 @@ TEST_F(WasmModuleVerifyTest, DataCountSegmentCount_omitted) { #undef WASM_INIT_EXPR_F64 #undef WASM_INIT_EXPR_ANYREF #undef WASM_INIT_EXPR_GLOBAL +#undef REF_NULL_ELEMENT +#undef REF_FUNC_ELEMENT #undef EMPTY_BODY #undef NOP_BODY #undef SIG_ENTRY_i_i diff --git a/deps/v8/test/unittests/wasm/streaming-decoder-unittest.cc b/deps/v8/test/unittests/wasm/streaming-decoder-unittest.cc index a5b89762ad..765e5a74ff 100644 --- a/deps/v8/test/unittests/wasm/streaming-decoder-unittest.cc +++ b/deps/v8/test/unittests/wasm/streaming-decoder-unittest.cc @@ -20,9 +20,11 @@ namespace wasm { struct MockStreamingResult { size_t num_sections = 0; size_t num_functions = 0; - bool ok = true; + WasmError error; OwnedVector<uint8_t> received_bytes; + bool ok() const { return !error.has_error(); } + MockStreamingResult() = default; }; @@ -33,20 +35,20 @@ class MockStreamingProcessor : public StreamingProcessor { bool ProcessModuleHeader(Vector<const uint8_t> bytes, uint32_t offset) override { - // TODO(ahaas): Share code with the module-decoder. Decoder decoder(bytes.begin(), bytes.end()); uint32_t magic_word = decoder.consume_u32("wasm magic"); if (decoder.failed() || magic_word != kWasmMagic) { - result_->ok = false; + result_->error = WasmError(0, "expected wasm magic"); return false; } uint32_t magic_version = decoder.consume_u32("wasm version"); if (decoder.failed() || magic_version != kWasmVersion) { - result_->ok = false; + result_->error = WasmError(4, "expected wasm version"); return false; } return true; } + // Process all sections but the code section. bool ProcessSection(SectionCode section_code, Vector<const uint8_t> bytes, uint32_t offset) override { @@ -54,7 +56,7 @@ class MockStreamingProcessor : public StreamingProcessor { return true; } - bool ProcessCodeSectionHeader(size_t num_functions, uint32_t offset, + bool ProcessCodeSectionHeader(int num_functions, uint32_t offset, std::shared_ptr<WireBytesStorage>) override { return true; } @@ -74,14 +76,17 @@ class MockStreamingProcessor : public StreamingProcessor { } // Report an error detected in the StreamingDecoder. - void OnError(const WasmError&) override { result_->ok = false; } + void OnError(const WasmError& error) override { + result_->error = error; + CHECK(!result_->ok()); + } void OnAbort() override {} bool Deserialize(Vector<const uint8_t> module_bytes, Vector<const uint8_t> wire_bytes) override { return false; - }; + } private: MockStreamingResult* const result_; @@ -98,14 +103,14 @@ class WasmStreamingDecoderTest : public ::testing::Test { stream.OnBytesReceived(data.SubVector(0, split)); stream.OnBytesReceived(data.SubVector(split, data.length())); stream.Finish(); - EXPECT_TRUE(result.ok); + EXPECT_TRUE(result.ok()); EXPECT_EQ(expected_sections, result.num_sections); EXPECT_EQ(expected_functions, result.num_functions); EXPECT_EQ(data, result.received_bytes.as_vector()); } } - void ExpectFailure(Vector<const uint8_t> data) { + void ExpectFailure(Vector<const uint8_t> data, const char* message) { for (int split = 0; split <= data.length(); ++split) { MockStreamingResult result; StreamingDecoder stream( @@ -113,18 +118,17 @@ class WasmStreamingDecoderTest : public ::testing::Test { stream.OnBytesReceived(data.SubVector(0, split)); stream.OnBytesReceived(data.SubVector(split, data.length())); stream.Finish(); - EXPECT_FALSE(result.ok); + EXPECT_FALSE(result.ok()); + EXPECT_EQ(message, result.error.message()); } } - - MockStreamingResult result; }; TEST_F(WasmStreamingDecoderTest, EmptyStream) { MockStreamingResult result; StreamingDecoder stream(base::make_unique<MockStreamingProcessor>(&result)); stream.Finish(); - EXPECT_FALSE(result.ok); + EXPECT_FALSE(result.ok()); } TEST_F(WasmStreamingDecoderTest, IncompleteModuleHeader) { @@ -134,10 +138,11 @@ TEST_F(WasmStreamingDecoderTest, IncompleteModuleHeader) { StreamingDecoder stream(base::make_unique<MockStreamingProcessor>(&result)); stream.OnBytesReceived(Vector<const uint8_t>(data, 1)); stream.Finish(); - EXPECT_FALSE(result.ok); + EXPECT_FALSE(result.ok()); } for (int length = 1; length < static_cast<int>(arraysize(data)); ++length) { - ExpectFailure(Vector<const uint8_t>(data, length)); + ExpectFailure(Vector<const uint8_t>(data, length), + "unexpected end of stream"); } } @@ -149,14 +154,14 @@ TEST_F(WasmStreamingDecoderTest, MagicAndVersion) { TEST_F(WasmStreamingDecoderTest, BadMagic) { for (uint32_t x = 1; x; x <<= 1) { const uint8_t data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion)}; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "expected wasm magic"); } } TEST_F(WasmStreamingDecoderTest, BadVersion) { for (uint32_t x = 1; x; x <<= 1) { const uint8_t data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion ^ x)}; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "expected wasm version"); } } @@ -243,7 +248,7 @@ TEST_F(WasmStreamingDecoderTest, OneSectionNotEnoughPayload1) { 0x0, // 4 0x0 // 5 }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "unexpected end of stream"); } TEST_F(WasmStreamingDecoderTest, OneSectionNotEnoughPayload2) { @@ -254,7 +259,7 @@ TEST_F(WasmStreamingDecoderTest, OneSectionNotEnoughPayload2) { 0x6, // Section Length 0x0 // Payload }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "unexpected end of stream"); } TEST_F(WasmStreamingDecoderTest, OneSectionInvalidLength) { @@ -262,13 +267,13 @@ TEST_F(WasmStreamingDecoderTest, OneSectionInvalidLength) { U32_LE(kWasmMagic), // -- U32_LE(kWasmVersion), // -- 0x1, // Section ID - 0x80, // Section Length (0 in LEB) + 0x80, // Section Length (invalid LEB) 0x80, // -- 0x80, // -- 0x80, // -- 0x80, // -- }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "expected section length"); } TEST_F(WasmStreamingDecoderTest, TwoLongSections) { @@ -383,7 +388,7 @@ TEST_F(WasmStreamingDecoderTest, EmptyFunction) { 0x1, // Number of Functions 0x0, // Function Length }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "invalid function length (0)"); } TEST_F(WasmStreamingDecoderTest, TwoFunctions) { @@ -440,7 +445,7 @@ TEST_F(WasmStreamingDecoderTest, CodeSectionLengthZero) { kCodeSectionCode, // Section ID 0x0, // Section Length }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "code section cannot have size 0"); } TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooHigh) { @@ -461,7 +466,7 @@ TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooHigh) { 0x1, // Function Length 0x0, // Function }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "not all code section bytes were used"); } TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooHighZeroFunctions) { @@ -472,7 +477,7 @@ TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooHighZeroFunctions) { 0xD, // Section Length 0x0, // Number of Functions }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "not all code section bytes were used"); } TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooLow) { @@ -493,7 +498,7 @@ TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooLow) { 0x1, // Function Length 0x0, // Function }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "read past code section end"); } TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooLowEndsInNumFunctions) { @@ -516,7 +521,7 @@ TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooLowEndsInNumFunctions) { 0x1, // Function Length 0x0, // Function }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "invalid code section length"); } TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooLowEndsInFunctionLength) { @@ -541,7 +546,7 @@ TEST_F(WasmStreamingDecoderTest, CodeSectionLengthTooLowEndsInFunctionLength) { 0x1, // Function Length 0x0, // Function }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "read past code section end"); } TEST_F(WasmStreamingDecoderTest, NumberOfFunctionsTooHigh) { @@ -562,7 +567,7 @@ TEST_F(WasmStreamingDecoderTest, NumberOfFunctionsTooHigh) { 0x1, // Function Length 0x0, // Function }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "unexpected end of stream"); } TEST_F(WasmStreamingDecoderTest, NumberOfFunctionsTooLow) { @@ -586,7 +591,7 @@ TEST_F(WasmStreamingDecoderTest, NumberOfFunctionsTooLow) { 0x0, // 6 0x0, // 7 }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "not all code section bytes were used"); } TEST_F(WasmStreamingDecoderTest, TwoCodeSections) { @@ -604,7 +609,7 @@ TEST_F(WasmStreamingDecoderTest, TwoCodeSections) { 0x1, // Function Length 0x0, // Function }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "code section can only appear once"); } TEST_F(WasmStreamingDecoderTest, UnknownSection) { @@ -645,7 +650,7 @@ TEST_F(WasmStreamingDecoderTest, UnknownSectionSandwich) { 0x1, // Function Length 0x0, // Function }; - ExpectFailure(ArrayVector(data)); + ExpectFailure(ArrayVector(data), "code section can only appear once"); } } // namespace wasm diff --git a/deps/v8/test/unittests/wasm/trap-handler-x64-unittest.cc b/deps/v8/test/unittests/wasm/trap-handler-x64-unittest.cc index 8c42b1735c..6baf42e076 100644 --- a/deps/v8/test/unittests/wasm/trap-handler-x64-unittest.cc +++ b/deps/v8/test/unittests/wasm/trap-handler-x64-unittest.cc @@ -468,9 +468,9 @@ TEST_P(TrapHandlerTest, TestCrashInOtherThread) { *trap_handler::GetThreadInWasmThreadLocalAddress() = 0; } -INSTANTIATE_TEST_CASE_P(/* no prefix */, TrapHandlerTest, - ::testing::Values(kDefault, kCallback), - PrintTrapHandlerTestParam); +INSTANTIATE_TEST_SUITE_P(/* no prefix */, TrapHandlerTest, + ::testing::Values(kDefault, kCallback), + PrintTrapHandlerTestParam); #undef __ } // namespace wasm diff --git a/deps/v8/test/unittests/wasm/wasm-code-manager-unittest.cc b/deps/v8/test/unittests/wasm/wasm-code-manager-unittest.cc index e90c97f3a1..e43f0ab5f9 100644 --- a/deps/v8/test/unittests/wasm/wasm-code-manager-unittest.cc +++ b/deps/v8/test/unittests/wasm/wasm-code-manager-unittest.cc @@ -165,8 +165,8 @@ class WasmCodeManagerTest : public TestWithContext, std::shared_ptr<WasmModule> module(new WasmModule); module->num_declared_functions = kNumFunctions; bool can_request_more = style == Growable; - return manager()->NewNativeModule(i_isolate(), kAllWasmFeatures, size, - can_request_more, std::move(module)); + return engine()->NewNativeModule(i_isolate(), kAllWasmFeatures, size, + can_request_more, std::move(module)); } WasmCode* AddCode(NativeModule* native_module, uint32_t index, size_t size) { @@ -175,24 +175,24 @@ class WasmCodeManagerTest : public TestWithContext, std::unique_ptr<byte[]> exec_buff(new byte[size]); desc.buffer = exec_buff.get(); desc.instr_size = static_cast<int>(size); - return native_module->AddCode(index, desc, 0, 0, 0, {}, OwnedVector<byte>(), + return native_module->AddCode(index, desc, 0, 0, {}, OwnedVector<byte>(), WasmCode::kFunction, WasmCode::kOther); } size_t page() const { return AllocatePageSize(); } - WasmCodeManager* manager() { - return i_isolate()->wasm_engine()->code_manager(); - } + WasmEngine* engine() { return i_isolate()->wasm_engine(); } + + WasmCodeManager* manager() { return engine()->code_manager(); } void SetMaxCommittedMemory(size_t limit) { manager()->SetMaxCommittedMemoryForTesting(limit); } }; -INSTANTIATE_TEST_CASE_P(Parameterized, WasmCodeManagerTest, - ::testing::Values(Fixed, Growable), - PrintWasmCodeManageTestParam); +INSTANTIATE_TEST_SUITE_P(Parameterized, WasmCodeManagerTest, + ::testing::Values(Fixed, Growable), + PrintWasmCodeManageTestParam); TEST_P(WasmCodeManagerTest, EmptyCase) { SetMaxCommittedMemory(0 * page()); diff --git a/deps/v8/test/unittests/zone/segmentpool-unittest.cc b/deps/v8/test/unittests/zone/segmentpool-unittest.cc deleted file mode 100644 index b3556a9519..0000000000 --- a/deps/v8/test/unittests/zone/segmentpool-unittest.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2016 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "src/zone/accounting-allocator.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace v8 { -namespace internal { - -TEST(Zone, SegmentPoolConstraints) { - size_t sizes[]{ - 0, // Corner case - AccountingAllocator::kMaxPoolSize, - GB // Something really large - }; - - AccountingAllocator allocator; - for (size_t size : sizes) { - allocator.ConfigureSegmentPool(size); - size_t total_size = 0; - for (size_t power = 0; power < AccountingAllocator::kNumberBuckets; - ++power) { - total_size += - allocator.unused_segments_max_sizes_[power] * (size_t(1) << power); - } - EXPECT_LE(total_size, size); - } -} - -} // namespace internal -} // namespace v8 |