Author: Armin Rigo <ar...@tunes.org> Branch: static-callback-embedding Changeset: r2535:dd5771e43bd0 Date: 2016-01-07 16:19 +0100 http://bitbucket.org/cffi/cffi/changeset/dd5771e43bd0/
Log: Allow platform-specific hacks to invoke the compiler diff --git a/testing/embedding/test_basic.py b/testing/embedding/test_basic.py --- a/testing/embedding/test_basic.py +++ b/testing/embedding/test_basic.py @@ -1,3 +1,4 @@ +import py import sys, os import shutil, subprocess from testing.udir import udir @@ -35,10 +36,22 @@ env=env) self._compiled_modules.add(name) - def compile(self, name, modules, extra=[]): + def compile(self, name, modules, **flags): path = self.get_path() filename = '%s.c' % name shutil.copy(os.path.join(local_dir, filename), path) + if sys.platform.startswith('linux'): + self._compile_linux(name, modules, **flags) + elif sys.platform.startswith('win'): + self._compile_win(name, modules, **flags) + else: + py.test.skip("don't know how to invoke the C compiler on %r" % + (sys.platform,)) + + def _compile_linux(self, name, modules, + opt=False, threads=False, defines={}): + path = self.get_path() + filename = '%s.c' % name if 'CC' in os.environ: args = os.environ['CC'].split() else: @@ -47,6 +60,10 @@ args.extend(os.environ['CFLAGS'].split()) if 'LDFLAGS' in os.environ: args.extend(os.environ['LDFLAGS'].split()) + if threads: + args.append('-pthread') + if opt: + args.append('-O2') args.extend(['-g', filename, '-o', name, '-L.']) if '__pypy__' in sys.builtin_module_names: # xxx a bit hackish, maybe ffi.compile() should do a better job @@ -63,9 +80,14 @@ args.extend(['%s.so' % modname for modname in modules]) args.append('-lpython2.7') args.append('-Wl,-rpath=$ORIGIN/') - args.extend(extra) + for key, value in sorted(defines.items()): + args.append('-D%s=%s' % (key, value)) self._run(args) + def _compile_win(self, name, modules, + opt=False, threads=False, defines={}): + xxxx + def execute(self, name): path = self.get_path() env = os.environ.copy() diff --git a/testing/embedding/test_performance.py b/testing/embedding/test_performance.py --- a/testing/embedding/test_performance.py +++ b/testing/embedding/test_performance.py @@ -4,7 +4,7 @@ class TestPerformance(EmbeddingTests): def test_perf_single_threaded(self): self.prepare_module('perf') - self.compile('perf-test', ['_perf_cffi'], ['-O2']) + self.compile('perf-test', ['_perf_cffi'], opt=True) output = self.execute('perf-test') print '='*79 print output.rstrip() @@ -12,8 +12,8 @@ def test_perf_in_1_thread(self): self.prepare_module('perf') - self.compile('perf-test', ['_perf_cffi'], - ['-pthread', '-O2', '-DPTEST_USE_THREAD=1']) + self.compile('perf-test', ['_perf_cffi'], opt=True, threads=True, + defines={'PTEST_USE_THREAD': '1'}) output = self.execute('perf-test') print '='*79 print output.rstrip() @@ -21,8 +21,8 @@ def test_perf_in_2_threads(self): self.prepare_module('perf') - self.compile('perf-test', ['_perf_cffi'], - ['-pthread', '-O2', '-DPTEST_USE_THREAD=2']) + self.compile('perf-test', ['_perf_cffi'], opt=True, threads=True, + defines={'PTEST_USE_THREAD': '2'}) output = self.execute('perf-test') print '='*79 print output.rstrip() @@ -30,8 +30,8 @@ def test_perf_in_4_threads(self): self.prepare_module('perf') - self.compile('perf-test', ['_perf_cffi'], - ['-pthread', '-O2', '-DPTEST_USE_THREAD=4']) + self.compile('perf-test', ['_perf_cffi'], opt=True, threads=True, + defines={'PTEST_USE_THREAD': '4'}) output = self.execute('perf-test') print '='*79 print output.rstrip() @@ -39,8 +39,8 @@ def test_perf_in_8_threads(self): self.prepare_module('perf') - self.compile('perf-test', ['_perf_cffi'], - ['-pthread', '-O2', '-DPTEST_USE_THREAD=8']) + self.compile('perf-test', ['_perf_cffi'], opt=True, threads=True, + defines={'PTEST_USE_THREAD': '8'}) output = self.execute('perf-test') print '='*79 print output.rstrip() diff --git a/testing/embedding/test_thread.py b/testing/embedding/test_thread.py --- a/testing/embedding/test_thread.py +++ b/testing/embedding/test_thread.py @@ -4,7 +4,7 @@ class TestThread(EmbeddingTests): def test_first_calls_in_parallel(self): self.prepare_module('add1') - self.compile('thread1-test', ['_add1_cffi'], ['-pthread']) + self.compile('thread1-test', ['_add1_cffi'], threads=True) for i in range(50): output = self.execute('thread1-test') assert output == ("starting\n" @@ -20,7 +20,7 @@ def test_init_different_modules_in_different_threads(self): self.prepare_module('add1') self.prepare_module('add2') - self.compile('thread2-test', ['_add1_cffi', '_add2_cffi'], ['-pthread']) + self.compile('thread2-test', ['_add1_cffi', '_add2_cffi'], threads=True) output = self.execute('thread2-test') output = self._take_out(output, "preparing") output = self._take_out(output, ".") @@ -37,7 +37,7 @@ self.prepare_module('add1') self.prepare_module('add2') self.compile('thread2-test', ['_add1_cffi', '_add2_cffi'], - ['-pthread', '-DT2TEST_AGAIN_ADD1']) + threads=True, defines={'T2TEST_AGAIN_ADD1': '1'}) output = self.execute('thread2-test') output = self._take_out(output, "adding 40 and 2\n") assert output == ("starting\n" @@ -50,7 +50,7 @@ def test_load_in_parallel_more(self): self.prepare_module('add2') self.prepare_module('add3') - self.compile('thread3-test', ['_add2_cffi', '_add3_cffi'], ['-pthread']) + self.compile('thread3-test', ['_add2_cffi', '_add3_cffi'], threads=True) for i in range(150): output = self.execute('thread3-test') for j in range(10): diff --git a/testing/embedding/test_tlocal.py b/testing/embedding/test_tlocal.py --- a/testing/embedding/test_tlocal.py +++ b/testing/embedding/test_tlocal.py @@ -4,7 +4,7 @@ class TestThreadLocal(EmbeddingTests): def test_thread_local(self): self.prepare_module('tlocal') - self.compile('tlocal-test', ['_tlocal_cffi'], ['-pthread']) + self.compile('tlocal-test', ['_tlocal_cffi'], threads=True) for i in range(10): output = self.execute('tlocal-test') assert output == "done\n" _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit