Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fuzzing] execute every exported function #3959

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enhance wasm mutator fuzz tests with improved argument logging
  • Loading branch information
lum1n0us committed Dec 24, 2024
commit 670f154f017b6766898f7789f6b1cf452c951787
54 changes: 44 additions & 10 deletions tests/fuzz/wasm-mutator-fuzz/wasm_mutator_fuzz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ random_gen_val(wasm_valkind_t kind)
return wasm_val_t{ .kind = WASM_F64, .of = { .f64 = dis(gen) } };
}
else if (kind == WASM_EXTERNREF) {
// TODO:
return wasm_val_t{ .kind = WASM_EXTERNREF, .of = { .foreign = 0 } };
std::uniform_int_distribution<uintptr_t> dis;
return wasm_val_t{ .kind = WASM_EXTERNREF,
.of = { .foreign = dis(gen) } };
}
else if (kind == WASM_FUNCREF) {
// TODO:
return wasm_val_t{ .kind = WASM_FUNCREF, .of = { .ref = nullptr } };
}
// TODO:v128
else {
assert(0);
assert(0 && "unsupported value kind");
}
}

Expand Down Expand Up @@ -88,18 +89,53 @@ execute_export_functions(wasm_module_t module, wasm_module_inst_t inst)

/* execute the function */
wasm_exec_env_t exec_env = wasm_runtime_get_exec_env_singleton(inst);

{
std::cout << "[EXECUTION] " << export_type.name << "(";
for (unsigned p_i = 0; p_i < param_count; p_i++) {
if (p_i != 0) {
std::cout << ", ";
}

if (args[p_i].kind == WASM_I32) {
std::cout << "i32:" << args[p_i].of.i32;
}
else if (args[p_i].kind == WASM_I64) {
std::cout << "i64:" << args[p_i].of.i64;
}
else if (args[p_i].kind == WASM_F32) {
std::cout << "f32:" << args[p_i].of.f32;
}
else if (args[p_i].kind == WASM_F64) {
std::cout << "f64:" << args[p_i].of.f64;
}
else if (args[p_i].kind == WASM_EXTERNREF) {
std::cout << "externref:" << args[p_i].of.foreign;
}
else if (args[p_i].kind == WASM_FUNCREF) {
std::cout << "funcref:" << args[p_i].of.ref;
}
// TODO:v128
else {
assert(0 && "unsupported value kind");
}
}

std::cout << ")";
}

bool ret =
wasm_runtime_call_wasm_a(exec_env, func, result_count,
results.data(), param_count, args.data());
if (!ret) {
const char *exception = wasm_runtime_get_exception(inst);
if (!exception) {
std::cout << "Failed to execute function: " << export_type.name
<< ". No exception info." << std::endl;
std::cout << "[EXECUTION] " << export_type.name
<< "() failed. No exception info." << std::endl;
}
else {
std::cout << "Failed to execute function: " << export_type.name
<< ". " << exception << std::endl;
std::cout << "[EXECUTION] " << export_type.name << "() failed. "
<< exception << std::endl;
}
}

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

execute_export_functions(module, inst);

std::cout << "PASS" << std::endl;

wasm_runtime_deinstantiate(inst);
wasm_runtime_unload(module);
wasm_runtime_destroy();
Expand Down