mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-16 01:31:45 +00:00
Update kernel
This commit is contained in:
240
Tests/CPUID.cpp
240
Tests/CPUID.cpp
@@ -25,131 +25,131 @@ extern bool DebuggerIsAttached;
|
||||
|
||||
__constructor void TestCPUIDStructs()
|
||||
{
|
||||
if (!DebuggerIsAttached)
|
||||
return;
|
||||
if (!DebuggerIsAttached)
|
||||
return;
|
||||
|
||||
if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
|
||||
{
|
||||
CPU::x86::AMD::CPUID0x00000000 cpuid0;
|
||||
CPU::x86::AMD::CPUID0x00000001 cpuid1;
|
||||
CPU::x86::AMD::CPUID0x00000005 cpuid5;
|
||||
CPU::x86::AMD::CPUID0x00000006 cpuid6;
|
||||
CPU::x86::AMD::CPUID0x00000007 cpuid7;
|
||||
CPU::x86::AMD::CPUID0x0000000B_ECX_0 cpuidB_C_0;
|
||||
CPU::x86::AMD::CPUID0x0000000B_ECX_1 cpuidB_C_1;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_0 cpuidD_C_0;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_1 cpuidD_C_1;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_2 cpuidD_C_2;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_11 cpuidD_C_11;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_12 cpuidD_C_12;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_3E cpuidD_C_3E;
|
||||
CPU::x86::AMD::CPUID0x80000000 cpuid80000000;
|
||||
CPU::x86::AMD::CPUID0x80000001 cpuid80000001;
|
||||
CPU::x86::AMD::CPUID0x80000002 cpuid80000002;
|
||||
CPU::x86::AMD::CPUID0x80000003 cpuid80000003;
|
||||
CPU::x86::AMD::CPUID0x80000004 cpuid80000004;
|
||||
CPU::x86::AMD::CPUID0x80000005 cpuid80000005;
|
||||
CPU::x86::AMD::CPUID0x80000006 cpuid80000006;
|
||||
CPU::x86::AMD::CPUID0x80000007 cpuid80000007;
|
||||
CPU::x86::AMD::CPUID0x80000008 cpuid80000008;
|
||||
CPU::x86::AMD::CPUID0x8000000A cpuid8000000A;
|
||||
CPU::x86::AMD::CPUID0x80000019 cpuid80000019;
|
||||
CPU::x86::AMD::CPUID0x8000001A cpuid8000001A;
|
||||
CPU::x86::AMD::CPUID0x8000001B cpuid8000001B;
|
||||
CPU::x86::AMD::CPUID0x8000001C cpuid8000001C;
|
||||
CPU::x86::AMD::CPUID0x8000001D cpuid8000001D;
|
||||
CPU::x86::AMD::CPUID0x8000001E cpuid8000001E;
|
||||
CPU::x86::AMD::CPUID0x8000001F cpuid8000001F;
|
||||
CPU::x86::AMD::CPUID0x80000020 cpuid80000020;
|
||||
CPU::x86::AMD::CPUID0x80000021 cpuid80000021;
|
||||
CPU::x86::AMD::CPUID0x80000022 cpuid80000022;
|
||||
CPU::x86::AMD::CPUID0x80000023 cpuid80000023;
|
||||
CPU::x86::AMD::CPUID0x80000026 cpuid80000026;
|
||||
if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
|
||||
{
|
||||
CPU::x86::AMD::CPUID0x00000000 cpuid0;
|
||||
CPU::x86::AMD::CPUID0x00000001 cpuid1;
|
||||
CPU::x86::AMD::CPUID0x00000005 cpuid5;
|
||||
CPU::x86::AMD::CPUID0x00000006 cpuid6;
|
||||
CPU::x86::AMD::CPUID0x00000007 cpuid7;
|
||||
CPU::x86::AMD::CPUID0x0000000B_ECX_0 cpuidB_C_0;
|
||||
CPU::x86::AMD::CPUID0x0000000B_ECX_1 cpuidB_C_1;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_0 cpuidD_C_0;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_1 cpuidD_C_1;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_2 cpuidD_C_2;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_11 cpuidD_C_11;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_12 cpuidD_C_12;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_3E cpuidD_C_3E;
|
||||
CPU::x86::AMD::CPUID0x80000000 cpuid80000000;
|
||||
CPU::x86::AMD::CPUID0x80000001 cpuid80000001;
|
||||
CPU::x86::AMD::CPUID0x80000002 cpuid80000002;
|
||||
CPU::x86::AMD::CPUID0x80000003 cpuid80000003;
|
||||
CPU::x86::AMD::CPUID0x80000004 cpuid80000004;
|
||||
CPU::x86::AMD::CPUID0x80000005 cpuid80000005;
|
||||
CPU::x86::AMD::CPUID0x80000006 cpuid80000006;
|
||||
CPU::x86::AMD::CPUID0x80000007 cpuid80000007;
|
||||
CPU::x86::AMD::CPUID0x80000008 cpuid80000008;
|
||||
CPU::x86::AMD::CPUID0x8000000A cpuid8000000A;
|
||||
CPU::x86::AMD::CPUID0x80000019 cpuid80000019;
|
||||
CPU::x86::AMD::CPUID0x8000001A cpuid8000001A;
|
||||
CPU::x86::AMD::CPUID0x8000001B cpuid8000001B;
|
||||
CPU::x86::AMD::CPUID0x8000001C cpuid8000001C;
|
||||
CPU::x86::AMD::CPUID0x8000001D cpuid8000001D;
|
||||
CPU::x86::AMD::CPUID0x8000001E cpuid8000001E;
|
||||
CPU::x86::AMD::CPUID0x8000001F cpuid8000001F;
|
||||
CPU::x86::AMD::CPUID0x80000020 cpuid80000020;
|
||||
CPU::x86::AMD::CPUID0x80000021 cpuid80000021;
|
||||
CPU::x86::AMD::CPUID0x80000022 cpuid80000022;
|
||||
CPU::x86::AMD::CPUID0x80000023 cpuid80000023;
|
||||
CPU::x86::AMD::CPUID0x80000026 cpuid80000026;
|
||||
|
||||
cpuid0.Get();
|
||||
cpuid1.Get();
|
||||
cpuid5.Get();
|
||||
cpuid6.Get();
|
||||
cpuid7.Get();
|
||||
cpuidB_C_0.Get();
|
||||
cpuidB_C_1.Get();
|
||||
cpuidD_C_0.Get();
|
||||
cpuidD_C_1.Get();
|
||||
cpuidD_C_2.Get();
|
||||
cpuidD_C_11.Get();
|
||||
cpuidD_C_12.Get();
|
||||
cpuidD_C_3E.Get();
|
||||
cpuid80000000.Get();
|
||||
cpuid80000001.Get();
|
||||
cpuid80000002.Get();
|
||||
cpuid80000003.Get();
|
||||
cpuid80000004.Get();
|
||||
cpuid80000005.Get();
|
||||
cpuid80000006.Get();
|
||||
cpuid80000007.Get();
|
||||
cpuid80000008.Get();
|
||||
cpuid8000000A.Get();
|
||||
cpuid80000019.Get();
|
||||
cpuid8000001A.Get();
|
||||
cpuid8000001B.Get();
|
||||
cpuid8000001C.Get();
|
||||
cpuid8000001D.Get();
|
||||
cpuid8000001E.Get();
|
||||
cpuid8000001F.Get();
|
||||
cpuid80000020.Get();
|
||||
cpuid80000021.Get();
|
||||
cpuid80000022.Get();
|
||||
cpuid80000023.Get();
|
||||
cpuid80000026.Get();
|
||||
cpuid0.Get();
|
||||
cpuid1.Get();
|
||||
cpuid5.Get();
|
||||
cpuid6.Get();
|
||||
cpuid7.Get();
|
||||
cpuidB_C_0.Get();
|
||||
cpuidB_C_1.Get();
|
||||
cpuidD_C_0.Get();
|
||||
cpuidD_C_1.Get();
|
||||
cpuidD_C_2.Get();
|
||||
cpuidD_C_11.Get();
|
||||
cpuidD_C_12.Get();
|
||||
cpuidD_C_3E.Get();
|
||||
cpuid80000000.Get();
|
||||
cpuid80000001.Get();
|
||||
cpuid80000002.Get();
|
||||
cpuid80000003.Get();
|
||||
cpuid80000004.Get();
|
||||
cpuid80000005.Get();
|
||||
cpuid80000006.Get();
|
||||
cpuid80000007.Get();
|
||||
cpuid80000008.Get();
|
||||
cpuid8000000A.Get();
|
||||
cpuid80000019.Get();
|
||||
cpuid8000001A.Get();
|
||||
cpuid8000001B.Get();
|
||||
cpuid8000001C.Get();
|
||||
cpuid8000001D.Get();
|
||||
cpuid8000001E.Get();
|
||||
cpuid8000001F.Get();
|
||||
cpuid80000020.Get();
|
||||
cpuid80000021.Get();
|
||||
cpuid80000022.Get();
|
||||
cpuid80000023.Get();
|
||||
cpuid80000026.Get();
|
||||
|
||||
// asmv("int3");
|
||||
}
|
||||
else if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_INTEL) == 0)
|
||||
{
|
||||
CPU::x86::Intel::CPUID0x00000000 cpuid0;
|
||||
CPU::x86::Intel::CPUID0x00000001 cpuid1;
|
||||
CPU::x86::Intel::CPUID0x00000002 cpuid2;
|
||||
CPU::x86::Intel::CPUID0x00000003 cpuid3;
|
||||
CPU::x86::Intel::CPUID0x00000004_1 cpuid4_1;
|
||||
CPU::x86::Intel::CPUID0x00000005 cpuid5;
|
||||
CPU::x86::Intel::CPUID0x00000006 cpuid6;
|
||||
CPU::x86::Intel::CPUID0x00000007_0 cpuid7_0;
|
||||
CPU::x86::Intel::CPUID0x00000007_1 cpuid7_1;
|
||||
CPU::x86::Intel::CPUID0x0000000A cpuidA;
|
||||
CPU::x86::Intel::CPUID0x00000015 cpuid15;
|
||||
CPU::x86::Intel::CPUID0x00000016 cpuid16;
|
||||
CPU::x86::Intel::CPUID0x80000000 cpuid80000000;
|
||||
CPU::x86::Intel::CPUID0x80000001 cpuid80000001;
|
||||
CPU::x86::Intel::CPUID0x80000002 cpuid80000002;
|
||||
CPU::x86::Intel::CPUID0x80000003 cpuid80000003;
|
||||
CPU::x86::Intel::CPUID0x80000004 cpuid80000004;
|
||||
CPU::x86::Intel::CPUID0x80000006 cpuid80000006;
|
||||
CPU::x86::Intel::CPUID0x80000008 cpuid80000008;
|
||||
CPU::x86::Intel::CPUID0x8000000A cpuid8000000A;
|
||||
// asmv("int3");
|
||||
}
|
||||
else if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_INTEL) == 0)
|
||||
{
|
||||
CPU::x86::Intel::CPUID0x00000000 cpuid0;
|
||||
CPU::x86::Intel::CPUID0x00000001 cpuid1;
|
||||
CPU::x86::Intel::CPUID0x00000002 cpuid2;
|
||||
CPU::x86::Intel::CPUID0x00000003 cpuid3;
|
||||
CPU::x86::Intel::CPUID0x00000004_1 cpuid4_1;
|
||||
CPU::x86::Intel::CPUID0x00000005 cpuid5;
|
||||
CPU::x86::Intel::CPUID0x00000006 cpuid6;
|
||||
CPU::x86::Intel::CPUID0x00000007_0 cpuid7_0;
|
||||
CPU::x86::Intel::CPUID0x00000007_1 cpuid7_1;
|
||||
CPU::x86::Intel::CPUID0x0000000A cpuidA;
|
||||
CPU::x86::Intel::CPUID0x00000015 cpuid15;
|
||||
CPU::x86::Intel::CPUID0x00000016 cpuid16;
|
||||
CPU::x86::Intel::CPUID0x80000000 cpuid80000000;
|
||||
CPU::x86::Intel::CPUID0x80000001 cpuid80000001;
|
||||
CPU::x86::Intel::CPUID0x80000002 cpuid80000002;
|
||||
CPU::x86::Intel::CPUID0x80000003 cpuid80000003;
|
||||
CPU::x86::Intel::CPUID0x80000004 cpuid80000004;
|
||||
CPU::x86::Intel::CPUID0x80000006 cpuid80000006;
|
||||
CPU::x86::Intel::CPUID0x80000008 cpuid80000008;
|
||||
CPU::x86::Intel::CPUID0x8000000A cpuid8000000A;
|
||||
|
||||
cpuid0.Get();
|
||||
cpuid1.Get();
|
||||
cpuid2.Get();
|
||||
cpuid3.Get();
|
||||
cpuid4_1.Get();
|
||||
cpuid5.Get();
|
||||
cpuid6.Get();
|
||||
cpuid7_0.Get();
|
||||
cpuid7_1.Get();
|
||||
cpuidA.Get();
|
||||
cpuid15.Get();
|
||||
cpuid16.Get();
|
||||
cpuid80000000.Get();
|
||||
cpuid80000001.Get();
|
||||
cpuid80000002.Get();
|
||||
cpuid80000003.Get();
|
||||
cpuid80000004.Get();
|
||||
cpuid80000006.Get();
|
||||
cpuid80000008.Get();
|
||||
cpuid8000000A.Get();
|
||||
cpuid0.Get();
|
||||
cpuid1.Get();
|
||||
cpuid2.Get();
|
||||
cpuid3.Get();
|
||||
cpuid4_1.Get();
|
||||
cpuid5.Get();
|
||||
cpuid6.Get();
|
||||
cpuid7_0.Get();
|
||||
cpuid7_1.Get();
|
||||
cpuidA.Get();
|
||||
cpuid15.Get();
|
||||
cpuid16.Get();
|
||||
cpuid80000000.Get();
|
||||
cpuid80000001.Get();
|
||||
cpuid80000002.Get();
|
||||
cpuid80000003.Get();
|
||||
cpuid80000004.Get();
|
||||
cpuid80000006.Get();
|
||||
cpuid80000008.Get();
|
||||
cpuid8000000A.Get();
|
||||
|
||||
// asmv("int3");
|
||||
}
|
||||
// asmv("int3");
|
||||
}
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
||||
|
@@ -22,6 +22,16 @@
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <filesystem.hpp>
|
||||
#include "../syscalls.h"
|
||||
|
||||
void TestSeekMacros() /* static assert, no constructor needed */
|
||||
{
|
||||
static_assert(SYSCALL_SEEK_SET == SEEK_SET);
|
||||
static_assert(SYSCALL_SEEK_CUR == SEEK_CUR);
|
||||
static_assert(SYSCALL_SEEK_END == SEEK_END);
|
||||
}
|
||||
|
||||
__constructor void TestMacros()
|
||||
{
|
||||
{
|
||||
|
@@ -18,8 +18,8 @@
|
||||
#ifdef DEBUG
|
||||
|
||||
#include <memory.hpp>
|
||||
#include <string.hpp>
|
||||
#include <debug.h>
|
||||
#include <string>
|
||||
|
||||
/* Originally from: https://github.com/EnderIce2/FennixProject/blob/main/kernel/test.cpp */
|
||||
|
||||
@@ -28,20 +28,20 @@
|
||||
class test_mem_new_delete
|
||||
{
|
||||
public:
|
||||
test_mem_new_delete();
|
||||
~test_mem_new_delete();
|
||||
test_mem_new_delete();
|
||||
~test_mem_new_delete();
|
||||
};
|
||||
|
||||
test_mem_new_delete::test_mem_new_delete()
|
||||
{
|
||||
for (char i = 0; i < 2; i++)
|
||||
;
|
||||
for (char i = 0; i < 2; i++)
|
||||
;
|
||||
}
|
||||
|
||||
test_mem_new_delete::~test_mem_new_delete()
|
||||
{
|
||||
for (char i = 0; i < 2; i++)
|
||||
;
|
||||
for (char i = 0; i < 2; i++)
|
||||
;
|
||||
}
|
||||
|
||||
extern bool EnableExternalMemoryTracer;
|
||||
@@ -50,204 +50,212 @@ extern bool DebuggerIsAttached;
|
||||
void TestMemoryAllocation()
|
||||
{
|
||||
#ifdef a32
|
||||
return; /* Not really for now. */
|
||||
return; /* Not ready for now. */
|
||||
#endif
|
||||
if (EnableExternalMemoryTracer || DebuggerIsAttached)
|
||||
{
|
||||
debug("The test is disabled when the external memory tracer or a debugger is enabled.");
|
||||
return;
|
||||
}
|
||||
if (EnableExternalMemoryTracer || DebuggerIsAttached)
|
||||
{
|
||||
debug("The test is disabled when the external memory tracer or a debugger is enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
void *tmpAlloc1 = kmalloc(176);
|
||||
void *tmpAlloc2 = kmalloc(511);
|
||||
void *tmpAlloc3 = kmalloc(1027);
|
||||
void *tmpAlloc4 = kmalloc(1569);
|
||||
for (int repeat = 0; repeat < 4; repeat++)
|
||||
{
|
||||
debug("---------------[TEST %d]---------------\n", repeat);
|
||||
void *tmpAlloc1 = kmalloc(176);
|
||||
void *tmpAlloc2 = kmalloc(511);
|
||||
void *tmpAlloc3 = kmalloc(1027);
|
||||
void *tmpAlloc4 = kmalloc(1569);
|
||||
for (int repeat = 0; repeat < 4; repeat++)
|
||||
{
|
||||
debug("---------------[TEST %d]---------------\n", repeat);
|
||||
|
||||
debug("Single Page Request Test");
|
||||
{
|
||||
uint64_t prq1 = (uint64_t)KernelAllocator.RequestPage();
|
||||
KernelAllocator.FreePage((void *)prq1);
|
||||
debug("Single Page Request Test");
|
||||
{
|
||||
uint64_t prq1 = (uint64_t)KernelAllocator.RequestPage();
|
||||
KernelAllocator.FreePage((void *)prq1);
|
||||
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
KernelAllocator.FreePage(KernelAllocator.RequestPage());
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
KernelAllocator.FreePage(KernelAllocator.RequestPage());
|
||||
|
||||
uint64_t prq2 = (uint64_t)KernelAllocator.RequestPage();
|
||||
KernelAllocator.FreePage((void *)prq2);
|
||||
uint64_t prq2 = (uint64_t)KernelAllocator.RequestPage();
|
||||
KernelAllocator.FreePage((void *)prq2);
|
||||
|
||||
debug(" Result:\t\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
debug(" Result:\t\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("Multiple Page Request Test");
|
||||
{
|
||||
uint64_t prq1 = (uint64_t)KernelAllocator.RequestPages(10);
|
||||
KernelAllocator.FreePages((void *)prq1, 10);
|
||||
debug("Multiple Page Request Test");
|
||||
{
|
||||
uint64_t prq1 = (uint64_t)KernelAllocator.RequestPages(10);
|
||||
KernelAllocator.FreePages((void *)prq1, 10);
|
||||
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
KernelAllocator.FreePages(KernelAllocator.RequestPages(20), 20);
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
KernelAllocator.FreePages(KernelAllocator.RequestPages(20), 20);
|
||||
|
||||
uint64_t prq2 = (uint64_t)KernelAllocator.RequestPages(10);
|
||||
KernelAllocator.FreePages((void *)prq2, 10);
|
||||
uint64_t prq2 = (uint64_t)KernelAllocator.RequestPages(10);
|
||||
KernelAllocator.FreePages((void *)prq2, 10);
|
||||
|
||||
debug(" Result:\t\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
debug(" Result:\t\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("Multiple Fixed Malloc Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
debug("Multiple Fixed Malloc Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
kfree(kmalloc(0x10000));
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
{
|
||||
kfree(kmalloc(0x10000));
|
||||
kfree(kmalloc(0x1000));
|
||||
kfree(kmalloc(0x100));
|
||||
kfree(kmalloc(0x10));
|
||||
kfree(kmalloc(0x1));
|
||||
}
|
||||
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result:\t\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
debug(" Result:\t\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("Multiple Dynamic Malloc Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
debug("Multiple Dynamic Malloc Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
kfree(kmalloc(i));
|
||||
for (size_t i = 1; i < MEMTEST_ITERATIONS; i++)
|
||||
kfree(kmalloc(i));
|
||||
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result:\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
debug(" Result:\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("New/Delete Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
debug("New/Delete Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
{
|
||||
test_mem_new_delete *t = new test_mem_new_delete();
|
||||
delete t;
|
||||
}
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
{
|
||||
test_mem_new_delete *t = new test_mem_new_delete();
|
||||
delete t;
|
||||
}
|
||||
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result: \t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
debug(" Result: \t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("New/Delete Fixed Array Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
debug("New/Delete Fixed Array Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
{
|
||||
char *t = new char[128];
|
||||
delete[] t;
|
||||
}
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
{
|
||||
char *t = new char[128];
|
||||
delete[] t;
|
||||
}
|
||||
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result: \t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
debug(" Result: \t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("New/Delete Dynamic Array Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
debug("New/Delete Dynamic Array Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
continue;
|
||||
char *t = new char[i];
|
||||
delete[] t;
|
||||
}
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
continue;
|
||||
char *t = new char[i];
|
||||
delete[] t;
|
||||
}
|
||||
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result:\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
debug(" Result:\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("calloc Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
debug("calloc Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
{
|
||||
char *t = (char *)kcalloc(128, 1);
|
||||
kfree(t);
|
||||
}
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
{
|
||||
char *t = (char *)kcalloc(128, 1);
|
||||
kfree(t);
|
||||
}
|
||||
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result:\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
debug(" Result:\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
|
||||
debug("realloc Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
debug("realloc Test");
|
||||
{
|
||||
uintptr_t prq1 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq1);
|
||||
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
{
|
||||
char *t = (char *)kmalloc(128);
|
||||
t = (char *)krealloc(t, 256);
|
||||
kfree(t);
|
||||
}
|
||||
for (size_t i = 0; i < MEMTEST_ITERATIONS; i++)
|
||||
{
|
||||
char *t = (char *)kmalloc(128);
|
||||
t = (char *)krealloc(t, 256);
|
||||
kfree(t);
|
||||
}
|
||||
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
uintptr_t prq2 = (uintptr_t)kmalloc(0x1000);
|
||||
kfree((void *)prq2);
|
||||
|
||||
debug(" Result:\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
}
|
||||
debug(" Result:\t1-[%#lx]; 2-[%#lx]", (void *)prq1, (void *)prq2);
|
||||
assert(prq1 == prq2);
|
||||
}
|
||||
}
|
||||
|
||||
kfree(tmpAlloc1);
|
||||
kfree(tmpAlloc2);
|
||||
kfree(tmpAlloc3);
|
||||
kfree(tmpAlloc4);
|
||||
kfree(tmpAlloc1);
|
||||
kfree(tmpAlloc2);
|
||||
kfree(tmpAlloc3);
|
||||
kfree(tmpAlloc4);
|
||||
|
||||
debug("Memory Stress Test");
|
||||
for (size_t i = 0; i < 0x1000; i++)
|
||||
kfree(kmalloc(i));
|
||||
debug("Memory Stress Test");
|
||||
for (size_t i = 1; i < 0x1000; i++)
|
||||
kfree(kmalloc(i));
|
||||
|
||||
debug("Invalid Usage Test");
|
||||
kfree(tmpAlloc1);
|
||||
kfree(tmpAlloc2);
|
||||
kfree(tmpAlloc3);
|
||||
kfree(tmpAlloc4);
|
||||
debug("Invalid Usage Test");
|
||||
kfree(tmpAlloc1);
|
||||
kfree(tmpAlloc2);
|
||||
kfree(tmpAlloc3);
|
||||
kfree(tmpAlloc4);
|
||||
|
||||
void *InvMlc = kmalloc(0);
|
||||
assert(InvMlc == nullptr);
|
||||
krealloc(InvMlc, 0);
|
||||
assert(InvMlc == nullptr);
|
||||
kcalloc(0, 0);
|
||||
assert(InvMlc == nullptr);
|
||||
kcalloc(1, 0);
|
||||
assert(InvMlc == nullptr);
|
||||
kcalloc(0, 1);
|
||||
assert(InvMlc == nullptr);
|
||||
kfree(InvMlc);
|
||||
/* Allocation functions have assertions to check for invalid usage */
|
||||
|
||||
debug("Memory Test Complete");
|
||||
// void *InvMlc = kmalloc(0);
|
||||
// assert(InvMlc == nullptr);
|
||||
// krealloc(InvMlc, 0);
|
||||
// assert(InvMlc == nullptr);
|
||||
// kcalloc(0, 0);
|
||||
// assert(InvMlc == nullptr);
|
||||
// kcalloc(1, 0);
|
||||
// assert(InvMlc == nullptr);
|
||||
// kcalloc(0, 1);
|
||||
// assert(InvMlc == nullptr);
|
||||
// kfree(InvMlc);
|
||||
|
||||
debug("Memory Test Complete");
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
||||
|
@@ -23,118 +23,125 @@
|
||||
|
||||
extern bool EnableExternalMemoryTracer;
|
||||
extern bool DebuggerIsAttached;
|
||||
extern Memory::MemoryAllocatorType AllocatorType;
|
||||
|
||||
__constructor void TestMemoryOperations()
|
||||
{
|
||||
if (EnableExternalMemoryTracer || DebuggerIsAttached)
|
||||
{
|
||||
debug("The test is disabled when the external memory tracer or a debugger is enabled.");
|
||||
return;
|
||||
}
|
||||
if (EnableExternalMemoryTracer || DebuggerIsAttached)
|
||||
{
|
||||
debug("The test is disabled when the external memory tracer or a debugger is enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
int arr1[5] = {1, 2, 3, 4, 5};
|
||||
int arr2[5] = {0, 0, 0, 0, 0};
|
||||
char str1[] = "Hello";
|
||||
char str2[] = "World";
|
||||
if (AllocatorType == Memory::MemoryAllocatorType::Pages)
|
||||
{
|
||||
debug("The test is disabled when the allocator is set to pages.");
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy_unsafe(arr2, arr1, sizeof(arr1));
|
||||
debug("memcpy: arr2[0]=%d, arr2[1]=%d, arr2[2]=%d, arr2[3]=%d, arr2[4]=%d",
|
||||
arr2[0], arr2[1], arr2[2], arr2[3], arr2[4]);
|
||||
if (memcmp(arr1, arr2, sizeof(arr1)) != 0)
|
||||
{
|
||||
error("memcpy failed!");
|
||||
inf_loop;
|
||||
}
|
||||
int arr1[5] = {1, 2, 3, 4, 5};
|
||||
int arr2[5] = {0, 0, 0, 0, 0};
|
||||
char str1[] = "Hello";
|
||||
char str2[] = "World";
|
||||
|
||||
memset_unsafe(arr2, 0, sizeof(arr2));
|
||||
debug("memset: arr2[0]=%d, arr2[1]=%d, arr2[2]=%d, arr2[3]=%d, arr2[4]=%d",
|
||||
arr2[0], arr2[1], arr2[2], arr2[3], arr2[4]);
|
||||
if (memcmp(arr1, arr2, sizeof(arr1)) == 0)
|
||||
{
|
||||
error("memset failed!");
|
||||
inf_loop;
|
||||
}
|
||||
memcpy_unsafe(arr2, arr1, sizeof(arr1));
|
||||
debug("memcpy: arr2[0]=%d, arr2[1]=%d, arr2[2]=%d, arr2[3]=%d, arr2[4]=%d",
|
||||
arr2[0], arr2[1], arr2[2], arr2[3], arr2[4]);
|
||||
if (memcmp(arr1, arr2, sizeof(arr1)) != 0)
|
||||
{
|
||||
error("memcpy failed!");
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
memmove_unsafe(str1 + 3, str1, strlen(str1) + 1);
|
||||
debug("memmove: str1=%s", str1);
|
||||
if (strcmp(str1, "HelHello") != 0)
|
||||
{
|
||||
error("memmove failed!");
|
||||
inf_loop;
|
||||
}
|
||||
memset_unsafe(arr2, 0, sizeof(arr2));
|
||||
debug("memset: arr2[0]=%d, arr2[1]=%d, arr2[2]=%d, arr2[3]=%d, arr2[4]=%d",
|
||||
arr2[0], arr2[1], arr2[2], arr2[3], arr2[4]);
|
||||
if (memcmp(arr1, arr2, sizeof(arr1)) == 0)
|
||||
{
|
||||
error("memset failed!");
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
char carr[512];
|
||||
char carrTo[16];
|
||||
memmove_unsafe(str1 + 3, str1, strlen(str1) + 1);
|
||||
debug("memmove: str1=%s", str1);
|
||||
if (strcmp(str1, "HelHello") != 0)
|
||||
{
|
||||
error("memmove failed!");
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
for (size_t i = 0; i < 16; i++)
|
||||
carrTo[i] = 'a';
|
||||
char carr[512];
|
||||
char carrTo[16];
|
||||
|
||||
for (size_t i = 0; i < 512; i += 16)
|
||||
memcpy_unsafe(carr + i, carrTo, 16);
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
for (size_t i = 0; i < 16; i++)
|
||||
carrTo[i] = 'a';
|
||||
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
if (carr[i] != 'a')
|
||||
{
|
||||
error("memcpy failed!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < 512; i += 16)
|
||||
memcpy_unsafe(carr + i, carrTo, 16);
|
||||
|
||||
{
|
||||
char carrFull[512];
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
carrFull[i] = 'b';
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
if (carr[i] != 'a')
|
||||
{
|
||||
error("memcpy failed!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy_unsafe(carr, carrFull, 512);
|
||||
{
|
||||
char carrFull[512];
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
carrFull[i] = 'b';
|
||||
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
if (carr[i] != 'b')
|
||||
{
|
||||
error("memcpy failed!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
memcpy_unsafe(carr, carrFull, 512);
|
||||
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
for (size_t i = 0; i < 512; i += 16)
|
||||
memset_unsafe(carr + i, 'c', 16);
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
if (carr[i] != 'b')
|
||||
{
|
||||
error("memcpy failed!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
if (carr[i] != 'c')
|
||||
{
|
||||
error("memcpy failed!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
for (size_t i = 0; i < 512; i += 16)
|
||||
memset_unsafe(carr + i, 'c', 16);
|
||||
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
memset_unsafe(carr, 'd', 512);
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
if (carr[i] != 'c')
|
||||
{
|
||||
error("memcpy failed!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
if (carr[i] != 'd')
|
||||
{
|
||||
error("memset failed!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
memset_unsafe(carr, 'd', 512);
|
||||
|
||||
debug("Memory operations test passed");
|
||||
for (size_t i = 0; i < 512; i++)
|
||||
{
|
||||
if (carr[i] != 'd')
|
||||
{
|
||||
error("memset failed!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debug("Memory operations test passed");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -23,46 +23,46 @@
|
||||
|
||||
__constructor void TestRandom()
|
||||
{
|
||||
int RDRANDFlag = 0;
|
||||
if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
|
||||
{
|
||||
CPU::x86::AMD::CPUID0x00000001 cpuid;
|
||||
cpuid.Get();
|
||||
RDRANDFlag = cpuid.ECX.RDRAND;
|
||||
}
|
||||
else if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_INTEL) == 0)
|
||||
{
|
||||
CPU::x86::Intel::CPUID0x00000001 cpuid;
|
||||
cpuid.Get();
|
||||
RDRANDFlag = cpuid.ECX.RDRAND;
|
||||
}
|
||||
int RDRANDFlag = 0;
|
||||
if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
|
||||
{
|
||||
CPU::x86::AMD::CPUID0x00000001 cpuid;
|
||||
cpuid.Get();
|
||||
RDRANDFlag = cpuid.ECX.RDRAND;
|
||||
}
|
||||
else if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_INTEL) == 0)
|
||||
{
|
||||
CPU::x86::Intel::CPUID0x00000001 cpuid;
|
||||
cpuid.Get();
|
||||
RDRANDFlag = cpuid.ECX.RDRAND;
|
||||
}
|
||||
|
||||
if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) == 0)
|
||||
RDRANDFlag = 0;
|
||||
if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) == 0)
|
||||
RDRANDFlag = 0;
|
||||
|
||||
#if defined(a86)
|
||||
if (RDRANDFlag)
|
||||
{
|
||||
uintptr_t RDSEEDValue = 0;
|
||||
asmv("1: rdseed %0; jnc 1b"
|
||||
: "=r"(RDSEEDValue));
|
||||
debug("RDSEED: %ld", RDSEEDValue);
|
||||
}
|
||||
if (RDRANDFlag)
|
||||
{
|
||||
uintptr_t RDSEEDValue = 0;
|
||||
asmv("1: rdseed %0; jnc 1b"
|
||||
: "=r"(RDSEEDValue));
|
||||
debug("RDSEED: %ld", RDSEEDValue);
|
||||
}
|
||||
#endif
|
||||
|
||||
Random::ChangeSeed(0xdeadbeef);
|
||||
uint16_t Seeds16[16];
|
||||
uint32_t Seeds32[16];
|
||||
uint64_t Seeds64[16];
|
||||
for (short i = 0; i < 16; i++)
|
||||
{
|
||||
Seeds16[i] = Random::rand16();
|
||||
Seeds32[i] = Random::rand32();
|
||||
Seeds64[i] = Random::rand64();
|
||||
}
|
||||
debug("Random 16: %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld", Seeds16[0], Seeds16[1], Seeds16[2], Seeds16[3], Seeds16[4], Seeds16[5], Seeds16[6], Seeds16[7], Seeds16[8], Seeds16[9], Seeds16[10], Seeds16[11], Seeds16[12], Seeds16[13], Seeds16[14], Seeds16[15]);
|
||||
debug("Random 32: %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld", Seeds32[0], Seeds32[1], Seeds32[2], Seeds32[3], Seeds32[4], Seeds32[5], Seeds32[6], Seeds32[7], Seeds32[8], Seeds32[9], Seeds32[10], Seeds32[11], Seeds32[12], Seeds32[13], Seeds32[14], Seeds32[15]);
|
||||
debug("Random 64: %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld", Seeds64[0], Seeds64[1], Seeds64[2], Seeds64[3], Seeds64[4], Seeds64[5], Seeds64[6], Seeds64[7], Seeds64[8], Seeds64[9], Seeds64[10], Seeds64[11], Seeds64[12], Seeds64[13], Seeds64[14], Seeds64[15]);
|
||||
Random::ChangeSeed(0xdeadbeef);
|
||||
uint16_t Seeds16[16];
|
||||
uint32_t Seeds32[16];
|
||||
uint64_t Seeds64[16];
|
||||
for (short i = 0; i < 16; i++)
|
||||
{
|
||||
Seeds16[i] = Random::rand16();
|
||||
Seeds32[i] = Random::rand32();
|
||||
Seeds64[i] = Random::rand64();
|
||||
}
|
||||
debug("Random 16: %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld", Seeds16[0], Seeds16[1], Seeds16[2], Seeds16[3], Seeds16[4], Seeds16[5], Seeds16[6], Seeds16[7], Seeds16[8], Seeds16[9], Seeds16[10], Seeds16[11], Seeds16[12], Seeds16[13], Seeds16[14], Seeds16[15]);
|
||||
debug("Random 32: %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld", Seeds32[0], Seeds32[1], Seeds32[2], Seeds32[3], Seeds32[4], Seeds32[5], Seeds32[6], Seeds32[7], Seeds32[8], Seeds32[9], Seeds32[10], Seeds32[11], Seeds32[12], Seeds32[13], Seeds32[14], Seeds32[15]);
|
||||
debug("Random 64: %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld", Seeds64[0], Seeds64[1], Seeds64[2], Seeds64[3], Seeds64[4], Seeds64[5], Seeds64[6], Seeds64[7], Seeds64[8], Seeds64[9], Seeds64[10], Seeds64[11], Seeds64[12], Seeds64[13], Seeds64[14], Seeds64[15]);
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
||||
|
198
Tests/String.cpp
198
Tests/String.cpp
@@ -18,102 +18,136 @@
|
||||
#ifdef DEBUG
|
||||
|
||||
#include <std/string.hpp>
|
||||
#include <memory.hpp>
|
||||
#include <debug.h>
|
||||
|
||||
void TestString()
|
||||
{
|
||||
std::string hw("Hello, world!");
|
||||
debug("String length: %d", hw.length());
|
||||
debug("String capacity: %d", hw.capacity());
|
||||
debug("String data: %s", hw.c_str());
|
||||
if (hw == "Hello, world!" && hw != "World, hello!")
|
||||
debug("String comparison works!");
|
||||
else
|
||||
{
|
||||
error("String comparison doesn't work! \"%s\"", hw.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
char *sanity_alloc = (char *)kmalloc(1024);
|
||||
for (int i = 0; i < 1024; i++)
|
||||
sanity_alloc[i] = 'A';
|
||||
std::string hw("Hello, world!");
|
||||
|
||||
std::string hi("Hi");
|
||||
char chi[3];
|
||||
chi[0] = hi[0];
|
||||
chi[1] = hi[1];
|
||||
chi[2] = '\0';
|
||||
if (strcmp(chi, "Hi") == 0)
|
||||
debug("String indexing works!");
|
||||
else
|
||||
{
|
||||
error("String indexing doesn't work! \"%s\" \"%s\"", chi, hi.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
for (int i = 0; i < 1024; i++)
|
||||
if (sanity_alloc[i] != 'A')
|
||||
{
|
||||
error("Sanity check failed! %d", i);
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
hi << " there!";
|
||||
if (hi == "Hi there!")
|
||||
debug("String concatenation works!");
|
||||
else
|
||||
{
|
||||
error("String concatenation doesn't work! \"%s\"", hi.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
debug("String length: %d", hw.length());
|
||||
debug("String capacity: %d", hw.capacity());
|
||||
debug("String data: %s", hw.c_str());
|
||||
if (hw == "Hello, world!" && hw != "World, hello!")
|
||||
debug("String comparison works!");
|
||||
else
|
||||
{
|
||||
error("String comparison doesn't work! \"%s\"", hw.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
hi << " " << hw;
|
||||
if (hi == "Hi there! Hello, world!")
|
||||
debug("String concatenation works!");
|
||||
else
|
||||
{
|
||||
error("String concatenation doesn't work! \"%s\"", hi.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
for (int i = 0; i < 1024; i++)
|
||||
if (sanity_alloc[i] != 'A')
|
||||
{
|
||||
error("Sanity check failed! %d", i);
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
std::string eq0("Hello, world!");
|
||||
std::string eq1("Hello, world!");
|
||||
std::string eq2("World, hello!");
|
||||
kfree(sanity_alloc);
|
||||
|
||||
if (eq0 == eq1)
|
||||
debug("String equality works!");
|
||||
else
|
||||
{
|
||||
error("String equality doesn't work! \"%s\" \"%s\"", eq0.c_str(), eq1.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
std::string hi("Hi");
|
||||
char chi[3];
|
||||
chi[0] = hi[0];
|
||||
chi[1] = hi[1];
|
||||
chi[2] = '\0';
|
||||
if (strcmp(chi, "Hi") == 0)
|
||||
debug("String indexing works!");
|
||||
else
|
||||
{
|
||||
error("String indexing doesn't work! \"%s\" \"%s\"", chi, hi.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
if (eq0 != eq2)
|
||||
debug("String inequality works!");
|
||||
else
|
||||
{
|
||||
error("String inequality doesn't work! \"%s\" \"%s\"", eq0.c_str(), eq2.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
sanity_alloc = (char *)kmalloc(1024);
|
||||
for (int i = 0; i < 1024; i++)
|
||||
sanity_alloc[i] = 'A';
|
||||
|
||||
char chw[14];
|
||||
int i = 0;
|
||||
foreach (auto c in hw)
|
||||
{
|
||||
chw[i] = c;
|
||||
i++;
|
||||
}
|
||||
chw[i] = '\0';
|
||||
hi << " there!";
|
||||
if (hi == "Hi there!")
|
||||
debug("String concatenation works!");
|
||||
else
|
||||
{
|
||||
error("String concatenation doesn't work! \"%s\"", hi.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
if (strcmp(chw, "Hello, world!") == 0)
|
||||
debug("String iteration works!");
|
||||
else
|
||||
{
|
||||
error("String iteration doesn't work! \"%s\" \"%s\" %d", chw, hw.c_str(), i);
|
||||
inf_loop;
|
||||
}
|
||||
hi << " " << hw;
|
||||
if (hi == "Hi there! Hello, world!")
|
||||
debug("String concatenation works!");
|
||||
else
|
||||
{
|
||||
error("String concatenation doesn't work! \"%s\"", hi.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
std::string a("Hello");
|
||||
std::string b("World");
|
||||
std::string c;
|
||||
c = a + ", " + b + "!";
|
||||
std::string eq0("Hello, world!");
|
||||
std::string eq1("Hello, world!");
|
||||
std::string eq2("World, hello!");
|
||||
|
||||
if (c == "Hello, World!")
|
||||
debug("String addition works!");
|
||||
else
|
||||
{
|
||||
error("String addition doesn't work! \"%s\"", c.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
if (eq0 == eq1)
|
||||
debug("String equality works!");
|
||||
else
|
||||
{
|
||||
error("String equality doesn't work! \"%s\" \"%s\"", eq0.c_str(), eq1.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
if (eq0 != eq2)
|
||||
debug("String inequality works!");
|
||||
else
|
||||
{
|
||||
error("String inequality doesn't work! \"%s\" \"%s\"", eq0.c_str(), eq2.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
char chw[14];
|
||||
int i = 0;
|
||||
foreach (auto c in hw)
|
||||
{
|
||||
chw[i] = c;
|
||||
i++;
|
||||
}
|
||||
chw[i] = '\0';
|
||||
|
||||
if (strcmp(chw, "Hello, world!") == 0)
|
||||
debug("String iteration works!");
|
||||
else
|
||||
{
|
||||
error("String iteration doesn't work! \"%s\" \"%s\" %d", chw, hw.c_str(), i);
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
std::string a("Hello");
|
||||
std::string b("World");
|
||||
std::string c;
|
||||
c = a + ", " + b + "!";
|
||||
|
||||
if (c == "Hello, World!")
|
||||
debug("String addition works!");
|
||||
else
|
||||
{
|
||||
error("String addition doesn't work! \"%s\"", c.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1024; i++)
|
||||
if (sanity_alloc[i] != 'A')
|
||||
{
|
||||
error("Sanity check failed! %d", i);
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
kfree(sanity_alloc);
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
||||
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include "../syscalls.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
__aligned(0x1000) __no_stack_protector void TestSyscalls()
|
||||
{
|
||||
#if defined(a64)
|
||||
__asm__ __volatile__("syscall"
|
||||
:
|
||||
: "a"(_Print), "D"('H'), "S"(0)
|
||||
: "rcx", "r11", "memory");
|
||||
|
||||
int fork_id = -0xda;
|
||||
|
||||
__asm__ __volatile__("syscall"
|
||||
: "=a"(fork_id)
|
||||
: "a"(_Fork)
|
||||
: "rcx", "r11", "memory");
|
||||
|
||||
__asm__ __volatile__("syscall"
|
||||
:
|
||||
: "a"(_Exit), "D"(fork_id)
|
||||
: "rcx", "r11", "memory");
|
||||
#elif defined(a32)
|
||||
#elif defined(aa64)
|
||||
#endif
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
#endif
|
@@ -21,103 +21,103 @@
|
||||
|
||||
__constructor void TestTypeSize()
|
||||
{
|
||||
debug("--- INT TYPES ---");
|
||||
debug("sizeof(__INT8_TYPE__) = %lld", sizeof(__INT8_TYPE__));
|
||||
debug("sizeof(__INT16_TYPE__) = %lld", sizeof(__INT16_TYPE__));
|
||||
debug("sizeof(__INT32_TYPE__) = %lld", sizeof(__INT32_TYPE__));
|
||||
debug("sizeof(__INT64_TYPE__) = %lld", sizeof(__INT64_TYPE__));
|
||||
debug("--- INT TYPES ---");
|
||||
debug("sizeof(__INT8_TYPE__) = %lld", sizeof(__INT8_TYPE__));
|
||||
debug("sizeof(__INT16_TYPE__) = %lld", sizeof(__INT16_TYPE__));
|
||||
debug("sizeof(__INT32_TYPE__) = %lld", sizeof(__INT32_TYPE__));
|
||||
debug("sizeof(__INT64_TYPE__) = %lld", sizeof(__INT64_TYPE__));
|
||||
|
||||
debug("-- UINT TYPES ---");
|
||||
debug("sizeof(__UINT8_TYPE__) = %lld", sizeof(__INT8_TYPE__));
|
||||
debug("sizeof(__UINT16_TYPE__) = %lld", sizeof(__INT16_TYPE__));
|
||||
debug("sizeof(__UINT32_TYPE__) = %lld", sizeof(__INT32_TYPE__));
|
||||
debug("sizeof(__UINT64_TYPE__) = %lld", sizeof(__INT64_TYPE__));
|
||||
debug("-- UINT TYPES ---");
|
||||
debug("sizeof(__UINT8_TYPE__) = %lld", sizeof(__INT8_TYPE__));
|
||||
debug("sizeof(__UINT16_TYPE__) = %lld", sizeof(__INT16_TYPE__));
|
||||
debug("sizeof(__UINT32_TYPE__) = %lld", sizeof(__INT32_TYPE__));
|
||||
debug("sizeof(__UINT64_TYPE__) = %lld", sizeof(__INT64_TYPE__));
|
||||
|
||||
debug("--- INT LEAST TYPES ---");
|
||||
debug("sizeof(__INT_LEAST8_TYPE__) = %lld", sizeof(__INT_LEAST8_TYPE__));
|
||||
debug("sizeof(__INT_LEAST16_TYPE__) = %lld", sizeof(__INT_LEAST16_TYPE__));
|
||||
debug("sizeof(__INT_LEAST32_TYPE__) = %lld", sizeof(__INT_LEAST32_TYPE__));
|
||||
debug("sizeof(__INT_LEAST64_TYPE__) = %lld", sizeof(__INT_LEAST64_TYPE__));
|
||||
debug("--- INT LEAST TYPES ---");
|
||||
debug("sizeof(__INT_LEAST8_TYPE__) = %lld", sizeof(__INT_LEAST8_TYPE__));
|
||||
debug("sizeof(__INT_LEAST16_TYPE__) = %lld", sizeof(__INT_LEAST16_TYPE__));
|
||||
debug("sizeof(__INT_LEAST32_TYPE__) = %lld", sizeof(__INT_LEAST32_TYPE__));
|
||||
debug("sizeof(__INT_LEAST64_TYPE__) = %lld", sizeof(__INT_LEAST64_TYPE__));
|
||||
|
||||
debug("--- UINT LEAST TYPES ---");
|
||||
debug("sizeof(__UINT_LEAST8_TYPE__) = %lld", sizeof(__UINT_LEAST8_TYPE__));
|
||||
debug("sizeof(__UINT_LEAST16_TYPE__) = %lld", sizeof(__UINT_LEAST16_TYPE__));
|
||||
debug("sizeof(__UINT_LEAST32_TYPE__) = %lld", sizeof(__UINT_LEAST32_TYPE__));
|
||||
debug("sizeof(__UINT_LEAST64_TYPE__) = %lld", sizeof(__UINT_LEAST64_TYPE__));
|
||||
debug("--- UINT LEAST TYPES ---");
|
||||
debug("sizeof(__UINT_LEAST8_TYPE__) = %lld", sizeof(__UINT_LEAST8_TYPE__));
|
||||
debug("sizeof(__UINT_LEAST16_TYPE__) = %lld", sizeof(__UINT_LEAST16_TYPE__));
|
||||
debug("sizeof(__UINT_LEAST32_TYPE__) = %lld", sizeof(__UINT_LEAST32_TYPE__));
|
||||
debug("sizeof(__UINT_LEAST64_TYPE__) = %lld", sizeof(__UINT_LEAST64_TYPE__));
|
||||
|
||||
debug("--- INT FAST TYPES ---");
|
||||
debug("sizeof(__INT_FAST8_TYPE__) = %lld", sizeof(__INT_FAST8_TYPE__));
|
||||
debug("sizeof(__INT_FAST16_TYPE__) = %lld", sizeof(__INT_FAST16_TYPE__));
|
||||
debug("sizeof(__INT_FAST32_TYPE__) = %lld", sizeof(__INT_FAST32_TYPE__));
|
||||
debug("sizeof(__INT_FAST64_TYPE__) = %lld", sizeof(__INT_FAST64_TYPE__));
|
||||
debug("--- INT FAST TYPES ---");
|
||||
debug("sizeof(__INT_FAST8_TYPE__) = %lld", sizeof(__INT_FAST8_TYPE__));
|
||||
debug("sizeof(__INT_FAST16_TYPE__) = %lld", sizeof(__INT_FAST16_TYPE__));
|
||||
debug("sizeof(__INT_FAST32_TYPE__) = %lld", sizeof(__INT_FAST32_TYPE__));
|
||||
debug("sizeof(__INT_FAST64_TYPE__) = %lld", sizeof(__INT_FAST64_TYPE__));
|
||||
|
||||
debug("--- UINT FAST TYPES ---");
|
||||
debug("sizeof(__UINT_FAST8_TYPE__) = %lld", sizeof(__UINT_FAST8_TYPE__));
|
||||
debug("sizeof(__UINT_FAST16_TYPE__) = %lld", sizeof(__UINT_FAST16_TYPE__));
|
||||
debug("sizeof(__UINT_FAST32_TYPE__) = %lld", sizeof(__UINT_FAST32_TYPE__));
|
||||
debug("sizeof(__UINT_FAST64_TYPE__) = %lld", sizeof(__UINT_FAST64_TYPE__));
|
||||
debug("--- UINT FAST TYPES ---");
|
||||
debug("sizeof(__UINT_FAST8_TYPE__) = %lld", sizeof(__UINT_FAST8_TYPE__));
|
||||
debug("sizeof(__UINT_FAST16_TYPE__) = %lld", sizeof(__UINT_FAST16_TYPE__));
|
||||
debug("sizeof(__UINT_FAST32_TYPE__) = %lld", sizeof(__UINT_FAST32_TYPE__));
|
||||
debug("sizeof(__UINT_FAST64_TYPE__) = %lld", sizeof(__UINT_FAST64_TYPE__));
|
||||
|
||||
debug("--- INTPTR TYPES ---");
|
||||
debug("sizeof(__INTPTR_TYPE__) = %lld", sizeof(__INTPTR_TYPE__));
|
||||
debug("sizeof(__UINTPTR_TYPE__) = %lld", sizeof(__UINTPTR_TYPE__));
|
||||
debug("--- INTPTR TYPES ---");
|
||||
debug("sizeof(__INTPTR_TYPE__) = %lld", sizeof(__INTPTR_TYPE__));
|
||||
debug("sizeof(__UINTPTR_TYPE__) = %lld", sizeof(__UINTPTR_TYPE__));
|
||||
|
||||
debug("--- OTHER TYPES ---");
|
||||
debug("sizeof(__PTRDIFF_TYPE__) = %lld", sizeof(__PTRDIFF_TYPE__));
|
||||
debug("sizeof(__SIZE_TYPE__) = %lld", sizeof(__SIZE_TYPE__));
|
||||
debug("sizeof(__WCHAR_TYPE__) = %lld", sizeof(__WCHAR_TYPE__));
|
||||
debug("sizeof(__WINT_TYPE__) = %lld", sizeof(__WINT_TYPE__));
|
||||
debug("sizeof(__SIG_ATOMIC_TYPE__) = %lld", sizeof(__SIG_ATOMIC_TYPE__));
|
||||
debug("--- OTHER TYPES ---");
|
||||
debug("sizeof(__PTRDIFF_TYPE__) = %lld", sizeof(__PTRDIFF_TYPE__));
|
||||
debug("sizeof(__SIZE_TYPE__) = %lld", sizeof(__SIZE_TYPE__));
|
||||
debug("sizeof(__WCHAR_TYPE__) = %lld", sizeof(__WCHAR_TYPE__));
|
||||
debug("sizeof(__WINT_TYPE__) = %lld", sizeof(__WINT_TYPE__));
|
||||
debug("sizeof(__SIG_ATOMIC_TYPE__) = %lld", sizeof(__SIG_ATOMIC_TYPE__));
|
||||
|
||||
debug("--- INTX MAX TYPES ---");
|
||||
debug("__INT8_MAX__ = %#llx", __INT8_MAX__);
|
||||
debug("__INT16_MAX__ = %#llx", __INT16_MAX__);
|
||||
debug("__INT32_MAX__ = %#llx", __INT32_MAX__);
|
||||
debug("__INT64_MAX__ = %#llx", __INT64_MAX__);
|
||||
debug("--- INTX MAX TYPES ---");
|
||||
debug("__INT8_MAX__ = %#llx", __INT8_MAX__);
|
||||
debug("__INT16_MAX__ = %#llx", __INT16_MAX__);
|
||||
debug("__INT32_MAX__ = %#llx", __INT32_MAX__);
|
||||
debug("__INT64_MAX__ = %#llx", __INT64_MAX__);
|
||||
|
||||
debug("--- UINTX MAX TYPES ---");
|
||||
debug("__UINT8_MAX__ = %#llx", __UINT8_MAX__);
|
||||
debug("__UINT16_MAX__ = %#llx", __UINT16_MAX__);
|
||||
debug("__UINT32_MAX__ = %#llx", __UINT32_MAX__);
|
||||
debug("__UINT64_MAX__ = %#llx", __UINT64_MAX__);
|
||||
debug("--- UINTX MAX TYPES ---");
|
||||
debug("__UINT8_MAX__ = %#llx", __UINT8_MAX__);
|
||||
debug("__UINT16_MAX__ = %#llx", __UINT16_MAX__);
|
||||
debug("__UINT32_MAX__ = %#llx", __UINT32_MAX__);
|
||||
debug("__UINT64_MAX__ = %#llx", __UINT64_MAX__);
|
||||
|
||||
// debug("--- INTMAX TYPES ---");
|
||||
// debug("__INTMAX_TYPE__ = %#llx", __INTMAX_TYPE__);
|
||||
// debug("__UINTMAX_TYPE__ = %#llx", __UINTMAX_TYPE__);
|
||||
// debug("--- INTMAX TYPES ---");
|
||||
// debug("__INTMAX_TYPE__ = %#llx", __INTMAX_TYPE__);
|
||||
// debug("__UINTMAX_TYPE__ = %#llx", __UINTMAX_TYPE__);
|
||||
|
||||
debug("--- INTLEASTX MAX ---");
|
||||
debug("__INT_LEAST8_MAX__ = %#llx", __INT_LEAST8_MAX__);
|
||||
debug("__INT_LEAST16_MAX__ = %#llx", __INT_LEAST16_MAX__);
|
||||
debug("__INT_LEAST32_MAX__ = %#llx", __INT_LEAST32_MAX__);
|
||||
debug("__INT_LEAST64_MAX__ = %#llx", __INT_LEAST64_MAX__);
|
||||
debug("--- INTLEASTX MAX ---");
|
||||
debug("__INT_LEAST8_MAX__ = %#llx", __INT_LEAST8_MAX__);
|
||||
debug("__INT_LEAST16_MAX__ = %#llx", __INT_LEAST16_MAX__);
|
||||
debug("__INT_LEAST32_MAX__ = %#llx", __INT_LEAST32_MAX__);
|
||||
debug("__INT_LEAST64_MAX__ = %#llx", __INT_LEAST64_MAX__);
|
||||
|
||||
debug("--- UINTLEASTX MAX ---");
|
||||
debug("__UINT_LEAST8_MAX__ = %#llx", __UINT_LEAST8_MAX__);
|
||||
debug("__UINT_LEAST16_MAX__ = %#llx", __UINT_LEAST16_MAX__);
|
||||
debug("--- UINTLEASTX MAX ---");
|
||||
debug("__UINT_LEAST8_MAX__ = %#llx", __UINT_LEAST8_MAX__);
|
||||
debug("__UINT_LEAST16_MAX__ = %#llx", __UINT_LEAST16_MAX__);
|
||||
|
||||
debug("--- INTFASTX MAX ---");
|
||||
debug("__INT_FAST8_MAX__ = %#llx", __INT_FAST8_MAX__);
|
||||
debug("__INT_FAST16_MAX__ = %#llx", __INT_FAST16_MAX__);
|
||||
debug("__INT_FAST32_MAX__ = %#llx", __INT_FAST32_MAX__);
|
||||
debug("__INT_FAST64_MAX__ = %#llx", __INT_FAST64_MAX__);
|
||||
debug("--- INTFASTX MAX ---");
|
||||
debug("__INT_FAST8_MAX__ = %#llx", __INT_FAST8_MAX__);
|
||||
debug("__INT_FAST16_MAX__ = %#llx", __INT_FAST16_MAX__);
|
||||
debug("__INT_FAST32_MAX__ = %#llx", __INT_FAST32_MAX__);
|
||||
debug("__INT_FAST64_MAX__ = %#llx", __INT_FAST64_MAX__);
|
||||
|
||||
debug("--- UINTFASTX MAX ---");
|
||||
debug("__UINT_FAST8_MAX__ = %#llx", __UINT_FAST8_MAX__);
|
||||
debug("__UINT_FAST16_MAX__ = %#llx", __UINT_FAST16_MAX__);
|
||||
debug("__UINT_FAST32_MAX__ = %#llx", __UINT_FAST32_MAX__);
|
||||
debug("__UINT_FAST64_MAX__ = %#llx", __UINT_FAST64_MAX__);
|
||||
debug("--- UINTFASTX MAX ---");
|
||||
debug("__UINT_FAST8_MAX__ = %#llx", __UINT_FAST8_MAX__);
|
||||
debug("__UINT_FAST16_MAX__ = %#llx", __UINT_FAST16_MAX__);
|
||||
debug("__UINT_FAST32_MAX__ = %#llx", __UINT_FAST32_MAX__);
|
||||
debug("__UINT_FAST64_MAX__ = %#llx", __UINT_FAST64_MAX__);
|
||||
|
||||
debug("--- INTPTR MAX ---");
|
||||
debug("__INTPTR_MAX__ = %#llx", __INTPTR_MAX__);
|
||||
debug("__UINTPTR_MAX__ = %#llx", __UINTPTR_MAX__);
|
||||
debug("--- INTPTR MAX ---");
|
||||
debug("__INTPTR_MAX__ = %#llx", __INTPTR_MAX__);
|
||||
debug("__UINTPTR_MAX__ = %#llx", __UINTPTR_MAX__);
|
||||
|
||||
debug("--- OTHER MAX ---");
|
||||
debug("__PTRDIFF_MAX__ = %#llx", __PTRDIFF_MAX__);
|
||||
debug("__SIZE_MAX__ = %#llx", __SIZE_MAX__);
|
||||
debug("__WCHAR_MAX__ = %#llx", __WCHAR_MAX__);
|
||||
debug("__WINT_MAX__ = %#llx", __WINT_MAX__);
|
||||
debug("__SIG_ATOMIC_MAX__ = %#llx", __SIG_ATOMIC_MAX__);
|
||||
debug("__INTMAX_MAX__ = %#llx", __INTMAX_MAX__);
|
||||
debug("__UINTMAX_MAX__ = %#llx", __UINTMAX_MAX__);
|
||||
debug("--- OTHER MAX ---");
|
||||
debug("__PTRDIFF_MAX__ = %#llx", __PTRDIFF_MAX__);
|
||||
debug("__SIZE_MAX__ = %#llx", __SIZE_MAX__);
|
||||
debug("__WCHAR_MAX__ = %#llx", __WCHAR_MAX__);
|
||||
debug("__WINT_MAX__ = %#llx", __WINT_MAX__);
|
||||
debug("__SIG_ATOMIC_MAX__ = %#llx", __SIG_ATOMIC_MAX__);
|
||||
debug("__INTMAX_MAX__ = %#llx", __INTMAX_MAX__);
|
||||
debug("__UINTMAX_MAX__ = %#llx", __UINTMAX_MAX__);
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
||||
|
@@ -19,18 +19,51 @@
|
||||
|
||||
#include <std.hpp>
|
||||
#include <assert.h>
|
||||
#include <vector>
|
||||
|
||||
__constructor void Test_std()
|
||||
void Test_std()
|
||||
{
|
||||
std::atomic_int a = 0;
|
||||
a++;
|
||||
assert(a == 1);
|
||||
std::atomic_int a = 0;
|
||||
a++;
|
||||
assert(a == 1);
|
||||
|
||||
int b = a.exchange(2);
|
||||
assert(b == 1);
|
||||
assert(a == 2);
|
||||
int b = a.exchange(2);
|
||||
assert(b == 1);
|
||||
assert(a == 2);
|
||||
|
||||
debug("std: OK");
|
||||
/* ---------------------------- */
|
||||
|
||||
std::vector<int> intVector;
|
||||
intVector.push_back(10);
|
||||
intVector.push_back(20);
|
||||
intVector.push_back(30);
|
||||
assert(intVector.size() == 3);
|
||||
|
||||
assert(intVector[0] == 10);
|
||||
assert(intVector[1] == 20);
|
||||
assert(intVector[2] == 30);
|
||||
|
||||
intVector.pop_back();
|
||||
assert(intVector.size() == 2);
|
||||
|
||||
intVector.clear();
|
||||
assert(intVector.empty());
|
||||
|
||||
intVector.push_back(1);
|
||||
intVector.push_back(1);
|
||||
intVector.push_back(1);
|
||||
intVector.push_back(1);
|
||||
intVector.push_back(1);
|
||||
|
||||
intVector.erase(intVector.end() - 1);
|
||||
assert(intVector.size() == 4);
|
||||
debug("0: %#lx", intVector[0]);
|
||||
debug("1: %#lx", intVector[1]);
|
||||
debug("2: %#lx", intVector[2]);
|
||||
debug("3: %#lx", intVector[3]);
|
||||
debug("4: %#lx", intVector[4]);
|
||||
|
||||
debug("std: OK");
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
||||
|
Reference in New Issue
Block a user