blob: 5feab065c7a5901cdbc7490b08baa632afe8d834 [file] [log] [blame]
Don Turnerfda67012018-01-19 18:10:25 +00001# Copyright 2018 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15################################################
16# Script to build and run the Oboe tests on an attached Android device or emulator
17#
18# Prerequisites:
19# - CMake on PATH
20# - ANDROID_NDK environment variable is set to your Android NDK location
21# e.g. /Library/Android/sdk/ndk-bundle
22# - Android device or emulator attached and accessible via adb
23#
24# Instructions:
25# Run this script from within the oboe/tests directory. A directory 'build' will be
26# created containing the test binary. This binary will then be copied to the device/emulator
27# and executed.
28#
29# The initial run may take some time as GTest is built, subsequent runs should be much, much
30# faster.
31#
32# If you want to perform a clean build just delete the 'build' folder and re-run this script
33#
34################################################
35
36#!/bin/bash
37
38# Directories, paths and filenames
39BUILD_DIR=build
40CMAKE=cmake
41TEST_BINARY_FILENAME=testOboe
Don Turnerff649d02018-07-04 18:35:02 +010042REMOTE_TEMP_DIR=/data/local/tmp
43TEST_PACKAGE_NAME=com.google.sample.oboe.liveeffect
44REMOTE_DIR=/data/data/${TEST_PACKAGE_NAME}
Don Turnerfda67012018-01-19 18:10:25 +000045
46# Check prerequisites
47if [ -z "$ANDROID_NDK" ]; then
48 echo "Please set ANDROID_NDK to the Android NDK folder"
49 exit 1
50fi
51
52if [ ! $(type -P ${CMAKE}) ]; then
53 echo "${CMAKE} was not found on your path. You can install it using Android Studio using Tools->Android->SDK Manager->SDK Tools."
54 exit 1
55fi
56
57# Get the device ABI
58ABI=$(adb shell getprop ro.product.cpu.abi | tr -d '\n\r')
59
60if [ -z "$ABI" ]; then
61 echo "No device ABI was set. Please ensure a device or emulator is running"
62 exit 1
63fi
64
65echo "Device/emulator architecture is $ABI"
66
67if [ ${ABI} == "arm64-v8a" ] || [ ${ABI} == "x86_64" ]; then
68 PLATFORM=android-21
69elif [ ${ABI} == "armeabi-v7a" ] || [ ${ABI} == "x86" ]; then
70 PLATFORM=android-16
71else
72 echo "Unrecognised ABI: ${ABI}. Supported ABIs are: arm64-v8a, armeabi-v7a, x86_64, x86. If you feel ${ABI} should be supported please file an issue on github.com/google/oboe"
73 exit 1
74fi
75
76# Configure the build
77echo "Building tests for ${ABI} using ${PLATFORM}"
78
79CMAKE_ARGS="-H. \
80 -B${BUILD_DIR} \
81 -DANDROID_ABI=${ABI} \
82 -DANDROID_PLATFORM=${PLATFORM} \
83 -DCMAKE_BUILD_TYPE=RelWithDebInfo \
84 -DCMAKE_CXX_FLAGS=-std=c++11 \
85 -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
86 -DCMAKE_VERBOSE_MAKEFILE=1"
87
88mkdir -p ${BUILD_DIR}
89
90cmake ${CMAKE_ARGS}
91
92# Perform the build
93pushd ${BUILD_DIR}
94 make -j5
95
96 if [ $? -eq 0 ]; then
97 echo "Tests built successfully"
98 else
99 echo "Building tests FAILED"
100 exit 1
101 fi
102
103popd
104
105
106# Push the test binary to the device and run it
Don Turnerfda67012018-01-19 18:10:25 +0000107adb shell mkdir -p ${REMOTE_DIR}
Don Turnerff649d02018-07-04 18:35:02 +0100108adb push ${BUILD_DIR}/${TEST_BINARY_FILENAME} ${REMOTE_TEMP_DIR}
109echo "Pushed ${BUILD_DIR}/${TEST_BINARY_FILENAME} to ${REMOTE_TEMP_DIR}"
110
111echo "Copying ${TEST_BINARY_FILENAME} from ${REMOTE_TEMP_DIR} to ${REMOTE_DIR}"
112adb shell run-as ${TEST_PACKAGE_NAME} cp ${REMOTE_TEMP_DIR}/${TEST_BINARY_FILENAME} ${REMOTE_DIR}
Don Turnerfda67012018-01-19 18:10:25 +0000113
114echo "Running test binary"
Don Turnerff649d02018-07-04 18:35:02 +0100115adb shell run-as ${TEST_PACKAGE_NAME} ${REMOTE_DIR}/${TEST_BINARY_FILENAME}