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 non-toybox implementation" 49 non_toy=true 50 fi 51 52 adb shell $dash_t "\ 53 export C=\"\$(which $toy)\"; \ 54 export CMDNAME=$toy; \ 55 export FILES=/data/local/tmp/toybox-tests/tests/files/ ; \ 56 export LANG=en_US.UTF-8; \ 57 export VERBOSE=1 ; \ 58 mkdir $tmp_dir/$toy && cd $tmp_dir/$toy ; \ 59 source /data/local/tmp/toybox-tests/runtest.sh ; \ 60 source /data/local/tmp/toybox-tests/tests/$toy.test ; \ 61 if [ "\$FAILCOUNT" -ne 0 ]; then exit 1; fi; \ 62 cd .. && rm -rf $toy" 63 if [ $? -eq 0 ]; then 64 pass_count=$(($pass_count+1)) 65 elif [ "$non_toy" = "true" ]; then 66 non_toy_failures="$non_toy_failures $toy" 67 else 68 if [[ "$toy" = "vi" ]]; then 69 non_toy_failures="$non_toy_failures $toy" 70 else 71 failures="$failures $toy" 72 fi 73 fi 74} 75 76# 77# Run the selected test or all tests. 78# 79 80failures="" 81pass_count=0 82if [ "$#" -eq 0 ]; then 83 # Run all the tests. 84 for t in tests/*.test; do 85 toy=`echo $t | sed 's|tests/||' | sed 's|\.test||'` 86 test_toy $toy 87 done 88else 89 # Just run the tests for the given toys. 90 for toy in "$@"; do 91 test_toy $toy 92 done 93fi 94 95# 96# Show a summary and return a meaningful exit status. 97# 98 99echo 100echo "_________________________________________________________________________" 101echo 102echo -e "${green}PASSED${plain}: $pass_count" 103for failure in $failures; do 104 echo -e "${red}FAILED${plain}: $failure" 105done 106for failure in $non_toy_failures; do 107 echo -e "${red}FAILED${plain}: $failure (ignoring)" 108done 109 110# We should have run *something*... 111if [ $pass_count -eq 0 ]; then exit 1; fi 112# And all failures are bad... 113if [ -n "$failures" ]; then exit 1; fi 114exit 0 115