aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2020-11-24 13:51:05 -0700
committerJosh Rahm <joshuarahm@gmail.com>2020-11-24 13:51:05 -0700
commit6a1e0acc14b62c00317ac61c6ad6d8ffe441be4f (patch)
tree6ba55838c79cc9f6ef0aefa682f65d87ba575270 /tests
parent93b063fedfcf7409a67df035170ea5670cad22e1 (diff)
downloadstm32l4-6a1e0acc14b62c00317ac61c6ad6d8ffe441be4f.tar.gz
stm32l4-6a1e0acc14b62c00317ac61c6ad6d8ffe441be4f.tar.bz2
stm32l4-6a1e0acc14b62c00317ac61c6ad6d8ffe441be4f.zip
rename halloc to kalloc
Diffstat (limited to 'tests')
-rw-r--r--tests/test_memory.c138
1 files changed, 69 insertions, 69 deletions
diff --git a/tests/test_memory.c b/tests/test_memory.c
index 04e9289..6e523aa 100644
--- a/tests/test_memory.c
+++ b/tests/test_memory.c
@@ -18,11 +18,11 @@ struct TEST_STRUCT2 {
};
/* Copy of the node structure. */
-typedef struct HALLOC_NODE {
+typedef struct KALLOC_NODE {
union {
uint32_t header;
struct {
- /* Is this memory block currently in use (hasn't been hfree'd) */
+ /* Is this memory block currently in use (hasn't been kfree'd) */
bool used:1;
/* Number of words allocated. Does not include the header. */
uint16_t size:12;
@@ -33,20 +33,20 @@ typedef struct HALLOC_NODE {
};
uint8_t mem[]; /* The memory to use. */
-} halloc_node_t;
+} kalloc_node_t;
-extern halloc_node_t* halloc_start;
+extern kalloc_node_t* kalloc_start;
-static void wipeout_halloc()
+static void wipeout_kalloc()
{
- memset(halloc_start, 0, 1024);
- halloc_start = NULL;
+ memset(kalloc_start, 0, 1024);
+ kalloc_start = NULL;
}
static struct TEST_STRUCT* new_test_struct()
{
- struct TEST_STRUCT* ret = halloc(sizeof(struct TEST_STRUCT));
+ struct TEST_STRUCT* ret = kalloc(sizeof(struct TEST_STRUCT));
ret->array[0] = 1;
ret->array[1] = 2;
@@ -57,7 +57,7 @@ static struct TEST_STRUCT* new_test_struct()
static struct TEST_STRUCT2* new_test_struct2()
{
- struct TEST_STRUCT2* ret = halloc(sizeof(struct TEST_STRUCT2));
+ struct TEST_STRUCT2* ret = kalloc(sizeof(struct TEST_STRUCT2));
for (int i = 0; i < 10; ++ i) {
ret->array[i] = i;
@@ -69,7 +69,7 @@ static struct TEST_STRUCT2* new_test_struct2()
#define ASSERT_CHAIN(t1, t2) \
ASSERT_EQ(V(t1) + sizeof(*t1) + 4, V(t2))
-TEST(memory, halloc)
+TEST(memory, kalloc)
{
#define V(x) ((void*)(x))
@@ -92,7 +92,7 @@ TEST(memory, halloc)
char buf[1024];
- if (debug_halloc_assert_consistency(buf, 1024)) {
+ if (debug_kalloc_assert_consistency(buf, 1024)) {
fprintf(
stderr,
"Consistency check failed. (%s:%d)\n",
@@ -102,7 +102,7 @@ TEST(memory, halloc)
ASSERT_TRUE(false);
}
- wipeout_halloc();
+ wipeout_kalloc();
return 0;
}
@@ -113,7 +113,7 @@ struct UNEVEN_STRUCT {
struct UNEVEN_STRUCT* new_uneven_struct()
{
- struct UNEVEN_STRUCT* ret = halloc(sizeof(struct UNEVEN_STRUCT));
+ struct UNEVEN_STRUCT* ret = kalloc(sizeof(struct UNEVEN_STRUCT));
ret->arr[0] = 1;
ret->arr[1] = 2;
@@ -127,10 +127,10 @@ struct UNEVEN_STRUCT* new_uneven_struct()
#define size_for(n) \
(((n) / 4) + ((n) % 4 != 0))
-TEST(memory, uneven_halloc)
+TEST(memory, uneven_kalloc)
{
- if (halloc_start) {
- wipeout_halloc();
+ if (kalloc_start) {
+ wipeout_kalloc();
}
struct UNEVEN_STRUCT* test1 = new_uneven_struct();
@@ -138,15 +138,15 @@ TEST(memory, uneven_halloc)
ASSERT_EQ(V(test1) + 12, test2);
- wipeout_halloc();
+ wipeout_kalloc();
return 0;
}
-TEST(memory, halloc_free)
+TEST(memory, kalloc_free)
{
- if (halloc_start) {
- wipeout_halloc();
+ if (kalloc_start) {
+ wipeout_kalloc();
}
struct TEST_STRUCT* test1 = new_test_struct();
@@ -155,13 +155,13 @@ TEST(memory, halloc_free)
struct TEST_STRUCT2* test4 = new_test_struct2();
struct TEST_STRUCT2* test5 = new_test_struct2();
- hfree(test2);
- hfree(test4);
- hfree(test3);
- hfree(test1);
- hfree(test5);
+ kfree(test2);
+ kfree(test4);
+ kfree(test3);
+ kfree(test1);
+ kfree(test5);
- ASSERT_EQ((int) halloc_start->size * 4, MAX_HEAP_SIZE - 4);
+ ASSERT_EQ((int) kalloc_start->size * 4, MAX_HEAP_SIZE - 4);
test1 = new_test_struct();
test2 = new_test_struct2();
@@ -169,13 +169,13 @@ TEST(memory, halloc_free)
test4 = new_test_struct2();
test5 = new_test_struct2();
- hfree(test1);
- hfree(test3);
- hfree(test2);
- hfree(test4);
- hfree(test5);
+ kfree(test1);
+ kfree(test3);
+ kfree(test2);
+ kfree(test4);
+ kfree(test5);
- ASSERT_EQ((int) halloc_start->size * 4, MAX_HEAP_SIZE - 4);
+ ASSERT_EQ((int) kalloc_start->size * 4, MAX_HEAP_SIZE - 4);
test1 = new_test_struct();
test2 = new_test_struct2();
@@ -183,47 +183,47 @@ TEST(memory, halloc_free)
test4 = new_test_struct2();
test5 = new_test_struct2();
- hfree(test4);
- hfree(test3);
- hfree(test1);
- hfree(test2);
- hfree(test5);
+ kfree(test4);
+ kfree(test3);
+ kfree(test1);
+ kfree(test2);
+ kfree(test5);
- ASSERT_EQ((int) halloc_start->size * 4, MAX_HEAP_SIZE - 4);
+ ASSERT_EQ((int) kalloc_start->size * 4, MAX_HEAP_SIZE - 4);
- wipeout_halloc();
+ wipeout_kalloc();
return 0;
}
-TEST(memory, halloc_free_alloc2)
+TEST(memory, kalloc_free_alloc2)
{
- if (halloc_start) {
- wipeout_halloc();
+ if (kalloc_start) {
+ wipeout_kalloc();
}
struct TEST_STRUCT2* test1 = new_test_struct2();
struct TEST_STRUCT2* test2 = new_test_struct2();
- hfree(test1);
+ kfree(test1);
struct TEST_STRUCT* test3 = new_test_struct();
struct TEST_STRUCT* test4 = new_test_struct();
- ASSERT_EQ(debug_halloc_get_next_ptr(test3), V(test4));
+ ASSERT_EQ(debug_kalloc_get_next_ptr(test3), V(test4));
ASSERT_EQ(
// There should be a free block after test4.
- debug_halloc_get_next_ptr(debug_halloc_get_next_ptr(test4)),
+ debug_kalloc_get_next_ptr(debug_kalloc_get_next_ptr(test4)),
V(test2));
ASSERT_EQ(
// There should be a free block after test4.
- debug_halloc_get_prev_ptr(debug_halloc_get_prev_ptr(test2)),
+ debug_kalloc_get_prev_ptr(debug_kalloc_get_prev_ptr(test2)),
V(test4));
char buf[1024];
- if (debug_halloc_assert_consistency(buf, 1024)) {
+ if (debug_kalloc_assert_consistency(buf, 1024)) {
fprintf(stderr, "Consistency check failed.\n");
fprintf(stderr, buf);
ASSERT_TRUE(false);
@@ -234,18 +234,18 @@ TEST(memory, halloc_free_alloc2)
TEST(memory, relink_backref_after_free)
{
- if (halloc_start) {
- wipeout_halloc();
+ if (kalloc_start) {
+ wipeout_kalloc();
}
struct TEST_STRUCT* test2 = new_test_struct();
struct TEST_STRUCT* test3 = new_test_struct();
- hfree(test2);
- hfree(test3);
+ kfree(test2);
+ kfree(test3);
char buf[1024];
- if (debug_halloc_assert_consistency(buf, 1024)) {
+ if (debug_kalloc_assert_consistency(buf, 1024)) {
fprintf(stderr, "Consistency check failed.\n");
fprintf(stderr, buf);
ASSERT_TRUE(false);
@@ -257,8 +257,8 @@ TEST(memory, relink_backref_after_free)
TEST(memory, consistency_stress)
{
#define NRUNS 500
- if (halloc_start) {
- wipeout_halloc();
+ if (kalloc_start) {
+ wipeout_kalloc();
}
int i;
@@ -267,9 +267,9 @@ TEST(memory, consistency_stress)
for (i = 0; i < NRUNS; ++ i) {
size_t nalloc = rand() % 20;
- allocd[i] = halloc(nalloc);
+ allocd[i] = kalloc(nalloc);
- if (debug_halloc_assert_consistency(buf, 1024)) {
+ if (debug_kalloc_assert_consistency(buf, 1024)) {
fprintf(
stderr,
"Consistency check failed. (At index=%d, %s:%d)\n",
@@ -285,7 +285,7 @@ TEST(memory, consistency_stress)
memset(allocd[i], 0xFF, nalloc);
size_t idx = rand() % NRUNS;
- if (debug_halloc_assert_consistency(buf, 1024)) {
+ if (debug_kalloc_assert_consistency(buf, 1024)) {
fprintf(
stderr,
"Consistency check failed. (At index=%d, %s:%d)\n",
@@ -296,10 +296,10 @@ TEST(memory, consistency_stress)
ASSERT_TRUE(false);
}
- hfree(allocd[idx]);
+ kfree(allocd[idx]);
allocd[idx] = NULL;
- if (debug_halloc_assert_consistency(buf, 1024)) {
+ if (debug_kalloc_assert_consistency(buf, 1024)) {
fprintf(
stderr,
"Consistency check failed. (At index=%d, %s:%d)\n",
@@ -311,10 +311,10 @@ TEST(memory, consistency_stress)
}
idx = rand() % NRUNS;
- hfree(allocd[idx]);
+ kfree(allocd[idx]);
allocd[idx] = NULL;
- if (debug_halloc_assert_consistency(buf, 1024)) {
+ if (debug_kalloc_assert_consistency(buf, 1024)) {
fprintf(
stderr,
"Consistency check failed. (At index=%d, %s:%d)\n",
@@ -328,10 +328,10 @@ TEST(memory, consistency_stress)
for(i = 0; i < NRUNS; ++ i) {
if (allocd[i]) {
- hfree(allocd[i]);
+ kfree(allocd[i]);
}
- if (debug_halloc_assert_consistency(buf, 1024)) {
+ if (debug_kalloc_assert_consistency(buf, 1024)) {
fprintf(
stderr,
"Consistency check failed. (At index=%d, %s:%d)\n",
@@ -342,15 +342,15 @@ TEST(memory, consistency_stress)
ASSERT_TRUE(false);
}
}
- ASSERT_EQ((int) halloc_start->size * 4, MAX_HEAP_SIZE - 4);
+ ASSERT_EQ((int) kalloc_start->size * 4, MAX_HEAP_SIZE - 4);
return 0;
}
-TEST(memory, halloc_free_alloc)
+TEST(memory, kalloc_free_alloc)
{
- if (halloc_start) {
- wipeout_halloc();
+ if (kalloc_start) {
+ wipeout_kalloc();
}
new_test_struct();
@@ -359,14 +359,14 @@ TEST(memory, halloc_free_alloc)
struct TEST_STRUCT2* test4 = new_test_struct2();
new_test_struct2();
- hfree(test4);
+ kfree(test4);
struct TEST_STRUCT2* test6 = new_test_struct2();
// test_6 should have been allocated in test_4's spot.
ASSERT_EQ(test6, test4);
- hfree(test2);
+ kfree(test2);
struct TEST_STRUCT* test7 = new_test_struct();
struct TEST_STRUCT* test8 = new_test_struct();