forked from mozilla-b2g/gaia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gaia-test
executable file
·216 lines (185 loc) · 4.94 KB
/
gaia-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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
SELF=`basename $0`
SELF_DIR=`dirname $0`
#
# Run the gaia unit test agent server and with firefox.
#
# Basic usage:
#
# gaia-test <gaia location> <firefox binary>
#
# The both parameters are optional.
#
# The gaia directory to test is found using the following heuristic:
# 1) If the gaia location specified on the command line is a directory,
# then use it.
# 2) If the gaia location is not specified, use the $GAIADIR environment
# variable.
# 2) If the environment variable is not specified either, then use
# the scripts location to determine the gaia directory. This assumes
# the script is found in gaia/bin.
#
# The firefox binary is found using the following heuristic:
# 1) If the firefox binary is specified on the command line, then attempt
# to find it in the path if its relative or just use it if its absolute.
# 2) If the firefox binary is not specified, then use the $FIREFOX
# environment variable to find the executable in the path.
# 3) If the environment is not specified either, then look for 'firefox'
# in the path.
#
usage() {
echo "$SELF [ -d ] [ -f ] [ -h ] [ <gaia dir> [ <firefox/B2G binary> ] ]"
echo " -d: runs in B2G Desktop"
echo " -f: forces the profile generation -- will delete an existing profile directory"
echo " -h: displays this help"
echo
echo "Use the environment variable FIREFOX to point to a specific firefox binary."
echo "Use the environment variable B2G to point to a specific B2G Desktop binary."
echo "Use the environment variable GAIADIR to point to a specific Gaia directory."
echo -n "Use the environment variable PROFILE_FOLDER to change the profile directory."
echo " It should be a subdirectory of the Gaia directory."
exit 1
}
handle_options() {
mode="firefox"
force_profile=
while getopts dfh f; do
case $f in
d)
mode="b2g"
;;
f)
force_profile=1
;;
h|\?)
usage
;;
esac
done
}
configure_gaia_location() {
#
# Configure gaia location
#
if [ ! -z "$1" ] ; then
GAIADIR="$1"
fi
if [ -z "$GAIADIR" ] ; then
GAIADIR="$SELF_DIR/.."
fi
if [ ! -d "$GAIADIR" ] ; then
echo "$SELF: '$GAIADIR' is not a directory!"
exit 1
fi
GAIADIR=$( cd "$GAIADIR"; pwd)
echo "$SELF: Using gaia at '$GAIADIR'."
}
configure_firefox_location() {
#
# Configure firefox test binary
#
if [ ! -z "$1" ] ; then
FIREFOX="$1"
fi
if [ -z "$FIREFOX" ] ; then
FIREFOX='firefox'
fi
BASE_FIREFOX="$FIREFOX"
FIREFOX=`which $BASE_FIREFOX`
if [ ! -x "$FIREFOX" ] ; then
echo "$SELF: Unable to find an executable '$BASE_FIREFOX' in path!"
exit 1
fi
#
# Verify firefox version is new enough
#
VERSION=`$FIREFOX --version | awk '{print $3}'`
REQ_VERSION='22'
if expr "$VERSION" \< "$REQ_VERSION" >/dev/null ; then
echo "$SELF: Firefox is only version $VERSION; use $REQ_VERSION or newer."
exit 1
fi
echo "$SELF: Using Firefox $VERSION at '$FIREFOX'."
}
configure_b2g_location() {
#
# Configure b2g test binary
#
if [ ! -z "$1" ] ; then
B2G=`which $1`
if [ ! -x "$B2G" ] ; then
echo "$SELF: Unable to find an executable '$1' in path!"
exit 1
fi
fi
if [ -z "$B2G" ] ; then
make b2g
B2G="./b2g/b2g-bin"
if [ ! -x "$B2G" ] ; then
# set the path for Mac OS X
B2G="./b2g/Contents/MacOS/b2g-bin"
fi
fi
# if we still don't have it, fail
if [ ! -x "$B2G" ] ; then
echo "$SELF: Couldn't download a suitable executable for B2G Desktop"
exit 1
fi
echo "$SELF: Using B2G Desktop at '$B2G'."
}
configure_profile_folder() {
if [ -z "$PROFILE_FOLDER" ] ; then
PROFILE_FOLDER="profile-gaia-test-$mode"
fi
export PROFILE_FOLDER
echo "$SELF: Using profile at '$PROFILE_FOLDER'"
}
generate_profile_folder_if_needed() {
if [ -n "$force_profile" ] ; then
rm -rf "$PROFILE_FOLDER"
fi
if [ ! -d "$PROFILE_FOLDER" ] ; then
echo "$SELF: Building the debug profile."
NO_LOCK_SCREEN=1 DEBUG=1 DESKTOP=0 make
fi
}
launch_test_runner_in_firefox() {
#
# Launch firefox
#
$FIREFOX --no-remote -profile "$GAIADIR/$PROFILE_FOLDER" app://test-agent.gaiamobile.org/ &
}
launch_test_runner_in_b2g() {
$B2G -profile "$GAIADIR/$PROFILE_FOLDER" --runapp 'Test Agent' &
}
handle_options "$@" && shift `expr $OPTIND - 1`
configure_gaia_location "$1"
configure_${mode}_location "$2"
#
# Verify additional dependencies are installed
#
NODE=`which nodejs`
NPM=`which npm`
if [ ! -x "$NODE" ] ; then
NODE=`which node`
if [ ! -x "$NODE" ] ; then
echo "$SELF: Unable to find node; please install node.js."
exit 1
fi
elif [ ! -x "$NPM" ] ; then
echo "$SELF: Unable to find npm; please install npm."
exit 1
fi
cd $GAIADIR
configure_profile_folder
generate_profile_folder_if_needed
launch_test_runner_in_${mode}
cleanup() {
echo "$SELF: Stopping the test runner on exit."
kill "%1"
}
trap cleanup EXIT
#
# Launch the test agent
#
make test-agent-server