Skip to content

Commit 6862721

Browse files
ibmibmibmhydai
authored andcommitted
[WASI] Add wasi-test for testing basic WASI interface
* Run wasi-test on Github Action Signed-off-by: Shen-Ta Hsieh <[email protected]>
1 parent 5e8a06e commit 6862721

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ jobs:
120120
apt update
121121
apt install -y gcovr ninja-build
122122
123+
- name: Install rustup
124+
run: |
125+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --target wasm32-wasi
126+
123127
- name: Build WasmEdge using gcc with Debug mode
124128
run: |
125129
cmake -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DBUILD_COVERAGE=ON .

test/host/wasi/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ target_link_libraries(wasiTests
1212
wasmedgeAST
1313
wasmedgeHostModuleWasi
1414
)
15+
16+
if(BUILD_COVERAGE)
17+
add_test(
18+
NAME wasi-test
19+
COMMAND bash -c "[ -e \"$HOME/.cargo/env\" ] && . \"$HOME/.cargo/env\"; \"${PROJECT_SOURCE_DIR}\"/utils/wasi-test/run-wasi-test.sh \"${PROJECT_BINARY_DIR}/tools/wasmedge\""
20+
)
21+
endif()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
From a33de43ac84703faa5a0ee4d7403360e0efb1922 Mon Sep 17 00:00:00 2001
2+
From: Shen-Ta Hsieh <[email protected]>
3+
Date: Sat, 19 Jun 2021 10:03:12 +0800
4+
Subject: [PATCH] [PATCH] Disable other tests except wasmedge
5+
6+
---
7+
compat.py | 12 +++++++-----
8+
1 file changed, 7 insertions(+), 5 deletions(-)
9+
10+
diff --git a/compat.py b/compat.py
11+
index 9341520..da54714 100755
12+
--- a/compat.py
13+
+++ b/compat.py
14+
@@ -28,8 +28,14 @@ def load_config(filepath):
15+
return config
16+
17+
def test(cmd, config, cwd):
18+
+ print(' '.join(cmd))
19+
result = subprocess.run(cmd, cwd=cwd, encoding='utf8', input=config.get('stdin'), timeout=config.get('timeout', 5), capture_output=True)
20+
- assert_result(result, config)
21+
+ try:
22+
+ assert_result(result, config)
23+
+ except:
24+
+ print('==stderr==')
25+
+ print(result.stderr)
26+
+ raise
27+
28+
def test_deno(filepath, config, cwd):
29+
cmd = ['deno', 'run']
30+
@@ -202,10 +208,6 @@ def main():
31+
inputs.extend(sorted(glob.glob("target/wasm32-wasi/**/*.wasm")))
32+
33+
tests = {
34+
- "deno": test_deno,
35+
- "node": test_node,
36+
- "wasmer": test_wasmer,
37+
- "wasmtime": test_wasmtime,
38+
"wasmedge": test_wasmedge,
39+
}
40+
41+
--
42+
2.31.1
43+

utils/wasi-test/run-wasi-test.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: Apache-2.0
3+
# Test WasmEdge WASI layer.
4+
# The testcase is from https://github.com/khronosproject/wasi-test
5+
6+
set -Eeuo pipefail
7+
trap cleanup SIGINT SIGTERM ERR EXIT
8+
9+
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
10+
current_dir=$(pwd -P)
11+
12+
usage() {
13+
cat <<EOF
14+
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [path_to_wasmedge_tools]
15+
16+
Run wasi-test testcases.
17+
18+
Available options:
19+
20+
-h, --help Print this help and exit
21+
EOF
22+
exit
23+
}
24+
25+
cleanup() {
26+
trap - SIGINT SIGTERM ERR EXIT
27+
cd $current_dir
28+
msg "removing git repo"
29+
rm -Rf wasi-test
30+
return 0
31+
}
32+
33+
msg() {
34+
echo >&2 -e "${1-}"
35+
}
36+
37+
die() {
38+
local msg=$1
39+
local code=${2-1} # default exit status 1
40+
msg "$msg"
41+
exit "$code"
42+
}
43+
44+
parse_params() {
45+
while :; do
46+
case "${1-}" in
47+
-h | --help) usage ;;
48+
-v | --verbose) set -x ;;
49+
-?*) die "Unknown option: $1" ;;
50+
*) break ;;
51+
esac
52+
shift
53+
done
54+
55+
if ! command -v realpath &> /dev/null; then
56+
realpath() {
57+
readlink -f -- "$@"
58+
}
59+
fi
60+
61+
local wasmedge_path=$(realpath "${1-}")
62+
msg "path = $wasmedge_path"
63+
if [[ x"$wasmedge_path" != x ]]; then
64+
export PATH="$wasmedge_path:$PATH"
65+
fi
66+
return 0
67+
}
68+
69+
check_command() {
70+
if ! command -v "$1" &> /dev/null; then
71+
die "$1 not found!"
72+
exit 1
73+
fi
74+
return 0
75+
}
76+
77+
parse_params "$@"
78+
check_command git
79+
check_command python3
80+
check_command wasmedgec
81+
check_command wasmedge
82+
83+
msg "Cloning git repo..."
84+
git clone https://github.com/khronosproject/wasi-test.git --depth 1
85+
cd wasi-test
86+
87+
msg "Applying patch..."
88+
git apply "$script_dir"/0001-PATCH-Disable-other-tests-except-wasmedge.patch
89+
90+
if command -v cargo &> /dev/null; then
91+
msg "Building wasm files..."
92+
cargo build --release --target wasm32-wasi
93+
else
94+
curl -L -O https://github.com/khronosproject/wasi-test-suite/archive/refs/heads/master.tar.gz
95+
mkdir -p target/wasm32-wasi
96+
tar -xf master.tar.gz -C target/wasm32-wasi
97+
fi
98+
99+
msg "Running tests..."
100+
python3 compat.py

0 commit comments

Comments
 (0)