Author: Armin Rigo <[email protected]>
Branch: c5
Changeset: r575:aa88fa9f2d50
Date: 2013-12-20 14:20 +0100
http://bitbucket.org/pypy/stmgc/changeset/aa88fa9f2d50/

Log:    Tweak the tests

diff --git a/c5/largemalloc.c b/c5/largemalloc.c
--- a/c5/largemalloc.c
+++ b/c5/largemalloc.c
@@ -77,6 +77,11 @@
    decreasing order (if you start from 'd.next').  At the end of this
    list are some unsorted chunks.  All unsorted chunks are after all
    sorted chunks.  The flag 'FLAG_SORTED' distinguishes them.
+
+   Note that if the user always calls stm_large_malloc() with a large
+   enough argument, then the few bins corresponding to smaller values
+   will never be sorted at all.  They are still populated with the
+   fragments of space between bigger allocations.
 */
 
 static dlist_t largebins[N_BINS] = {
@@ -101,6 +106,13 @@
     INIT(80), INIT(81), INIT(82), INIT(83) };
 #undef INIT
 
+void _stm_large_reset(void)
+{
+    int i;
+    for (i = 0; i < N_BINS; i++)
+        largebins[i].prev = largebins[i].next = &largebins[i];
+}
+
 
 static char *allocate_more(size_t request_size);
 
diff --git a/c5/largemalloc.h b/c5/largemalloc.h
--- a/c5/largemalloc.h
+++ b/c5/largemalloc.h
@@ -3,3 +3,4 @@
 char *stm_large_malloc(size_t request_size);
 void stm_large_free(char *data);
 void _stm_large_dump(char *data);
+void _stm_large_reset(void);
diff --git a/c5/test/support.py b/c5/test/support.py
--- a/c5/test/support.py
+++ b/c5/test/support.py
@@ -45,6 +45,7 @@
 char *stm_large_malloc(size_t request_size);
 void stm_large_free(char *data);
 void _stm_large_dump(char *data);
+void _stm_large_reset(void);
 
 void *memset(void *s, int c, size_t n);
 """)
diff --git a/c5/test/test_largemalloc.py b/c5/test/test_largemalloc.py
--- a/c5/test/test_largemalloc.py
+++ b/c5/test/test_largemalloc.py
@@ -4,6 +4,9 @@
 
 class TestLargeMalloc(object):
 
+    def setup_method(self, meth):
+        lib._stm_large_reset()
+
     def test_simple(self):
         d1 = lib.stm_large_malloc(7000)
         d2 = lib.stm_large_malloc(8000)
@@ -32,7 +35,8 @@
         assert d8 == d4
 
     def test_random(self):
-        r = random.Random(1005)
+        r = random.Random(1007)
+        first = None
         p = []
         for i in range(100000):
             if len(p) != 0 and (len(p) > 100 or r.randrange(0, 5) < 2):
@@ -46,9 +50,12 @@
                 sz = r.randrange(8, 160) * 8
                 d = lib.stm_large_malloc(sz)
                 print 'alloc %5d  (%s)' % (sz, d)
+                if first is None:
+                    first = d
                 lib.memset(d, 0xdd, sz)
                 content1 = chr(r.randrange(0, 256))
                 content2 = chr(r.randrange(0, 256))
                 d[0] = content1
                 d[sz - 1] = content2
                 p.append((d, sz, content1, content2))
+        lib._stm_large_dump(first)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to