Skip to content

Commit

Permalink
[test] Add EMTEST_SKIP_NETWORK_TESTS (#21380)
Browse files Browse the repository at this point in the history
I was doing some work on an airplane over the weekend and I found this
useful.
  • Loading branch information
sbc100 committed Feb 20, 2024
1 parent 23d8972 commit b5eca2f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
config.NODE_JS_TEST = config.NODE_JS


requires_network = unittest.skipIf(os.getenv('EMTEST_SKIP_NETWORK_TESTS'), 'This test requires network access')


def test_file(*path_components):
"""Construct a path relative to the emscripten "tests" directory."""
return str(Path(TEST_ROOT, *path_components))
Expand Down
19 changes: 19 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from common import requires_wasm_eh, crossplatform, with_both_sjlj, also_with_standalone_wasm
from common import also_with_minimal_runtime, also_with_wasm_bigint, also_with_wasm64, flaky
from common import EMTEST_BUILD_VERBOSE, PYTHON, WEBIDL_BINDER
from common import requires_network
from tools import shared, building, utils, response_file, cache
from tools.utils import read_file, write_file, delete_file, read_binary
import common
Expand Down Expand Up @@ -1001,6 +1002,7 @@ def test_cmake_emscripten_system_processor(self):
[EMCMAKE, 'cmake', cmake_dir, '-DEMSCRIPTEN_SYSTEM_PROCESSOR=arm'], stdout=PIPE).stdout
self.assertContained('CMAKE_SYSTEM_PROCESSOR is arm', out)

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

@requires_network
def test_cmake_find_modules(self):
self.run_process([EMCMAKE, 'cmake', test_file('cmake/find_modules')])
self.run_process(['cmake', '--build', '.'])
Expand Down Expand Up @@ -2276,6 +2279,7 @@ def test_sdl_scan_code_from_key(self):
''')
self.do_runf('main.c', '204\n')

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

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

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

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

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

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

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

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

@requires_network
def test_bzip2(self):
self.do_runf('bzip2_test.c', 'usage: unzcrash filename',
emcc_args=['-sUSE_BZIP2', '-Wno-pointer-sign'])
self.do_runf('bzip2_test.c', 'usage: unzcrash filename',
emcc_args=['--use-port=bzip2', '-Wno-pointer-sign'])

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

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

@requires_network
def test_icu(self):
self.set_setting('USE_ICU')
self.do_runf('other/test_icu.cpp')

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

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

@crossplatform
@requires_network
def test_external_ports(self):
if config.FROZEN_CACHE:
self.skipTest("test doesn't work with frozen cache")
Expand Down

0 comments on commit b5eca2f

Please sign in to comment.