blob: 89c8c91627f8b1bf8006c7d97d80583d6ebf85e6 [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.
Yi-Yo Chiang971eaf62021-02-02 16:53:32 +08008if [[ $(adb shell getprop ro.debuggable) == 1 ]]; then
9 adb shell su root rm -rf /data/local/tmp/toybox-tests/
10fi
Elliott Hughes616210e2019-06-22 09:37:57 -070011adb shell rm -rf /data/local/tmp/toybox-tests/
Elliott Hughesd3633b12017-08-03 14:52:32 -070012adb shell mkdir /data/local/tmp/toybox-tests/
13adb push tests/ /data/local/tmp/toybox-tests/
14adb push scripts/runtest.sh /data/local/tmp/toybox-tests/
15
16# Make a temporary directory on the device.
Elliott Hughes616210e2019-06-22 09:37:57 -070017tmp_dir=`adb shell mktemp --directory /data/local/tmp/toybox-tests-tmp.XXXXXXXXXX`
18
Elliott Hughes6f8fa1e2019-07-08 14:30:07 -070019if tty -s; then
Elliott Hughes5e3d99d2019-07-02 10:22:32 -070020 green="\033[1;32m"
21 red="\033[1;31m"
22 plain="\033[0m"
23else
24 green=""
25 red=""
26 plain=""
27fi
Elliott Hughesd3633b12017-08-03 14:52:32 -070028
Elliott Hughes59e3d622019-12-13 16:36:38 -080029# Force pty allocation (http://b/142798587).
30dash_t="-tt"
31
Elliott Hughesd3633b12017-08-03 14:52:32 -070032test_toy() {
33 toy=$1
34
35 echo
36
37 location=$(adb shell "which $toy")
Elliott Hughes21e94152019-07-02 15:57:47 -070038 if [ -z "$location" ]; then
Elliott Hughesd3633b12017-08-03 14:52:32 -070039 echo "-- $toy not present"
40 return
41 fi
42
43 echo "-- $toy"
44
45 implementation=$(adb shell "realpath $location")
Elliott Hughes71a0a172019-07-31 15:53:01 -070046 non_toy=false
Elliott Hughesd3633b12017-08-03 14:52:32 -070047 if [ "$implementation" != "/system/bin/toybox" ]; then
48 echo "-- note: $toy is non-toybox implementation"
Elliott Hughes71a0a172019-07-31 15:53:01 -070049 non_toy=true
Elliott Hughesd3633b12017-08-03 14:52:32 -070050 fi
51
Elliott Hughes21e94152019-07-02 15:57:47 -070052 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 Hughes616210e2019-06-22 09:37:57 -070063 if [ $? -eq 0 ]; then
64 pass_count=$(($pass_count+1))
Elliott Hughes71a0a172019-07-31 15:53:01 -070065 elif [ "$non_toy" = "true" ]; then
66 non_toy_failures="$non_toy_failures $toy"
Elliott Hughes616210e2019-06-22 09:37:57 -070067 else
Elliott Hughesad173402020-02-28 17:50:02 -080068 failures="$failures $toy"
Elliott Hughes616210e2019-06-22 09:37:57 -070069 fi
Elliott Hughesd3633b12017-08-03 14:52:32 -070070}
71
Elliott Hughes616210e2019-06-22 09:37:57 -070072#
73# Run the selected test or all tests.
74#
75
76failures=""
77pass_count=0
Elliott Hughesd3633b12017-08-03 14:52:32 -070078if [ "$#" -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
84else
85 # Just run the tests for the given toys.
86 for toy in "$@"; do
87 test_toy $toy
88 done
89fi
Elliott Hughes616210e2019-06-22 09:37:57 -070090
91#
92# Show a summary and return a meaningful exit status.
93#
94
95echo
96echo "_________________________________________________________________________"
97echo
98echo -e "${green}PASSED${plain}: $pass_count"
99for failure in $failures; do
100 echo -e "${red}FAILED${plain}: $failure"
101done
Elliott Hughes71a0a172019-07-31 15:53:01 -0700102for failure in $non_toy_failures; do
103 echo -e "${red}FAILED${plain}: $failure (ignoring)"
104done
Elliott Hughes616210e2019-06-22 09:37:57 -0700105
106# We should have run *something*...
107if [ $pass_count -eq 0 ]; then exit 1; fi
108# And all failures are bad...
109if [ -n "$failures" ]; then exit 1; fi
110exit 0