| 65 | } |
| 66 | |
| 67 | auto test_fifo_ordering() -> bool { |
| 68 | klog::Info("Running test_fifo_ordering..."); |
| 69 | |
| 70 | FifoScheduler scheduler; |
| 71 | constexpr size_t kTaskCount = 10; |
| 72 | TaskControlBlock* tasks[kTaskCount]; |
| 73 | |
| 74 | // 初始化任务 |
| 75 | for (size_t i = 0; i < kTaskCount; ++i) { |
| 76 | tasks[i] = new TaskControlBlock("Task", 10, nullptr, nullptr); |
| 77 | tasks[i]->fsm.Receive(MsgSchedule{}); |
| 78 | scheduler.Enqueue(tasks[i]); |
| 79 | } |
| 80 | |
| 81 | EXPECT_EQ(scheduler.GetQueueSize(), kTaskCount, |
| 82 | "Queue size should match task count"); |
| 83 | |
| 84 | // 验证严格的 FIFO 顺序 |
| 85 | for (size_t i = 0; i < kTaskCount; ++i) { |
| 86 | auto* picked = scheduler.PickNext(); |
| 87 | EXPECT_NE(picked, nullptr, "Picked task should not be nullptr"); |
| 88 | EXPECT_EQ(picked, tasks[i], "Task should be picked in FIFO order"); |
| 89 | } |
| 90 | |
| 91 | EXPECT_TRUE(scheduler.IsEmpty(), "Scheduler should be empty after all picks"); |
| 92 | |
| 93 | // 清理内存 |
| 94 | for (size_t i = 0; i < kTaskCount; ++i) { |
| 95 | delete tasks[i]; |
| 96 | } |
| 97 | |
| 98 | klog::Info("test_fifo_ordering passed"); |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | auto test_fifo_dequeue() -> bool { |
| 103 | klog::Info("Running test_fifo_dequeue..."); |
no test coverage detected