Author: Armin Rigo <ar...@tunes.org> Branch: stmgc-c7 Changeset: r75784:a4514bd45065 Date: 2015-02-09 18:44 +0100 http://bitbucket.org/pypy/pypy/changeset/a4514bd45065/
Log: Improve the tests. Seems for some reason that *only with the JIT* we're getting the wrong location reported for write-read conflicts . diff --git a/pypy/module/pypystm/test_pypy_c/support.py b/pypy/module/pypystm/test_pypy_c/support.py --- a/pypy/module/pypystm/test_pypy_c/support.py +++ b/pypy/module/pypystm/test_pypy_c/support.py @@ -101,8 +101,10 @@ f.write(str(src) + '\n') f.write("print %s(%s)\n" % (funcname, arglist)) - def _execute(self, import_site=False): + def _execute(self, import_site=False, jit=True): cmdline = [sys.executable] + if not jit: + cmdline.extend(['--jit', 'off']) if not import_site: cmdline.append('-S') cmdline.append(str(self.filepath)) @@ -125,22 +127,27 @@ from pypy.stm.print_stm_log import StmLog return StmLog(str(self.logfile)) - def _check_count_conflicts(self, func_or_src, args=[]): + def _check_count_conflicts(self, func_or_src, args=[], **kwds): self._write_source(func_or_src, args) - self._execute() - stmlog = self._parse_log() - count = stmlog.get_total_aborts_and_pauses() + self._execute(**kwds) + self.stmlog = self._parse_log() + self.stmlog.dump() + count = self.stmlog.get_total_aborts_and_pauses() print 'stmlog.get_total_aborts_and_pauses():', count return count - def check_almost_no_conflict(self, *args): - count = self._check_count_conflicts(*args) + def check_almost_no_conflict(self, *args, **kwds): + count = self._check_count_conflicts(*args, **kwds) assert count < 500 - def check_MANY_conflicts(self, *args): - count = self._check_count_conflicts(*args) + def check_MANY_conflicts(self, *args, **kwds): + count = self._check_count_conflicts(*args, **kwds) assert count > 20000 - def check_SOME_conflicts(self, *args): - count = self._check_count_conflicts(*args) + def check_SOME_conflicts(self, *args, **kwds): + count = self._check_count_conflicts(*args, **kwds) assert count > 1000 + + def check_conflict_location(self, text): + first_conflict = self.stmlog.get_conflicts()[0] + assert first_conflict.get_marker1().rstrip().endswith(text) diff --git a/pypy/module/pypystm/test_pypy_c/test_conflict.py b/pypy/module/pypystm/test_pypy_c/test_conflict.py --- a/pypy/module/pypystm/test_pypy_c/test_conflict.py +++ b/pypy/module/pypystm/test_pypy_c/test_conflict.py @@ -3,17 +3,21 @@ class TestConflict(BaseTestSTM): - def test_obvious(self): + def test_obvious(self, jit=False): def f(): class X(object): pass x = X() # shared x.a = 0 def g(): - x.a += 1 + x.a += 1 #loc1 run_in_threads(g) # - self.check_MANY_conflicts(f) + self.check_MANY_conflicts(f, jit=jit) + self.check_conflict_location("#loc1") + + def test_obvious_with_jit(self): + self.test_obvious(jit=True) def test_plain_dict_access(self): def f(): @@ -44,3 +48,23 @@ run_in_threads(g, arg_thread_num=True) # self.check_SOME_conflicts(f) + + def test_plain_write_read(self, jit=False): + def f(): + class X(object): + pass + x = X() + x.a = 0 + def g(tnum): + if tnum == 0: + x.a += 1 #loc2 + else: + if x.a < 0: + raise AssertionError + run_in_threads(g, arg_thread_num=True) + # + self.check_SOME_conflicts(f, jit=jit) + self.check_conflict_location("#loc2") + + def test_plain_write_read_with_jit(self): + self.test_plain_write_read(jit=True) diff --git a/pypy/stm/print_stm_log.py b/pypy/stm/print_stm_log.py --- a/pypy/stm/print_stm_log.py +++ b/pypy/stm/print_stm_log.py @@ -146,9 +146,19 @@ def sortkey(self): return self.aborted_time + self.paused_time + def get_event_name(self): + return event_name[self.event] + + def get_marker1(self): + return print_marker(self.marker1) + + def get_marker2(self): + return print_marker(self.marker2) + def __str__(self): s = '%.3fs lost in aborts, %.3fs paused (%dx %s)\n' % ( - self.aborted_time, self.paused_time, self.num_events, event_name[self.event]) + self.aborted_time, self.paused_time, self.num_events, + self.get_event_name()) s += print_marker(self.marker1) if self.marker2: s += '\n%s' % print_marker(self.marker2) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit