blob: 65fa6f9baacdf44934bb935a233359c5d4451fed [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 Hughes5e3d99d2019-07-02 10:22:32 -070016if [ tty -s ]; then
17 green="\033[1;32m"
18 red="\033[1;31m"
19 plain="\033[0m"
Elliott Hughes21e94152019-07-02 15:57:47 -070020 dash_t="-t"
Elliott Hughes5e3d99d2019-07-02 10:22:32 -070021else
22 green=""
23 red=""
24 plain=""
Elliott Hughes21e94152019-07-02 15:57:47 -070025 dash_t=""
Elliott Hughes5e3d99d2019-07-02 10:22:32 -070026fi
Elliott Hughesd3633b12017-08-03 14:52:32 -070027
28test_toy() {
29 toy=$1
30
31 echo
32
33 location=$(adb shell "which $toy")
Elliott Hughes21e94152019-07-02 15:57:47 -070034 if [ -z "$location" ]; then
Elliott Hughesd3633b12017-08-03 14:52:32 -070035 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 Hughes21e94152019-07-02 15:57:47 -070046 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 Hughes616210e2019-06-22 09:37:57 -070057 if [ $? -eq 0 ]; then
58 pass_count=$(($pass_count+1))
59 else
60 failures="$failures $toy"
61 fi
Elliott Hughesd3633b12017-08-03 14:52:32 -070062}
63
Elliott Hughes616210e2019-06-22 09:37:57 -070064#
65# Run the selected test or all tests.
66#
67
68failures=""
69pass_count=0
Elliott Hughesd3633b12017-08-03 14:52:32 -070070if [ "$#" -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
76else
77 # Just run the tests for the given toys.
78 for toy in "$@"; do
79 test_toy $toy
80 done
81fi
Elliott Hughes616210e2019-06-22 09:37:57 -070082
83#
84# Show a summary and return a meaningful exit status.
85#
86
87echo
88echo "_________________________________________________________________________"
89echo
90echo -e "${green}PASSED${plain}: $pass_count"
91for failure in $failures; do
92 echo -e "${red}FAILED${plain}: $failure"
93done
94
95# We should have run *something*...
96if [ $pass_count -eq 0 ]; then exit 1; fi
97# And all failures are bad...
98if [ -n "$failures" ]; then exit 1; fi
99exit 0