Update with current status
[gnash.git] / testsuite / misc-ming.all / hostcmd-geturl_testrunner.sh
blob1b268a5040b68581a065af285edbd6f75bf19d54
1 #!/bin/sh
4 # hostcmd-geturl_testrunner.sh - container-emulated getURL()/MovieClip.getURL()
5 # target test runner generator
7 # Copyright (C) 2017 Free Software Foundation, Inc.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 # Original author: Nutchanon Wetchasit <Nutchanon.Wetchasit@gmail.com>
26 # The generated test runner checks Gnash for:
27 # * Undefined and null target passing via getURL() and MovieClip.getURL()
28 # (bug #50393)
29 # <https://savannah.gnu.org/bugs/?50393>
31 # Usage:
32 # ./hostcmd-geturl_testrunner.sh <builddir> <srcdir> <swfversion> <swf>
34 # Generated test runner's exit codes:
35 # 0 if tester ran completely
36 # non-zero if tester encountered an error
38 # Note:
39 # The generated test file requires a filesystem that supports named pipes.
42 # Check for generation parameters
43 while getopts "" name
45 case $name in
47 echo "Usage: $0 <builddir> <srcdir> <swfversion> <swf>" >&2
48 exit 1;;
49 esac
50 done
51 shift $(($OPTIND - 1))
52 if [ "$#" -ne 4 ]
53 then
54 echo "Usage: $0 <builddir> <srcdir> <swfversion> <swf>" >&2
55 exit 1
58 # Load generation parameters
59 top_builddir=$1
60 shift
61 top_srcdir=$1
62 shift
63 swfversion=$1
64 shift
65 swf=$1
67 # Generate the test runner
68 echo "#!/bin/sh"
69 echo
71 echo "# Environment variables"
72 env | grep '^GNASH' | while read reply
74 echo "export \"${reply}\""
75 done
77 cat << EOF
79 # Filenames and constants
80 LOGFILE=${top_builddir}/testoutlog.\$\$
81 PIPE2CONTAINER=${top_builddir}/tocontainer.\$\$
82 PIPE2PLAYER=${top_builddir}/toplayer.\$\$
83 STARTTIMEOUT=10
84 READTIMEOUT=5
86 # Test counts
87 TESTED=0
88 FAILED=0
89 PASSED=0
91 # check_equals(\$op1, \$op2, \$msg)
92 # Equality checker and counter
93 check_equals() {
94 if [ "\$1" = "\$2" ]
95 then
96 echo "PASSED: \$3"
97 PASSED=\`expr "\$PASSED" + 1\`
98 else
99 echo "FAILED: \$3 (\"\$1\" != \"\$2\")"
100 FAILED=\`expr "\$FAILED" + 1\`
102 TESTED=\`expr "\$TESTED" + 1\`
105 # xcheck_equals(\$op1, \$op2, \$msg)
106 # Equality checker and counter (for expected failure)
107 xcheck_equals() {
108 if [ "\$1" = "\$2" ]
109 then
110 echo "XPASSED: \$3"
111 PASSED=\`expr "\$PASSED" + 1\`
112 else
113 echo "XFAILED: \$3 (\"\$1\" != \"\$2\")"
114 FAILED=\`expr "\$FAILED" + 1\`
116 TESTED=\`expr "\$TESTED" + 1\`
119 # check_totals(\$op, \$msg)
120 # Test count checker
121 check_totals() {
122 check_equals "\$TESTED" "\$1" "\$2"
125 # check_error(\$bool, \$msg)
126 # Assert \$bool is 0; if not, flag error in the test, and exit
127 check_error() {
128 if [ "\$1" -ne 0 ]
129 then
130 echo "ERROR: \$2" >&2
131 exit 1
135 # read_timeout(\$varname, \$timeout)
136 # Read one line from standard input, with a specified timeout (in seconds)
137 read_timeout() {
138 trap 'trap - USR1; return 142' USR1
139 (sleep "\$2" && kill -USR1 "\$\$" > /dev/null 2>&1) &
140 TIMEOUTPID=\$!
141 read "\$1"
142 READERROR=\$?
143 kill "\$TIMEOUTPID" > /dev/null 2>&1
144 trap - USR1
145 return \$READERROR
148 # Create required named pipes
149 if [ \! -p "\$PIPE2CONTAINER" ]
150 then
151 mkfifo "\$PIPE2CONTAINER"
152 check_error "\$?" "Failed to create a named pipe: \$PIPE2CONTAINER"
154 if [ \! -p "\$PIPE2PLAYER" ]
155 then
156 mkfifo "\$PIPE2PLAYER"
157 check_error "\$?" "Failed to create a named pipe: \$PIPE2PLAYER"
160 # Open player-to-host pipe
161 exec 3<> "\$PIPE2CONTAINER"
162 check_error \$? "Failed to open a named pipe: \$PIPE2CONTAINER"
164 # Open host-to-player pipe
165 exec 4<> "\$PIPE2PLAYER"
166 check_error \$? "Failed to open a named pipe: \$PIPE2PLAYER"
168 # Start player
169 "${top_builddir}/gui/gnash" -r 0 -vv -F 3:4 "${swf}" > "\$LOGFILE" 2>&1 &
170 GNASHPID=\$!
172 # Wait until the SWF code start running, by loop-checking logfile
173 STARTCOUNTDOWN=\$STARTTIMEOUT
174 while [ \$STARTCOUNTDOWN -gt 0 ]
176 if grep "TRACE: STARTOFTEST" "\$LOGFILE" 2>&1 > /dev/null
177 then
178 break
180 sleep 1
181 STARTCOUNTDOWN=\`expr \$STARTCOUNTDOWN - 1\`
182 done
184 [ \$STARTCOUNTDOWN -ne 0 ]
185 check_equals \$? 0 "Gnash-side ActionScript code should be successfully started"
188 # Built-in getURL target tests
191 # Read for empty-target getURL statement
192 read_timeout LINE \$READTIMEOUT <&3
193 check_equals "\$LINE" '<invoke name="getURL" returntype="xml"><arguments><string>geturl-emptytarget.html</string><string>GET</string></arguments></invoke>' "Gnash should correctly pass built-in getURL call with empty target"
195 if [ $swfversion -ge 5 ]
196 then
197 # Read for no-target getURL statement
198 read_timeout LINE \$READTIMEOUT <&3
199 check_equals "\$LINE" '<invoke name="getURL" returntype="xml"><arguments><string>geturl-notarget.html</string><string>GET</string></arguments></invoke>' "Gnash should correctly pass built-in getURL call with no target"
201 if [ $swfversion -ge 7 ]
202 then
203 # Read for undefined-target getURL statement (SWF7-above form)
204 read_timeout LINE \$READTIMEOUT <&3
205 check_equals "\$LINE" '<invoke name="getURL" returntype="xml"><arguments><string>geturl-undeftarget.html</string><string>GET</string><string>undefined</string></arguments></invoke>' "Gnash should correctly pass built-in getURL call with undefined target"
206 else
207 # Read for undefined-target getURL statement (SWF6-below form)
208 read_timeout LINE \$READTIMEOUT <&3
209 check_equals "\$LINE" '<invoke name="getURL" returntype="xml"><arguments><string>geturl-undeftarget.html</string><string>GET</string></arguments></invoke>' "Gnash should correctly pass built-in getURL call with undefined target"
212 # Read for null-target getURL statement
213 read_timeout LINE \$READTIMEOUT <&3
214 check_equals "\$LINE" '<invoke name="getURL" returntype="xml"><arguments><string>geturl-nulltarget.html</string><string>GET</string><string>null</string></arguments></invoke>' "Gnash should correctly pass built-in getURL call with null target"
217 # MovieClip-based getURL() target tests
220 # Read for empty-target MovieClip-based getURL statement
221 read_timeout LINE \$READTIMEOUT <&3
222 check_equals "\$LINE" "<invoke name=\"getURL\" returntype=\"xml\"><arguments><string>mcgeturl-emptytarget.html</string><string>GET</string></arguments></invoke>" "Gnash should correctly pass MovieClip-based getURL call with empty target"
224 # Read for no-target MovieClip-based getURL statement
225 read_timeout LINE \$READTIMEOUT <&3
226 check_equals "\$LINE" '<invoke name="getURL" returntype="xml"><arguments><string>mcgeturl-notarget.html</string><string>GET</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based getURL call with no target"
228 # Read for undefined-target MovieClip-based getURL statement
229 read_timeout LINE \$READTIMEOUT <&3
230 check_equals "\$LINE" '<invoke name="getURL" returntype="xml"><arguments><string>mcgeturl-undeftarget.html</string><string>GET</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based getURL call with undefined target"
232 # Read for null-target MovieClip-based getURL statement
233 read_timeout LINE \$READTIMEOUT <&3
234 check_equals "\$LINE" "<invoke name=\"getURL\" returntype=\"xml\"><arguments><string>mcgeturl-nulltarget.html</string><string>GET</string><string>null</string></arguments></invoke>" "Gnash should correctly pass MovieClip-based getURL call with null target"
237 # Close pipes
238 exec 3<&-
239 exec 4<&-
241 # Force Gnash to exit
242 kill \$GNASHPID
243 wait \$GNASHPID
245 # Show player-side output
246 exec 5< "\$LOGFILE"
247 cat <&5
248 exec 5<&-
250 # Check for total number of test run
251 if [ $swfversion -ge 5 ]
252 then
253 check_totals "9" "There should be 9 tests run"
254 else
255 check_totals "2" "There should be 2 tests run"
258 # Remove temporary files
259 rm "\$LOGFILE"
260 rm "\$PIPE2CONTAINER"
261 rm "\$PIPE2PLAYER"