Skip to content

Commit

Permalink
prepare coverage + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pannous committed Dec 23, 2024
1 parent e191d0a commit 25b391e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 41 deletions.
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,18 @@ if (TRACE)
# add_compile_options(-Wall)
# add_compile_options(-Wextra)
endif ()
#add_compile_options(-enable-coverage)
add_compile_options(--coverage)
add_compile_options(-ftest-coverage)
add_compile_options(-fprofile-arcs)
#add_compile_options(-fprofile-generate)
#add_compile_options(-fprofile-use)
#add_compile_options(-fprofile-dir=${CMAKE_BINARY_DIR}/coverage)
#add_compile_options(-fprofile-update=atomic)
#add_compile_options(-fprofile-correction)
#add_compile_options(-fprofile-abs-path)
#add_compile_options(-fprofile-use=atomic)
#add_compile_options(-fprofile-use=correction)

if (SANITIZE) # OR TRACE
message("SANITIZE")
Expand All @@ -426,7 +438,6 @@ if (SANITIZE) # OR TRACE
endif ()
set(ASAN_OPTIONS=detect_stack_use_after_return=1) # unnecessary because -Wreturn-stack-address
add_compile_options(-g)
# add_compile_options(-enable-coverage)
add_compile_options(-Wno-missing-field-initializers)
add_compile_options(-Wformat=2)
# # add_compile_options(-Wpointer-arith)
Expand Down
43 changes: 6 additions & 37 deletions source/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,49 +65,18 @@ int test_wasmedge_gc() {

// Run the `new_object` function
WasmEdge_String FuncName = WasmEdge_StringCreateByCString("new_object");
WasmEdge_Value Params[1] = {WasmEdge_ValueGenI32(32)};
WasmEdge_Value Params[0] = {};//WasmEdge_ValueGenI32(32)};
WasmEdge_Value Returns[1];
// WasmEdge_VMRunWasmFromBuffer()
// Result = WasmEdge_VMRunRegisteredFunction(VM, ModuleName.Buf, FuncName.Buf, Params, 1, Returns, 1);
// Load the WASM module into a buffer
FILE *wasm_file = fopen(path, "rb");
if (!wasm_file) {
printf("Failed to open file: %s\n", path);
return 1;
}
fseek(wasm_file, 0, SEEK_END);
long wasm_file_size = ftell(wasm_file);
fseek(wasm_file, 0, SEEK_SET);

uint8_t *wasm_buffer = (uint8_t *) malloc(wasm_file_size);
if (wasm_buffer == NULL) {
printf("Failed to allocate memory for WASM buffer.\n");
fclose(wasm_file);
return 1;
}
fread(wasm_buffer, 1, wasm_file_size, wasm_file);
fclose(wasm_file);

// Run the WASM using the `WasmEdge_VMRunWasmFromBuffer` function
// WasmEdge_Value Params[1] = {WasmEdge_ValueGenI32(32)};
// WasmEdge_Value Returns[1];
Result = WasmEdge_VMRunWasmFromBuffer(VM, wasm_buffer, wasm_file_size, FuncName, Params, 1, Returns, 1);

free(wasm_buffer); // Free the allocated buffer after use

int wasm_file_size = 0;
const uint8_t *wasm_buffer = reinterpret_cast<const uint8_t *>(readFile(path, &wasm_file_size));
Result = WasmEdge_VMRunWasmFromBuffer(VM, wasm_buffer, wasm_file_size, FuncName, Params, 0, Returns, 1);
if (!WasmEdge_ResultOK(Result)) {
printf("Failed to execute function: %s\n", WasmEdge_ResultGetMessage(Result));
return 1;
}
if (!WasmEdge_ResultOK(Result)) {
printf("Failed to execute function: %s\n", WasmEdge_ResultGetMessage(Result));
return 1;
}


auto mem = WasmEdge_StringCreateByCString("memory");
// WasmEdge_ModuleInstanceContext *module_ctx2 = WasmEdge_VMGetStoreContext(VM);
WasmEdge_StoreContext *storeContext = WasmEdge_VMGetStoreContext(VM);
// WasmEdge_StoreContext *storeContext = WasmEdge_VMGetStoreContext(VM);
const WasmEdge_ModuleInstanceContext *module_ctx = WasmEdge_VMGetActiveModule(VM);
WasmEdge_MemoryInstanceContext *memory_ctx = WasmEdge_ModuleInstanceFindMemory(module_ctx, mem);
uint8_t *memo = WasmEdge_MemoryInstanceGetPointer(memory_ctx, 0, 0);
Expand All @@ -131,7 +100,7 @@ int test_wasmedge_gc() {
printf("Result: %p\n", pVoid);
printf("Result: %d\n", *(int*)pVoid);
printf("Result: %d\n", WasmEdge_ValueGetI32(Return));
exit(0);
// exit(0);

// Cleanup
WasmEdge_VMDelete(VM);
Expand Down
4 changes: 1 addition & 3 deletions source/wasm_runner_edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ extern "C" int64 run_wasm(bytes buffer, int buf_size) {
// auto WasiMod = CreateWasiModule();
// WasmEdge_VMRegisterModuleFromImport(VMCxt, WasiMod);

WasmEdge_Value Params[1];
WasmEdge_Value Params[0];
WasmEdge_Value Returns[1];
WasmEdge_String FuncName = WasmEdge_StringCreateByCString("wasp_main");
WasmEdge_Result Res = WasmEdge_VMRunWasmFromBuffer(VMCxt, buffer, buf_size, FuncName, Params, 0, Returns, 1);
Expand All @@ -255,8 +255,6 @@ extern "C" int64 run_wasm(bytes buffer, int buf_size) {
Res = WasmEdge_VMRunWasmFromBuffer(VMCxt, buffer, buf_size, FuncName2, Params, 0, Returns, 1);
}
const WasmEdge_ModuleInstanceContext *module_ctx = WasmEdge_VMGetActiveModule(VMCxt);


auto mem = WasmEdge_StringCreateByCString("memory");
WasmEdge_MemoryInstanceContext *memory_ctx = WasmEdge_ModuleInstanceFindMemory(module_ctx, mem);
uint8_t *memo = WasmEdge_MemoryInstanceGetPointer(memory_ctx, 0, 0);
Expand Down

0 comments on commit 25b391e

Please sign in to comment.