diff --git a/lib/c-api/tests/deprecated_tests.rs b/lib/c-api/tests/deprecated_tests.rs index f8c2a6683..b15a26b1b 100644 --- a/lib/c-api/tests/deprecated_tests.rs +++ b/lib/c-api/tests/deprecated_tests.rs @@ -1,4 +1,6 @@ -use std::process::Command; +mod test_c_helpers; + +use test_c_helpers::compile_with_cmake_and_run_test; #[test] fn test_deprecated_c_api() { @@ -15,40 +17,6 @@ fn test_deprecated_c_api() { #[cfg(target_os = "windows")] r#"-G "MinGW Makefiles""#, ]; - // we use -f so it doesn't fail if the file doesn't exist - run_command("rm", project_tests_dir, vec!["-f", "CMakeCache.txt"]); - run_command("cmake", project_tests_dir, cmake_args); - run_command("make", project_tests_dir, vec!["-Wdev", "-Werror=dev"]); - run_command("make", project_tests_dir, vec!["test", "ARGS=\"-V\""]); -} - -fn run_command(command_str: &str, dir: &str, args: Vec<&str>) { - println!( - "Running command: `{}` with arguments: {:?}", - command_str, args - ); - - let mut command = Command::new(command_str); - command.args(&args); - command.current_dir(dir); - - match command.output() { - Ok(result) => { - println!( - "> Status: `{:?}`\n> Stdout: `{}`\n> Stderr: `{}`", - result.status.code(), - String::from_utf8_lossy(&result.stdout[..]), - String::from_utf8_lossy(&result.stderr[..]), - ); - - if result.status.success() { - assert!(true) - } else { - panic!("Command failed with exit status: `{:?}`", result.status); - } - } - Err(error) => panic!("Command failed: `{}`", error), - } - - println!("\n"); + + compile_with_cmake_and_run_test(project_tests_dir, cmake_args); } diff --git a/lib/c-api/tests/test_c_helpers/mod.rs b/lib/c-api/tests/test_c_helpers/mod.rs new file mode 100644 index 000000000..32c520cae --- /dev/null +++ b/lib/c-api/tests/test_c_helpers/mod.rs @@ -0,0 +1,46 @@ +use std::process::Command; + +pub fn compile_with_cmake_and_run_test(project_tests_dir: &str, cmake_args: Vec<&str>) { + run_command( + "rm", + project_tests_dir, + vec![ + "-f", // we use -f so it doesn't fail if the file doesn't exist + "CMakeCache.txt", + ], + ); + run_command("cmake", project_tests_dir, cmake_args); + run_command("make", project_tests_dir, vec!["-Wdev", "-Werror=dev"]); + run_command("make", project_tests_dir, vec!["test", "ARGS=\"-V\""]); +} + +pub fn run_command(command_str: &str, dir: &str, args: Vec<&str>) { + println!( + "Running command: `{}` with arguments: {:?}", + command_str, args + ); + + let mut command = Command::new(command_str); + command.args(&args); + command.current_dir(dir); + + match command.output() { + Ok(result) => { + println!( + "> Status: `{:?}`\n> Stdout: `{}`\n> Stderr: `{}`", + result.status.code(), + String::from_utf8_lossy(&result.stdout[..]), + String::from_utf8_lossy(&result.stderr[..]), + ); + + if result.status.success() { + assert!(true) + } else { + panic!("Command failed with exit status: `{:?}`", result.status); + } + } + Err(error) => panic!("Command failed: `{}`", error), + } + + println!("\n"); +} diff --git a/lib/c-api/tests/wasm_c_api/CMakeLists.txt b/lib/c-api/tests/wasm_c_api/CMakeLists.txt new file mode 100644 index 000000000..55eedab30 --- /dev/null +++ b/lib/c-api/tests/wasm_c_api/CMakeLists.txt @@ -0,0 +1,140 @@ +cmake_minimum_required (VERSION 2.6) +project (WasmerWasmCApiTests) + +# Examples as tests from the `wasm-c-api` repository. +add_executable(wasm-c-api-callback wasm-c-api/example/callback.c) +#add_executable(wasm-c-api-finalize wasm-c-api/example/finalize.c) +#add_executable(wasm-c-api-global wasm-c-api/example/global.c) +add_executable(wasm-c-api-hello wasm-c-api/example/hello.c) +#add_executable(wasm-c-api-hostref wasm-c-api/example/hostref.c) +#add_executable(wasm-c-api-memory wasm-c-api/example/memory.c) +#add_executable(wasm-c-api-multi wasm-c-api/example/multi.c) +add_executable(wasm-c-api-reflect wasm-c-api/example/reflect.c) +add_executable(wasm-c-api-serialize wasm-c-api/example/serialize.c) +#add_executable(wasm-c-api-start wasm-c-api/example/start.c) +#add_executable(wasm-c-api-table wasm-c-api/example/table.c) +#add_executable(wasm-c-api-threads wasm-c-api/example/threads.c) +#add_executable(wasm-c-api-trap wasm-c-api/example/trap.c) + +# Our additional tests. +#add_executable(test-wasi test-wasi.c) + +include_directories(wasm-c-api/include) +include_directories(../../) + +find_library( + WASMER_LIB NAMES libwasmer_c_api.dylib libwasmer_c_api.so wasmer_c_api.dll + PATHS ${CMAKE_SOURCE_DIR}/../../../../target/release/ +) + +if(NOT WASMER_LIB) + message(FATAL_ERROR "wasmer library not found") +endif() + +enable_testing() + +set( + COMPILER_OPTIONS + # Clang or gcc + $<$,$>: + "-Werror" > + # MSVC + $<$: + "/WX" > +) + +target_link_libraries(wasm-c-api-callback general ${WASMER_LIB}) +target_compile_options(wasm-c-api-callback PRIVATE ${COMPILER_OPTIONS}) +add_test(NAME wasm-c-api-callback + COMMAND wasm-c-api-callback + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example/ +) + +#target_link_libraries(wasm-c-api-finalize general ${WASMER_LIB}) +#target_compile_options(wasm-c-api-finalize PRIVATE ${COMPILER_OPTIONS}) +#add_test(NAME wasm-c-api-finalize +# COMMAND wasm-c-api-finalize +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example/ +#) + +#target_link_libraries(wasm-c-api-global general ${WASMER_LIB}) +#target_compile_options(wasm-c-api-global PRIVATE ${COMPILER_OPTIONS}) +#add_test(NAME wasm-c-api-global +# COMMAND wasm-c-api-global +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example/ +#) + +target_link_libraries(wasm-c-api-hello general ${WASMER_LIB}) +target_compile_options(wasm-c-api-hello PRIVATE ${COMPILER_OPTIONS}) +add_test(NAME wasm-c-api-hello + COMMAND wasm-c-api-hello + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example/ +) + +#target_link_libraries(wasm-c-api-hostref general ${WASMER_LIB}) +#target_compile_options(wasm-c-api-hostref PRIVATE ${COMPILER_OPTIONS}) +#add_test(NAME wasm-c-api-hostref +# COMMAND wasm-c-api-hostref +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example/ +#) + +#target_link_libraries(wasm-c-api-memory general ${WASMER_LIB}) +#target_compile_options(wasm-c-api-memory PRIVATE ${COMPILER_OPTIONS}) +#add_test(NAME wasm-c-api-memory +# COMMAND wasm-c-api-memory +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example/ +#) + +#target_link_libraries(wasm-c-api-multi general ${WASMER_LIB}) +#target_compile_options(wasm-c-api-multi PRIVATE ${COMPILER_OPTIONS}) +#add_test(NAME wasm-c-api-multi +# COMMAND wasm-c-api-multi +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example/ +#) + +target_link_libraries(wasm-c-api-reflect general ${WASMER_LIB}) +target_compile_options(wasm-c-api-reflect PRIVATE ${COMPILER_OPTIONS}) +add_test(NAME wasm-c-api-reflect + COMMAND wasm-c-api-reflect + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example/ +) + +target_link_libraries(wasm-c-api-serialize general ${WASMER_LIB}) +target_compile_options(wasm-c-api-serialize PRIVATE ${COMPILER_OPTIONS}) +add_test(NAME wasm-c-api-serialize + COMMAND wasm-c-api-serialize + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example/ +) + +#target_link_libraries(wasm-c-api-start general ${WASMER_LIB}) +#target_compile_options(wasm-c-api-start PRIVATE ${COMPILER_OPTIONS}) +#add_test(NAME wasm-c-api-start +# COMMAND wasm-c-api-start +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example/ +#) + +#target_link_libraries(wasm-c-api-table general ${WASMER_LIB}) +#target_compile_options(wasm-c-api-table PRIVATE ${COMPILER_OPTIONS}) +#add_test(NAME wasm-c-api-table +# COMMAND wasm-c-api-table +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example/ +#) + +#target_link_libraries(wasm-c-api-threads general ${WASMER_LIB}) +#target_compile_options(wasm-c-api-threads PRIVATE ${COMPILER_OPTIONS}) +#add_test(NAME wasm-c-api-threads +# COMMAND wasm-c-api-threads +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example/ +#) + +#target_link_libraries(wasm-c-api-trap general ${WASMER_LIB}) +#target_compile_options(wasm-c-api-trap PRIVATE ${COMPILER_OPTIONS}) +#add_test(NAME wasm-c-api-trap +# COMMAND wasm-c-api-trap +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/example/ +#) + +#set_property(TARGET test-wasi PROPERTY C_STANDARD 11) +#target_link_libraries(test-wasi general ${WASMER_LIB}) +#target_compile_options(test-wasi PRIVATE ${COMPILER_OPTIONS}) +#add_test(test-wasi test-wasi) diff --git a/lib/c-api/tests/wasm-c-api-wasi.c b/lib/c-api/tests/wasm_c_api/test-wasi.c similarity index 98% rename from lib/c-api/tests/wasm-c-api-wasi.c rename to lib/c-api/tests/wasm_c_api/test-wasi.c index bc020d418..9a507b02e 100644 --- a/lib/c-api/tests/wasm-c-api-wasi.c +++ b/lib/c-api/tests/wasm_c_api/test-wasi.c @@ -3,8 +3,8 @@ #include #include -#include "wasm.h" -#include "wasmer_wasm.h" +#include "../../wasm.h" +#include "../../wasmer_wasm.h" #define BUF_SIZE 128 diff --git a/lib/c-api/tests/wasm_c_api/wasm-c-api-callback b/lib/c-api/tests/wasm_c_api/wasm-c-api-callback new file mode 100755 index 000000000..0d13b4eba Binary files /dev/null and b/lib/c-api/tests/wasm_c_api/wasm-c-api-callback differ diff --git a/lib/c-api/tests/wasm_c_api/wasm-c-api-global b/lib/c-api/tests/wasm_c_api/wasm-c-api-global new file mode 100755 index 000000000..db530731c Binary files /dev/null and b/lib/c-api/tests/wasm_c_api/wasm-c-api-global differ diff --git a/lib/c-api/tests/wasm_c_api/wasm-c-api-hello b/lib/c-api/tests/wasm_c_api/wasm-c-api-hello new file mode 100755 index 000000000..806e09104 Binary files /dev/null and b/lib/c-api/tests/wasm_c_api/wasm-c-api-hello differ diff --git a/lib/c-api/tests/wasm_c_api/wasm-c-api-memory b/lib/c-api/tests/wasm_c_api/wasm-c-api-memory new file mode 100755 index 000000000..094ff5d0e Binary files /dev/null and b/lib/c-api/tests/wasm_c_api/wasm-c-api-memory differ diff --git a/lib/c-api/tests/wasm_c_api/wasm-c-api-reflect b/lib/c-api/tests/wasm_c_api/wasm-c-api-reflect new file mode 100755 index 000000000..ce6ce7b51 Binary files /dev/null and b/lib/c-api/tests/wasm_c_api/wasm-c-api-reflect differ diff --git a/lib/c-api/tests/wasm_c_api/wasm-c-api-serialize b/lib/c-api/tests/wasm_c_api/wasm-c-api-serialize new file mode 100755 index 000000000..f9c5bb1e7 Binary files /dev/null and b/lib/c-api/tests/wasm_c_api/wasm-c-api-serialize differ diff --git a/lib/c-api/tests/wasm_c_api_tests.rs b/lib/c-api/tests/wasm_c_api_tests.rs new file mode 100644 index 000000000..4f838ee53 --- /dev/null +++ b/lib/c-api/tests/wasm_c_api_tests.rs @@ -0,0 +1,18 @@ +mod test_c_helpers; + +use test_c_helpers::compile_with_cmake_and_run_test; + +#[test] +fn test_wasm_c_api() { + let project_tests_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/wasm_c_api/"); + + let cmake_args = vec![ + ".", + // We need something like this to get this working on Windows, but this doesn't seem + // quite right -- perhaps it's double escaping the quotes? + #[cfg(target_os = "windows")] + r#"-G "MinGW Makefiles""#, + ]; + + compile_with_cmake_and_run_test(project_tests_dir, cmake_args); +}