Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -74,6 +74,17 @@ ) endif() +if(CMAKE_SYSTEM_NAME STREQUAL "Android") + add_custom_target(push_android + COMMAND ${PROJECT_SOURCE_DIR}/utils/push_android.sh + ${TEST_SUITE_REMOTE_HOST} + ${TEST_SUITE_ANDROID_RUN_UNDER} + ${PROJECT_BINARY_DIR} + ${TEST_SUITE_ANDROID_PREBUILT_LOCATION} + USES_TERMINAL + ) +endif() + # Run Under configuration for RunSafely.sh (will be set in lit.site.cfg) set(TEST_SUITE_RUN_UNDER "" CACHE STRING "RunSafely.sh run-under (-u) parameter") Index: External/SPEC/CFP2006/CMakeLists.txt =================================================================== --- External/SPEC/CFP2006/CMakeLists.txt +++ External/SPEC/CFP2006/CMakeLists.txt @@ -2,9 +2,12 @@ if(TEST_SUITE_SPEC2006_ROOT) cpu2006_subdir(433.milc) cpu2006_subdir(444.namd) - cpu2006_subdir(447.dealII) cpu2006_subdir(450.soplex) cpu2006_subdir(453.povray) cpu2006_subdir(470.lbm) cpu2006_subdir(482.sphinx3) + + if(NOT TARGET_OS STREQUAL "Android") + cpu2006_subdir(447.dealII) + endif() endif() Index: External/SPEC/CINT2006/462.libquantum/CMakeLists.txt =================================================================== --- External/SPEC/CINT2006/462.libquantum/CMakeLists.txt +++ External/SPEC/CINT2006/462.libquantum/CMakeLists.txt @@ -8,11 +8,20 @@ # diff --strip-trailing-cr # (This flag is a gnu extension, maybe we should rather extend fpcmp or # somehow copy+fix the reference outputs?) - llvm_test_verify(RUN_TYPE ${run_type} WORKDIR ${CMAKE_CURRENT_BINARY_DIR} - diff --strip-trailing-cr - data/${run_type}/output/${run_type}.out - ${run_type}.out - ) + # diff in Android doesn't have --strip-trailing-cr, use -w instead + if(NOT TARGET_OS STREQUAL "Android") + llvm_test_verify(RUN_TYPE ${run_type} WORKDIR ${CMAKE_CURRENT_BINARY_DIR} + diff --strip-trailing-cr + data/${run_type}/output/${run_type}.out + ${run_type}.out + ) + else() + llvm_test_verify(RUN_TYPE ${run_type} WORKDIR ${CMAKE_CURRENT_BINARY_DIR} + diff -w + data/${run_type}/output/${run_type}.out + ${run_type}.out + ) + endif() endmacro() test_input(test 33 5) Index: External/SPEC/CINT2006/CMakeLists.txt =================================================================== --- External/SPEC/CINT2006/CMakeLists.txt +++ External/SPEC/CINT2006/CMakeLists.txt @@ -1,6 +1,5 @@ include(${CMAKE_SOURCE_DIR}/External/SPEC/SpecCPU2006.cmake) if(TEST_SUITE_SPEC2006_ROOT) - cpu2006_subdir(400.perlbench) cpu2006_subdir(401.bzip2) cpu2006_subdir(403.gcc) cpu2006_subdir(429.mcf) @@ -8,8 +7,12 @@ cpu2006_subdir(456.hmmer) cpu2006_subdir(458.sjeng) cpu2006_subdir(462.libquantum) - cpu2006_subdir(464.h264ref) cpu2006_subdir(471.omnetpp) cpu2006_subdir(473.astar) - cpu2006_subdir(483.xalancbmk) + + if(NOT TARGET_OS STREQUAL "Android") + cpu2006_subdir(400.perlbench) + cpu2006_subdir(464.h264ref) + cpu2006_subdir(483.xalancbmk) + endif() endif() Index: MicroBenchmarks/CMakeLists.txt =================================================================== --- MicroBenchmarks/CMakeLists.txt +++ MicroBenchmarks/CMakeLists.txt @@ -1,8 +1,10 @@ file(COPY lit.local.cfg DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) -add_subdirectory(libs) -add_subdirectory(XRay) -add_subdirectory(LCALS) -add_subdirectory(harris) -add_subdirectory(ImageProcessing) -add_subdirectory(LoopInterchange) +if(NOT TARGET_OS STREQUAL "Android") + add_subdirectory(libs) + add_subdirectory(XRay) + add_subdirectory(LCALS) + add_subdirectory(harris) + add_subdirectory(ImageProcessing) + add_subdirectory(LoopInterchange) +endif() Index: MultiSource/Applications/CMakeLists.txt =================================================================== --- MultiSource/Applications/CMakeLists.txt +++ MultiSource/Applications/CMakeLists.txt @@ -1,4 +1,6 @@ -add_subdirectory(JM) +if(NOT TARGET_OS STREQUAL "Android") + add_subdirectory(JM) +endif() add_subdirectory(SIBsim4) add_subdirectory(aha) add_subdirectory(d) @@ -8,37 +10,46 @@ add_subdirectory(oggenc) endif() add_subdirectory(sgefa) -add_subdirectory(spiff) +if(NOT TARGET_OS STREQUAL "Android") + add_subdirectory(spiff) +endif() add_subdirectory(viterbi) add_subdirectory(ALAC) add_subdirectory(hbd) add_subdirectory(lambda-0.1.3) add_subdirectory(minisat) -if(NOT TARGET_OS STREQUAL "SunOS") +if(NOT TARGET_OS STREQUAL "SunOS" + AND (NOT TARGET_OS STREQUAL "Android")) add_subdirectory(hexxagon) endif() if(NOT DEFINED SMALL_PROBLEM_SIZE) add_subdirectory(lua) endif() -if(TARGET_OS STREQUAL "Linux" AND (NOT ARCH STREQUAL "XCore")) +if(TARGET_OS STREQUAL "Linux" AND (NOT ARCH STREQUAL "XCore") + AND (NOT TARGET_OS STREQUAL "Android")) add_subdirectory(obsequi) endif() if(NOT TARGET_OS STREQUAL "SunOS") add_subdirectory(kimwitu++) endif() -if(NOT TARGET_OS STREQUAL "SunOS") +if(NOT TARGET_OS STREQUAL "SunOS" + AND (NOT TARGET_OS STREQUAL "Android")) add_subdirectory(SPASS) endif() if(NOT ARCH STREQUAL "XCore") - add_subdirectory(ClamAV) add_subdirectory(lemon) - add_subdirectory(siod) + if(NOT TARGET_OS STREQUAL "Android") + add_subdirectory(ClamAV) + add_subdirectory(siod) + endif() endif() if((NOT ARCH STREQUAL "PowerPC") AND (NOT ARCH STREQUAL "XCore")) add_subdirectory(sqlite3) endif() if(NOT TEST_SUITE_BENCHMARKING_ONLY) - add_subdirectory(Burg) + if(NOT TARGET_OS STREQUAL "Android") + add_subdirectory(Burg) + endif() add_subdirectory(treecc) endif() Index: MultiSource/Benchmarks/CMakeLists.txt =================================================================== --- MultiSource/Benchmarks/CMakeLists.txt +++ MultiSource/Benchmarks/CMakeLists.txt @@ -29,7 +29,9 @@ add_subdirectory(tramp3d-v4) add_subdirectory(DOE-ProxyApps-C++) if(NOT "${ARCH}" STREQUAL "XCore") - add_subdirectory(7zip) + if(NOT TARGET_OS STREQUAL "Android") + add_subdirectory(7zip) + endif() add_subdirectory(PAQ8p) endif() if(NOT DEFINED SMALL_PROBLEM_SIZE) Index: MultiSource/Benchmarks/DOE-ProxyApps-C++/CMakeLists.txt =================================================================== --- MultiSource/Benchmarks/DOE-ProxyApps-C++/CMakeLists.txt +++ MultiSource/Benchmarks/DOE-ProxyApps-C++/CMakeLists.txt @@ -1,5 +1,7 @@ add_subdirectory(HPCCG) add_subdirectory(PENNANT) add_subdirectory(miniFE) -add_subdirectory(CLAMR) +if(NOT TARGET_OS STREQUAL "Android") + add_subdirectory(CLAMR) +endif() add_subdirectory(HACCKernels) Index: MultiSource/Benchmarks/MiBench/CMakeLists.txt =================================================================== --- MultiSource/Benchmarks/MiBench/CMakeLists.txt +++ MultiSource/Benchmarks/MiBench/CMakeLists.txt @@ -4,7 +4,9 @@ add_subdirectory(consumer-jpeg) add_subdirectory(consumer-typeset) add_subdirectory(network-dijkstra) -add_subdirectory(network-patricia) +if(NOT TARGET_OS STREQUAL "Android") + add_subdirectory(network-patricia) +endif() add_subdirectory(security-rijndael) add_subdirectory(security-sha) add_subdirectory(telecomm-CRC32) @@ -17,7 +19,8 @@ add_subdirectory(office-stringsearch) add_subdirectory(security-blowfish) add_subdirectory(telecomm-adpcm) - if((NOT "${ARCH}" STREQUAL "XCore") AND (NOT "${ARCH}" STREQUAL "ARM")) + if((NOT "${ARCH}" STREQUAL "XCore") AND (NOT "${ARCH}" STREQUAL "ARM") + AND (NOT TARGET_OS STREQUAL "Android")) add_subdirectory(office-ispell) endif() endif() Index: MultiSource/Benchmarks/Prolangs-C/CMakeLists.txt =================================================================== --- MultiSource/Benchmarks/Prolangs-C/CMakeLists.txt +++ MultiSource/Benchmarks/Prolangs-C/CMakeLists.txt @@ -1,6 +1,7 @@ add_subdirectory(agrep) add_subdirectory(gnugo) -if((NOT "${ARCH}" STREQUAL "Sparc") AND (NOT "${ARCH}" STREQUAL "Alpha")) +if((NOT "${ARCH}" STREQUAL "Sparc") AND (NOT "${ARCH}" STREQUAL "Alpha") + AND (NOT TARGET_OS STREQUAL "Android")) add_subdirectory(bison) endif() if(NOT TEST_SUITE_BENCHMARKING_ONLY) @@ -17,6 +18,8 @@ add_subdirectory(unix-tbl) if(NOT "${ARCH}" STREQUAL "XCore") add_subdirectory(archie-client) - add_subdirectory(unix-smail) + if(NOT TARGET_OS STREQUAL "Android") + add_subdirectory(unix-smail) + endif() endif() endif() Index: SingleSource/UnitTests/C++11/CMakeLists.txt =================================================================== --- SingleSource/UnitTests/C++11/CMakeLists.txt +++ SingleSource/UnitTests/C++11/CMakeLists.txt @@ -3,7 +3,11 @@ file(GLOB Source RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.c *.cpp) if(${CMAKE_EXE_LINKER_FLAGS} MATCHES "-static") - list(APPEND LDFLAGS -Wl,--whole-archive -lpthread -Wl,--no-whole-archive) + if(CMAKE_SYSTEM_NAME STREQUAL "Android") + list(APPEND LDFLAGS -Wl,--whole-archive -Wl,--no-whole-archive) + else() + list(APPEND LDFLAGS -Wl,--whole-archive -lpthread -Wl,--no-whole-archive) + endif() endif() llvm_singlesource() Index: SingleSource/UnitTests/CMakeLists.txt =================================================================== --- SingleSource/UnitTests/CMakeLists.txt +++ SingleSource/UnitTests/CMakeLists.txt @@ -42,4 +42,7 @@ ms_struct_pack_layout-1.c ) endif() +if(TARGET_OS STREQUAL "Android") + list(REMOVE_ITEM Source 2005-05-11-Popcount-ffs-fls.c) +endif() llvm_singlesource() Index: cmake/templates/build-arm64-linux-android.sh =================================================================== --- /dev/null +++ cmake/templates/build-arm64-linux-android.sh @@ -0,0 +1,68 @@ +#!/bin/bash +rm -rf CMakeCache.txt + + +# REQUIRED: path to the test-suite source file +TEST_SUITE_LOCATION="/data/local/tmp/devspace/test-suite" +# REQUIRED: path to android ndk that contains necessary header files and libraries +ANDROID_NDK_LOCATION="/usr/local/google/home/ziangwan/Desktop/android-ndk-r20" + +# REQUIRED: host system name +# Look inside $ANDROID_NDK_LOCATION/toolchains/llvm/prebuilt to figure out. +HOST_SYSTEM="linux-x86_64" + +# REQUIRED: target android device serial number +DEVICE_SERIAL="852Y007XC" +# REQUIRED: a writable location on the device to run the test. +DEVICE_TEST_LOCATION="/data/local/tmp" + +# OPTIONAL: path to custom llvm build bin not inside Android NDK +COMPILER_BUILD="/data/local/tmp/docspace/llvm-build" +# OPTIONAL: custom flags used during compilation +CUSTOMC_COMPILE_FLAGS="-mcpu=cortex-a57.cortex-a53" +# OPTIONAL: path to SPEC CPU2006 folder +# /data/local/tmp/docspace/cpu2006 +SPEC2006_LOCATION="" + + +# Construct command line arguments to make the test-suite compile. +# -L $ANDROID_NDK_LOCATION/toolchains/llvm/prebuilt/$HOST_SYSTEM/lib/gcc/aarch64-linux-android/4.9.x/ +COMPILE_FLAGS="$CUSTOMC_COMPILE_FLAGS \ +-Wno-format-security \ +-D BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD" + +# Define SPEC_CPU_LINUX macro for SPEC to correctly execute. +if [[ ! -z $SPEC2006_LOCATION ]]; then + COMPILE_FLAGS+=" -D SPEC_CPU_LINUX" +fi + + +# Create a symbolic link to custom compiler build, if any. +PREBUILT_LOCATION=$ANDROID_NDK_LOCATION/toolchains/llvm/prebuilt/$HOST_SYSTEM +if [[ ! -z $COMPILER_BUILD ]]; then + rm -f $PREBUILT_LOCATION/bin/clang + rm -f $PREBUILT_LOCATION/bin/clang++ + ln -s $COMPILER_BUILD/bin/clang $PREBUILT_LOCATION/bin/clang + ln -s $COMPILER_BUILD/bin/clang++ $PREBUILT_LOCATION/bin/clang++ + ln -s $COMPILER_BUILD/lib/clang $PREBUILT_LOCATION/lib/clang +fi + + +# -D TEST_SUITE_BENCHMARKING_ONLY=false \ +# -D TEST_SUITE_SPEC2006_ROOT=$SPEC2006_LOCATION \ +# -D TEST_SUITE_RUN_TYPE=ref \ +cmake \ + -D CMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_LOCATION/build/cmake/android.toolchain.cmake \ + -D ANDROID_NATIVE_API_LEVEL=29 \ + -D ANDROID_ABI=arm64-v8a \ + -D CMAKE_C_FLAGS="$COMPILE_FLAGS" \ + -D CMAKE_CXX_FLAGS="$COMPILE_FLAGS" \ + -D CMAKE_STRIP=$COMPILER_BUILD/bin/llvm-strip \ + -D TEST_SUITE_REMOTE_CLIENT="adb" \ + -D TEST_SUITE_REMOTE_HOST=$DEVICE_SERIAL \ + -D TEST_SUITE_ANDROID_RUN_UNDER=$DEVICE_TEST_LOCATION \ + -D TEST_SUITE_ANDROID_PREBUILT_LOCATION=$PREBUILT_LOCATION \ + -D TEST_SUITE_COLLECT_CODE_SIZE=Off \ + -G "Ninja" \ + -C $TEST_SUITE_LOCATION/cmake/caches/O3.cmake \ + $TEST_SUITE_LOCATION Index: lit.cfg =================================================================== --- lit.cfg +++ lit.cfg @@ -31,6 +31,9 @@ config.remote_host = lit_config.params.get('remote_host', config.remote_host) if config.remote_host: config.test_modules.append('remote') +if config.remote_client == "adb": + config.test_modules.remove("remote") + config.test_modules.append("android") # Load previous test results so we can skip tests that did not change. previous_results_file = lit_config.params.get('previous', None) Index: lit.site.cfg.in =================================================================== --- lit.site.cfg.in +++ lit.site.cfg.in @@ -5,6 +5,7 @@ config.remote_client = "@TEST_SUITE_REMOTE_CLIENT@" config.remote_host = "@TEST_SUITE_REMOTE_HOST@" config.run_under = "@TEST_SUITE_RUN_UNDER@" +config.android_run_under = "@TEST_SUITE_ANDROID_RUN_UNDER@" config.strip_tool = "@CMAKE_STRIP@" config.profile_generate = @TEST_SUITE_PROFILE_GENERATE@ config.llvm_profdata = "@TEST_SUITE_LLVM_PROFDATA@" Index: litsupport/modules/android.py =================================================================== --- /dev/null +++ litsupport/modules/android.py @@ -0,0 +1,60 @@ +""" Allow cross-execution targeting Android devices. + +Test module to execute a benchmark through adb on a connected Android +device. This assumes all relevant directories and files are present on the remote +device.""" +import logging +import os +import subprocess + +from litsupport import testplan + + +def mutatePlan(context, plan): + # serial number of the device + if hasattr(context.config, "remote_host") and context.config.remote_host != "": + remote_host = "-s " + context.config.remote_host + else: + remote_host = "" + + # the path to load libc++_shared.so + extra_lib_loc = "LD_LIBRARY_PATH=" + context.config.android_run_under + + # Prepend `adb [-s remote_host] shell` in front of each command. + # Prepend LD_LIBRARY_PATH to resolve libc++_shared.so. + def make_adb_command(s_in): + s_out = "adb {} shell \"{} {}\"".format( + remote_host, extra_lib_loc, s_in) + return s_out + + plan.preparescript = [make_adb_command(script) + for script in plan.preparescript] + plan.runscript = [make_adb_command(script) + for script in plan.runscript] + plan.verifyscript = [make_adb_command(script) + for script in plan.verifyscript] + + # Create output directory if nonexist. + plan.preparescript.append("adb {} shell mkdir -p {}".format( + remote_host, context.tmpDir)) + + # Replace the host-side path in the commands with + # device-side path. + toreplace_str = context.config.test_source_root + replacement_str = os.path.join(context.config.android_run_under, + os.path.split(context.config.test_source_root)[1]) + + plan.preparescript = [script.replace(toreplace_str, replacement_str) + for script in plan.preparescript] + plan.runscript = [script.replace(toreplace_str, replacement_str) + for script in plan.runscript] + plan.verifyscript = [script.replace(toreplace_str, replacement_str) + for script in plan.verifyscript] + + # adb pull timeit time files. + if hasattr(context, "timefiles"): + for timefile in context.timefiles: + plan.profilescript.append("adb {} pull {} {}".format( + remote_host, + timefile.replace(toreplace_str, replacement_str), + timefile)) Index: utils/push_android.sh =================================================================== --- /dev/null +++ utils/push_android.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# the target id +DEVICE_SERIAL=$1 +# location on the test device +DEVICE_TEST_LOCATION=$2 +# build source path +BUILD_DIRECTORY=$3 +# the host system name +PREBUILT_LOCATION=$4 + + +# Create a stage directory inside the build directory that +# excludes all files that need not to be pushed. +RSYNC_FLAGS="" +RSYNC_FLAGS+=" -a" +RSYNC_FLAGS+=" --delete --delete-excluded" +RSYNC_FLAGS+=" --exclude=\"*.o\"" +RSYNC_FLAGS+=" --exclude=\"*.a\"" +RSYNC_FLAGS+=" --exclude=\"*.time\"" +RSYNC_FLAGS+=" --exclude=\"*.cmake\"" +RSYNC_FLAGS+=" --exclude=Output/" +RSYNC_FLAGS+=" --exclude=.ninja_deps" +RSYNC_FLAGS+=" --exclude=.ninja_log" +RSYNC_FLAGS+=" --exclude=build.ninja" +RSYNC_FLAGS+=" --exclude=rules.ninja" +RSYNC_FLAGS+=" --exclude=CMakeFiles/" + +rm -rf $BUILD_DIRECTORY/stage +rsync $RSYNC_FLAGS $BUILD_DIRECTORY $BUILD_DIRECTORY/stage/ + + +# Push the stage directory onto the device. +adb -s $DEVICE_SERIAL shell rm -rf $DEVICE_TEST_LOCATION/$(basename $BUILD_DIRECTORY) +adb -s $DEVICE_SERIAL push $BUILD_DIRECTORY/stage/$(basename $BUILD_DIRECTORY) $DEVICE_TEST_LOCATION + + +# Remove the stage directory. +rm -rf $BUILD_DIRECTORY/stage + + +# Push the shared library onto the device. +adb -s $DEVICE_SERIAL push $PREBUILT_LOCATION/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so \ + $DEVICE_TEST_LOCATION/libc++_shared.so