refactor: update CMakeLists.txt for testing support and modify demo output

This commit is contained in:
liang.he@intel.com 2025-10-29 02:07:39 +00:00
parent be4dc9fcf9
commit 29d5070e7f
3 changed files with 20 additions and 6 deletions

View File

@ -5,9 +5,8 @@ cmake_minimum_required (VERSION 3.14)
project(checked_api_sample)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# assertion required
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_C_STANDARD 23)
@ -54,3 +53,9 @@ ExternalProject_Add(wasm
BUILD_COMMAND ${CMAKE_COMMAND} --build build
INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR}
)
enable_testing()
add_test(NAME checked_api_sample_test
COMMAND ${PROJECT_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

View File

@ -80,8 +80,18 @@ main(int argc, char *argv_main[])
arguments);
VERIFY_API_RESULT(wasm_runtime_call_wasm_a_checked, api_result,
release_runtime);
printf("Native finished calling wasm function: fib, returned: %d\n",
result[0].of.i32);
printf("Native finished calling wasm function: fib(%d), returned: %d\n",
arguments[0].of.i32, result[0].of.i32);
bh_assert(result[0].of.i32 == 8);
arguments[0].of.i32 = 2;
api_result = wasm_runtime_call_wasm_a_checked(exec_env, func, 1, result, 1,
arguments);
VERIFY_API_RESULT(wasm_runtime_call_wasm_a_checked, api_result,
release_runtime);
printf("Native finished calling wasm function: fib(%d), returned: %d\n",
arguments[0].of.i32, result[0].of.i32);
bh_assert(result[0].of.i32 == 1);
ret = EXIT_SUCCESS;

View File

@ -17,7 +17,6 @@ __attribute__((export_name("fib"))) int
fib(int n)
{
int result = fibonacci(n);
printf("fibonacci(%d)=%d\n", n, result);
return result;
}