| // Copyright 2018 The Fuchsia Authors | |
| // | |
| // Use of this source code is governed by a MIT-style | |
| // license that can be found in the LICENSE file or at | |
| // https://opensource.org/licenses/MIT | |
| /// Test arch enable/disable interrupt routines. | |
| #[cfg(ktest)] | |
| #[unittest::suite(name = "interrupt_tests_rust")] | |
| mod interrupt_disable_tests { | |
| use unittest::{assert_eq, expect_eq}; | |
| use crate::arch_rs::{ | |
| InterruptDisableGuard, InterruptSavedState, arch_interrupt_restore, arch_interrupt_save, | |
| disable_ints, enable_ints, ints_disabled, | |
| }; | |
| /// interrupt_disable_test | |
| #[test] | |
| fn interrupt_disable_test() { | |
| // make sure ints are disabled and that a simple enable/disable tracks | |
| assert_eq!(false, ints_disabled()); | |
| disable_ints(); | |
| expect_eq!(true, ints_disabled()); | |
| enable_ints(); | |
| assert_eq!(false, ints_disabled()); | |
| } | |
| /// interrupt_save_restore_test | |
| #[test] | |
| fn interrupt_save_restore_test() { | |
| // validate that a simple save/restore works | |
| { | |
| assert_eq!(false, ints_disabled()); | |
| let state: InterruptSavedState = arch_interrupt_save(); | |
| expect_eq!(true, ints_disabled()); | |
| arch_interrupt_restore(state); | |
| assert_eq!(false, ints_disabled()); | |
| } | |
| // validate that a nested save/restore works | |
| { | |
| assert_eq!(false, ints_disabled()); | |
| let state: InterruptSavedState = arch_interrupt_save(); | |
| expect_eq!(true, ints_disabled()); | |
| let state2: InterruptSavedState = arch_interrupt_save(); | |
| expect_eq!(true, ints_disabled()); | |
| arch_interrupt_restore(state2); | |
| expect_eq!(true, ints_disabled()); | |
| arch_interrupt_restore(state); | |
| assert_eq!(false, ints_disabled()); | |
| } | |
| } | |
| /// interrupt_save_restore_guard_test | |
| #[test] | |
| fn interrupt_save_restore_guard_test() { | |
| // validate that a save/restore guard works | |
| assert_eq!(false, ints_disabled()); | |
| { | |
| let _irqd = InterruptDisableGuard::new(); | |
| expect_eq!(true, ints_disabled()); | |
| } | |
| assert_eq!(false, ints_disabled()); | |
| // validate that a nested guard works | |
| { | |
| let _irqd = InterruptDisableGuard::new(); | |
| expect_eq!(true, ints_disabled()); | |
| { | |
| let _irqd2 = InterruptDisableGuard::new(); | |
| expect_eq!(true, ints_disabled()); | |
| } | |
| expect_eq!(true, ints_disabled()); | |
| } | |
| assert_eq!(false, ints_disabled()); | |
| // validate that early drop reenables interrupts | |
| { | |
| let irqd = InterruptDisableGuard::new(); | |
| expect_eq!(true, ints_disabled()); | |
| drop(irqd); | |
| expect_eq!(false, ints_disabled()); | |
| } | |
| assert_eq!(false, ints_disabled()); | |
| // validate that nested early drop works | |
| { | |
| let _irqd = InterruptDisableGuard::new(); | |
| expect_eq!(true, ints_disabled()); | |
| { | |
| let irqd2 = InterruptDisableGuard::new(); | |
| expect_eq!(true, ints_disabled()); | |
| drop(irqd2); | |
| expect_eq!(true, ints_disabled()); | |
| } | |
| expect_eq!(true, ints_disabled()); | |
| } | |
| assert_eq!(false, ints_disabled()); | |
| } | |
| } |