SimpleKernel 1.17.0
Loading...
Searching...
No Matches
TaskTestHarness Class Reference

Task 模块单元测试的基类 Fixture. More...

#include <task_test_harness.hpp>

Inheritance diagram for TaskTestHarness:
Inheritance graph
Collaboration diagram for TaskTestHarness:
Collaboration graph

Protected Member Functions

void SetUp () override
 
void TearDown () override
 
void SetNumCores (size_t num_cores)
 设置测试使用的核心数量(在 SetUp 前调用)
 
auto GetEnvironmentState () -> test_env::TestEnvironmentState &
 获取环境层状态
 

Protected Attributes

size_t num_cores_ = 1
 
test_env::TestEnvironmentState env_state_
 

Detailed Description

Task 模块单元测试的基类 Fixture.

负责每个测试的 SetUp 和 TearDown,确保测试隔离

Definition at line 19 of file task_test_harness.hpp.

Member Function Documentation

◆ GetEnvironmentState()

auto TaskTestHarness::GetEnvironmentState ( ) -> test_env::TestEnvironmentState&
inlineprotected

获取环境层状态

Definition at line 32 of file task_test_harness.hpp.

32 {
33 return env_state_;
34 }
test_env::TestEnvironmentState env_state_

◆ SetNumCores()

void TaskTestHarness::SetNumCores ( size_t  num_cores)
inlineprotected

设置测试使用的核心数量(在 SetUp 前调用)

Definition at line 27 of file task_test_harness.hpp.

27{ num_cores_ = num_cores; }

◆ SetUp()

void TaskTestHarness::SetUp ( )
overrideprotected

Definition at line 12 of file task_test_harness.cpp.

12 {
13 // 1. 初始化环境层(每个测试都有独立实例)
15
16 // 2. 设置当前线程的环境指针(让 Mock 层可以访问)
18
19 // 3. 绑定主测试线程到 core 0
20 env_state_.BindThreadToCore(std::this_thread::get_id(), 0);
21
22 // 3. 重置 PerCpu 数据
23 per_cpu::PerCpuArraySingleton::create();
24 auto& per_cpu_array = per_cpu::PerCpuArraySingleton::instance();
25 for (size_t i = 0; i < SIMPLEKERNEL_MAX_CORE_COUNT; ++i) {
26 per_cpu_array[i] = per_cpu::PerCpu(i);
27 }
28
29 // 4. 重置 TaskManager(如果有 ResetForTesting 方法)
30 // 注意:这需要在 TaskManager 中实现
31 // TaskManagerSingleton::instance().ResetForTesting();
32}
void BindThreadToCore(std::thread::id tid, size_t core_id)
将指定线程绑定到核心
void InitializeCores(size_t num_cores)
初始化指定数量的核心
void SetCurrentThreadEnvironment()
设置当前线程的环境实例指针
每个 CPU 核心的局部数据
Definition per_cpu.hpp:23
Here is the call graph for this function:

◆ TearDown()

void TaskTestHarness::TearDown ( )
overrideprotected

Definition at line 34 of file task_test_harness.cpp.

34 {
35 per_cpu::PerCpuArraySingleton::destroy();
36 // 清除当前线程的环境指针
38
39 // 其他清理
41}
void ClearCurrentThreadEnvironment()
清除当前线程的环境实例指针
void ClearSwitchHistory()
清空所有核心的切换历史
Here is the call graph for this function:

Member Data Documentation

◆ env_state_

test_env::TestEnvironmentState TaskTestHarness::env_state_
protected

Definition at line 37 of file task_test_harness.hpp.

◆ num_cores_

size_t TaskTestHarness::num_cores_ = 1
protected

Definition at line 36 of file task_test_harness.hpp.


The documentation for this class was generated from the following files: