mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-16 10:21:22 +00:00
Add basic Global API
This commit is contained in:
1
lib/runtime-c-api/tests/.gitignore
vendored
1
lib/runtime-c-api/tests/.gitignore
vendored
@ -9,6 +9,7 @@ install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
test-globals
|
||||
test-instantiate
|
||||
test-import-function
|
||||
test-memory
|
||||
|
@ -1,6 +1,7 @@
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
project (WasmerCApiTests)
|
||||
|
||||
add_executable(test-globals test-globals.c)
|
||||
add_executable(test-instantiate test-instantiate.c)
|
||||
add_executable(test-import-function test-import-function.c)
|
||||
add_executable(test-memory test-memory.c)
|
||||
@ -16,6 +17,8 @@ if(NOT WASMER_LIB)
|
||||
message(FATAL_ERROR "wasmer library not found")
|
||||
endif()
|
||||
|
||||
target_link_libraries(test-globals
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-instantiate
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-import-function
|
||||
@ -28,6 +31,7 @@ target_link_libraries(test-tables
|
||||
general ${WASMER_LIB})
|
||||
|
||||
enable_testing()
|
||||
add_test(test-globals test-globals)
|
||||
add_test(test-instantiate test-instantiate)
|
||||
add_test(test-import-function test-import-function)
|
||||
add_test(test-memory test-memory)
|
||||
|
30
lib/runtime-c-api/tests/test-globals.c
Normal file
30
lib/runtime-c-api/tests/test-globals.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include "../wasmer.h"
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
wasmer_value_t val;
|
||||
val.tag = WASM_I32;
|
||||
val.value.I32 = 7;
|
||||
wasmer_global_t *global = wasmer_global_new(val, true);
|
||||
|
||||
wasmer_value_t get_val = wasmer_global_get(global);
|
||||
assert( get_val.value.I32 == 7);
|
||||
|
||||
wasmer_value_t val2;
|
||||
val2.tag = WASM_I32;
|
||||
val2.value.I32 = 14;
|
||||
wasmer_global_set(global, val2);
|
||||
|
||||
wasmer_value_t new_get_val = wasmer_global_get(global);
|
||||
assert( new_get_val.value.I32 == 14);
|
||||
|
||||
wasmer_global_descriptor_t desc = wasmer_global_get_descriptor(global);
|
||||
assert(desc.mutable_);
|
||||
assert(desc.kind == WASM_I32);
|
||||
|
||||
wasmer_global_destroy(global);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user