diff options
Diffstat (limited to 'tests/runner.py')
-rw-r--r-- | tests/runner.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py index a931ced9..d523dbba 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -751,6 +751,71 @@ if 'benchmark' not in sys.argv: ''' self.do_test(src, '*4096,4096,8192,69632*') + def test_pystruct(self): + if COMPILER != LLVM_GCC: return # TODO: Clang here + if F_OPTS: return # TODO: fix + src = ''' + #include <stdio.h> + + // Based on CPython code + union PyGC_Head { + struct { + union PyGC_Head *gc_next; + union PyGC_Head *gc_prev; + size_t gc_refs; + } gc; + long double dummy; /* force worst-case alignment */ + } ; + + struct gc_generation { + PyGC_Head head; + int threshold; /* collection threshold */ + int count; /* count of allocations or collections of younger + generations */ + }; + + #define NUM_GENERATIONS 3 + #define GEN_HEAD(n) (&generations[n].head) + + /* linked lists of container objects */ + static struct gc_generation generations[NUM_GENERATIONS] = { + /* PyGC_Head, threshold, count */ + {{{GEN_HEAD(0), GEN_HEAD(0), 0}}, 700, 0}, + {{{GEN_HEAD(1), GEN_HEAD(1), 0}}, 10, 0}, + {{{GEN_HEAD(2), GEN_HEAD(2), 0}}, 10, 0}, + }; + + int main() + { + gc_generation *n = NULL; + printf("*%d,%d,%d,%d,%d,%d,%d,%d*\\n", + (int)(&n[0]), + (int)(&n[0].head), + (int)(&n[0].head.gc.gc_next), + (int)(&n[0].head.gc.gc_prev), + (int)(&n[0].head.gc.gc_refs), + (int)(&n[0].threshold), (int)(&n[0].count), (int)(&n[1]) + ); + printf("*%d,%d,%d*\\n", + (int)(&generations[0]) == + (int)(&generations[0].head.gc.gc_next), + (int)(&generations[0]) == + (int)(&generations[0].head.gc.gc_prev), + (int)(&generations[0]) == + (int)(&generations[1]) + ); + int x1 = (int)(&generations[0]); + int x2 = (int)(&generations[1]); + printf("*%d*\\n", x1 == x2); + for (int i = 0; i < NUM_GENERATIONS; i++) { + PyGC_Head *list = GEN_HEAD(i); + printf("%d:%d,%d\\n", i, (int)list == (int)(list->gc.gc_prev), (int)list ==(int)(list->gc.gc_next)); + } + printf("*%d*\\n", int(GEN_HEAD(2)) - int(GEN_HEAD(1))); + } + ''' + self.do_test(src, '*0,0,0,4,8,12,16,20*\n*1,0,0*\n*0*\n0:1,1\n1:1,1\n2:1,1\n*20*') + def test_ptrtoint(self): src = ''' #include <stdio.h> |