blob: d85cca31e959caadfb7906a0a53ee653d6211bb1 [file] [log] [blame]
Elliott Hughesd3633b12017-08-03 14:52:32 -07001#!/bin/bash
2
Elliott Hughes616210e2019-06-22 09:37:57 -07003#
4# Setup.
5#
6
Elliott Hughesd3633b12017-08-03 14:52:32 -07007# Copy the toybox tests across.
Elliott Hughes616210e2019-06-22 09:37:57 -07008adb shell rm -rf /data/local/tmp/toybox-tests/
Elliott Hughesd3633b12017-08-03 14:52:32 -07009adb shell mkdir /data/local/tmp/toybox-tests/
10adb push tests/ /data/local/tmp/toybox-tests/
11adb push scripts/runtest.sh /data/local/tmp/toybox-tests/
12
13# Make a temporary directory on the device.
Elliott Hughes616210e2019-06-22 09:37:57 -070014tmp_dir=`adb shell mktemp --directory /data/local/tmp/toybox-tests-tmp.XXXXXXXXXX`
15
Elliott Hughes6f8fa1e2019-07-08 14:30:07 -070016if tty -s; then
Elliott Hughes5e3d99d2019-07-02 10:22:32 -070017 green="\033[1;32m"
18 red="\033[1;31m"
19 plain="\033[0m"
20else
21 green=""
22 red=""
23 plain=""
24fi
Elliott Hughesd3633b12017-08-03 14:52:32 -070025
Elliott Hughes59e3d622019-12-13 16:36:38 -080026# Force pty allocation (http://b/142798587).
27dash_t="-tt"
28
Elliott Hughesd3633b12017-08-03 14:52:32 -070029test_toy() {
30 toy=$1
31
32 echo
33
34 location=$(adb shell "which $toy")
Elliott Hughes21e94152019-07-02 15:57:47 -070035 if [ -z "$location" ]; then
Elliott Hughesd3633b12017-08-03 14:52:32 -070036 echo "-- $toy not present"
37 return
38 fi
39
40 echo "-- $toy"
41
42 implementation=$(adb shell "realpath $location")
Elliott Hughes71a0a172019-07-31 15:53:01 -070043 non_toy=false
Elliott Hughesd3633b12017-08-03 14:52:32 -070044 if [ "$implementation" != "/system/bin/toybox" ]; then
45 echo "-- note: $toy is non-toybox implementation"
Elliott Hughes71a0a172019-07-31 15:53:01 -070046 non_toy=true
Elliott Hughesd3633b12017-08-03 14:52:32 -070047 fi
48
Elliott Hughes21e94152019-07-02 15:57:47 -070049 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 Hughes616210e2019-06-22 09:37:57 -070060 if [ $? -eq 0 ]; then
61 pass_count=$(($pass_count+1))
Elliott Hughes71a0a172019-07-31 15:53:01 -070062 elif [ "$non_toy" = "true" ]; then
63 non_toy_failures="$non_toy_failures $toy"
Elliott Hughes616210e2019-06-22 09:37:57 -070064 else
Elliott Hughesad173402020-02-28 17:50:02 -080065 failures="$failures $toy"
Elliott Hughes616210e2019-06-22 09:37:57 -070066 fi
Elliott Hughesd3633b12017-08-03 14:52:32 -070067}
68
Elliott Hughes616210e2019-06-22 09:37:57 -070069#
70# Run the selected test or all tests.
71#
72
73failures=""
74pass_count=0
Elliott Hughesd3633b12017-08-03 14:52:32 -070075if [ "$#" -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
81else
82 # Just run the tests for the given toys.
83 for toy in "$@"; do
84 test_toy $toy
85 done
86fi
Elliott Hughes616210e2019-06-22 09:37:57 -070087
88#
89# Show a summary and return a meaningful exit status.
90#
91
92echo
93echo "_________________________________________________________________________"
94echo
95echo -e "${green}PASSED${plain}: $pass_count"
96for failure in $failures; do
97 echo -e "${red}FAILED${plain}: $failure"
98done
Elliott Hughes71a0a172019-07-31 15:53:01 -070099for failure in $non_toy_failures; do
100 echo -e "${red}FAILED${plain}: $failure (ignoring)"
101done
Elliott Hughes616210e2019-06-22 09:37:57 -0700102
103# We should have run *something*...
104if [ $pass_count -eq 0 ]; then exit 1; fi
105# And all failures are bad...
106if [ -n "$failures" ]; then exit 1; fi
107exit 0