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

Add new file

parent 27616d32
Branches
No related tags found
No related merge requests found
#include "../simpletest/simpletest.h"
#include "scheduler.h"
// Test for fiber finish state toggle
DEFINE_TEST(TestFiberFinishStateToggle) {
void* dummyFunc = reinterpret_cast<void*>(+[](Context*, Context*){});
Fiber testFiber(reinterpret_cast<void(*)(Context*, Context*)>(dummyFunc), nullptr);
// Initially not finished
TEST_EQ(testFiber.isFinished(), false);
// Toggle finish state
testFiber.setFinished(true);
TEST_EQ(testFiber.isFinished(), true);
}
// Test scheduler spawn and execution flow
DEFINE_TEST(TestSchedulerSpawnAndExecution) {
Scheduler scheduler;
void* dummyFunc = reinterpret_cast<void*>(+[](Context*, Context*){});
// Create and spawn fibers
Fiber* fiber1 = new Fiber(reinterpret_cast<void(*)(Context*, Context*)>(dummyFunc), nullptr);
Fiber* fiber2 = new Fiber(reinterpret_cast<void(*)(Context*, Context*)>(dummyFunc), nullptr);
scheduler.spawn(fiber1);
scheduler.spawn(fiber2);
// Check if fibers are added to the queue
TEST_EQ(scheduler.hasFibers(), true);
// Note: Actual context switching cannot be tested here
// Assuming do_it would process the fibers correctly
scheduler.do_it();
// After execution, no fibers should be left
TEST_EQ(scheduler.hasFibers(), false);
}
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