Skip to content

Commit

Permalink
[Test] Fix the API unit test error of wasmedge_process on non-Linux
Browse files Browse the repository at this point in the history
platforms.

Signed-off-by: YiYing He <[email protected]>
  • Loading branch information
q82419 committed Jul 8, 2022
1 parent 6b37fb9 commit d4beee0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
38 changes: 29 additions & 9 deletions test/api/APIUnitTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2019-2022 Second State INC

#include "common/defines.h"
#include "wasmedge/wasmedge.h"

#include <algorithm>
Expand Down Expand Up @@ -933,17 +934,17 @@ TEST(APICoreTest, Compiler) {
WasmEdge_ConfigureCompilerSetOutputFormat(
Conf, WasmEdge_CompilerOutputFormat_Native);
Compiler = WasmEdge_CompilerCreate(Conf);
EXPECT_TRUE(WasmEdge_ResultOK(
WasmEdge_CompilerCompile(Compiler, TPath, "test_aot.so")));
EXPECT_TRUE(WasmEdge_ResultOK(WasmEdge_CompilerCompile(
Compiler, TPath, "test_aot" WASMEDGE_LIB_EXTENSION)));
EXPECT_TRUE(WasmEdge_ResultOK(WasmEdge_CompilerCompile(
Compiler, "../spec/testSuites/core/binary/binary.164.wasm",
"binary_164_aot.so")));
"binary_164_aot" WASMEDGE_LIB_EXTENSION)));
// Check the header of the output files.
OutFile.open("test_aot.so", std::ios::binary);
OutFile.open("test_aot" WASMEDGE_LIB_EXTENSION, std::ios::binary);
EXPECT_TRUE(OutFile.read(reinterpret_cast<char *>(Buf), 4));
OutFile.close();
EXPECT_FALSE(std::equal(WASMMagic, WASMMagic + 4, Buf));
OutFile.open("binary_164_aot.so", std::ios::binary);
OutFile.open("binary_164_aot" WASMEDGE_LIB_EXTENSION, std::ios::binary);
EXPECT_TRUE(OutFile.read(reinterpret_cast<char *>(Buf), 4));
OutFile.close();
EXPECT_FALSE(std::equal(WASMMagic, WASMMagic + 4, Buf));
Expand Down Expand Up @@ -1008,7 +1009,7 @@ TEST(APICoreTest, Loader) {
static_cast<uint32_t>(Buf.size()))));
#ifdef WASMEDGE_BUILD_AOT_RUNTIME
// Failed case to parse from buffer with AOT compiled WASM
EXPECT_TRUE(readToVector("test_aot.so", Buf));
EXPECT_TRUE(readToVector("test_aot" WASMEDGE_LIB_EXTENSION, Buf));
Mod = nullptr;
EXPECT_TRUE(isErrMatch(
WasmEdge_ErrCode_MalformedMagic,
Expand Down Expand Up @@ -2009,29 +2010,45 @@ TEST(APICoreTest, ModuleInstance) {
WasmEdge_VMDelete(VM);

// Setup extra plugin path
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || \
defined(__TOS_WIN__) || defined(__WINDOWS__)
#if WASMEDGE_OS_WINDOWS
::_putenv_s("WASMEDGE_PLUGIN_PATH", "../../plugins/wasmedge_process");
#else
::setenv("WASMEDGE_PLUGIN_PATH", "../../plugins/wasmedge_process", 0);
#endif

// wasmedge_process only works on Linux.
// Load plugins
WasmEdge_Plugin_loadWithDefaultPluginPaths();

// Create wasmedge_process.
HostMod = WasmEdge_ModuleInstanceCreateWasmEdgeProcess(Args, 2, false);
#if WASMEDGE_OS_LINUX
EXPECT_NE(HostMod, nullptr);
WasmEdge_ModuleInstanceDelete(HostMod);
#else
EXPECT_EQ(HostMod, nullptr);
#endif
HostMod = WasmEdge_ModuleInstanceCreateWasmEdgeProcess(nullptr, 0, false);
#if WASMEDGE_OS_LINUX
EXPECT_NE(HostMod, nullptr);
WasmEdge_ModuleInstanceDelete(HostMod);
#else
EXPECT_EQ(HostMod, nullptr);
#endif
HostMod = WasmEdge_ModuleInstanceCreateWasmEdgeProcess(Args, 2, true);
#if WASMEDGE_OS_LINUX
EXPECT_NE(HostMod, nullptr);
WasmEdge_ModuleInstanceDelete(HostMod);
#else
EXPECT_EQ(HostMod, nullptr);
#endif
HostMod = WasmEdge_ModuleInstanceCreateWasmEdgeProcess(nullptr, 0, true);
#if WASMEDGE_OS_LINUX
EXPECT_NE(HostMod, nullptr);
WasmEdge_ModuleInstanceDelete(HostMod);
#else
EXPECT_EQ(HostMod, nullptr);
#endif

// Initialize wasmedge_process in VM.
Conf = WasmEdge_ConfigureCreate();
Expand All @@ -2041,8 +2058,11 @@ TEST(APICoreTest, ModuleInstance) {
WasmEdge_ConfigureDelete(Conf);
HostMod = WasmEdge_VMGetImportModuleContext(
VM, WasmEdge_HostRegistration_WasmEdge_Process);
#if WASMEDGE_OS_LINUX
EXPECT_NE(HostMod, nullptr);
WasmEdge_ModuleInstanceInitWasmEdgeProcess(Args, 2, false);
#else
EXPECT_EQ(HostMod, nullptr);
#endif
WasmEdge_VMDelete(VM);
}

Expand Down
5 changes: 5 additions & 0 deletions test/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ target_link_libraries(wasmedgeAPIUnitTests
wasmedge_c_shared
)

target_include_directories(wasmedgeAPIUnitTests
PRIVATE
${CMAKE_SOURCE_DIR}/include
)

wasmedge_add_executable(wasmedgeAPIVMCoreTests
APIVMCoreTest.cpp
)
Expand Down

0 comments on commit d4beee0

Please sign in to comment.