blob: 50654f045b731030056de03f5262f8709f6fb8d8 [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"
20else
21 green=""
22 red=""
23 plain=""
24fi
Elliott Hughesd3633b12017-08-03 14:52:32 -070025
26test_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 Hughes0da31fe2019-06-27 08:35:15 -070047 export C=\"\$(which $toy)\"; \
Elliott Hughesd3633b12017-08-03 14:52:32 -070048 export LANG=en_US.UTF-8; \
Elliott Hughes616210e2019-06-22 09:37:57 -070049 mkdir $tmp_dir/$toy && cd $tmp_dir/$toy ; \
Elliott Hughesd3633b12017-08-03 14:52:32 -070050 source /data/local/tmp/toybox-tests/runtest.sh ; \
Elliott Hughes616210e2019-06-22 09:37:57 -070051 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 Hughesd3633b12017-08-03 14:52:32 -070059}
60
Elliott Hughes616210e2019-06-22 09:37:57 -070061#
62# Run the selected test or all tests.
63#
64
65failures=""
66pass_count=0
Elliott Hughesd3633b12017-08-03 14:52:32 -070067if [ "$#" -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
73else
74 # Just run the tests for the given toys.
75 for toy in "$@"; do
76 test_toy $toy
77 done
78fi
Elliott Hughes616210e2019-06-22 09:37:57 -070079
80#
81# Show a summary and return a meaningful exit status.
82#
83
84echo
85echo "_________________________________________________________________________"
86echo
87echo -e "${green}PASSED${plain}: $pass_count"
88for failure in $failures; do
89 echo -e "${red}FAILED${plain}: $failure"
90done
91
92# We should have run *something*...
93if [ $pass_count -eq 0 ]; then exit 1; fi
94# And all failures are bad...
95if [ -n "$failures" ]; then exit 1; fi
96exit 0