Enhance/Fix sample socket-api and workload (#2006)

- Add python script to test socket-api cases
- Fix issues in socket-api send_recv wasm app
- Fix issues in building samples/workload/meshoptimizer
- Enhance build script of sample workload
This commit is contained in:
Wenyong Huang 2023-03-08 16:36:08 +08:00 committed by GitHub
parent a15a731e12
commit 289fc5efbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 199 additions and 34 deletions

View File

@ -10,9 +10,18 @@ import subprocess
import sys import sys
import time import time
import traceback import traceback
import glob
WAMRC_CMD = "../../wamr-compiler/build/wamrc" WAMRC_CMD = "../../wamr-compiler/build/wamrc"
def compile_wasm_files_to_aot(wasm_apps_dir):
wasm_files = glob.glob(wasm_apps_dir + "/*.wasm")
print("Compile wasm app into aot files")
for wasm_file in wasm_files:
aot_file = wasm_file[0 : len(wasm_file) - 5] + ".aot";
cmd = [ WAMRC_CMD, "-o", aot_file, wasm_file ]
subprocess.check_call(cmd)
def start_server(cwd): def start_server(cwd):
""" """
Startup the 'simple' process works in TCP server mode Startup the 'simple' process works in TCP server mode
@ -92,19 +101,8 @@ def main():
print("Test with AOT mode") print("Test with AOT mode")
test_aot = True test_aot = True
suffix = ".aot" suffix = ".aot"
wasm_files = [ "timer", "sensor", "connection", wasm_apps_dir = args.working_directory + "/wasm-apps"
"event_publisher", "event_subscriber", compile_wasm_files_to_aot(wasm_apps_dir)
"request_handler", "request_sender" ]
work_dir = args.working_directory
wasm_apps_dir = work_dir + "/wasm-apps"
print("Compile wasm app into aot files")
for wasm_file in wasm_files:
CMD = []
CMD.append(WAMRC_CMD)
CMD.append("-o")
CMD.append(wasm_apps_dir + "/" + wasm_file + ".aot")
CMD.append(wasm_apps_dir + "/" + wasm_file + ".wasm")
subprocess.check_call(CMD)
ret = 1 ret = 1
app_server = None app_server = None

View File

@ -0,0 +1,141 @@
#!/usr/bin/env python3
#
# Copyright (C) 2023 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
import argparse
import shlex
import subprocess
import sys
import time
import traceback
import glob
WAMRC_CMD = "../../wamr-compiler/build/wamrc"
def compile_wasm_files_to_aot(wasm_apps_dir):
wasm_files = glob.glob(wasm_apps_dir + "/*.wasm")
print("Compile wasm app into aot files")
for wasm_file in wasm_files:
aot_file = wasm_file[0 : len(wasm_file) - 5] + ".aot";
cmd = [ WAMRC_CMD, "-o", aot_file, wasm_file ]
subprocess.check_call(cmd)
def start_server(cmd, cwd):
app_server = subprocess.Popen(shlex.split(cmd), cwd=cwd)
return app_server
def run_cmd(cmd, cwd):
qry_prc = subprocess.run(
shlex.split(cmd), cwd=cwd, check=False, capture_output=True
)
if (qry_prc.returncode != 0):
print("Run {} failed, return {}".format(cmd), qry_prc.returncode)
return
print("return code: {}, output:\n{}".format(qry_prc.returncode,
qry_prc.stdout.decode()))
def main():
"""
GO!GO!!GO!!!
"""
parser = argparse.ArgumentParser(description="run the sample and examine outputs")
parser.add_argument("working_directory", type=str)
parser.add_argument("--aot", action='store_true', help="Test with AOT")
args = parser.parse_args()
test_aot = False
suffix = ".wasm"
if not args.aot:
print("Test with interpreter mode")
else:
print("Test with AOT mode")
test_aot = True
suffix = ".aot"
wasm_apps_dir = args.working_directory
compile_wasm_files_to_aot(wasm_apps_dir)
ret = 1
app_server = None
try:
print("\n================================")
print("Test TCP server and client")
cmd = "./iwasm --addr-pool=0.0.0.0/15 tcp_server" + suffix
app_server = start_server(cmd, args.working_directory)
# wait for a second
time.sleep(1)
cmd = "./iwasm --addr-pool=127.0.0.1/15 tcp_client" + suffix
for i in range(5):
run_cmd(cmd, args.working_directory)
print("\n================================")
print("Test UDP server and client")
cmd = "./iwasm --addr-pool=0.0.0.0/15 udp_server" + suffix
app_server = start_server(cmd, args.working_directory)
# wait for a second
time.sleep(1)
cmd = "./iwasm --addr-pool=127.0.0.1/15 udp_client" + suffix
for i in range(5):
run_cmd(cmd, args.working_directory)
print("\n=====================================================")
print("Sleep 80 seconds to wait TCP server port actually close")
time.sleep(80)
print("\n================================")
print("Test send and receive")
cmd = "./iwasm --addr-pool=127.0.0.1/0 ./send_recv" + suffix
run_cmd(cmd, args.working_directory)
print("\n================================")
print("Test socket options")
cmd = "./iwasm socket_opts" + suffix
run_cmd(cmd, args.working_directory)
print("\n================================")
print("Test timeout server and client")
cmd = "./iwasm --addr-pool=0.0.0.0/15 timeout_server" + suffix
app_server = start_server(cmd, args.working_directory)
# wait for a second
time.sleep(1)
cmd = "./iwasm --addr-pool=127.0.0.1/15 timeout_client" + suffix
run_cmd(cmd, args.working_directory)
print("\n==========================================")
print("Test multicast_client and multicast_server")
cmd = "./iwasm --addr-pool=0.0.0.0/0,::/0 multicast_client.wasm 224.0.0.1"
app_server = start_server(cmd, args.working_directory)
# wait for a second
time.sleep(1)
cmd = "./multicast_server 224.0.0.1"
run_cmd(cmd, args.working_directory)
cmd = "./iwasm --addr-pool=0.0.0.0/0,::/0 multicast_client.wasm FF02:113D:6FDD:2C17:A643:FFE2:1BD1:3CD2"
app_server = start_server(cmd, args.working_directory)
# wait for a second
time.sleep(1)
cmd = "./multicast_server FF02:113D:6FDD:2C17:A643:FFE2:1BD1:3CD2"
run_cmd(cmd, args.working_directory)
print("\n================================")
print("Test address resolving")
cmd = "./iwasm --allow-resolve=*.com addr_resolve.wasm github.com"
cmd = "./multicast_server FF02:113D:6FDD:2C17:A643:FFE2:1BD1:3CD2"
run_cmd(cmd, args.working_directory)
# wait for a second
time.sleep(1)
print("--> All pass")
ret = 0
except AssertionError:
traceback.print_exc()
finally:
app_server.kill()
return ret
if __name__ == "__main__":
sys.exit(main())

View File

@ -19,6 +19,7 @@
static pthread_mutex_t lock = { 0 }; static pthread_mutex_t lock = { 0 };
static pthread_cond_t cond = { 0 }; static pthread_cond_t cond = { 0 };
static bool server_create_failed = false;
static bool server_is_ready = false; static bool server_is_ready = false;
void * void *
@ -46,6 +47,8 @@ run_as_server(void *arg)
pthread_mutex_lock(&lock); pthread_mutex_lock(&lock);
sock = socket(AF_INET, SOCK_STREAM, 0); sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) { if (sock < 0) {
server_create_failed = true;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
perror("Create a socket failed"); perror("Create a socket failed");
return NULL; return NULL;
@ -53,6 +56,8 @@ run_as_server(void *arg)
#ifndef __wasi__ #ifndef __wasi__
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on))) { if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on))) {
server_create_failed = true;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
perror("Setsockopt failed"); perror("Setsockopt failed");
goto fail1; goto fail1;
@ -66,12 +71,16 @@ run_as_server(void *arg)
addrlen = sizeof(addr); addrlen = sizeof(addr);
if (bind(sock, (struct sockaddr *)&addr, addrlen) < 0) { if (bind(sock, (struct sockaddr *)&addr, addrlen) < 0) {
server_create_failed = true;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
perror("Bind failed"); perror("Bind failed");
goto fail1; goto fail1;
} }
if (listen(sock, 0) < 0) { if (listen(sock, 0) < 0) {
server_create_failed = true;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
perror("Listen failed"); perror("Listen failed");
goto fail1; goto fail1;
@ -117,11 +126,15 @@ run_as_client(void *arg)
ssize_t recv_len = 0; ssize_t recv_len = 0;
pthread_mutex_lock(&lock); pthread_mutex_lock(&lock);
while (false == server_is_ready) { while (!server_create_failed && !server_is_ready) {
pthread_cond_wait(&cond, &lock); pthread_cond_wait(&cond, &lock);
} }
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
if (server_create_failed) {
return NULL;
}
printf("Client is running...\n"); printf("Client is running...\n");
sock = socket(AF_INET, SOCK_STREAM, 0); sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) { if (sock < 0) {

View File

@ -23,6 +23,7 @@
static pthread_mutex_t lock = { 0 }; static pthread_mutex_t lock = { 0 };
static pthread_cond_t cond = { 0 }; static pthread_cond_t cond = { 0 };
static bool server_create_failed = false;
static bool server_is_ready = false; static bool server_is_ready = false;
#ifdef __wasi__ #ifdef __wasi__
@ -71,6 +72,8 @@ run_as_server(void *arg)
pthread_mutex_lock(&lock); pthread_mutex_lock(&lock);
sock = socket(AF_INET, SOCK_STREAM, 0); sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) { if (sock < 0) {
server_create_failed = true;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
perror("Create a socket failed"); perror("Create a socket failed");
return NULL; return NULL;
@ -78,6 +81,8 @@ run_as_server(void *arg)
#ifndef __wasi__ #ifndef __wasi__
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on))) { if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on))) {
server_create_failed = true;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
perror("Setsockopt failed"); perror("Setsockopt failed");
goto fail1; goto fail1;
@ -91,12 +96,16 @@ run_as_server(void *arg)
addrlen = sizeof(addr); addrlen = sizeof(addr);
if (bind(sock, (struct sockaddr *)&addr, addrlen) < 0) { if (bind(sock, (struct sockaddr *)&addr, addrlen) < 0) {
server_create_failed = true;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
perror("Bind failed"); perror("Bind failed");
goto fail1; goto fail1;
} }
if (listen(sock, 0) < 0) { if (listen(sock, 0) < 0) {
server_create_failed = true;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
perror("Listen failed"); perror("Listen failed");
goto fail1; goto fail1;
@ -142,11 +151,15 @@ run_as_client(void *arg)
ssize_t recv_len = 0; ssize_t recv_len = 0;
pthread_mutex_lock(&lock); pthread_mutex_lock(&lock);
while (false == server_is_ready) { while (!server_create_failed && !server_is_ready) {
pthread_cond_wait(&cond, &lock); pthread_cond_wait(&cond, &lock);
} }
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
if (server_create_failed) {
return NULL;
}
local_printf("Client is running...\n"); local_printf("Client is running...\n");
sock = socket(AF_INET, SOCK_STREAM, 0); sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) { if (sock < 0) {

View File

@ -24,7 +24,7 @@ ExternalProject_Add(iwasm
CONFIGURE_COMMAND CONFIGURE_COMMAND
${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/../../product-mini/platforms/linux -B build -DWAMR_BUILD_LIBC_EMCC=1 ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/../../product-mini/platforms/linux -B build -DWAMR_BUILD_LIBC_EMCC=1
BUILD_COMMAND BUILD_COMMAND
${CMAKE_COMMAND} --build build ${CMAKE_COMMAND} --build build --parallel 4
INSTALL_COMMAND INSTALL_COMMAND
# FIXME: replace with --install # FIXME: replace with --install
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_COMMAND} -E copy_if_different
@ -43,7 +43,7 @@ ExternalProject_Add(wamrc
CONFIGURE_COMMAND CONFIGURE_COMMAND
${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/../../wamr-compiler -B build ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/../../wamr-compiler -B build
BUILD_COMMAND BUILD_COMMAND
${CMAKE_COMMAND} --build build ${CMAKE_COMMAND} --build build --parallel 4
INSTALL_COMMAND INSTALL_COMMAND
# FIXME: replace with --install # FIXME: replace with --install
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_COMMAND} -E copy_if_different

View File

@ -50,7 +50,7 @@ ExternalProject_Add(bwa
-DCMAKE_SYSROOT=${WASISDK_SYSROOT} -DCMAKE_SYSROOT=${WASISDK_SYSROOT}
-DCMAKE_C_FLAGS=-isystem\ ${CMAKE_CURRENT_SOURCE_DIR}/../include/sse\ -isystem\ ${CMAKE_CURRENT_SOURCE_DIR}/../include/libc/musl -DCMAKE_C_FLAGS=-isystem\ ${CMAKE_CURRENT_SOURCE_DIR}/../include/sse\ -isystem\ ${CMAKE_CURRENT_SOURCE_DIR}/../include/libc/musl
${CMAKE_CURRENT_SOURCE_DIR}/bwa ${CMAKE_CURRENT_SOURCE_DIR}/bwa
BUILD_COMMAND make bwa_wasm_opt BUILD_COMMAND make bwa_wasm_opt -j 4
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different ./bwa.opt.wasm ${CMAKE_CURRENT_BINARY_DIR}/bwa.wasm INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different ./bwa.opt.wasm ${CMAKE_CURRENT_BINARY_DIR}/bwa.wasm
) )

View File

@ -21,7 +21,7 @@ include(ExternalProject)
ExternalProject_Add(codecbench ExternalProject_Add(codecbench
PREFIX codecbench PREFIX codecbench
GIT_REPOSITORY https://github.com/zeux/meshoptimizer.git GIT_REPOSITORY https://github.com/zeux/meshoptimizer.git
GIT_TAG f926b288264522e1b331a41b07ba40167f396913 GIT_TAG f734fd572aed5bf76e84d9ed62ca6f4f6c47d84e
GIT_SHALLOW ON GIT_SHALLOW ON
GIT_PROGRESS ON GIT_PROGRESS ON
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/meshoptimizer SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/meshoptimizer
@ -33,6 +33,6 @@ ExternalProject_Add(codecbench
-DCMAKE_TOOLCHAIN_FILE=${WASISDK_TOOLCHAIN} -DCMAKE_TOOLCHAIN_FILE=${WASISDK_TOOLCHAIN}
-DCMAKE_SYSROOT=${WASISDK_SYSROOT} -DCMAKE_SYSROOT=${WASISDK_SYSROOT}
${CMAKE_CURRENT_SOURCE_DIR}/meshoptimizer ${CMAKE_CURRENT_SOURCE_DIR}/meshoptimizer
BUILD_COMMAND make codecbench BUILD_COMMAND make codecbench -j 4
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different ./codecbench.wasm ${CMAKE_CURRENT_BINARY_DIR}/codecbench.wasm INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different ./codecbench.wasm ${CMAKE_CURRENT_BINARY_DIR}/codecbench.wasm
) )

View File

@ -1,8 +1,8 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt
index b13d946..4254003 100644 index 612cf3b..22a365a 100644
--- a/CMakeLists.txt --- a/CMakeLists.txt
+++ b/CMakeLists.txt +++ b/CMakeLists.txt
@@ -149,3 +149,43 @@ install(FILES @@ -158,3 +158,43 @@ install(FILES
${CMAKE_CURRENT_BINARY_DIR}/meshoptimizerConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/meshoptimizerConfigVersion.cmake
COMPONENT meshoptimizer COMPONENT meshoptimizer
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/meshoptimizer) DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/meshoptimizer)
@ -47,10 +47,10 @@ index b13d946..4254003 100644
+ +
+add_dependencies(codecbench.opt codecbench) +add_dependencies(codecbench.opt codecbench)
diff --git a/src/vertexcodec.cpp b/src/vertexcodec.cpp diff --git a/src/vertexcodec.cpp b/src/vertexcodec.cpp
index 821c467..b7d30b1 100644 index 4bd1112..257c258 100644
--- a/src/vertexcodec.cpp --- a/src/vertexcodec.cpp
+++ b/src/vertexcodec.cpp +++ b/src/vertexcodec.cpp
@@ -83,13 +83,13 @@ @@ -89,13 +89,13 @@
#endif #endif
#ifdef SIMD_WASM #ifdef SIMD_WASM
@ -71,7 +71,7 @@ index 821c467..b7d30b1 100644
#endif #endif
namespace meshopt namespace meshopt
@@ -691,7 +691,7 @@ static v128_t decodeShuffleMask(unsigned char mask0, unsigned char mask1) @@ -757,7 +757,7 @@ static v128_t decodeShuffleMask(unsigned char mask0, unsigned char mask1)
v128_t sm1 = wasm_v128_load(&kDecodeBytesGroupShuffle[mask1]); v128_t sm1 = wasm_v128_load(&kDecodeBytesGroupShuffle[mask1]);
v128_t sm1off = wasm_v128_load(&kDecodeBytesGroupCount[mask0]); v128_t sm1off = wasm_v128_load(&kDecodeBytesGroupCount[mask0]);
@ -80,7 +80,7 @@ index 821c467..b7d30b1 100644
v128_t sm1r = wasm_i8x16_add(sm1, sm1off); v128_t sm1r = wasm_i8x16_add(sm1, sm1off);
@@ -741,7 +741,7 @@ static const unsigned char* decodeBytesGroupSimd(const unsigned char* data, unsi @@ -807,7 +807,7 @@ static const unsigned char* decodeBytesGroupSimd(const unsigned char* data, unsi
v128_t shuf = decodeShuffleMask(mask0, mask1); v128_t shuf = decodeShuffleMask(mask0, mask1);
@ -89,7 +89,7 @@ index 821c467..b7d30b1 100644
wasm_v128_store(buffer, result); wasm_v128_store(buffer, result);
@@ -763,7 +763,7 @@ static const unsigned char* decodeBytesGroupSimd(const unsigned char* data, unsi @@ -829,7 +829,7 @@ static const unsigned char* decodeBytesGroupSimd(const unsigned char* data, unsi
v128_t shuf = decodeShuffleMask(mask0, mask1); v128_t shuf = decodeShuffleMask(mask0, mask1);
@ -99,7 +99,7 @@ index 821c467..b7d30b1 100644
wasm_v128_store(buffer, result); wasm_v128_store(buffer, result);
diff --git a/src/vertexfilter.cpp b/src/vertexfilter.cpp diff --git a/src/vertexfilter.cpp b/src/vertexfilter.cpp
index 14a73b1..8f4b3c1 100644 index 5c7589c..c79cad4 100644
--- a/src/vertexfilter.cpp --- a/src/vertexfilter.cpp
+++ b/src/vertexfilter.cpp +++ b/src/vertexfilter.cpp
@@ -57,10 +57,10 @@ @@ -57,10 +57,10 @@
@ -116,4 +116,4 @@ index 14a73b1..8f4b3c1 100644
+#define wasmx_unziphi_v32x4(a, b) wasm_i32x4_shuffle(a, b, 1, 3, 5, 7) +#define wasmx_unziphi_v32x4(a, b) wasm_i32x4_shuffle(a, b, 1, 3, 5, 7)
#endif #endif
namespace meshopt #ifndef __has_builtin

View File

@ -36,7 +36,7 @@ ExternalProject_Add(av1
-DCMAKE_SYSROOT=${WASISDK_SYSROOT} -DCMAKE_SYSROOT=${WASISDK_SYSROOT}
-DCMAKE_C_FLAGS=-isystem\ ${CMAKE_CURRENT_SOURCE_DIR}/../include/sse\ -isystem\ ${CMAKE_CURRENT_SOURCE_DIR}/../include/libc/musl -DCMAKE_C_FLAGS=-isystem\ ${CMAKE_CURRENT_SOURCE_DIR}/../include/sse\ -isystem\ ${CMAKE_CURRENT_SOURCE_DIR}/../include/libc/musl
${CMAKE_CURRENT_SOURCE_DIR}/av1 ${CMAKE_CURRENT_SOURCE_DIR}/av1
BUILD_COMMAND make testavx_opt BUILD_COMMAND make testavx_opt -j 4
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different
testavx.opt.wasm testavx.opt.wasm
${CMAKE_CURRENT_SOURCE_DIR}/av1/third_party/samples/elephants_dream_480p24.ivf ${CMAKE_CURRENT_SOURCE_DIR}/av1/third_party/samples/elephants_dream_480p24.ivf