-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·124 lines (104 loc) · 3.1 KB
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
#########################################################
# #
# Run test suite and generate coverage reports #
# #
#########################################################
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[1;96m'
NC='\033[0m' # No color
echo
avd="PixelTest" # Default AVD
image="system-images;android-27;google_apis;x86"
headless=false
useEmulator=true
# Parse args
while getopts ":a:sph" opt; do
case $opt in
a)
avd="$OPTARG"
;;
s)
headless=true
echo -e "${BLUE}Running in headless mode. Remove -s to run non-headless.${NC}"
echo
;;
p)
useEmulator=false
echo -e "${BLUE}Attempting to use an attached phone. Remove -p to start an emulator.${NC}"
echo
;;
h)
echo "Usage: test.sh [-a=avd device name] [-s] [-h] [-p]"
echo " -s Run emulator headless."
echo " -p Use an attached phone. Don't start the emulator."
echo
exit 1
;;
esac
done
if $useEmulator; then
# Check that emulator was provided as an argument
result=`avdmanager list avd | grep "Name: $avd$"`
if [ -z "$result" ]; then
echo -e "${YELLOW}Creating test AVD...${NC}"
echo
echo no | avdmanager create avd -n "$avd" -k "$image" > /dev/null
# Check if create failed
if [ $? != 0 ]; then
echo
echo -e "${RED}Failed to create test AVD with package '$image'.${NC}"
echo
exit 1
fi
cp config.ini $HOME/.android/avd/$avd.avd/
echo -e "${YELLOW}Created AVD device: $avd${NC}"
echo
fi
# Check that device exists in avdmanager
result=`avdmanager list avd | grep "Name: $avd$"`
if [ -z "$result" ]; then
echo "$avd was not a valid device in avdmanager."
echo "Valid devices are: "
avdmanager list avd | grep "Name:" --color=never
echo
exit 1
fi
echo -e "${YELLOW}Using AVD device: $avd${NC}"
echo
echo -e "${YELLOW}=== Starting emulator in background... ===${NC}"
echo
# Start emulator
if $headless; then
emulator -avd "$avd" -no-audio -no-window -no-boot-anim &
else
emulator -avd "$avd" &
fi
# Wait for emulator
echo -e "${YELLOW}Waiting for emulator to boot...${NC}"
adb wait-for-device
while [ "`adb shell getprop sys.boot_completed | tr -d '\r' `" != "1" ];
do
sleep 2
done
echo -e "${YELLOW}BOOT SUCCESSFUL${NC}"
fi
echo
echo -e "${YELLOW}=== Starting build/test... ===${NC}"
echo
# Run test and generate coverage reports
adb uninstall splitsound.com.splitsound
error=0
./gradlew clean jacocoTestReport
error=$?
if $useEmulator; then
echo
echo -e "${YELLOW}Shutting down emulator...${NC}"
# Shut down emulator
adb -s emulator-5554 emu kill
adb kill-server
fi
echo
# Exit with error code from build
exit $error