Author: Armin Rigo <[email protected]>
Branch: c7-full-profiling
Changeset: r1448:3bb5d6edf0ca
Date: 2014-10-04 15:33 +0200
http://bitbucket.org/pypy/stmgc/changeset/3bb5d6edf0ca/

Log:    Fix marker tests

diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -146,9 +146,11 @@
     uintptr_t odd_number;
     object_t *object;
 } stm_loc_marker_t;
-void (*stmcb_timing_event)(stm_thread_local_t *tl, /* the local thread */
-                           enum stm_event_e event,
-                           stm_loc_marker_t *markers);
+
+typedef void (*stmcb_timing_event_fn)(stm_thread_local_t *tl,
+                                      enum stm_event_e event,
+                                      stm_loc_marker_t *markers);
+stmcb_timing_event_fn stmcb_timing_event;
 
 void stm_push_marker(stm_thread_local_t *, uintptr_t, object_t *);
 void stm_update_marker_num(stm_thread_local_t *, uintptr_t);
@@ -552,8 +554,7 @@
         self.current_thread = 0
 
     def teardown_method(self, meth):
-        lib.stmcb_expand_marker = ffi.NULL
-        lib.stmcb_debug_print = ffi.NULL
+        lib.stmcb_timing_event = ffi.NULL
         tl = self.tls[self.current_thread]
         if lib._stm_in_transaction(tl) and lib.stm_is_inevitable():
             self.commit_transaction()      # must succeed!
@@ -639,7 +640,7 @@
         self.push_root(ffi.cast("object_t *", 8))
 
     def check_char_everywhere(self, obj, expected_content, offset=HDR):
-        for i in range(len(self.tls)):
+        for i in range(len(self.tls) + 1):
             addr = lib._stm_get_segment_base(i)
             content = addr[int(ffi.cast("uintptr_t", obj)) + offset]
             assert content == expected_content
diff --git a/c7/test/test_marker.py b/c7/test/test_marker.py
--- a/c7/test/test_marker.py
+++ b/c7/test/test_marker.py
@@ -1,8 +1,35 @@
 from support import *
 import py, time
 
+
 class TestMarker(BaseTest):
 
+    def recording(self, kind):
+        seen = []
+        @ffi.callback("stmcb_timing_event_fn")
+        def timing_event(tl, event, markers):
+            if event == kind:
+                seen.append(tl)
+                seen.append(markers[0].tl)
+                seen.append(markers[0].segment_base)
+                seen.append(markers[0].odd_number)
+                seen.append(markers[0].object)
+                seen.append(markers[1].tl)
+                seen.append(markers[1].segment_base)
+                seen.append(markers[1].odd_number)
+                seen.append(markers[1].object)
+        lib.stmcb_timing_event = timing_event
+        self.timing_event_keepalive = timing_event
+        self.seen = seen
+
+    def check_recording(self, i1, o1, i2, o2):
+        seen = self.seen
+        assert seen[0] == self.tls[1]
+        segbase = lib._stm_get_segment_base
+        assert seen[1:5] == [self.tls[1], segbase(2), i1, o1]
+        assert seen[5:9] == [self.tls[0], segbase(1), i2, o2]
+        assert len(seen) == 9
+
     def test_marker_odd_simple(self):
         self.start_transaction()
         self.push_root(ffi.cast("object_t *", 29))
@@ -13,74 +40,17 @@
         assert int(ffi.cast("uintptr_t", x)) == 29
 
     def test_abort_marker_no_shadowstack(self):
-        tl = self.get_stm_thread_local()
-        assert tl.longest_marker_state == lib.STM_TIME_OUTSIDE_TRANSACTION
-        assert tl.longest_marker_time == 0.0
+        self.recording(lib.STM_CONTENTION_WRITE_WRITE)
+        p = stm_allocate_old(16)
         #
         self.start_transaction()
-        start = time.time()
-        while abs(time.time() - start) <= 0.1:
-            pass
-        self.abort_transaction()
+        stm_set_char(p, 'A')
         #
-        tl = self.get_stm_thread_local()
-        assert tl.longest_marker_state == lib.STM_TIME_RUN_ABORTED_OTHER
-        assert 0.099 <= tl.longest_marker_time <= 0.9
-        assert tl.longest_marker_self[0] == '\x00'
-        assert tl.longest_marker_other[0] == '\x00'
-
-    def test_abort_marker_shadowstack(self):
+        self.switch(1)
         self.start_transaction()
-        p = stm_allocate(16)
-        self.push_root(ffi.cast("object_t *", 29))
-        self.push_root(p)
-        start = time.time()
-        while abs(time.time() - start) <= 0.1:
-            pass
-        self.abort_transaction()
+        py.test.raises(Conflict, stm_set_char, p, 'B')
         #
-        tl = self.get_stm_thread_local()
-        assert tl.longest_marker_state == lib.STM_TIME_RUN_ABORTED_OTHER
-        assert 0.099 <= tl.longest_marker_time <= 0.9
-        assert tl.longest_marker_self[0] == '\x00'
-        assert tl.longest_marker_other[0] == '\x00'
-
-    def test_abort_marker_no_shadowstack_cb(self):
-        @ffi.callback("void(char *, uintptr_t, object_t *, char *, size_t)")
-        def expand_marker(base, number, ptr, outbuf, outbufsize):
-            seen.append(1)
-        lib.stmcb_expand_marker = expand_marker
-        seen = []
-        #
-        self.start_transaction()
-        self.abort_transaction()
-        #
-        tl = self.get_stm_thread_local()
-        assert tl.longest_marker_self[0] == '\x00'
-        assert not seen
-
-    def test_abort_marker_shadowstack_cb(self):
-        @ffi.callback("void(char *, uintptr_t, object_t *, char *, size_t)")
-        def expand_marker(base, number, ptr, outbuf, outbufsize):
-            s = '%d %r\x00' % (number, ptr)
-            assert len(s) <= outbufsize
-            outbuf[0:len(s)] = s
-        lib.stmcb_expand_marker = expand_marker
-        #
-        self.start_transaction()
-        p = stm_allocate(16)
-        self.push_root(ffi.cast("object_t *", 29))
-        self.push_root(p)
-        start = time.time()
-        while abs(time.time() - start) <= 0.1:
-            pass
-        self.abort_transaction()
-        #
-        tl = self.get_stm_thread_local()
-        assert tl.longest_marker_state == lib.STM_TIME_RUN_ABORTED_OTHER
-        assert 0.099 <= tl.longest_marker_time <= 0.9
-        assert ffi.string(tl.longest_marker_self) == '29 %r' % (p,)
-        assert ffi.string(tl.longest_marker_other) == ''
+        self.check_recording(0, ffi.NULL, 0, ffi.NULL)
 
     def test_macros(self):
         self.start_transaction()
@@ -116,72 +86,8 @@
         lib.stm_pop_marker(tl)
         py.test.raises(EmptyStack, self.pop_root)
 
-    def test_stm_expand_marker(self):
-        @ffi.callback("void(char *, uintptr_t, object_t *, char *, size_t)")
-        def expand_marker(base, number, ptr, outbuf, outbufsize):
-            s = '%d %r\x00' % (number, ptr)
-            assert len(s) <= outbufsize
-            outbuf[0:len(s)] = s
-        lib.stmcb_expand_marker = expand_marker
-        self.start_transaction()
-        p = stm_allocate(16)
-        self.push_root(ffi.cast("object_t *", 29))
-        self.push_root(p)
-        self.push_root(stm_allocate(32))
-        self.push_root(stm_allocate(16))
-        raw = lib._stm_expand_marker()
-        assert ffi.string(raw) == '29 %r' % (p,)
-
-    def test_stmcb_debug_print(self):
-        @ffi.callback("void(char *, uintptr_t, object_t *, char *, size_t)")
-        def expand_marker(base, number, ptr, outbuf, outbufsize):
-            s = '<<<%d>>>\x00' % (number,)
-            assert len(s) <= outbufsize
-            outbuf[0:len(s)] = s
-        @ffi.callback("void(char *, double, char *)")
-        def debug_print(cause, time, marker):
-            if 0.0 < time < 1.0:
-                time = "time_ok"
-            seen.append((ffi.string(cause), time, ffi.string(marker)))
-        seen = []
-        lib.stmcb_expand_marker = expand_marker
-        lib.stmcb_debug_print = debug_print
-        #
-        self.start_transaction()
-        p = stm_allocate(16)
-        self.push_root(ffi.cast("object_t *", 29))
-        self.push_root(p)
-        self.abort_transaction()
-        #
-        assert seen == [("run aborted other", "time_ok", "<<<29>>>")]
-
-    def test_multiple_markers(self):
-        @ffi.callback("void(char *, uintptr_t, object_t *, char *, size_t)")
-        def expand_marker(base, number, ptr, outbuf, outbufsize):
-            seen.append(number)
-            s = '%d %r\x00' % (number, ptr == ffi.NULL)
-            assert len(s) <= outbufsize
-            outbuf[0:len(s)] = s
-        seen = []
-        lib.stmcb_expand_marker = expand_marker
-        #
-        self.start_transaction()
-        p = stm_allocate(16)
-        self.push_root(ffi.cast("object_t *", 27))
-        self.push_root(p)
-        self.push_root(ffi.cast("object_t *", 29))
-        self.push_root(ffi.cast("object_t *", ffi.NULL))
-        raw = lib._stm_expand_marker()
-        assert ffi.string(raw) == '29 True'
-        assert seen == [29]
-
     def test_double_abort_markers_cb_write_write(self):
-        @ffi.callback("void(char *, uintptr_t, object_t *, char *, size_t)")
-        def expand_marker(base, number, ptr, outbuf, outbufsize):
-            s = '%d\x00' % (number,)
-            assert len(s) <= outbufsize
-            outbuf[0:len(s)] = s
-        lib.stmcb_expand_marker = expand_marker
+        self.recording(lib.STM_CONTENTION_WRITE_WRITE)
         p = stm_allocate_old(16)
         #
         self.start_transaction()
@@ -200,19 +106,10 @@
         self.push_root(ffi.cast("object_t *", ffi.NULL))
         py.test.raises(Conflict, stm_set_char, p, 'B')
         #
-        tl = self.get_stm_thread_local()
-        assert tl.longest_marker_state == lib.STM_TIME_RUN_ABORTED_WRITE_WRITE
-        assert ffi.string(tl.longest_marker_self) == '21'
-        assert ffi.string(tl.longest_marker_other) == '19'
+        self.check_recording(21, ffi.NULL, 19, ffi.NULL)
 
     def test_double_abort_markers_cb_inevitable(self):
-        @ffi.callback("void(char *, uintptr_t, object_t *, char *, size_t)")
-        def expand_marker(base, number, ptr, outbuf, outbufsize):
-            c = (base + int(ffi.cast("uintptr_t", ptr)))[8]
-            s = '%d %r\x00' % (number, c)
-            assert len(s) <= outbufsize
-            outbuf[0:len(s)] = s
-        lib.stmcb_expand_marker = expand_marker
+        self.recording(lib.STM_CONTENTION_INEVITABLE)
         #
         self.start_transaction()
         p = stm_allocate(16)
@@ -234,18 +131,10 @@
         self.push_root(ffi.cast("object_t *", p))
         py.test.raises(Conflict, self.become_inevitable)
         #
-        tl = self.get_stm_thread_local()
-        assert tl.longest_marker_state == lib.STM_TIME_RUN_ABORTED_INEVITABLE
-        assert ffi.string(tl.longest_marker_self) == "21 'B'"
-        assert ffi.string(tl.longest_marker_other) == "19 'A'"
+        self.check_recording(21, p, 19, p)
 
     def test_read_write_contention(self):
-        @ffi.callback("void(char *, uintptr_t, object_t *, char *, size_t)")
-        def expand_marker(base, number, ptr, outbuf, outbufsize):
-            s = '%d\x00' % (number,)
-            assert len(s) <= outbufsize
-            outbuf[0:len(s)] = s
-        lib.stmcb_expand_marker = expand_marker
+        self.recording(lib.STM_CONTENTION_WRITE_READ)
         p = stm_allocate_old(16)
         #
         self.start_transaction()
@@ -262,19 +151,10 @@
         self.push_root(ffi.cast("object_t *", ffi.NULL))
         py.test.raises(Conflict, self.commit_transaction)
         #
-        tl = self.get_stm_thread_local()
-        assert tl.longest_marker_state == lib.STM_TIME_RUN_ABORTED_WRITE_READ
-        assert ffi.string(tl.longest_marker_self) == '19'
-        assert ffi.string(tl.longest_marker_other) == (
-            '<read at unknown location>')
+        self.check_recording(19, ffi.NULL, 0, ffi.NULL)
 
     def test_double_remote_markers_cb_write_write(self):
-        @ffi.callback("void(char *, uintptr_t, object_t *, char *, size_t)")
-        def expand_marker(base, number, ptr, outbuf, outbufsize):
-            s = '%d\x00' % (number,)
-            assert len(s) <= outbufsize
-            outbuf[0:len(s)] = s
-        lib.stmcb_expand_marker = expand_marker
+        self.recording(lib.STM_CONTENTION_WRITE_WRITE)
         p = stm_allocate_old(16)
         #
         self.start_transaction()
@@ -300,19 +180,10 @@
         #
         py.test.raises(Conflict, self.switch, 0)
         #
-        tl = self.get_stm_thread_local()
-        assert tl is tl0
-        assert tl.longest_marker_state == lib.STM_TIME_RUN_ABORTED_WRITE_WRITE
-        assert ffi.string(tl.longest_marker_self) == '19'
-        assert ffi.string(tl.longest_marker_other) == '21'
+        self.check_recording(21, ffi.NULL, 19, ffi.NULL)
 
     def test_double_remote_markers_cb_write_read(self):
-        @ffi.callback("void(char *, uintptr_t, object_t *, char *, size_t)")
-        def expand_marker(base, number, ptr, outbuf, outbufsize):
-            s = '%d\x00' % (number,)
-            assert len(s) <= outbufsize
-            outbuf[0:len(s)] = s
-        lib.stmcb_expand_marker = expand_marker
+        self.recording(lib.STM_CONTENTION_WRITE_READ)
         p = stm_allocate_old(16)
         #
         self.start_transaction()
@@ -333,8 +204,4 @@
         #
         py.test.raises(Conflict, self.switch, 0)
         #
-        tl = self.get_stm_thread_local()
-        assert tl is tl0
-        assert tl.longest_marker_state == lib.STM_TIME_RUN_ABORTED_WRITE_READ
-        assert ffi.string(tl.longest_marker_self)=='<read at unknown location>'
-        assert ffi.string(tl.longest_marker_other) == '21'
+        self.check_recording(21, ffi.NULL, 0, ffi.NULL)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to