1#!/bin/bash 2 3# 4# Setup. 5# 6 7# Copy the toybox tests across. 8if [[ $(adb shell getprop ro.debuggable) == 1 ]]; then 9 adb shell su root rm -rf /data/local/tmp/toybox-tests/ 10fi 11adb shell rm -rf /data/local/tmp/toybox-tests/ 12adb shell mkdir /data/local/tmp/toybox-tests/ 13adb push tests/ /data/local/tmp/toybox-tests/ 14adb push scripts/runtest.sh /data/local/tmp/toybox-tests/ 15 16# Make a temporary directory on the device. 17tmp_dir=`adb shell mktemp --directory /data/local/tmp/toybox-tests-tmp.XXXXXXXXXX` 18 19if tty -s; then 20 green="\033[1;32m" 21 red="\033[1;31m" 22 plain="\033[0m" 23else 24 green="" 25 red="" 26 plain="" 27fi 28 29# Force pty allocation (http://b/142798587). 30dash_t="-tt" 31 32test_toy() { 33 toy=$1 34 35 echo 36 37 location=$(adb shell "which $toy") 38 if [ -z "$location" ]; then 39 echo "-- $toy not present" 40 return 41 fi 42 43 echo "-- $toy" 44 45 implementation=$(adb shell "realpath $location") 46 non_toy=false 47 if [ "$implementation" != "/system/bin/toybox" ]; then 48 echo "-- note: $toy is *not* toybox; this does not count as a test failure" 49 non_toy=true 50 fi 51 52 adb shell $dash_t "\ 53 export C=\"\$(which $toy)\"; \ 54 export CMDNAME=$toy; \ 55 export TESTDIR=$tmp_dir; \ 56 export FILES=/data/local/tmp/toybox-tests/tests/files/ ; \ 57 export LANG=en_US.UTF-8; \ 58 export VERBOSE=1 ; \ 59 mkdir $tmp_dir/$toy && cd $tmp_dir/$toy ; \ 60 source /data/local/tmp/toybox-tests/runtest.sh ; \ 61 source /data/local/tmp/toybox-tests/tests/$toy.test ; \ 62 if [ "\$FAILCOUNT" -ne 0 ]; then exit 1; fi; \ 63 cd .. && rm -rf $toy" 64 if [ $? -eq 0 ]; then 65 pass_count=$(($pass_count+1)) 66 elif [ "$non_toy" = "true" ]; then 67 non_toy_failures="$non_toy_failures $toy" 68 else 69 if [[ "$toy" = "vi" ]]; then 70 non_toy_failures="$non_toy_failures $toy" 71 else 72 failures="$failures $toy" 73 fi 74 fi 75} 76 77# 78# Run the selected test or all tests. 79# 80 81failures="" 82pass_count=0 83if [ "$#" -eq 0 ]; then 84 # Run all the tests. 85 for t in tests/*.test; do 86 toy=`echo $t | sed 's|tests/||' | sed 's|\.test||'` 87 test_toy $toy 88 done 89else 90 # Just run the tests for the given toys. 91 for toy in "$@"; do 92 test_toy $toy 93 done 94fi 95 96# 97# Show a summary and return a meaningful exit status. 98# 99 100echo 101echo "_________________________________________________________________________" 102echo 103echo -e "${green}PASSED${plain}: $pass_count" 104for failure in $failures; do 105 echo -e "${red}FAILED${plain}: $failure" 106done 107for failure in $non_toy_failures; do 108 echo -e "${red}FAILED${plain}: $failure (ignoring)" 109done 110 111# We should have run *something*... 112if [ $pass_count -eq 0 ]; then exit 1; fi 113# And all failures are bad... 114if [ -n "$failures" ]; then exit 1; fi 115exit 0 116