Skip to content

Commit c94f3b2

Browse files
authored
Fix crash in emrun.py (#13553)
Split out from #13412 and add a test. Fixes emscripten-core/emsdk#712
1 parent 0967ae3 commit c94f3b2

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

emrun.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ def kill_browser_process():
424424
# starting a browser process from command line generally launches just a "stub" spawner
425425
# process that immediately exits.
426426
def detect_browser_processes():
427+
if not browser_exe:
428+
return # Running with --no_browser, we are not binding to a spawned browser.
429+
427430
global current_browser_processes
428431
logv('First navigation occurred. Identifying currently running browser processes')
429432
running_browser_processes = list_processes_by_name(browser_exe)

tests/test_browser.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5019,18 +5019,43 @@ def test_manual_pthread_proxy_hammer(self, args):
50195019
extra_tries=0)
50205020

50215021

5022+
EMRUN = path_from_root('emrun')
5023+
5024+
50225025
class emrun(RunnerCore):
50235026
def test_emrun_info(self):
50245027
if not has_browser():
50255028
self.skipTest('need a browser')
5026-
result = self.run_process([path_from_root('emrun'), '--system_info', '--browser_info'], stdout=PIPE).stdout
5029+
result = self.run_process([EMRUN, '--system_info', '--browser_info'], stdout=PIPE).stdout
50275030
assert 'CPU' in result
50285031
assert 'Browser' in result
50295032
assert 'Traceback' not in result
50305033

5031-
result = self.run_process([path_from_root('emrun'), '--list_browsers'], stdout=PIPE).stdout
5034+
result = self.run_process([EMRUN, '--list_browsers'], stdout=PIPE).stdout
50325035
assert 'Traceback' not in result
50335036

5037+
def test_no_browser(self):
5038+
# Test --no_browser mode where we have to take care of launching the browser outselves
5039+
# and killin emrun when we are done.
5040+
if not has_browser():
5041+
self.skipTest('need a browser')
5042+
5043+
self.run_process([EMCC, path_from_root('tests', 'test_emrun.c'), '--emrun', '-o', 'hello_world.html'])
5044+
proc = subprocess.Popen([EMRUN, '--no_browser', '.', '--port=3333'], stdout=PIPE)
5045+
try:
5046+
if EMTEST_BROWSER:
5047+
browser_cmd = shlex.split(EMTEST_BROWSER)
5048+
browser = subprocess.Popen(browser_cmd + ['http://localhost:3333/hello_world.html'])
5049+
while True:
5050+
stdout = proc.stdout.read()
5051+
if b'Dumping out file' in stdout:
5052+
break
5053+
browser.terminate()
5054+
browser.wait()
5055+
finally:
5056+
proc.terminate()
5057+
proc.wait()
5058+
50345059
def test_emrun(self):
50355060
self.run_process([EMCC, path_from_root('tests', 'test_emrun.c'), '--emrun', '-o', 'hello_world.html'])
50365061
if not has_browser():
@@ -5042,7 +5067,7 @@ def test_emrun(self):
50425067
# delete it. Therefore switch away from that directory before launching.
50435068

50445069
os.chdir(path_from_root())
5045-
args_base = [path_from_root('emrun'), '--timeout', '30', '--safe_firefox_profile',
5070+
args_base = [EMRUN, '--timeout', '30', '--safe_firefox_profile',
50465071
'--kill_exit', '--port', '6939', '--verbose',
50475072
'--log_stdout', self.in_dir('stdout.txt'),
50485073
'--log_stderr', self.in_dir('stderr.txt')]

0 commit comments

Comments
 (0)