Skip to content

Commit 670f154

Browse files
committed
Enhance wasm mutator fuzz tests with improved argument logging
1 parent 419d093 commit 670f154

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

tests/fuzz/wasm-mutator-fuzz/wasm_mutator_fuzz.cc

+44-10
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ random_gen_val(wasm_valkind_t kind)
3737
return wasm_val_t{ .kind = WASM_F64, .of = { .f64 = dis(gen) } };
3838
}
3939
else if (kind == WASM_EXTERNREF) {
40-
// TODO:
41-
return wasm_val_t{ .kind = WASM_EXTERNREF, .of = { .foreign = 0 } };
40+
std::uniform_int_distribution<uintptr_t> dis;
41+
return wasm_val_t{ .kind = WASM_EXTERNREF,
42+
.of = { .foreign = dis(gen) } };
4243
}
4344
else if (kind == WASM_FUNCREF) {
44-
// TODO:
4545
return wasm_val_t{ .kind = WASM_FUNCREF, .of = { .ref = nullptr } };
4646
}
47+
// TODO:v128
4748
else {
48-
assert(0);
49+
assert(0 && "unsupported value kind");
4950
}
5051
}
5152

@@ -88,18 +89,53 @@ execute_export_functions(wasm_module_t module, wasm_module_inst_t inst)
8889

8990
/* execute the function */
9091
wasm_exec_env_t exec_env = wasm_runtime_get_exec_env_singleton(inst);
92+
93+
{
94+
std::cout << "[EXECUTION] " << export_type.name << "(";
95+
for (unsigned p_i = 0; p_i < param_count; p_i++) {
96+
if (p_i != 0) {
97+
std::cout << ", ";
98+
}
99+
100+
if (args[p_i].kind == WASM_I32) {
101+
std::cout << "i32:" << args[p_i].of.i32;
102+
}
103+
else if (args[p_i].kind == WASM_I64) {
104+
std::cout << "i64:" << args[p_i].of.i64;
105+
}
106+
else if (args[p_i].kind == WASM_F32) {
107+
std::cout << "f32:" << args[p_i].of.f32;
108+
}
109+
else if (args[p_i].kind == WASM_F64) {
110+
std::cout << "f64:" << args[p_i].of.f64;
111+
}
112+
else if (args[p_i].kind == WASM_EXTERNREF) {
113+
std::cout << "externref:" << args[p_i].of.foreign;
114+
}
115+
else if (args[p_i].kind == WASM_FUNCREF) {
116+
std::cout << "funcref:" << args[p_i].of.ref;
117+
}
118+
// TODO:v128
119+
else {
120+
assert(0 && "unsupported value kind");
121+
}
122+
}
123+
124+
std::cout << ")";
125+
}
126+
91127
bool ret =
92128
wasm_runtime_call_wasm_a(exec_env, func, result_count,
93129
results.data(), param_count, args.data());
94130
if (!ret) {
95131
const char *exception = wasm_runtime_get_exception(inst);
96132
if (!exception) {
97-
std::cout << "Failed to execute function: " << export_type.name
98-
<< ". No exception info." << std::endl;
133+
std::cout << "[EXECUTION] " << export_type.name
134+
<< "() failed. No exception info." << std::endl;
99135
}
100136
else {
101-
std::cout << "Failed to execute function: " << export_type.name
102-
<< ". " << exception << std::endl;
137+
std::cout << "[EXECUTION] " << export_type.name << "() failed. "
138+
<< exception << std::endl;
103139
}
104140
}
105141

@@ -141,8 +177,6 @@ LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
141177

142178
execute_export_functions(module, inst);
143179

144-
std::cout << "PASS" << std::endl;
145-
146180
wasm_runtime_deinstantiate(inst);
147181
wasm_runtime_unload(module);
148182
wasm_runtime_destroy();

0 commit comments

Comments
 (0)