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 | 5e3d99d | 2019-07-02 10:22:32 -0700 | [diff] [blame] | 16 | if [ tty -s ]; then |
| 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 | |
| 26 | test_toy() { |
| 27 | toy=$1 |
| 28 | |
| 29 | echo |
| 30 | |
| 31 | location=$(adb shell "which $toy") |
| 32 | if [ $? -ne 0 ]; then |
| 33 | echo "-- $toy not present" |
| 34 | return |
| 35 | fi |
| 36 | |
| 37 | echo "-- $toy" |
| 38 | |
| 39 | implementation=$(adb shell "realpath $location") |
| 40 | if [ "$implementation" != "/system/bin/toybox" ]; then |
| 41 | echo "-- note: $toy is non-toybox implementation" |
| 42 | fi |
| 43 | |
| 44 | adb shell -t "export FILES=/data/local/tmp/toybox-tests/tests/files/ ; \ |
| 45 | export VERBOSE=1 ; \ |
| 46 | export CMDNAME=$toy; \ |
Elliott Hughes | 0da31fe | 2019-06-27 08:35:15 -0700 | [diff] [blame] | 47 | export C=\"\$(which $toy)\"; \ |
Elliott Hughes | d3633b1 | 2017-08-03 14:52:32 -0700 | [diff] [blame] | 48 | export LANG=en_US.UTF-8; \ |
Elliott Hughes | 616210e | 2019-06-22 09:37:57 -0700 | [diff] [blame] | 49 | mkdir $tmp_dir/$toy && cd $tmp_dir/$toy ; \ |
Elliott Hughes | d3633b1 | 2017-08-03 14:52:32 -0700 | [diff] [blame] | 50 | source /data/local/tmp/toybox-tests/runtest.sh ; \ |
Elliott Hughes | 616210e | 2019-06-22 09:37:57 -0700 | [diff] [blame] | 51 | source /data/local/tmp/toybox-tests/tests/$toy.test ; \ |
| 52 | if [ "\$FAILCOUNT" -ne 0 ]; then exit 1; fi; \ |
| 53 | cd .. && rm -rf $toy" |
| 54 | if [ $? -eq 0 ]; then |
| 55 | pass_count=$(($pass_count+1)) |
| 56 | else |
| 57 | failures="$failures $toy" |
| 58 | fi |
Elliott Hughes | d3633b1 | 2017-08-03 14:52:32 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Elliott Hughes | 616210e | 2019-06-22 09:37:57 -0700 | [diff] [blame] | 61 | # |
| 62 | # Run the selected test or all tests. |
| 63 | # |
| 64 | |
| 65 | failures="" |
| 66 | pass_count=0 |
Elliott Hughes | d3633b1 | 2017-08-03 14:52:32 -0700 | [diff] [blame] | 67 | if [ "$#" -eq 0 ]; then |
| 68 | # Run all the tests. |
| 69 | for t in tests/*.test; do |
| 70 | toy=`echo $t | sed 's|tests/||' | sed 's|\.test||'` |
| 71 | test_toy $toy |
| 72 | done |
| 73 | else |
| 74 | # Just run the tests for the given toys. |
| 75 | for toy in "$@"; do |
| 76 | test_toy $toy |
| 77 | done |
| 78 | fi |
Elliott Hughes | 616210e | 2019-06-22 09:37:57 -0700 | [diff] [blame] | 79 | |
| 80 | # |
| 81 | # Show a summary and return a meaningful exit status. |
| 82 | # |
| 83 | |
| 84 | echo |
| 85 | echo "_________________________________________________________________________" |
| 86 | echo |
| 87 | echo -e "${green}PASSED${plain}: $pass_count" |
| 88 | for failure in $failures; do |
| 89 | echo -e "${red}FAILED${plain}: $failure" |
| 90 | done |
| 91 | |
| 92 | # We should have run *something*... |
| 93 | if [ $pass_count -eq 0 ]; then exit 1; fi |
| 94 | # And all failures are bad... |
| 95 | if [ -n "$failures" ]; then exit 1; fi |
| 96 | exit 0 |