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