From 35b323639e0fc03b3c6f048c0b31b4a52fabe0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= Date: Wed, 29 Jan 2025 16:42:04 +0100 Subject: [PATCH] [Android] Add driver script to run tests emulator when cross-compiling --- tests/CMakeLists.txt | 6 ++++++ tests/ctest-android.sh.in | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/ctest-android.sh.in diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0176a062b..61f84edf0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -197,3 +197,9 @@ endif() # test-specific compile options set_target_properties(dispatch_c99 PROPERTIES C_STANDARD 99) + +if(CMAKE_SYSTEM_NAME STREQUAL Android) + configure_file(ctest-android.sh.in + ${CMAKE_CURRENT_BINARY_DIR}/ctest-android.sh + @ONLY NEWLINE_STYLE LF) +endif() diff --git a/tests/ctest-android.sh.in b/tests/ctest-android.sh.in new file mode 100644 index 000000000..72eda3924 --- /dev/null +++ b/tests/ctest-android.sh.in @@ -0,0 +1,45 @@ +#!/system/bin/sh + +# Run tests in Android emulator when cross-compiling: +# $ adb push /data/local/tmp" +# $ adb shell "sh /data/local/tmp/tests/ctest-android.sh" + +BINARY_DIR=$(dirname "$0")/.. +UTILITY="$BINARY_DIR/bsdtestharness" +if [ ! -f "$UTILITY" ]; then + echo "Utility not found: $UTILITY." + exit 1 +fi + +# CMake injects test executables at configuration time +TESTS="@DISPATCH_C_TESTS@" +COUNT=$(echo "$TESTS" | tr ';' '\n' | wc -l) +echo "Running $COUNT test-cases from $BINARY_DIR" + +# Tests depend on libdispatch.so and libBlocksRuntime.so +export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$BINARY_DIR" + +TIMOUT=120 +FAILURE=0 +IFS=';' +chmod +x "$UTILITY" + +for TEST in $TESTS; do + chmod +x "$BINARY_DIR/dispatch_$TEST" + OUTPUT=$(timeout "${TIMOUT}s" "$UTILITY" "$BINARY_DIR/dispatch_$TEST" 2>&1) + EC=$? + if [ $EC -eq 124 ]; then + echo "Error: dispatch_$TEST timed out after $TIMOUT seconds" + echo "************\nOutput:\n$OUTPUT\n************" + FAILURE=1 + elif [ $EC -ne 0 ]; then + echo "Error: dispatch_$TEST failed" + echo "************\nOutput:\n$OUTPUT\n************" + FAILURE=1 + else + echo "dispatch_$TEST passed" + fi +done + +unset IFS +exit $FAILURE