3 # Copyright (C) 2010 The Android Open Source Project
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # This shell script is used to run one test on a device emulator.
31 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
37 if [ "$VERBOSE" = "yes" ] ; then
47 echo "ERROR: Unknown option '$opt', use --help for list of valid ones."
50 *) # Simply record parameter
51 if [ -z "$PARAMETERS" ] ; then
54 PARAMETERS="$PARAMETERS $opt"
61 if [ "$OPTION_HELP" = "yes" ] ; then
62 echo "Usage: $PROGNAME [options] <test-name>"
64 echo "Run one C library test on a device/emulator through ADB."
68 echo " --help|-h|-? Print this help"
69 echo " --verbose Enable verbose mode"
70 echo " --adb=<file> Specify adb executable for device tests"
75 if [ -z "$ANDROID_PRODUCT_OUT" ] ; then
76 echo "ERROR: ANDROID_PRODUCT_OUT not defined. Please run the 'lunch' command"
80 if [ ! -f "$ANDROID_PRODUCT_OUT/system.img" ] ; then
81 echo "ERROR: Missing file: $ANDROID_PRODUCT_OUT/system.img"
82 echo "Are you sure you built the proper system image?"
86 EXEC_ROOT_PATH="$ANDROID_PRODUCT_OUT/obj/EXECUTABLES"
87 if [ ! -d "$EXEC_ROOT_PATH" ] ; then
88 echo "ERROR: Missing directory: $EXEC_ROOT_PATH"
89 echo "Are you sure you built the proper system image?"
93 if [ -z "$PARAMETERS" ] ; then
94 echo "ERROR: Please specify test name."
95 echo "Must be one of the following:"
96 for FILE in `cd $EXEC_ROOT_PATH && ls -d test_*`; do
97 TEST=`echo "$FILE" | sed -e "s!test_\(.*\)_intermediates!\\1!g"`
104 # Normalize test name, i.e. remove test_ prefix
105 TEST=`echo "$TEST" | sed -e "s!^test_!!g"`
107 TESTDIR="$EXEC_ROOT_PATH/test_${TEST}_intermediates"
108 if [ ! -d "$TESTDIR" ] ; then
109 echo "ERROR: No test by that name: test_$TEST!"
113 TESTNAME="test_$TEST"
114 TESTEXE="$TESTDIR/$TESTNAME"
115 if [ ! -f "$TESTEXE" ] ; then
116 echo "ERROR: Missing file: $TESTEXE"
117 echo "Are you sure your last test build was complete?"
121 # Run a command in ADB and return 0 in case of success, or 1 otherwise.
122 # This is needed because "adb shell" does not return the proper status
123 # of the launched command.
125 # NOTE: You must call set_adb_cmd_log before that to set the location
126 # of the temporary log file that will be used.
131 if [ -z "$ADB_CMD_LOG" ] ; then
132 dump "INTERNAL ERROR: ADB_CMD_LOG not set!"
135 if [ $VERBOSE = "yes" ] ; then
136 echo "$ADB_CMD shell $@"
137 $ADB_CMD shell $@ "&&" echo OK "||" echo KO | tee $ADB_CMD_LOG
139 $ADB_CMD shell $@ "&&" echo OK "||" echo KO > $ADB_CMD_LOG
141 # Get last line in log, should be OK or KO
142 RET=`tail -n1 $ADB_CMD_LOG`
143 # Get rid of \r at the end of lines
144 RET=`echo "$RET" | sed -e 's![[:cntrl:]]!!g'`
153 # Returns 0 if a variable containing one or more items separated
154 # by spaces contains a given value.
155 # $1: variable name (e.g. FOO)
159 echo `var_value $1` | tr ' ' '\n' | fgrep -q -e "$2"
162 TMPDIR=/tmp/bionic-tests
164 set_adb_cmd_log $TMPDIR/adb.log.txt
166 DEVICE_TEST_DIR=/data/local/bionic-test
167 DEVICE_TEST=$DEVICE_TEST_DIR/$TESTNAME
168 adb_cmd mkdir $DEVICE_TEST_DIR
169 $ADB_CMD push $TESTEXE $DEVICE_TEST_DIR/
170 if [ $? != 0 ] ; then
171 echo "ERROR: Can't push test to device!"
175 adb_cmd chmod 0755 $DEVICE_TEST &&
178 adb_cmd rm -r $DEVICE_TEST_DIR
180 if [ "$RET" != 0 ] ; then