mirror of
https://github.com/cuberite/libdeflate.git
synced 2025-08-04 10:16:44 -04:00

android_tests is only useful for local testing, and it wasn't being run in Travis CI. Move it into a separate script to avoid complicating run_tests.sh.
63 lines
1.8 KiB
Bash
63 lines
1.8 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Test libdeflate on a connected arm64 Android device.
|
|
# Requires the Android NDK (release 19 or later) and adb.
|
|
|
|
set -eu -o pipefail
|
|
cd "$(dirname "$0")/.."
|
|
|
|
if [ $# -ne 0 ]; then
|
|
echo 1>&2 "Usage: $0"
|
|
exit 2
|
|
fi
|
|
|
|
# Use NDKDIR if specified in environment, else use default value.
|
|
: "${NDKDIR:=$HOME/android-ndk-r21d}"
|
|
if [ ! -e "$NDKDIR" ]; then
|
|
cat 1>&2 << EOF
|
|
Android NDK was not found in NDKDIR=$NDKDIR! Set the
|
|
environmental variable NDKDIR to the location of your Android NDK installation.
|
|
EOF
|
|
exit 1
|
|
fi
|
|
|
|
# Use TESTDATA if specified in environment, else generate it.
|
|
if [ -z "${TESTDATA:-}" ]; then
|
|
# Generate default TESTDATA file.
|
|
TESTDATA=$(mktemp -t libdeflate_testdata.XXXXXXX)
|
|
export TESTDATA
|
|
trap 'rm -f "$TESTDATA"' EXIT
|
|
find . '(' -name '*.c' -o -name '*.h' -o -name '*.sh' ')' \
|
|
-exec cat '{}' ';' | head -c 1000000 > "$TESTDATA"
|
|
fi
|
|
|
|
# Create a temporary file.
|
|
TMPFILE=$(mktemp -t libdeflate_tmpfile.XXXXXX)
|
|
trap 'rm -f "$TMPFILE"' EXIT
|
|
|
|
android_build_and_test() {
|
|
echo "Running Android tests with $*"
|
|
|
|
./scripts/android_build.sh --ndkdir="$NDKDIR" "$@" \
|
|
all test_programs > /dev/null
|
|
adb push "$TESTDATA" ./scripts/exec_tests.sh benchmark test_* \
|
|
/data/local/tmp/ > /dev/null
|
|
|
|
# Note: adb shell always returns 0, even if the shell command fails...
|
|
adb shell "cd /data/local/tmp && WRAPPER= TESTDATA=$(basename "$TESTDATA") sh exec_tests.sh" \
|
|
> "$TMPFILE"
|
|
if ! grep -q "exec_tests finished successfully" "$TMPFILE"; then
|
|
echo 1>&2 "Android test failure! adb shell output:"
|
|
cat "$TMPFILE"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
for arch in arm32 arm64; do
|
|
android_build_and_test --arch=$arch
|
|
android_build_and_test --arch=$arch --enable-crc
|
|
android_build_and_test --arch=$arch --enable-crypto
|
|
android_build_and_test --arch=$arch --enable-crc --enable-crypto
|
|
done
|
|
echo "Android tests passed"
|