Skip to content

Commit bdd9f9b

Browse files
committed
Fuzzing stubs for defined types.
1 parent 86c9dcd commit bdd9f9b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

test/gtest/type-domains.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,10 @@ fuzztest::Domain<HeapTypePlan> AvailableStrictSubHeapType(TypeBuilderPlan plan,
496496
return matchingOrAbstract(
497497
[](auto kind) { return kind == ContKind; },
498498
fuzztest::Just(HeapType(HeapTypes::nocont.getBasic(share))));
499+
case HeapType::handler:
500+
return matchingOrAbstract(
501+
[](auto kind) { return kind == HandlerKind; },
502+
fuzztest::Just(HeapType(HeapTypes::nocont.getBasic(share))));
499503
case HeapType::any:
500504
return matchingOrAbstract(
501505
[](auto kind) { return kind == StructKind || kind == ArrayKind; },
@@ -532,6 +536,7 @@ fuzztest::Domain<HeapTypePlan> AvailableStrictSubHeapType(TypeBuilderPlan plan,
532536
case HeapType::nofunc:
533537
case HeapType::nocont:
534538
case HeapType::noexn:
539+
case HeapType::nohandler:
535540
// No strict subtypes, so just return super.
536541
return fuzztest::Just(super);
537542
}
@@ -586,6 +591,7 @@ AvailableStrictSuperHeapType(TypeBuilderPlan plan, HeapTypePlan sub) {
586591
case HeapType::cont:
587592
case HeapType::any:
588593
case HeapType::exn:
594+
case HeapType::handler:
589595
// No strict supertypes, so just return sub.
590596
return fuzztest::Just(sub);
591597
case HeapType::eq:
@@ -617,6 +623,10 @@ AvailableStrictSuperHeapType(TypeBuilderPlan plan, HeapTypePlan sub) {
617623
return matchingOrAbstract(
618624
[](auto kind) { return kind == ContKind; },
619625
fuzztest::Just(HeapType(HeapTypes::cont.getBasic(share))));
626+
case HeapType::nohandler:
627+
return matchingOrAbstract(
628+
[](auto kind) { return kind == HandlerKind; },
629+
fuzztest::Just(HeapType(HeapTypes::handler.getBasic(share))));
620630
case HeapType::noexn:
621631
return fuzztest::Just(
622632
HeapTypePlan{HeapType(HeapTypes::exn.getBasic(share))});
@@ -1134,6 +1144,15 @@ void TestBuiltTypes(std::pair<std::vector<HeapType>, TypeBuilderPlan> pair) {
11341144
}
11351145
};
11361146

1147+
auto checkHandler = [&](HandlerPlan& plan, HeapType type) {
1148+
ASSERT_TRUE(type.isHandler());
1149+
auto value_types = type.getHandler().value_types;
1150+
ASSERT_EQ(plan.size(), value_types.size());
1151+
for (size_t i = 0; i < plan.size(); ++i) {
1152+
checkType(plan[i], value_types[i]);
1153+
}
1154+
};
1155+
11371156
auto checkDef = [&](TypeDefPlan& plan, HeapType type) {
11381157
if (auto* f = plan.getFunc()) {
11391158
checkFunc(*f, type);
@@ -1143,6 +1162,8 @@ void TestBuiltTypes(std::pair<std::vector<HeapType>, TypeBuilderPlan> pair) {
11431162
checkArray(*a, type);
11441163
} else if (auto* c = plan.getCont()) {
11451164
checkCont(*c, type);
1165+
} else if (auto* h = plan.getHandler()) {
1166+
checkCont(*h, type);
11461167
} else {
11471168
WASM_UNREACHABLE("unexpected variant");
11481169
}

test/gtest/type-domains.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ inline fuzztest::Domain<HeapType> ArbitraryUnsharedAbstractHeapType() {
3131
HeapTypes::ext,
3232
HeapTypes::func,
3333
HeapTypes::cont,
34+
HeapTypes::handler,
3435
HeapTypes::any,
3536
HeapTypes::eq,
3637
HeapTypes::i31,
@@ -43,6 +44,7 @@ inline fuzztest::Domain<HeapType> ArbitraryUnsharedAbstractHeapType() {
4344
HeapTypes::nofunc,
4445
HeapTypes::nocont,
4546
HeapTypes::noexn,
47+
HeapTypes::nohandler,
4648
});
4749
}
4850

@@ -67,7 +69,13 @@ inline fuzztest::Domain<Type> ArbitraryNonRefType() {
6769
std::vector<Type>{Type::i32, Type::i64, Type::f32, Type::f64, Type::v128});
6870
}
6971

70-
enum UnsharedTypeKind { FuncKind, StructKind, ArrayKind, ContKind };
72+
enum UnsharedTypeKind {
73+
FuncKind,
74+
StructKind,
75+
ArrayKind,
76+
ContKind,
77+
HandlerKind
78+
};
7179

7280
struct TypeKind {
7381
UnsharedTypeKind kind;
@@ -108,12 +116,15 @@ using ArrayPlan = FieldPlan;
108116
// If there is no available func type definition, this will be nullopt and we
109117
// will have to use a default fallback.
110118
using ContPlan = std::optional<size_t>;
119+
using HandlerPlan = std::vector<TypePlan>;
111120

112-
struct TypeDefPlan : std::variant<FuncPlan, StructPlan, ArrayPlan, ContPlan> {
121+
struct TypeDefPlan
122+
: std::variant<FuncPlan, StructPlan, ArrayPlan, ContPlan, HandlerPlan> {
113123
FuncPlan* getFunc() { return std::get_if<FuncPlan>(this); }
114124
StructPlan* getStruct() { return std::get_if<StructPlan>(this); }
115125
ArrayPlan* getArray() { return std::get_if<ArrayPlan>(this); }
116126
ContPlan* getCont() { return std::get_if<ContPlan>(this); }
127+
HandlerPlan* getHandler() { return std::get_if<HandlerPlan>(this); }
117128
};
118129

119130
struct TypeBuilderPlan {

0 commit comments

Comments
 (0)