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