You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
253 lines
6.7 KiB
253 lines
6.7 KiB
/* |
|
* DO NOT EDIT THIS FILE. Generated by checkmk. |
|
* Edit the original source file "memoryory-test.check" instead. |
|
*/ |
|
|
|
#include "ptlisp-test.h" |
|
#include "../src/lisp.h" |
|
|
|
|
|
START_TEST(memory_alloc_test) { |
|
memory_init(128); |
|
|
|
Pointer ptr; |
|
Pointer a, b; |
|
/*SIMPLES ALLOCS*/ |
|
ptr = memory_new(SYMBOL, sizeof(Symbol) + 4); |
|
ck_assert_uint_eq(ptr, 0); |
|
ck_assert_uint_eq(TYPE(ptr), SYMBOL); |
|
ck_assert_uint_eq(SIZE(ptr), 2); |
|
/* ck_assert_uint_eq(MEMORY.freelist, 2); */ |
|
ck_assert_uint_eq(NEXT(2), -1u); |
|
ck_assert_uint_eq(SIZE(2), 128 - 2); |
|
|
|
a = memory_new(STRING, sizeof(Symbol) + 10); |
|
ck_assert_uint_eq(a, 2); |
|
ck_assert(TYPE(a) == STRING); |
|
ck_assert_uint_eq(SIZE(a), 4); |
|
|
|
ptr = memory_new(STRING, sizeof(String) + 37); |
|
ck_assert_uint_eq(ptr, 6); |
|
ck_assert_uint_eq(SIZE(ptr), 8); |
|
|
|
memory_destroy(a); |
|
/* ck_assert_uint_eq(MEMORY.freelist, a); */ |
|
ptr = memory_new(TABLE, sizeof(Table)); |
|
ck_assert_uint_eq(ptr, a); |
|
ck_assert(TYPE(ptr) == TABLE); |
|
|
|
ptr = memory_new(ARRAY, sizeof(Array) + 1024); |
|
ck_assert_uint_eq(ptr, 14); |
|
ck_assert_uint_eq(TYPE(ptr), ARRAY); |
|
ck_assert_uint_eq(SIZE(ptr), 256); |
|
/* ck_assert_uint_eq(MEMORY.size, 512); */ |
|
/* ck_assert_uint_eq(MEMORY.freelist, 14 + 256); */ |
|
|
|
memory_new(SYMBOL, 1); |
|
a = memory_new(SYMBOL, 1); |
|
memory_new(SYMBOL, 1); |
|
b = memory_new(SYMBOL, 1); |
|
memory_new(SYMBOL, 1); |
|
|
|
memory_destroy(a); |
|
/* ck_assert_uint_eq(MEMORY.freelist, a); */ |
|
memory_destroy(b); |
|
/* ck_assert_uint_eq(MEMORY.freelist, b); */ |
|
ck_assert_uint_eq(NEXT(b), a); |
|
b = a; |
|
a = memory_new(SYMBOL, 1); |
|
/* ck_assert_uint_eq(MEMORY.freelist, b); */ |
|
|
|
memory_free(); |
|
} |
|
END_TEST |
|
|
|
START_TEST(memory_basic_free_test) { |
|
memory_init(1024); |
|
Pointer ptr = memory_new(SYMBOL, 1); |
|
memory_destroy(ptr); |
|
/* ck_assert_uint_eq(MEMORY.freelist, ptr); */ |
|
ck_assert_uint_eq(NEXT(ptr), -1u); |
|
memory_free(); |
|
} |
|
END_TEST |
|
|
|
START_TEST(memory_basic2_free_test) { |
|
memory_init(1024); |
|
Pointer a, b; |
|
a = memory_new(SYMBOL, 1); |
|
b = memory_new(SYMBOL, 1); |
|
memory_destroy(b); |
|
/* ck_assert_uint_eq(MEMORY.freelist, b); */ |
|
ck_assert_uint_eq(NEXT(b), -1u); |
|
memory_free(); |
|
} |
|
END_TEST |
|
|
|
START_TEST(memory_basic3_free_test) { |
|
memory_init(1024); |
|
Pointer a, b; |
|
a = memory_new(SYMBOL, 1); |
|
b = memory_new(SYMBOL, 1); |
|
memory_destroy(a); |
|
/* ck_assert_uint_eq(MEMORY.freelist, a); */ |
|
ck_assert_uint_eq(NEXT(a), b + 2); |
|
memory_free(); |
|
} |
|
END_TEST |
|
|
|
START_TEST(memory_basic4_free_test) { |
|
memory_init(1024); |
|
Pointer a, b; |
|
a = memory_new(SYMBOL, 1); |
|
b = memory_new(SYMBOL, 1); |
|
memory_destroy(a); |
|
/* ck_assert_uint_eq(MEMORY.freelist, a); */ |
|
memory_destroy(b); |
|
/* ck_assert_uint_eq(MEMORY.freelist, a); */ |
|
ck_assert_uint_eq(NEXT(a), b + 2); |
|
ck_assert_uint_eq(NEXT(b + 2), -1u); |
|
memory_free(); |
|
} |
|
END_TEST |
|
|
|
START_TEST(memory_free_merging_test) { |
|
memory_init(1024); |
|
Pointer a, b, c, d, e; |
|
a = memory_new(SYMBOL, 1); // 0 |
|
b = memory_new(SYMBOL, 1); // 1 |
|
c = memory_new(SYMBOL, 1); // 2 |
|
d = memory_new(SYMBOL, 1); // 3 |
|
e = memory_new(SYMBOL, 1); // 4 |
|
(void) a; |
|
memory_destroy(b); // fl => b => -1u |
|
/* ck_assert_uint_eq(MEMORY.freelist, b); */ |
|
memory_destroy(d); // fl => d => b => -1u |
|
/* ck_assert_uint_eq(MEMORY.freelist, d); */ |
|
memory_destroy(c); // fl => b => -1u |
|
/* ck_assert_uint_eq(MEMORY.freelist, b); */ |
|
ck_assert_uint_eq(NEXT(b), e + 2); |
|
memory_free(); |
|
} |
|
END_TEST |
|
|
|
START_TEST(memory_free_merging2_test) { |
|
memory_init(1024); |
|
Pointer a, b, c, d, e; |
|
a = memory_new(SYMBOL, 1); // 0 |
|
b = memory_new(SYMBOL, 1); // 1 |
|
c = memory_new(SYMBOL, 1); // 2 |
|
d = memory_new(SYMBOL, 1); // 3 |
|
e = memory_new(SYMBOL, 1); // 4 |
|
memory_destroy(b); // fl => b => -1u |
|
memory_destroy(c); // fl => b => -1u |
|
/* ck_assert_uint_eq(MEMORY.freelist, b); */ |
|
ck_assert_uint_eq(NEXT(b), e + 2); |
|
memory_free(); |
|
} |
|
END_TEST |
|
|
|
START_TEST(memory_free_merging3_test) { |
|
memory_init(1024); |
|
Pointer a, b, c, d, e; |
|
a = memory_new(SYMBOL, 1); // 0 |
|
b = memory_new(SYMBOL, 1); // 1 |
|
c = memory_new(SYMBOL, 1); // 2 |
|
d = memory_new(SYMBOL, 1); // 3 |
|
e = memory_new(SYMBOL, 1); // 4 |
|
memory_destroy(c); // fl => b => -1u |
|
memory_destroy(b); // fl => b => -1u |
|
/* ck_assert_uint_eq(MEMORY.freelist, b); */ |
|
ck_assert_uint_eq(NEXT(b), e + 2); |
|
memory_free(); |
|
} |
|
END_TEST |
|
|
|
START_TEST(memory_realloc_test) { |
|
memory_init(16); |
|
Pointer a, b; |
|
a = memory_new(SYMBOL, 1); // 0 |
|
b = memory_resize(a, 1); |
|
ck_assert_uint_eq(a, b); |
|
ck_assert_uint_eq(SIZE(a), 2); |
|
memory_free(); |
|
} |
|
END_TEST |
|
|
|
START_TEST(memory_realloc_shrink_test) { |
|
memory_init(16 * 1); |
|
Pointer a, b; |
|
a = memory_new(SYMBOL, sizeof(Symbol) + 12); // 0 |
|
b = memory_resize(a, sizeof(Symbol)); |
|
ck_assert_uint_eq(a, b); |
|
ck_assert_uint_eq(SIZE(a), 2); |
|
/* ck_assert_uint_eq(MEMORY.freelist, 2); */ |
|
memory_free(); |
|
} |
|
END_TEST |
|
|
|
START_TEST(memory_realloc_free_slot_test) { |
|
memory_init(16); |
|
Pointer a, b, c; |
|
a = memory_new(SYMBOL, sizeof(Symbol) + 8); // 0 |
|
b = memory_new(SYMBOL, sizeof(Symbol) + 1); |
|
memory_destroy(b); |
|
/* ck_assert_uint_eq(MEMORY.freelist, b); */ |
|
ck_assert_uint_eq(SIZE(b), 12); |
|
c = memory_resize(a, sizeof(Symbol) + 16); |
|
ck_assert_uint_eq(a, c); |
|
ck_assert_uint_eq(SIZE(a), 4); |
|
/* ck_assert_uint_eq(MEMORY.freelist, b); */ |
|
memory_free(); |
|
} |
|
END_TEST |
|
|
|
START_TEST(memory_realloc_free_big_slot_test) { |
|
memory_init(16 * 1); |
|
Pointer a, b, c; |
|
a = memory_new(SYMBOL, 8); // 0 |
|
b = memory_new(SYMBOL, 24); |
|
memory_destroy(b); |
|
/* ck_assert_uint_eq(MEMORY.freelist, b); */ |
|
c = memory_resize(a, 16); |
|
ck_assert_uint_eq(a, c); |
|
ck_assert_uint_eq(memory_get(a)->size, 4); |
|
/* ck_assert_uint_eq(MEMORY.freelist, 4); */ |
|
memory_free(); |
|
} |
|
END_TEST |
|
|
|
START_TEST(memory_realloc_relocate_test) { |
|
memory_init(16 * 1); |
|
Pointer a, b, c; |
|
a = memory_new(SYMBOL, 8); // 0 |
|
b = memory_new(SYMBOL, 8); // 1 |
|
/* ck_assert_uint_eq(MEMORY.freelist, 4); */ |
|
ck_assert_uint_eq(SIZE(4), 12); |
|
ck_assert_uint_eq(NEXT(4), -1u); |
|
c = memory_resize(a, 16); |
|
memory_free(); |
|
} |
|
END_TEST |
|
|
|
Suite* make_memory_test_suite(void) { |
|
Suite *s1 = suite_create("Memory"); |
|
TCase *tc1_1 = tcase_create("Memory"); |
|
|
|
suite_add_tcase(s1, tc1_1); |
|
tcase_add_test(tc1_1, memory_alloc_test); |
|
tcase_add_test(tc1_1, memory_basic_free_test); |
|
tcase_add_test(tc1_1, memory_basic2_free_test); |
|
tcase_add_test(tc1_1, memory_basic3_free_test); |
|
tcase_add_test(tc1_1, memory_basic4_free_test); |
|
tcase_add_test(tc1_1, memory_free_merging_test); |
|
tcase_add_test(tc1_1, memory_free_merging2_test); |
|
tcase_add_test(tc1_1, memory_free_merging3_test); |
|
tcase_add_test(tc1_1, memory_realloc_test); |
|
tcase_add_test(tc1_1, memory_realloc_shrink_test); |
|
tcase_add_test(tc1_1, memory_realloc_free_slot_test); |
|
tcase_add_test(tc1_1, memory_realloc_free_big_slot_test); |
|
tcase_add_test(tc1_1, memory_realloc_relocate_test); |
|
|
|
return s1; |
|
}
|
|
|