|
SimpleKernel 1.17.0
|
测试环境状态 More...
#include <test_environment_state.hpp>

Public Member Functions | |
| TestEnvironmentState ()=default | |
| ~TestEnvironmentState ()=default | |
| TestEnvironmentState (const TestEnvironmentState &)=delete | |
| TestEnvironmentState (TestEnvironmentState &&)=delete | |
| auto | operator= (const TestEnvironmentState &) -> TestEnvironmentState &=delete |
| auto | operator= (TestEnvironmentState &&) -> TestEnvironmentState &=delete |
| void | InitializeCores (size_t num_cores) |
| 初始化指定数量的核心 | |
| void | ResetAllCores () |
| 重置所有核心状态(中断、页表、历史记录) | |
| auto | GetCore (size_t core_id) -> CoreEnvironment & |
| 获取指定核心的环境 | |
| auto | GetCoreCount () const -> size_t |
| 获取核心数量 | |
| void | BindThreadToCore (std::thread::id tid, size_t core_id) |
| 将指定线程绑定到核心 | |
| auto | GetCoreIdForThread (std::thread::id tid) -> size_t |
| 获取线程对应的核心 ID | |
| auto | GetCurrentCoreEnv () -> CoreEnvironment & |
| 获取当前线程的核心环境 | |
| void | RegisterTaskContext (void *context_ptr, TaskControlBlock *task) |
| 注册任务上下文,建立上下文指针到任务的映射 | |
| void | UnregisterTaskContext (void *context_ptr) |
| 注销任务上下文 | |
| auto | FindTaskByContext (void *context_ptr) -> TaskControlBlock * |
| 通过上下文指针查找任务 | |
| void | DumpAllCoreStates () const |
| 打印所有核心的状态信息 | |
| auto | GetAllSwitchHistory () const -> std::vector< CoreEnvironment::SwitchEvent > |
| 获取所有核心的切换历史,按时间戳排序 | |
| void | ClearSwitchHistory () |
| 清空所有核心的切换历史 | |
| void | SetCurrentThreadEnvironment () |
| 设置当前线程的环境实例指针 | |
| void | ClearCurrentThreadEnvironment () |
| 清除当前线程的环境实例指针 | |
Static Public Member Functions | |
| static auto | GetCurrentThreadEnvironment () -> TestEnvironmentState * |
| 获取当前线程的环境实例指针(供 Mock 层调用) | |
Private Attributes | |
| std::vector< CoreEnvironment > | cores_ |
| std::unordered_map< std::thread::id, size_t > | thread_to_core_map_ |
| std::unordered_map< void *, TaskControlBlock * > | context_to_task_map_ |
| std::mutex | map_mutex_ |
| size_t | next_core_id_ = 0 |
测试环境状态
设计说明:
工作流程:
示例:
Definition at line 86 of file test_environment_state.hpp.
|
default |
|
default |
|
delete |
|
delete |
| void test_env::TestEnvironmentState::BindThreadToCore | ( | std::thread::id | tid, |
| size_t | core_id | ||
| ) |
将指定线程绑定到核心
| tid | 线程 ID |
| core_id | 核心 ID |
Definition at line 66 of file test_environment_state.cpp.

| void test_env::TestEnvironmentState::ClearCurrentThreadEnvironment | ( | ) |
清除当前线程的环境实例指针
Definition at line 22 of file test_environment_state.cpp.

| void test_env::TestEnvironmentState::ClearSwitchHistory | ( | ) |
清空所有核心的切换历史
Definition at line 162 of file test_environment_state.cpp.

| void test_env::TestEnvironmentState::DumpAllCoreStates | ( | ) | const |
打印所有核心的状态信息
Definition at line 127 of file test_environment_state.cpp.
| auto test_env::TestEnvironmentState::FindTaskByContext | ( | void * | context_ptr | ) | -> TaskControlBlock* |
通过上下文指针查找任务
Definition at line 117 of file test_environment_state.cpp.
| auto test_env::TestEnvironmentState::GetAllSwitchHistory | ( | ) | const -> std::vector<CoreEnvironment::SwitchEvent> |
获取所有核心的切换历史,按时间戳排序
Definition at line 144 of file test_environment_state.cpp.
| auto test_env::TestEnvironmentState::GetCore | ( | size_t | core_id | ) | -> CoreEnvironment& |
获取指定核心的环境
| core_id | 核心 ID |
| std::out_of_range | 如果 core_id 无效 |
Definition at line 53 of file test_environment_state.cpp.
| auto test_env::TestEnvironmentState::GetCoreCount | ( | ) | const -> size_t |
获取核心数量
Definition at line 61 of file test_environment_state.cpp.
| auto test_env::TestEnvironmentState::GetCoreIdForThread | ( | std::thread::id | tid | ) | -> size_t |
获取线程对应的核心 ID
| tid | 线程 ID |
Definition at line 76 of file test_environment_state.cpp.
| auto test_env::TestEnvironmentState::GetCurrentCoreEnv | ( | ) | -> CoreEnvironment& |
获取当前线程的核心环境
Definition at line 99 of file test_environment_state.cpp.
|
static |
获取当前线程的环境实例指针(供 Mock 层调用)
用法:Mock 层(cpu_io.h、arch.cpp)通过这个函数获取当前测试的环境 例如:auto* env = TestEnvironmentState::GetCurrentThreadEnvironment();
Definition at line 26 of file test_environment_state.cpp.

| void test_env::TestEnvironmentState::InitializeCores | ( | size_t | num_cores | ) |
初始化指定数量的核心
| num_cores | 核心数量 |
Definition at line 31 of file test_environment_state.cpp.

|
delete |
|
delete |
| void test_env::TestEnvironmentState::RegisterTaskContext | ( | void * | context_ptr, |
| TaskControlBlock * | task | ||
| ) |
注册任务上下文,建立上下文指针到任务的映射
| context_ptr | 任务的上下文指针(&task.task_context) |
| task | 任务指针 |
Definition at line 106 of file test_environment_state.cpp.
| void test_env::TestEnvironmentState::ResetAllCores | ( | ) |
重置所有核心状态(中断、页表、历史记录)
Definition at line 40 of file test_environment_state.cpp.
| void test_env::TestEnvironmentState::SetCurrentThreadEnvironment | ( | ) |
设置当前线程的环境实例指针
原理:设置一个 thread_local 指针指向 this 效果:同一线程中,Mock 层可以通过 GetCurrentThreadEnvironment() 获取这个环境
Definition at line 18 of file test_environment_state.cpp.

| void test_env::TestEnvironmentState::UnregisterTaskContext | ( | void * | context_ptr | ) |
注销任务上下文
Definition at line 112 of file test_environment_state.cpp.
|
private |
Definition at line 211 of file test_environment_state.hpp.
|
private |
Definition at line 205 of file test_environment_state.hpp.
|
mutableprivate |
Definition at line 214 of file test_environment_state.hpp.
|
private |
Definition at line 217 of file test_environment_state.hpp.
|
private |
Definition at line 208 of file test_environment_state.hpp.