mirror of
https://github.com/mii443/wasmer.git
synced 2025-08-30 12:19:28 +00:00
test(c-api) Restore the wasm-c-api
test suite.
This commit is contained in:
@ -1,4 +1,6 @@
|
|||||||
use std::process::Command;
|
mod test_c_helpers;
|
||||||
|
|
||||||
|
use test_c_helpers::compile_with_cmake_and_run_test;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deprecated_c_api() {
|
fn test_deprecated_c_api() {
|
||||||
@ -15,40 +17,6 @@ fn test_deprecated_c_api() {
|
|||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
r#"-G "MinGW Makefiles""#,
|
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>) {
|
compile_with_cmake_and_run_test(project_tests_dir, cmake_args);
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
46
lib/c-api/tests/test_c_helpers/mod.rs
Normal file
46
lib/c-api/tests/test_c_helpers/mod.rs
Normal file
@ -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");
|
||||||
|
}
|
140
lib/c-api/tests/wasm_c_api/CMakeLists.txt
Normal file
140
lib/c-api/tests/wasm_c_api/CMakeLists.txt
Normal file
@ -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
|
||||||
|
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:
|
||||||
|
"-Werror" >
|
||||||
|
# MSVC
|
||||||
|
$<$<CXX_COMPILER_ID: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)
|
@ -3,8 +3,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include "wasm.h"
|
#include "../../wasm.h"
|
||||||
#include "wasmer_wasm.h"
|
#include "../../wasmer_wasm.h"
|
||||||
|
|
||||||
#define BUF_SIZE 128
|
#define BUF_SIZE 128
|
||||||
|
|
BIN
lib/c-api/tests/wasm_c_api/wasm-c-api-callback
Executable file
BIN
lib/c-api/tests/wasm_c_api/wasm-c-api-callback
Executable file
Binary file not shown.
BIN
lib/c-api/tests/wasm_c_api/wasm-c-api-global
Executable file
BIN
lib/c-api/tests/wasm_c_api/wasm-c-api-global
Executable file
Binary file not shown.
BIN
lib/c-api/tests/wasm_c_api/wasm-c-api-hello
Executable file
BIN
lib/c-api/tests/wasm_c_api/wasm-c-api-hello
Executable file
Binary file not shown.
BIN
lib/c-api/tests/wasm_c_api/wasm-c-api-memory
Executable file
BIN
lib/c-api/tests/wasm_c_api/wasm-c-api-memory
Executable file
Binary file not shown.
BIN
lib/c-api/tests/wasm_c_api/wasm-c-api-reflect
Executable file
BIN
lib/c-api/tests/wasm_c_api/wasm-c-api-reflect
Executable file
Binary file not shown.
BIN
lib/c-api/tests/wasm_c_api/wasm-c-api-serialize
Executable file
BIN
lib/c-api/tests/wasm_c_api/wasm-c-api-serialize
Executable file
Binary file not shown.
18
lib/c-api/tests/wasm_c_api_tests.rs
Normal file
18
lib/c-api/tests/wasm_c_api_tests.rs
Normal file
@ -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);
|
||||||
|
}
|
Reference in New Issue
Block a user