Skip to content
Snippets Groups Projects
Commit 2ae841e6 authored by t2-akhmetov's avatar t2-akhmetov
Browse files

Add new file

parent 6cd62e17
No related branches found
No related tags found
No related merge requests found
#include "../simpletest/simpletest.h"
#include <iostream>
#include <cstdlib>
struct Fiber {
char stack[StackSize];
Context context;
Fiber(void(*func)(Context*, Context*)) {
char* sp = stack + sizeof(stack);
sp = reinterpret_cast<char*>((reinterpret_cast<uintptr_t>(sp)) & -16L); // Align stack
sp -= 128; // Account for Red Zone
context.rip = (void*)func;
context.rsp = (void*)sp;
}
};
// Test Fiber Stack Alignment
DEFINE_TEST(TestFiberStackAlignment) {
Fiber testFiber([](Context*, Context*){});
uintptr_t stackPtr = reinterpret_cast<uintptr_t>(testFiber.context.rsp);
TEST_EQ(stackPtr % 16, 0); // Stack should be 16-byte aligned
}
// Test Fiber Stack Size
DEFINE_TEST(TestFiberStackSize) {
Fiber testFiber([](Context*, Context*){});
char* stackBottom = reinterpret_cast<char*>(testFiber.context.rsp);
char* stackTop = testFiber.stack;
TEST_EQ(stackTop - stackBottom, StackSize - 128); // Check for expected stack size accounting for Red Zone
}
// Test Fiber Context Initialization
DEFINE_TEST(TestFiberContextInitialization) {
Fiber testFiber([](Context* mc, Context* sc){ swap_context(sc, mc); });
TEST_NEQ(testFiber.context.rip, nullptr); // Instruction Pointer should not be null
TEST_NEQ(testFiber.context.rsp, nullptr); // Stack Pointer should not be null
}
int main() {
TestFixture::ExecuteAllTests();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment