| 69 | } |
| 70 | |
| 71 | auto 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 | |
| 123 | SpinLock smp_lock("smp_lock"); |
| 124 | int shared_counter = 0; |
no test coverage detected