diff --git a/Task 2/unittest_1.cpp b/Task 2/unittest_1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2714c653e03bf51945d6b419b71a4350be51b804 --- /dev/null +++ b/Task 2/unittest_1.cpp @@ -0,0 +1,26 @@ +#include "../simpletest/simpletest.h" +#include "scheduler.h" + +DEFINE_TEST(TestFiberInitialization) { + void* dummyFunc = reinterpret_cast<void*>(+[](Context*, Context*){}); + int sharedData = 42; + Fiber testFiber(reinterpret_cast<void(*)(Context*, Context*)>(dummyFunc), &sharedData); + + TEST_EQ(testFiber.getSharedData(), &sharedData); +} + +// Test for fiber stack alignment +DEFINE_TEST(TestFiberStackAlignment) { + void* dummyFunc = reinterpret_cast<void*>(+[](Context*, Context*){}); + Fiber testFiber(reinterpret_cast<void(*)(Context*, Context*)>(dummyFunc), nullptr); + + uintptr_t stackPtr = reinterpret_cast<uintptr_t>(testFiber.get_context()->rsp); + TEST_EQ(stackPtr % 16, 0); +} + +// More tests go here... + +int main() { + TestFixture::ExecuteAllTests(); + return 0; +}