PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/rpython/jit/backend/llsupport/test/zrpy_releasegil_test.py

https://bitbucket.org/pypy/pypy/
Python | 124 lines | 104 code | 12 blank | 8 comment | 2 complexity | 41c474d65b20f67ad0bdf122e582ea00 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, Apache-2.0
  1. from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
  2. from rpython.rlib.jit import dont_look_inside
  3. from rpython.jit.metainterp.optimizeopt import ALL_OPTS_NAMES
  4. from rpython.translator.tool.cbuild import ExternalCompilationInfo
  5. from rpython.rlib import rposix
  6. from rpython.rtyper.annlowlevel import llhelper
  7. from rpython.jit.backend.llsupport.test.zrpy_gc_test import BaseFrameworkTests
  8. from rpython.jit.backend.llsupport.test.zrpy_gc_test import check
  9. from rpython.tool.udir import udir
  10. class ReleaseGILTests(BaseFrameworkTests):
  11. compile_kwds = dict(enable_opts=ALL_OPTS_NAMES, thread=True)
  12. def define_simple(self):
  13. c_strchr = rffi.llexternal('strchr', [rffi.CCHARP, lltype.Signed],
  14. rffi.CCHARP)
  15. def before(n, x):
  16. return (n, None, None, None, None, None,
  17. None, None, None, None, None, None)
  18. #
  19. def f(n, x, *args):
  20. a = rffi.str2charp(str(n))
  21. c_strchr(a, ord('0'))
  22. lltype.free(a, flavor='raw')
  23. n -= 1
  24. return (n, x) + args
  25. return before, f, None
  26. def test_simple(self):
  27. self.run('simple')
  28. assert 'call_release_gil' in udir.join('TestCompileFramework.log').read()
  29. def define_close_stack(self):
  30. #
  31. class Glob(object):
  32. pass
  33. glob = Glob()
  34. class X(object):
  35. pass
  36. #
  37. def callback(p1, p2):
  38. for i in range(100):
  39. glob.lst.append(X())
  40. return rffi.cast(rffi.INT, 1)
  41. CALLBACK = lltype.Ptr(lltype.FuncType([lltype.Signed,
  42. lltype.Signed], rffi.INT))
  43. #
  44. @dont_look_inside
  45. def alloc1():
  46. return llmemory.raw_malloc(16)
  47. @dont_look_inside
  48. def free1(p):
  49. llmemory.raw_free(p)
  50. c_qsort = rffi.llexternal('qsort', [rffi.VOIDP, rffi.SIZE_T,
  51. rffi.SIZE_T, CALLBACK], lltype.Void)
  52. #
  53. def f42(n):
  54. length = len(glob.lst)
  55. raw = alloc1()
  56. wrapper = rffi._make_wrapper_for(CALLBACK, callback, None, True)
  57. fn = llhelper(CALLBACK, wrapper)
  58. if n & 1: # to create a loop and a bridge, and also
  59. pass # to run the qsort() call in the blackhole interp
  60. c_qsort(rffi.cast(rffi.VOIDP, raw), rffi.cast(rffi.SIZE_T, 2),
  61. rffi.cast(rffi.SIZE_T, 8), fn)
  62. free1(raw)
  63. check(len(glob.lst) > length)
  64. del glob.lst[:]
  65. #
  66. def before(n, x):
  67. glob.lst = []
  68. return (n, None, None, None, None, None,
  69. None, None, None, None, None, None)
  70. #
  71. def f(n, x, *args):
  72. f42(n)
  73. n -= 1
  74. return (n, x) + args
  75. return before, f, None
  76. def test_close_stack(self):
  77. self.run('close_stack')
  78. assert 'call_release_gil' in udir.join('TestCompileFramework.log').read()
  79. # XXX this should also test get/set_alterrno ?
  80. def define_get_set_errno(self):
  81. eci = ExternalCompilationInfo(
  82. post_include_bits=[r'''
  83. #include <errno.h>
  84. static int test_get_set_errno(void) {
  85. int r = errno;
  86. //fprintf(stderr, "read saved errno: %d\n", r);
  87. errno = 42;
  88. return r;
  89. }
  90. '''])
  91. c_test = rffi.llexternal('test_get_set_errno', [], rffi.INT,
  92. compilation_info=eci,
  93. save_err=rffi.RFFI_FULL_ERRNO)
  94. def before(n, x):
  95. return (n, None, None, None, None, None,
  96. None, None, None, None, None, None)
  97. #
  98. def f(n, x, *args):
  99. rposix.set_saved_errno(24)
  100. result1 = c_test()
  101. result2 = rposix.get_saved_errno()
  102. assert result1 == 24
  103. assert result2 == 42
  104. n -= 1
  105. return (n, x) + args
  106. return before, f, None
  107. def test_get_set_errno(self):
  108. self.run('get_set_errno')
  109. assert 'call_release_gil' in udir.join('TestCompileFramework.log').read()