diff options
author | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-07 17:49:24 +0200 |
---|---|---|
committer | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-07 19:36:02 +0200 |
commit | c197918681a51a09c70bbac5110fc665b4edb948 (patch) | |
tree | e48117b1f060b4c7912eb41f8a7e22ac91eaf2c4 | |
parent | decaad001cf3eca4e1214327b7339c23dd70e5cc (diff) |
Use do_run_from_file() for test_gc
-rw-r--r-- | tests/core/test_gc.in | 107 | ||||
-rw-r--r-- | tests/core/test_gc.out | 18 | ||||
-rw-r--r-- | tests/test_core.py | 128 |
3 files changed, 128 insertions, 125 deletions
diff --git a/tests/core/test_gc.in b/tests/core/test_gc.in new file mode 100644 index 00000000..ae94b0ec --- /dev/null +++ b/tests/core/test_gc.in @@ -0,0 +1,107 @@ + + #include <stdio.h> + #include <gc.h> + #include <assert.h> + + void *global; + + void finalizer(void *ptr, void *arg) { + printf("finalizing %d (global == %d)\n", (int)arg, ptr == global); + } + + void finalizer2(void *ptr, void *arg) { + printf("finalizing2 %d (global == %d)\n", (int)arg, ptr == global); + } + + int main() { + GC_INIT(); + + void *local, *local2, *local3, *local4, *local5, *local6; + + // Hold on to global, drop locals + + global = GC_MALLOC(1024); // rooted since in a static allocation + GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0); + printf("alloc %p\n", global); + + local = GC_MALLOC(1024); // not rooted since stack is not scanned + GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void*)1, 0, 0); + printf("alloc %p\n", local); + + assert((char*)local - (char*)global >= 1024 || (char*)global - (char*)local >= 1024); + + local2 = GC_MALLOC(1024); // no finalizer + printf("alloc %p\n", local2); + + local3 = GC_MALLOC(1024); // with finalizable2 + GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer2, (void*)2, 0, 0); + printf("alloc %p\n", local); + + local4 = GC_MALLOC(1024); // yet another + GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer2, (void*)3, 0, 0); + printf("alloc %p\n", local); + + printf("basic test\n"); + + GC_FORCE_COLLECT(); + + printf("*\n"); + + GC_FREE(global); // force free will actually work + + // scanning inside objects + + global = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0); + local = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void*)1, 0, 0); + local2 = GC_MALLOC_ATOMIC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local2, finalizer, (void*)2, 0, 0); + local3 = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer, (void*)3, 0, 0); + local4 = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer, (void*)4, 0, 0); + local5 = GC_MALLOC_UNCOLLECTABLE(12); + // This should never trigger since local5 is uncollectable + GC_REGISTER_FINALIZER_NO_ORDER(local5, finalizer, (void*)5, 0, 0); + + printf("heap size = %d\n", GC_get_heap_size()); + + local4 = GC_REALLOC(local4, 24); + + printf("heap size = %d\n", GC_get_heap_size()); + + local6 = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local6, finalizer, (void*)6, 0, 0); + // This should be the same as a free + GC_REALLOC(local6, 0); + + void **globalData = (void**)global; + globalData[0] = local; + globalData[1] = local2; + + void **localData = (void**)local; + localData[0] = local3; + + void **local2Data = (void**)local2; + local2Data[0] = local4; // actually ignored, because local2 is atomic, so 4 is freeable + + printf("object scan test test\n"); + + GC_FORCE_COLLECT(); + + printf("*\n"); + + GC_FREE(global); // force free will actually work + + printf("*\n"); + + GC_FORCE_COLLECT(); + + printf(".\n"); + + global = 0; + + return 0; + } +
\ No newline at end of file diff --git a/tests/core/test_gc.out b/tests/core/test_gc.out new file mode 100644 index 00000000..6ce8bff9 --- /dev/null +++ b/tests/core/test_gc.out @@ -0,0 +1,18 @@ +basic test +finalizing 1 (global == 0) +finalizing2 2 (global == 0) +finalizing2 3 (global == 0) +* +finalizing 0 (global == 1) +heap size = 72 +heap size = 84 +finalizing 6 (global == 0) +object scan test test +finalizing 4 (global == 0) +* +finalizing 0 (global == 1) +* +finalizing 1 (global == 0) +finalizing 2 (global == 0) +finalizing 3 (global == 0) +. diff --git a/tests/test_core.py b/tests/test_core.py index 1dc26eb8..f8b077b7 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -6203,132 +6203,10 @@ def process(filename): Settings.GC_SUPPORT = 1 - src = r''' - #include <stdio.h> - #include <gc.h> - #include <assert.h> - - void *global; - - void finalizer(void *ptr, void *arg) { - printf("finalizing %d (global == %d)\n", (int)arg, ptr == global); - } - - void finalizer2(void *ptr, void *arg) { - printf("finalizing2 %d (global == %d)\n", (int)arg, ptr == global); - } - - int main() { - GC_INIT(); - - void *local, *local2, *local3, *local4, *local5, *local6; - - // Hold on to global, drop locals - - global = GC_MALLOC(1024); // rooted since in a static allocation - GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0); - printf("alloc %p\n", global); - - local = GC_MALLOC(1024); // not rooted since stack is not scanned - GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void*)1, 0, 0); - printf("alloc %p\n", local); - - assert((char*)local - (char*)global >= 1024 || (char*)global - (char*)local >= 1024); - - local2 = GC_MALLOC(1024); // no finalizer - printf("alloc %p\n", local2); - - local3 = GC_MALLOC(1024); // with finalizable2 - GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer2, (void*)2, 0, 0); - printf("alloc %p\n", local); - - local4 = GC_MALLOC(1024); // yet another - GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer2, (void*)3, 0, 0); - printf("alloc %p\n", local); - - printf("basic test\n"); - - GC_FORCE_COLLECT(); - - printf("*\n"); - - GC_FREE(global); // force free will actually work - - // scanning inside objects - - global = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0); - local = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void*)1, 0, 0); - local2 = GC_MALLOC_ATOMIC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local2, finalizer, (void*)2, 0, 0); - local3 = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer, (void*)3, 0, 0); - local4 = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer, (void*)4, 0, 0); - local5 = GC_MALLOC_UNCOLLECTABLE(12); - // This should never trigger since local5 is uncollectable - GC_REGISTER_FINALIZER_NO_ORDER(local5, finalizer, (void*)5, 0, 0); - - printf("heap size = %d\n", GC_get_heap_size()); - - local4 = GC_REALLOC(local4, 24); - - printf("heap size = %d\n", GC_get_heap_size()); - - local6 = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local6, finalizer, (void*)6, 0, 0); - // This should be the same as a free - GC_REALLOC(local6, 0); - - void **globalData = (void**)global; - globalData[0] = local; - globalData[1] = local2; - - void **localData = (void**)local; - localData[0] = local3; - - void **local2Data = (void**)local2; - local2Data[0] = local4; // actually ignored, because local2 is atomic, so 4 is freeable - - printf("object scan test test\n"); - - GC_FORCE_COLLECT(); - - printf("*\n"); - - GC_FREE(global); // force free will actually work - - printf("*\n"); - - GC_FORCE_COLLECT(); - - printf(".\n"); - - global = 0; + test_path = path_from_root('tests', 'core', 'test_gc') + src, output = (test_path + s for s in ('.in', '.out')) - return 0; - } - ''' - self.do_run(src, '''basic test -finalizing 1 (global == 0) -finalizing2 2 (global == 0) -finalizing2 3 (global == 0) -* -finalizing 0 (global == 1) -heap size = 72 -heap size = 84 -finalizing 6 (global == 0) -object scan test test -finalizing 4 (global == 0) -* -finalizing 0 (global == 1) -* -finalizing 1 (global == 0) -finalizing 2 (global == 0) -finalizing 3 (global == 0) -. -''') + self.do_run_from_file(src, output) # Generate tests for everything def make_run(fullname, name=-1, compiler=-1, embetter=0, quantum_size=0, |