Skip to content

[Android] Add driver script for running tests in emulator when cross-compiling #855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
45 changes: 45 additions & 0 deletions tests/ctest-android.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/system/bin/sh

# Run tests in Android emulator when cross-compiling:
# $ adb push <binary-dir> /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