Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move get_library helpers into test classes #8385

Merged
merged 2 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 44 additions & 71 deletions tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,49 @@ def do_ll_run(self, ll_file, expected_output=None, args=[], js_engines=None,
output_nicerizer=output_nicerizer,
assert_returncode=assert_returncode)

def get_freetype_library(self):
self.set_setting('DEAD_FUNCTIONS', self.get_setting('DEAD_FUNCTIONS') + ['_inflateEnd', '_inflate', '_inflateReset', '_inflateInit2_'])

return self.get_library('freetype', os.path.join('objs', '.libs', 'libfreetype.a'))

def get_poppler_library(self):
# The fontconfig symbols are all missing from the poppler build
# e.g. FcConfigSubstitute
self.set_setting('ERROR_ON_UNDEFINED_SYMBOLS', 0)

Building.COMPILER_TEST_OPTS += [
'-I' + path_from_root('tests', 'freetype', 'include'),
'-I' + path_from_root('tests', 'poppler', 'include')
]

freetype = self.get_freetype_library()

# Poppler has some pretty glaring warning. Suppress them to keep the
# test output readable.
Building.COMPILER_TEST_OPTS += [
'-Wno-sentinel',
'-Wno-logical-not-parentheses',
'-Wno-unused-private-field',
'-Wno-tautological-compare',
'-Wno-unknown-pragmas',
]
poppler = self.get_library(
'poppler',
[os.path.join('utils', 'pdftoppm.o'), os.path.join('utils', 'parseargs.o'), os.path.join('poppler', '.libs', 'libpoppler.a')],
env_init={'FONTCONFIG_CFLAGS': ' ', 'FONTCONFIG_LIBS': ' '},
configure_args=['--disable-libjpeg', '--disable-libpng', '--disable-poppler-qt', '--disable-poppler-qt4', '--disable-cms', '--disable-cairo-output', '--disable-abiword-output', '--enable-shared=no'])

return poppler + freetype

def get_zlib_library(self):
if WINDOWS:
return self.get_library('zlib', os.path.join('libz.a'),
configure=[path_from_root('emconfigure.bat')],
configure_args=['cmake', '.'],
make=['mingw32-make'],
make_args=[])
return self.get_library('zlib', os.path.join('libz.a'), make_args=['libz.a'])


# Run a server and a web page. When a test runs, we tell the server about it,
# which tells the web page, which then opens a window with the test. Doing
Expand Down Expand Up @@ -1364,42 +1407,8 @@ def btest(self, filename, expected=None, reference=None, force_c=False,
self.btest(filename, expected, reference, force_c, reference_slack, manual_reference, post_build,
original_args + ['--proxy-to-worker', '-s', 'GL_TESTING=1'], outfile, message, timeout=timeout)

###################################################################################################


def get_zlib_library(runner_core):
if WINDOWS:
return runner_core.get_library('zlib', os.path.join('libz.a'),
configure=[path_from_root('emconfigure.bat')],
configure_args=['cmake', '.'],
make=['mingw32-make'],
make_args=[])
else:
return runner_core.get_library('zlib', os.path.join('libz.a'), make_args=['libz.a'])


# Both test_core and test_other access the Bullet library, share the access here to avoid duplication.
def get_bullet_library(runner_core, use_cmake):
if use_cmake:
configure_commands = ['cmake', '.']
configure_args = ['-DBUILD_DEMOS=OFF', '-DBUILD_EXTRAS=OFF', '-DUSE_GLUT=OFF']
# Depending on whether 'configure' or 'cmake' is used to build, Bullet places output files in different directory structures.
generated_libs = [os.path.join('src', 'BulletDynamics', 'libBulletDynamics.a'),
os.path.join('src', 'BulletCollision', 'libBulletCollision.a'),
os.path.join('src', 'LinearMath', 'libLinearMath.a')]
else:
configure_commands = ['sh', './configure']
# Force a nondefault --host= so that the configure script will interpret that we are doing cross-compilation
# and skip attempting to run the generated executable with './a.out', which would fail since we are building a .js file.
configure_args = ['--disable-shared', '--host=i686-pc-linux-gnu', '--disable-demos', '--disable-dependency-tracking']
generated_libs = [os.path.join('src', '.libs', 'libBulletDynamics.a'),
os.path.join('src', '.libs', 'libBulletCollision.a'),
os.path.join('src', '.libs', 'libLinearMath.a')]

return runner_core.get_library('bullet', generated_libs,
configure=configure_commands,
configure_args=configure_args,
cache_name_extra=configure_commands[0])
###################################################################################################


def build_library(name,
Expand Down Expand Up @@ -1510,42 +1519,6 @@ def open_make_err(i, mode='r'):
return generated_libs


def get_freetype_library(runner_core):
runner_core.set_setting('DEAD_FUNCTIONS', runner_core.get_setting('DEAD_FUNCTIONS') + ['_inflateEnd', '_inflate', '_inflateReset', '_inflateInit2_'])

return runner_core.get_library('freetype', os.path.join('objs', '.libs', 'libfreetype.a'))


def get_poppler_library(runner_core):
# The fontconfig symbols are all missing from the poppler build
# e.g. FcConfigSubstitute
runner_core.set_setting('ERROR_ON_UNDEFINED_SYMBOLS', 0)

Building.COMPILER_TEST_OPTS += [
'-I' + path_from_root('tests', 'freetype', 'include'),
'-I' + path_from_root('tests', 'poppler', 'include')
]

freetype = get_freetype_library(runner_core)

# Poppler has some pretty glaring warning. Suppress them to keep the
# test output readable.
Building.COMPILER_TEST_OPTS += [
'-Wno-sentinel',
'-Wno-logical-not-parentheses',
'-Wno-unused-private-field',
'-Wno-tautological-compare',
'-Wno-unknown-pragmas',
]
poppler = runner_core.get_library(
'poppler',
[os.path.join('utils', 'pdftoppm.o'), os.path.join('utils', 'parseargs.o'), os.path.join('poppler', '.libs', 'libpoppler.a')],
env_init={'FONTCONFIG_CFLAGS': ' ', 'FONTCONFIG_LIBS': ' '},
configure_args=['--disable-libjpeg', '--disable-libpng', '--disable-poppler-qt', '--disable-poppler-qt4', '--disable-cms', '--disable-cairo-output', '--disable-abiword-output', '--enable-shared=no'])

return poppler + freetype


def check_js_engines():
total_engines = len(shared.JS_ENGINES)
shared.JS_ENGINES = list(filter(jsrun.check_engine, shared.JS_ENGINES))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if __name__ == '__main__':
raise Exception('do not run this file directly; do something like: tests/runner.py benchmark')

from runner import RunnerCore, chdir, get_poppler_library
from runner import RunnerCore, chdir
from tools.shared import run_process, path_from_root, CLANG, Building, SPIDERMONKEY_ENGINE, LLVM_ROOT, CLOSURE_COMPILER, CLANG_CC, V8_ENGINE, PIPE, try_delete, PYTHON, EMCC
from tools import shared, jsrun

Expand Down Expand Up @@ -1016,7 +1016,7 @@ def test_zzz_poppler(self):
''' % DEFAULT_ARG)

def lib_builder(name, native, env_init):
return get_poppler_library(self)
return self.get_poppler_library()

# TODO: Fix poppler native build and remove skip_native=True
self.do_benchmark('poppler', '', 'hashed printout',
Expand Down
41 changes: 33 additions & 8 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from tools.shared import Building, STDOUT, PIPE, run_js, run_process, try_delete
from tools.shared import NODE_JS, V8_ENGINE, JS_ENGINES, SPIDERMONKEY_ENGINE, PYTHON, EMCC, EMAR, WINDOWS, AUTODEBUGGER
from tools import jsrun, shared
from runner import RunnerCore, path_from_root, core_test_modes, get_zlib_library, get_bullet_library, get_freetype_library, get_poppler_library, EMTEST_SKIP_SLOW
from runner import RunnerCore, path_from_root, core_test_modes, EMTEST_SKIP_SLOW
from runner import skip_if, no_wasm_backend, needs_dlfcn, no_windows, env_modify, with_env_modify, is_slow_test, create_test_file

# decorators for limiting which modes a test can run in
Expand Down Expand Up @@ -126,6 +126,31 @@ def find_files(*ext_list):
output = find_files('.out', '.txt')
self.do_run_from_file(src, output, **kwargs)

def get_bullet_library(self, use_cmake):
if use_cmake:
configure_commands = ['cmake', '.']
configure_args = ['-DBUILD_DEMOS=OFF', '-DBUILD_EXTRAS=OFF', '-DUSE_GLUT=OFF']
# Depending on whether 'configure' or 'cmake' is used to build, Bullet
# places output files in different directory structures.
generated_libs = [os.path.join('src', 'BulletDynamics', 'libBulletDynamics.a'),
os.path.join('src', 'BulletCollision', 'libBulletCollision.a'),
os.path.join('src', 'LinearMath', 'libLinearMath.a')]
else:
configure_commands = ['sh', './configure']
# Force a nondefault --host= so that the configure script will interpret
# that we are doing cross-compilation
# and skip attempting to run the generated executable with './a.out',
# which would fail since we are building a .js file.
configure_args = ['--disable-shared', '--host=i686-pc-linux-gnu', '--disable-demos', '--disable-dependency-tracking']
generated_libs = [os.path.join('src', '.libs', 'libBulletDynamics.a'),
os.path.join('src', '.libs', 'libBulletCollision.a'),
os.path.join('src', '.libs', 'libLinearMath.a')]

return self.get_library('bullet', generated_libs,
configure=configure_commands,
configure_args=configure_args,
cache_name_extra=configure_commands[0])

def test_hello_world(self):
self.do_run_in_out_file_test('tests', 'core', 'test_hello_world')

Expand Down Expand Up @@ -4054,7 +4079,7 @@ def test_dylink_zlib(self):
self.set_setting('BINARYEN_TRAP_MODE', 'clamp')

Building.COMPILER_TEST_OPTS += ['-I' + path_from_root('tests', 'zlib')]
zlib_archive = get_zlib_library(self)
zlib_archive = self.get_zlib_library()
self.dylink_test(main=open(path_from_root('tests', 'zlib', 'example.c')).read(),
side=zlib_archive,
expected=open(path_from_root('tests', 'zlib', 'ref.txt')).read(),
Expand All @@ -4063,7 +4088,7 @@ def test_dylink_zlib(self):
# @needs_dlfcn
# def test_dylink_bullet(self):
# Building.COMPILER_TEST_OPTS += ['-I' + path_from_root('tests', 'bullet', 'src')]
# side = get_bullet_library(self, True)
# side = self.get_bullet_library(self, True)
# self.dylink_test(main=open(path_from_root('tests', 'bullet', 'Demos', 'HelloWorld', 'HelloWorld.cpp')).read(),
# side=side,
# expected=[open(path_from_root('tests', 'bullet', 'output.txt')).read(), # different roundings
Expand Down Expand Up @@ -5522,7 +5547,7 @@ def test_freetype(self):
self.do_run(open(path_from_root('tests', 'freetype', 'main.c')).read(),
open(path_from_root('tests', 'freetype', 'ref.txt')).read(),
['font.ttf', 'test!', '150', '120', '25'],
libraries=get_freetype_library(self),
libraries=self.get_freetype_library(),
includes=[path_from_root('tests', 'freetype', 'include')])
self.set_setting('OUTLINING_LIMIT', 0)

Expand All @@ -5531,14 +5556,14 @@ def test_freetype(self):
self.do_run(open(path_from_root('tests', 'freetype', 'main_2.c')).read(),
open(path_from_root('tests', 'freetype', 'ref_2.txt')).read(),
['font.ttf', 'w', '32', '32', '25'],
libraries=get_freetype_library(self),
libraries=self.get_freetype_library(),
includes=[path_from_root('tests', 'freetype', 'include')])

print('[issue 324 case 2]')
self.do_run(open(path_from_root('tests', 'freetype', 'main_3.c')).read(),
open(path_from_root('tests', 'freetype', 'ref_3.txt')).read(),
['font.ttf', 'W', '32', '32', '0'],
libraries=get_freetype_library(self),
libraries=self.get_freetype_library(),
includes=[path_from_root('tests', 'freetype', 'include')])

print('[issue 324 case 3]')
Expand Down Expand Up @@ -5615,7 +5640,7 @@ def test():
open(path_from_root('tests', 'bullet', 'output2.txt')).read(),
open(path_from_root('tests', 'bullet', 'output3.txt')).read(),
open(path_from_root('tests', 'bullet', 'output4.txt')).read()],
libraries=get_bullet_library(self, use_cmake),
libraries=self.get_bullet_library(use_cmake),
includes=[path_from_root('tests', 'bullet', 'src')])
test()

Expand All @@ -5639,7 +5664,7 @@ def test():

ppm_data = str(list(bytearray(open(path_from_root('tests', 'poppler', 'ref.ppm'), 'rb').read())))
self.do_run('', ppm_data.replace(' ', ''),
libraries=get_poppler_library(self),
libraries=self.get_poppler_library(),
args=['-scale-to', '512', 'paper.pdf', 'filename'])

test()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from tools.shared import CLANG, CLANG_CC, CLANG_CPP, LLVM_AR
from tools.shared import COMPILER_ENGINE, NODE_JS, SPIDERMONKEY_ENGINE, JS_ENGINES, V8_ENGINE
from tools.shared import WebAssembly
from runner import RunnerCore, path_from_root, get_zlib_library, no_wasm_backend
from runner import RunnerCore, path_from_root, no_wasm_backend
from runner import needs_dlfcn, env_modify, no_windows, chdir, with_env_modify, create_test_file
from tools import jsrun, shared
import tools.line_endings
Expand Down Expand Up @@ -1058,7 +1058,7 @@ def measure_funcs(filename):
]:
Building.COMPILER_TEST_OPTS = test_opts
test('zlib', path_from_root('tests', 'zlib', 'example.c'),
get_zlib_library(self),
self.get_zlib_library(),
open(path_from_root('tests', 'zlib', 'ref.txt')).read(),
expected_ranges,
args=['-I' + path_from_root('tests', 'zlib')], suffix='c')
Expand Down