2016-09-23 16:04:33 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-02-05 09:49:33 +00:00
|
|
|
#############################################################################
|
|
|
|
#
|
2021-02-19 12:54:16 +00:00
|
|
|
# This script tests Android cross-compiles using setenv-android.sh script.
|
2021-02-05 09:49:33 +00:00
|
|
|
#
|
2021-03-08 22:51:48 +00:00
|
|
|
# Written and placed in public domain by Jeffrey Walton and Uri Blumenthal.
|
2021-02-05 09:49:33 +00:00
|
|
|
#
|
|
|
|
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
|
|
|
|
# licensed under the Boost Software License 1.0, while the individual files
|
|
|
|
# in the compilation are all public domain.
|
2016-09-23 16:04:33 +00:00
|
|
|
#
|
|
|
|
# See http://www.cryptopp.com/wiki/Android_(Command_Line) for more details
|
2021-02-05 09:49:33 +00:00
|
|
|
#
|
2021-02-05 08:56:14 +00:00
|
|
|
#############################################################################
|
|
|
|
|
2021-02-07 08:59:34 +00:00
|
|
|
# Error checking
|
|
|
|
if [ -z "$(command -v ./setenv-android.sh 2>/dev/null)" ]; then
|
|
|
|
echo "Failed to locate setenv-android.sh."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Error checking
|
|
|
|
if [ ! -d "${ANDROID_NDK_ROOT}" ]; then
|
2021-02-07 11:31:33 +00:00
|
|
|
echo "ERROR: ANDROID_NDK_ROOT is not a valid path for ${USER}. Please set it."
|
|
|
|
echo "ANDROID_NDK_ROOT is '${ANDROID_NDK_ROOT}'"
|
2021-02-07 08:59:34 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Error checking
|
|
|
|
if [ ! -d "${ANDROID_SDK_ROOT}" ]; then
|
2021-02-07 11:31:33 +00:00
|
|
|
echo "ERROR: ANDROID_SDK_ROOT is not a valid path for ${USER}. Please set it."
|
|
|
|
echo "ANDROID_SDK_ROOT is '${ANDROID_SDK_ROOT}'"
|
2021-02-05 10:18:29 +00:00
|
|
|
exit 1
|
2018-07-30 19:32:53 +00:00
|
|
|
fi
|
|
|
|
|
2021-02-15 21:36:23 +00:00
|
|
|
# Error checking
|
|
|
|
if [ -z "$(command -v ndk-build 2>/dev/null)" ]; then
|
|
|
|
echo "ERROR: ndk-build is not on-path for ${USER}. Please set it."
|
|
|
|
echo "PATH is '${PATH}'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-10-16 11:30:40 +00:00
|
|
|
# Temp directory
|
2021-02-07 16:44:15 +00:00
|
|
|
if [[ -z "${TMPDIR}" ]]; then
|
2020-03-10 01:53:08 +00:00
|
|
|
TMPDIR="$HOME/tmp"
|
2021-02-07 16:44:15 +00:00
|
|
|
mkdir -p "${TMPDIR}"
|
2021-02-15 21:49:26 +00:00
|
|
|
if [ -n "${SUDO_USER}" ]; then
|
|
|
|
chown -R "${SUDO_USER}" "${TMPDIR}"
|
2021-02-15 23:14:09 +00:00
|
|
|
fi
|
2018-01-21 14:05:34 +00:00
|
|
|
fi
|
2019-10-15 22:05:54 +00:00
|
|
|
|
2021-02-05 10:18:29 +00:00
|
|
|
# Sane default
|
|
|
|
if [[ -z "${MAKE_JOBS}" ]]; then
|
|
|
|
MAKE_JOBS=4
|
|
|
|
fi
|
2019-10-16 11:30:40 +00:00
|
|
|
|
|
|
|
# Cleanup old artifacts
|
2021-02-07 16:44:15 +00:00
|
|
|
rm -rf "${TMPDIR}/build.failed" 2>/dev/null
|
|
|
|
rm -rf "${TMPDIR}/build.log" 2>/dev/null
|
Add ARMv8.4 cpu feature detection support (GH #685) (#687)
This PR adds ARMv8.4 cpu feature detection support. Previously we only needed ARMv8.1 and things were much easier. For example, ARMv8.1 `__ARM_FEATURE_CRYPTO` meant PMULL, AES, SHA-1 and SHA-256 were available. ARMv8.4 `__ARM_FEATURE_CRYPTO` means PMULL, AES, SHA-1, SHA-256, SHA-512, SHA-3, SM3 and SM4 are available.
We still use the same pattern as before. We make something available based on compiler version and/or preprocessor macros. But this time around we had to tighten things up a bit to ensure ARMv8.4 did not cross-pollinate down into ARMv8.1.
ARMv8.4 is largely untested at the moment. There is no hardware in the field and CI lacks QEMU with the relevant patches/support. We will probably have to revisit some of this stuff in the future.
Since this update applies to ARM gadgets we took the time to expand Android and iOS testing on Travis. Travis now tests more platforms, and includes Autotools and CMake builds, too.
2018-07-15 12:35:14 +00:00
|
|
|
|
2021-02-05 10:18:29 +00:00
|
|
|
#############################################################################
|
|
|
|
|
2021-03-08 22:46:09 +00:00
|
|
|
# Prepare the environment
|
|
|
|
unset CXX CPPFLAGS CXXFLAGS LDFLAGS
|
|
|
|
unset ANDROID_CPPFLAGS ANDROID_CXXFLAGS ANDROID_LDFLAGS ANDROID_SYSROOT
|
|
|
|
|
|
|
|
if [[ -e TestScripts/setenv-android.sh ]]; then
|
|
|
|
cp TestScripts/setenv-android.sh .
|
2021-03-08 22:50:13 +00:00
|
|
|
chmod u+x setenv-android.sh
|
2021-03-08 22:46:09 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
|
2020-03-10 01:53:08 +00:00
|
|
|
PLATFORMS=(armv7a aarch64 x86 x86_64)
|
2019-10-16 11:30:40 +00:00
|
|
|
|
|
|
|
for platform in "${PLATFORMS[@]}"
|
2016-09-23 16:04:33 +00:00
|
|
|
do
|
2020-03-13 20:20:17 +00:00
|
|
|
# setenv-android.sh reads these two variables for configuration info.
|
2021-02-14 22:00:01 +00:00
|
|
|
# Android 5.0 is 21. Android 6.0 is 23.
|
2022-12-27 15:37:04 +00:00
|
|
|
export ANDROID_API="23"
|
2021-02-07 16:44:15 +00:00
|
|
|
export ANDROID_CPU="${platform}"
|
2020-03-11 06:22:27 +00:00
|
|
|
|
2020-03-10 01:53:08 +00:00
|
|
|
make -f GNUmakefile-cross distclean > /dev/null 2>&1
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "===================================================================="
|
2021-02-07 16:44:15 +00:00
|
|
|
echo "Testing for Android support of ${platform}"
|
2020-03-10 01:53:08 +00:00
|
|
|
|
2020-03-10 15:50:33 +00:00
|
|
|
# Test if we can set the environment for the platform
|
|
|
|
if ! ./setenv-android.sh > /dev/null 2>&1;
|
|
|
|
then
|
|
|
|
echo
|
2021-02-07 16:44:15 +00:00
|
|
|
echo "There were problems testing ${platform}"
|
|
|
|
echo "${platform} ==> SKIPPED" >> "${TMPDIR}/build.log"
|
2020-03-10 01:53:08 +00:00
|
|
|
|
2020-03-10 15:50:33 +00:00
|
|
|
continue
|
|
|
|
fi
|
2020-03-10 01:53:08 +00:00
|
|
|
|
|
|
|
echo
|
2021-02-05 10:18:29 +00:00
|
|
|
echo "===================================================================="
|
2021-02-07 16:44:15 +00:00
|
|
|
echo "Building for ${platform}..."
|
2020-03-10 01:53:08 +00:00
|
|
|
|
|
|
|
# run in subshell to not keep any envars
|
|
|
|
(
|
2020-03-11 06:22:27 +00:00
|
|
|
source ./setenv-android.sh
|
2021-02-07 16:44:15 +00:00
|
|
|
if make -k -j "${MAKE_JOBS}" -f GNUmakefile-cross static dynamic cryptest.exe;
|
2020-03-10 01:53:08 +00:00
|
|
|
then
|
2021-02-07 16:44:15 +00:00
|
|
|
echo "${platform} ==> SUCCESS" >> "${TMPDIR}/build.log"
|
2020-03-10 01:53:08 +00:00
|
|
|
else
|
2021-02-07 16:44:15 +00:00
|
|
|
echo "${platform} ==> FAILURE" >> "${TMPDIR}/build.log"
|
|
|
|
touch "${TMPDIR}/build.failed"
|
2020-03-10 01:53:08 +00:00
|
|
|
fi
|
2021-03-09 14:43:57 +00:00
|
|
|
|
2021-03-11 21:14:58 +00:00
|
|
|
# Test code generation
|
|
|
|
if [[ "${platform}" == "armv7a" ]]
|
|
|
|
then
|
|
|
|
|
|
|
|
# Test NEON code generation
|
2022-01-06 17:43:15 +00:00
|
|
|
# In the past we looked for the vector loads, stores and shifts using vld and friends.
|
|
|
|
# It looks like objdump changed its output format on Android after Clang, so we need
|
|
|
|
# to check for statements like eor v0.16b, v2.16b, v0.16b nowadays.
|
2023-09-30 07:11:15 +00:00
|
|
|
count=$(${OBJDUMP} --disassemble chacha_simd.o 2>&1 | grep -c -E 'vld|vst|vshl|vshr|veor|v0\.|v1\.|v2\.|v3\.|v4\.|v5\.|v6\.|v7\.')
|
2021-03-11 21:14:58 +00:00
|
|
|
if [[ "${count}" -gt 64 ]]
|
|
|
|
then
|
|
|
|
echo "${platform} : NEON ==> SUCCESS" >> "${TMPDIR}/build.log"
|
|
|
|
else
|
|
|
|
echo "${platform} : NEON ==> FAILURE" >> "${TMPDIR}/build.log"
|
|
|
|
touch "${TMPDIR}/build.failed"
|
|
|
|
fi
|
|
|
|
|
|
|
|
elif [[ "${platform}" == "aarch64" ]]
|
2021-03-09 14:43:57 +00:00
|
|
|
then
|
|
|
|
|
2021-03-11 22:22:40 +00:00
|
|
|
# Test ASIMD code generation
|
2022-01-06 17:43:15 +00:00
|
|
|
# In the past we looked for the vector loads, stores and shifts using vld and friends.
|
|
|
|
# It looks like objdump changed its output format on Android after Clang, so we need
|
|
|
|
# to check for statements like eor v0.16b, v2.16b, v0.16b nowadays.
|
2023-09-30 07:11:15 +00:00
|
|
|
count=$(${OBJDUMP} --disassemble chacha_simd.o 2>&1 | grep -c -E 'vld|vst|vshl|vshr|veor|v0\.|v1\.|v2\.|v3\.|v4\.|v5\.|v6\.|v7\.')
|
2021-03-11 22:22:40 +00:00
|
|
|
if [[ "${count}" -gt 64 ]]
|
|
|
|
then
|
|
|
|
echo "${platform} : ASIMD ==> SUCCESS" >> "${TMPDIR}/build.log"
|
|
|
|
else
|
|
|
|
echo "${platform} : ASIMD ==> FAILURE" >> "${TMPDIR}/build.log"
|
|
|
|
touch "${TMPDIR}/build.failed"
|
|
|
|
fi
|
|
|
|
|
2021-03-09 14:43:57 +00:00
|
|
|
# Test AES code generation
|
|
|
|
count=$(${OBJDUMP} --disassemble rijndael_simd.o 2>&1 | grep -c -E 'aese|aesd|aesmc|aesimc')
|
2021-03-11 21:14:58 +00:00
|
|
|
if [[ "${count}" -gt 32 ]]
|
2021-03-09 14:43:57 +00:00
|
|
|
then
|
|
|
|
echo "${platform} : AES ==> SUCCESS" >> "${TMPDIR}/build.log"
|
|
|
|
else
|
|
|
|
echo "${platform} : AES ==> FAILURE" >> "${TMPDIR}/build.log"
|
|
|
|
touch "${TMPDIR}/build.failed"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Test PMULL code generation
|
|
|
|
count=$(${OBJDUMP} --disassemble gcm_simd.o 2>&1 | grep -c -E 'pmull|pmull2')
|
2021-03-11 21:14:58 +00:00
|
|
|
if [[ "${count}" -gt 16 ]]
|
2021-03-09 14:43:57 +00:00
|
|
|
then
|
|
|
|
echo "${platform} : PMULL ==> SUCCESS" >> "${TMPDIR}/build.log"
|
|
|
|
else
|
|
|
|
echo "${platform} : PMULL ==> FAILURE" >> "${TMPDIR}/build.log"
|
|
|
|
touch "${TMPDIR}/build.failed"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Test SHA1 code generation
|
|
|
|
count=$(${OBJDUMP} --disassemble sha_simd.o 2>&1 | grep -c -E 'sha1c|sha1m|sha1p|sha1h|sha1su0|sha1su1')
|
2021-03-11 21:14:58 +00:00
|
|
|
if [[ "${count}" -gt 32 ]]
|
2021-03-09 14:43:57 +00:00
|
|
|
then
|
|
|
|
echo "${platform} : SHA1 ==> SUCCESS" >> "${TMPDIR}/build.log"
|
|
|
|
else
|
|
|
|
echo "${platform} : SHA1 ==> FAILURE" >> "${TMPDIR}/build.log"
|
|
|
|
touch "${TMPDIR}/build.failed"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Test SHA2 code generation
|
|
|
|
count=$(${OBJDUMP} --disassemble sha_simd.o | grep -c -E 'sha256h|sha256su0|sha256su1')
|
2021-03-11 21:14:58 +00:00
|
|
|
if [[ "${count}" -gt 32 ]]
|
2021-03-09 14:43:57 +00:00
|
|
|
then
|
|
|
|
echo "${platform} : SHA2 ==> SUCCESS" >> "${TMPDIR}/build.log"
|
|
|
|
else
|
|
|
|
echo "${platform} : SHA2 ==> FAILURE" >> "${TMPDIR}/build.log"
|
|
|
|
touch "${TMPDIR}/build.failed"
|
|
|
|
fi
|
|
|
|
elif [[ "${platform}" == "x86" || "${platform}" == "x86_64" ]]
|
|
|
|
then
|
|
|
|
|
|
|
|
# Test AES code generation
|
|
|
|
count=$(${OBJDUMP} --disassemble rijndael_simd.o 2>&1 | grep -c -E 'aesenc|aesdec|aesenclast|aesdeclast|aesimc')
|
2021-03-11 21:14:58 +00:00
|
|
|
if [[ "${count}" -gt 32 ]]
|
2021-03-09 14:43:57 +00:00
|
|
|
then
|
|
|
|
echo "${platform} : AES ==> SUCCESS" >> "${TMPDIR}/build.log"
|
|
|
|
else
|
|
|
|
echo "${platform} : AES ==> FAILURE" >> "${TMPDIR}/build.log"
|
|
|
|
touch "${TMPDIR}/build.failed"
|
|
|
|
fi
|
|
|
|
|
2021-05-10 18:44:15 +00:00
|
|
|
# Test CLMUL code generation
|
2021-03-12 02:07:13 +00:00
|
|
|
count=$(${OBJDUMP} --disassemble gcm_simd.o 2>&1 | grep -c -E 'pclmulqdq|pclmullqlq|pclmullqhq|vpclmulqdq')
|
2021-03-11 21:14:58 +00:00
|
|
|
if [[ "${count}" -gt 16 ]]
|
2021-03-09 14:43:57 +00:00
|
|
|
then
|
2021-05-10 18:44:15 +00:00
|
|
|
echo "${platform} : CLMUL ==> SUCCESS" >> "${TMPDIR}/build.log"
|
2021-03-09 14:43:57 +00:00
|
|
|
else
|
2021-05-10 18:44:15 +00:00
|
|
|
echo "${platform} : CLMUL ==> FAILURE" >> "${TMPDIR}/build.log"
|
2021-03-09 14:43:57 +00:00
|
|
|
touch "${TMPDIR}/build.failed"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Test SHA1 code generation
|
|
|
|
count=$(${OBJDUMP} --disassemble sha_simd.o 2>&1 | grep -c -E 'sha1rnds4|sha1nexte|sha1msg1|sha1msg2')
|
2021-03-11 21:14:58 +00:00
|
|
|
if [[ "${count}" -gt 32 ]]
|
2021-03-09 14:43:57 +00:00
|
|
|
then
|
|
|
|
echo "${platform} : SHA1 ==> SUCCESS" >> "${TMPDIR}/build.log"
|
|
|
|
else
|
|
|
|
echo "${platform} : SHA1 ==> FAILURE" >> "${TMPDIR}/build.log"
|
|
|
|
touch "${TMPDIR}/build.failed"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Test SHA2 code generation
|
|
|
|
count=$(${OBJDUMP} --disassemble sha_simd.o | grep -c -E 'sha256rnds2|sha256msg1|sha256msg2')
|
2021-03-11 21:14:58 +00:00
|
|
|
if [[ "${count}" -gt 32 ]]
|
2021-03-09 14:43:57 +00:00
|
|
|
then
|
|
|
|
echo "${platform} : SHA2 ==> SUCCESS" >> "${TMPDIR}/build.log"
|
|
|
|
else
|
|
|
|
echo "${platform} : SHA2 ==> FAILURE" >> "${TMPDIR}/build.log"
|
|
|
|
touch "${TMPDIR}/build.failed"
|
|
|
|
fi
|
|
|
|
fi
|
2020-03-10 01:53:08 +00:00
|
|
|
)
|
2016-09-23 16:04:33 +00:00
|
|
|
done
|
2018-01-21 14:05:34 +00:00
|
|
|
|
2021-02-05 10:18:29 +00:00
|
|
|
echo
|
2020-03-10 01:53:08 +00:00
|
|
|
echo "====================================================="
|
2021-02-07 16:44:15 +00:00
|
|
|
cat "${TMPDIR}/build.log"
|
2018-04-01 06:37:32 +00:00
|
|
|
|
2018-01-21 14:05:34 +00:00
|
|
|
# let the script fail if any of the builds failed
|
2021-02-07 16:44:15 +00:00
|
|
|
if [ -f "${TMPDIR}/build.failed" ]; then
|
2021-02-05 10:18:29 +00:00
|
|
|
exit 1
|
2018-01-21 14:05:34 +00:00
|
|
|
fi
|
2018-04-05 22:38:43 +00:00
|
|
|
|
2021-02-05 10:18:29 +00:00
|
|
|
exit 0
|