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

Unified Diff: test/unittests/wasm/asm-types-unittest.cc

Issue 2078053002: V8. ASM-2-WASM. Another asm-types.h revision. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: git pull Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/wasm/asm-types.cc ('K') | « src/wasm/asm-types.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/wasm/asm-types-unittest.cc
diff --git a/test/unittests/wasm/asm-types-unittest.cc b/test/unittests/wasm/asm-types-unittest.cc
index 49f4320a8e60f2d4e83cd2ac491c362f46bad432..c377d760c95c0ba2c09ea74d3cc6d9254f61be2b 100644
--- a/test/unittests/wasm/asm-types-unittest.cc
+++ b/test/unittests/wasm/asm-types-unittest.cc
@@ -225,8 +225,16 @@ TEST_F(AsmTypeTest, Names) {
StrEq("(int, int...) -> signed"));
EXPECT_THAT(Type::MinMaxType(zone(), Type::Float(), Type::Floatish())->Name(),
StrEq("(floatish, floatish...) -> float"));
- EXPECT_THAT(Type::MinMaxType(zone(), Type::Double(), Type::Double())->Name(),
- StrEq("(double, double...) -> double"));
+ EXPECT_THAT(Type::MinMaxType(zone(), Type::Double(), Type::DoubleQ())->Name(),
+ StrEq("(double?, double?...) -> double"));
+
+ EXPECT_THAT(Type::FFIType(zone())->Name(), StrEq("Function"));
+
+ EXPECT_THAT(Type::FunctionTableType(zone(), 4)->Name(),
+ StrEq("[unbound][4]"));
+ auto* ft = Type::FunctionTableType(zone(), 15);
+ ft->AsFunctionTableType()->set_signature(Function(Type::Double)(Type::Int));
+ EXPECT_THAT(ft->Name(), StrEq("(int) -> double[15]"));
}
TEST_F(AsmTypeTest, IsExactly) {
@@ -240,6 +248,7 @@ TEST_F(AsmTypeTest, IsExactly) {
Function(Type::Int)(Type::Int, Type::Int),
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
Function(Type::Int)(Type::Float), Type::FroundType(zone()),
+ Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
};
for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
@@ -263,6 +272,7 @@ TEST_F(AsmTypeTest, IsA) {
Function(Type::Int)(Type::Int, Type::Int),
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
Function(Type::Int)(Type::Float), Type::FroundType(zone()),
+ Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
};
for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
@@ -357,6 +367,67 @@ TEST_F(AsmTypeTest, ValidateCall) {
EXPECT_EQ(Type::Int(), overload->AsCallableType()->ValidateCall(idif2i));
EXPECT_EQ(Type::None(), overload->AsCallableType()->ValidateCall(i2d));
EXPECT_EQ(Type::None(), i2f->AsCallableType()->ValidateCall(i2d));
+
+ auto* ffi = Type::FFIType(zone());
+ AsmType* (*kReturnTypes[])() = {
+ Type::Void, Type::Double, Type::Signed,
+ };
+ AsmType* (*kExternTypes[])() = {
+ Type::Double, Type::Signed, Type::FixNum,
+ };
+ for (size_t ii = 0; ii < arraysize(kReturnTypes); ++ii) {
+ for (size_t jj = 0; jj < arraysize(kExternTypes); ++jj) {
+ auto* f = Function(kReturnTypes[ii])(kExternTypes[jj]);
+ EXPECT_EQ(kReturnTypes[ii](), ffi->AsCallableType()->ValidateCall(f))
+ << kReturnTypes[ii]()->Name();
+
+ // Call with extern type should fail.
bradnelson 2016/06/17 23:38:50 Comment seems off here
John 2016/06/20 15:09:53 Done.
+ f = Function(kReturnTypes[ii])(kExternTypes[jj], Type::Int);
+ EXPECT_EQ(Type::None(), ffi->AsCallableType()->ValidateCall(f))
+ << kReturnTypes[ii]()->Name();
+ }
+ }
+
+ auto* ft0 = Type::FunctionTableType(zone(), 10);
+ ft0->AsFunctionTableType()->set_signature(fi2d);
+ EXPECT_EQ(Type::Double(), ft0->AsCallableType()->ValidateCall(fi2d));
+ EXPECT_EQ(Type::None(), ft0->AsCallableType()->ValidateCall(i2d));
+
+ auto* ft1 = Type::FunctionTableType(zone(), 10);
+ EXPECT_EQ(Type::Double(), ft1->AsCallableType()->ValidateCall(fi2d));
+ EXPECT_EQ(Type::Double(), ft1->AsCallableType()->ValidateCall(fi2d));
+ EXPECT_EQ(Type::None(), ft1->AsCallableType()->ValidateCall(i2d));
+}
+
+TEST_F(AsmTypeTest, ToReturnType) {
+ std::unordered_map<AsmType*, AsmType*> kToReturnType = {
+ {Type::Signed(), Type::Signed()}, {Type::FixNum(), Type::Signed()},
+ {Type::Double(), Type::Double()}, {Type::Float(), Type::Float()},
+ {Type::Void(), Type::Void()},
+ };
+
+ Type* test_types[] = {
+#define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
+ FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
+#undef CREATE
+ Function(Type::Int)(Type::Double),
+ Function(Type::Int)(Type::DoubleQ),
+ Overload(Function(Type::Int)(Type::Double)),
+ Function(Type::Int)(Type::Int, Type::Int),
+ Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
+ Function(Type::Int)(Type::Float), Type::FroundType(zone()),
+ Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
+ };
+
+ for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
+ auto* return_type = Type::None();
+ auto to_return_type_iter = kToReturnType.find(test_types[ii]);
+ if (to_return_type_iter != kToReturnType.end()) {
+ return_type = to_return_type_iter->second;
+ }
+ EXPECT_EQ(return_type, test_types[ii]->ToReturnType())
+ << return_type->Name() << " != " << test_types[ii]->ToReturnType();
+ }
}
TEST_F(AsmTypeTest, IsReturnType) {
@@ -370,6 +441,7 @@ TEST_F(AsmTypeTest, IsReturnType) {
Function(Type::Int)(Type::Int, Type::Int),
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
Function(Type::Int)(Type::Float), Type::FroundType(zone()),
+ Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
};
std::unordered_set<Type*> return_types{
@@ -384,6 +456,38 @@ TEST_F(AsmTypeTest, IsReturnType) {
}
}
+TEST_F(AsmTypeTest, ToParameterType) {
+ std::unordered_map<AsmType*, AsmType*> kToParameterType = {
+ {Type::Int(), Type::Int()}, {Type::Signed(), Type::Int()},
+ {Type::Unsigned(), Type::Int()}, {Type::FixNum(), Type::Int()},
+ {Type::Double(), Type::Double()}, {Type::Float(), Type::Float()},
+ };
+
+ Type* test_types[] = {
+#define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
+ FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
+#undef CREATE
+ Function(Type::Int)(Type::Double),
+ Function(Type::Int)(Type::DoubleQ),
+ Overload(Function(Type::Int)(Type::Double)),
+ Function(Type::Int)(Type::Int, Type::Int),
+ Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
+ Function(Type::Int)(Type::Float), Type::FroundType(zone()),
+ Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
+ };
+
+ for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
+ auto* parameter_type = Type::None();
+ auto to_parameter_type_iter = kToParameterType.find(test_types[ii]);
+ if (to_parameter_type_iter != kToParameterType.end()) {
+ parameter_type = to_parameter_type_iter->second;
+ }
+ EXPECT_EQ(parameter_type, test_types[ii]->ToParameterType())
+ << parameter_type->Name()
+ << " != " << test_types[ii]->ToParameterType();
+ }
+}
+
TEST_F(AsmTypeTest, IsParameterType) {
Type* test_types[] = {
#define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
@@ -395,6 +499,7 @@ TEST_F(AsmTypeTest, IsParameterType) {
Function(Type::Int)(Type::Int, Type::Int),
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
Function(Type::Int)(Type::Float), Type::FroundType(zone()),
+ Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
};
std::unordered_set<Type*> parameter_types{
@@ -421,6 +526,7 @@ TEST_F(AsmTypeTest, IsComparableType) {
Function(Type::Int)(Type::Int, Type::Int),
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
Function(Type::Int)(Type::Float), Type::FroundType(zone()),
+ Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
};
std::unordered_set<Type*> comparable_types{
@@ -447,6 +553,7 @@ TEST_F(AsmTypeTest, ElementSizeInBytes) {
Function(Type::Int)(Type::Int, Type::Int),
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
Function(Type::Int)(Type::Float), Type::FroundType(zone()),
+ Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
};
auto ElementSizeInBytesForType = [](Type* type) -> int32_t {
@@ -483,6 +590,7 @@ TEST_F(AsmTypeTest, LoadType) {
Function(Type::Int)(Type::Int, Type::Int),
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
Function(Type::Int)(Type::Float), Type::FroundType(zone()),
+ Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
};
auto LoadTypeForType = [](Type* type) -> Type* {
@@ -519,6 +627,7 @@ TEST_F(AsmTypeTest, StoreType) {
Function(Type::Int)(Type::Int, Type::Int),
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
Function(Type::Int)(Type::Float), Type::FroundType(zone()),
+ Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
};
auto StoreTypeForType = [](Type* type) -> Type* {
« src/wasm/asm-types.cc ('K') | « src/wasm/asm-types.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698