Author: Antonio Cuni <anto.c...@gmail.com> Branch: vmprof-resolve_addr Changeset: r93755:0bf081e65685 Date: 2018-02-05 10:05 +0100 http://bitbucket.org/pypy/pypy/changeset/0bf081e65685/
Log: don't use a hardcoded address, but use a more proper way of discovering one diff --git a/pypy/module/_vmprof/test/test__vmprof.py b/pypy/module/_vmprof/test/test__vmprof.py --- a/pypy/module/_vmprof/test/test__vmprof.py +++ b/pypy/module/_vmprof/test/test__vmprof.py @@ -1,6 +1,8 @@ import py import sys from rpython.tool.udir import udir +from rpython.rlib import rvmprof +from rpython.rtyper.lltypesystem import rffi, lltype from pypy.tool.pytest.objspace import gettestobjspace class AppTestVMProf(object): @@ -11,6 +13,9 @@ cls.w_tmpfilename2 = cls.space.wrap(str(udir.join('test__vmprof.2'))) cls.w_plain = cls.space.wrap(not cls.runappdirect and '__pypy__' not in sys.builtin_module_names) + # + addr = rffi.cast(lltype.Signed, rvmprof.get_address_of_vmprof_start_sampling()) + cls.w_addr_of_vmprof_start_sampling = cls.space.wrap(addr) def test_import_vmprof(self): tmpfile = open(self.tmpfilename, 'wb') @@ -152,8 +157,7 @@ def test_resolve_addr(self): import _vmprof - addr = 0x517450 # XXX dont' hardcode + addr = self.addr_of_vmprof_start_sampling name, lineno, srcfile = _vmprof.resolve_addr(addr) - assert name == 'PyLong_AsLong' - assert lineno == 0 - assert srcfile == 'python' + assert name == 'vmprof_start_sampling' + assert srcfile.endswith('rvmprof.c') diff --git a/rpython/rlib/rvmprof/__init__.py b/rpython/rlib/rvmprof/__init__.py --- a/rpython/rlib/rvmprof/__init__.py +++ b/rpython/rlib/rvmprof/__init__.py @@ -84,3 +84,15 @@ vmprof_tl_stack.setraw(x) start_sampling() + +# -------------- +# used by tests +# -------------- + +def get_address_of_vmprof_start_sampling(): + """ + This is used only for testing that vmp_resolve_addr can find the correct + symbol name + """ + fn = _get_vmprof().cintf.vmprof_start_sampling + return rffi.cast(rffi.VOIDP, fn) diff --git a/rpython/rlib/rvmprof/test/test_rvmprof.py b/rpython/rlib/rvmprof/test/test_rvmprof.py --- a/rpython/rlib/rvmprof/test/test_rvmprof.py +++ b/rpython/rlib/rvmprof/test/test_rvmprof.py @@ -204,8 +204,7 @@ class TestSymbolTable(object): def test_vmp_resolve_addr(self): - # XXX: don't hardcode this addr - addr = rffi.cast(rffi.VOIDP, 0x517450) + addr = rvmprof.get_address_of_vmprof_start_sampling() name, lineno, srcfile = rvmprof.resolve_addr(addr) - assert name == 'PyLong_AsLong' - + assert name == 'vmprof_start_sampling' + assert srcfile.endswith('rvmprof.c') _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit