diff --git a/Task 1/unittest_1.cpp b/Task 1/unittest_1.cpp index 535a0d2c2f8efc974b684b24edc8d14fc1f0fbdf..26eb8986be03491fd5a9157af4fab1300b4d9cf0 100644 --- a/Task 1/unittest_1.cpp +++ b/Task 1/unittest_1.cpp @@ -28,14 +28,17 @@ DEFINE_TEST(TestFiberStackAlignment) { } // Test Fiber Stack Size -DEFINE_TEST(TestFiberStackSize) { - Fiber testFiber([](Context*, Context*){}); - char* stackBottom = testFiber.stack_bottom_; // Assuming stack_bottom_ points to the beginning of the stack - char* stackTop = testFiber.stack_top_; // stack_top_ should point to the top of the stack (end of allocation) +DEFINE_TEST(TestFiberStackAlignmentAndPosition) { + Fiber testFiber([](Context*, Context*){}, nullptr); + uintptr_t stackPtr = reinterpret_cast<uintptr_t>(testFiber.context.rsp); + + // Check alignment + TEST_EQ(stackPtr % 16, 0); // Stack should be 16-byte aligned - // Since stack grows downwards, stackTop should be a smaller address than stackBottom - int actualStackSize = stackBottom - stackTop; - TEST_EQ(actualStackSize, StackSize - 128); // Check for expected stack size accounting for Red Zone + // Assuming the stack grows downwards, stackPtr should be less than the address of stack[] + uintptr_t stackArrayPtr = reinterpret_cast<uintptr_t>(testFiber.stack); + TEST_TRUE(stackPtr < stackArrayPtr); + TEST_TRUE(stackPtr >= stackArrayPtr - StackSize); // Within the bounds of the stack } // Test Fiber Context Initialization