Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,30 @@ set(CMAKE_POLICY_VERSION_MINIMUM 3.5)

SET(CMAKE_BUILD_TYPE Debug)

# add_definitions (-m32)
set(CMAKE_CXX_STANDARD 17)

#TODO: modularization me
# Detect Hosting target info
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
# Set WAMR_BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
set (WAMR_BUILD_TARGET "AARCH64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
set (WAMR_BUILD_TARGET "RISCV64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (WAMR_BUILD_TARGET "X86_64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
# Build as X86_32 by default in 32-bit platform
set (WAMR_BUILD_TARGET "X86_32")
else ()
message(SEND_ERROR "Unsupported build target platform!")
endif ()
endif ()

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")

Expand Down Expand Up @@ -65,20 +88,32 @@ add_subdirectory(gc)
add_subdirectory(tid-allocator)
add_subdirectory(unsupported-features)
add_subdirectory(smart-tests)
add_subdirectory (running-modes)

if (NOT WAMR_BUILD_TARGET STREQUAL "X86_32")
if(WAMR_BUILD_TARGET STREQUAL "X86_64")
add_subdirectory(aot-stack-frame)

# should enable 32-bit llvm when X86_32
add_subdirectory (aot)
add_subdirectory (custom-section)
add_subdirectory (compilation)

# Fast-JIT or mem64 is not supported on X86_32
add_subdirectory (running-modes)
add_subdirectory (memory64)
add_subdirectory (shared-heap)

# HW_BOUND_CHECK is not supported on X86_32
add_subdirectory (runtime-common)
endif()

if(WAMR_BUILD_TARGET STREQUAL "AARCH64")
add_subdirectory(aot-stack-frame)

add_subdirectory (aot)
add_subdirectory (custom-section)
add_subdirectory (compilation)

add_subdirectory (memory64)
add_subdirectory (shared-heap)

add_subdirectory (runtime-common)
endif ()
14 changes: 14 additions & 0 deletions tests/unit/common/test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
#include <iostream>
#include <memory>
#include <fstream>
#include <limits.h>
#include <string>
#include <unistd.h>

static inline std::string
get_test_binary_dir()
{
char cwd[PATH_MAX] = { 0 };
if (!getcwd(cwd, sizeof(cwd))) {
return std::string();
}

return std::string(cwd);
}

template<int Size = 512 * 1024>
class WAMRRuntimeRAII
Expand Down
28 changes: 8 additions & 20 deletions tests/unit/compilation/aot_compiler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,6 @@ static std::string CWD;
static std::string MAIN_WASM = "/main.wasm";
static char *WASM_FILE;

static std::string
get_binary_path()
{
char cwd[1024];
memset(cwd, 0, 1024);

if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
}

char *path_end = strrchr(cwd, '/');
if (path_end != NULL) {
*path_end = '\0';
}

return std::string(cwd);
}

extern "C" {
char *
aot_generate_tempfile_name(const char *prefix, const char *extension,
Expand All @@ -50,7 +33,7 @@ class aot_compiler_test_suit : public testing::Test

static void SetUpTestCase()
{
CWD = get_binary_path();
CWD = get_test_binary_dir();
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
}

Expand Down Expand Up @@ -117,8 +100,13 @@ TEST_F(aot_compiler_test_suit, aot_emit_object_file)

// Test size_level in range from 0 to 3.
option.opt_level = 3;
for (i = 0; i <= 3; i++) {
option.size_level = i;
#if defined(__aarch64__) || defined(_M_ARM64)
std::vector<int> size_levels = { 0, 3 };
#else
std::vector<int> size_levels = { 0, 1, 2, 3 };
#endif
for (auto size_level : size_levels) {
option.size_level = size_level;
test_aot_emit_object_file_with_option(&option);
}

Expand Down
19 changes: 1 addition & 18 deletions tests/unit/compilation/aot_emit_aot_file_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,6 @@ static std::string CWD;
static std::string MAIN_WASM = "/main.wasm";
static char *WASM_FILE;

static std::string
get_binary_path()
{
char cwd[1024];
memset(cwd, 0, 1024);

if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
}

char *path_end = strrchr(cwd, '/');
if (path_end != NULL) {
*path_end = '\0';
}

return std::string(cwd);
}

extern "C" {
uint8 *
aot_emit_aot_file_buf(AOTCompContext *comp_ctx, AOTCompData *comp_data,
Expand All @@ -50,7 +33,7 @@ class aot_emit_aot_file_test_suite : public testing::Test

static void SetUpTestCase()
{
CWD = get_binary_path();
CWD = get_test_binary_dir();
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
}

Expand Down
19 changes: 1 addition & 18 deletions tests/unit/compilation/aot_emit_control_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@ static std::string CWD;
static std::string MAIN_WASM = "/main.wasm";
static char *WASM_FILE;

static std::string
get_binary_path()
{
char cwd[1024];
memset(cwd, 0, 1024);

if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
}

char *path_end = strrchr(cwd, '/');
if (path_end != NULL) {
*path_end = '\0';
}

return std::string(cwd);
}

class aot_emit_control_test_suite : public testing::Test
{
protected:
Expand All @@ -45,7 +28,7 @@ class aot_emit_control_test_suite : public testing::Test

static void SetUpTestCase()
{
CWD = get_binary_path();
CWD = get_test_binary_dir();
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
}

Expand Down
19 changes: 1 addition & 18 deletions tests/unit/compilation/aot_emit_function_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,6 @@ static std::string CWD;
static std::string MAIN_WASM = "/main.wasm";
static char *WASM_FILE;

static std::string
get_binary_path()
{
char cwd[1024];
memset(cwd, 0, 1024);

if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
}

char *path_end = strrchr(cwd, '/');
if (path_end != NULL) {
*path_end = '\0';
}

return std::string(cwd);
}

class aot_emit_function_test_suite : public testing::Test
{
protected:
Expand All @@ -44,7 +27,7 @@ class aot_emit_function_test_suite : public testing::Test

static void SetUpTestCase()
{
CWD = get_binary_path();
CWD = get_test_binary_dir();
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
}

Expand Down
19 changes: 1 addition & 18 deletions tests/unit/compilation/aot_emit_memory_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,12 @@ static std::string CWD;
static std::string MAIN_WASM = "/main.wasm";
static char *WASM_FILE;

static std::string
get_binary_path()
{
char cwd[1024];
memset(cwd, 0, 1024);

if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
}

char *path_end = strrchr(cwd, '/');
if (path_end != NULL) {
*path_end = '\0';
}

return std::string(cwd);
}

class compilation_aot_emit_memory_test : public testing::Test
{
protected:
void SetUp() override
{
CWD = get_binary_path();
CWD = get_test_binary_dir();
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
AOTCompOption option = { 0 };

Expand Down
19 changes: 1 addition & 18 deletions tests/unit/compilation/aot_emit_numberic_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@ static std::string CWD;
static std::string MAIN_WASM = "/main.wasm";
static char *WASM_FILE;

static std::string
get_binary_path()
{
char cwd[1024];
memset(cwd, 0, 1024);

if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
}

char *path_end = strrchr(cwd, '/');
if (path_end != NULL) {
*path_end = '\0';
}

return std::string(cwd);
}

class aot_emit_numberic_test_suite : public testing::Test
{
protected:
Expand All @@ -45,7 +28,7 @@ class aot_emit_numberic_test_suite : public testing::Test

static void SetUpTestCase()
{
CWD = get_binary_path();
CWD = get_test_binary_dir();
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
}

Expand Down
19 changes: 1 addition & 18 deletions tests/unit/compilation/aot_emit_parametric_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,6 @@ static std::string CWD;
static std::string MAIN_WASM = "/main.wasm";
static char *WASM_FILE;

static std::string
get_binary_path()
{
char cwd[1024];
memset(cwd, 0, 1024);

if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
}

char *path_end = strrchr(cwd, '/');
if (path_end != NULL) {
*path_end = '\0';
}

return std::string(cwd);
}

class aot_emit_parametric_test_suite : public testing::Test
{
protected:
Expand All @@ -44,7 +27,7 @@ class aot_emit_parametric_test_suite : public testing::Test

static void SetUpTestCase()
{
CWD = get_binary_path();
CWD = get_test_binary_dir();
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
}

Expand Down
19 changes: 1 addition & 18 deletions tests/unit/compilation/aot_emit_table_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,6 @@ static std::string CWD;
static std::string MAIN_WASM = "/main.wasm";
static char *WASM_FILE;

static std::string
get_binary_path()
{
char cwd[1024];
memset(cwd, 0, 1024);

if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
}

char *path_end = strrchr(cwd, '/');
if (path_end != NULL) {
*path_end = '\0';
}

return std::string(cwd);
}

class aot_emit_table_test_suite : public testing::Test
{
protected:
Expand All @@ -44,7 +27,7 @@ class aot_emit_table_test_suite : public testing::Test

static void SetUpTestCase()
{
CWD = get_binary_path();
CWD = get_test_binary_dir();
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
}

Expand Down
19 changes: 1 addition & 18 deletions tests/unit/compilation/aot_llvm_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,6 @@ static std::string CWD;
static std::string MAIN_WASM = "/main.wasm";
static char *WASM_FILE;

static std::string
get_binary_path()
{
char cwd[1024];
memset(cwd, 0, 1024);

if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
}

char *path_end = strrchr(cwd, '/');
if (path_end != NULL) {
*path_end = '\0';
}

return std::string(cwd);
}

class aot_llvm_test_suite : public testing::Test
{
protected:
Expand All @@ -44,7 +27,7 @@ class aot_llvm_test_suite : public testing::Test

static void SetUpTestCase()
{
CWD = get_binary_path();
CWD = get_test_binary_dir();
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
}

Expand Down
Loading
Loading