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()
29 # <https://savannah.gnu.org/bugs/?50393>
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
39 # The generated test file requires a filesystem that supports named pipes.
42 # Check for generation parameters
47 echo "Usage: $0 <builddir> <srcdir> <swfversion> <swf>" >&2
51 shift $
(($OPTIND - 1))
54 echo "Usage: $0 <builddir> <srcdir> <swfversion> <swf>" >&2
58 # Load generation parameters
67 # Generate the test runner
71 echo "# Environment variables"
72 env |
grep '^GNASH' |
while read reply
74 echo "export \"${reply}\""
79 # Filenames and constants
80 LOGFILE=${top_builddir}/testoutlog.\$\$
81 PIPE2CONTAINER=${top_builddir}/tocontainer.\$\$
82 PIPE2PLAYER=${top_builddir}/toplayer.\$\$
91 # check_equals(\$op1, \$op2, \$msg)
92 # Equality checker and counter
97 PASSED=\`expr "\$PASSED" + 1\`
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)
111 PASSED=\`expr "\$PASSED" + 1\`
113 echo "XFAILED: \$3 (\"\$1\" != \"\$2\")"
114 FAILED=\`expr "\$FAILED" + 1\`
116 TESTED=\`expr "\$TESTED" + 1\`
119 # check_totals(\$op, \$msg)
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
130 echo "ERROR: \$2" >&2
135 # read_timeout(\$varname, \$timeout)
136 # Read one line from standard input, with a specified timeout (in seconds)
138 trap 'trap - USR1; return 142' USR1
139 (sleep "\$2" && kill -USR1 "\$\$" > /dev/null 2>&1) &
143 kill "\$TIMEOUTPID" > /dev/null 2>&1
148 # Create required named pipes
149 if [ \! -p "\$PIPE2CONTAINER" ]
151 mkfifo "\$PIPE2CONTAINER"
152 check_error "\$?" "Failed to create a named pipe: \$PIPE2CONTAINER"
154 if [ \! -p "\$PIPE2PLAYER" ]
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"
169 "${top_builddir}/gui/gnash" -r 0 -vv -F 3:4 "${swf}" > "\$LOGFILE" 2>&1 &
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
181 STARTCOUNTDOWN=\`expr \$STARTCOUNTDOWN - 1\`
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 ]
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 ]
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"
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"
241 # Force Gnash to exit
245 # Show player-side output
250 # Check for total number of test run
251 if [ $swfversion -ge 5 ]
253 check_totals "9" "There should be 9 tests run"
255 check_totals "2" "There should be 2 tests run"
258 # Remove temporary files
260 rm "\$PIPE2CONTAINER"