mirror of
https://github.com/fluencelabs/wasmer
synced 2025-07-02 18:11:34 +00:00
Implement basic C API memory functions
This commit is contained in:
1
lib/runtime-c-api/tests/.gitignore
vendored
1
lib/runtime-c-api/tests/.gitignore
vendored
@ -11,4 +11,5 @@ CTestTestfile.cmake
|
||||
_deps
|
||||
test-instantiate
|
||||
test-import-function
|
||||
test-memory
|
||||
rust-build
|
@ -3,6 +3,7 @@ project (WasmerCApiTests)
|
||||
|
||||
add_executable(test-instantiate test-instantiate.c)
|
||||
add_executable(test-import-function test-import-function.c)
|
||||
add_executable(test-memory test-memory.c)
|
||||
|
||||
find_library(
|
||||
WASMER_LIB NAMES libwasmer_runtime_c_api.dylib libwasmer_runtime_c_api.so libwasmer_runtime_c_api.dll
|
||||
@ -17,8 +18,11 @@ target_link_libraries(test-instantiate
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-import-function
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-memory
|
||||
general ${WASMER_LIB})
|
||||
|
||||
enable_testing()
|
||||
add_test(test-instantiate test-instantiate)
|
||||
add_test(test-import-function test-import-function)
|
||||
add_test(test-memory test-memory)
|
||||
|
||||
|
23
lib/runtime-c-api/tests/test-memory.c
Normal file
23
lib/runtime-c-api/tests/test-memory.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include "../wasmer.h"
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
wasmer_memory_t *memory = NULL;
|
||||
wasmer_limits_t descriptor;
|
||||
descriptor.min = 10;
|
||||
descriptor.max = 10;
|
||||
wasmer_memory_result_t memory_result = wasmer_memory_new(&memory, descriptor);
|
||||
printf("Memory result: %d\n", memory_result);
|
||||
assert(memory_result == WASMER_MEMORY_OK);
|
||||
|
||||
uint32_t len = wasmer_memory_length(memory);
|
||||
printf("Memory pages length: %d\n", len);
|
||||
assert(len == 10);
|
||||
|
||||
printf("Destroy memory\n");
|
||||
wasmer_memory_destroy(memory);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user