Skip to content

Commit 29d5070

Browse files
committed
refactor: update CMakeLists.txt for testing support and modify demo output
1 parent be4dc9f commit 29d5070

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

samples/checked-api/CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ cmake_minimum_required (VERSION 3.14)
55

66
project(checked_api_sample)
77

8-
if(NOT CMAKE_BUILD_TYPE)
9-
set(CMAKE_BUILD_TYPE Release)
10-
endif()
8+
# assertion required
9+
set(CMAKE_BUILD_TYPE Debug)
1110

1211
set(CMAKE_C_STANDARD 23)
1312

@@ -54,3 +53,9 @@ ExternalProject_Add(wasm
5453
BUILD_COMMAND ${CMAKE_COMMAND} --build build
5554
INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR}
5655
)
56+
57+
enable_testing()
58+
add_test(NAME checked_api_sample_test
59+
COMMAND ${PROJECT_NAME}
60+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
61+
)

samples/checked-api/src/demo.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,18 @@ main(int argc, char *argv_main[])
8080
arguments);
8181
VERIFY_API_RESULT(wasm_runtime_call_wasm_a_checked, api_result,
8282
release_runtime);
83-
printf("Native finished calling wasm function: fib, returned: %d\n",
84-
result[0].of.i32);
83+
printf("Native finished calling wasm function: fib(%d), returned: %d\n",
84+
arguments[0].of.i32, result[0].of.i32);
85+
bh_assert(result[0].of.i32 == 8);
86+
87+
arguments[0].of.i32 = 2;
88+
api_result = wasm_runtime_call_wasm_a_checked(exec_env, func, 1, result, 1,
89+
arguments);
90+
VERIFY_API_RESULT(wasm_runtime_call_wasm_a_checked, api_result,
91+
release_runtime);
92+
printf("Native finished calling wasm function: fib(%d), returned: %d\n",
93+
arguments[0].of.i32, result[0].of.i32);
94+
bh_assert(result[0].of.i32 == 1);
8595

8696
ret = EXIT_SUCCESS;
8797

samples/checked-api/wasm-apps/fib.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ __attribute__((export_name("fib"))) int
1717
fib(int n)
1818
{
1919
int result = fibonacci(n);
20-
printf("fibonacci(%d)=%d\n", n, result);
2120
return result;
2221
}
2322

0 commit comments

Comments
 (0)