Permalink
Browse files

Test allocating a large cons chain.

  • Loading branch information...
1 parent 488bb98 commit c852994fe8c2ccd11df50b6d796832e8d7844b57 @nelhage committed Dec 30, 2008
Showing with 27 additions and 0 deletions.
  1. +27 −0 tests.c
View
27 tests.c
@@ -111,11 +111,15 @@ START_TEST(gc_basic_vector)
{
int i;
reg1 = sc_alloc_vector(10);
+ fail_unless(sc_vectorp(reg1));
+
for(i = 0; i < 10; i++) {
sc_vector_set(reg1, i, sc_alloc_cons());
sc_set_car(sc_vector_ref(reg1, i), sc_make_number(i));
}
gc_gc();
+
+ fail_unless(sc_vectorp(reg1));
for(i = 0; i < 10; i++) {
fail_unless(sc_consp(sc_vector_ref(reg1, i)));
fail_unless(sc_number(sc_car(sc_vector_ref(reg1, i))) == i);
@@ -138,6 +142,28 @@ START_TEST(gc_large_allocs)
}
END_TEST
+START_TEST(gc_many_allocs)
+{
+ int i;
+ reg2 = reg1 = sc_alloc_cons();
+ for(i = 0; i < 2000; i++) {
+ sc_set_car(reg2, sc_make_number(i));
+ sc_set_cdr(reg2, sc_alloc_cons());
+ reg2 = sc_cdr(reg2);
+ }
+
+ gc_gc();
+
+ reg2 = reg1;
+ for(i = 0; i < 2000; i++) {
+ fail_unless(sc_consp(reg2));
+ fail_unless(sc_numberp(sc_car(reg2)));
+ fail_unless(sc_number(sc_car(reg2)) == i);
+ reg2 = sc_cdr(reg2);
+ }
+}
+END_TEST
+
gc_handle external_root;
void gc_reloc_external() {
gc_relocate(&external_root);
@@ -248,6 +274,7 @@ Suite *gc_suite()
tcase_add_test(tc_core, gc_cons_cycle);
tcase_add_test(tc_core, gc_basic_vector);
tcase_add_test(tc_core, gc_large_allocs);
+ tcase_add_test(tc_core, gc_many_allocs);
tcase_add_test(tc_core, gc_root_hook);
tcase_add_test(tc_core, gc_roots);
tcase_add_test(tc_core, gc_live_roots);

0 comments on commit c852994

Please sign in to comment.