1#!/bin/bash
2
3# Copy the toybox tests across.
4adb shell mkdir /data/local/tmp/toybox-tests/
5adb push tests/ /data/local/tmp/toybox-tests/
6adb push scripts/runtest.sh /data/local/tmp/toybox-tests/
7
8# Make a temporary directory on the device.
9tmp_dir=`adb shell TMPDIR=/data/local/tmp mktemp --directory`
10
11test_toy() {
12  toy=$1
13
14  echo
15
16  location=$(adb shell "which $toy")
17  if [ $? -ne 0 ]; then
18    echo "-- $toy not present"
19    return
20  fi
21
22  echo "-- $toy"
23
24  implementation=$(adb shell "realpath $location")
25  if [ "$implementation" != "/system/bin/toybox" ]; then
26    echo "-- note: $toy is non-toybox implementation"
27  fi
28
29  adb shell -t "export FILES=/data/local/tmp/toybox-tests/tests/files/ ; \
30                export VERBOSE=1 ; \
31                export CMDNAME=$toy; \
32                export C=$toy; \
33                export LANG=en_US.UTF-8; \
34                cd $tmp_dir ; \
35                source /data/local/tmp/toybox-tests/runtest.sh ; \
36                source /data/local/tmp/toybox-tests/tests/$toy.test"
37}
38
39if [ "$#" -eq 0 ]; then
40  # Run all the tests.
41  for t in tests/*.test; do
42    toy=`echo $t | sed 's|tests/||' | sed 's|\.test||'`
43    test_toy $toy
44  done
45else
46  # Just run the tests for the given toys.
47  for toy in "$@"; do
48    test_toy $toy
49  done
50fi
51