[pypy-commit] stmgc c7: stop_transaction hacking for tests

Raemi noreply at buildbot.pypy.org
Tue Jan 14 16:15:20 CET 2014


Author: Remi Meier <remi.meier at gmail.com>
Branch: c7
Changeset: r608:cb41605afd90
Date: 2014-01-14 16:15 +0100
http://bitbucket.org/pypy/stmgc/changeset/cb41605afd90/

Log:	stop_transaction hacking for tests

diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -463,7 +463,6 @@
 
 void _stm_teardown_thread(void)
 {
-    assert(!_STM_TL2->running_transaction);
     wait_until_updated();
     stm_list_free(_STM_TL2->modified_objects);
     _STM_TL2->modified_objects = NULL;
@@ -538,7 +537,6 @@
 
     wait_until_updated();
     stm_list_clear(_STM_TL2->modified_objects);
-    assert(stm_list_is_empty(_STM_TL2->new_object_ranges));
 
     /* check that there is no stm_abort() in the following maybe_update() */
     _STM_TL1->jmpbufptr = NULL;
@@ -569,8 +567,8 @@
 
 void stm_stop_transaction(void)
 {
+    assert(_STM_TL2->running_transaction);
 #if 0
-    assert(_STM_TL2->running_transaction);
 
     write_fence();   /* see later in this function for why */
 
@@ -662,9 +660,8 @@
             }
         }
     }
-
+#endif
     _STM_TL2->running_transaction = 0;
-#endif
 }
 
 void stm_abort_transaction(void)
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -33,7 +33,7 @@
 void stm_setup_thread(void);
 
 void stm_start_transaction(jmpbufptr_t *);
-void stm_stop_transaction(void);
+bool _stm_stop_transaction(void);
 object_t *stm_allocate(size_t size);
 
 void stm_read(object_t *object);
@@ -54,12 +54,27 @@
 
 lib = ffi.verify('''
 #include <string.h>
+#include <assert.h>
+
 #include "core.h"
 
 size_t stm_object_size_rounded_up(object_t * obj) {
     return 16;
 }
 
+bool _stm_stop_transaction(void) {
+    jmpbufptr_t here;
+    if (__builtin_setjmp(here) == 0) {
+         assert(_STM_TL1->jmpbufptr == (jmpbufptr_t*)-1);
+         _STM_TL1->jmpbufptr = &here;
+         stm_stop_transaction();
+         _STM_TL1->jmpbufptr = (jmpbufptr_t*)-1;
+         return 0;
+    }
+    _STM_TL1->jmpbufptr = (jmpbufptr_t*)-1;
+    return 1;
+}
+
 ''', sources=source_files,
      define_macros=[('STM_TESTS', '1')],
      undef_macros=['NDEBUG'],
@@ -87,14 +102,14 @@
     return lib._stm_was_written(lib._stm_tl_address(ptr))
 
 def stm_start_transaction():
-    lib.stm_start_transaction()
+    lib.stm_start_transaction(ffi.cast("jmpbufptr_t*", -1))
 
-def stm_stop_transaction(expected_conflict):
-    res = lib.stm_stop_transaction()
+def stm_stop_transaction(expected_conflict=False):
+    res = lib._stm_stop_transaction()
     if expected_conflict:
+        assert res == 1
+    else:
         assert res == 0
-    else:
-        assert res == 1
 
 
 class BaseTest(object):
diff --git a/c7/test/test_basic.py b/c7/test/test_basic.py
--- a/c7/test/test_basic.py
+++ b/c7/test/test_basic.py
@@ -23,6 +23,14 @@
         p4 = stm_allocate(16)
         assert p4 - p3 == 16
 
+    def test_simple(self):
+        stm_start_transaction()
+        self.switch(1)
+        stm_start_transaction()
+        stm_stop_transaction()
+        self.switch(0)
+        stm_stop_transaction()
+
     def test_read_write_1(self):
         stm_start_transaction()
         p1 = stm_allocate(16)


More information about the pypy-commit mailing list