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