Split emrun tests out of `browser` (#12594)
Unlike the other browser tests they don't use the test runner harness and instead launch their own browser. I was finding that running the test locally in isolation that browser test harness would interfere with the browser that emrun was starting.. since they both honor EMTEST_BROWSER.
This commit is contained in:
Родитель
3f7d8eeac3
Коммит
9608511c6f
|
@ -248,6 +248,7 @@ commands:
|
|||
cat $TMPDIR/fifo > /dev/null # wait until $EXTRA_AUTOSTART is spawned, which indicates the end of Openbox initialization
|
||||
rm -r $TMPDIR
|
||||
python3 tests/runner.py browser skip:browser.test_sdl2_mouse skip:browser.test_html5_webgl_create_context skip:browser.test_webgl_offscreen_canvas_in_pthread skip:browser.test_webgl_offscreen_canvas_in_mainthread_after_pthread skip:browser.test_glut_glutget
|
||||
python3 tests/runner.py emrun
|
||||
openbox --exit
|
||||
wait || true # wait for startx to shutdown cleanly, or not
|
||||
test-chrome:
|
||||
|
@ -279,6 +280,7 @@ commands:
|
|||
export EMTEST_BROWSER="/usr/bin/google-chrome $CHROME_FLAGS_BASE $CHROME_FLAGS_HEADLESS $CHROME_FLAGS_WASM $CHROME_FLAGS_NOCACHE"
|
||||
# skip test_zzz_zzz_4GB_fail as it OOMs on the current bot
|
||||
python3 tests/runner.py browser skip:browser.test_zzz_zzz_4GB_fail
|
||||
python3 tests/runner.py emrun
|
||||
test-sockets-chrome:
|
||||
description: "Runs emscripten sockets tests under chrome"
|
||||
steps:
|
||||
|
|
54
emrun.py
54
emrun.py
|
@ -161,8 +161,8 @@ def logv(msg):
|
|||
Only shown if run with --verbose.
|
||||
"""
|
||||
global last_message_time
|
||||
with http_mutex:
|
||||
if emrun_options.verbose:
|
||||
if emrun_options.verbose:
|
||||
with http_mutex:
|
||||
if emrun_options.log_html:
|
||||
sys.stdout.write(format_html(msg))
|
||||
else:
|
||||
|
@ -475,6 +475,7 @@ class HTTPWebServer(socketserver.ThreadingMixIn, HTTPServer):
|
|||
now = tick()
|
||||
# Did user close browser?
|
||||
if not emrun_options.no_browser and not is_browser_process_alive():
|
||||
logv("Shutting down because browser is no longer alive")
|
||||
delete_emrun_safe_firefox_profile()
|
||||
if not emrun_options.serve_after_close:
|
||||
self.is_running = False
|
||||
|
@ -659,35 +660,34 @@ class HTTPHandler(SimpleHTTPRequestHandler):
|
|||
data = data.replace("+", " ")
|
||||
data = unquote_u(data)
|
||||
|
||||
# The user page sent a message with POST. Parse the message and log it to stdout/stderr.
|
||||
is_stdout = False
|
||||
is_stderr = False
|
||||
seq_num = -1
|
||||
# The html shell is expected to send messages of form ^out^(number)^(message) or ^err^(number)^(message).
|
||||
if data.startswith('^err^'):
|
||||
is_stderr = True
|
||||
elif data.startswith('^out^'):
|
||||
is_stdout = True
|
||||
if is_stderr or is_stdout:
|
||||
try:
|
||||
i = data.index('^', 5)
|
||||
seq_num = int(data[5:i])
|
||||
data = data[i + 1:]
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
is_exit = data.startswith('^exit^')
|
||||
|
||||
if data == '^pageload^': # Browser is just notifying that it has successfully launched the page.
|
||||
have_received_messages = True
|
||||
elif not is_exit:
|
||||
elif data.startswith('^exit^'):
|
||||
if not emrun_options.serve_after_exit:
|
||||
page_exit_code = int(data[6:])
|
||||
logv('Web page has quit with a call to exit() with return code ' + str(page_exit_code) + '. Shutting down web server. Pass --serve_after_exit to keep serving even after the page terminates with exit().')
|
||||
self.server.shutdown()
|
||||
return
|
||||
else:
|
||||
# The user page sent a message with POST. Parse the message and log it to stdout/stderr.
|
||||
is_stdout = False
|
||||
is_stderr = False
|
||||
seq_num = -1
|
||||
# The html shell is expected to send messages of form ^out^(number)^(message) or ^err^(number)^(message).
|
||||
if data.startswith('^err^'):
|
||||
is_stderr = True
|
||||
elif data.startswith('^out^'):
|
||||
is_stdout = True
|
||||
if is_stderr or is_stdout:
|
||||
try:
|
||||
i = data.index('^', 5)
|
||||
seq_num = int(data[5:i])
|
||||
data = data[i + 1:]
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
log = browser_loge if is_stderr else browser_logi
|
||||
self.server.handle_incoming_message(seq_num, log, data)
|
||||
elif not emrun_options.serve_after_exit:
|
||||
page_exit_code = int(data[6:])
|
||||
logv('Web page has quit with a call to exit() with return code ' + str(page_exit_code) + '. Shutting down web server. Pass --serve_after_exit to keep serving even after the page terminates with exit().')
|
||||
self.server.shutdown()
|
||||
return
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text/plain')
|
||||
|
|
|
@ -20,7 +20,7 @@ import zlib
|
|||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
from urllib.request import urlopen
|
||||
|
||||
from runner import BrowserCore, path_from_root, has_browser, EMTEST_BROWSER
|
||||
from runner import BrowserCore, RunnerCore, path_from_root, has_browser, EMTEST_BROWSER
|
||||
from runner import no_wasm_backend, create_test_file, parameterized, ensure_dir
|
||||
from tools import building
|
||||
from tools import shared
|
||||
|
@ -2438,77 +2438,6 @@ void *getBindBuffer() {
|
|||
create_test_file('data.dat', 'data from the file ' + ('.' * 9000))
|
||||
self.btest(path_from_root('tests', 'mmap_file.c'), expected='1', args=['--preload-file', 'data.dat'])
|
||||
|
||||
def test_emrun_info(self):
|
||||
if not has_browser():
|
||||
self.skipTest('need a browser')
|
||||
result = self.run_process([path_from_root('emrun'), '--system_info', '--browser_info'], stdout=PIPE).stdout
|
||||
assert 'CPU' in result
|
||||
assert 'Browser' in result
|
||||
assert 'Traceback' not in result
|
||||
|
||||
result = self.run_process([path_from_root('emrun'), '--list_browsers'], stdout=PIPE).stdout
|
||||
assert 'Traceback' not in result
|
||||
|
||||
# Deliberately named as test_zzz_emrun to make this test the last one
|
||||
# as this test may take the focus away from the main test window
|
||||
# by opening a new window and possibly not closing it.
|
||||
def test_zzz_emrun(self):
|
||||
self.compile_btest([path_from_root('tests', 'test_emrun.c'), '--emrun', '-o', 'hello_world.html'])
|
||||
if not has_browser():
|
||||
self.skipTest('need a browser')
|
||||
|
||||
# We cannot run emrun from the temp directory the suite will clean up afterwards, since the
|
||||
# browser that is launched will have that directory as startup directory, and the browser will
|
||||
# not close as part of the test, pinning down the cwd on Windows and it wouldn't be possible to
|
||||
# delete it. Therefore switch away from that directory before launching.
|
||||
|
||||
os.chdir(path_from_root())
|
||||
args_base = [path_from_root('emrun'), '--timeout', '30', '--safe_firefox_profile',
|
||||
'--kill_exit', '--port', '6939', '--verbose',
|
||||
'--log_stdout', self.in_dir('stdout.txt'),
|
||||
'--log_stderr', self.in_dir('stderr.txt')]
|
||||
|
||||
# Verify that trying to pass argument to the page without the `--` separator will
|
||||
# generate an actionable error message
|
||||
err = self.expect_fail(args_base + ['--foo'])
|
||||
self.assertContained('error: unrecognized arguments: --foo', err)
|
||||
self.assertContained('remember to add `--` between arguments', err)
|
||||
|
||||
if EMTEST_BROWSER is not None:
|
||||
# If EMTEST_BROWSER carried command line arguments to pass to the browser,
|
||||
# (e.g. "firefox -profile /path/to/foo") those can't be passed via emrun,
|
||||
# so strip them out.
|
||||
browser_cmd = shlex.split(EMTEST_BROWSER)
|
||||
browser_path = browser_cmd[0]
|
||||
args_base += ['--browser', browser_path]
|
||||
if len(browser_cmd) > 1:
|
||||
browser_args = browser_cmd[1:]
|
||||
if 'firefox' in browser_path and ('-profile' in browser_args or '--profile' in browser_args):
|
||||
# emrun uses its own -profile, strip it out
|
||||
parser = argparse.ArgumentParser(add_help=False) # otherwise it throws with -headless
|
||||
parser.add_argument('-profile')
|
||||
parser.add_argument('--profile')
|
||||
browser_args = parser.parse_known_args(browser_args)[1]
|
||||
if browser_args:
|
||||
args_base += ['--browser_args', ' ' + ' '.join(browser_args)]
|
||||
|
||||
for args in [
|
||||
args_base,
|
||||
args_base + ['--private_browsing', '--port', '6941']
|
||||
]:
|
||||
args += [self.in_dir('hello_world.html'), '--', '1', '2', '--3']
|
||||
print(shared.shlex_join(args))
|
||||
proc = self.run_process(args, check=False)
|
||||
self.assertEqual(proc.returncode, 100)
|
||||
stdout = open(self.in_dir('stdout.txt'), 'r').read()
|
||||
stderr = open(self.in_dir('stderr.txt'), 'r').read()
|
||||
self.assertContained('argc: 4', stdout)
|
||||
self.assertContained('argv[3]: --3', stdout)
|
||||
self.assertContained('hello, world!', stdout)
|
||||
self.assertContained('Testing ASCII characters: !"$%&\'()*+,-./:;<=>?@[\\]^_`{|}~', stdout)
|
||||
self.assertContained('Testing char sequences: %20%21 ä', stdout)
|
||||
self.assertContained('hello, error stream!', stderr)
|
||||
|
||||
# This does not actually verify anything except that --cpuprofiler and --memoryprofiler compiles.
|
||||
# Run interactive.test_cpuprofiler_memoryprofiler for interactive testing.
|
||||
@requires_graphics_hardware
|
||||
|
@ -4956,3 +4885,73 @@ window.close = function() {
|
|||
# don't run this with the default extra_tries value, as this is
|
||||
# *meant* to notice something random, a race condition.
|
||||
extra_tries=0)
|
||||
|
||||
|
||||
class emrun(RunnerCore):
|
||||
def test_emrun_info(self):
|
||||
if not has_browser():
|
||||
self.skipTest('need a browser')
|
||||
result = self.run_process([path_from_root('emrun'), '--system_info', '--browser_info'], stdout=PIPE).stdout
|
||||
assert 'CPU' in result
|
||||
assert 'Browser' in result
|
||||
assert 'Traceback' not in result
|
||||
|
||||
result = self.run_process([path_from_root('emrun'), '--list_browsers'], stdout=PIPE).stdout
|
||||
assert 'Traceback' not in result
|
||||
|
||||
def test_emrun(self):
|
||||
self.run_process([EMCC, path_from_root('tests', 'test_emrun.c'), '--emrun', '-o', 'hello_world.html'])
|
||||
if not has_browser():
|
||||
self.skipTest('need a browser')
|
||||
|
||||
# We cannot run emrun from the temp directory the suite will clean up afterwards, since the
|
||||
# browser that is launched will have that directory as startup directory, and the browser will
|
||||
# not close as part of the test, pinning down the cwd on Windows and it wouldn't be possible to
|
||||
# delete it. Therefore switch away from that directory before launching.
|
||||
|
||||
os.chdir(path_from_root())
|
||||
args_base = [path_from_root('emrun'), '--timeout', '30', '--safe_firefox_profile',
|
||||
'--kill_exit', '--port', '6939', '--verbose',
|
||||
'--log_stdout', self.in_dir('stdout.txt'),
|
||||
'--log_stderr', self.in_dir('stderr.txt')]
|
||||
|
||||
# Verify that trying to pass argument to the page without the `--` separator will
|
||||
# generate an actionable error message
|
||||
err = self.expect_fail(args_base + ['--foo'])
|
||||
self.assertContained('error: unrecognized arguments: --foo', err)
|
||||
self.assertContained('remember to add `--` between arguments', err)
|
||||
|
||||
if EMTEST_BROWSER is not None:
|
||||
# If EMTEST_BROWSER carried command line arguments to pass to the browser,
|
||||
# (e.g. "firefox -profile /path/to/foo") those can't be passed via emrun,
|
||||
# so strip them out.
|
||||
browser_cmd = shlex.split(EMTEST_BROWSER)
|
||||
browser_path = browser_cmd[0]
|
||||
args_base += ['--browser', browser_path]
|
||||
if len(browser_cmd) > 1:
|
||||
browser_args = browser_cmd[1:]
|
||||
if 'firefox' in browser_path and ('-profile' in browser_args or '--profile' in browser_args):
|
||||
# emrun uses its own -profile, strip it out
|
||||
parser = argparse.ArgumentParser(add_help=False) # otherwise it throws with -headless
|
||||
parser.add_argument('-profile')
|
||||
parser.add_argument('--profile')
|
||||
browser_args = parser.parse_known_args(browser_args)[1]
|
||||
if browser_args:
|
||||
args_base += ['--browser_args', ' ' + ' '.join(browser_args)]
|
||||
|
||||
for args in [
|
||||
args_base,
|
||||
args_base + ['--private_browsing', '--port', '6941']
|
||||
]:
|
||||
args += [self.in_dir('hello_world.html'), '--', '1', '2', '--3']
|
||||
print(shared.shlex_join(args))
|
||||
proc = self.run_process(args, check=False)
|
||||
self.assertEqual(proc.returncode, 100)
|
||||
stdout = open(self.in_dir('stdout.txt'), 'r').read()
|
||||
stderr = open(self.in_dir('stderr.txt'), 'r').read()
|
||||
self.assertContained('argc: 4', stdout)
|
||||
self.assertContained('argv[3]: --3', stdout)
|
||||
self.assertContained('hello, world!', stdout)
|
||||
self.assertContained('Testing ASCII characters: !"$%&\'()*+,-./:;<=>?@[\\]^_`{|}~', stdout)
|
||||
self.assertContained('Testing char sequences: %20%21 ä', stdout)
|
||||
self.assertContained('hello, error stream!', stderr)
|
||||
|
|
Загрузка…
Ссылка в новой задаче