use turkos_os_guest_power::psci_reset::*; const OLD_BOOT:u64=0x2135_0001; const NEW_BOOT:u64=0x2135_0002; const VIRT:Probe=Probe{present:true,enabled:true,compatible:true,conduit:Some(Conduit::Hvc),version:0x0001_0000,features_reset:0}; fn ready()->ResetCoordinator{let mut c=ResetCoordinator::new(OLD_BOOT,1).unwrap();c.probe(VIRT).unwrap();c} #[test]fn os_guest_power_psci_reset_positive(){let mut c=ResetCoordinator::new(OLD_BOOT,1).unwrap(); let s=c.probe(VIRT).unwrap();assert_eq!((s.phase,s.conduit,s.version),(Phase::Ready,Conduit::Hvc as u64,0x0001_0000)); let inv=c.arm_reset(OP_RESET,1).unwrap();assert_eq!(inv,Invocation{conduit:Conduit::Hvc,function:SYSTEM_RESET,old_boot_id:OLD_BOOT,old_boot0_seq:1,ticket_sequence:1}); let final_s=c.observe_reboot(RebootObservation{new_boot_id:NEW_BOOT,new_boot0_seq:2,conduit:Conduit::Hvc,function:SYSTEM_RESET,ticket_sequence:1,reused_log:false}).unwrap(); assert_eq!(final_s,Status{old_boot_id:OLD_BOOT,new_boot_id:NEW_BOOT,old_boot0_seq:1,new_boot0_seq:2,phase:Phase::RebootVerified,conduit:Conduit::Hvc as u64,version:0x0001_0000,armed:1,verified_reboots:1,refused:0,last_ticket:1})} #[test]fn os_guest_power_psci_reset_negative(){let mut c=ready();c.arm_reset(OP_RESET,1).unwrap(); let good=RebootObservation{new_boot_id:NEW_BOOT,new_boot0_seq:2,conduit:Conduit::Hvc,function:SYSTEM_RESET,ticket_sequence:1,reused_log:false}; for bad in[RebootObservation{reused_log:true,..good},RebootObservation{new_boot0_seq:1,..good},RebootObservation{new_boot0_seq:0,..good}]{ let before=c.status();assert_eq!(c.observe_reboot(bad),Err(Error::ReusedBootLog));assert_eq!(c.status(),Status{refused:before.refused+1,..before});} for stale in[RebootObservation{new_boot_id:0,..good},RebootObservation{new_boot_id:OLD_BOOT,..good}]{ let before=c.status();assert_eq!(c.observe_reboot(stale),Err(Error::StaleBootIdentity));assert_eq!(c.status(),Status{refused:before.refused+1,..before});} assert_eq!(c.status().phase,Phase::Armed);assert_eq!(c.status().verified_reboots,0); assert_eq!(c.observe_reboot(good).unwrap().verified_reboots,1)} #[test]fn os_guest_power_psci_reset_probe_validation(){let mut c=ResetCoordinator::new(OLD_BOOT,1).unwrap(); for bad in[Probe{present:false,..VIRT},Probe{enabled:false,..VIRT},Probe{compatible:false,..VIRT},Probe{conduit:None,..VIRT}]{ assert_eq!(c.probe(bad),Err(Error::NoPsci));} for unsup in[Probe{version:1,..VIRT},Probe{features_reset:-1,..VIRT}]{ assert_eq!(c.probe(unsup),Err(Error::Unsupported));} assert_eq!(c.status().refused,6);assert_eq!(c.arm_reset(OP_RESET,1),Err(Error::State)); c.probe(Probe{conduit:Some(Conduit::Smc),version:MIN_VERSION,features_reset:0,..VIRT}).unwrap(); assert_eq!(c.arm_reset(OP_RESET,1).unwrap().conduit,Conduit::Smc)} #[test]fn os_guest_power_psci_reset_ticket_and_state(){let mut c=ready(); for(op,seq)in[(1,1),(0,1),(OP_RESET,0)]{let before=c.status();assert_eq!(c.arm_reset(op,seq),Err(Error::Ticket));assert_eq!(c.status().refused,before.refused+1);} let obs=RebootObservation{new_boot_id:NEW_BOOT,new_boot0_seq:2,conduit:Conduit::Hvc,function:SYSTEM_RESET,ticket_sequence:3,reused_log:false}; assert_eq!(c.observe_reboot(obs),Err(Error::State));c.arm_reset(OP_RESET,3).unwrap(); assert_eq!(c.arm_reset(OP_RESET,4),Err(Error::State));c.observe_reboot(obs).unwrap(); assert_eq!(c.observe_reboot(obs),Err(Error::State))} #[test]fn os_guest_power_psci_reset_observation_binding(){let mut c=ready();c.arm_reset(OP_RESET,2).unwrap(); let good=RebootObservation{new_boot_id:NEW_BOOT,new_boot0_seq:2,conduit:Conduit::Hvc,function:SYSTEM_RESET,ticket_sequence:2,reused_log:false}; for bad in[RebootObservation{conduit:Conduit::Smc,..good},RebootObservation{function:PSCI_VERSION,..good},RebootObservation{ticket_sequence:1,..good}]{ let before=c.status();assert_eq!(c.observe_reboot(bad),Err(Error::Ticket));assert_eq!(c.status().refused,before.refused+1);} assert_eq!(c.observe_reboot(good).unwrap().phase,Phase::RebootVerified)} #[test]fn os_guest_power_psci_reset_invalid_configuration(){for(b,s)in[(0,1),(OLD_BOOT,0)]{assert_eq!(ResetCoordinator::new(b,s).unwrap_err(),Error::Configuration)} let mut c=ready();assert_eq!(c.probe(VIRT),Err(Error::State))}