mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Update kernel
This commit is contained in:
@ -21,33 +21,111 @@
|
||||
#include <debug.h>
|
||||
#include <string>
|
||||
|
||||
#include "../kernel.h"
|
||||
|
||||
/* Originally from: https://github.com/EnderIce2/FennixProject/blob/main/kernel/test.cpp */
|
||||
|
||||
#define MEMTEST_ITERATIONS 1024
|
||||
#define MAX_SIZE 1024
|
||||
|
||||
void testMemoryIntegrity()
|
||||
{
|
||||
debug("Testing memory integrity...");
|
||||
|
||||
for (size_t i = 1; i <= MAX_SIZE; i *= 2)
|
||||
{
|
||||
void *ptr1 = malloc(i);
|
||||
if (ptr1 == NULL)
|
||||
{
|
||||
error("malloc failed for size %zu", i);
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
memset(ptr1, 0xAA, i);
|
||||
|
||||
for (size_t j = 0; j < i; ++j)
|
||||
{
|
||||
if (*((unsigned char *)ptr1 + j) != 0xAA)
|
||||
{
|
||||
error("Memory corruption detected before free (size %zu)", i);
|
||||
inf_loop;
|
||||
}
|
||||
}
|
||||
|
||||
void *ptr2 = malloc(i * 2);
|
||||
if (ptr2 == NULL)
|
||||
{
|
||||
error("malloc failed for size %zu", i * 2);
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
memset(ptr2, 0xBB, i * 2);
|
||||
|
||||
for (size_t j = 0; j < i; ++j)
|
||||
{
|
||||
if (*((unsigned char *)ptr1 + j) != 0xAA)
|
||||
{
|
||||
error("Memory corruption detected in previous allocation (size %zu)", i);
|
||||
inf_loop;
|
||||
}
|
||||
}
|
||||
|
||||
free(ptr1);
|
||||
|
||||
for (size_t j = 0; j < i; ++j)
|
||||
{
|
||||
if (*((unsigned char *)ptr2 + j) != 0xBB)
|
||||
{
|
||||
error("Memory corruption detected in current allocation (size %zu)", i * 2);
|
||||
inf_loop;
|
||||
}
|
||||
}
|
||||
|
||||
void *ptr3 = realloc(ptr2, i * 3);
|
||||
if (ptr3 == NULL)
|
||||
{
|
||||
error("realloc failed for size %zu", i * 3);
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
memset(ptr3, 0xCC, i * 3);
|
||||
|
||||
for (size_t j = 0; j < i; ++j)
|
||||
{
|
||||
if (*((unsigned char *)ptr3 + j) != 0xCC)
|
||||
{
|
||||
error("Memory corruption detected after realloc (size %zu)", i * 3);
|
||||
inf_loop;
|
||||
}
|
||||
}
|
||||
|
||||
free(ptr3);
|
||||
}
|
||||
|
||||
debug("Memory integrity test passed.");
|
||||
}
|
||||
|
||||
class test_mem_new_delete
|
||||
{
|
||||
public:
|
||||
test_mem_new_delete();
|
||||
~test_mem_new_delete();
|
||||
test_mem_new_delete()
|
||||
{
|
||||
for (char i = 0; i < 2; i++)
|
||||
;
|
||||
}
|
||||
|
||||
~test_mem_new_delete()
|
||||
{
|
||||
for (char i = 0; i < 2; i++)
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
test_mem_new_delete::test_mem_new_delete()
|
||||
{
|
||||
for (char i = 0; i < 2; i++)
|
||||
;
|
||||
}
|
||||
|
||||
test_mem_new_delete::~test_mem_new_delete()
|
||||
{
|
||||
for (char i = 0; i < 2; i++)
|
||||
;
|
||||
}
|
||||
|
||||
extern bool DebuggerIsAttached;
|
||||
|
||||
void TestMemoryAllocation()
|
||||
{
|
||||
return; /* Bit annoying to have to wait for this to finish */
|
||||
#ifdef a32
|
||||
return; /* Not ready for now. */
|
||||
#endif
|
||||
@ -57,6 +135,8 @@ void TestMemoryAllocation()
|
||||
return;
|
||||
}
|
||||
|
||||
testMemoryIntegrity();
|
||||
|
||||
void *tmpAlloc1 = kmalloc(176);
|
||||
void *tmpAlloc2 = kmalloc(511);
|
||||
void *tmpAlloc3 = kmalloc(1027);
|
||||
@ -113,7 +193,8 @@ void TestMemoryAllocation()
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result:\t\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
if (Config.AllocatorType != Memory::MemoryAllocatorType::rpmalloc_)
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("Multiple Dynamic Malloc Test");
|
||||
@ -128,7 +209,8 @@ void TestMemoryAllocation()
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result:\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
if (Config.AllocatorType != Memory::MemoryAllocatorType::rpmalloc_)
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("New/Delete Test");
|
||||
@ -146,7 +228,8 @@ void TestMemoryAllocation()
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result: \t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
if (Config.AllocatorType != Memory::MemoryAllocatorType::rpmalloc_)
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("New/Delete Fixed Array Test");
|
||||
@ -164,7 +247,8 @@ void TestMemoryAllocation()
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result: \t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
if (Config.AllocatorType != Memory::MemoryAllocatorType::rpmalloc_)
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("New/Delete Dynamic Array Test");
|
||||
@ -184,7 +268,8 @@ void TestMemoryAllocation()
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result:\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
if (Config.AllocatorType != Memory::MemoryAllocatorType::rpmalloc_)
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("calloc Test");
|
||||
@ -202,7 +287,8 @@ void TestMemoryAllocation()
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result:\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
if (Config.AllocatorType != Memory::MemoryAllocatorType::rpmalloc_)
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("realloc Test");
|
||||
@ -221,7 +307,8 @@ void TestMemoryAllocation()
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result:\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
if (Config.AllocatorType != Memory::MemoryAllocatorType::rpmalloc_)
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user