| 182 | } |
| 183 | |
| 184 | auto test_cfs_preemption() -> bool { |
| 185 | klog::Info("Running test_cfs_preemption..."); |
| 186 | |
| 187 | CfsScheduler scheduler; |
| 188 | |
| 189 | TaskControlBlock task1("Task1", 1, nullptr, nullptr); |
| 190 | task1.sched_data.cfs.weight = CfsScheduler::kDefaultWeight; |
| 191 | task1.sched_data.cfs.vruntime = 1000; |
| 192 | |
| 193 | TaskControlBlock task2("Task2", 2, nullptr, nullptr); |
| 194 | task2.sched_data.cfs.weight = CfsScheduler::kDefaultWeight; |
| 195 | task2.sched_data.cfs.vruntime = 0; // 更小的 vruntime |
| 196 | |
| 197 | scheduler.Enqueue(&task2); |
| 198 | |
| 199 | // task1 运行时,应该被抢占 |
| 200 | bool should_preempt = scheduler.OnTick(&task1); |
| 201 | EXPECT_TRUE(should_preempt, "Task with higher vruntime should be preempted"); |
| 202 | |
| 203 | klog::Info("test_cfs_preemption passed"); |
| 204 | return true; |
| 205 | } |
| 206 | |
| 207 | auto test_cfs_no_preemption() -> bool { |
| 208 | klog::Info("Running test_cfs_no_preemption..."); |
no test coverage detected