aboutsummaryrefslogtreecommitdiff
path: root/run-tests-on-android.sh
blob: 02f278f5200a2713858827cd772c355ddb1ad76b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash

#
# Setup.
#

# Copy the toybox tests across.
if [[ $(adb shell getprop ro.debuggable) == 1 ]]; then
  adb shell su root rm -rf /data/local/tmp/toybox-tests/
fi
adb shell rm -rf /data/local/tmp/toybox-tests/
adb shell mkdir /data/local/tmp/toybox-tests/
adb push tests/ /data/local/tmp/toybox-tests/
adb push scripts/runtest.sh /data/local/tmp/toybox-tests/

# Make a temporary directory on the device.
tmp_dir=`adb shell mktemp --directory /data/local/tmp/toybox-tests-tmp.XXXXXXXXXX`

if tty -s; then
  green="\033[1;32m"
  red="\033[1;31m"
  plain="\033[0m"
else
  green=""
  red=""
  plain=""
fi

# Force pty allocation (http://b/142798587).
dash_t="-tt"

test_toy() {
  toy=$1

  echo

  location=$(adb shell "which $toy")
  if [ -z "$location" ]; then
    echo "-- $toy not present"
    return
  fi

  echo "-- $toy"

  implementation=$(adb shell "realpath $location")
  non_toy=false
  if [ "$implementation" != "/system/bin/toybox" ]; then
    echo "-- note: $toy is *not* toybox; this does not count as a test failure"
    non_toy=true
  fi

  adb shell $dash_t "\
      export C=\"\$(which $toy)\"; \
      export CMDNAME=$toy; \
      export TESTDIR=$tmp_dir; \
      export FILES=/data/local/tmp/toybox-tests/tests/files/ ; \
      export LANG=en_US.UTF-8; \
      export VERBOSE=1 ; \
      mkdir $tmp_dir/$toy && cd $tmp_dir/$toy ; \
      source /data/local/tmp/toybox-tests/runtest.sh ; \
      source /data/local/tmp/toybox-tests/tests/$toy.test ; \
      if [ "\$FAILCOUNT" -ne 0 ]; then exit 1; fi; \
      cd .. && rm -rf $toy"
  if [ $? -eq 0 ]; then
    pass_count=$(($pass_count+1))
  elif [ "$non_toy" = "true" ]; then
    non_toy_failures="$non_toy_failures $toy"
  else
    if [[ "$toy" = "vi" ]]; then
      non_toy_failures="$non_toy_failures $toy"
    else
      failures="$failures $toy"
    fi
  fi
}

#
# Run the selected test or all tests.
#

failures=""
pass_count=0
if [ "$#" -eq 0 ]; then
  # Run all the tests.
  for t in tests/*.test; do
    toy=`echo $t | sed 's|tests/||' | sed 's|\.test||'`
    test_toy $toy
  done
else
  # Just run the tests for the given toys.
  for toy in "$@"; do
    test_toy $toy
  done
fi

#
# Show a summary and return a meaningful exit status.
#

echo
echo "_________________________________________________________________________"
echo
echo -e "${green}PASSED${plain}: $pass_count"
for failure in $failures; do
  echo -e "${red}FAILED${plain}: $failure"
done
for failure in $non_toy_failures; do
  echo -e "${red}FAILED${plain}: $failure (ignoring)"
done

# We should have run *something*...
if [ $pass_count -eq 0 ]; then exit 1; fi
# And all failures are bad...
if [ -n "$failures" ]; then exit 1; fi
exit 0