Debian Codegraph @

android/remote-test-driver

raw
1 #! /bin/sh
2 # test-driver - basic testsuite driver script.
3
4 # Based on automake's 'test-driver' with some ugly tricks to make it run on Android
5 # Search for 'adb' below -- Beuc
6 scriptversion=2017-03-29.19; # UTC
7
8 # Copyright (C) 2011-2014 Free Software Foundation, Inc.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2, or (at your option)
13 # any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22
23 # As a special exception to the GNU General Public License, if you
24 # distribute this file as part of a program that contains a
25 # configuration script generated by Autoconf, you may include it under
26 # the same distribution terms that you use for the rest of that program.
27
28 # This file is maintained in Automake, please report
29 # bugs to <[email protected]> or send patches to
30 # <[email protected]>.
31
32 # Make unconditional expansion of undefined variables an error. This
33 # helps a lot in preventing typo-related bugs.
34 set -u
35
36 usage_error ()
37 {
38 echo "$0: $*" >&2
39 print_usage >&2
40 exit 2
41 }
42
43 print_usage ()
44 {
45 cat <<END
46 Usage:
47 test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
48 [--expect-failure={yes|no}] [--color-tests={yes|no}]
49 [--enable-hard-errors={yes|no}] [--]
50 TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
51 The '--test-name', '--log-file' and '--trs-file' options are mandatory.
52 END
53 }
54
55 test_name= # Used for reporting.
56 log_file= # Where to save the output of the test script.
57 trs_file= # Where to save the metadata of the test run.
58 expect_failure=no
59 color_tests=no
60 enable_hard_errors=yes
61 while test $# -gt 0; do
62 case $1 in
63 --help) print_usage; exit $?;;
64 --version) echo "test-driver $scriptversion"; exit $?;;
65 --test-name) test_name=$2; shift;;
66 --log-file) log_file=$2; shift;;
67 --trs-file) trs_file=$2; shift;;
68 --color-tests) color_tests=$2; shift;;
69 --expect-failure) expect_failure=$2; shift;;
70 --enable-hard-errors) enable_hard_errors=$2; shift;;
71 --) shift; break;;
72 -*) usage_error "invalid option: '$1'";;
73 *) break;;
74 esac
75 shift
76 done
77
78 missing_opts=
79 test x"$test_name" = x && missing_opts="$missing_opts --test-name"
80 test x"$log_file" = x && missing_opts="$missing_opts --log-file"
81 test x"$trs_file" = x && missing_opts="$missing_opts --trs-file"
82 if test x"$missing_opts" != x; then
83 usage_error "the following mandatory options are missing:$missing_opts"
84 fi
85
86 if test $# -eq 0; then
87 usage_error "missing argument"
88 fi
89
90 if test $color_tests = yes; then
91 # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
92 red='' # Red.
93 grn='' # Green.
94 lgn='' # Light green.
95 blu='' # Blue.
96 mgn='' # Magenta.
97 std='' # No color.
98 else
99 red= grn= lgn= blu= mgn= std=
100 fi
101
102 do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
103 trap "st=129; $do_exit" 1
104 trap "st=130; $do_exit" 2
105 trap "st=141; $do_exit" 13
106 trap "st=143; $do_exit" 15
107
108 # Test script is run here.
109 if file $test_name | grep -q 'shared object'; then
110 estatus=77
111 else
112 out=$(adb push $test_name /data/data/org.freedink/lib/ 2>&1)
113 if [ $? -ne 0 ]; then echo $out; exit 1; fi
114 adb shell "cd /data/data/org.freedink/lib && LD_LIBRARY_PATH=. $@" >$log_file 2>&1
115 grep -q 'OK! ' $log_file
116 estatus=$?
117 fi
118
119 if test $enable_hard_errors = no && test $estatus -eq 99; then
120 tweaked_estatus=1
121 else
122 tweaked_estatus=$estatus
123 fi
124
125 case $tweaked_estatus:$expect_failure in
126 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
127 0:*) col=$grn res=PASS recheck=no gcopy=no;;
128 77:*) col=$blu res=SKIP recheck=no gcopy=yes;;
129 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;;
130 *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;;
131 *:*) col=$red res=FAIL recheck=yes gcopy=yes;;
132 esac
133
134 # Report the test outcome and exit status in the logs, so that one can
135 # know whether the test passed or failed simply by looking at the '.log'
136 # file, without the need of also peaking into the corresponding '.trs'
137 # file (automake bug#11814).
138 echo "$res $test_name (exit status: $estatus)" >>$log_file
139
140 # Report outcome to console.
141 echo "${col}${res}${std}: $test_name"
142
143 # Register the test result, and other relevant metadata.
144 echo ":test-result: $res" > $trs_file
145 echo ":global-test-result: $res" >> $trs_file
146 echo ":recheck: $recheck" >> $trs_file
147 echo ":copy-in-global-log: $gcopy" >> $trs_file
148
149 # Local Variables:
150 # mode: shell-script
151 # sh-indentation: 2
152 # eval: (add-hook 'write-file-hooks 'time-stamp)
153 # time-stamp-start: "scriptversion="
154 # time-stamp-format: "%:y-%02m-%02d.%02H"
155 # time-stamp-time-zone: "UTC"
156 # time-stamp-end: "; # UTC"
157 # End: