Skip to content

Commit 96ae102

Browse files
authored
[test] Split browser-specific code into browser_common.py. NFC (#25728)
common.py was getting pretty huge and about 900 lines of it was browser-test specific stuff.
1 parent 9c7ed75 commit 96ae102

File tree

8 files changed

+957
-915
lines changed

8 files changed

+957
-915
lines changed

test/browser_common.py

Lines changed: 915 additions & 0 deletions
Large diffs are not rendered by default.

test/common.py

Lines changed: 8 additions & 888 deletions
Large diffs are not rendered by default.

test/parallel_testsuite.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import time
1212
import unittest
1313

14+
import browser_common
1415
import common
1516
from common import errlog
1617

@@ -124,7 +125,7 @@ def run(self, result):
124125
worker_id_lock = manager.Lock()
125126
with multiprocessing.Pool(
126127
processes=use_cores,
127-
initializer=common.init_worker,
128+
initializer=browser_common.init_worker,
128129
initargs=(worker_id_counter, worker_id_lock),
129130
) as pool:
130131
if python_multiprocessing_structures_are_buggy():

test/runner.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
__rootpath__ = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
3838
sys.path.insert(0, __rootpath__)
3939

40+
import browser_common
4041
import common
4142
import jsrun
4243
import parallel_testsuite
@@ -509,9 +510,9 @@ def parse_args():
509510

510511

511512
def configure():
512-
common.EMTEST_BROWSER = os.getenv('EMTEST_BROWSER')
513-
common.EMTEST_BROWSER_AUTO_CONFIG = os.getenv('EMTEST_BROWSER_AUTO_CONFIG')
514-
common.EMTEST_HEADLESS = int(os.getenv('EMTEST_HEADLESS', '0'))
513+
browser_common.EMTEST_BROWSER = os.getenv('EMTEST_BROWSER')
514+
browser_common.EMTEST_BROWSER_AUTO_CONFIG = os.getenv('EMTEST_BROWSER_AUTO_CONFIG')
515+
browser_common.EMTEST_HEADLESS = int(os.getenv('EMTEST_HEADLESS', '0'))
515516
common.EMTEST_DETECT_TEMPFILE_LEAKS = int(os.getenv('EMTEST_DETECT_TEMPFILE_LEAKS', '0'))
516517
common.EMTEST_ALL_ENGINES = int(os.getenv('EMTEST_ALL_ENGINES', '0'))
517518
common.EMTEST_SKIP_SLOW = int(os.getenv('EMTEST_SKIP_SLOW', '0'))
@@ -526,7 +527,7 @@ def configure():
526527
assert 'PARALLEL_SUITE_EMCC_CORES' not in os.environ, 'use EMTEST_CORES rather than PARALLEL_SUITE_EMCC_CORES'
527528
parallel_testsuite.NUM_CORES = os.environ.get('EMTEST_CORES') or os.environ.get('EMCC_CORES')
528529

529-
common.configure_test_browser()
530+
browser_common.configure_test_browser()
530531

531532

532533
def cleanup_emscripten_temp():
@@ -582,8 +583,8 @@ def set_env(name, option_value):
582583
# Remove any old test files before starting the run
583584
cleanup_emscripten_temp()
584585
utils.delete_file(common.flaky_tests_log_filename)
585-
utils.delete_file(common.browser_spawn_lock_filename)
586-
utils.delete_file(f'{common.browser_spawn_lock_filename}_counter')
586+
utils.delete_file(browser_common.browser_spawn_lock_filename)
587+
utils.delete_file(f'{browser_common.browser_spawn_lock_filename}_counter')
587588
if options.force_browser_process_termination or os.getenv('EMTEST_FORCE_BROWSER_PROCESS_TERMINATION'):
588589
config = common.get_browser_config()
589590

test/test_browser.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,27 @@
2222
from urllib.request import urlopen
2323

2424
import common
25-
from common import (
25+
from browser_common import (
2626
CHROMIUM_BASED_BROWSERS,
27-
EMRUN,
28-
WEBIDL_BINDER,
2927
BrowserCore,
3028
HttpServerThread,
3129
Reporting,
32-
RunnerCore,
3330
browser_should_skip_feature,
34-
copytree,
35-
create_file,
36-
ensure_dir,
3731
find_browser_test_file,
32+
get_browser,
3833
get_safari_version,
3934
has_browser,
4035
is_chrome,
4136
is_firefox,
4237
is_safari,
38+
)
39+
from common import (
40+
EMRUN,
41+
WEBIDL_BINDER,
42+
RunnerCore,
43+
copytree,
44+
create_file,
45+
ensure_dir,
4346
path_from_root,
4447
read_file,
4548
test_file,
@@ -177,7 +180,7 @@ def shell_with_script(shell_file, output_file, replacement):
177180

178181

179182
def is_swiftshader(_):
180-
return is_chrome() and '--use-gl=swiftshader' in common.EMTEST_BROWSER
183+
return is_chrome() and '--use-gl=swiftshader' in get_browser()
181184

182185

183186
no_swiftshader = skip_if_simple('not compatible with swiftshader', is_swiftshader)
@@ -232,7 +235,7 @@ def decorator(f):
232235
@wraps(f)
233236
def decorated(self, *args, **kwargs):
234237
if should_skip == 'error':
235-
raise Exception(f'This test requires a browser that supports {feature.name} but your browser {common.EMTEST_BROWSER} does not support this. Run with {skip_env_var}=1 or EMTEST_AUTOSKIP=1 to skip this test automatically.')
238+
raise Exception(f'This test requires a browser that supports {feature.name} but your browser {get_browser()} does not support this. Run with {skip_env_var}=1 or EMTEST_AUTOSKIP=1 to skip this test automatically.')
236239
elif should_skip:
237240
self.skip_exec = message
238241
f(self, *args, **kwargs)
@@ -265,7 +268,7 @@ class browser(BrowserCore):
265268
def setUpClass(cls):
266269
super().setUpClass()
267270
cls.browser_timeout = 60
268-
if common.EMTEST_BROWSER != 'node':
271+
if get_browser() != 'node':
269272
print()
270273
print('Running the browser tests. Make sure the browser allows popups from localhost.')
271274
print()
@@ -275,7 +278,7 @@ def proxy_to_worker(self):
275278

276279
def require_jspi(self):
277280
if not is_chrome():
278-
self.skipTest(f'Current browser ({common.EMTEST_BROWSER}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.')
281+
self.skipTest(f'Current browser ({get_browser()}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.')
279282
super().require_jspi()
280283

281284
def post_manual_reftest(self):
@@ -3351,7 +3354,7 @@ def test_cocos2d_hello(self):
33513354
})
33523355
def test_async(self, opt, args):
33533356
if is_jspi(args) and not is_chrome():
3354-
self.skipTest(f'Current browser ({common.EMTEST_BROWSER}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.')
3357+
self.skipTest(f'Current browser ({get_browser()}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.')
33553358

33563359
self.btest_exit('test_async.c', cflags=[opt, '-g2'] + args)
33573360

@@ -5045,7 +5048,7 @@ def test_embind_with_pthreads(self):
50455048
})
50465049
def test_embind(self, args):
50475050
if is_jspi(args) and not is_chrome():
5048-
self.skipTest(f'Current browser ({common.EMTEST_BROWSER}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.')
5051+
self.skipTest(f'Current browser ({get_browser()}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.')
50495052
if is_jspi(args) and self.is_wasm64():
50505053
self.skipTest('_emval_await fails')
50515054

@@ -5728,9 +5731,9 @@ def test_no_browser(self):
57285731
self.run_process([EMCC, test_file('test_emrun.c'), '--emrun', '-o', 'hello_world.html'])
57295732
proc = subprocess.Popen([EMRUN, '--no-browser', '.', '--port=3333'], stdout=PIPE)
57305733
try:
5731-
if common.EMTEST_BROWSER:
5734+
if get_browser():
57325735
print('Starting browser')
5733-
browser_cmd = shlex.split(common.EMTEST_BROWSER)
5736+
browser_cmd = shlex.split(get_browser())
57345737
browser = subprocess.Popen(browser_cmd + ['http://localhost:3333/hello_world.html'])
57355738
try:
57365739
while True:
@@ -5769,11 +5772,11 @@ def test_emrun(self):
57695772
'--log-stdout', self.in_dir('stdout.txt'),
57705773
'--log-stderr', self.in_dir('stderr.txt')]
57715774

5772-
if common.EMTEST_BROWSER is not None:
5775+
if get_browser() is not None:
57735776
# If EMTEST_BROWSER carried command line arguments to pass to the browser,
57745777
# (e.g. "firefox -profile /path/to/foo") those can't be passed via emrun,
57755778
# so strip them out.
5776-
browser_cmd = shlex.split(common.EMTEST_BROWSER)
5779+
browser_cmd = shlex.split(get_browser())
57775780
browser_path = browser_cmd[0]
57785781
args_base += ['--browser', browser_path]
57795782
if len(browser_cmd) > 1:

test/test_interactive.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
if __name__ == '__main__':
1111
raise Exception('do not run this file directly; do something like: test/runner.py interactive')
1212

13-
from common import BrowserCore, create_file, test_file
13+
from browser_common import BrowserCore
14+
from common import create_file, test_file
1415
from decorators import also_with_minimal_runtime, parameterized
1516

1617
from tools.utils import WINDOWS

test/test_posixtest_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
parallel.
88
"""
99

10-
from common import BrowserCore
10+
from browser_common import BrowserCore
1111

1212

1313
class posixtest_browser(BrowserCore):

test/test_sockets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
import clang_native
1919
import common
20-
from common import NON_ZERO, PYTHON, BrowserCore, create_file, read_file
20+
from browser_common import BrowserCore
21+
from common import NON_ZERO, PYTHON, create_file, read_file
2122
from decorators import (
2223
crossplatform,
2324
no_windows,

0 commit comments

Comments
 (0)