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