Skip to content

Commit 336c06d

Browse files
Add test of cmake
1 parent c64198a commit 336c06d

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ default: build
5353
check:
5454
CC="clang --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot" \
5555
CXX="clang++ --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot -fno-exceptions" \
56-
PATH="$(PATH_PREFIX)/bin:$$PATH" tests/run.sh $(RUNTIME)
56+
PATH="$(PATH_PREFIX)/bin:$$PATH" tests/run.sh "$(RUNTIME)" "$(BUILD_PREFIX)"
5757

5858
clean:
5959
rm -rf build $(DESTDIR)

tests/cmake/CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
3+
project(wasi-sdk-test)
4+
5+
# Sanity check setup
6+
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL WASI)
7+
message(FATAL_ERROR "Wrong system name (${CMAKE_SYSTEM_NAME}), wrong toolchain file in use?")
8+
endif()
9+
10+
if(NOT DEFINED WASI)
11+
message(FATAL_ERROR "WASI is not set, platform file likely not loaded")
12+
endif()
13+
14+
set(RUNWASI "" CACHE STRING "Path to or name of WASM runner")
15+
16+
# Test build a C and C++ target respectively
17+
add_executable(void_main_c ../general/void_main.c)
18+
add_executable(void_main_cc ../general/void_main.cc)
19+
20+
include(CTest)
21+
enable_testing()
22+
23+
add_test(NAME void_main_c
24+
COMMAND
25+
${CMAKE_CURRENT_SOURCE_DIR}/test_driver.sh
26+
${RUNWASI}
27+
$<TARGET_FILE:void_main_c>
28+
${CMAKE_CURRENT_SOURCE_DIR}/../general/void_main.c.stdout.expected)
29+
add_test(NAME void_main_cc
30+
COMMAND
31+
${CMAKE_CURRENT_SOURCE_DIR}/test_driver.sh
32+
${RUNWASI}
33+
$<TARGET_FILE:void_main_cc>
34+
${CMAKE_CURRENT_SOURCE_DIR}/../general/void_main.cc.stdout.expected)

tests/cmake/test_driver.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# Simplified runner for cmake
3+
4+
set -ex
5+
6+
runwasi="$1"
7+
target="$2"
8+
stdout_expected="$3"
9+
stderr_expected="/dev/null"
10+
11+
stdout_observed="$target.stdout.observed"
12+
stderr_observed="$target.stderr.observed"
13+
14+
"$runwasi" "$target" > "$stdout_observed" 2> "$stderr_observed"
15+
16+
diff -u "$stderr_expected" "$stderr_observed"
17+
diff -u "$stdout_expected" "$stdout_observed"

tests/run.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ else
2020
runwasi=""
2121
fi
2222

23+
if [ $# -gt 1 ]; then
24+
wasi_sdk="$2"
25+
else
26+
wasi_sdk=""
27+
fi
28+
2329
testdir=$(dirname $0)
2430
CC=${CC:=clang}
2531
CXX=${CXX:=clang++}
2632

2733
echo $CC
2834
echo $CXX
35+
echo "SDK: $wasi_sdk"
2936

3037
cd $testdir/compile-only
3138
for options in -O0 -O2 "-O2 -flto"; do
@@ -54,3 +61,22 @@ for options in -O0 -O2 "-O2 -flto"; do
5461
done
5562
done
5663
cd - >/dev/null
64+
65+
if [[ -n "$wasi_sdk" ]]; then
66+
for option in Debug Release; do
67+
rm -rf "$testdir/cmake/build/$option"
68+
mkdir -p "$testdir/cmake/build/$option"
69+
cd "$testdir/cmake/build/$option"
70+
cmake \
71+
-DCMAKE_BUILD_TYPE="$option" \
72+
-DRUNWASI="$runwasi" \
73+
-DWASI_SDK_PREFIX="$wasi_sdk" \
74+
-DCMAKE_TOOLCHAIN_FILE="$wasi_sdk/share/cmake/wasi-sdk.cmake" \
75+
../..
76+
make
77+
if [[ -n "$runwasi" ]]; then
78+
ctest --output-on-failure
79+
fi
80+
cd - >/dev/null
81+
done
82+
fi

0 commit comments

Comments
 (0)