Skip to content

Commit b5eca2f

Browse files
authored
[test] Add EMTEST_SKIP_NETWORK_TESTS (#21380)
I was doing some work on an airplane over the weekend and I found this useful.
1 parent 23d8972 commit b5eca2f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

test/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
config.NODE_JS_TEST = config.NODE_JS
9494

9595

96+
requires_network = unittest.skipIf(os.getenv('EMTEST_SKIP_NETWORK_TESTS'), 'This test requires network access')
97+
98+
9699
def test_file(*path_components):
97100
"""Construct a path relative to the emscripten "tests" directory."""
98101
return str(Path(TEST_ROOT, *path_components))

test/test_other.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from common import requires_wasm_eh, crossplatform, with_both_sjlj, also_with_standalone_wasm
3838
from common import also_with_minimal_runtime, also_with_wasm_bigint, also_with_wasm64, flaky
3939
from common import EMTEST_BUILD_VERBOSE, PYTHON, WEBIDL_BINDER
40+
from common import requires_network
4041
from tools import shared, building, utils, response_file, cache
4142
from tools.utils import read_file, write_file, delete_file, read_binary
4243
import common
@@ -1001,6 +1002,7 @@ def test_cmake_emscripten_system_processor(self):
10011002
[EMCMAKE, 'cmake', cmake_dir, '-DEMSCRIPTEN_SYSTEM_PROCESSOR=arm'], stdout=PIPE).stdout
10021003
self.assertContained('CMAKE_SYSTEM_PROCESSOR is arm', out)
10031004

1005+
@requires_network
10041006
def test_cmake_find_stuff(self):
10051007
# Ensure that zlib exists in the sysroot
10061008
self.run_process([EMCC, test_file('hello_world.c'), '-sUSE_ZLIB'])
@@ -1021,6 +1023,7 @@ def test_cmake_install(self):
10211023
self.assertContained('foo: 42\n', self.run_js('build2/Bar.js'))
10221024
self.run_process(['cmake', '--build', 'build2', '--target', 'install'])
10231025

1026+
@requires_network
10241027
def test_cmake_find_modules(self):
10251028
self.run_process([EMCMAKE, 'cmake', test_file('cmake/find_modules')])
10261029
self.run_process(['cmake', '--build', '.'])
@@ -2276,6 +2279,7 @@ def test_sdl_scan_code_from_key(self):
22762279
''')
22772280
self.do_runf('main.c', '204\n')
22782281

2282+
@requires_network
22792283
def test_sdl2_mixer_wav(self):
22802284
self.emcc(test_file('browser/test_sdl2_mixer_wav.c'), ['-sUSE_SDL_MIXER=2'], output_filename='a.out.js')
22812285
self.emcc(test_file('browser/test_sdl2_mixer_wav.c'), ['--use-port=sdl2_mixer'], output_filename='a.out.js')
@@ -2286,11 +2290,13 @@ def test_sdl2_linkable(self):
22862290
self.emcc(test_file('browser/test_sdl2_misc.c'), ['-sLINKABLE', '-sUSE_SDL=2'], output_filename='a.out.js')
22872291
self.emcc(test_file('browser/test_sdl2_misc.c'), ['-sLINKABLE', '--use-port=sdl2'], output_filename='a.out.js')
22882292

2293+
@requires_network
22892294
def test_sdl2_gfx_linkable(self):
22902295
# Same as above but for sdl2_gfx library
22912296
self.emcc(test_file('browser/test_sdl2_misc.c'), ['-Wl,-fatal-warnings', '-sLINKABLE', '-sUSE_SDL_GFX=2'], output_filename='a.out.js')
22922297
self.emcc(test_file('browser/test_sdl2_misc.c'), ['-Wl,-fatal-warnings', '-sLINKABLE', '--use-port=sdl2_gfx'], output_filename='a.out.js')
22932298

2299+
@requires_network
22942300
def test_libpng(self):
22952301
shutil.copyfile(test_file('third_party/libpng/pngtest.png'), 'pngtest.png')
22962302
self.do_runf('third_party/libpng/pngtest.c', 'libpng passes test',
@@ -2299,11 +2305,13 @@ def test_libpng(self):
22992305
emcc_args=['--embed-file', 'pngtest.png', '--use-port=libpng'])
23002306

23012307
@node_pthreads
2308+
@requires_network
23022309
def test_libpng_with_pthreads(self):
23032310
shutil.copyfile(test_file('third_party/libpng/pngtest.png'), 'pngtest.png')
23042311
self.do_runf('third_party/libpng/pngtest.c', 'libpng passes test',
23052312
emcc_args=['--embed-file', 'pngtest.png', '-sUSE_LIBPNG', '-pthread'])
23062313

2314+
@requires_network
23072315
def test_giflib(self):
23082316
# giftext.c contains a sprintf warning
23092317
self.emcc_args += ['-Wno-fortify-source']
@@ -2322,6 +2330,7 @@ def test_giflib(self):
23222330
emcc_args=['--embed-file', 'treescap.gif', '--use-port=giflib'],
23232331
args=['treescap.gif'])
23242332

2333+
@requires_network
23252334
def test_libjpeg(self):
23262335
shutil.copyfile(test_file('screenshot.jpg'), 'screenshot.jpg')
23272336
self.do_runf('jpeg_test.c', 'Image is 600 by 450 with 3 components',
@@ -2331,22 +2340,26 @@ def test_libjpeg(self):
23312340
emcc_args=['--embed-file', 'screenshot.jpg', '--use-port=libjpeg'],
23322341
args=['screenshot.jpg'])
23332342

2343+
@requires_network
23342344
def test_bullet(self):
23352345
self.do_runf('bullet_hello_world.cpp', 'BULLET RUNNING', emcc_args=['-sUSE_BULLET'])
23362346
self.do_runf('bullet_hello_world.cpp', 'BULLET RUNNING', emcc_args=['--use-port=bullet'])
23372347

2348+
@requires_network
23382349
def test_vorbis(self):
23392350
# This will also test if ogg compiles, because vorbis depends on ogg
23402351
self.do_runf('vorbis_test.c', 'ALL OK', emcc_args=['-sUSE_VORBIS'])
23412352
self.do_runf('vorbis_test.c', 'ALL OK', emcc_args=['--use-port=vorbis'])
23422353

2354+
@requires_network
23432355
def test_bzip2(self):
23442356
self.do_runf('bzip2_test.c', 'usage: unzcrash filename',
23452357
emcc_args=['-sUSE_BZIP2', '-Wno-pointer-sign'])
23462358
self.do_runf('bzip2_test.c', 'usage: unzcrash filename',
23472359
emcc_args=['--use-port=bzip2', '-Wno-pointer-sign'])
23482360

23492361
@with_both_sjlj
2362+
@requires_network
23502363
def test_freetype(self):
23512364
# copy the Liberation Sans Bold truetype file located in the
23522365
# <emscripten_root>/test/freetype to the compilation folder
@@ -2375,19 +2388,24 @@ def test_freetype(self):
23752388
self.do_runf('freetype_test.c', expectedOutput,
23762389
emcc_args=['--use-port=freetype', '--embed-file', 'LiberationSansBold.ttf'])
23772390

2391+
@requires_network
2392+
@requires_network
23782393
def test_freetype_with_pthreads(self):
23792394
# Verify that freetype supports compilation requiring pthreads
23802395
self.emcc(test_file('freetype_test.c'), ['-pthread', '-sUSE_FREETYPE'], output_filename='a.out.js')
23812396

2397+
@requires_network
23822398
def test_icu(self):
23832399
self.set_setting('USE_ICU')
23842400
self.do_runf('other/test_icu.cpp')
23852401

2402+
@requires_network
23862403
def test_sdl2_ttf(self):
23872404
# This is a compile-only to test to verify that sdl2-ttf (and freetype and harfbuzz) are buildable.
23882405
self.emcc(test_file('browser/test_sdl2_ttf.c'), args=['-sUSE_SDL=2', '-sUSE_SDL_TTF=2'], output_filename='a.out.js')
23892406
self.emcc(test_file('browser/test_sdl2_ttf.c'), args=['--use-port=sdl2', '--use-port=sdl2_ttf'], output_filename='a.out.js')
23902407

2408+
@requires_network
23912409
def test_contrib_ports(self):
23922410
# Verify that contrib ports can be used (using the only contrib port available ATM, but can be replaced
23932411
# with a different contrib port when there is another one
@@ -2401,6 +2419,7 @@ def test_external_ports_simple(self):
24012419
self.do_runf('other/test_external_ports_simple.c', emcc_args=[f'--use-port={simple_port_path}'])
24022420

24032421
@crossplatform
2422+
@requires_network
24042423
def test_external_ports(self):
24052424
if config.FROZEN_CACHE:
24062425
self.skipTest("test doesn't work with frozen cache")

0 commit comments

Comments
 (0)