PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/rpython/jit/backend/test/support.py

https://bitbucket.org/pypy/pypy/
Python | 140 lines | 131 code | 8 blank | 1 comment | 5 complexity | f1431796965727380def170063d6a0de MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, Apache-2.0
  1. import py
  2. import sys
  3. from rpython.rlib.debug import debug_print
  4. from rpython.translator.translator import TranslationContext, graphof
  5. from rpython.jit.metainterp.optimizeopt import ALL_OPTS_NAMES
  6. from rpython.rlib.rarithmetic import is_valid_int
  7. class BaseCompiledMixin(object):
  8. CPUClass = None
  9. basic = False
  10. def _get_TranslationContext(self):
  11. return TranslationContext()
  12. def _compile_and_run(self, t, entry_point, entry_point_graph, args):
  13. raise NotImplementedError
  14. # XXX backendopt is ignored
  15. def meta_interp(self, function, args, repeat=1, inline=False, trace_limit=sys.maxint,
  16. backendopt=None, listcomp=False, **kwds): # XXX ignored
  17. from rpython.jit.metainterp.warmspot import WarmRunnerDesc
  18. from rpython.annotator.listdef import s_list_of_strings
  19. from rpython.annotator import model as annmodel
  20. for arg in args:
  21. assert is_valid_int(arg)
  22. self.pre_translation_hook()
  23. t = self._get_TranslationContext()
  24. if listcomp:
  25. t.config.translation.list_comprehension_operations = True
  26. arglist = ", ".join(['int(argv[%d])' % (i + 1) for i in range(len(args))])
  27. if len(args) == 1:
  28. arglist += ','
  29. arglist = '(%s)' % arglist
  30. if repeat != 1:
  31. src = py.code.Source("""
  32. def entry_point(argv):
  33. args = %s
  34. res = function(*args)
  35. for k in range(%d - 1):
  36. res = function(*args)
  37. print res
  38. return 0
  39. """ % (arglist, repeat))
  40. else:
  41. src = py.code.Source("""
  42. def entry_point(argv):
  43. args = %s
  44. res = function(*args)
  45. print res
  46. return 0
  47. """ % (arglist,))
  48. exec src.compile() in locals()
  49. t.buildannotator().build_types(function, [int] * len(args),
  50. main_entry_point=True)
  51. t.buildrtyper().specialize()
  52. warmrunnerdesc = WarmRunnerDesc(t, translate_support_code=True,
  53. CPUClass=self.CPUClass,
  54. **kwds)
  55. for jd in warmrunnerdesc.jitdrivers_sd:
  56. jd.warmstate.set_param_threshold(3) # for tests
  57. jd.warmstate.set_param_trace_eagerness(2) # for tests
  58. jd.warmstate.set_param_trace_limit(trace_limit)
  59. jd.warmstate.set_param_inlining(inline)
  60. jd.warmstate.set_param_enable_opts(ALL_OPTS_NAMES)
  61. mixlevelann = warmrunnerdesc.annhelper
  62. entry_point_graph = mixlevelann.getgraph(entry_point, [s_list_of_strings],
  63. annmodel.SomeInteger())
  64. warmrunnerdesc.finish()
  65. self.post_translation_hook()
  66. return self._compile_and_run(t, entry_point, entry_point_graph, args)
  67. def pre_translation_hook(self):
  68. pass
  69. def post_translation_hook(self):
  70. pass
  71. def check_loops(self, *args, **kwds):
  72. pass
  73. def check_loop_count(self, *args, **kwds):
  74. pass
  75. def check_tree_loop_count(self, *args, **kwds):
  76. pass
  77. def check_enter_count(self, *args, **kwds):
  78. pass
  79. def check_enter_count_at_most(self, *args, **kwds):
  80. pass
  81. def check_max_trace_length(self, *args, **kwds):
  82. pass
  83. def check_aborted_count(self, *args, **kwds):
  84. pass
  85. def check_aborted_count_at_least(self, *args, **kwds):
  86. pass
  87. def interp_operations(self, *args, **kwds):
  88. py.test.skip("interp_operations test skipped")
  89. class CCompiledMixin(BaseCompiledMixin):
  90. slow = False
  91. def setup_class(cls):
  92. if cls.slow:
  93. from rpython.jit.conftest import option
  94. if not option.run_slow_tests:
  95. py.test.skip("use --slow to execute this long-running test")
  96. def _get_TranslationContext(self):
  97. t = TranslationContext()
  98. t.config.translation.gc = 'boehm'
  99. t.config.translation.list_comprehension_operations = True
  100. return t
  101. def _compile_and_run(self, t, entry_point, entry_point_graph, args):
  102. from rpython.translator.c.genc import CStandaloneBuilder as CBuilder
  103. # XXX patch exceptions
  104. cbuilder = CBuilder(t, entry_point, config=t.config)
  105. cbuilder.generate_source()
  106. self._check_cbuilder(cbuilder)
  107. exe_name = cbuilder.compile()
  108. debug_print('---------- Test starting ----------')
  109. stdout = cbuilder.cmdexec(" ".join([str(arg) for arg in args]))
  110. res = int(stdout)
  111. debug_print('---------- Test done (%d) ----------' % (res,))
  112. return res
  113. def _check_cbuilder(self, cbuilder):
  114. pass