Skip to content

Commit 46472ee

Browse files
authored
Enable Unit test on Mac(m1) (#4841)
- detecting host arch. and platform instead of hard-coding - fix few compilation errors because of stricter rules involve by appleclang - refactor: modernize wasm-apps CMakeLists.txt to target-specific options and install commands - refactor: modernize memory64 CMakeLists.txt to target-specific options and install commands - Update running-modes CMakeLists.txt: enable AOT and INTERP; JIT/FAST_JIT gating for x86_64. Fix typo in JIT section. - fix: replace deprecated get_binary_path function with get_test_binary_dir for improved portability - fix: adjust size_level test cases for aarch64 architecture compatibility
1 parent 9d1dc3e commit 46472ee

30 files changed

+276
-470
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ tests/benchmarks/coremark/coremark*
4040
samples/workload/include/**
4141
!samples/workload/include/.gitkeep
4242

43-
# core/iwasm/libraries/wasi-threads
43+
# core/iwasm/libraries/wasi-threads
44+
45+
tests/unit/runtime-common/wasm-apps/main.aot
46+
tests/unit/aot-stack-frame/wasm-apps/test_aot.h

tests/unit/CMakeLists.txt

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,30 @@ set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
1414

1515
SET(CMAKE_BUILD_TYPE Debug)
1616

17-
# add_definitions (-m32)
17+
set(CMAKE_CXX_STANDARD 17)
18+
19+
#TODO: modularization me
20+
# Detect Hosting target info
21+
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
22+
# Set WAMR_BUILD_TARGET, currently values supported:
23+
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
24+
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
25+
if (NOT DEFINED WAMR_BUILD_TARGET)
26+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
27+
set (WAMR_BUILD_TARGET "AARCH64")
28+
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
29+
set (WAMR_BUILD_TARGET "RISCV64")
30+
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
31+
# Build as X86_64 by default in 64-bit platform
32+
set (WAMR_BUILD_TARGET "X86_64")
33+
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
34+
# Build as X86_32 by default in 32-bit platform
35+
set (WAMR_BUILD_TARGET "X86_32")
36+
else ()
37+
message(SEND_ERROR "Unsupported build target platform!")
38+
endif ()
39+
endif ()
40+
1841
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
1942
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
2043

@@ -66,20 +89,32 @@ add_subdirectory(tid-allocator)
6689
add_subdirectory(unsupported-features)
6790
add_subdirectory(smart-tests)
6891
add_subdirectory(exception-handling)
92+
add_subdirectory(running-modes)
6993

70-
if (NOT WAMR_BUILD_TARGET STREQUAL "X86_32")
94+
if(WAMR_BUILD_TARGET STREQUAL "X86_64")
7195
add_subdirectory(aot-stack-frame)
7296

7397
# should enable 32-bit llvm when X86_32
7498
add_subdirectory (aot)
7599
add_subdirectory (custom-section)
76100
add_subdirectory (compilation)
77101

78-
# Fast-JIT or mem64 is not supported on X86_32
79-
add_subdirectory (running-modes)
80102
add_subdirectory (memory64)
81103
add_subdirectory (shared-heap)
82104

83105
# HW_BOUND_CHECK is not supported on X86_32
106+
add_subdirectory (runtime-common)
107+
endif()
108+
109+
if(WAMR_BUILD_TARGET STREQUAL "AARCH64")
110+
add_subdirectory(aot-stack-frame)
111+
112+
add_subdirectory (aot)
113+
add_subdirectory (custom-section)
114+
add_subdirectory (compilation)
115+
116+
add_subdirectory (memory64)
117+
add_subdirectory (shared-heap)
118+
84119
add_subdirectory (runtime-common)
85120
endif ()

tests/unit/common/test_helper.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111
#include <iostream>
1212
#include <memory>
1313
#include <fstream>
14+
#include <limits.h>
15+
#include <string>
16+
#include <unistd.h>
17+
18+
static inline std::string
19+
get_test_binary_dir()
20+
{
21+
char cwd[PATH_MAX] = { 0 };
22+
if (!getcwd(cwd, sizeof(cwd))) {
23+
return std::string();
24+
}
25+
26+
return std::string(cwd);
27+
}
1428

1529
template<int Size = 512 * 1024>
1630
class WAMRRuntimeRAII

tests/unit/compilation/aot_compiler_test.cc

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,6 @@ static std::string CWD;
1414
static std::string MAIN_WASM = "/main.wasm";
1515
static char *WASM_FILE;
1616

17-
static std::string
18-
get_binary_path()
19-
{
20-
char cwd[1024];
21-
memset(cwd, 0, 1024);
22-
23-
if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
24-
}
25-
26-
char *path_end = strrchr(cwd, '/');
27-
if (path_end != NULL) {
28-
*path_end = '\0';
29-
}
30-
31-
return std::string(cwd);
32-
}
33-
3417
extern "C" {
3518
char *
3619
aot_generate_tempfile_name(const char *prefix, const char *extension,
@@ -50,7 +33,7 @@ class aot_compiler_test_suit : public testing::Test
5033

5134
static void SetUpTestCase()
5235
{
53-
CWD = get_binary_path();
36+
CWD = get_test_binary_dir();
5437
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
5538
}
5639

@@ -117,8 +100,13 @@ TEST_F(aot_compiler_test_suit, aot_emit_object_file)
117100

118101
// Test size_level in range from 0 to 3.
119102
option.opt_level = 3;
120-
for (i = 0; i <= 3; i++) {
121-
option.size_level = i;
103+
#if defined(__aarch64__) || defined(_M_ARM64)
104+
std::vector<int> size_levels = { 0, 3 };
105+
#else
106+
std::vector<int> size_levels = { 0, 1, 2, 3 };
107+
#endif
108+
for (auto size_level : size_levels) {
109+
option.size_level = size_level;
122110
test_aot_emit_object_file_with_option(&option);
123111
}
124112

tests/unit/compilation/aot_emit_aot_file_test.cc

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,6 @@ static std::string CWD;
1414
static std::string MAIN_WASM = "/main.wasm";
1515
static char *WASM_FILE;
1616

17-
static std::string
18-
get_binary_path()
19-
{
20-
char cwd[1024];
21-
memset(cwd, 0, 1024);
22-
23-
if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
24-
}
25-
26-
char *path_end = strrchr(cwd, '/');
27-
if (path_end != NULL) {
28-
*path_end = '\0';
29-
}
30-
31-
return std::string(cwd);
32-
}
33-
3417
extern "C" {
3518
uint8 *
3619
aot_emit_aot_file_buf(AOTCompContext *comp_ctx, AOTCompData *comp_data,
@@ -50,7 +33,7 @@ class aot_emit_aot_file_test_suite : public testing::Test
5033

5134
static void SetUpTestCase()
5235
{
53-
CWD = get_binary_path();
36+
CWD = get_test_binary_dir();
5437
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
5538
}
5639

tests/unit/compilation/aot_emit_control_test.cc

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,6 @@ static std::string CWD;
1515
static std::string MAIN_WASM = "/main.wasm";
1616
static char *WASM_FILE;
1717

18-
static std::string
19-
get_binary_path()
20-
{
21-
char cwd[1024];
22-
memset(cwd, 0, 1024);
23-
24-
if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
25-
}
26-
27-
char *path_end = strrchr(cwd, '/');
28-
if (path_end != NULL) {
29-
*path_end = '\0';
30-
}
31-
32-
return std::string(cwd);
33-
}
34-
3518
class aot_emit_control_test_suite : public testing::Test
3619
{
3720
protected:
@@ -45,7 +28,7 @@ class aot_emit_control_test_suite : public testing::Test
4528

4629
static void SetUpTestCase()
4730
{
48-
CWD = get_binary_path();
31+
CWD = get_test_binary_dir();
4932
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
5033
}
5134

tests/unit/compilation/aot_emit_function_test.cc

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,6 @@ static std::string CWD;
1414
static std::string MAIN_WASM = "/main.wasm";
1515
static char *WASM_FILE;
1616

17-
static std::string
18-
get_binary_path()
19-
{
20-
char cwd[1024];
21-
memset(cwd, 0, 1024);
22-
23-
if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
24-
}
25-
26-
char *path_end = strrchr(cwd, '/');
27-
if (path_end != NULL) {
28-
*path_end = '\0';
29-
}
30-
31-
return std::string(cwd);
32-
}
33-
3417
class aot_emit_function_test_suite : public testing::Test
3518
{
3619
protected:
@@ -44,7 +27,7 @@ class aot_emit_function_test_suite : public testing::Test
4427

4528
static void SetUpTestCase()
4629
{
47-
CWD = get_binary_path();
30+
CWD = get_test_binary_dir();
4831
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
4932
}
5033

tests/unit/compilation/aot_emit_memory_test.cc

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,12 @@ static std::string CWD;
1616
static std::string MAIN_WASM = "/main.wasm";
1717
static char *WASM_FILE;
1818

19-
static std::string
20-
get_binary_path()
21-
{
22-
char cwd[1024];
23-
memset(cwd, 0, 1024);
24-
25-
if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
26-
}
27-
28-
char *path_end = strrchr(cwd, '/');
29-
if (path_end != NULL) {
30-
*path_end = '\0';
31-
}
32-
33-
return std::string(cwd);
34-
}
35-
3619
class compilation_aot_emit_memory_test : public testing::Test
3720
{
3821
protected:
3922
void SetUp() override
4023
{
41-
CWD = get_binary_path();
24+
CWD = get_test_binary_dir();
4225
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
4326
AOTCompOption option = { 0 };
4427

tests/unit/compilation/aot_emit_numberic_test.cc

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,6 @@ static std::string CWD;
1515
static std::string MAIN_WASM = "/main.wasm";
1616
static char *WASM_FILE;
1717

18-
static std::string
19-
get_binary_path()
20-
{
21-
char cwd[1024];
22-
memset(cwd, 0, 1024);
23-
24-
if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
25-
}
26-
27-
char *path_end = strrchr(cwd, '/');
28-
if (path_end != NULL) {
29-
*path_end = '\0';
30-
}
31-
32-
return std::string(cwd);
33-
}
34-
3518
class aot_emit_numberic_test_suite : public testing::Test
3619
{
3720
protected:
@@ -45,7 +28,7 @@ class aot_emit_numberic_test_suite : public testing::Test
4528

4629
static void SetUpTestCase()
4730
{
48-
CWD = get_binary_path();
31+
CWD = get_test_binary_dir();
4932
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
5033
}
5134

tests/unit/compilation/aot_emit_parametric_test.cc

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,6 @@ static std::string CWD;
1414
static std::string MAIN_WASM = "/main.wasm";
1515
static char *WASM_FILE;
1616

17-
static std::string
18-
get_binary_path()
19-
{
20-
char cwd[1024];
21-
memset(cwd, 0, 1024);
22-
23-
if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
24-
}
25-
26-
char *path_end = strrchr(cwd, '/');
27-
if (path_end != NULL) {
28-
*path_end = '\0';
29-
}
30-
31-
return std::string(cwd);
32-
}
33-
3417
class aot_emit_parametric_test_suite : public testing::Test
3518
{
3619
protected:
@@ -44,7 +27,7 @@ class aot_emit_parametric_test_suite : public testing::Test
4427

4528
static void SetUpTestCase()
4629
{
47-
CWD = get_binary_path();
30+
CWD = get_test_binary_dir();
4831
WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
4932
}
5033

0 commit comments

Comments
 (0)