• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 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=testRhythmGame
42REMOTE_DIR=/data/local/tmp/RhythmGame
43
44# Check prerequisites
45if [ -z "$ANDROID_NDK" ]; then
46    echo "Please set ANDROID_NDK to the Android NDK folder"
47    exit 1
48fi
49
50if [ ! $(type -P ${CMAKE}) ]; then
51	echo "${CMAKE} was not found on your path. You can install it using Android Studio using Tools->Android->SDK Manager->SDK Tools."
52	exit 1
53fi
54
55# Get the device ABI
56ABI=$(adb shell getprop ro.product.cpu.abi | tr -d '\n\r')
57
58if [ -z "$ABI" ]; then
59    echo "No device ABI was set. Please ensure a device or emulator is running"
60    exit 1
61fi
62
63echo "Device/emulator architecture is $ABI"
64
65if [ ${ABI} == "arm64-v8a" ] || [ ${ABI} == "x86_64" ]; then
66	PLATFORM=android-21
67elif [ ${ABI} == "armeabi-v7a" ] || [ ${ABI} == "x86" ]; then
68	PLATFORM=android-16
69else
70	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"
71	exit 1
72fi
73
74# Configure the build
75echo "Building tests for ${ABI} using ${PLATFORM}"
76
77CMAKE_ARGS="-H. \
78	-B${BUILD_DIR} \
79	-DANDROID_ABI=${ABI} \
80	-DANDROID_PLATFORM=${PLATFORM} \
81  	-DCMAKE_BUILD_TYPE=RelWithDebInfo \
82	-DCMAKE_CXX_FLAGS=-std=c++14 \
83	-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
84	-DCMAKE_VERBOSE_MAKEFILE=1"
85
86mkdir -p ${BUILD_DIR}
87
88cmake ${CMAKE_ARGS}
89
90# Perform the build
91pushd ${BUILD_DIR}
92    make -j5
93
94	if [ $? -eq 0 ]; then
95		echo "Tests built successfully"
96	else
97		echo "Building tests FAILED"
98		exit 1
99	fi
100
101popd
102
103
104# Push the test binary to the device and run it
105echo "Pushing test binary to device/emulator"
106adb shell mkdir -p ${REMOTE_DIR}
107adb push ${BUILD_DIR}/${TEST_BINARY_FILENAME} ${REMOTE_DIR}
108
109echo "Running test binary"
110adb shell ${REMOTE_DIR}/${TEST_BINARY_FILENAME}