From d07849b97cdd4f4d3db1c778e90c512b1854ba74 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 2 Apr 2019 14:04:13 -0700 Subject: [PATCH] Move get_library helpers into test classes (#8385) These are essentially methods for some reason were defined as free functions. --- tests/runner.py | 115 +++++++++++++++------------------------- tests/test_benchmark.py | 4 +- tests/test_core.py | 41 +++++++++++--- tests/test_other.py | 4 +- 4 files changed, 81 insertions(+), 83 deletions(-) diff --git a/tests/runner.py b/tests/runner.py index 85223d9dd3fd..16b21d6866d7 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -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 @@ -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, @@ -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)) diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index 658dcb902533..b785130861e4 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -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 @@ -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', diff --git a/tests/test_core.py b/tests/test_core.py index a09851327d7b..e7407289ff18 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -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 @@ -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') @@ -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(), @@ -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 @@ -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) @@ -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]') @@ -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() @@ -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() diff --git a/tests/test_other.py b/tests/test_other.py index 29ba03811ed5..bedb68f22ab0 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -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 @@ -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')