MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / test_interrupt_restore

Function test_interrupt_restore

tests/system_test/spinlock_test.cpp:71–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71auto test_interrupt_restore() -> bool {
72 klog::Info("Running test_interrupt_restore...");
73 TestSpinLock lock("intr");
74
75 // Case 1: Interrupts enabled
76 cpu_io::EnableInterrupt();
77 if (!cpu_io::GetInterruptStatus()) {
78 klog::Err("FAIL: Failed to enable interrupts");
79 return false;
80 }
81
82 (void)lock.Lock();
83 if (cpu_io::GetInterruptStatus()) {
84 klog::Err("FAIL: Lock didn't disable interrupts");
85 (void)lock.UnLock();
86 return false;
87 }
88 (void)lock.UnLock();
89
90 if (!cpu_io::GetInterruptStatus()) {
91 klog::Err("FAIL: Unlock didn't restore interrupts (expected enabled)");
92 return false;
93 }
94
95 // Case 2: Interrupts disabled
96 cpu_io::DisableInterrupt();
97 // Ensure disabled
98 if (cpu_io::GetInterruptStatus()) {
99 klog::Err("FAIL: Failed to disable interrupts for test");
100 return false;
101 }
102
103 (void)lock.Lock();
104 if (cpu_io::GetInterruptStatus()) {
105 klog::Err("FAIL: Lock enabled interrupts unexpectedly");
106 (void)lock.UnLock();
107 cpu_io::EnableInterrupt();
108 return false;
109 }
110 (void)lock.UnLock();
111
112 if (cpu_io::GetInterruptStatus()) {
113 klog::Err("FAIL: Unlock enabled interrupts (expected disabled)");
114 cpu_io::EnableInterrupt();
115 return false;
116 }
117
118 cpu_io::EnableInterrupt(); // Cleanup
119 klog::Info("test_interrupt_restore passed");
120 return true;
121}
122
123SpinLock smp_lock("smp_lock");
124int shared_counter = 0;

Callers 1

spinlock_testFunction · 0.85

Calls 7

InfoFunction · 0.85
EnableInterruptFunction · 0.85
GetInterruptStatusFunction · 0.85
ErrFunction · 0.85
DisableInterruptFunction · 0.85
LockMethod · 0.45
UnLockMethod · 0.45

Tested by

no test coverage detected