SimpleKernel 1.17.0
Loading...
Searching...
No Matches
spinlock_test.cpp File Reference
#include "spinlock.hpp"
#include <etl/format.h>
#include <atomic>
#include <cstdint>
#include "basic_info.hpp"
#include "cpu_io.h"
#include "system_test.h"
Include dependency graph for spinlock_test.cpp:

Go to the source code of this file.

Functions

auto spinlock_test () -> bool
 

Function Documentation

◆ spinlock_test()

auto spinlock_test ( ) -> bool

Definition at line 348 of file spinlock_test.cpp.

348 {
349 bool ret = true;
351
352 // 单元测试仅在核心 0 上运行,以避免日志混乱
353 if (core_id == 0) {
354 klog::Info("Starting spinlock_test");
355 ret = ret && test_basic_lock();
356 ret = ret && test_recursive_lock();
357 ret = ret && test_lock_guard();
358 ret = ret && test_interrupt_restore();
359 }
360
361 // SMP (多核) 测试在所有核心上运行
362 // 使用顺序执行以确保如果前一个测试失败,屏障不会死锁
363 if (!spinlock_smp_test()) ret = false;
364 if (!spinlock_smp_buffer_test()) ret = false;
365 if (!spinlock_smp_string_test()) ret = false;
366
367 if (core_id == 0) {
368 if (ret) {
369 klog::Info("spinlock_test passed");
370 } else {
371 klog::Err("spinlock_test failed");
372 }
373 }
374 return ret;
375}
auto GetCurrentCoreId() -> size_t
Definition cpu_io.h:26
auto Err(etl::format_string< Args... > fmt, Args &&... args) -> void
以 ERROR 级别记录日志
auto Info(etl::format_string< Args... > fmt, Args &&... args) -> void
以 INFO 级别记录日志
size_t core_id
核心 ID
Definition per_cpu.hpp:1
Here is the call graph for this function: